Changeset 86089 in webkit
- Timestamp:
- May 9, 2011 2:47:10 PM (13 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r86077 r86089 1 2011-05-09 Anders Carlsson <andersca@apple.com> 2 3 Reviewed by Sam Weinig. 4 5 Move EnvironmentVariables out into its own .cpp file 6 https://bugs.webkit.org/show_bug.cgi?id=60507 7 8 * UIProcess/Launcher/mac/EnvironmentVariables.cpp: Added. 9 (WebKit::EnvironmentVariables::EnvironmentVariables): 10 (WebKit::EnvironmentVariables::~EnvironmentVariables): 11 (WebKit::EnvironmentVariables::set): 12 (WebKit::EnvironmentVariables::get): 13 (WebKit::EnvironmentVariables::appendValue): 14 (WebKit::EnvironmentVariables::valueIfVariableHasName): 15 (WebKit::EnvironmentVariables::createStringForVariable): 16 (WebKit::EnvironmentVariables::copyEnvironmentVariables): 17 * UIProcess/Launcher/mac/EnvironmentVariables.h: Added. 18 (WebKit::EnvironmentVariables::environmentPointer): 19 * UIProcess/Launcher/mac/ProcessLauncherMac.mm: 20 * WebKit2.xcodeproj/project.pbxproj: 21 1 22 2011-05-09 Adam Roben <aroben@apple.com> 2 23 -
trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm
r80646 r86089 27 27 #import "ProcessLauncher.h" 28 28 29 #import "EnvironmentVariables.h" 29 30 #import "RunLoop.h" 30 31 #import "WebProcess.h" … … 66 67 #endif 67 68 } 68 69 class EnvironmentVariables {70 WTF_MAKE_NONCOPYABLE(EnvironmentVariables);71 72 public:73 EnvironmentVariables()74 : m_environmentPointer(*_NSGetEnviron())75 {76 }77 78 ~EnvironmentVariables()79 {80 size_t size = m_allocatedStrings.size();81 for (size_t i = 0; i < size; ++i)82 fastFree(m_allocatedStrings[i]);83 }84 85 void set(const char* name, const char* value)86 {87 // Check if we need to copy the environment.88 if (m_environmentPointer == *_NSGetEnviron())89 copyEnvironmentVariables();90 91 // Allocate a string for the name and value.92 const char* nameAndValue = createStringForVariable(name, value);93 94 for (size_t i = 0; i < m_environmentVariables.size() - 1; ++i) {95 if (valueIfVariableHasName(m_environmentVariables[i], name)) {96 // Just replace the environment variable.97 m_environmentVariables[i] = const_cast<char*>(nameAndValue);98 return;99 }100 }101 102 // Append the new string.103 ASSERT(!m_environmentVariables.last());104 m_environmentVariables.last() = const_cast<char*>(nameAndValue);105 m_environmentVariables.append(static_cast<char*>(0));106 107 m_environmentPointer = m_environmentVariables.data();108 }109 110 const char* get(const char* name) const111 {112 for (size_t i = 0; m_environmentPointer[i]; ++i) {113 if (const char* value = valueIfVariableHasName(m_environmentPointer[i], name))114 return value;115 }116 return 0;117 }118 119 // Will append the value with the given separator if the environment variable already exists.120 void appendValue(const char* name, const char* value, char separator)121 {122 const char* existingValue = get(name);123 if (!existingValue) {124 set(name, value);125 return;126 }127 128 Vector<char, 128> newValue;129 newValue.append(existingValue, strlen(existingValue));130 newValue.append(separator);131 newValue.append(value, strlen(value) + 1);132 133 set(name, newValue.data());134 }135 136 char** environmentPointer() const { return m_environmentPointer; }137 138 private:139 const char* valueIfVariableHasName(const char* environmentVariable, const char* name) const140 {141 // Find the environment variable name.142 const char* equalsLocation = strchr(environmentVariable, '=');143 ASSERT(equalsLocation);144 145 size_t nameLength = equalsLocation - environmentVariable;146 if (strlen(name) != nameLength)147 return 0;148 if (memcmp(environmentVariable, name, nameLength))149 return 0;150 151 return equalsLocation + 1;152 }153 154 const char* createStringForVariable(const char* name, const char* value)155 {156 int nameLength = strlen(name);157 int valueLength = strlen(value);158 159 // Allocate enough room to hold 'name=value' and the null character.160 char* string = static_cast<char*>(fastMalloc(nameLength + 1 + valueLength + 1));161 memcpy(string, name, nameLength);162 string[nameLength] = '=';163 memcpy(string + nameLength + 1, value, valueLength);164 string[nameLength + 1 + valueLength] = '\0';165 166 m_allocatedStrings.append(string);167 168 return string;169 }170 171 void copyEnvironmentVariables()172 {173 for (size_t i = 0; (*_NSGetEnviron())[i]; i++)174 m_environmentVariables.append((*_NSGetEnviron())[i]);175 176 // Null-terminate the array.177 m_environmentVariables.append(static_cast<char*>(0));178 179 // Update the environment pointer.180 m_environmentPointer = m_environmentVariables.data();181 }182 183 char** m_environmentPointer;184 Vector<char*> m_environmentVariables;185 186 // These allocated strings will be freed in the destructor.187 Vector<char*> m_allocatedStrings;188 };189 69 190 70 void ProcessLauncher::launchProcess() -
trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
r86021 r86089 151 151 1A6FBD2811E69BC200DB1371 /* NetscapePlugin.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A6FBD2611E69BC200DB1371 /* NetscapePlugin.h */; }; 152 152 1A6FBD2911E69BC200DB1371 /* NetscapePlugin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A6FBD2711E69BC200DB1371 /* NetscapePlugin.cpp */; }; 153 1A7C6CDA1378950800B9C04D /* EnvironmentVariables.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A7C6CD81378950800B9C04D /* EnvironmentVariables.cpp */; }; 154 1A7C6CDB1378950800B9C04D /* EnvironmentVariables.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A7C6CD91378950800B9C04D /* EnvironmentVariables.h */; }; 153 155 1A8EF4CB1252403700F7067F /* PluginControllerProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A8EF4C91252403700F7067F /* PluginControllerProxy.h */; }; 154 156 1A8EF4CC1252403700F7067F /* PluginControllerProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A8EF4CA1252403700F7067F /* PluginControllerProxy.cpp */; }; … … 1025 1027 1A6FBD2611E69BC200DB1371 /* NetscapePlugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetscapePlugin.h; sourceTree = "<group>"; }; 1026 1028 1A6FBD2711E69BC200DB1371 /* NetscapePlugin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetscapePlugin.cpp; sourceTree = "<group>"; }; 1029 1A7C6CD81378950800B9C04D /* EnvironmentVariables.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EnvironmentVariables.cpp; sourceTree = "<group>"; }; 1030 1A7C6CD91378950800B9C04D /* EnvironmentVariables.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EnvironmentVariables.h; sourceTree = "<group>"; }; 1027 1031 1A8EF4C91252403700F7067F /* PluginControllerProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginControllerProxy.h; sourceTree = "<group>"; }; 1028 1032 1A8EF4CA1252403700F7067F /* PluginControllerProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PluginControllerProxy.cpp; sourceTree = "<group>"; }; … … 2767 2771 isa = PBXGroup; 2768 2772 children = ( 2773 1A7C6CD81378950800B9C04D /* EnvironmentVariables.cpp */, 2774 1A7C6CD91378950800B9C04D /* EnvironmentVariables.h */, 2769 2775 BC111B1B112F5FE600337BAB /* ProcessLauncherMac.mm */, 2770 2776 BCF501B3123EF602005955AE /* ThreadLauncherMac.mm */, … … 3713 3719 6EE849C81368D9390038D481 /* WKInspectorMac.h in Headers */, 3714 3720 37F90DE31376560E0051CF68 /* HTTPCookieAcceptPolicy.h in Headers */, 3721 1A7C6CDB1378950800B9C04D /* EnvironmentVariables.h in Headers */, 3715 3722 ); 3716 3723 runOnlyForDeploymentPostprocessing = 0; … … 4344 4351 51C4032C136749D800DC972D /* AuthenticationManager.mac.mm in Sources */, 4345 4352 DF58C6361371ACA000F9A37C /* NativeWebWheelEventMac.mm in Sources */, 4353 1A7C6CDA1378950800B9C04D /* EnvironmentVariables.cpp in Sources */, 4346 4354 ); 4347 4355 runOnlyForDeploymentPostprocessing = 0;
Note: See TracChangeset
for help on using the changeset viewer.