Source/WebCore: Export KURL::baseAsString() so it can be called in WebProcessProxy...
authoradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Oct 2011 17:55:31 +0000 (17:55 +0000)
committeradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Oct 2011 17:55:31 +0000 (17:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=70168

Reviewed by Alexey Proskuryakov.

No new tests. There is no change in functionality.

* WebCore.exp.in: Export KURL::baseAsString().

Source/WebKit2: Calling WKPageLoadAlternateHTMLString() where baseURL does not point to a directory causes an invalid message to be returned from WebProcess
https://bugs.webkit.org/show_bug.cgi?id=70168

Reviewed by Alexey Proskuryakov.

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::assumeReadAccessToBaseURL): Add the file path of url's base URL to m_localPathsWithAssumedReadAccess,
since url may not point to a directory.

Tools: Add a test to call WKPageLoadAlternateHTMLString() with a non-directory URL.
https://bugs.webkit.org/show_bug.cgi?id=70168

Reviewed by Alexey Proskuryakov.

* TestWebKitAPI/Tests/WebKit2/LoadAlternateHTMLStringWithNonDirectoryURL.cpp: Added.
(TestWebKitAPI::didFinishLoadForFrame):
(TestWebKitAPI::TEST): Call WKPageLoadAlternateHTMLString() with a file URL and make sure it finishes loading.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/win/TestWebKitAPI.vcproj:
Add the new file.

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

Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/WebProcessProxy.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2/LoadAlternateHTMLStringWithNonDirectoryURL.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj

index f5fafe4..5f9ab9d 100644 (file)
@@ -1,3 +1,14 @@
+2011-10-17  Ada Chan  <adachan@apple.com>
+
+        Export KURL::baseAsString() so it can be called in WebProcessProxy::assumeReadAccessToBaseURL() in WebKit2.
+        https://bugs.webkit.org/show_bug.cgi?id=70168
+
+        Reviewed by Alexey Proskuryakov.
+
+        No new tests. There is no change in functionality.
+
+        * WebCore.exp.in: Export KURL::baseAsString().
+
 2011-10-17  Ryosuke Niwa  <rniwa@webkit.org>
 
         Touch Internals.cpp to make 64-bit GTK+ build happy.
index e8fd5fd..54b4532 100644 (file)
@@ -1285,6 +1285,7 @@ __ZNK7WebCore4Font8drawTextEPNS_15GraphicsContextERKNS_7TextRunERKNS_10FloatPoin
 __ZNK7WebCore4KURL10protocolIsEPKc
 __ZNK7WebCore4KURL11createCFURLEv
 __ZNK7WebCore4KURL11isLocalFileEv
+__ZNK7WebCore4KURL12baseAsStringEv
 __ZNK7WebCore4KURL14fileSystemPathEv
 __ZNK7WebCore4KURL17lastPathComponentEv
 __ZNK7WebCore4KURL4hostEv
index 4c39810..045cc33 100644 (file)
@@ -1,3 +1,14 @@
+2011-10-17  Ada Chan  <adachan@apple.com>
+
+        Calling WKPageLoadAlternateHTMLString() where baseURL does not point to a directory causes an invalid message to be returned from WebProcess
+        https://bugs.webkit.org/show_bug.cgi?id=70168
+
+        Reviewed by Alexey Proskuryakov.
+
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::assumeReadAccessToBaseURL): Add the file path of url's base URL to m_localPathsWithAssumedReadAccess,
+        since url may not point to a directory.
+
 2011-10-17  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Add methods to get/set a custom text enconding to WebKit2 GTK+ API
index de89db4..26490cc 100644 (file)
@@ -209,9 +209,13 @@ void WebProcessProxy::assumeReadAccessToBaseURL(const String& urlString)
     if (!url.isLocalFile())
         return;
 
+    // There's a chance that urlString does not point to a directory.
+    // Get url's base URL to add to m_localPathsWithAssumedReadAccess.
+    KURL baseURL(KURL(), url.baseAsString());
+    
     // Client loads an alternate string. This doesn't grant universal file read, but the web process is assumed
     // to have read access to this directory already.
-    m_localPathsWithAssumedReadAccess.add(url.fileSystemPath());
+    m_localPathsWithAssumedReadAccess.add(baseURL.fileSystemPath());
 }
 
 bool WebProcessProxy::checkURLReceivedFromWebProcess(const String& urlString)
index cd7ed91..062712d 100644 (file)
@@ -1,3 +1,18 @@
+2011-10-17  Ada Chan  <adachan@apple.com>
+
+        Add a test to call WKPageLoadAlternateHTMLString() with a non-directory URL.
+        https://bugs.webkit.org/show_bug.cgi?id=70168
+
+        Reviewed by Alexey Proskuryakov.
+
+        * TestWebKitAPI/Tests/WebKit2/LoadAlternateHTMLStringWithNonDirectoryURL.cpp: Added.
+        (TestWebKitAPI::didFinishLoadForFrame):
+        (TestWebKitAPI::TEST): Call WKPageLoadAlternateHTMLString() with a file URL and make sure it finishes loading.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/win/TestWebKitAPI.vcproj:
+        Add the new file.
+
 2011-10-17  Darin Adler  <darin@apple.com>
 
         Add some more *.pyc ignores in directories with Python scripts.
index e74ca57..80fe5bb 100644 (file)
@@ -31,6 +31,7 @@
                4BFDFFA9131477770061F24B /* HitTestResultNodeHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFDFFA8131477770061F24B /* HitTestResultNodeHandle.cpp */; };
                520BCF4C141EB09E00937EA8 /* WebArchive_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */; };
                520BCF4D141EB09E00937EA8 /* WebArchive.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 520BCF4B141EB09E00937EA8 /* WebArchive.cpp */; };
+               52CB47411448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52CB47401448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp */; };
                81B50193140F232300D9EB58 /* StringBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 81B50192140F232300D9EB58 /* StringBuilder.cpp */; };
                939BA91714103412001A01BD /* DeviceScaleFactorOnBack.mm in Sources */ = {isa = PBXBuildFile; fileRef = 939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */; };
                A7A966DB140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */; };
                4BFDFFA8131477770061F24B /* HitTestResultNodeHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HitTestResultNodeHandle.cpp; sourceTree = "<group>"; };
                520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebArchive_Bundle.cpp; sourceTree = "<group>"; };
                520BCF4B141EB09E00937EA8 /* WebArchive.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebArchive.cpp; sourceTree = "<group>"; };
+               52CB47401448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoadAlternateHTMLStringWithNonDirectoryURL.cpp; sourceTree = "<group>"; };
                81B50192140F232300D9EB58 /* StringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringBuilder.cpp; path = WTF/StringBuilder.cpp; sourceTree = "<group>"; };
                8DD76FA10486AA7600D96B5E /* TestWebKitAPI */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = TestWebKitAPI; sourceTree = BUILT_PRODUCTS_DIR; };
                939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeviceScaleFactorOnBack.mm; sourceTree = "<group>"; };
                                4BFDFFA61314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp */,
                                BC575AAC126E83B9006F0F12 /* InjectedBundleBasic.cpp */,
                                BC575AAF126E83C8006F0F12 /* InjectedBundleBasic_Bundle.cpp */,
+                               52CB47401448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp */,
                                33DC8910141953A300747EF7 /* LoadCanceledNoServerRedirectCallback.cpp */,
                                33DC89131419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp */,
                                33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */,
                                520BCF4D141EB09E00937EA8 /* WebArchive.cpp in Sources */,
                                F6FDDDD314241AD4004F1729 /* PrivateBrowsingPushStateNoHistoryCallback.cpp in Sources */,
                                C0991C51143C7D68007998F2 /* RetainPtrHashing.cpp in Sources */,
+                               52CB47411448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/LoadAlternateHTMLStringWithNonDirectoryURL.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/LoadAlternateHTMLStringWithNonDirectoryURL.cpp
new file mode 100644 (file)
index 0000000..7878741
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2011 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. 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 INC. 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 "config.h"
+#include "JavaScriptTest.h"
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+
+#include <WebKit2/WKContext.h>
+#include <WebKit2/WKPage.h>
+#include <WebKit2/WKRetainPtr.h>
+
+namespace TestWebKitAPI {
+    
+static bool didFinishLoad = false;
+    
+static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
+{
+    didFinishLoad = true;
+}
+
+TEST(WebKit2, LoadAlternateHTMLStringWithNonDirectoryURL)
+{
+    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
+    PlatformWebView webView(context.get());
+
+    WKPageLoaderClient loaderClient;
+    memset(&loaderClient, 0, sizeof(loaderClient));
+    
+    loaderClient.version = 0;
+    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
+    WKPageSetPageLoaderClient(webView.page(), &loaderClient);
+
+    WKRetainPtr<WKURLRef> fileURL(AdoptWK, Util::createURLForResource("simple", "html"));
+    WKRetainPtr<WKStringRef> alternateHTMLString(AdoptWK, WKStringCreateWithUTF8CString("<html><body><img src='icon.png'></body></html>"));
+    
+    // Call WKPageLoadAlternateHTMLString() with fileURL which does not point to a directory
+    WKPageLoadAlternateHTMLString(webView.page(), alternateHTMLString.get(), fileURL.get(), fileURL.get());
+    
+    // If we can finish loading the html without resulting in an invalid message being sent from the WebProcess, this test passes.
+    Util::run(&didFinishLoad);
+}
+
+} // namespace TestWebKitAPI
index 7d1fb8e..50ec080 100644 (file)
                                        >
                                </File>
                                <File
+                                       RelativePath="..\Tests\WebKit2\LoadAlternateHTMLStringWithNonDirectoryURL.cpp"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\Tests\WebKit2\LoadCanceledNoServerRedirectCallback.cpp"
                                        >
                                </File>