WebKitTools:
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Nov 2007 19:53:25 +0000 (19:53 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Nov 2007 19:53:25 +0000 (19:53 +0000)
        Reviewed by Adam.

        <rdar://problem/5132005>
        setUserStyleSheetEnabled is not fully implemented in Windows DRT.

        * DumpRenderTree/win/DumpRenderTree.vcproj:
        Add shlwapi.lib

        * DumpRenderTree/win/LayoutTestControllerWin.cpp:
        (LayoutTestController::setUserStyleSheetEnabled):
        Implement this.

        (appendComponentToPath):
        New method which wraps the Win32 API PathAppend.

        (followShortcuts):
        New method which checks if a file points to a shortcut and
        follows the shortcut.

        (resolveCygwinPath):
        New method that takes a cygwin unix-style path and returns the Win32 path.

        (cfStringRefToWString):

        (LayoutTestController::setUserStyleSheetLocation):
        Implement this.

LayoutTests:

        Reviewed by Adam.

        <rdar://problem/5132005>
        setUserStyleSheetEnabled is not fully implemented in Windows DRT.

        * platform/win/Skipped:

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

LayoutTests/ChangeLog
LayoutTests/platform/win/Skipped
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/win/DumpRenderTree.vcproj
WebKitTools/DumpRenderTree/win/LayoutTestControllerWin.cpp

index 37fbae3dc8f4cfc05056c448c0ec2dfe7d9ac67f..dd866099557605b3e5e42b55ec3ee0ea53735e1f 100644 (file)
@@ -1,3 +1,12 @@
+2007-11-29  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Adam.
+
+        <rdar://problem/5132005>
+        setUserStyleSheetEnabled is not fully implemented in Windows DRT.
+        
+        * platform/win/Skipped:
+
 2007-11-28  Mark Rowe  <mrowe@apple.com>
 
         Unreviewed layout test fix.  Fix typos in the name of four files used by HTTP layout tests.
index c546f720d42c0581274c979d4a4f2f7879230f62..40ac89e7ddc5f3a0569970210c291cc01da68e63 100644 (file)
@@ -269,9 +269,7 @@ http/tests/security/javascriptURL/xss-DENIED-to-javascript-url-in-foreign-domain
 # DRT is not fully implemented in boomer <rdar://problem/5128261>
 fast/dom/Window/setting-properties-on-closed-window.html
 fast/events/objc-event-api.html
-fast/loader/user-style-sheet-resource-load-callbacks.html
 http/tests/misc/window-dot-stop.html
-http/tests/security/local-user-CSS-from-remote.html
 http/tests/xmlhttprequest/abort-should-cancel-load.html
 svg/custom/use-events-crash.svg
 
index 303fbccebd517ea7344309dd4a191edd89e066f9..05e0ff834821c1a5c7dd66bf2430d10472aab778 100644 (file)
@@ -1,3 +1,32 @@
+2007-11-29  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Adam.
+
+        <rdar://problem/5132005>
+        setUserStyleSheetEnabled is not fully implemented in Windows DRT.
+        
+        * DumpRenderTree/win/DumpRenderTree.vcproj:
+        Add shlwapi.lib
+        
+        * DumpRenderTree/win/LayoutTestControllerWin.cpp:
+        (LayoutTestController::setUserStyleSheetEnabled):
+        Implement this.
+        
+        (appendComponentToPath):
+        New method which wraps the Win32 API PathAppend.
+        
+        (followShortcuts):
+        New method which checks if a file points to a shortcut and
+        follows the shortcut.
+        
+        (resolveCygwinPath):
+        New method that takes a cygwin unix-style path and returns the Win32 path.
+        
+        (cfStringRefToWString):
+        
+        (LayoutTestController::setUserStyleSheetLocation):
+        Implement this.
+
 2007-11-29  Alice Liu  <alice.liu@apple.com>
 
         Reviewed by Adam.
index b587a3742463ceaf9d4afa2aeb3b3c028c8a28fb..696916b02e338b155a37009c0a1c9ab90e20a7d8 100644 (file)
                        />\r
                        <Tool\r
                                Name="VCLinkerTool"\r
-                               AdditionalDependencies="WebKitGUID$(WebKitConfigSuffix).lib WebKit$(WebKitDLLConfigSuffix).lib WTF$(WebKitConfigSuffix).lib CoreGraphics$(LibraryConfigSuffix).lib CoreFoundation$(LibraryConfigSuffix).lib pthreadVC2$(LibraryConfigSuffix).lib gdi32.lib ole32.lib oleaut32.lib user32.lib"\r
+                               AdditionalDependencies="WebKitGUID$(WebKitConfigSuffix).lib WebKit$(WebKitDLLConfigSuffix).lib WTF$(WebKitConfigSuffix).lib CoreGraphics$(LibraryConfigSuffix).lib CoreFoundation$(LibraryConfigSuffix).lib pthreadVC2$(LibraryConfigSuffix).lib gdi32.lib ole32.lib oleaut32.lib user32.lib shlwapi.lib"\r
                                OutputFile="$(OutDir)\$(ProjectName)$(WebKitConfigSuffix).exe"\r
                                LinkIncremental="2"\r
                                AdditionalLibraryDirectories="&quot;$(WebKitOutputDir)\lib&quot;;&quot;$(WebKitLibrariesDir)\lib&quot;;&quot;$(WebKitOutputDir)\bin&quot;"\r
index 9e6e70faac9625633bf69e9eeae07988b81015b0..d9da808ba73261f996189fb4cf67a6f4f5ee5708 100644 (file)
@@ -45,6 +45,9 @@
 #include <WebKit/WebKit.h>
 #include <string>
 #include <CoreFoundation/CoreFoundation.h>
+#include <shlwapi.h>
+#include <shlguid.h>
+#include <shobjidl.h>
 
 using std::string;
 using std::wstring;
@@ -274,12 +277,161 @@ void LayoutTestController::setUseDashboardCompatibilityMode(bool flag)
 
 void LayoutTestController::setUserStyleSheetEnabled(bool flag)
 {
-    // FIXME: Implement!
+    COMPtr<IWebView> webView;
+    if (FAILED(frame->webView(&webView)))
+        return;
+
+    COMPtr<IWebPreferences> preferences;
+    if (FAILED(webView->preferences(&preferences)))
+        return;
+
+   preferences->setUserStyleSheetEnabled(flag);
 }
 
-void LayoutTestController::setUserStyleSheetLocation(JSStringRef path)
+bool appendComponentToPath(wstring& path, const wstring& component)
 {
-    // FIXME: Implement!
+    WCHAR buffer[MAX_PATH];
+
+    if (path.size() + 1 > MAX_PATH)
+        return false;
+
+    memcpy(buffer, path.data(), path.size() * sizeof(WCHAR));
+    buffer[path.size()] = '\0';
+
+    if (!PathAppendW(buffer, component.c_str()))
+        return false;
+
+    path = wstring(buffer);
+    return true;
+}
+
+static bool followShortcuts(wstring& path)
+{
+    if (PathFileExists(path.c_str()))
+        return true;
+
+    // Do we have a shortcut?
+    path.append(TEXT(".lnk"));
+    if (!PathFileExists(path.c_str()))
+       return false;
+
+    // We have a shortcut, find its target.
+    COMPtr<IShellLink> shortcut(Create, CLSID_ShellLink);
+    if (!shortcut)
+       return false;
+    COMPtr<IPersistFile> persistFile(Query, shortcut);
+    if (!shortcut)
+        return false;
+    if (FAILED(persistFile->Load(path.c_str(), STGM_READ)))
+        return false;
+    if (FAILED(shortcut->Resolve(0, 0)))
+        return false;
+    WCHAR targetPath[MAX_PATH];
+    DWORD targetPathLen = _countof(targetPath);
+    if (FAILED(shortcut->GetPath(targetPath, targetPathLen, 0, 0)))
+        return false;
+    if (!PathFileExists(targetPath))
+        return false;
+    // Use the target path as the result path instead.
+    path = wstring(targetPath);
+
+    return true;
+}
+
+static bool resolveCygwinPath(const wstring& cygwinPath, wstring& windowsPath)
+{
+    if (cygwinPath[0] != '/')
+        return false;
+
+    // Get the Root path.
+    WCHAR rootPath[MAX_PATH];
+    DWORD rootPathSize = _countof(rootPath);
+    DWORD keyType;
+    DWORD result = ::SHGetValueW(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2\\/"), TEXT("native"), &keyType, &rootPath, &rootPathSize);
+    
+    if (result != ERROR_SUCCESS || keyType != REG_SZ)
+        return false;
+
+    windowsPath = wstring(rootPath, rootPathSize);
+
+    int oldPos = 1;
+    while (1) {
+        int newPos = cygwinPath.find('/', oldPos);
+
+        if (newPos == -1) {
+            wstring pathComponent = cygwinPath.substr(oldPos);
+
+            if (!appendComponentToPath(windowsPath, pathComponent))
+               return false;
+
+            if (!followShortcuts(windowsPath))
+                return false;
+
+            break;
+        }
+
+        wstring pathComponent = cygwinPath.substr(oldPos, newPos - oldPos);
+        if (!appendComponentToPath(windowsPath, pathComponent))
+            return false;
+
+        if (!followShortcuts(windowsPath))
+            return false;
+
+        oldPos = newPos + 1;
+    }
+    return true;
+}
+
+static wstring cfStringRefToWString(CFStringRef cfStr)
+{
+    Vector<wchar_t> v(CFStringGetLength(cfStr));
+    CFStringGetCharacters(cfStr, CFRangeMake(0, CFStringGetLength(cfStr)), (UniChar *)v.data());
+
+    return wstring(v.data(), v.size());
+}
+
+void LayoutTestController::setUserStyleSheetLocation(JSStringRef jsURL)
+{
+    COMPtr<IWebView> webView;
+    if (FAILED(frame->webView(&webView)))
+        return;
+
+    COMPtr<IWebPreferences> preferences;
+    if (FAILED(webView->preferences(&preferences)))
+        return;
+
+    RetainPtr<CFStringRef> urlString(AdoptCF, JSStringCopyCFString(0, jsURL));
+    RetainPtr<CFURLRef> url(AdoptCF, CFURLCreateWithString(0, urlString.get(), 0));
+    if (!url)
+        return;
+
+    // Now copy the file system path, POSIX style.
+    RetainPtr<CFStringRef> pathCF(AdoptCF, CFURLCopyFileSystemPath(url.get(), kCFURLPOSIXPathStyle));
+    if (!pathCF)
+        return;
+
+    wstring path = cfStringRefToWString(pathCF.get());
+
+    wstring resultPath;
+    if (!resolveCygwinPath(path, resultPath))
+        return;
+
+    // The path has been resolved, now convert it back to a CFURL.
+    int result = WideCharToMultiByte(CP_UTF8, 0, resultPath.c_str(), resultPath.size() + 1, 0, 0, 0, 0);
+    Vector<char> utf8Vector(result);
+    result = WideCharToMultiByte(CP_UTF8, 0, resultPath.c_str(), resultPath.size() + 1, utf8Vector.data(), result, 0, 0);
+    if (!result)
+        return;
+
+    url = CFURLCreateFromFileSystemRepresentation(0, (const UInt8*)utf8Vector.data(), utf8Vector.size() - 1, false);
+    if (!url)
+        return;
+
+    resultPath = cfStringRefToWString(CFURLGetString(url.get()));
+
+    BSTR resultPathBSTR = SysAllocStringLen(resultPath.data(), resultPath.size());
+    preferences->setUserStyleSheetLocation(resultPathBSTR);
+    SysFreeString(resultPathBSTR);
 }
 
 void LayoutTestController::setWindowIsKey(bool flag)