Bug 32711 - [gtk] Make paths relocatable on runtime
Summary: [gtk] Make paths relocatable on runtime
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Windows XP
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-18 06:18 PST by Fridrich Strba
Modified: 2010-03-05 14:40 PST (History)
4 users (show)

See Also:


Attachments
Patch doing what was described before (2.50 KB, patch)
2010-03-03 01:45 PST, Fridrich Strba
no flags Details | Formatted Diff | Diff
Patch that does what the previous one, but does not leak memory. (2.73 KB, patch)
2010-03-04 07:11 PST, Fridrich Strba
no flags Details | Formatted Diff | Diff
Patch modified not to use String::format (2.72 KB, patch)
2010-03-04 08:23 PST, Fridrich Strba
no flags Details | Formatted Diff | Diff
Patch fixing a forgetful mind (1.20 KB, patch)
2010-03-04 10:13 PST, Fridrich Strba
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fridrich Strba 2009-12-18 06:18:38 PST
In platform/graphics/gtk/ImageGtk.cpp, the position of the icon is computer like this: fileName = String::format("%s/webkit-1.0/images/%s.png", DATA_DIR, name).utf8()
This assumes that the runtime prefix will be identical to the configure-time prefix, which is not to be assumed on windows. The generic solution for this problem would be to simply get by win32 api call the position of the libwebkit*.dll at runtime and compute the position from this information. Something like:

#ifdef _WIN32
#  include <shlobj.h>
#  include <mbstring.h>
/* search for data relative to where we are installed */

static HMODULE hmodule;

#ifdef __cplusplus
extern "C" {
#endif
BOOL WINAPI
DllMain (HINSTANCE hinstDLL,
	 DWORD     fdwReason,
	 LPVOID    lpvReserved)
{
  switch (fdwReason)
    {
    case DLL_PROCESS_ATTACH:
      hmodule = hinstDLL;
      break;
    }

  return TRUE;
}
#ifdef __cplusplus
}
#endif

static char *
get_webkit_datadir (void)
{
  static char retval[1000];
  static int beenhere = 0;

  unsigned char *p;

  if (beenhere)
    return retval;

  if (!GetModuleFileName (hmodule, (CHAR *) retval, sizeof(retval) - 10))
    return DATA_DIR;

  p = _mbsrchr ((const unsigned char *) retval, '\\');
  *p = '\0';
  p = _mbsrchr ((const unsigned char *) retval, '\\');
  if (p) {
    if (stricmp ((const char *) (p+1), "bin") == 0)
      *p = '\0';
  }
  strcat (retval, "\\share");

  beenhere = 1;

  return retval;
}

#undef DATA_DIR
#define DATA_DIR get_webkit_datadir ()
#endif

which should work for the ImageGtk.cpp file. Although a more general solution in line with what we are doing in evolution could be provided if we expect this problem not to be an isolated one:
http://git.gnome.org/cgit/evolution/tree/e-util/e-win32-reloc.c
Comment 1 Fridrich Strba 2010-03-03 01:45:31 PST
Created attachment 49887 [details]
Patch doing what was described before
Comment 2 Fridrich Strba 2010-03-04 07:11:36 PST
Created attachment 50013 [details]
Patch that does what the previous one, but does not leak memory.
Comment 3 Fridrich Strba 2010-03-04 08:23:49 PST
Created attachment 50027 [details]
Patch modified not to use String::format
Comment 4 Holger Freyther 2010-03-04 09:10:10 PST
Comment on attachment 50027 [details]
Patch modified not to use String::format

I don't know if that is the best thing to do, but it seems to make sense and it has no impact on UNIX for WebKitGTK+ and we don't seem to leak memory.


> +static char *
> +get_webkit_datadir(void)

I think this is a small style violation, but I see that we copy the code from other places.
Comment 5 WebKit Commit Bot 2010-03-04 10:00:17 PST
Comment on attachment 50027 [details]
Patch modified not to use String::format

Clearing flags on attachment: 50027

Committed r55531: <http://trac.webkit.org/changeset/55531>
Comment 6 WebKit Commit Bot 2010-03-04 10:00:22 PST
All reviewed patches have been landed.  Closing bug.
Comment 7 Fridrich Strba 2010-03-04 10:13:44 PST
Created attachment 50033 [details]
Patch fixing a forgetful mind
Comment 8 Holger Freyther 2010-03-04 10:18:15 PST
Comment on attachment 50033 [details]
Patch fixing a forgetful mind

ooops.
Comment 9 Fridrich Strba 2010-03-04 10:21:04 PST
reopening so that it can land
Comment 10 WebKit Commit Bot 2010-03-04 11:39:17 PST
Comment on attachment 50033 [details]
Patch fixing a forgetful mind

Rejecting patch 50033 from commit-queue.

Failed to run "['/Users/eseidel/Projects/CommitQueue/WebKitTools/Scripts/svn-apply', '--reviewer', 'Holger Freyther', '--force']" exit_code: 1
patching file WebCore/ChangeLog
Hunk #1 succeeded at 1 with fuzz 3.
patching file WebCore/platform/graphics/gtk/ImageGtk.cpp
Hunk #1 FAILED at 159.
1 out of 1 hunk FAILED -- saving rejects to file WebCore/platform/graphics/gtk/ImageGtk.cpp.rej

Full output: http://webkit-commit-queue.appspot.com/results/331689
Comment 11 Eric Seidel (no email) 2010-03-05 14:38:52 PST
Looks like this patch will need an update.
Comment 12 Fridrich Strba 2010-03-05 14:40:09 PST
The fix landed as a part of other patch, closing this bug