Title: [135217] trunk/Source/WebCore
Revision
135217
Author
[email protected]
Date
2012-11-19 17:35:57 -0800 (Mon, 19 Nov 2012)

Log Message

[WIN] Add WebCore::getRegistryValue()
https://bugs.webkit.org/show_bug.cgi?id=97828

Reviewed by Brent Fulgham.

The new function adds an abstraction to SHGetValue(), which isn't available on WinCE.
Changing the existing files allows us to share more code between WinCE and WinNT in a next step.

* platform/win/MIMETypeRegistryWin.cpp:
(WebCore::mimeTypeForExtension):
(WebCore):
(WebCore::MIMETypeRegistry::getPreferredExtensionForMIMEType):
* platform/win/WindowsExtras.h:
(WebCore::getRegistryValue):
(WebCore):
* plugins/win/PluginDatabaseWin.cpp:
(WebCore::addPluginPathsFromRegistry):
(WebCore::addWindowsMediaPlayerPluginDirectory):
(WebCore::addQuickTimePluginDirectory):
(WebCore::addAdobeAcrobatPluginDirectory):
(WebCore::addJavaPluginDirectory):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (135216 => 135217)


--- trunk/Source/WebCore/ChangeLog	2012-11-20 01:22:16 UTC (rev 135216)
+++ trunk/Source/WebCore/ChangeLog	2012-11-20 01:35:57 UTC (rev 135217)
@@ -1,3 +1,27 @@
+2012-11-19  Patrick Gansterer  <[email protected]>
+
+        [WIN] Add WebCore::getRegistryValue()
+        https://bugs.webkit.org/show_bug.cgi?id=97828
+
+        Reviewed by Brent Fulgham.
+
+        The new function adds an abstraction to SHGetValue(), which isn't available on WinCE.
+        Changing the existing files allows us to share more code between WinCE and WinNT in a next step.
+
+        * platform/win/MIMETypeRegistryWin.cpp:
+        (WebCore::mimeTypeForExtension):
+        (WebCore):
+        (WebCore::MIMETypeRegistry::getPreferredExtensionForMIMEType):
+        * platform/win/WindowsExtras.h:
+        (WebCore::getRegistryValue):
+        (WebCore):
+        * plugins/win/PluginDatabaseWin.cpp:
+        (WebCore::addPluginPathsFromRegistry):
+        (WebCore::addWindowsMediaPlayerPluginDirectory):
+        (WebCore::addQuickTimePluginDirectory):
+        (WebCore::addAdobeAcrobatPluginDirectory):
+        (WebCore::addJavaPluginDirectory):
+
 2012-11-19  Alpha Lam  <[email protected]>
 
         Not reviewed. Build fix for Chromium.

Modified: trunk/Source/WebCore/platform/win/MIMETypeRegistryWin.cpp (135216 => 135217)


--- trunk/Source/WebCore/platform/win/MIMETypeRegistryWin.cpp	2012-11-20 01:22:16 UTC (rev 135216)
+++ trunk/Source/WebCore/platform/win/MIMETypeRegistryWin.cpp	2012-11-20 01:35:57 UTC (rev 135217)
@@ -26,13 +26,12 @@
 #include "config.h"
 #include "MIMETypeRegistry.h"
 
-#include <shlwapi.h>
+#include "WindowsExtras.h"
 #include <wtf/Assertions.h>
 #include <wtf/HashMap.h>
 #include <wtf/MainThread.h>
 
-namespace WebCore 
-{
+namespace WebCore {
 
 static String mimeTypeForExtension(const String& extension)
 {
@@ -41,14 +40,14 @@
     DWORD contentTypeStrLen = sizeof(contentTypeStr);
     DWORD keyType;
 
-    HRESULT result = SHGetValue(HKEY_CLASSES_ROOT, ext.charactersWithNullTermination(), L"Content Type", &keyType, (LPVOID)contentTypeStr, &contentTypeStrLen);
+    HRESULT result = getRegistryValue(HKEY_CLASSES_ROOT, ext.charactersWithNullTermination(), L"Content Type", &keyType, contentTypeStr, &contentTypeStrLen);
 
-    if (result == ERROR_SUCCESS && keyType == REG_SZ) 
+    if (result == ERROR_SUCCESS && keyType == REG_SZ)
         return String(contentTypeStr, contentTypeStrLen / sizeof(contentTypeStr[0]) - 1);
 
     return String();
 }
-   
+
 String MIMETypeRegistry::getPreferredExtensionForMIMEType(const String& type)
 {
     String path = "MIME\\Database\\Content Type\\" + type;
@@ -56,9 +55,9 @@
     DWORD extStrLen = sizeof(extStr);
     DWORD keyType;
 
-    HRESULT result = SHGetValueW(HKEY_CLASSES_ROOT, path.charactersWithNullTermination(), L"Extension", &keyType, (LPVOID)extStr, &extStrLen);
+    HRESULT result = getRegistryValue(HKEY_CLASSES_ROOT, path.charactersWithNullTermination(), L"Extension", &keyType, extStr, &extStrLen);
 
-    if (result == ERROR_SUCCESS && keyType == REG_SZ) 
+    if (result == ERROR_SUCCESS && keyType == REG_SZ)
         return String(extStr + 1, extStrLen / sizeof(extStr[0]) - 2);
 
     return String();

Modified: trunk/Source/WebCore/platform/win/WindowsExtras.h (135216 => 135217)


--- trunk/Source/WebCore/platform/win/WindowsExtras.h	2012-11-20 01:22:16 UTC (rev 135216)
+++ trunk/Source/WebCore/platform/win/WindowsExtras.h	2012-11-20 01:35:57 UTC (rev 135217)
@@ -25,6 +25,7 @@
 #ifndef WindowsExtras_h
 #define WindowsExtras_h
 
+#include <shlwapi.h>
 #include <windows.h>
 
 namespace WebCore {
@@ -33,6 +34,20 @@
 const HWND HWND_MESSAGE = 0;
 #endif
 
+inline HRESULT getRegistryValue(HKEY hkey, LPCWSTR pszSubKey, LPCWSTR pszValue, LPDWORD pdwType, LPVOID pvData, LPDWORD pcbData)
+{
+#if OS(WINCE)
+    HKEY key;
+    if (::RegOpenKeyExW(hkey, pszSubKey, 0, 0, &key) != ERROR_SUCCESS)
+        return ERROR_INVALID_NAME;
+    HRESULT result = ::RegQueryValueExW(key, pszValue, 0, pdwType, static_cast<LPBYTE>(pvData), pcbData);
+    ::RegCloseKey(key);
+    return result;
+#else
+    return ::SHGetValueW(hkey, pszSubKey, pszValue, pdwType, pvData, pcbData);
+#endif
+}
+
 inline void* getWindowPointer(HWND hWnd, int index)
 {
 #if OS(WINCE)

Modified: trunk/Source/WebCore/plugins/win/PluginDatabaseWin.cpp (135216 => 135217)


--- trunk/Source/WebCore/plugins/win/PluginDatabaseWin.cpp	2012-11-20 01:22:16 UTC (rev 135216)
+++ trunk/Source/WebCore/plugins/win/PluginDatabaseWin.cpp	2012-11-20 01:35:57 UTC (rev 135217)
@@ -31,8 +31,7 @@
 #include "Frame.h"
 #include "KURL.h"
 #include "PluginPackage.h"
-#include <windows.h>
-#include <shlwapi.h>
+#include "WindowsExtras.h"
 
 #if OS(WINCE)
 // WINCE doesn't support Registry Key Access Rights. The parameter should always be 0
@@ -40,17 +39,6 @@
 #define KEY_ENUMERATE_SUB_KEYS 0
 #endif
 
-DWORD SHGetValue(HKEY hkey, LPCWSTR pszSubKey, LPCWSTR pszValue, LPDWORD pdwType, LPVOID pvData, LPDWORD pcbData)
-{
-    HKEY key;
-    if (RegOpenKeyEx(hkey, pszSubKey, 0, 0, &key) == ERROR_SUCCESS) {
-        DWORD result = RegQueryValueEx(key, pszValue, 0, pdwType, (LPBYTE)pvData, pcbData);
-        RegCloseKey(key);
-        return result;
-    }
-    return ERROR_INVALID_NAME;
-}
-
 BOOL PathRemoveFileSpec(LPWSTR moduleFileNameStr)
 {
     if (!*moduleFileNameStr)
@@ -102,7 +90,7 @@
         DWORD pathStrSize = sizeof(pathStr);
         DWORD type;
 
-        result = SHGetValue(key, name, TEXT("Path"), &type, (LPBYTE)pathStr, &pathStrSize);
+        result = getRegistryValue(key, name, L"Path", &type, pathStr, &pathStrSize);
         if (result != ERROR_SUCCESS || type != REG_SZ)
             continue;
 
@@ -263,7 +251,7 @@
     WCHAR installationDirectoryStr[_MAX_PATH];
     DWORD installationDirectorySize = sizeof(installationDirectoryStr);
 
-    HRESULT result = SHGetValue(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\MediaPlayer"), TEXT("Installation Directory"), &type, (LPBYTE)&installationDirectoryStr, &installationDirectorySize);
+    HRESULT result = getRegistryValue(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\MediaPlayer", L"Installation Directory", &type, &installationDirectoryStr, &installationDirectorySize);
 
     if (result == ERROR_SUCCESS && type == REG_SZ)
         directories.append(String(installationDirectoryStr, installationDirectorySize / sizeof(WCHAR) - 1));
@@ -275,7 +263,7 @@
     WCHAR installationDirectoryStr[_MAX_PATH];
     DWORD installationDirectorySize = sizeof(installationDirectoryStr);
 
-    HRESULT result = SHGetValue(HKEY_LOCAL_MACHINE, TEXT("Software\\Apple Computer, Inc.\\QuickTime"), TEXT("InstallDir"), &type, (LPBYTE)&installationDirectoryStr, &installationDirectorySize);
+    HRESULT result = getRegistryValue(HKEY_LOCAL_MACHINE, L"Software\\Apple Computer, Inc.\\QuickTime", L"InstallDir", &type, &installationDirectoryStr, &installationDirectorySize);
 
     if (result == ERROR_SUCCESS && type == REG_SZ) {
         String pluginDir = String(installationDirectoryStr, installationDirectorySize / sizeof(WCHAR) - 1) + "\\plugins";
@@ -317,7 +305,7 @@
         DWORD acrobatInstallPathSize = sizeof(acrobatInstallPathStr);
 
         String acrobatPluginKeyPath = "Software\\Adobe\\Acrobat Reader\\" + latestAcrobatVersionString + "\\InstallPath";
-        result = SHGetValue(HKEY_LOCAL_MACHINE, acrobatPluginKeyPath.charactersWithNullTermination(), 0, &type, (LPBYTE)acrobatInstallPathStr, &acrobatInstallPathSize);
+        result = getRegistryValue(HKEY_LOCAL_MACHINE, acrobatPluginKeyPath.charactersWithNullTermination(), 0, &type, acrobatInstallPathStr, &acrobatInstallPathSize);
 
         if (result == ERROR_SUCCESS) {
             String acrobatPluginDirectory = String(acrobatInstallPathStr, acrobatInstallPathSize / sizeof(WCHAR) - 1) + "\\browser";
@@ -364,10 +352,10 @@
         DWORD useNewPluginSize;
 
         String javaPluginKeyPath = "Software\\JavaSoft\\Java Plug-in\\" + latestJavaVersionString;
-        result = SHGetValue(HKEY_LOCAL_MACHINE, javaPluginKeyPath.charactersWithNullTermination(), TEXT("UseNewJavaPlugin"), &type, (LPVOID)&useNewPluginValue, &useNewPluginSize);
+        result = getRegistryValue(HKEY_LOCAL_MACHINE, javaPluginKeyPath.charactersWithNullTermination(), L"UseNewJavaPlugin", &type, &useNewPluginValue, &useNewPluginSize);
 
         if (result == ERROR_SUCCESS && useNewPluginValue == 1) {
-            result = SHGetValue(HKEY_LOCAL_MACHINE, javaPluginKeyPath.charactersWithNullTermination(), TEXT("JavaHome"), &type, (LPBYTE)javaInstallPathStr, &javaInstallPathSize);
+            result = getRegistryValue(HKEY_LOCAL_MACHINE, javaPluginKeyPath.charactersWithNullTermination(), L"JavaHome", &type, javaInstallPathStr, &javaInstallPathSize);
             if (result == ERROR_SUCCESS) {
                 String javaPluginDirectory = String(javaInstallPathStr, javaInstallPathSize / sizeof(WCHAR) - 1) + "\\bin\\new_plugin";
                 directories.append(javaPluginDirectory);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to