Changeset 79746 in webkit


Ignore:
Timestamp:
Feb 25, 2011 4:47:31 PM (13 years ago)
Author:
Darin Adler
Message:

<rdar://problem/8036034> WebKit2 should work even if DYLD_FRAMEWORK_PATH is not set

Reviewed by Anders Carlsson.

  • UIProcess/Launcher/mac/ProcessLauncherMac.mm:

(WebKit::EnvironmentVariables::~EnvironmentVariables): Use fastFree, not delete, on
the strings here because they are allocated with fastMalloc, not new.
(WebKit::EnvironmentVariables::set): Use const more.
(WebKit::EnvironmentVariables::get): Ditto.
(WebKit::EnvironmentVariables::appendValue): Ditto.
(WebKit::EnvironmentVariables::valueIfVariableHasName): Ditto. Also fix mistake
where this would match if the name matched only a prefix of the environment variable's
name. We want to match the whole name, so we need to use memcmp, not strncmp.
(WebKit::EnvironmentVariables::createStringForVariable): Use const more.
(WebKit::ProcessLauncher::launchProcess): Use clearer name, frameworkExecutablePath,
for what was called bundlePath before. Append the frameworks path to DYLD_FRAMEWORK_PATH,
ensuring we can pick up other frameworks from the same directory in the web process.
Use a const_cast instead of a C-style cast.

Location:
trunk/Source/WebKit2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r79743 r79746  
     12011-02-25  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Anders Carlsson.
     4
     5        <rdar://problem/8036034> WebKit2 should work even if DYLD_FRAMEWORK_PATH is not set
     6
     7        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
     8        (WebKit::EnvironmentVariables::~EnvironmentVariables): Use fastFree, not delete, on
     9        the strings here because they are allocated with fastMalloc, not new.
     10        (WebKit::EnvironmentVariables::set): Use const more.
     11        (WebKit::EnvironmentVariables::get): Ditto.
     12        (WebKit::EnvironmentVariables::appendValue): Ditto.
     13        (WebKit::EnvironmentVariables::valueIfVariableHasName): Ditto. Also fix mistake
     14        where this would match if the name matched only a prefix of the environment variable's
     15        name. We want to match the whole name, so we need to use memcmp, not strncmp.
     16        (WebKit::EnvironmentVariables::createStringForVariable): Use const more.
     17        (WebKit::ProcessLauncher::launchProcess): Use clearer name, frameworkExecutablePath,
     18        for what was called bundlePath before. Append the frameworks path to DYLD_FRAMEWORK_PATH,
     19        ensuring we can pick up other frameworks from the same directory in the web process.
     20        Use a const_cast instead of a C-style cast.
     21
    1222011-02-25  Chris Fleizach  <cfleizach@apple.com>
    223
  • trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm

    r78441 r79746  
    7878    ~EnvironmentVariables()
    7979    {
    80         deleteAllValues(m_allocatedStrings);
     80        size_t size = m_allocatedStrings.size();
     81        for (size_t i = 0; i < size; ++i)
     82            fastFree(m_allocatedStrings[i]);
    8183    }
    8284
     
    8890
    8991        // Allocate a string for the name and value.
    90         char* nameAndValue = createStringForVariable(name, value);
     92        const char* nameAndValue = createStringForVariable(name, value);
    9193
    9294        for (size_t i = 0; i < m_environmentVariables.size() - 1; ++i) {
    93             char* environmentVariable = m_environmentVariables[i];
    94 
    95             if (valueIfVariableHasName(environmentVariable, name)) {
     95            if (valueIfVariableHasName(m_environmentVariables[i], name)) {
    9696                // Just replace the environment variable.
    97                 m_environmentVariables[i] = nameAndValue;
     97                m_environmentVariables[i] = const_cast<char*>(nameAndValue);
    9898                return;
    9999            }
     
    102102        // Append the new string.
    103103        ASSERT(!m_environmentVariables.last());
    104         m_environmentVariables.last() = nameAndValue;
     104        m_environmentVariables.last() = const_cast<char*>(nameAndValue);
    105105        m_environmentVariables.append(static_cast<char*>(0));
    106106
     
    108108    }
    109109
    110     char* get(const char* name) const
     110    const char* get(const char* name) const
    111111    {
    112112        for (size_t i = 0; m_environmentPointer[i]; ++i) {
    113             if (char* value = valueIfVariableHasName(m_environmentPointer[i], name))
     113            if (const char* value = valueIfVariableHasName(m_environmentPointer[i], name))
    114114                return value;
    115115        }
     
    120120    void appendValue(const char* name, const char* value, char separator)
    121121    {
    122         char* existingValue = get(name);
     122        const char* existingValue = get(name);
    123123        if (!existingValue) {
    124124            set(name, value);
     
    137137
    138138private:
    139     char *valueIfVariableHasName(const char* environmentVariable, const char* name) const
     139    const char* valueIfVariableHasName(const char* environmentVariable, const char* name) const
    140140    {
    141141        // Find the environment variable name.
    142         char* equalsLocation = strchr(environmentVariable, '=');
     142        const char* equalsLocation = strchr(environmentVariable, '=');
    143143        ASSERT(equalsLocation);
    144144
    145145        size_t nameLength = equalsLocation - environmentVariable;
    146         if (strncmp(environmentVariable, name, nameLength))
     146        if (strlen(name) != nameLength)
    147147            return 0;
     148        if (memcmp(environmentVariable, name, nameLength))
     149            return 0;
    148150
    149151        return equalsLocation + 1;
    150152    }
    151153
    152     char* createStringForVariable(const char* name, const char* value)
     154    const char* createStringForVariable(const char* name, const char* value)
    153155    {
    154156        int nameLength = strlen(name);
     
    193195
    194196    NSBundle *webKit2Bundle = [NSBundle bundleWithIdentifier:@"com.apple.WebKit2"];
    195     const char* bundlePath = [[webKit2Bundle executablePath] fileSystemRepresentation];
     197    const char* frameworksPath = [[[webKit2Bundle bundlePath] stringByDeletingLastPathComponent] fileSystemRepresentation];
     198    const char* frameworkExecutablePath = [[webKit2Bundle executablePath] fileSystemRepresentation];
    196199
    197200    NSString *webProcessAppPath = [webKit2Bundle pathForAuxiliaryExecutable:@"WebProcess.app"];
     
    201204    CString serviceName = String::format("com.apple.WebKit.WebProcess-%d-%p", getpid(), this).utf8();
    202205
    203     const char* path = [webProcessAppExecutablePath fileSystemRepresentation];
    204     const char* args[] = { path, bundlePath, "-type", processTypeAsString(m_launchOptions.processType), "-servicename", serviceName.data(), 0 };
     206    const char* args[] = { [webProcessAppExecutablePath fileSystemRepresentation], frameworkExecutablePath, "-type", processTypeAsString(m_launchOptions.processType), "-servicename", serviceName.data(), 0 };
    205207
    206208    // Register ourselves.
     
    244246    EnvironmentVariables environmentVariables;
    245247
     248    environmentVariables.appendValue("DYLD_FRAMEWORK_PATH", frameworksPath, ':');
     249
    246250    if (m_launchOptions.processType == ProcessLauncher::PluginProcess) {
    247251        // We need to insert the plug-in process shim.
    248252        NSString *pluginProcessShimPathNSString = [[webProcessAppExecutablePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"PluginProcessShim.dylib"];
    249         const char *pluginProcessShimPath = [pluginProcessShimPathNSString fileSystemRepresentation];
     253        const char* pluginProcessShimPath = [pluginProcessShimPathNSString fileSystemRepresentation];
    250254
    251255        // Make sure that the file exists.
     
    255259    }
    256260   
    257     int result = posix_spawn(&processIdentifier, path, 0, &attr, (char *const*)args, environmentVariables.environmentPointer());
     261    int result = posix_spawn(&processIdentifier, args[0], 0, &attr, const_cast<char**>(args), environmentVariables.environmentPointer());
    258262
    259263    posix_spawnattr_destroy(&attr);
Note: See TracChangeset for help on using the changeset viewer.