Title: [242468] trunk
Revision
242468
Author
beid...@apple.com
Date
2019-03-05 09:20:36 -0800 (Tue, 05 Mar 2019)

Log Message

Correctly handle sandbox extensions when the same WKWebView loads multiple file:// URLs.
<rdar://problem/47820581> and https://bugs.webkit.org/show_bug.cgi?id=195291

Reviewed by Tim Horton.

Source/WebKit:

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::SandboxExtensionTracker::shouldReuseCommittedSandboxExtension): If there is a pendingProvisionalSandboxExtension
  then its existence should override our willingness to reuse the existing committed extension.
(WebKit::shouldReuseCommittedSandboxExtension): Deleted.
* WebProcess/WebPage/WebPage.h:

Tools:

Loading a file: URL into a WKWebView and then loading another file: url from a completely
different directory into that same WKWebView should work.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/LoadFileURL.mm: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (242467 => 242468)


--- trunk/Source/WebKit/ChangeLog	2019-03-05 17:18:30 UTC (rev 242467)
+++ trunk/Source/WebKit/ChangeLog	2019-03-05 17:20:36 UTC (rev 242468)
@@ -1,3 +1,16 @@
+2019-03-05  Brady Eidson  <beid...@apple.com>
+
+        Correctly handle sandbox extensions when the same WKWebView loads multiple file:// URLs.
+        <rdar://problem/47820581> and https://bugs.webkit.org/show_bug.cgi?id=195291
+
+        Reviewed by Tim Horton.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::SandboxExtensionTracker::shouldReuseCommittedSandboxExtension): If there is a pendingProvisionalSandboxExtension
+          then its existence should override our willingness to reuse the existing committed extension.
+        (WebKit::shouldReuseCommittedSandboxExtension): Deleted.
+        * WebProcess/WebPage/WebPage.h:
+
 2019-03-05  Ryan Haddad  <ryanhad...@apple.com>
 
         Unreviewed, rolling out r242403.

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (242467 => 242468)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2019-03-05 17:18:30 UTC (rev 242467)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2019-03-05 17:20:36 UTC (rev 242468)
@@ -4396,7 +4396,7 @@
     m_pendingProvisionalSandboxExtension = WTFMove(pendingProvisionalSandboxExtension);
 }
 
-static bool shouldReuseCommittedSandboxExtension(WebFrame* frame)
+bool WebPage::SandboxExtensionTracker::shouldReuseCommittedSandboxExtension(WebFrame* frame)
 {
     ASSERT(frame->isMainFrame());
 
@@ -4407,6 +4407,9 @@
     if (isReload(frameLoadType))
         return true;
 
+    if (m_pendingProvisionalSandboxExtension)
+        return false;
+
     DocumentLoader* documentLoader = frameLoader.documentLoader();
     DocumentLoader* provisionalDocumentLoader = frameLoader.provisionalDocumentLoader();
     if (!documentLoader || !provisionalDocumentLoader)

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (242467 => 242468)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2019-03-05 17:18:30 UTC (rev 242467)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2019-03-05 17:20:36 UTC (rev 242468)
@@ -729,6 +729,7 @@
 
     private:
         void setPendingProvisionalSandboxExtension(RefPtr<SandboxExtension>&&);
+        bool shouldReuseCommittedSandboxExtension(WebFrame*);
 
         RefPtr<SandboxExtension> m_pendingProvisionalSandboxExtension;
         RefPtr<SandboxExtension> m_provisionalSandboxExtension;

Modified: trunk/Tools/ChangeLog (242467 => 242468)


--- trunk/Tools/ChangeLog	2019-03-05 17:18:30 UTC (rev 242467)
+++ trunk/Tools/ChangeLog	2019-03-05 17:20:36 UTC (rev 242468)
@@ -1,3 +1,16 @@
+2019-03-05  Brady Eidson  <beid...@apple.com>
+
+        Correctly handle sandbox extensions when the same WKWebView loads multiple file:// URLs.
+        <rdar://problem/47820581> and https://bugs.webkit.org/show_bug.cgi?id=195291
+
+        Reviewed by Tim Horton.
+
+        Loading a file: URL into a WKWebView and then loading another file: url from a completely
+        different directory into that same WKWebView should work.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/LoadFileURL.mm: Added.
+
 2019-02-28  Ryosuke Niwa  <rn...@webkit.org>
 
         Add WeakHashSet

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (242467 => 242468)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-03-05 17:18:30 UTC (rev 242467)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-03-05 17:20:36 UTC (rev 242468)
@@ -213,6 +213,7 @@
 		5120C83E1E67678F0025B250 /* WebsiteDataStoreCustomPaths.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5120C83B1E674E350025B250 /* WebsiteDataStoreCustomPaths.html */; };
 		512C4C9E20EAA40D004945EA /* ResponsivenessTimerCrash.mm in Sources */ = {isa = PBXBuildFile; fileRef = 512C4C9D20EAA405004945EA /* ResponsivenessTimerCrash.mm */; };
 		51393E221523952D005F39C5 /* DOMWindowExtensionBasic_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51393E1D1523944A005F39C5 /* DOMWindowExtensionBasic_Bundle.cpp */; };
+		51396E1A222E516000A42FCE /* LoadFileURL.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51396E19222E4E8600A42FCE /* LoadFileURL.mm */; };
 		5142B2731517C8C800C32B19 /* ContextMenuCanCopyURL.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5142B2721517C89100C32B19 /* ContextMenuCanCopyURL.html */; };
 		514958BE1F7427AC00E87BAD /* WKWebViewAutofillTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 514958BD1F7427AC00E87BAD /* WKWebViewAutofillTests.mm */; };
 		515BE16F1D428BB100DD7C68 /* StoreBlobToBeDeleted.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 515BE16E1D4288FF00DD7C68 /* StoreBlobToBeDeleted.html */; };
@@ -1586,6 +1587,7 @@
 		512C4C9D20EAA405004945EA /* ResponsivenessTimerCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ResponsivenessTimerCrash.mm; sourceTree = "<group>"; };
 		51393E1D1523944A005F39C5 /* DOMWindowExtensionBasic_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMWindowExtensionBasic_Bundle.cpp; sourceTree = "<group>"; };
 		51393E1E1523944A005F39C5 /* DOMWindowExtensionBasic.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMWindowExtensionBasic.cpp; sourceTree = "<group>"; };
+		51396E19222E4E8600A42FCE /* LoadFileURL.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LoadFileURL.mm; sourceTree = "<group>"; };
 		5142B2701517C88B00C32B19 /* ContextMenuCanCopyURL.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ContextMenuCanCopyURL.mm; sourceTree = "<group>"; };
 		5142B2721517C89100C32B19 /* ContextMenuCanCopyURL.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = ContextMenuCanCopyURL.html; sourceTree = "<group>"; };
 		514958BD1F7427AC00E87BAD /* WKWebViewAutofillTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewAutofillTests.mm; sourceTree = "<group>"; };
@@ -2537,6 +2539,7 @@
 				37D36ED61AF42ECD00BAF5D9 /* LoadAlternateHTMLString.mm */,
 				A125478D1DB18B9400358564 /* LoadDataWithNilMIMEType.mm */,
 				4612C2B8210A6ABF00B788A6 /* LoadFileThenReload.mm */,
+				51396E19222E4E8600A42FCE /* LoadFileURL.mm */,
 				57901FAC1CAF12C200ED64F9 /* LoadInvalidURLRequest.mm */,
 				51E6A8921D2F1BEC00C004B6 /* LocalStorageClear.mm */,
 				CA38459520AE012E00990D3B /* LocalStorageDatabaseTracker.mm */,
@@ -4128,6 +4131,7 @@
 				7CCE7EFF1A411AE600447C4C /* LoadCanceledNoServerRedirectCallback.cpp in Sources */,
 				A125478F1DB18B9400358564 /* LoadDataWithNilMIMEType.mm in Sources */,
 				4612C2B9210A6ACE00B788A6 /* LoadFileThenReload.mm in Sources */,
+				51396E1A222E516000A42FCE /* LoadFileURL.mm in Sources */,
 				5C838F7F1DB04F900082858F /* LoadInvalidURLRequest.mm in Sources */,
 				7C83E0C01D0A652700FEBCF3 /* LoadInvalidURLRequest.mm in Sources */,
 				7CCE7F001A411AE600447C4C /* LoadPageOnCrash.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LoadFileURL.mm (0 => 242468)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LoadFileURL.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LoadFileURL.mm	2019-03-05 17:20:36 UTC (rev 242468)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2019 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"
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import "TestNavigationDelegate.h"
+#import <WebKit/WebKit.h>
+#import <wtf/RetainPtr.h>
+
+
+TEST(WKWebView, LoadTwoFiles)
+{
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    auto delegate = adoptNS([[TestNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    NSURL *file = [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
+    [webView loadFileURL:file allowingReadAccessToURL:file.URLByDeletingLastPathComponent];
+    [delegate waitForDidFinishNavigation];
+
+    // Load a second file: resource that is in a completely different directory from the above
+    file = [[NSBundle mainBundle] URLForResource:@"simple2" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
+    NSURL *targetURL = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/simple2.html" stringByExpandingTildeInPath]];
+    [[NSFileManager defaultManager] createDirectoryAtURL:targetURL.URLByDeletingLastPathComponent withIntermediateDirectories:YES attributes:nil error:nil];
+    [[NSFileManager defaultManager] removeItemAtURL:targetURL error:nil];
+    [[NSFileManager defaultManager] copyItemAtURL:file toURL:targetURL error:nil];
+    
+    // If this second load succeeds (e.g. doesn't timeout due to a sandbox violation) the test passes
+    [webView loadFileURL:targetURL allowingReadAccessToURL:targetURL.URLByDeletingLastPathComponent];
+    [delegate waitForDidFinishNavigation];
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to