Skip to content

Commit

Permalink
Stop using explicit memory management in WebKitLauncherWin
Browse files Browse the repository at this point in the history
We now use stack-allocated STL objects instead.

Prep work for <http://webkit.org/b/56571> First argument passed to WebKit.exe is ignored by
Safari

Reviewed by Steve Falkenburg.

* WebKitLauncherWin/WebKitLauncherWin.cpp:
(getStringValue):
(applePathFromRegistry):
(safariInstallDir):
(safariBrowserExe):
(_tWinMain):
Changed to use stack-allocated STL objects instead of malloc/free.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@104189 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
aroben@apple.com committed Jan 5, 2012
1 parent d3cf472 commit 2ce145d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
19 changes: 19 additions & 0 deletions Tools/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
2012-01-05 Adam Roben <aroben@apple.com>

Stop using explicit memory management in WebKitLauncherWin

We now use stack-allocated STL objects instead.

Prep work for <http://webkit.org/b/56571> First argument passed to WebKit.exe is ignored by
Safari

Reviewed by Steve Falkenburg.

* WebKitLauncherWin/WebKitLauncherWin.cpp:
(getStringValue):
(applePathFromRegistry):
(safariInstallDir):
(safariBrowserExe):
(_tWinMain):
Changed to use stack-allocated STL objects instead of malloc/free.

2012-01-05 Adam Roben <aroben@apple.com>

Turn WebKitTestRunner into a stub .exe launcher and a .dll that contains all the real code
Expand Down
44 changes: 23 additions & 21 deletions Tools/WebKitLauncherWin/WebKitLauncherWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,55 @@

#include "resource.h"
#include <shlwapi.h>
#include <string>
#include <tchar.h>
#include <vector>
#include <windows.h>

static LPTSTR getStringValue(HKEY key, LPCTSTR valueName)
using namespace std;

typedef basic_string<TCHAR> tstring;

static tstring getStringValue(HKEY key, const tstring& valueName)
{
DWORD type = 0;
DWORD bufferSize = 0;
if (RegQueryValueEx(key, valueName, 0, &type, 0, &bufferSize) != ERROR_SUCCESS || type != REG_SZ)
return 0;
if (RegQueryValueEx(key, valueName.c_str(), 0, &type, 0, &bufferSize) != ERROR_SUCCESS || type != REG_SZ)
return tstring();

LPTSTR buffer = static_cast<LPTSTR>(malloc(bufferSize));
if (RegQueryValueEx(key, valueName, 0, &type, reinterpret_cast<LPBYTE>(buffer), &bufferSize) != ERROR_SUCCESS) {
free(buffer);
return 0;
}
vector<TCHAR> buffer(bufferSize / sizeof(TCHAR));
if (RegQueryValueEx(key, valueName.c_str(), 0, &type, reinterpret_cast<LPBYTE>(&buffer[0]), &bufferSize) != ERROR_SUCCESS)
return tstring();

return buffer;
return &buffer[0];
}

static LPTSTR applePathFromRegistry(LPCTSTR key, LPCTSTR value)
static tstring applePathFromRegistry(const tstring& key, const tstring& value)
{
HKEY applePathKey = 0;
LONG error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &applePathKey);
LONG error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, key.c_str(), 0, KEY_READ, &applePathKey);
if (error != ERROR_SUCCESS)
return 0;
LPTSTR path = getStringValue(applePathKey, value);
return tstring();
tstring path = getStringValue(applePathKey, value);
RegCloseKey(applePathKey);
return path;
}

static LPTSTR safariInstallDir()
static tstring safariInstallDir()
{
return applePathFromRegistry(TEXT("SOFTWARE\\Apple Computer, Inc.\\Safari"), TEXT("InstallDir"));
}

static LPTSTR safariBrowserExe()
static tstring safariBrowserExe()
{
return applePathFromRegistry(TEXT("SOFTWARE\\Apple Computer, Inc.\\Safari"), TEXT("BrowserExe"));
}

int APIENTRY _tWinMain(HINSTANCE instance, HINSTANCE, LPTSTR commandLine, int)
{
LPTSTR path = safariInstallDir();
LPTSTR browserExe = safariBrowserExe();
if (!path || !browserExe) {
tstring path = safariInstallDir();
tstring browserExe = safariBrowserExe();
if (path.empty() || browserExe.empty()) {
MessageBox(0, TEXT("Safari must be installed to run a WebKit nightly. You can download Safari from http://www.apple.com/safari/download"), TEXT("Safari not found"), MB_ICONSTOP);
return 1;
}
Expand All @@ -86,10 +90,8 @@ int APIENTRY _tWinMain(HINSTANCE instance, HINSTANCE, LPTSTR commandLine, int)
STARTUPINFO startupInfo = {0};
startupInfo.cb = sizeof(startupInfo);
PROCESS_INFORMATION processInfo = {0};
if (!CreateProcess(browserExe, commandLine, 0, 0, FALSE, NORMAL_PRIORITY_CLASS | CREATE_UNICODE_ENVIRONMENT, 0, path, &startupInfo, &processInfo))
if (!CreateProcess(browserExe.c_str(), commandLine, 0, 0, FALSE, NORMAL_PRIORITY_CLASS | CREATE_UNICODE_ENVIRONMENT, 0, path.c_str(), &startupInfo, &processInfo))
MessageBox(0, TEXT("Safari could not be launched. Please make sure you have the latest version of Safari installed and try again. You can download Safari from http://www.apple.com/safari/download"), TEXT("Safari launch failed"), MB_ICONSTOP);

free(browserExe);
free(path);
return 0;
}

0 comments on commit 2ce145d

Please sign in to comment.