Fix Bug 15532: run-safari fails if Safari is installed in a non-default location
authoraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Oct 2007 20:11:24 +0000 (20:11 +0000)
committeraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Oct 2007 20:11:24 +0000 (20:11 +0000)
 WebKitTools:

         Fix Bug 15532: run-safari fails if Safari is installed in a non-default location

         http://bugs.webkit.org/show_bug.cgi?id=15532

         FindSafari simply prints the location of an installed Safari.exe on
         stdout.

         Reviewed by Darin.

         * FindSafari/FindSafari.cpp: Copied from WebKitTools/WebKitInitializer/WebKitInitializer.cpp.
         (getStringValue):
         (getWebViewCLSID):
         (getInstalledWebKitDirectory):
         (_tmain):
         * FindSafari/FindSafari.vcproj: Added.
         * Scripts/webkitdirs.pm:
         (sub installedSafariPath): Added. Calls FindSafari on Windows.

 WebKit/win:

         Add FindSafari

         Reviewed by Darin.

         * WebKit.vcproj/WebKit.sln:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@26706 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/win/ChangeLog
WebKit/win/WebKit.vcproj/WebKit.sln
WebKitTools/ChangeLog
WebKitTools/FindSafari/FindSafari.cpp [new file with mode: 0644]
WebKitTools/FindSafari/FindSafari.vcproj [new file with mode: 0644]
WebKitTools/Scripts/webkitdirs.pm

index e928521492df29b75125a45305d36fc533970f0f..d630374889e131ba7f0c0f65c781ef464e6fa59d 100644 (file)
@@ -1,3 +1,11 @@
+2007-10-16  Adam Roben  <aroben@apple.com>
+
+        Add FindSafari
+
+        Reviewed by Darin.
+
+        * WebKit.vcproj/WebKit.sln:
+
 2007-10-16  Adam Roben  <aroben@apple.com>
 
         Rename WebKit_debug.dll to WebKit.dll for the Debug configuration
index acebca0c4a5d96fb12c9dea40faae64a5d4abb46..f034d13d94b5e36f35adecd177ca273af2c5c5bd 100644 (file)
@@ -50,6 +50,7 @@ EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WTF", "..\..\..\JavaScriptCore\JavaScriptCore.vcproj\WTF\WTF.vcproj", "{AA8A5A85-592B-4357-BC60-E0E91E026AF6}"\r
 EndProject\r
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WebKitInitializer", "..\..\..\WebKitTools\WebKitInitializer\WebKitInitializer.vcproj", "{9E96B9B5-0CCB-47F8-A95E-C25ABE049E02}"\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FindSafari", "..\..\..\WebKitTools\FindSafari\FindSafari.vcproj", "{DA31DA52-6675-48D4-89E0-333A7144397C}"\r
 EndProject\r
 Global\r
        GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
@@ -101,6 +102,10 @@ Global
                {9E96B9B5-0CCB-47F8-A95E-C25ABE049E02}.Debug|Win32.Build.0 = Debug|Win32\r
                {9E96B9B5-0CCB-47F8-A95E-C25ABE049E02}.Release|Win32.ActiveCfg = Release|Win32\r
                {9E96B9B5-0CCB-47F8-A95E-C25ABE049E02}.Release|Win32.Build.0 = Release|Win32\r
+               {DA31DA52-6675-48D4-89E0-333A7144397C}.Debug|Win32.ActiveCfg = Debug|Win32\r
+               {DA31DA52-6675-48D4-89E0-333A7144397C}.Debug|Win32.Build.0 = Debug|Win32\r
+               {DA31DA52-6675-48D4-89E0-333A7144397C}.Release|Win32.ActiveCfg = Release|Win32\r
+               {DA31DA52-6675-48D4-89E0-333A7144397C}.Release|Win32.Build.0 = Release|Win32\r
        EndGlobalSection\r
        GlobalSection(SolutionProperties) = preSolution\r
                HideSolutionNode = FALSE\r
index fc04fe9471253a77b1775654297535fa1925b50b..3a95403bc6e554157dfc3ee1f933b088be1d22d6 100644 (file)
         number of tweaks, including fixing a potential bug where expectedDirectoryForTest
         would take the type of results into account only some of the time.
 
+2007-10-16  Adam Roben  <aroben@apple.com>
+
+        Fix Bug 15532: run-safari fails if Safari is installed in a non-default location
+
+        http://bugs.webkit.org/show_bug.cgi?id=15532
+
+        FindSafari simply prints the location of an installed Safari.exe on
+        stdout.
+
+        Reviewed by Darin.
+
+        * FindSafari/FindSafari.cpp: Copied from WebKitTools/WebKitInitializer/WebKitInitializer.cpp.
+        (getStringValue):
+        (getWebViewCLSID):
+        (getInstalledWebKitDirectory):
+        (_tmain):
+        * FindSafari/FindSafari.vcproj: Added.
+        * Scripts/webkitdirs.pm:
+        (sub installedSafariPath): Added. Calls FindSafari on Windows.
+
 2007-10-16  Adam Roben  <aroben@apple.com>
 
         Updated for rename of WebKit_debug.dll to WebKit.dll for the Debug configuration
diff --git a/WebKitTools/FindSafari/FindSafari.cpp b/WebKitTools/FindSafari/FindSafari.cpp
new file mode 100644 (file)
index 0000000..8580602
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <shlwapi.h>
+#include <stdio.h>
+#include <tchar.h>
+#include <windows.h>
+
+#define LOG(header, ...) \
+    do { \
+        _ftprintf(stderr, header); \
+        _ftprintf(stderr, __VA_ARGS__); \
+    } while (0)
+#define LOG_WARNING(...) LOG(TEXT("WARNING: "), __VA_ARGS__)
+#define LOG_ERROR(...) LOG(TEXT("ERROR: "), __VA_ARGS__)
+
+static TCHAR* getStringValue(HKEY key, LPCTSTR valueName)
+{
+    DWORD type = 0;
+    DWORD bufferSize = 0;
+    if (RegQueryValueEx(key, valueName, 0, &type, 0, &bufferSize) != ERROR_SUCCESS || type != REG_SZ)
+        return 0;
+
+    TCHAR* buffer = (TCHAR*)malloc(bufferSize);
+    if (RegQueryValueEx(key, 0, 0, &type, reinterpret_cast<LPBYTE>(buffer), &bufferSize) != ERROR_SUCCESS) {
+        free(buffer);
+        return 0;
+    }
+
+    return buffer;
+}
+
+static LPOLESTR getWebViewCLSID()
+{
+    // FIXME <rdar://5505062>: Once WebKit switches to truly version-independent
+    // ProgIDs, this should just become "WebKit.WebView".
+    LPCTSTR webViewProgID = TEXT("WebKit.WebView.3");
+
+    CLSID clsid = CLSID_NULL;
+    HRESULT hr = CLSIDFromProgID(webViewProgID, &clsid);
+    if (FAILED(hr)) {
+        LOG_WARNING(TEXT("Failed to get CLSID for %s\n"), webViewProgID);
+        return 0;
+    }
+
+    LPOLESTR clsidString = 0;
+    if (FAILED(StringFromCLSID(clsid, &clsidString))) {
+        LOG_WARNING(TEXT("Failed to get string representation of CLSID for WebView\n"));
+        return 0;
+    }
+
+    return clsidString;
+}
+
+static TCHAR* getInstalledWebKitDirectory()
+{
+    LPCTSTR keyPrefix = TEXT("SOFTWARE\\Classes\\CLSID\\");
+    LPCTSTR keySuffix = TEXT("\\InprocServer32");
+
+    LPOLESTR clsid = getWebViewCLSID();
+    if (!clsid)
+        return 0;
+
+    size_t keyBufferLength = _tcslen(keyPrefix) + _tcslen(clsid) + _tcslen(keySuffix) + 1;
+    TCHAR* keyString = (TCHAR*)malloc(keyBufferLength * sizeof(TCHAR));
+
+    int ret = _sntprintf_s(keyString, keyBufferLength, keyBufferLength - 1, TEXT("%s%s%s"), keyPrefix, clsid, keySuffix);
+    CoTaskMemFree(clsid);
+    if (ret == -1) {
+        LOG_WARNING(TEXT("Failed to construct InprocServer32 key\n"));
+        return 0;
+    }
+
+    HKEY serverKey = 0;
+    LONG error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyString, 0, KEY_READ, &serverKey);
+    free(keyString);
+    if (error != ERROR_SUCCESS) {
+        LOG_WARNING(TEXT("Failed to open registry key %s\n"), keyString);
+        return 0;
+    }
+
+    TCHAR* webKitPath = getStringValue(serverKey, 0);
+    RegCloseKey(serverKey);
+    if (!webKitPath) {
+        LOG_WARNING(TEXT("Couldn't retrieve value for registry key %s\n"), keyString);
+        return 0;
+    }
+
+    TCHAR* startOfFileName = PathFindFileName(webKitPath);
+    if (startOfFileName == webKitPath) {
+        LOG_WARNING(TEXT("Couldn't find filename from path %s\n"), webKitPath);
+        free(webKitPath);
+        return 0;
+    }
+
+    *startOfFileName = '\0';
+    return webKitPath;
+}
+
+int _tmain(int argc, TCHAR* argv[])
+{
+    TCHAR* path = getInstalledWebKitDirectory();
+    if (!path) {
+        LOG_ERROR(TEXT("Couldn't determine installed Safari path\n"));
+        return 1;
+    }
+
+    _tprintf(TEXT("%s"), path);
+    free(path);
+    return 0;
+}
diff --git a/WebKitTools/FindSafari/FindSafari.vcproj b/WebKitTools/FindSafari/FindSafari.vcproj
new file mode 100644 (file)
index 0000000..7eed459
--- /dev/null
@@ -0,0 +1,190 @@
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="8.00"\r
+       Name="FindSafari"\r
+       ProjectGUID="{DA31DA52-6675-48D4-89E0-333A7144397C}"\r
+       RootNamespace="FindSafari"\r
+       >\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"\r
+               />\r
+       </Platforms>\r
+       <ToolFiles>\r
+       </ToolFiles>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory="$(WebKitOutputDir)\bin"\r
+                       IntermediateDirectory="$(WebKitOutputDir)\obj\$(ProjectName)\$(ConfigurationName)"\r
+                       ConfigurationType="1"\r
+                       CharacterSet="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="3"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="4"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               AdditionalDependencies="shlwapi.lib"\r
+                               GenerateDebugInformation="true"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="$(WebKitOutputDir)\bin"\r
+                       IntermediateDirectory="$(WebKitOutputDir)\obj\$(ProjectName)\$(ConfigurationName)"\r
+                       ConfigurationType="1"\r
+                       CharacterSet="1"\r
+                       WholeProgramOptimization="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               RuntimeLibrary="2"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               AdditionalDependencies="shlwapi.lib"\r
+                               GenerateDebugInformation="true"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+       </Configurations>\r
+       <References>\r
+       </References>\r
+       <Files>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"\r
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
+                       >\r
+                       <File\r
+                               RelativePath=".\FindSafari.cpp"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Header Files"\r
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"\r
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"\r
+                       >\r
+               </Filter>\r
+               <Filter\r
+                       Name="Resource Files"\r
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"\r
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"\r
+                       >\r
+               </Filter>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
index 6e3eff911e2585ae1b35200a0a9d724bf811e565..ab0a26a2160eb2602a55516256ce87e2c52e8801 100644 (file)
@@ -290,6 +290,31 @@ sub setConfiguration
     $configuration = $passedConfiguration if $passedConfiguration;
 }
 
+sub safariPathFromSafariBundle
+{
+    my ($safariBundle) = @_;
+
+    return "$safariBundle/Contents/MacOS/Safari" if isOSX();
+    return $safariBundle if isCygwin();
+}
+
+sub installedSafariPath
+{
+    my $safariBundle;
+
+    if (isOSX()) {
+        $safariBundle = "/Applications/Safari.app";
+    } elsif (isCygwin()) {
+        $safariBundle = `"$configurationProductDir/FindSafari.exe"`;
+        $safariBundle =~ s/[\r\n]+$//;
+        $safariBundle = `cygpath -u '$safariBundle'`;
+        $safariBundle =~ s/[\r\n]+$//;
+        $safariBundle .= "Safari.exe";
+    }
+
+    return safariPathFromSafariBundle($safariBundle);
+}
+
 # Locate Safari.
 sub safariPath
 {
@@ -303,21 +328,10 @@ sub safariPath
         } elsif (isCygwin() && -x "$configurationProductDir/bin/Safari.exe") {
             $safariBundle = "$configurationProductDir/bin/Safari.exe";
         } else {
-            # Otherwise use the installed Safari
-            if (isOSX()) {
-                $safariBundle = "/Applications/Safari.app";
-            } elsif (isCygwin()) {
-                chomp(my $programFiles = `cygpath -u '$ENV{"PROGRAMFILES"}'`);
-                $safariBundle = "$programFiles/Safari/Safari.exe";
-            }
+            return installedSafariPath();
         }
     }
-    my $safariPath;
-    if (isOSX()) {
-        $safariPath = "$safariBundle/Contents/MacOS/Safari";
-    } elsif (isCygwin()) {
-        $safariPath = $safariBundle;
-    }
+    my $safariPath = safariPathFromSafariBundle($safariBundle);
     die "Can't find executable at $safariPath.\n" if isOSX() && !-x $safariPath;
     return $safariPath;
 }