Summary: WKWebView is missing an equivalent to WebKit 1's API to set the media style.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Nov 2019 18:09:30 +0000 (18:09 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Nov 2019 18:09:30 +0000 (18:09 +0000)
<rdar://problem/49862107> and https://bugs.webkit.org/show_bug.cgi?id=203974

Reviewed by Alex Christensen.

Source/WebKit:

Covered by new API test.

This is basically:
- Expose a read/write property on WKWebView.
- Pipe the new media type to the WebProcess.
- Force a style recalc.

* UIProcess/API/Cocoa/WKWebView.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView setMediaType:]):
(-[WKWebView mediaType]):

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::setOverriddenMediaType):
* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::overriddenMediaType const):

* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::overrideMediaType const):

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::setOverriddenMediaType):
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::overriddenMediaType const):
* WebProcess/WebPage/WebPage.messages.in:

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/MediaType.mm: Added.
(TEST):
* TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:

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

15 files changed:
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPageCreationParameters.cpp
Source/WebKit/Shared/WebPageCreationParameters.h
Source/WebKit/UIProcess/API/Cocoa/WKWebView.h
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/MediaType.mm [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm

index e723f5d..6db0f4a 100644 (file)
@@ -1,5 +1,38 @@
 2019-11-14  Brady Eidson  <beidson@apple.com>
 
+        Summary: WKWebView is missing an equivalent to WebKit 1's API to set the media style.
+        <rdar://problem/49862107> and https://bugs.webkit.org/show_bug.cgi?id=203974
+
+        Reviewed by Alex Christensen.
+
+        Covered by new API test.
+
+        This is basically:
+        - Expose a read/write property on WKWebView.
+        - Pipe the new media type to the WebProcess.
+        - Force a style recalc.
+
+        * UIProcess/API/Cocoa/WKWebView.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView setMediaType:]):
+        (-[WKWebView mediaType]):
+        
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::setOverriddenMediaType):
+        * UIProcess/WebPageProxy.h:
+        (WebKit::WebPageProxy::overriddenMediaType const):
+        
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::overrideMediaType const):
+        
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::setOverriddenMediaType):
+        * WebProcess/WebPage/WebPage.h:
+        (WebKit::WebPage::overriddenMediaType const):
+        * WebProcess/WebPage/WebPage.messages.in:
+
+2019-11-14  Brady Eidson  <beidson@apple.com>
+
         pageZoom/setPageZoom: should not be in a Mac-only part of WKWebView.mm
         https://bugs.webkit.org/show_bug.cgi?id=204128
 
index 7f55a88..7b72af3 100644 (file)
@@ -129,6 +129,7 @@ void WebPageCreationParameters::encode(IPC::Encoder& encoder) const
 #endif
     encoder << backgroundColor;
     encoder << oldPageID;
+    encoder << overriddenMediaType;
 }
 
 Optional<WebPageCreationParameters> WebPageCreationParameters::decode(IPC::Decoder& decoder)
@@ -393,6 +394,9 @@ Optional<WebPageCreationParameters> WebPageCreationParameters::decode(IPC::Decod
         return WTF::nullopt;
     parameters.oldPageID = WTFMove(*oldPageID);
 
+    if (!decoder.decode(parameters.overriddenMediaType))
+        return WTF::nullopt;
+
     return parameters;
 }
 
index fbf5439..59972ef 100644 (file)
@@ -200,6 +200,8 @@ struct WebPageCreationParameters {
     Optional<WebCore::Color> backgroundColor;
 
     Optional<WebCore::PageIdentifier> oldPageID;
+
+    String overriddenMediaType;
 };
 
 } // namespace WebKit
index 46d324f..d7e57c7 100644 (file)
@@ -320,6 +320,14 @@ The uniform type identifier kUTTypeWebArchive can be used get the related pasteb
  */
 + (BOOL)handlesURLScheme:(NSString *)urlScheme WK_API_AVAILABLE(macos(10.13), ios(11.0));
 
+
+/* @abstract The media type for the WKWebView
+@discussion The value of mediaType will override the normal value of the CSS media property.
+ Setting the value to nil will restore the normal value.
+ The default value is nil.
+*/
+@property (nonatomic, null_resettable, copy) NSString *mediaType;
+
 #if !TARGET_OS_IPHONE
 /* @abstract Returns an NSPrintOperation object configured to print the contents of this WKWebView
 @param printInfo The print info object used to configure the resulting print operation.
index e7e5d27..3951d8d 100644 (file)
@@ -4776,6 +4776,16 @@ inline WebKit::FindOptions toFindOptions(WKFindConfiguration *configuration)
     });
 }
 
+- (void)setMediaType:(NSString *)mediaStyle
+{
+    _page->setOverriddenMediaType(mediaStyle);
+}
+
+- (NSString *)mediaType
+{
+    return _page->overriddenMediaType().isNull() ? nil : (NSString *)_page->overriddenMediaType();
+}
+
 @end
 
 @implementation WKWebView (WKPrivate)
index a3e2066..a05a8b2 100644 (file)
@@ -7418,6 +7418,8 @@ WebPageCreationParameters WebPageProxy::creationParameters(WebProcessProxy& proc
     parameters.needsFontAttributes = m_needsFontAttributes;
     parameters.backgroundColor = m_backgroundColor;
 
+    parameters.overriddenMediaType = m_overriddenMediaType;
+
     process.addWebUserContentControllerProxy(m_userContentController, parameters);
 
     return parameters;
@@ -9498,6 +9500,12 @@ void WebPageProxy::completeTextManipulation(WebCore::TextManipulationController:
     m_process->connection()->sendWithAsyncReply(Messages::WebPage::CompleteTextManipulation(itemID, tokens), WTFMove(completionHandler), m_webPageID);
 }
 
+void WebPageProxy::setOverriddenMediaType(const String& mediaType)
+{
+    m_overriddenMediaType = mediaType;
+    m_process->send(Messages::WebPage::SetOverriddenMediaType(mediaType), m_webPageID);
+}
+
 } // namespace WebKit
 
 #undef MERGE_WHEEL_EVENTS
index 8488b76..a1bcc6d 100644 (file)
@@ -1621,6 +1621,9 @@ public:
     void completeTextManipulation(WebCore::TextManipulationController::ItemIdentifier, const Vector<WebCore::TextManipulationController::ManipulationToken>&,
         WTF::Function<void (WebCore::TextManipulationController::ManipulationResult)>&&);
 
+    const String& overriddenMediaType() const { return m_overriddenMediaType; }
+    void setOverriddenMediaType(const String&);
+
 private:
     WebPageProxy(PageClient&, WebProcessProxy&, Ref<API::PageConfiguration>&&);
     void platformInitialize();
@@ -2617,6 +2620,8 @@ private:
     COMPtr<ID3D11Device1> m_device;
 #endif
     bool m_isQuotaIncreaseDenied { false };
+    
+    String m_overriddenMediaType;
 };
 
 } // namespace WebKit
index d3f7879..d6dd756 100644 (file)
@@ -1720,7 +1720,11 @@ ObjectContentType WebFrameLoaderClient::objectContentType(const URL& url, const
 
 String WebFrameLoaderClient::overrideMediaType() const
 {
-    notImplemented();
+    if (m_frame) {
+        if (auto* page = m_frame->page())
+            return page->overriddenMediaType();
+    }
+
     return String();
 }
 
index a556faf..c43d3bd 100644 (file)
@@ -432,6 +432,7 @@ WebPage::WebPage(PageIdentifier pageID, WebPageCreationParameters&& parameters)
 #if ENABLE(TEXT_AUTOSIZING)
     , m_textAutoSizingAdjustmentTimer(*this, &WebPage::textAutoSizingAdjustmentTimerFired)
 #endif
+    , m_overriddenMediaType(parameters.overriddenMediaType)
 {
     ASSERT(m_identifier);
 
@@ -6825,6 +6826,15 @@ void WebPage::textAutoSizingAdjustmentTimerFired()
 }
 #endif
 
+void WebPage::setOverriddenMediaType(const String& mediaType)
+{
+    if (mediaType == m_overriddenMediaType)
+        return;
+
+    m_overriddenMediaType = mediaType;
+    m_page->setNeedsRecalcStyleInAllFrames();
+}
+
 } // namespace WebKit
 
 #undef RELEASE_LOG_IF_ALLOWED
index 55830e8..a12658c 100644 (file)
@@ -1240,6 +1240,9 @@ public:
     void requestPasswordForQuickLookDocumentInMainFrame(const String& fileName, CompletionHandler<void(const String&)>&&);
 #endif
 
+    const String& overriddenMediaType() const { return m_overriddenMediaType; }
+    void setOverriddenMediaType(const String&);
+    
 private:
     WebPage(WebCore::PageIdentifier, WebPageCreationParameters&&);
 
@@ -1998,6 +2001,8 @@ private:
 #if ENABLE(TEXT_AUTOSIZING)
     WebCore::Timer m_textAutoSizingAdjustmentTimer;
 #endif
+
+    String m_overriddenMediaType;
 };
 
 #if !PLATFORM(IOS_FAMILY)
index 262daef..0f2c3ac 100644 (file)
@@ -581,4 +581,6 @@ GenerateSyntheticEditingCommand(enum:uint8_t WebKit::SyntheticEditingCommandType
 
     StartTextManipulations(Vector<WebCore::TextManipulationController::ExclusionRule> exclusionRules) -> () Async
     CompleteTextManipulation(WebCore::TextManipulationController::ItemIdentifier itemID, Vector<WebCore::TextManipulationController::ManipulationToken> tokens) -> (enum:uint8_t WebCore::TextManipulationController::ManipulationResult result) Async
+    
+    SetOverriddenMediaType(String mediaType)
 }
index f6dcf2c..575a694 100644 (file)
@@ -1,5 +1,17 @@
 2019-11-14  Brady Eidson  <beidson@apple.com>
 
+        Summary: WKWebView is missing an equivalent to WebKit 1's API to set the media style.
+        <rdar://problem/49862107> and https://bugs.webkit.org/show_bug.cgi?id=203974
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/MediaType.mm: Added.
+        (TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
+
+2019-11-14  Brady Eidson  <beidson@apple.com>
+
         pageZoom/setPageZoom: should not be in a Mac-only part of WKWebView.mm
         https://bugs.webkit.org/show_bug.cgi?id=204128
 
index 3084bd4..80ef587 100644 (file)
                51B1EE971C80FAEF0064FB98 /* IndexedDBPersistence-2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51B1EE951C80FADD0064FB98 /* IndexedDBPersistence-2.html */; };
                51BCEE4E1C84F53B0042C82E /* IndexedDBMultiProcess-1.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51BCEE4C1C84F52C0042C82E /* IndexedDBMultiProcess-1.html */; };
                51BCEE4F1C84F53B0042C82E /* IndexedDBMultiProcess-2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51BCEE4D1C84F52C0042C82E /* IndexedDBMultiProcess-2.html */; };
+               51BE9E662376089F00B4E117 /* MediaType.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51BE9E652376089500B4E117 /* MediaType.mm */; };
                51C683DE1EA134E800650183 /* WKURLSchemeHandler-1.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51C683DD1EA134DB00650183 /* WKURLSchemeHandler-1.mm */; };
                51C8E1A51F26AF4C00BF731B /* ResourceLoadStatistics.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51C8E1A41F26AC5400BF731B /* ResourceLoadStatistics.mm */; };
                51C8E1A91F27F49600BF731B /* EmptyGrandfatheredResourceLoadStatistics.plist in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51C8E1A81F27F47300BF731B /* EmptyGrandfatheredResourceLoadStatistics.plist */; };
                51BCEE491C84F4AF0042C82E /* IndexedDBMultiProcess.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = IndexedDBMultiProcess.mm; sourceTree = "<group>"; };
                51BCEE4C1C84F52C0042C82E /* IndexedDBMultiProcess-1.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "IndexedDBMultiProcess-1.html"; sourceTree = "<group>"; };
                51BCEE4D1C84F52C0042C82E /* IndexedDBMultiProcess-2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "IndexedDBMultiProcess-2.html"; sourceTree = "<group>"; };
+               51BE9E652376089500B4E117 /* MediaType.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MediaType.mm; sourceTree = "<group>"; };
                51C683DD1EA134DB00650183 /* WKURLSchemeHandler-1.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "WKURLSchemeHandler-1.mm"; sourceTree = "<group>"; };
                51C8E1A41F26AC5400BF731B /* ResourceLoadStatistics.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ResourceLoadStatistics.mm; sourceTree = "<group>"; };
                51C8E1A81F27F47300BF731B /* EmptyGrandfatheredResourceLoadStatistics.plist */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; path = EmptyGrandfatheredResourceLoadStatistics.plist; sourceTree = "<group>"; };
                                8C10AF96206467770018FD90 /* LocalStoragePersistence.mm */,
                                7A6A2C6F1DCCF87B00C0D085 /* LocalStorageQuirkTest.mm */,
                                07CC7DFD2266330800E39181 /* MediaBufferingPolicy.mm */,
+                               51BE9E652376089500B4E117 /* MediaType.mm */,
                                5165FE03201EE617009F7EC3 /* MessagePortProviders.mm */,
                                51CD1C6A1B38CE3600142CA5 /* ModalAlerts.mm */,
                                1ABC3DED1899BE6D004F0626 /* Navigation.mm */,
                                07CC7DFE2266330900E39181 /* MediaBufferingPolicy.mm in Sources */,
                                CDA315981ED53651009F60D3 /* MediaPlaybackSleepAssertion.mm in Sources */,
                                CDC9442E1EF1FC080059C3C4 /* MediaStreamTrackDetached.mm in Sources */,
+                               51BE9E662376089F00B4E117 /* MediaType.mm in Sources */,
                                7CCE7EC51A411A7E00447C4C /* MemoryCacheDisableWithinResourceLoadDelegate.mm in Sources */,
                                7CCE7EC61A411A7E00447C4C /* MemoryCachePruneWithinResourceLoadDelegate.mm in Sources */,
                                5C0BF88D1DD5964D00B00328 /* MemoryPressureHandler.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/MediaType.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/MediaType.mm
new file mode 100644 (file)
index 0000000..01407ff
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * 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 "TestNavigationDelegate.h"
+#import "TestWKWebView.h"
+#import <WebKit/WKFindConfiguration.h>
+#import <WebKit/WKFindResult.h>
+#import <WebKit/WKWebView.h>
+#import <wtf/RetainPtr.h>
+
+NSString *testPage = @"<style>\n"
+"@media screen {\n"
+".ShowForPrinting{\n"
+"    visibility: hidden;\n"
+"}\n"
+".ShowForLavaLamp{\n"
+"    visibility: hidden;\n"
+"}\n"
+"}\n"
+"@media print {\n"
+".ShowForScreen{\n"
+"    visibility: hidden;\n"
+"}\n"
+".ShowForLavaLamp{\n"
+"    visibility: hidden;\n"
+"}\n"
+"}\n"
+"@media lavalamp {\n"
+".ShowForScreen {\n"
+"    visibility: hidden;\n"
+"}\n"
+".ShowForPrinting{\n"
+"    visibility: hidden;\n"
+"}\n"
+"}\n"
+"</style>\n"
+"<div class='ShowForScreen'>Screen</div>\n"
+"<div class='ShowForPrinting'>Print</div>\n"
+"<div class='ShowForLavaLamp'>LavaLamp</div>\n";
+
+TEST(WKWebView, MediaType)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
+    [webView synchronouslyLoadHTMLString:testPage baseURL:nil];
+
+    EXPECT_TRUE(webView.get().mediaType == nil);
+    EXPECT_TRUE([[[webView stringByEvaluatingJavaScript:@"document.body.innerText"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] isEqualToString:@"Screen"]);
+    
+    webView.get().mediaType = @"screen";
+    EXPECT_TRUE([[[webView stringByEvaluatingJavaScript:@"document.body.innerText"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] isEqualToString:@"Screen"]);
+
+    webView.get().mediaType = @"print";
+    EXPECT_TRUE([[[webView stringByEvaluatingJavaScript:@"document.body.innerText"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] isEqualToString:@"Print"]);
+
+    webView.get().mediaType = @"lavalamp";
+    EXPECT_TRUE([[[webView stringByEvaluatingJavaScript:@"document.body.innerText"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] isEqualToString:@"LavaLamp"]);
+}
index 7a7265d..796eb4e 100644 (file)
@@ -3008,6 +3008,75 @@ TEST(ProcessSwap, PageZoomLevelAfterSwap)
 
 #endif // PLATFORM(MAC)
 
+static const char* mediaTypeBytes = R"PSONRESOURCE(
+<style>
+@media screen {
+.print{
+    visibility: hidden;
+}
+}
+
+@media print {
+.screen{
+    visibility: hidden;
+}
+}
+</style>
+<body>
+<div class="screen">Screen</div>
+<div class="print">Print</div>
+</body>
+)PSONRESOURCE";
+
+TEST(ProcessSwap, MediaTypeAfterSwap)
+{
+    auto processPoolConfiguration = psonProcessPoolConfiguration();
+    auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
+
+    auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [webViewConfiguration setProcessPool:processPool.get()];
+    auto handler = adoptNS([[PSONScheme alloc] init]);
+    [handler addMappingFromURLString:@"pson://www.webkit.org/main.html" toData:mediaTypeBytes];
+    [handler addMappingFromURLString:@"pson://www.apple.com/main.html" toData:mediaTypeBytes];
+    [webViewConfiguration setURLSchemeHandler:handler.get() forURLScheme:@"PSON"];
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
+    auto delegate = adoptNS([[PSONNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"pson://www.webkit.org/main.html"]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&done);
+    done = false;
+
+    NSString *innerText = [[webView stringByEvaluatingJavaScript:@"document.body.innerText"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+    EXPECT_TRUE([innerText isEqualToString:@"Screen"]);
+
+    webView.get().mediaType = @"print";
+
+    innerText = [[webView stringByEvaluatingJavaScript:@"document.body.innerText"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+    EXPECT_TRUE([innerText isEqualToString:@"Print"]);
+
+    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"pson://www.apple.com/main.html"]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&done);
+    done = false;
+
+    innerText = [[webView stringByEvaluatingJavaScript:@"document.body.innerText"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+    EXPECT_TRUE([innerText isEqualToString:@"Print"]);
+
+    // Kill the WebProcess, the page should reload automatically and the media type should be maintained.
+    kill([webView _webProcessIdentifier], 9);
+
+    TestWebKitAPI::Util::run(&done);
+    done = false;
+
+    innerText = [[webView stringByEvaluatingJavaScript:@"document.body.innerText"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+    EXPECT_TRUE([innerText isEqualToString:@"Print"]);
+}
+
 static const char* navigateBeforePageLoadEndBytes = R"PSONRESOURCE(
 <body>
 <a id="testLink" href="pson://www.apple.com/main.html">Link</a>