Add a WebViewDidMoveToWindowObserver for WKWebView
authorjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Mar 2019 04:38:26 +0000 (04:38 +0000)
committerjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Mar 2019 04:38:26 +0000 (04:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195223
<rdar://problem/48520161>

Reviewed by Darin Adler.

The load optimizer would only allow itself to optimize loads whenever the web view
who owns the page is (visible && focused), otherwises it will wait until the web view
becomes (visible && focused). Therefore, we need a way to notify the load optimizer
changes of statuses.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView didMoveToWindow]):
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::viewDidMoveToWindow):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::addWebViewDidMoveToWindowObserver):
(WebKit::WebPageProxy::removeWebViewDidMoveToWindowObserver):
(WebKit::WebPageProxy::webViewDidMoveToWindow):
* UIProcess/WebPageProxy.h:
* UIProcess/WebViewDidMoveToWindowObserver.h: Added.
* WebKit.xcodeproj/project.pbxproj:

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebViewDidMoveToWindowObserver.h [new file with mode: 0644]
Source/WebKit/WebKit.xcodeproj/project.pbxproj

index 1679d9b..c0104a5 100644 (file)
@@ -1,3 +1,28 @@
+2019-03-03  Jiewen Tan  <jiewen_tan@apple.com>
+
+        Add a WebViewDidMoveToWindowObserver for WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=195223
+        <rdar://problem/48520161>
+
+        Reviewed by Darin Adler.
+
+        The load optimizer would only allow itself to optimize loads whenever the web view
+        who owns the page is (visible && focused), otherwises it will wait until the web view
+        becomes (visible && focused). Therefore, we need a way to notify the load optimizer
+        changes of statuses.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView didMoveToWindow]):
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::viewDidMoveToWindow):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::addWebViewDidMoveToWindowObserver):
+        (WebKit::WebPageProxy::removeWebViewDidMoveToWindowObserver):
+        (WebKit::WebPageProxy::webViewDidMoveToWindow):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebViewDidMoveToWindowObserver.h: Added.
+        * WebKit.xcodeproj/project.pbxproj:
+
 2019-03-03  Andy Estes  <aestes@apple.com>
 
         [Apple Pay] Untangle WebPageProxy and WebPaymentCoordinatorProxy
 2019-03-03  Andy Estes  <aestes@apple.com>
 
         [Apple Pay] Untangle WebPageProxy and WebPaymentCoordinatorProxy
index 0153d48..5725848 100644 (file)
@@ -2488,6 +2488,7 @@ static WebCore::FloatPoint constrainContentOffset(WebCore::FloatPoint contentOff
 - (void)didMoveToWindow
 {
     _page->activityStateDidChange(WebCore::ActivityState::allFlags());
 - (void)didMoveToWindow
 {
     _page->activityStateDidChange(WebCore::ActivityState::allFlags());
+    _page->webViewDidMoveToWindow();
 }
 
 - (void)setOpaque:(BOOL)opaque
 }
 
 - (void)setOpaque:(BOOL)opaque
index 07994e7..5f235f4 100644 (file)
@@ -2217,6 +2217,7 @@ void WebViewImpl::viewDidMoveToWindow()
     }
 
     m_page->setIntrinsicDeviceScaleFactor(intrinsicDeviceScaleFactor());
     }
 
     m_page->setIntrinsicDeviceScaleFactor(intrinsicDeviceScaleFactor());
+    m_page->webViewDidMoveToWindow();
 }
 
 void WebViewImpl::viewDidChangeBackingProperties()
 }
 
 void WebViewImpl::viewDidChangeBackingProperties()
index f8ec560..71c457b 100644 (file)
 #include "WebResourceLoadStatisticsStore.h"
 #include "WebURLSchemeHandler.h"
 #include "WebUserContentControllerProxy.h"
 #include "WebResourceLoadStatisticsStore.h"
 #include "WebURLSchemeHandler.h"
 #include "WebUserContentControllerProxy.h"
+#include "WebViewDidMoveToWindowObserver.h"
 #include "WebsiteDataStore.h"
 #include <WebCore/AdClickAttribution.h>
 #include <WebCore/BitmapImage.h>
 #include "WebsiteDataStore.h"
 #include <WebCore/AdClickAttribution.h>
 #include <WebCore/BitmapImage.h>
@@ -8782,6 +8783,27 @@ uint64_t WebPageProxy::paymentCoordinatorDestinationID(const WebPaymentCoordinat
 
 #endif
 
 
 #endif
 
+void WebPageProxy::addObserver(WebViewDidMoveToWindowObserver& observer)
+{
+    auto result = m_webViewDidMoveToWindowObservers.add(&observer, makeWeakPtr(observer));
+    ASSERT_UNUSED(result, result.isNewEntry);
+}
+
+void WebPageProxy::removeObserver(WebViewDidMoveToWindowObserver& observer)
+{
+    auto result = m_webViewDidMoveToWindowObservers.remove(&observer);
+    ASSERT_UNUSED(result, result);
+}
+
+void WebPageProxy::webViewDidMoveToWindow()
+{
+    for (const auto& observer : m_webViewDidMoveToWindowObservers) {
+        if (!observer.value)
+            continue;
+        observer.value->webViewDidMoveToWindow();
+    }
+}
+
 } // namespace WebKit
 
 #undef MERGE_WHEEL_EVENTS
 } // namespace WebKit
 
 #undef MERGE_WHEEL_EVENTS
index 8fca6bb..cee8976 100644 (file)
@@ -228,6 +228,7 @@ typedef HWND PlatformWidget;
 namespace WebKit {
 class DrawingAreaProxy;
 class EditableImageController;
 namespace WebKit {
 class DrawingAreaProxy;
 class EditableImageController;
+class GamepadData;
 class NativeWebGestureEvent;
 class NativeWebKeyboardEvent;
 class NativeWebMouseEvent;
 class NativeWebGestureEvent;
 class NativeWebKeyboardEvent;
 class NativeWebMouseEvent;
@@ -263,7 +264,7 @@ class WebProcessProxy;
 class WebUserContentControllerProxy;
 class WebWheelEvent;
 class WebsiteDataStore;
 class WebUserContentControllerProxy;
 class WebWheelEvent;
 class WebsiteDataStore;
-class GamepadData;
+class WebViewDidMoveToWindowObserver;
 
 struct AttributedString;
 struct ColorSpaceData;
 
 struct AttributedString;
 struct ColorSpaceData;
@@ -1470,6 +1471,10 @@ public:
     void dumpAdClickAttribution(CompletionHandler<void(const String&)>&&);
     void clearAdClickAttribution(CompletionHandler<void()>&&);
 
     void dumpAdClickAttribution(CompletionHandler<void(const String&)>&&);
     void clearAdClickAttribution(CompletionHandler<void()>&&);
 
+    void addObserver(WebViewDidMoveToWindowObserver&);
+    void removeObserver(WebViewDidMoveToWindowObserver&);
+    void webViewDidMoveToWindow();
+
     // IPC::MessageReceiver
     // Implemented in generated WebPageProxyMessageReceiver.cpp
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
     // IPC::MessageReceiver
     // Implemented in generated WebPageProxyMessageReceiver.cpp
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
@@ -2402,6 +2407,8 @@ private:
 #if HAVE(PENCILKIT)
     std::unique_ptr<EditableImageController> m_editableImageController;
 #endif
 #if HAVE(PENCILKIT)
     std::unique_ptr<EditableImageController> m_editableImageController;
 #endif
+
+    HashMap<WebViewDidMoveToWindowObserver*, WeakPtr<WebViewDidMoveToWindowObserver>> m_webViewDidMoveToWindowObservers;
 };
 
 } // namespace WebKit
 };
 
 } // namespace WebKit
diff --git a/Source/WebKit/UIProcess/WebViewDidMoveToWindowObserver.h b/Source/WebKit/UIProcess/WebViewDidMoveToWindowObserver.h
new file mode 100644 (file)
index 0000000..64bf832
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <wtf/WeakPtr.h>
+
+namespace WebKit {
+
+class WebViewDidMoveToWindowObserver : public CanMakeWeakPtr<WebViewDidMoveToWindowObserver> {
+public:
+    virtual ~WebViewDidMoveToWindowObserver() = default;
+
+    virtual void webViewDidMoveToWindow() = 0;
+};
+
+} // namespace WebKit
index e7e1dbf..edb0593 100644 (file)
                53BA47D11DC2EF5E004DF4AD /* NetworkDataTaskBlob.h in Headers */ = {isa = PBXBuildFile; fileRef = 539EB5471DC2EE40009D48CF /* NetworkDataTaskBlob.h */; };
                53CFBBC82224D1B500266546 /* TextCheckerCompletion.h in Headers */ = {isa = PBXBuildFile; fileRef = 53CFBBC72224D1B000266546 /* TextCheckerCompletion.h */; };
                570AB8F320AE3BD700B8BE87 /* SecKeyProxyStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 570AB8F220AE3BD700B8BE87 /* SecKeyProxyStore.h */; };
                53BA47D11DC2EF5E004DF4AD /* NetworkDataTaskBlob.h in Headers */ = {isa = PBXBuildFile; fileRef = 539EB5471DC2EE40009D48CF /* NetworkDataTaskBlob.h */; };
                53CFBBC82224D1B500266546 /* TextCheckerCompletion.h in Headers */ = {isa = PBXBuildFile; fileRef = 53CFBBC72224D1B000266546 /* TextCheckerCompletion.h */; };
                570AB8F320AE3BD700B8BE87 /* SecKeyProxyStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 570AB8F220AE3BD700B8BE87 /* SecKeyProxyStore.h */; };
+               572FD44322265CE200A1ECC3 /* WebViewDidMoveToWindowObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 572FD44122265CE200A1ECC3 /* WebViewDidMoveToWindowObserver.h */; };
                57597EB921811D9A0037F924 /* CtapHidDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 57597EB721811D9A0037F924 /* CtapHidDriver.h */; };
                57597EBD218184900037F924 /* CtapHidAuthenticator.h in Headers */ = {isa = PBXBuildFile; fileRef = 57597EBB2181848F0037F924 /* CtapHidAuthenticator.h */; };
                5772F206217DBD6A0056BF2C /* HidService.h in Headers */ = {isa = PBXBuildFile; fileRef = 5772F204217DBD6A0056BF2C /* HidService.h */; };
                57597EB921811D9A0037F924 /* CtapHidDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 57597EB721811D9A0037F924 /* CtapHidDriver.h */; };
                57597EBD218184900037F924 /* CtapHidAuthenticator.h in Headers */ = {isa = PBXBuildFile; fileRef = 57597EBB2181848F0037F924 /* CtapHidAuthenticator.h */; };
                5772F206217DBD6A0056BF2C /* HidService.h in Headers */ = {isa = PBXBuildFile; fileRef = 5772F204217DBD6A0056BF2C /* HidService.h */; };
                570AB8F220AE3BD700B8BE87 /* SecKeyProxyStore.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SecKeyProxyStore.h; sourceTree = "<group>"; };
                570AB90020B2517400B8BE87 /* AuthenticationChallengeProxyCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AuthenticationChallengeProxyCocoa.mm; sourceTree = "<group>"; };
                570AB90320B2541C00B8BE87 /* SecKeyProxyStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SecKeyProxyStore.mm; sourceTree = "<group>"; };
                570AB8F220AE3BD700B8BE87 /* SecKeyProxyStore.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SecKeyProxyStore.h; sourceTree = "<group>"; };
                570AB90020B2517400B8BE87 /* AuthenticationChallengeProxyCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AuthenticationChallengeProxyCocoa.mm; sourceTree = "<group>"; };
                570AB90320B2541C00B8BE87 /* SecKeyProxyStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SecKeyProxyStore.mm; sourceTree = "<group>"; };
+               572FD44122265CE200A1ECC3 /* WebViewDidMoveToWindowObserver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebViewDidMoveToWindowObserver.h; sourceTree = "<group>"; };
                575075A720AB763600693EA9 /* WebCredentialMac.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCredentialMac.mm; sourceTree = "<group>"; };
                5750F32A2032D4E500389347 /* LocalAuthentication.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = LocalAuthentication.framework; path = System/Library/Frameworks/LocalAuthentication.framework; sourceTree = SDKROOT; };
                5756DD74218D104900D4EE6A /* MockHidService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockHidService.h; sourceTree = "<group>"; };
                575075A720AB763600693EA9 /* WebCredentialMac.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCredentialMac.mm; sourceTree = "<group>"; };
                5750F32A2032D4E500389347 /* LocalAuthentication.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = LocalAuthentication.framework; path = System/Library/Frameworks/LocalAuthentication.framework; sourceTree = SDKROOT; };
                5756DD74218D104900D4EE6A /* MockHidService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockHidService.h; sourceTree = "<group>"; };
                                51D124251E6D3CC3002B2820 /* WebURLSchemeHandler.h */,
                                51E8B68D1E712873001B7132 /* WebURLSchemeTask.cpp */,
                                51D124271E6D3F1F002B2820 /* WebURLSchemeTask.h */,
                                51D124251E6D3CC3002B2820 /* WebURLSchemeHandler.h */,
                                51E8B68D1E712873001B7132 /* WebURLSchemeTask.cpp */,
                                51D124271E6D3F1F002B2820 /* WebURLSchemeTask.h */,
+                               572FD44122265CE200A1ECC3 /* WebViewDidMoveToWindowObserver.h */,
                        );
                        path = UIProcess;
                        sourceTree = "<group>";
                        );
                        path = UIProcess;
                        sourceTree = "<group>";
                                C54256BA18BEC18C00DE4179 /* WKFormSelectControl.h in Headers */,
                                0F08CF521D63C13A00B48DF1 /* WKFormSelectPicker.h in Headers */,
                                0F08CF541D63C14000B48DF1 /* WKFormSelectPopover.h in Headers */,
                                C54256BA18BEC18C00DE4179 /* WKFormSelectControl.h in Headers */,
                                0F08CF521D63C13A00B48DF1 /* WKFormSelectPicker.h in Headers */,
                                0F08CF541D63C14000B48DF1 /* WKFormSelectPopover.h in Headers */,
+                               572FD44322265CE200A1ECC3 /* WebViewDidMoveToWindowObserver.h in Headers */,
                                BCE4695A1214EDF4000B98EB /* WKFormSubmissionListener.h in Headers */,
                                37DFA7001810BB92001F4A9F /* WKFoundation.h in Headers */,
                                BCD0139B110FA420003B8A67 /* WKFrame.h in Headers */,
                                BCE4695A1214EDF4000B98EB /* WKFormSubmissionListener.h in Headers */,
                                37DFA7001810BB92001F4A9F /* WKFoundation.h in Headers */,
                                BCD0139B110FA420003B8A67 /* WKFrame.h in Headers */,