REGRESSION (r185111): Clicking phone numbers doesn't prompt to call sometimes
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Aug 2015 16:05:55 +0000 (16:05 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Aug 2015 16:05:55 +0000 (16:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=147678
<rdar://problem/21827815>

Reviewed by Brady Eidson.

Source/WebCore:

Fixes an issue where a non-user-initiated navigation of the main frame to a phone link (tel URL)
may be ignored. The navigation is ignored if the page was reloaded as a result of a web content
process crash, its lifetime exceeded the back-forward cache expiration interval, or a person
quits and opens Safari again, among other scenarios.

* history/HistoryItem.cpp:
(WebCore::HistoryItem::setShouldOpenExternalURLsPolicy): Added.
(WebCore::HistoryItem::shouldOpenExternalURLsPolicy): Added.
* history/HistoryItem.h:
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::loadDifferentDocumentItem): Apply the "should open external URLs" policy
from the history item, if applicable. Also, be more explicit when instantiating a NavigationAction
so as to help make it straightforward to reduce the number of NavigationAction constructors we have
in the future.
* loader/HistoryController.cpp:
(WebCore::HistoryController::saveDocumentState): Save the "should open external URLs" policy to
the history item.
(WebCore::HistoryController::restoreDocumentState): Apply the "should open external URLs" policy
from the history item to the document loader.
(WebCore::HistoryController::initializeItem): Update the "should open external URLs" policy of
the history item to reflect the policy of the document loader associated with the current frame.

Source/WebKit2:

Teach WebKit to save and restore the "should open external URLs" policy.

* Shared/SessionState.cpp:
(WebKit::isValidEnum): Added.
(WebKit::PageState::encode): Modified to encode the "should open external URLs" policy.
(WebKit::PageState::decode): Modified to decode the "should open external URLs" policy.
* Shared/SessionState.h: Added ShouldOpenExternalURLsPolicy to PageState (defaults to WebCore::ShouldOpenExternalURLsPolicy::ShouldNotAllow).
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _killWebContentProcessAndResetState]): Added; used in the unit test TestWebKitAPI/Tests/WebKit2Cocoa/ShouldOpenExternalURLsInNewWindowActions.mm.
* UIProcess/API/Cocoa/WKWebViewPrivate.h: Declare -[WKWebView _killWebContentProcessAndResetState].
* UIProcess/mac/LegacySessionStateCoding.cpp: Defined constant sessionHistoryEntryShouldOpenExternalURLsPolicyKey.
(WebKit::encodeSessionHistory): Modified to encode the "should open external URLs" policy.
(WebKit::decodeSessionHistoryEntry): Modified to decode the "should open external URLs" policy.
* WebProcess/WebCoreSupport/SessionStateConversion.cpp:
(WebKit::toPageState): Copy "should open external URLs" policy from specified history item.
(WebKit::toHistoryItem): Apply "should open external URLs" policy from PageState to HistoryItem.

Tools:

Add a test to ensure that we restore the "should open external URLs" policy on
page reload after the web content process crashes.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2/should-open-external-schemes.html: Added.
* TestWebKitAPI/Tests/WebKit2Cocoa/ShouldOpenExternalURLsInNewWindowActions.mm:
(TEST):

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

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/history/HistoryItem.cpp
Source/WebCore/history/HistoryItem.h
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/HistoryController.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/SessionState.cpp
Source/WebKit2/Shared/SessionState.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.cpp
Source/WebKit2/WebProcess/WebCoreSupport/SessionStateConversion.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2/should-open-external-schemes.html [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ShouldOpenExternalURLsInNewWindowActions.mm

index 70b2b85..8957752 100644 (file)
@@ -1,3 +1,33 @@
+2015-08-05  Daniel Bates  <dabates@apple.com>
+
+        REGRESSION (r185111): Clicking phone numbers doesn't prompt to call sometimes
+        https://bugs.webkit.org/show_bug.cgi?id=147678
+        <rdar://problem/21827815>
+
+        Reviewed by Brady Eidson.
+
+        Fixes an issue where a non-user-initiated navigation of the main frame to a phone link (tel URL)
+        may be ignored. The navigation is ignored if the page was reloaded as a result of a web content
+        process crash, its lifetime exceeded the back-forward cache expiration interval, or a person
+        quits and opens Safari again, among other scenarios.
+
+        * history/HistoryItem.cpp:
+        (WebCore::HistoryItem::setShouldOpenExternalURLsPolicy): Added.
+        (WebCore::HistoryItem::shouldOpenExternalURLsPolicy): Added.
+        * history/HistoryItem.h:
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::loadDifferentDocumentItem): Apply the "should open external URLs" policy
+        from the history item, if applicable. Also, be more explicit when instantiating a NavigationAction
+        so as to help make it straightforward to reduce the number of NavigationAction constructors we have
+        in the future.
+        * loader/HistoryController.cpp:
+        (WebCore::HistoryController::saveDocumentState): Save the "should open external URLs" policy to
+        the history item.
+        (WebCore::HistoryController::restoreDocumentState): Apply the "should open external URLs" policy
+        from the history item to the document loader.
+        (WebCore::HistoryController::initializeItem): Update the "should open external URLs" policy of
+        the history item to reflect the policy of the document loader associated with the current frame.
+
 2015-08-04  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Checkboxes and radio buttons should scale when zooming or pinching to zoom
index 8ab5e86..a1902d3 100644 (file)
@@ -351,6 +351,16 @@ void HistoryItem::clearDocumentState()
     m_documentState.clear();
 }
 
+void HistoryItem::setShouldOpenExternalURLsPolicy(ShouldOpenExternalURLsPolicy policy)
+{
+    m_shouldOpenExternalURLsPolicy = policy;
+}
+
+ShouldOpenExternalURLsPolicy HistoryItem::shouldOpenExternalURLsPolicy() const
+{
+    return m_shouldOpenExternalURLsPolicy;
+}
+
 bool HistoryItem::isTargetItem() const
 {
     return m_isTargetItem;
index 3aacc2a..09cf5ee 100644 (file)
@@ -28,6 +28,7 @@
 #define HistoryItem_h
 
 #include "FloatRect.h"
+#include "FrameLoaderTypes.h"
 #include "IntPoint.h"
 #include "IntRect.h"
 #include "SerializedScriptValue.h"
@@ -117,6 +118,9 @@ public:
     WEBCORE_EXPORT void setDocumentState(const Vector<String>&);
     void clearDocumentState();
 
+    WEBCORE_EXPORT void setShouldOpenExternalURLsPolicy(ShouldOpenExternalURLsPolicy);
+    WEBCORE_EXPORT ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy() const;
+
     void setURL(const URL&);
     WEBCORE_EXPORT void setURLString(const String&);
     WEBCORE_EXPORT void setOriginalURLString(const String&);
@@ -231,6 +235,8 @@ private:
     IntPoint m_scrollPoint;
     float m_pageScaleFactor;
     Vector<String> m_documentState;
+
+    ShouldOpenExternalURLsPolicy m_shouldOpenExternalURLsPolicy { ShouldOpenExternalURLsPolicy::ShouldNotAllow };
     
     HistoryItemVector m_children;
     
index 2daf404..611aa48 100644 (file)
@@ -3228,7 +3228,11 @@ void FrameLoader::loadDifferentDocumentItem(HistoryItem& item, FrameLoadType loa
 
     if (!item.referrer().isNull())
         request.setHTTPReferrer(item.referrer());
-    
+
+    ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy = shouldOpenExternalURLsPolicyToApply(m_frame, item.shouldOpenExternalURLsPolicy());
+    bool isFormSubmission = false;
+    Event* event = nullptr;
+
     // If this was a repost that failed the page cache, we might try to repost the form.
     NavigationAction action;
     if (formData) {
@@ -3254,10 +3258,10 @@ void FrameLoader::loadDifferentDocumentItem(HistoryItem& item, FrameLoadType loa
         
         if (cacheLoadPolicy == MayAttemptCacheOnlyLoadForFormSubmissionItem) {
             request.setCachePolicy(ReturnCacheDataDontLoad);
-            action = NavigationAction(request, loadType, false);
+            action = NavigationAction(request, loadType, isFormSubmission, event, shouldOpenExternalURLsPolicy);
         } else {
             request.setCachePolicy(ReturnCacheDataElseLoad);
-            action = NavigationAction(request, NavigationType::FormResubmitted);
+            action = NavigationAction(request, NavigationType::FormResubmitted, event, shouldOpenExternalURLsPolicy);
         }
     } else {
         switch (loadType) {
@@ -3282,7 +3286,7 @@ void FrameLoader::loadDifferentDocumentItem(HistoryItem& item, FrameLoadType loa
 
         ResourceRequest requestForOriginalURL(request);
         requestForOriginalURL.setURL(itemOriginalURL);
-        action = NavigationAction(requestForOriginalURL, loadType, false);
+        action = NavigationAction(requestForOriginalURL, loadType, isFormSubmission, event, shouldOpenExternalURLsPolicy);
     }
 
     loadWithNavigationAction(request, action, LockHistory::No, loadType, 0, AllowNavigationToInvalidURL::Yes);
index be5c074..12fd565 100644 (file)
@@ -191,6 +191,9 @@ void HistoryController::saveDocumentState()
     ASSERT(m_frame.document());
     Document& document = *m_frame.document();
     if (item->isCurrentDocument(document) && document.hasLivingRenderTree()) {
+        if (DocumentLoader* documentLoader = document.loader())
+            item->setShouldOpenExternalURLsPolicy(documentLoader->shouldOpenExternalURLsPolicyToPropagate());
+
         LOG(Loading, "WebCoreLoading %s: saving form state to %p", m_frame.tree().uniqueName().string().utf8().data(), item);
         item->setDocumentState(document.formElementsState());
     }
@@ -230,6 +233,8 @@ void HistoryController::restoreDocumentState()
     if (m_frame.loader().documentLoader()->isClientRedirect())
         return;
 
+    m_frame.loader().documentLoader()->setShouldOpenExternalURLsPolicy(m_currentItem->shouldOpenExternalURLsPolicy());
+
     LOG(Loading, "WebCoreLoading %s: restoring form state from %p", m_frame.tree().uniqueName().string().utf8().data(), m_currentItem.get());
     m_frame.document()->setStateForNewFormElements(m_currentItem->documentState());
 }
@@ -648,6 +653,8 @@ void HistoryController::initializeItem(HistoryItem& item)
     if (!unreachableURL.isEmpty() || documentLoader->response().httpStatusCode() >= 400)
         item.setLastVisitWasFailure(true);
 
+    item.setShouldOpenExternalURLsPolicy(documentLoader->shouldOpenExternalURLsPolicyToPropagate());
+
     // Save form state if this is a POST
     item.setFormInfoFromRequest(documentLoader->request());
 }
index 1f81436..0dbab06 100644 (file)
@@ -1,3 +1,28 @@
+2015-08-05  Daniel Bates  <dabates@apple.com>
+
+        REGRESSION (r185111): Clicking phone numbers doesn't prompt to call sometimes
+        https://bugs.webkit.org/show_bug.cgi?id=147678
+        <rdar://problem/21827815>
+
+        Reviewed by Brady Eidson.
+
+        Teach WebKit to save and restore the "should open external URLs" policy.
+
+        * Shared/SessionState.cpp:
+        (WebKit::isValidEnum): Added.
+        (WebKit::PageState::encode): Modified to encode the "should open external URLs" policy.
+        (WebKit::PageState::decode): Modified to decode the "should open external URLs" policy.
+        * Shared/SessionState.h: Added ShouldOpenExternalURLsPolicy to PageState (defaults to WebCore::ShouldOpenExternalURLsPolicy::ShouldNotAllow).
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _killWebContentProcessAndResetState]): Added; used in the unit test TestWebKitAPI/Tests/WebKit2Cocoa/ShouldOpenExternalURLsInNewWindowActions.mm.
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h: Declare -[WKWebView _killWebContentProcessAndResetState].
+        * UIProcess/mac/LegacySessionStateCoding.cpp: Defined constant sessionHistoryEntryShouldOpenExternalURLsPolicyKey.
+        (WebKit::encodeSessionHistory): Modified to encode the "should open external URLs" policy.
+        (WebKit::decodeSessionHistoryEntry): Modified to decode the "should open external URLs" policy.
+        * WebProcess/WebCoreSupport/SessionStateConversion.cpp:
+        (WebKit::toPageState): Copy "should open external URLs" policy from specified history item.
+        (WebKit::toHistoryItem): Apply "should open external URLs" policy from PageState to HistoryItem.
+
 2015-08-04  Antti Koivisto  <antti@apple.com>
 
         Network cache fetches should have timeout
index 168abf7..1cd2d9b 100644 (file)
 
 namespace WebKit {
 
+bool isValidEnum(WebCore::ShouldOpenExternalURLsPolicy policy)
+{
+    switch (policy) {
+    case WebCore::ShouldOpenExternalURLsPolicy::ShouldAllow:
+    case WebCore::ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemes:
+    case WebCore::ShouldOpenExternalURLsPolicy::ShouldNotAllow:
+        return true;
+    }
+    return false;
+}
+
 void HTTPBody::Element::encode(IPC::ArgumentEncoder& encoder) const
 {
     encoder.encodeEnum(type);
@@ -170,6 +181,7 @@ void PageState::encode(IPC::ArgumentEncoder& encoder) const
 {
     encoder << title;
     encoder << mainFrameState;
+    encoder.encodeEnum(shouldOpenExternalURLsPolicy);
 }
 
 bool PageState::decode(IPC::ArgumentDecoder& decoder, PageState& result)
@@ -178,6 +190,8 @@ bool PageState::decode(IPC::ArgumentDecoder& decoder, PageState& result)
         return false;
     if (!decoder.decode(result.mainFrameState))
         return false;
+    if (!decoder.decodeEnum(result.shouldOpenExternalURLsPolicy) || !isValidEnum(result.shouldOpenExternalURLsPolicy))
+        return false;
 
     return true;
 }
index d4d6a2b..735a9c3 100644 (file)
@@ -31,6 +31,7 @@
 #endif
 
 #include <WebCore/FloatRect.h>
+#include <WebCore/FrameLoaderTypes.h>
 #include <WebCore/IntRect.h>
 #include <WebCore/URL.h>
 #include <wtf/Optional.h>
@@ -44,6 +45,8 @@ class ArgumentEncoder;
 
 namespace WebKit {
 
+bool isValidEnum(WebCore::ShouldOpenExternalURLsPolicy);
+
 struct HTTPBody {
     struct Element {
         void encode(IPC::ArgumentEncoder&) const;
@@ -115,6 +118,7 @@ struct PageState {
 
     String title;
     FrameState mainFrameState;
+    WebCore::ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy { WebCore::ShouldOpenExternalURLsPolicy::ShouldNotAllow };
 };
 
 struct BackForwardListItemState {
index f06ff78..cea8e8a 100644 (file)
@@ -2046,6 +2046,11 @@ static WebCore::FloatPoint constrainContentOffset(WebCore::FloatPoint contentOff
     _page->process().terminate();
 }
 
+- (void)_killWebContentProcessAndResetState
+{
+    _page->terminateProcess();
+}
+
 #if PLATFORM(IOS)
 static WebCore::FloatSize activeMinimumLayoutSize(WKWebView *webView, const CGRect& bounds)
 {
index 08e47f6..79e90e1 100644 (file)
@@ -175,6 +175,8 @@ WK_EXTERN NSString * const _WKShouldOpenExternalURLsKey WK_AVAILABLE(WK_MAC_TBA,
 @property (nonatomic, setter=_setOverrideDeviceScaleFactor:) CGFloat _overrideDeviceScaleFactor WK_AVAILABLE(WK_MAC_TBA, NA);
 #endif
 
+- (void)_killWebContentProcessAndResetState;
+
 - (void)_getMainResourceDataWithCompletionHandler:(void (^)(NSData *, NSError *))completionHandler;
 - (void)_getWebArchiveDataWithCompletionHandler:(void (^)(NSData *, NSError *))completionHandler;
 
index 164acbd..dcd633a 100644 (file)
@@ -54,6 +54,7 @@ static const CFStringRef sessionHistoryEntryURLKey = CFSTR("SessionHistoryEntryU
 static const CFStringRef sessionHistoryEntryTitleKey = CFSTR("SessionHistoryEntryTitle");
 static const CFStringRef sessionHistoryEntryOriginalURLKey = CFSTR("SessionHistoryEntryOriginalURL");
 static const CFStringRef sessionHistoryEntryDataKey = CFSTR("SessionHistoryEntryData");
+static const CFStringRef sessionHistoryEntryShouldOpenExternalURLsPolicyKey = CFSTR("SessionHistoryEntryShouldOpenExternalURLsPolicyKey");
 
 // Session history entry data.
 const uint32_t sessionHistoryEntryDataVersion = 2;
@@ -426,12 +427,15 @@ static RetainPtr<CFDictionaryRef> encodeSessionHistory(const BackForwardListStat
         auto title = item.pageState.title.createCFString();
         auto originalURL = item.pageState.mainFrameState.originalURLString.createCFString();
         auto data = encodeSessionHistoryEntryData(item.pageState.mainFrameState);
+        auto shouldOpenExternalURLsPolicyValue = static_cast<uint64_t>(item.pageState.shouldOpenExternalURLsPolicy);
+        auto shouldOpenExternalURLsPolicy = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &shouldOpenExternalURLsPolicyValue));
 
         auto entryDictionary = createDictionary({
             { sessionHistoryEntryURLKey, url.get() },
             { sessionHistoryEntryTitleKey, title.get() },
             { sessionHistoryEntryOriginalURLKey, originalURL.get() },
             { sessionHistoryEntryDataKey, data.get() },
+            { sessionHistoryEntryShouldOpenExternalURLsPolicyKey, shouldOpenExternalURLsPolicy.get() },
         });
 
         CFArrayAppendValue(entries.get(), entryDictionary.get());
@@ -965,10 +969,20 @@ static bool decodeSessionHistoryEntry(CFDictionaryRef entryDictionary, BackForwa
     if (!historyEntryData)
         return false;
 
+    auto rawShouldOpenExternalURLsPolicy = dynamic_cf_cast<CFNumberRef>(CFDictionaryGetValue(entryDictionary, sessionHistoryEntryShouldOpenExternalURLsPolicyKey));
+    WebCore::ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy;
+    if (rawShouldOpenExternalURLsPolicy) {
+        uint64_t value;
+        CFNumberGetValue(rawShouldOpenExternalURLsPolicy, kCFNumberSInt64Type, &value);
+        shouldOpenExternalURLsPolicy = static_cast<WebCore::ShouldOpenExternalURLsPolicy>(value);
+    } else
+        shouldOpenExternalURLsPolicy = WebCore::ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemes;
+
     if (!decodeSessionHistoryEntryData(historyEntryData, backForwardListItemState.pageState.mainFrameState))
         return false;
 
     backForwardListItemState.pageState.title = title;
+    backForwardListItemState.pageState.shouldOpenExternalURLsPolicy = shouldOpenExternalURLsPolicy;
     backForwardListItemState.pageState.mainFrameState.urlString = urlString;
     backForwardListItemState.pageState.mainFrameState.originalURLString = originalURLString;
 
index 4520620..d7fe19c 100644 (file)
@@ -116,6 +116,7 @@ PageState toPageState(const WebCore::HistoryItem& historyItem)
 
     pageState.title = historyItem.title();
     pageState.mainFrameState = toFrameState(historyItem);
+    pageState.shouldOpenExternalURLsPolicy = historyItem.shouldOpenExternalURLsPolicy();
 
     return pageState;
 }
@@ -188,6 +189,7 @@ static void applyFrameState(HistoryItem& historyItem, const FrameState& frameSta
 Ref<HistoryItem> toHistoryItem(const PageState& pageState)
 {
     Ref<HistoryItem> historyItem = HistoryItem::create(pageState.mainFrameState.urlString, pageState.title);
+    historyItem->setShouldOpenExternalURLsPolicy(pageState.shouldOpenExternalURLsPolicy);
     applyFrameState(historyItem, pageState.mainFrameState);
 
     return historyItem;
index ccbf5f8..f863312 100644 (file)
@@ -1,3 +1,19 @@
+2015-08-05  Daniel Bates  <dabates@apple.com>
+
+        REGRESSION (r185111): Clicking phone numbers doesn't prompt to call sometimes
+        https://bugs.webkit.org/show_bug.cgi?id=147678
+        <rdar://problem/21827815>
+
+        Reviewed by Brady Eidson.
+
+        Add a test to ensure that we restore the "should open external URLs" policy on
+        page reload after the web content process crashes.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2/should-open-external-schemes.html: Added.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/ShouldOpenExternalURLsInNewWindowActions.mm:
+        (TEST):
+
 2015-08-04  Hunseop Jeong  <hs85.jeong@samsung.com>
 
         [EFL] Editing tests have been broken since r186694
index f25fa04..6b75a1d 100644 (file)
                CE3524F91B1441C40028A7C5 /* TextFieldDidBeginAndEndEditing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE3524F11B142B8D0028A7C5 /* TextFieldDidBeginAndEndEditing.cpp */; };
                CE3524FA1B1443890028A7C5 /* input-focus-blur.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CE3524F51B142BBB0028A7C5 /* input-focus-blur.html */; };
                CEA6CF2819CCF69D0064F5A7 /* open-and-close-window.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */; };
+               CEBABD491B71687C0051210A /* should-open-external-schemes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CEBABD481B71687C0051210A /* should-open-external-schemes.html */; };
                E1220DCA155B28AA0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */; };
                E194E1BD177E53C7009C4D4E /* StopLoadingFromDidReceiveResponse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E194E1BC177E534A009C4D4E /* StopLoadingFromDidReceiveResponse.html */; };
                E19DB9791B32137C00DB38D4 /* NavigatorLanguage.mm in Sources */ = {isa = PBXBuildFile; fileRef = E19DB9781B32137C00DB38D4 /* NavigatorLanguage.mm */; };
                                51E5C7021919C3B200D8B3E1 /* simple2.html in Copy Resources */,
                                51E5C7031919C3B200D8B3E1 /* simple3.html in Copy Resources */,
                                C01A23F21266156700C9ED55 /* spacebar-scrolling.html in Copy Resources */,
+                               CEBABD491B71687C0051210A /* should-open-external-schemes.html in Copy Resources */,
                                E194E1BD177E53C7009C4D4E /* StopLoadingFromDidReceiveResponse.html in Copy Resources */,
                                CD59F53519E9110D00CF1835 /* test-mse.mp4 in Copy Resources */,
                                524BBCA119E30C77002F1AF1 /* test.mp4 in Copy Resources */,
                CE3524F51B142BBB0028A7C5 /* input-focus-blur.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "input-focus-blur.html"; sourceTree = "<group>"; };
                CEA6CF2219CCF5BD0064F5A7 /* OpenAndCloseWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = OpenAndCloseWindow.mm; sourceTree = "<group>"; };
                CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "open-and-close-window.html"; sourceTree = "<group>"; };
+               CEBABD481B71687C0051210A /* should-open-external-schemes.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "should-open-external-schemes.html"; sourceTree = "<group>"; };
                E1220D9F155B25480013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryCacheDisableWithinResourceLoadDelegate.mm; sourceTree = "<group>"; };
                E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = MemoryCacheDisableWithinResourceLoadDelegate.html; sourceTree = "<group>"; };
                E194E1BA177E5145009C4D4E /* StopLoadingFromDidReceiveResponse.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StopLoadingFromDidReceiveResponse.mm; sourceTree = "<group>"; };
                                BC909778125571AB00083756 /* simple.html */,
                                51E780361919AFF8001829A2 /* simple2.html */,
                                51E780371919AFF8001829A2 /* simple3.html */,
+                               CEBABD481B71687C0051210A /* should-open-external-schemes.html */,
                                C02B7882126615410026BF0F /* spacebar-scrolling.html */,
                                CD59F53319E910BC00CF1835 /* test-mse.mp4 */,
                                524BBCA019E30C63002F1AF1 /* test.mp4 */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/should-open-external-schemes.html b/Tools/TestWebKitAPI/Tests/WebKit2/should-open-external-schemes.html
new file mode 100644 (file)
index 0000000..299e4d6
--- /dev/null
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+function navigateToTelURL()
+{
+     window.location.href = "tel:+1 (408) 996-1010";
+}
+
+function navigateToTelURLInZeroTimer()
+{
+    window.setTimeout(navigateToTelURL, 0);
+}
+
+function navigateToTelURLInNestedZeroTimer()
+{
+    window.setTimeout(navigateToTelURLInZeroTimer, 0);
+}
+</script>
+</head>
+</html>
index 2264a74..b249d0a 100644 (file)
@@ -29,6 +29,7 @@
 
 #import "PlatformUtilities.h"
 #import <WebKit/WKNavigationActionPrivate.h>
+#import <WebKit/WKWebViewPrivate.h>
 #import <wtf/RetainPtr.h>
 
 #if WK_API_ENABLED
@@ -206,6 +207,48 @@ TEST(WebKit2, ShouldOpenExternalURLsInTargetedLink)
     action = nullptr;
 }
 
+TEST(WebKit2, RestoreShouldOpenExternalURLsPolicyAfterCrash)
+{
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]);
+    [[window contentView] addSubview:webView.get()];
+    auto controller = adoptNS([[ShouldOpenExternalURLsInNewWindowActionsController alloc] init]);
+    [webView setNavigationDelegate:controller.get()];
+    [webView setUIDelegate:controller.get()];
+
+    finishedNavigation = false;
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"should-open-external-schemes" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+    TestWebKitAPI::Util::run(&finishedNavigation);
+    finishedNavigation = false;
+
+    // Before crash
+    decidedPolicy = false;
+    [webView evaluateJavaScript:@"navigateToTelURLInNestedZeroTimer()" completionHandler:nil]; // Non-user initiated navigation because it is performed in a nested timer callback.
+    TestWebKitAPI::Util::run(&decidedPolicy);
+    decidedPolicy = false;
+
+    ASSERT_TRUE([action _shouldOpenExternalSchemes]);
+    ASSERT_FALSE([action _shouldOpenAppLinks]);
+
+    // Crash
+    [webView _killWebContentProcessAndResetState];
+    [webView reload];
+
+    finishedNavigation = false;
+    TestWebKitAPI::Util::run(&finishedNavigation);
+    finishedNavigation = false;
+
+    // After crash
+    decidedPolicy = false;
+    [webView evaluateJavaScript:@"navigateToTelURLInNestedZeroTimer()" completionHandler:nil]; // Non-user initiated navigation because it is performed in a nested timer callback.
+    TestWebKitAPI::Util::run(&decidedPolicy);
+    decidedPolicy = false;
+
+    ASSERT_TRUE([action _shouldOpenExternalSchemes]);
+    ASSERT_FALSE([action _shouldOpenAppLinks]);
+};
+
 #endif
 
 #endif