- Revision
- 242336
- Author
- [email protected]
- Date
- 2019-03-03 20:38:26 -0800 (Sun, 03 Mar 2019)
Log Message
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:
Modified Paths
Added Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (242335 => 242336)
--- trunk/Source/WebKit/ChangeLog 2019-03-04 04:37:11 UTC (rev 242335)
+++ trunk/Source/WebKit/ChangeLog 2019-03-04 04:38:26 UTC (rev 242336)
@@ -1,3 +1,28 @@
+2019-03-03 Jiewen Tan <[email protected]>
+
+ 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 <[email protected]>
[Apple Pay] Untangle WebPageProxy and WebPaymentCoordinatorProxy
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (242335 => 242336)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2019-03-04 04:37:11 UTC (rev 242335)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2019-03-04 04:38:26 UTC (rev 242336)
@@ -2488,6 +2488,7 @@
- (void)didMoveToWindow
{
_page->activityStateDidChange(WebCore::ActivityState::allFlags());
+ _page->webViewDidMoveToWindow();
}
- (void)setOpaque:(BOOL)opaque
Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (242335 => 242336)
--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm 2019-03-04 04:37:11 UTC (rev 242335)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm 2019-03-04 04:38:26 UTC (rev 242336)
@@ -2217,6 +2217,7 @@
}
m_page->setIntrinsicDeviceScaleFactor(intrinsicDeviceScaleFactor());
+ m_page->webViewDidMoveToWindow();
}
void WebViewImpl::viewDidChangeBackingProperties()
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (242335 => 242336)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2019-03-04 04:37:11 UTC (rev 242335)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2019-03-04 04:38:26 UTC (rev 242336)
@@ -128,6 +128,7 @@
#include "WebResourceLoadStatisticsStore.h"
#include "WebURLSchemeHandler.h"
#include "WebUserContentControllerProxy.h"
+#include "WebViewDidMoveToWindowObserver.h"
#include "WebsiteDataStore.h"
#include <WebCore/AdClickAttribution.h>
#include <WebCore/BitmapImage.h>
@@ -8782,6 +8783,27 @@
#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
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (242335 => 242336)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.h 2019-03-04 04:37:11 UTC (rev 242335)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h 2019-03-04 04:38:26 UTC (rev 242336)
@@ -228,6 +228,7 @@
namespace WebKit {
class DrawingAreaProxy;
class EditableImageController;
+class GamepadData;
class NativeWebGestureEvent;
class NativeWebKeyboardEvent;
class NativeWebMouseEvent;
@@ -263,7 +264,7 @@
class WebUserContentControllerProxy;
class WebWheelEvent;
class WebsiteDataStore;
-class GamepadData;
+class WebViewDidMoveToWindowObserver;
struct AttributedString;
struct ColorSpaceData;
@@ -1470,6 +1471,10 @@
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;
@@ -2402,6 +2407,8 @@
#if HAVE(PENCILKIT)
std::unique_ptr<EditableImageController> m_editableImageController;
#endif
+
+ HashMap<WebViewDidMoveToWindowObserver*, WeakPtr<WebViewDidMoveToWindowObserver>> m_webViewDidMoveToWindowObservers;
};
} // namespace WebKit
Added: trunk/Source/WebKit/UIProcess/WebViewDidMoveToWindowObserver.h (0 => 242336)
--- trunk/Source/WebKit/UIProcess/WebViewDidMoveToWindowObserver.h (rev 0)
+++ trunk/Source/WebKit/UIProcess/WebViewDidMoveToWindowObserver.h 2019-03-04 04:38:26 UTC (rev 242336)
@@ -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
Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (242335 => 242336)
--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2019-03-04 04:37:11 UTC (rev 242335)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2019-03-04 04:38:26 UTC (rev 242336)
@@ -1019,6 +1019,7 @@
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 */; };
@@ -3356,6 +3357,7 @@
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>"; };
@@ -7515,6 +7517,7 @@
51D124251E6D3CC3002B2820 /* WebURLSchemeHandler.h */,
51E8B68D1E712873001B7132 /* WebURLSchemeTask.cpp */,
51D124271E6D3F1F002B2820 /* WebURLSchemeTask.h */,
+ 572FD44122265CE200A1ECC3 /* WebViewDidMoveToWindowObserver.h */,
);
path = UIProcess;
sourceTree = "<group>";
@@ -9741,6 +9744,7 @@
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 */,