2 * Copyright (C) 2010, 2011, 2015 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Intel Corporation. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
28 #include "WebPageProxy.h"
31 #include "APIContextMenuClient.h"
32 #include "APIFindClient.h"
33 #include "APIFindMatchesClient.h"
34 #include "APIFormClient.h"
35 #include "APIFrameInfo.h"
36 #include "APIGeometry.h"
37 #include "APIHistoryClient.h"
38 #include "APIHitTestResult.h"
39 #include "APILegacyContextHistoryClient.h"
40 #include "APILoaderClient.h"
41 #include "APINavigation.h"
42 #include "APINavigationAction.h"
43 #include "APINavigationClient.h"
44 #include "APINavigationResponse.h"
45 #include "APIPageConfiguration.h"
46 #include "APIPolicyClient.h"
47 #include "APISecurityOrigin.h"
48 #include "APIUIClient.h"
49 #include "APIURLRequest.h"
50 #include "AuthenticationChallengeProxy.h"
51 #include "AuthenticationDecisionListener.h"
52 #include "DataReference.h"
53 #include "DownloadProxy.h"
54 #include "DrawingAreaProxy.h"
55 #include "DrawingAreaProxyMessages.h"
56 #include "EventDispatcherMessages.h"
58 #include "NativeWebGestureEvent.h"
59 #include "NativeWebKeyboardEvent.h"
60 #include "NativeWebMouseEvent.h"
61 #include "NativeWebWheelEvent.h"
62 #include "NavigationActionData.h"
63 #include "NetworkProcessMessages.h"
64 #include "NotificationPermissionRequest.h"
65 #include "NotificationPermissionRequestManager.h"
66 #include "PageClient.h"
67 #include "PluginInformation.h"
68 #include "PluginProcessManager.h"
69 #include "PrintInfo.h"
70 #include "TextChecker.h"
71 #include "TextCheckerState.h"
72 #include "UserMediaPermissionRequestProxy.h"
73 #include "WKContextPrivate.h"
74 #include "WebBackForwardList.h"
75 #include "WebBackForwardListItem.h"
76 #include "WebCertificateInfo.h"
77 #include "WebContextMenuItem.h"
78 #include "WebContextMenuProxy.h"
79 #include "WebCoreArgumentCoders.h"
80 #include "WebEditCommandProxy.h"
82 #include "WebEventConversion.h"
83 #include "WebFormSubmissionListenerProxy.h"
84 #include "WebFramePolicyListenerProxy.h"
85 #include "WebFullScreenManagerProxy.h"
86 #include "WebFullScreenManagerProxyMessages.h"
88 #include "WebInspectorProxy.h"
89 #include "WebInspectorProxyMessages.h"
90 #include "WebNavigationState.h"
91 #include "WebNotificationManagerProxy.h"
92 #include "WebOpenPanelParameters.h"
93 #include "WebOpenPanelResultListenerProxy.h"
94 #include "WebPageCreationParameters.h"
95 #include "WebPageGroup.h"
96 #include "WebPageGroupData.h"
97 #include "WebPageMessages.h"
98 #include "WebPageProxyMessages.h"
99 #include "WebPopupItem.h"
100 #include "WebPopupMenuProxy.h"
101 #include "WebPreferences.h"
102 #include "WebProcessMessages.h"
103 #include "WebProcessPool.h"
104 #include "WebProcessProxy.h"
105 #include "WebProtectionSpace.h"
106 #include "WebUserContentControllerProxy.h"
107 #include "WebsiteDataStore.h"
108 #include <WebCore/BitmapImage.h>
109 #include <WebCore/DiagnosticLoggingClient.h>
110 #include <WebCore/DragController.h>
111 #include <WebCore/DragData.h>
112 #include <WebCore/FloatRect.h>
113 #include <WebCore/FocusDirection.h>
114 #include <WebCore/JSDOMBinding.h>
115 #include <WebCore/MIMETypeRegistry.h>
116 #include <WebCore/RenderEmbeddedObject.h>
117 #include <WebCore/SerializedCryptoKeyWrap.h>
118 #include <WebCore/TextCheckerClient.h>
119 #include <WebCore/TextIndicator.h>
120 #include <WebCore/URL.h>
121 #include <WebCore/WindowFeatures.h>
123 #include <wtf/NeverDestroyed.h>
124 #include <wtf/text/StringView.h>
126 #if ENABLE(ASYNC_SCROLLING)
127 #include "RemoteScrollingCoordinatorProxy.h"
130 #if USE(COORDINATED_GRAPHICS_MULTIPROCESS)
131 #include "CoordinatedLayerTreeHostProxyMessages.h"
134 #if ENABLE(VIBRATION)
135 #include "WebVibrationProxy.h"
139 #include <wtf/RefCountedLeakCounter.h>
143 #include "RemoteLayerTreeDrawingAreaProxy.h"
144 #include "RemoteLayerTreeScrollingPerformanceData.h"
145 #include "ViewSnapshotStore.h"
146 #include <WebCore/MachSendRight.h>
147 #include <WebCore/RunLoopObserver.h>
148 #include <WebCore/TextIndicatorWindow.h>
152 #include "WebVideoFullscreenManagerProxy.h"
153 #include "WebVideoFullscreenManagerProxyMessages.h"
157 #include <WebCore/CairoUtilities.h>
160 #if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS)
161 #include <WebCore/MediaPlaybackTarget.h>
162 #include <WebCore/WebMediaSessionManager.h>
165 #if ENABLE(MEDIA_SESSION)
166 #include "WebMediaSessionFocusManager.h"
167 #include "WebMediaSessionMetadata.h"
168 #include <WebCore/MediaSessionMetadata.h>
171 // This controls what strategy we use for mouse wheel coalescing.
172 #define MERGE_WHEEL_EVENTS 1
174 #define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, m_process->connection())
175 #define MESSAGE_CHECK_URL(url) MESSAGE_CHECK_BASE(m_process->checkURLReceivedFromWebProcess(url), m_process->connection())
177 using namespace WebCore;
179 // Represents the number of wheel events we can hold in the queue before we start pushing them preemptively.
180 static const unsigned wheelEventQueueSizeThreshold = 10;
184 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, webPageProxyCounter, ("WebPageProxy"));
186 class ExceededDatabaseQuotaRecords {
187 WTF_MAKE_NONCOPYABLE(ExceededDatabaseQuotaRecords); WTF_MAKE_FAST_ALLOCATED;
188 friend class NeverDestroyed<ExceededDatabaseQuotaRecords>;
192 String originIdentifier;
195 uint64_t currentQuota;
196 uint64_t currentOriginUsage;
197 uint64_t currentDatabaseUsage;
198 uint64_t expectedUsage;
199 RefPtr<Messages::WebPageProxy::ExceededDatabaseQuota::DelayedReply> reply;
202 static ExceededDatabaseQuotaRecords& singleton();
204 std::unique_ptr<Record> createRecord(uint64_t frameID, String originIdentifier,
205 String databaseName, String displayName, uint64_t currentQuota,
206 uint64_t currentOriginUsage, uint64_t currentDatabaseUsage, uint64_t expectedUsage,
207 PassRefPtr<Messages::WebPageProxy::ExceededDatabaseQuota::DelayedReply>);
209 void add(std::unique_ptr<Record>);
210 bool areBeingProcessed() const { return !!m_currentRecord; }
214 ExceededDatabaseQuotaRecords() { }
215 ~ExceededDatabaseQuotaRecords() { }
217 Deque<std::unique_ptr<Record>> m_records;
218 std::unique_ptr<Record> m_currentRecord;
221 ExceededDatabaseQuotaRecords& ExceededDatabaseQuotaRecords::singleton()
223 static NeverDestroyed<ExceededDatabaseQuotaRecords> records;
227 std::unique_ptr<ExceededDatabaseQuotaRecords::Record> ExceededDatabaseQuotaRecords::createRecord(
228 uint64_t frameID, String originIdentifier, String databaseName, String displayName,
229 uint64_t currentQuota, uint64_t currentOriginUsage, uint64_t currentDatabaseUsage,
230 uint64_t expectedUsage, PassRefPtr<Messages::WebPageProxy::ExceededDatabaseQuota::DelayedReply> reply)
232 auto record = std::make_unique<Record>();
233 record->frameID = frameID;
234 record->originIdentifier = originIdentifier;
235 record->databaseName = databaseName;
236 record->displayName = displayName;
237 record->currentQuota = currentQuota;
238 record->currentOriginUsage = currentOriginUsage;
239 record->currentDatabaseUsage = currentDatabaseUsage;
240 record->expectedUsage = expectedUsage;
241 record->reply = reply;
242 return WTF::move(record);
245 void ExceededDatabaseQuotaRecords::add(std::unique_ptr<ExceededDatabaseQuotaRecords::Record> record)
247 m_records.append(WTF::move(record));
250 ExceededDatabaseQuotaRecords::Record* ExceededDatabaseQuotaRecords::next()
252 m_currentRecord = nullptr;
253 if (!m_records.isEmpty())
254 m_currentRecord = m_records.takeFirst();
255 return m_currentRecord.get();
259 static const char* webKeyboardEventTypeString(WebEvent::Type type)
262 case WebEvent::KeyDown:
265 case WebEvent::KeyUp:
268 case WebEvent::RawKeyDown:
275 ASSERT_NOT_REACHED();
279 #endif // !LOG_DISABLED
281 class PageClientProtector {
282 WTF_MAKE_NONCOPYABLE(PageClientProtector);
284 PageClientProtector(PageClient& pageClient)
285 : m_pageClient(pageClient)
287 m_pageClient.refView();
290 ~PageClientProtector()
292 m_pageClient.derefView();
296 PageClient& m_pageClient;
299 Ref<WebPageProxy> WebPageProxy::create(PageClient& pageClient, WebProcessProxy& process, uint64_t pageID, Ref<API::PageConfiguration>&& configuration)
301 return adoptRef(*new WebPageProxy(pageClient, process, pageID, WTF::move(configuration)));
304 WebPageProxy::WebPageProxy(PageClient& pageClient, WebProcessProxy& process, uint64_t pageID, Ref<API::PageConfiguration>&& configuration)
305 : m_pageClient(pageClient)
306 , m_configuration(WTF::move(configuration))
307 , m_loaderClient(std::make_unique<API::LoaderClient>())
308 , m_policyClient(std::make_unique<API::PolicyClient>())
309 , m_formClient(std::make_unique<API::FormClient>())
310 , m_uiClient(std::make_unique<API::UIClient>())
311 , m_findClient(std::make_unique<API::FindClient>())
312 , m_findMatchesClient(std::make_unique<API::FindMatchesClient>())
313 , m_diagnosticLoggingClient(std::make_unique<API::DiagnosticLoggingClient>())
314 #if ENABLE(CONTEXT_MENUS)
315 , m_contextMenuClient(std::make_unique<API::ContextMenuClient>())
317 , m_navigationState(std::make_unique<WebNavigationState>())
319 , m_pageGroup(*m_configuration->pageGroup())
320 , m_preferences(*m_configuration->preferences())
321 , m_userContentController(m_configuration->userContentController())
322 , m_visitedLinkStore(*m_configuration->visitedLinkStore())
323 , m_websiteDataStore(m_configuration->websiteDataStore()->websiteDataStore())
324 , m_mainFrame(nullptr)
325 , m_userAgent(standardUserAgent())
326 , m_treatsSHA1CertificatesAsInsecure(m_configuration->treatsSHA1SignedCertificatesAsInsecure())
328 , m_hasReceivedLayerTreeTransactionAfterDidCommitLoad(true)
329 , m_firstLayerTreeTransactionIdAfterDidCommitLoad(0)
330 , m_deviceOrientation(0)
331 , m_dynamicViewportSizeUpdateWaitingForTarget(false)
332 , m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit(false)
333 , m_dynamicViewportSizeUpdateLayerTreeTransactionID(0)
334 , m_layerTreeTransactionIdAtLastTouchStart(0)
335 , m_hasNetworkRequestsOnSuspended(false)
337 , m_geolocationPermissionRequestManager(*this)
338 , m_notificationPermissionRequestManager(*this)
339 , m_userMediaPermissionRequestManager(*this)
340 , m_viewState(ViewState::NoFlags)
341 , m_viewWasEverInWindow(false)
343 , m_alwaysRunsAtForegroundPriority(m_configuration->alwaysRunsAtForegroundPriority())
345 , m_backForwardList(WebBackForwardList::create(*this))
346 , m_maintainsInactiveSelection(false)
347 , m_isEditable(false)
348 , m_textZoomFactor(1)
349 , m_pageZoomFactor(1)
350 , m_pageScaleFactor(1)
351 , m_pluginZoomFactor(1)
352 , m_pluginScaleFactor(1)
353 , m_intrinsicDeviceScaleFactor(1)
354 , m_customDeviceScaleFactor(0)
355 , m_topContentInset(0)
356 , m_layerHostingMode(LayerHostingMode::InProcess)
357 , m_drawsBackground(true)
358 , m_useFixedLayout(false)
359 , m_suppressScrollbarAnimations(false)
360 , m_paginationMode(Pagination::Unpaginated)
361 , m_paginationBehavesLikeColumns(false)
363 , m_gapBetweenPages(0)
366 , m_canRunModal(false)
367 , m_isInPrintingMode(false)
368 , m_isPerformingDOMPrintOperation(false)
369 , m_inDecidePolicyForResponseSync(false)
370 , m_decidePolicyForResponseRequest(0)
371 , m_syncMimeTypePolicyActionIsValid(false)
372 , m_syncMimeTypePolicyAction(PolicyUse)
373 , m_syncMimeTypePolicyDownloadID(0)
374 , m_inDecidePolicyForNavigationAction(false)
375 , m_syncNavigationActionPolicyActionIsValid(false)
376 , m_syncNavigationActionPolicyAction(PolicyUse)
377 , m_syncNavigationActionPolicyDownloadID(0)
378 , m_processingMouseMoveEvent(false)
379 #if ENABLE(TOUCH_EVENTS)
380 , m_isTrackingTouchEvents(false)
383 , m_sessionID(m_configuration->sessionID())
384 , m_isPageSuspended(false)
385 , m_addsVisitedLinks(true)
386 #if ENABLE(REMOTE_INSPECTOR)
387 , m_allowsRemoteInspection(true)
390 , m_isSmartInsertDeleteEnabled(TextChecker::isSmartInsertDeleteEnabled())
393 , m_backgroundColor(Color::white)
395 , m_spellDocumentTag(0)
396 , m_hasSpellDocumentTag(false)
397 , m_pendingLearnOrIgnoreWordMessageCount(0)
398 , m_mainFrameHasCustomContentProvider(false)
399 #if ENABLE(DRAG_SUPPORT)
400 , m_currentDragOperation(DragOperationNone)
401 , m_currentDragIsOverFileInput(false)
402 , m_currentDragNumberOfFilesToBeAccepted(0)
404 , m_pageLoadState(*this)
405 , m_delegatesScrolling(false)
406 , m_mainFrameHasHorizontalScrollbar(false)
407 , m_mainFrameHasVerticalScrollbar(false)
408 , m_canShortCircuitHorizontalWheelEvents(true)
409 , m_mainFrameIsPinnedToLeftSide(true)
410 , m_mainFrameIsPinnedToRightSide(true)
411 , m_mainFrameIsPinnedToTopSide(true)
412 , m_mainFrameIsPinnedToBottomSide(true)
413 , m_shouldUseImplicitRubberBandControl(false)
414 , m_rubberBandsAtLeft(true)
415 , m_rubberBandsAtRight(true)
416 , m_rubberBandsAtTop(true)
417 , m_rubberBandsAtBottom(true)
418 , m_enableVerticalRubberBanding(true)
419 , m_enableHorizontalRubberBanding(true)
420 , m_backgroundExtendsBeyondPage(false)
421 , m_shouldRecordNavigationSnapshots(false)
422 , m_isShowingNavigationGestureSnapshot(false)
424 , m_renderTreeSize(0)
425 , m_sessionRestorationRenderTreeSize(0)
426 , m_wantsSessionRestorationRenderTreeSizeThresholdEvent(false)
427 , m_hitRenderTreeSizeThreshold(false)
428 , m_suppressVisibilityUpdates(false)
429 , m_autoSizingShouldExpandToViewHeight(false)
432 , m_mayStartMediaWhenInWindow(true)
433 , m_waitingForDidUpdateViewState(false)
435 , m_scrollPerformanceDataCollectionEnabled(false)
437 , m_scrollPinningBehavior(DoNotPin)
439 , m_configurationPreferenceValues(m_configuration->preferenceValues())
440 , m_potentiallyChangedViewStateFlags(ViewState::NoFlags)
441 , m_viewStateChangeWantsSynchronousReply(false)
443 m_webProcessLifetimeTracker.addObserver(m_visitedLinkStore);
444 m_webProcessLifetimeTracker.addObserver(m_websiteDataStore);
446 if (m_process->state() == WebProcessProxy::State::Running) {
447 if (m_userContentController)
448 m_process->addWebUserContentControllerProxy(*m_userContentController);
449 m_process->addVisitedLinkStore(m_visitedLinkStore);
453 updateActivityToken();
454 updateProccessSuppressionState();
456 #if HAVE(OUT_OF_PROCESS_LAYER_HOSTING)
457 m_layerHostingMode = m_viewState & ViewState::IsInWindow ? m_pageClient.viewLayerHostingMode() : LayerHostingMode::OutOfProcess;
460 platformInitialize();
463 webPageProxyCounter.increment();
466 WebProcessPool::statistics().wkPageCount++;
468 m_preferences->addPage(*this);
469 m_pageGroup->addPage(this);
471 m_inspector = WebInspectorProxy::create(this);
472 #if ENABLE(FULLSCREEN_API)
473 m_fullScreenManager = WebFullScreenManagerProxy::create(*this, m_pageClient.fullScreenManagerProxyClient());
476 m_videoFullscreenManager = WebVideoFullscreenManagerProxy::create(*this);
478 #if ENABLE(VIBRATION)
479 m_vibration = WebVibrationProxy::create(this);
482 m_process->addMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID, *this);
484 if (m_sessionID.isEphemeral())
485 m_process->processPool().sendToNetworkingProcess(Messages::NetworkProcess::EnsurePrivateBrowsingSession(m_sessionID));
488 const CFIndex viewStateChangeRunLoopOrder = (CFIndex)RunLoopObserver::WellKnownRunLoopOrders::CoreAnimationCommit - 1;
489 m_viewStateChangeDispatcher = RunLoopObserver::create(viewStateChangeRunLoopOrder, [this] {
490 this->dispatchViewStateChange();
495 WebPageProxy::~WebPageProxy()
497 ASSERT(m_process->webPage(m_pageID) != this);
499 for (WebPageProxy* page : m_process->pages())
500 ASSERT(page != this);
506 WebProcessPool::statistics().wkPageCount--;
508 if (m_hasSpellDocumentTag)
509 TextChecker::closeSpellDocumentWithTag(m_spellDocumentTag);
511 m_preferences->removePage(*this);
512 m_pageGroup->removePage(this);
515 webPageProxyCounter.decrement();
519 const API::PageConfiguration& WebPageProxy::configuration() const
521 return m_configuration.get();
524 PlatformProcessIdentifier WebPageProxy::processIdentifier() const
529 return m_process->processIdentifier();
532 bool WebPageProxy::isValid() const
534 // A page that has been explicitly closed is never valid.
541 void WebPageProxy::setPreferences(WebPreferences& preferences)
543 if (&preferences == m_preferences.ptr())
546 m_preferences->removePage(*this);
547 m_preferences = preferences;
548 m_preferences->addPage(*this);
550 preferencesDidChange();
553 void WebPageProxy::setHistoryClient(std::unique_ptr<API::HistoryClient> historyClient)
555 m_historyClient = WTF::move(historyClient);
558 void WebPageProxy::setNavigationClient(std::unique_ptr<API::NavigationClient> navigationClient)
560 m_navigationClient = WTF::move(navigationClient);
563 void WebPageProxy::setLoaderClient(std::unique_ptr<API::LoaderClient> loaderClient)
566 m_loaderClient = std::make_unique<API::LoaderClient>();
570 m_loaderClient = WTF::move(loaderClient);
573 void WebPageProxy::setPolicyClient(std::unique_ptr<API::PolicyClient> policyClient)
576 m_policyClient = std::make_unique<API::PolicyClient>();
580 m_policyClient = WTF::move(policyClient);
583 void WebPageProxy::setFormClient(std::unique_ptr<API::FormClient> formClient)
586 m_formClient = std::make_unique<API::FormClient>();
590 m_formClient = WTF::move(formClient);
593 void WebPageProxy::setUIClient(std::unique_ptr<API::UIClient> uiClient)
596 m_uiClient = std::make_unique<API::UIClient>();
600 m_uiClient = WTF::move(uiClient);
605 m_process->send(Messages::WebPage::SetCanRunBeforeUnloadConfirmPanel(m_uiClient->canRunBeforeUnloadConfirmPanel()), m_pageID);
606 setCanRunModal(m_uiClient->canRunModal());
609 void WebPageProxy::setFindClient(std::unique_ptr<API::FindClient> findClient)
612 m_findClient = std::make_unique<API::FindClient>();
616 m_findClient = WTF::move(findClient);
619 void WebPageProxy::setFindMatchesClient(std::unique_ptr<API::FindMatchesClient> findMatchesClient)
621 if (!findMatchesClient) {
622 m_findMatchesClient = std::make_unique<API::FindMatchesClient>();
626 m_findMatchesClient = WTF::move(findMatchesClient);
629 void WebPageProxy::setDiagnosticLoggingClient(std::unique_ptr<API::DiagnosticLoggingClient> diagnosticLoggingClient)
631 if (!diagnosticLoggingClient) {
632 m_diagnosticLoggingClient = std::make_unique<API::DiagnosticLoggingClient>();
636 m_diagnosticLoggingClient = WTF::move(diagnosticLoggingClient);
639 #if ENABLE(CONTEXT_MENUS)
640 void WebPageProxy::setContextMenuClient(std::unique_ptr<API::ContextMenuClient> contextMenuClient)
642 if (!contextMenuClient) {
643 m_contextMenuClient = std::make_unique<API::ContextMenuClient>();
647 m_contextMenuClient = WTF::move(contextMenuClient);
651 void WebPageProxy::setInjectedBundleClient(const WKPageInjectedBundleClientBase* client)
654 m_injectedBundleClient = nullptr;
658 m_injectedBundleClient = std::make_unique<WebPageInjectedBundleClient>();
659 m_injectedBundleClient->initialize(client);
662 void WebPageProxy::handleMessage(IPC::Connection& connection, const String& messageName, const WebKit::UserData& messageBody)
664 auto* webProcessProxy = WebProcessProxy::fromConnection(&connection);
665 if (!webProcessProxy || !m_injectedBundleClient)
667 m_injectedBundleClient->didReceiveMessageFromInjectedBundle(this, messageName, webProcessProxy->transformHandlesToObjects(messageBody.object()).get());
670 void WebPageProxy::handleSynchronousMessage(IPC::Connection& connection, const String& messageName, const UserData& messageBody, UserData& returnUserData)
672 if (!WebProcessProxy::fromConnection(&connection) || !m_injectedBundleClient)
675 RefPtr<API::Object> returnData;
676 m_injectedBundleClient->didReceiveSynchronousMessageFromInjectedBundle(this, messageName, WebProcessProxy::fromConnection(&connection)->transformHandlesToObjects(messageBody.object()).get(), returnData);
677 returnUserData = UserData(WebProcessProxy::fromConnection(&connection)->transformObjectsToHandles(returnData.get()));
681 void WebPageProxy::reattachToWebProcess()
685 ASSERT(m_process->state() == WebProcessProxy::State::Terminated);
688 m_process->removeWebPage(m_pageID);
689 m_process->removeMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID);
691 m_process = m_process->processPool().createNewWebProcessRespectingProcessCountLimit();
693 ASSERT(m_process->state() != ChildProcessProxy::State::Terminated);
694 if (m_process->state() == ChildProcessProxy::State::Running)
695 processDidFinishLaunching();
696 m_process->addExistingWebPage(this, m_pageID);
697 m_process->addMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID, *this);
700 updateActivityToken();
702 m_inspector = WebInspectorProxy::create(this);
703 #if ENABLE(FULLSCREEN_API)
704 m_fullScreenManager = WebFullScreenManagerProxy::create(*this, m_pageClient.fullScreenManagerProxyClient());
707 m_videoFullscreenManager = WebVideoFullscreenManagerProxy::create(*this);
712 m_pageClient.didRelaunchProcess();
713 m_drawingArea->waitForBackingStoreUpdateOnNextPaint();
716 RefPtr<API::Navigation> WebPageProxy::reattachToWebProcessForReload()
722 reattachToWebProcess();
724 if (!m_backForwardList->currentItem())
727 auto navigation = m_navigationState->createReloadNavigation();
729 // We allow stale content when reloading a WebProcess that's been killed or crashed.
730 m_process->send(Messages::WebPage::GoToBackForwardItem(navigation->navigationID(), m_backForwardList->currentItem()->itemID()), m_pageID);
731 m_process->responsivenessTimer().start();
733 return WTF::move(navigation);
736 RefPtr<API::Navigation> WebPageProxy::reattachToWebProcessWithItem(WebBackForwardListItem* item)
741 if (item && item != m_backForwardList->currentItem())
742 m_backForwardList->goToItem(item);
745 reattachToWebProcess();
750 auto navigation = m_navigationState->createBackForwardNavigation();
752 m_process->send(Messages::WebPage::GoToBackForwardItem(navigation->navigationID(), item->itemID()), m_pageID);
753 m_process->responsivenessTimer().start();
755 return WTF::move(navigation);
758 void WebPageProxy::setSessionID(SessionID sessionID)
763 m_sessionID = sessionID;
764 m_process->send(Messages::WebPage::SetSessionID(sessionID), m_pageID);
766 if (sessionID.isEphemeral())
767 m_process->processPool().sendToNetworkingProcess(Messages::NetworkProcess::EnsurePrivateBrowsingSession(sessionID));
770 void WebPageProxy::initializeWebPage()
774 BackForwardListItemVector items = m_backForwardList->entries();
775 for (size_t i = 0; i < items.size(); ++i)
776 m_process->registerNewWebBackForwardListItem(items[i].get());
778 m_drawingArea = m_pageClient.createDrawingAreaProxy();
779 ASSERT(m_drawingArea);
781 #if ENABLE(ASYNC_SCROLLING)
782 if (m_drawingArea->type() == DrawingAreaTypeRemoteLayerTree) {
783 m_scrollingCoordinatorProxy = std::make_unique<RemoteScrollingCoordinatorProxy>(*this);
785 // On iOS, main frame scrolls are sent in terms of visible rect updates.
786 m_scrollingCoordinatorProxy->setPropagatesMainFrameScrolls(false);
791 #if ENABLE(INSPECTOR_SERVER)
792 if (m_preferences->developerExtrasEnabled())
793 inspector()->enableRemoteInspection();
796 process().send(Messages::WebProcess::CreateWebPage(m_pageID, creationParameters()), 0);
799 send(Messages::WebPage::SetSmartInsertDeleteEnabled(m_isSmartInsertDeleteEnabled));
803 void WebPageProxy::close()
810 if (m_activePopupMenu)
811 m_activePopupMenu->cancelTracking();
813 #if ENABLE(CONTEXT_MENUS)
814 m_activeContextMenu = nullptr;
817 m_backForwardList->pageClosed();
818 m_pageClient.pageClosed();
820 m_process->disconnectFramesFromPage(this);
822 resetState(ResetStateReason::PageInvalidated);
824 m_loaderClient = std::make_unique<API::LoaderClient>();
825 m_policyClient = std::make_unique<API::PolicyClient>();
826 m_formClient = std::make_unique<API::FormClient>();
827 m_uiClient = std::make_unique<API::UIClient>();
829 m_uiPopupMenuClient.initialize(nullptr);
831 m_findClient = std::make_unique<API::FindClient>();
832 m_findMatchesClient = std::make_unique<API::FindMatchesClient>();
833 m_diagnosticLoggingClient = std::make_unique<API::DiagnosticLoggingClient>();
834 #if ENABLE(CONTEXT_MENUS)
835 m_contextMenuClient = std::make_unique<API::ContextMenuClient>();
838 m_webProcessLifetimeTracker.pageWasInvalidated();
840 m_process->send(Messages::WebPage::Close(), m_pageID);
841 m_process->removeWebPage(m_pageID);
842 m_process->removeMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID);
843 m_process->processPool().supplement<WebNotificationManagerProxy>()->clearNotifications(this);
846 bool WebPageProxy::tryClose()
851 // Close without delay if the process allows it. Our goal is to terminate
852 // the process, so we check a per-process status bit.
853 if (m_process->isSuddenTerminationEnabled())
856 m_process->send(Messages::WebPage::TryClose(), m_pageID);
857 m_process->responsivenessTimer().start();
861 bool WebPageProxy::maybeInitializeSandboxExtensionHandle(const URL& url, SandboxExtension::Handle& sandboxExtensionHandle)
863 if (!url.isLocalFile())
866 if (m_process->hasAssumedReadAccessToURL(url))
869 // Inspector resources are in a directory with assumed access.
870 ASSERT_WITH_SECURITY_IMPLICATION(!WebInspectorProxy::isInspectorPage(*this));
872 SandboxExtension::createHandle("/", SandboxExtension::ReadOnly, sandboxExtensionHandle);
876 RefPtr<API::Navigation> WebPageProxy::loadRequest(const ResourceRequest& request, ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy, API::Object* userData)
881 auto navigation = m_navigationState->createLoadRequestNavigation(request);
883 auto transaction = m_pageLoadState.transaction();
885 m_pageLoadState.setPendingAPIRequestURL(transaction, request.url());
888 reattachToWebProcess();
890 SandboxExtension::Handle sandboxExtensionHandle;
891 bool createdExtension = maybeInitializeSandboxExtensionHandle(request.url(), sandboxExtensionHandle);
892 if (createdExtension)
893 m_process->willAcquireUniversalFileReadSandboxExtension();
894 m_process->send(Messages::WebPage::LoadRequest(navigation->navigationID(), request, sandboxExtensionHandle, (uint64_t)shouldOpenExternalURLsPolicy, UserData(process().transformObjectsToHandles(userData).get())), m_pageID);
895 m_process->responsivenessTimer().start();
897 return WTF::move(navigation);
900 RefPtr<API::Navigation> WebPageProxy::loadFile(const String& fileURLString, const String& resourceDirectoryURLString, API::Object* userData)
906 reattachToWebProcess();
908 URL fileURL = URL(URL(), fileURLString);
909 if (!fileURL.isLocalFile())
912 URL resourceDirectoryURL;
913 if (resourceDirectoryURLString.isNull())
914 resourceDirectoryURL = URL(ParsedURLString, ASCIILiteral("file:///"));
916 resourceDirectoryURL = URL(URL(), resourceDirectoryURLString);
917 if (!resourceDirectoryURL.isLocalFile())
921 auto navigation = m_navigationState->createLoadRequestNavigation(ResourceRequest(fileURL));
923 auto transaction = m_pageLoadState.transaction();
925 m_pageLoadState.setPendingAPIRequestURL(transaction, fileURLString);
927 String resourceDirectoryPath = resourceDirectoryURL.fileSystemPath();
929 SandboxExtension::Handle sandboxExtensionHandle;
930 SandboxExtension::createHandle(resourceDirectoryPath, SandboxExtension::ReadOnly, sandboxExtensionHandle);
931 m_process->assumeReadAccessToBaseURL(resourceDirectoryURL);
932 m_process->send(Messages::WebPage::LoadRequest(navigation->navigationID(), fileURL, sandboxExtensionHandle, (uint64_t)ShouldOpenExternalURLsPolicy::ShouldNotAllow, UserData(process().transformObjectsToHandles(userData).get())), m_pageID);
933 m_process->responsivenessTimer().start();
935 return WTF::move(navigation);
938 RefPtr<API::Navigation> WebPageProxy::loadData(API::Data* data, const String& MIMEType, const String& encoding, const String& baseURL, API::Object* userData)
943 auto navigation = m_navigationState->createLoadDataNavigation();
945 auto transaction = m_pageLoadState.transaction();
947 m_pageLoadState.setPendingAPIRequestURL(transaction, !baseURL.isEmpty() ? baseURL : ASCIILiteral("about:blank"));
950 reattachToWebProcess();
952 m_process->assumeReadAccessToBaseURL(baseURL);
953 m_process->send(Messages::WebPage::LoadData(navigation->navigationID(), data->dataReference(), MIMEType, encoding, baseURL, UserData(process().transformObjectsToHandles(userData).get())), m_pageID);
954 m_process->responsivenessTimer().start();
956 return WTF::move(navigation);
959 // FIXME: Get rid of loadHTMLString and just use loadData instead.
960 RefPtr<API::Navigation> WebPageProxy::loadHTMLString(const String& htmlString, const String& baseURL, API::Object* userData)
965 auto navigation = m_navigationState->createLoadDataNavigation();
967 auto transaction = m_pageLoadState.transaction();
969 m_pageLoadState.setPendingAPIRequestURL(transaction, !baseURL.isEmpty() ? baseURL : ASCIILiteral("about:blank"));
972 reattachToWebProcess();
974 m_process->assumeReadAccessToBaseURL(baseURL);
975 m_process->send(Messages::WebPage::LoadHTMLString(navigation->navigationID(), htmlString, baseURL, UserData(process().transformObjectsToHandles(userData).get())), m_pageID);
976 m_process->responsivenessTimer().start();
978 return WTF::move(navigation);
981 void WebPageProxy::loadAlternateHTMLString(const String& htmlString, const String& baseURL, const String& unreachableURL, API::Object* userData)
987 reattachToWebProcess();
989 auto transaction = m_pageLoadState.transaction();
991 m_pageLoadState.setUnreachableURL(transaction, unreachableURL);
994 m_mainFrame->setUnreachableURL(unreachableURL);
996 m_process->assumeReadAccessToBaseURL(baseURL);
997 m_process->assumeReadAccessToBaseURL(unreachableURL);
998 m_process->send(Messages::WebPage::LoadAlternateHTMLString(htmlString, baseURL, unreachableURL, m_failingProvisionalLoadURL, UserData(process().transformObjectsToHandles(userData).get())), m_pageID);
999 m_process->responsivenessTimer().start();
1002 void WebPageProxy::loadPlainTextString(const String& string, API::Object* userData)
1008 reattachToWebProcess();
1010 m_process->send(Messages::WebPage::LoadPlainTextString(string, UserData(process().transformObjectsToHandles(userData).get())), m_pageID);
1011 m_process->responsivenessTimer().start();
1014 void WebPageProxy::loadWebArchiveData(API::Data* webArchiveData, API::Object* userData)
1020 reattachToWebProcess();
1022 m_process->send(Messages::WebPage::LoadWebArchiveData(webArchiveData->dataReference(), UserData(process().transformObjectsToHandles(userData).get())), m_pageID);
1023 m_process->responsivenessTimer().start();
1026 void WebPageProxy::navigateToPDFLinkWithSimulatedClick(const String& url, IntPoint documentPoint, IntPoint screenPoint)
1031 if (WebCore::protocolIsJavaScript(url))
1035 reattachToWebProcess();
1037 m_process->send(Messages::WebPage::NavigateToPDFLinkWithSimulatedClick(url, documentPoint, screenPoint), m_pageID);
1038 m_process->responsivenessTimer().start();
1041 void WebPageProxy::stopLoading()
1046 m_process->send(Messages::WebPage::StopLoading(), m_pageID);
1047 m_process->responsivenessTimer().start();
1050 RefPtr<API::Navigation> WebPageProxy::reload(bool reloadFromOrigin, bool contentBlockersEnabled)
1052 SandboxExtension::Handle sandboxExtensionHandle;
1054 if (m_backForwardList->currentItem()) {
1055 String url = m_backForwardList->currentItem()->url();
1056 auto transaction = m_pageLoadState.transaction();
1057 m_pageLoadState.setPendingAPIRequestURL(transaction, url);
1059 // We may not have an extension yet if back/forward list was reinstated after a WebProcess crash or a browser relaunch
1060 bool createdExtension = maybeInitializeSandboxExtensionHandle(URL(URL(), url), sandboxExtensionHandle);
1061 if (createdExtension)
1062 m_process->willAcquireUniversalFileReadSandboxExtension();
1066 return reattachToWebProcessForReload();
1068 auto navigation = m_navigationState->createReloadNavigation();
1070 m_process->send(Messages::WebPage::Reload(navigation->navigationID(), reloadFromOrigin, contentBlockersEnabled, sandboxExtensionHandle), m_pageID);
1071 m_process->responsivenessTimer().start();
1073 return WTF::move(navigation);
1076 void WebPageProxy::recordNavigationSnapshot()
1078 if (WebBackForwardListItem* item = m_backForwardList->currentItem())
1079 recordNavigationSnapshot(*item);
1082 void WebPageProxy::recordNavigationSnapshot(WebBackForwardListItem& item)
1084 if (!m_shouldRecordNavigationSnapshots || m_suppressNavigationSnapshotting)
1088 ViewSnapshotStore::singleton().recordSnapshot(*this, item);
1094 RefPtr<API::Navigation> WebPageProxy::goForward()
1096 WebBackForwardListItem* forwardItem = m_backForwardList->forwardItem();
1100 auto transaction = m_pageLoadState.transaction();
1102 m_pageLoadState.setPendingAPIRequestURL(transaction, forwardItem->url());
1105 return reattachToWebProcessWithItem(forwardItem);
1107 RefPtr<API::Navigation> navigation;
1108 if (!m_backForwardList->currentItem()->itemIsInSameDocument(*forwardItem))
1109 navigation = m_navigationState->createBackForwardNavigation();
1111 m_process->send(Messages::WebPage::GoForward(navigation ? navigation->navigationID() : 0, forwardItem->itemID()), m_pageID);
1112 m_process->responsivenessTimer().start();
1117 RefPtr<API::Navigation> WebPageProxy::goBack()
1119 WebBackForwardListItem* backItem = m_backForwardList->backItem();
1123 auto transaction = m_pageLoadState.transaction();
1125 m_pageLoadState.setPendingAPIRequestURL(transaction, backItem->url());
1128 return reattachToWebProcessWithItem(backItem);
1130 RefPtr<API::Navigation> navigation;
1131 if (!m_backForwardList->currentItem()->itemIsInSameDocument(*backItem))
1132 navigation = m_navigationState->createBackForwardNavigation();
1134 m_process->send(Messages::WebPage::GoBack(navigation ? navigation->navigationID() : 0, backItem->itemID()), m_pageID);
1135 m_process->responsivenessTimer().start();
1140 RefPtr<API::Navigation> WebPageProxy::goToBackForwardItem(WebBackForwardListItem* item)
1143 return reattachToWebProcessWithItem(item);
1145 auto transaction = m_pageLoadState.transaction();
1147 m_pageLoadState.setPendingAPIRequestURL(transaction, item->url());
1149 RefPtr<API::Navigation> navigation;
1150 if (!m_backForwardList->currentItem()->itemIsInSameDocument(*item))
1151 navigation = m_navigationState->createBackForwardNavigation();
1153 m_process->send(Messages::WebPage::GoToBackForwardItem(navigation ? navigation->navigationID() : 0, item->itemID()), m_pageID);
1154 m_process->responsivenessTimer().start();
1159 void WebPageProxy::tryRestoreScrollPosition()
1164 m_process->send(Messages::WebPage::TryRestoreScrollPosition(), m_pageID);
1167 void WebPageProxy::didChangeBackForwardList(WebBackForwardListItem* added, Vector<RefPtr<WebBackForwardListItem>> removed)
1169 PageClientProtector protector(m_pageClient);
1171 m_loaderClient->didChangeBackForwardList(*this, added, WTF::move(removed));
1173 auto transaction = m_pageLoadState.transaction();
1175 m_pageLoadState.setCanGoBack(transaction, m_backForwardList->backItem());
1176 m_pageLoadState.setCanGoForward(transaction, m_backForwardList->forwardItem());
1179 void WebPageProxy::willGoToBackForwardListItem(uint64_t itemID, const UserData& userData)
1181 PageClientProtector protector(m_pageClient);
1183 if (WebBackForwardListItem* item = m_process->webBackForwardItem(itemID))
1184 m_loaderClient->willGoToBackForwardListItem(*this, item, m_process->transformHandlesToObjects(userData.object()).get());
1187 bool WebPageProxy::shouldKeepCurrentBackForwardListItemInList(WebBackForwardListItem* item)
1189 PageClientProtector protector(m_pageClient);
1191 return m_loaderClient->shouldKeepCurrentBackForwardListItemInList(*this, item);
1194 bool WebPageProxy::canShowMIMEType(const String& mimeType)
1196 if (MIMETypeRegistry::canShowMIMEType(mimeType))
1199 #if ENABLE(NETSCAPE_PLUGIN_API)
1200 String newMimeType = mimeType;
1201 PluginModuleInfo plugin = m_process->processPool().pluginInfoStore().findPlugin(newMimeType, URL());
1202 if (!plugin.path.isNull() && m_preferences->pluginsEnabled())
1204 #endif // ENABLE(NETSCAPE_PLUGIN_API)
1207 // On Mac, we can show PDFs.
1208 if (MIMETypeRegistry::isPDFOrPostScriptMIMEType(mimeType) && !WebProcessPool::omitPDFSupport())
1210 #endif // PLATFORM(COCOA)
1215 #if ENABLE(REMOTE_INSPECTOR)
1216 void WebPageProxy::setAllowsRemoteInspection(bool allow)
1218 if (m_allowsRemoteInspection == allow)
1221 m_allowsRemoteInspection = allow;
1224 m_process->send(Messages::WebPage::SetAllowsRemoteInspection(allow), m_pageID);
1227 void WebPageProxy::setRemoteInspectionNameOverride(const String& name)
1229 if (m_remoteInspectionNameOverride == name)
1232 m_remoteInspectionNameOverride = name;
1235 m_process->send(Messages::WebPage::SetRemoteInspectionNameOverride(m_remoteInspectionNameOverride), m_pageID);
1240 void WebPageProxy::setDrawsBackground(bool drawsBackground)
1242 if (m_drawsBackground == drawsBackground)
1245 m_drawsBackground = drawsBackground;
1248 m_process->send(Messages::WebPage::SetDrawsBackground(drawsBackground), m_pageID);
1251 void WebPageProxy::setTopContentInset(float contentInset)
1253 if (m_topContentInset == contentInset)
1256 m_topContentInset = contentInset;
1259 m_process->send(Messages::WebPage::SetTopContentInset(contentInset), m_pageID);
1262 void WebPageProxy::setUnderlayColor(const Color& color)
1264 if (m_underlayColor == color)
1267 m_underlayColor = color;
1270 m_process->send(Messages::WebPage::SetUnderlayColor(color), m_pageID);
1273 void WebPageProxy::viewWillStartLiveResize()
1277 #if ENABLE(INPUT_TYPE_COLOR_POPOVER) && ENABLE(INPUT_TYPE_COLOR)
1281 m_process->send(Messages::WebPage::ViewWillStartLiveResize(), m_pageID);
1284 void WebPageProxy::viewWillEndLiveResize()
1288 m_process->send(Messages::WebPage::ViewWillEndLiveResize(), m_pageID);
1291 void WebPageProxy::setViewNeedsDisplay(const IntRect& rect)
1293 m_pageClient.setViewNeedsDisplay(rect);
1296 void WebPageProxy::displayView()
1298 m_pageClient.displayView();
1301 bool WebPageProxy::canScrollView()
1303 return m_pageClient.canScrollView();
1306 void WebPageProxy::scrollView(const IntRect& scrollRect, const IntSize& scrollOffset)
1308 m_pageClient.scrollView(scrollRect, scrollOffset);
1311 void WebPageProxy::requestScroll(const FloatPoint& scrollPosition, const IntPoint& scrollOrigin, bool isProgrammaticScroll)
1313 m_pageClient.requestScroll(scrollPosition, scrollOrigin, isProgrammaticScroll);
1316 void WebPageProxy::setSuppressVisibilityUpdates(bool flag)
1318 if (m_suppressVisibilityUpdates == flag)
1320 m_suppressVisibilityUpdates = flag;
1322 if (!m_suppressVisibilityUpdates) {
1324 m_viewStateChangeDispatcher->schedule();
1326 dispatchViewStateChange();
1331 void WebPageProxy::updateViewState(ViewState::Flags flagsToUpdate)
1333 m_viewState &= ~flagsToUpdate;
1334 if (flagsToUpdate & ViewState::IsFocused && m_pageClient.isViewFocused())
1335 m_viewState |= ViewState::IsFocused;
1336 if (flagsToUpdate & ViewState::WindowIsActive && m_pageClient.isViewWindowActive())
1337 m_viewState |= ViewState::WindowIsActive;
1338 if (flagsToUpdate & ViewState::IsVisible && m_pageClient.isViewVisible())
1339 m_viewState |= ViewState::IsVisible;
1340 if (flagsToUpdate & ViewState::IsVisibleOrOccluded && m_pageClient.isViewVisibleOrOccluded())
1341 m_viewState |= ViewState::IsVisibleOrOccluded;
1342 if (flagsToUpdate & ViewState::IsInWindow && m_pageClient.isViewInWindow())
1343 m_viewState |= ViewState::IsInWindow;
1344 if (flagsToUpdate & ViewState::IsVisuallyIdle && m_pageClient.isVisuallyIdle())
1345 m_viewState |= ViewState::IsVisuallyIdle;
1348 void WebPageProxy::viewStateDidChange(ViewState::Flags mayHaveChanged, bool wantsSynchronousReply, ViewStateChangeDispatchMode dispatchMode)
1350 m_potentiallyChangedViewStateFlags |= mayHaveChanged;
1351 m_viewStateChangeWantsSynchronousReply = m_viewStateChangeWantsSynchronousReply || wantsSynchronousReply;
1353 if (m_suppressVisibilityUpdates && dispatchMode != ViewStateChangeDispatchMode::Immediate)
1357 bool isNewlyInWindow = !isInWindow() && (mayHaveChanged & ViewState::IsInWindow) && m_pageClient.isViewInWindow();
1358 if (dispatchMode == ViewStateChangeDispatchMode::Immediate || isNewlyInWindow) {
1359 dispatchViewStateChange();
1362 m_viewStateChangeDispatcher->schedule();
1364 UNUSED_PARAM(dispatchMode);
1365 dispatchViewStateChange();
1369 void WebPageProxy::viewDidLeaveWindow()
1371 #if ENABLE(INPUT_TYPE_COLOR_POPOVER) && ENABLE(INPUT_TYPE_COLOR)
1372 // When leaving the current page, close the popover color well.
1377 // When leaving the current page, close the video fullscreen.
1378 if (m_videoFullscreenManager)
1379 m_videoFullscreenManager->requestHideAndExitFullscreen();
1383 void WebPageProxy::viewDidEnterWindow()
1385 LayerHostingMode layerHostingMode = m_pageClient.viewLayerHostingMode();
1386 if (m_layerHostingMode != layerHostingMode) {
1387 m_layerHostingMode = layerHostingMode;
1388 m_process->send(Messages::WebPage::SetLayerHostingMode(static_cast<unsigned>(layerHostingMode)), m_pageID);
1392 void WebPageProxy::dispatchViewStateChange()
1395 m_viewStateChangeDispatcher->invalidate();
1401 // If the visibility state may have changed, then so may the visually idle & occluded agnostic state.
1402 if (m_potentiallyChangedViewStateFlags & ViewState::IsVisible)
1403 m_potentiallyChangedViewStateFlags |= ViewState::IsVisibleOrOccluded | ViewState::IsVisuallyIdle;
1405 // Record the prior view state, update the flags that may have changed,
1406 // and check which flags have actually changed.
1407 ViewState::Flags previousViewState = m_viewState;
1408 updateViewState(m_potentiallyChangedViewStateFlags);
1409 ViewState::Flags changed = m_viewState ^ previousViewState;
1411 bool isNowInWindow = (changed & ViewState::IsInWindow) && isInWindow();
1412 // We always want to wait for the Web process to reply if we've been in-window before and are coming back in-window.
1413 if (m_viewWasEverInWindow && isNowInWindow && m_drawingArea->hasVisibleContent())
1414 m_viewStateChangeWantsSynchronousReply = true;
1416 // Don't wait synchronously if the view state is not visible. (This matters in particular on iOS, where a hidden page may be suspended.)
1417 if (!(m_viewState & ViewState::IsVisible))
1418 m_viewStateChangeWantsSynchronousReply = false;
1420 if (changed || m_viewStateChangeWantsSynchronousReply || !m_nextViewStateChangeCallbacks.isEmpty())
1421 m_process->send(Messages::WebPage::SetViewState(m_viewState, m_viewStateChangeWantsSynchronousReply, m_nextViewStateChangeCallbacks), m_pageID);
1423 m_nextViewStateChangeCallbacks.clear();
1425 // This must happen after the SetViewState message is sent, to ensure the page visibility event can fire.
1426 updateActivityToken();
1428 // If we've started the responsiveness timer as part of telling the web process to update the backing store
1429 // state, it might not send back a reply (since it won't paint anything if the web page is hidden) so we
1430 // stop the unresponsiveness timer here.
1431 if ((changed & ViewState::IsVisible) && !isViewVisible())
1432 m_process->responsivenessTimer().stop();
1434 if (changed & ViewState::IsInWindow) {
1436 viewDidEnterWindow();
1438 viewDidLeaveWindow();
1441 updateBackingStoreDiscardableState();
1443 if (m_viewStateChangeWantsSynchronousReply)
1444 waitForDidUpdateViewState();
1446 m_potentiallyChangedViewStateFlags = ViewState::NoFlags;
1447 m_viewStateChangeWantsSynchronousReply = false;
1448 m_viewWasEverInWindow |= isNowInWindow;
1451 void WebPageProxy::updateActivityToken()
1453 if (m_viewState & ViewState::IsVisuallyIdle)
1454 m_pageIsUserObservableCount = nullptr;
1455 else if (!m_pageIsUserObservableCount)
1456 m_pageIsUserObservableCount = m_process->processPool().userObservablePageCount();
1459 if (!isViewVisible() && !m_alwaysRunsAtForegroundPriority)
1460 m_activityToken = nullptr;
1461 else if (!m_activityToken)
1462 m_activityToken = m_process->throttler().foregroundActivityToken();
1466 void WebPageProxy::updateProccessSuppressionState()
1468 if (m_preferences->pageVisibilityBasedProcessSuppressionEnabled())
1469 m_preventProcessSuppressionCount = nullptr;
1470 else if (!m_preventProcessSuppressionCount)
1471 m_preventProcessSuppressionCount = m_process->processPool().processSuppressionDisabledForPageCount();
1474 void WebPageProxy::layerHostingModeDidChange()
1479 LayerHostingMode layerHostingMode = m_pageClient.viewLayerHostingMode();
1480 if (m_layerHostingMode == layerHostingMode)
1483 m_layerHostingMode = layerHostingMode;
1484 m_process->send(Messages::WebPage::SetLayerHostingMode(static_cast<unsigned>(layerHostingMode)), m_pageID);
1487 void WebPageProxy::waitForDidUpdateViewState()
1492 if (m_process->state() != WebProcessProxy::State::Running)
1495 // If we have previously timed out with no response from the WebProcess, don't block the UIProcess again until it starts responding.
1496 if (m_waitingForDidUpdateViewState)
1500 // Hail Mary check. Should not be possible (dispatchViewStateChange should force async if not visible,
1501 // and if visible we should be holding an assertion) - but we should never block on a suspended process.
1502 if (!m_activityToken) {
1503 ASSERT_NOT_REACHED();
1508 m_waitingForDidUpdateViewState = true;
1510 m_drawingArea->waitForDidUpdateViewState();
1513 IntSize WebPageProxy::viewSize() const
1515 return m_pageClient.viewSize();
1518 void WebPageProxy::setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent& keyboardEvent, std::function<void (CallbackBase::Error)> callbackFunction)
1521 callbackFunction(CallbackBase::Error::OwnerWasInvalidated);
1525 uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), m_process->throttler().backgroundActivityToken());
1526 m_process->send(Messages::WebPage::SetInitialFocus(forward, isKeyboardEventValid, keyboardEvent, callbackID), m_pageID);
1529 void WebPageProxy::clearSelection()
1533 m_process->send(Messages::WebPage::ClearSelection(), m_pageID);
1536 void WebPageProxy::restoreSelectionInFocusedEditableElement()
1540 m_process->send(Messages::WebPage::RestoreSelectionInFocusedEditableElement(), m_pageID);
1543 void WebPageProxy::validateCommand(const String& commandName, std::function<void (const String&, bool, int32_t, CallbackBase::Error)> callbackFunction)
1546 callbackFunction(String(), false, 0, CallbackBase::Error::Unknown);
1550 uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), m_process->throttler().backgroundActivityToken());
1551 m_process->send(Messages::WebPage::ValidateCommand(commandName, callbackID), m_pageID);
1554 void WebPageProxy::setMaintainsInactiveSelection(bool newValue)
1556 m_maintainsInactiveSelection = newValue;
1559 void WebPageProxy::executeEditCommand(const String& commandName, const String& argument)
1561 static NeverDestroyed<String> ignoreSpellingCommandName(ASCIILiteral("ignoreSpelling"));
1566 if (commandName == ignoreSpellingCommandName)
1567 ++m_pendingLearnOrIgnoreWordMessageCount;
1569 m_process->send(Messages::WebPage::ExecuteEditCommand(commandName, argument), m_pageID);
1572 void WebPageProxy::setEditable(bool editable)
1574 if (editable == m_isEditable)
1579 m_isEditable = editable;
1580 m_process->send(Messages::WebPage::SetEditable(editable), m_pageID);
1584 void WebPageProxy::didCommitLayerTree(const RemoteLayerTreeTransaction&)
1589 #if ENABLE(DRAG_SUPPORT)
1590 void WebPageProxy::dragEntered(DragData& dragData, const String& dragStorageName)
1592 SandboxExtension::Handle sandboxExtensionHandle;
1593 SandboxExtension::HandleArray sandboxExtensionHandleEmptyArray;
1594 performDragControllerAction(DragControllerActionEntered, dragData, dragStorageName, sandboxExtensionHandle, sandboxExtensionHandleEmptyArray);
1597 void WebPageProxy::dragUpdated(DragData& dragData, const String& dragStorageName)
1599 SandboxExtension::Handle sandboxExtensionHandle;
1600 SandboxExtension::HandleArray sandboxExtensionHandleEmptyArray;
1601 performDragControllerAction(DragControllerActionUpdated, dragData, dragStorageName, sandboxExtensionHandle, sandboxExtensionHandleEmptyArray);
1604 void WebPageProxy::dragExited(DragData& dragData, const String& dragStorageName)
1606 SandboxExtension::Handle sandboxExtensionHandle;
1607 SandboxExtension::HandleArray sandboxExtensionHandleEmptyArray;
1608 performDragControllerAction(DragControllerActionExited, dragData, dragStorageName, sandboxExtensionHandle, sandboxExtensionHandleEmptyArray);
1611 void WebPageProxy::performDragOperation(DragData& dragData, const String& dragStorageName, const SandboxExtension::Handle& sandboxExtensionHandle, const SandboxExtension::HandleArray& sandboxExtensionsForUpload)
1613 performDragControllerAction(DragControllerActionPerformDragOperation, dragData, dragStorageName, sandboxExtensionHandle, sandboxExtensionsForUpload);
1616 void WebPageProxy::performDragControllerAction(DragControllerAction action, DragData& dragData, const String& dragStorageName, const SandboxExtension::Handle& sandboxExtensionHandle, const SandboxExtension::HandleArray& sandboxExtensionsForUpload)
1621 UNUSED_PARAM(dragStorageName);
1622 UNUSED_PARAM(sandboxExtensionHandle);
1623 UNUSED_PARAM(sandboxExtensionsForUpload);
1625 String url = dragData.asURL();
1627 m_process->assumeReadAccessToBaseURL(url);
1628 m_process->send(Messages::WebPage::PerformDragControllerAction(action, dragData), m_pageID);
1630 m_process->send(Messages::WebPage::PerformDragControllerAction(action, dragData.clientPosition(), dragData.globalPosition(), dragData.draggingSourceOperationMask(), dragStorageName, dragData.flags(), sandboxExtensionHandle, sandboxExtensionsForUpload), m_pageID);
1634 void WebPageProxy::didPerformDragControllerAction(uint64_t dragOperation, bool mouseIsOverFileInput, unsigned numberOfItemsToBeAccepted)
1636 MESSAGE_CHECK(dragOperation <= DragOperationDelete);
1638 m_currentDragOperation = static_cast<DragOperation>(dragOperation);
1639 m_currentDragIsOverFileInput = mouseIsOverFileInput;
1640 m_currentDragNumberOfFilesToBeAccepted = numberOfItemsToBeAccepted;
1644 void WebPageProxy::startDrag(const DragData& dragData, const ShareableBitmap::Handle& dragImageHandle)
1646 RefPtr<ShareableBitmap> dragImage = 0;
1647 if (!dragImageHandle.isNull()) {
1648 dragImage = ShareableBitmap::create(dragImageHandle);
1653 m_pageClient.startDrag(dragData, dragImage.release());
1657 void WebPageProxy::dragEnded(const IntPoint& clientPosition, const IntPoint& globalPosition, uint64_t operation)
1661 m_process->send(Messages::WebPage::DragEnded(clientPosition, globalPosition, operation), m_pageID);
1663 #endif // ENABLE(DRAG_SUPPORT)
1665 void WebPageProxy::handleMouseEvent(const NativeWebMouseEvent& event)
1670 // NOTE: This does not start the responsiveness timer because mouse move should not indicate interaction.
1671 if (event.type() != WebEvent::MouseMove)
1672 m_process->responsivenessTimer().start();
1674 if (m_processingMouseMoveEvent) {
1675 m_nextMouseMoveEvent = std::make_unique<NativeWebMouseEvent>(event);
1679 m_processingMouseMoveEvent = true;
1682 // <https://bugs.webkit.org/show_bug.cgi?id=57904> We need to keep track of the mouse down event in the case where we
1683 // display a popup menu for select elements. When the user changes the selected item,
1684 // we fake a mouse up event by using this stored down event. This event gets cleared
1685 // when the mouse up message is received from WebProcess.
1686 if (event.type() == WebEvent::MouseDown)
1687 m_currentlyProcessedMouseDownEvent = std::make_unique<NativeWebMouseEvent>(event);
1689 m_process->send(Messages::WebPage::MouseEvent(event), m_pageID);
1692 #if MERGE_WHEEL_EVENTS
1693 static bool canCoalesce(const WebWheelEvent& a, const WebWheelEvent& b)
1695 if (a.position() != b.position())
1697 if (a.globalPosition() != b.globalPosition())
1699 if (a.modifiers() != b.modifiers())
1701 if (a.granularity() != b.granularity())
1704 if (a.phase() != b.phase())
1706 if (a.momentumPhase() != b.momentumPhase())
1708 if (a.hasPreciseScrollingDeltas() != b.hasPreciseScrollingDeltas())
1715 static WebWheelEvent coalesce(const WebWheelEvent& a, const WebWheelEvent& b)
1717 ASSERT(canCoalesce(a, b));
1719 FloatSize mergedDelta = a.delta() + b.delta();
1720 FloatSize mergedWheelTicks = a.wheelTicks() + b.wheelTicks();
1723 FloatSize mergedUnacceleratedScrollingDelta = a.unacceleratedScrollingDelta() + b.unacceleratedScrollingDelta();
1725 return WebWheelEvent(WebEvent::Wheel, b.position(), b.globalPosition(), mergedDelta, mergedWheelTicks, b.granularity(), b.directionInvertedFromDevice(), b.phase(), b.momentumPhase(), b.hasPreciseScrollingDeltas(), b.scrollCount(), mergedUnacceleratedScrollingDelta, b.modifiers(), b.timestamp());
1727 return WebWheelEvent(WebEvent::Wheel, b.position(), b.globalPosition(), mergedDelta, mergedWheelTicks, b.granularity(), b.modifiers(), b.timestamp());
1730 #endif // MERGE_WHEEL_EVENTS
1732 static WebWheelEvent coalescedWheelEvent(Deque<NativeWebWheelEvent>& queue, Vector<NativeWebWheelEvent>& coalescedEvents)
1734 ASSERT(!queue.isEmpty());
1735 ASSERT(coalescedEvents.isEmpty());
1737 #if MERGE_WHEEL_EVENTS
1738 NativeWebWheelEvent firstEvent = queue.takeFirst();
1739 coalescedEvents.append(firstEvent);
1741 WebWheelEvent event = firstEvent;
1742 while (!queue.isEmpty() && canCoalesce(event, queue.first())) {
1743 NativeWebWheelEvent firstEvent = queue.takeFirst();
1744 coalescedEvents.append(firstEvent);
1745 event = coalesce(event, firstEvent);
1750 while (!queue.isEmpty())
1751 coalescedEvents.append(queue.takeFirst());
1752 return coalescedEvents.last();
1756 void WebPageProxy::handleWheelEvent(const NativeWebWheelEvent& event)
1758 #if ENABLE(ASYNC_SCROLLING)
1759 if (m_scrollingCoordinatorProxy && m_scrollingCoordinatorProxy->handleWheelEvent(platform(event)))
1766 if (!m_currentlyProcessedWheelEvents.isEmpty()) {
1767 m_wheelEventQueue.append(event);
1768 if (m_wheelEventQueue.size() < wheelEventQueueSizeThreshold)
1770 // The queue has too many wheel events, so push a new event.
1773 if (!m_wheelEventQueue.isEmpty()) {
1774 processNextQueuedWheelEvent();
1778 auto coalescedWheelEvent = std::make_unique<Vector<NativeWebWheelEvent>>();
1779 coalescedWheelEvent->append(event);
1780 m_currentlyProcessedWheelEvents.append(WTF::move(coalescedWheelEvent));
1781 sendWheelEvent(event);
1784 void WebPageProxy::processNextQueuedWheelEvent()
1786 auto nextCoalescedEvent = std::make_unique<Vector<NativeWebWheelEvent>>();
1787 WebWheelEvent nextWheelEvent = coalescedWheelEvent(m_wheelEventQueue, *nextCoalescedEvent.get());
1788 m_currentlyProcessedWheelEvents.append(WTF::move(nextCoalescedEvent));
1789 sendWheelEvent(nextWheelEvent);
1792 void WebPageProxy::sendWheelEvent(const WebWheelEvent& event)
1795 Messages::EventDispatcher::WheelEvent(
1798 shouldUseImplicitRubberBandControl() ? !m_backForwardList->backItem() : rubberBandsAtLeft(),
1799 shouldUseImplicitRubberBandControl() ? !m_backForwardList->forwardItem() : rubberBandsAtRight(),
1801 rubberBandsAtBottom()
1804 m_process->sendMainThreadPing();
1807 void WebPageProxy::handleKeyboardEvent(const NativeWebKeyboardEvent& event)
1812 LOG(KeyHandling, "WebPageProxy::handleKeyboardEvent: %s", webKeyboardEventTypeString(event.type()));
1814 m_keyEventQueue.append(event);
1816 m_process->responsivenessTimer().start();
1817 if (m_keyEventQueue.size() == 1) // Otherwise, sent from DidReceiveEvent message handler.
1818 m_process->send(Messages::WebPage::KeyEvent(event), m_pageID);
1821 WebPreferencesStore WebPageProxy::preferencesStore() const
1823 if (m_configurationPreferenceValues.isEmpty())
1824 return m_preferences->store();
1826 WebPreferencesStore store = m_preferences->store();
1827 for (const auto& preference : m_configurationPreferenceValues)
1828 store.m_values.set(preference.key, preference.value);
1833 #if ENABLE(NETSCAPE_PLUGIN_API)
1834 void WebPageProxy::findPlugin(const String& mimeType, uint32_t processType, const String& urlString, const String& frameURLString, const String& pageURLString, bool allowOnlyApplicationPlugins, uint64_t& pluginProcessToken, String& newMimeType, uint32_t& pluginLoadPolicy, String& unavailabilityDescription)
1836 PageClientProtector protector(m_pageClient);
1838 MESSAGE_CHECK_URL(urlString);
1840 newMimeType = mimeType.lower();
1841 pluginLoadPolicy = PluginModuleLoadNormally;
1843 PluginData::AllowedPluginTypes allowedPluginTypes = allowOnlyApplicationPlugins ? PluginData::OnlyApplicationPlugins : PluginData::AllPlugins;
1844 PluginModuleInfo plugin = m_process->processPool().pluginInfoStore().findPlugin(newMimeType, URL(URL(), urlString), allowedPluginTypes);
1846 pluginProcessToken = 0;
1850 pluginLoadPolicy = PluginInfoStore::defaultLoadPolicyForPlugin(plugin);
1853 RefPtr<API::Dictionary> pluginInformation = createPluginInformationDictionary(plugin, frameURLString, String(), pageURLString, String(), String());
1854 if (m_navigationClient)
1855 pluginLoadPolicy = m_navigationClient->decidePolicyForPluginLoad(*this, static_cast<PluginModuleLoadPolicy>(pluginLoadPolicy), pluginInformation.get(), unavailabilityDescription);
1857 pluginLoadPolicy = m_loaderClient->pluginLoadPolicy(*this, static_cast<PluginModuleLoadPolicy>(pluginLoadPolicy), pluginInformation.get(), unavailabilityDescription);
1859 UNUSED_PARAM(frameURLString);
1860 UNUSED_PARAM(pageURLString);
1861 UNUSED_PARAM(unavailabilityDescription);
1864 PluginProcessSandboxPolicy pluginProcessSandboxPolicy = PluginProcessSandboxPolicyNormal;
1865 switch (pluginLoadPolicy) {
1866 case PluginModuleLoadNormally:
1867 pluginProcessSandboxPolicy = PluginProcessSandboxPolicyNormal;
1869 case PluginModuleLoadUnsandboxed:
1870 pluginProcessSandboxPolicy = PluginProcessSandboxPolicyUnsandboxed;
1873 case PluginModuleBlockedForSecurity:
1874 case PluginModuleBlockedForCompatibility:
1875 pluginProcessToken = 0;
1879 pluginProcessToken = PluginProcessManager::singleton().pluginProcessToken(plugin, static_cast<PluginProcessType>(processType), pluginProcessSandboxPolicy);
1882 #endif // ENABLE(NETSCAPE_PLUGIN_API)
1884 #if ENABLE(TOUCH_EVENTS)
1886 bool WebPageProxy::shouldStartTrackingTouchEvents(const WebTouchEvent& touchStartEvent) const
1888 #if ENABLE(ASYNC_SCROLLING)
1889 for (auto& touchPoint : touchStartEvent.touchPoints()) {
1890 if (m_scrollingCoordinatorProxy->isPointInNonFastScrollableRegion(touchPoint.location()))
1896 UNUSED_PARAM(touchStartEvent);
1897 #endif // ENABLE(ASYNC_SCROLLING)
1903 #if ENABLE(MAC_GESTURE_EVENTS)
1904 void WebPageProxy::handleGestureEvent(const NativeWebGestureEvent& event)
1909 m_gestureEventQueue.append(event);
1910 // FIXME: Consider doing some coalescing here.
1911 m_process->responsivenessTimer().start();
1913 m_process->send(Messages::EventDispatcher::GestureEvent(m_pageID, event), 0);
1917 #if ENABLE(IOS_TOUCH_EVENTS)
1918 void WebPageProxy::handleTouchEventSynchronously(const NativeWebTouchEvent& event)
1923 if (event.type() == WebEvent::TouchStart) {
1924 m_isTrackingTouchEvents = shouldStartTrackingTouchEvents(event);
1925 m_layerTreeTransactionIdAtLastTouchStart = downcast<RemoteLayerTreeDrawingAreaProxy>(*drawingArea()).lastCommittedLayerTreeTransactionID();
1928 if (!m_isTrackingTouchEvents)
1931 m_process->responsivenessTimer().start();
1932 bool handled = false;
1933 m_process->sendSync(Messages::WebPage::TouchEventSync(event), Messages::WebPage::TouchEventSync::Reply(handled), m_pageID);
1934 didReceiveEvent(event.type(), handled);
1935 m_pageClient.doneWithTouchEvent(event, handled);
1936 m_process->responsivenessTimer().stop();
1938 if (event.allTouchPointsAreReleased())
1939 m_isTrackingTouchEvents = false;
1942 void WebPageProxy::handleTouchEventAsynchronously(const NativeWebTouchEvent& event)
1947 if (!m_isTrackingTouchEvents)
1950 m_process->send(Messages::EventDispatcher::TouchEvent(m_pageID, event), 0);
1952 if (event.allTouchPointsAreReleased())
1953 m_isTrackingTouchEvents = false;
1956 #elif ENABLE(TOUCH_EVENTS)
1957 void WebPageProxy::handleTouchEvent(const NativeWebTouchEvent& event)
1962 if (event.type() == WebEvent::TouchStart)
1963 m_isTrackingTouchEvents = shouldStartTrackingTouchEvents(event);
1965 if (!m_isTrackingTouchEvents)
1968 // If the page is suspended, which should be the case during panning, pinching
1969 // and animation on the page itself (kinetic scrolling, tap to zoom) etc, then
1970 // we do not send any of the events to the page even if is has listeners.
1971 if (!m_isPageSuspended) {
1972 m_touchEventQueue.append(event);
1973 m_process->responsivenessTimer().start();
1974 m_process->send(Messages::WebPage::TouchEvent(event), m_pageID);
1976 if (m_touchEventQueue.isEmpty()) {
1977 bool isEventHandled = false;
1978 m_pageClient.doneWithTouchEvent(event, isEventHandled);
1980 // We attach the incoming events to the newest queued event so that all
1981 // the events are delivered in the correct order when the event is dequed.
1982 QueuedTouchEvents& lastEvent = m_touchEventQueue.last();
1983 lastEvent.deferredTouchEvents.append(event);
1987 if (event.allTouchPointsAreReleased())
1988 m_isTrackingTouchEvents = false;
1990 #endif // ENABLE(TOUCH_EVENTS)
1992 void WebPageProxy::scrollBy(ScrollDirection direction, ScrollGranularity granularity)
1997 m_process->send(Messages::WebPage::ScrollBy(direction, granularity), m_pageID);
2000 void WebPageProxy::centerSelectionInVisibleArea()
2005 m_process->send(Messages::WebPage::CenterSelectionInVisibleArea(), m_pageID);
2008 void WebPageProxy::receivedPolicyDecision(PolicyAction action, WebFrameProxy* frame, uint64_t listenerID, API::Navigation* navigation)
2013 auto transaction = m_pageLoadState.transaction();
2015 if (action == PolicyIgnore)
2016 m_pageLoadState.clearPendingAPIRequestURL(transaction);
2018 uint64_t downloadID = 0;
2019 if (action == PolicyDownload) {
2020 // Create a download proxy.
2021 // FIXME: We should ensure that the downloadRequest is never empty.
2022 const ResourceRequest& downloadRequest = m_decidePolicyForResponseRequest ? *m_decidePolicyForResponseRequest : ResourceRequest();
2023 DownloadProxy* download = m_process->processPool().createDownloadProxy(downloadRequest);
2024 downloadID = download->downloadID();
2025 handleDownloadRequest(download);
2028 // If we received a policy decision while in decidePolicyForResponse the decision will
2029 // be sent back to the web process by decidePolicyForResponse.
2030 if (m_inDecidePolicyForResponseSync) {
2031 m_syncMimeTypePolicyActionIsValid = true;
2032 m_syncMimeTypePolicyAction = action;
2033 m_syncMimeTypePolicyDownloadID = downloadID;
2037 // If we received a policy decision while in decidePolicyForNavigationAction the decision will
2038 // be sent back to the web process by decidePolicyForNavigationAction.
2039 if (m_inDecidePolicyForNavigationAction) {
2040 m_syncNavigationActionPolicyActionIsValid = true;
2041 m_syncNavigationActionPolicyAction = action;
2042 m_syncNavigationActionPolicyDownloadID = downloadID;
2046 m_process->send(Messages::WebPage::DidReceivePolicyDecision(frame->frameID(), listenerID, action, navigation ? navigation->navigationID() : 0, downloadID), m_pageID);
2049 void WebPageProxy::setUserAgent(const String& userAgent)
2051 if (m_userAgent == userAgent)
2053 m_userAgent = userAgent;
2057 m_process->send(Messages::WebPage::SetUserAgent(m_userAgent), m_pageID);
2060 void WebPageProxy::setApplicationNameForUserAgent(const String& applicationName)
2062 if (m_applicationNameForUserAgent == applicationName)
2065 m_applicationNameForUserAgent = applicationName;
2066 if (!m_customUserAgent.isEmpty())
2069 setUserAgent(standardUserAgent(m_applicationNameForUserAgent));
2072 void WebPageProxy::setCustomUserAgent(const String& customUserAgent)
2074 if (m_customUserAgent == customUserAgent)
2077 m_customUserAgent = customUserAgent;
2079 if (m_customUserAgent.isEmpty()) {
2080 setUserAgent(standardUserAgent(m_applicationNameForUserAgent));
2084 setUserAgent(m_customUserAgent);
2087 void WebPageProxy::resumeActiveDOMObjectsAndAnimations()
2089 if (!isValid() || !m_isPageSuspended)
2092 m_isPageSuspended = false;
2094 m_process->send(Messages::WebPage::ResumeActiveDOMObjectsAndAnimations(), m_pageID);
2097 void WebPageProxy::suspendActiveDOMObjectsAndAnimations()
2099 if (!isValid() || m_isPageSuspended)
2102 m_isPageSuspended = true;
2104 m_process->send(Messages::WebPage::SuspendActiveDOMObjectsAndAnimations(), m_pageID);
2107 bool WebPageProxy::supportsTextEncoding() const
2109 // FIXME (118840): We should probably only support this for text documents, not all non-image documents.
2110 return m_mainFrame && !m_mainFrame->isDisplayingStandaloneImageDocument();
2113 void WebPageProxy::setCustomTextEncodingName(const String& encodingName)
2115 if (m_customTextEncodingName == encodingName)
2117 m_customTextEncodingName = encodingName;
2121 m_process->send(Messages::WebPage::SetCustomTextEncodingName(encodingName), m_pageID);
2124 void WebPageProxy::terminateProcess()
2126 // requestTermination() is a no-op for launching processes, so we get into an inconsistent state by calling resetStateAfterProcessExited().
2127 // FIXME: A client can terminate the page at any time, so we should do something more meaningful than assert and fall apart in release builds.
2128 // See also <https://bugs.webkit.org/show_bug.cgi?id=136012>.
2129 ASSERT(m_process->state() != WebProcessProxy::State::Launching);
2131 // NOTE: This uses a check of m_isValid rather than calling isValid() since
2132 // we want this to run even for pages being closed or that already closed.
2136 m_process->requestTermination();
2137 resetStateAfterProcessExited();
2140 SessionState WebPageProxy::sessionState(const std::function<bool (WebBackForwardListItem&)>& filter) const
2142 SessionState sessionState;
2144 sessionState.backForwardListState = m_backForwardList->backForwardListState(filter);
2146 String provisionalURLString = m_pageLoadState.pendingAPIRequestURL();
2147 if (provisionalURLString.isEmpty())
2148 provisionalURLString = m_pageLoadState.provisionalURL();
2150 if (!provisionalURLString.isEmpty())
2151 sessionState.provisionalURL = URL(URL(), provisionalURLString);
2153 sessionState.renderTreeSize = renderTreeSize();
2154 return sessionState;
2157 RefPtr<API::Navigation> WebPageProxy::restoreFromSessionState(SessionState sessionState, bool navigate)
2159 m_sessionRestorationRenderTreeSize = 0;
2160 m_hitRenderTreeSizeThreshold = false;
2162 bool hasBackForwardList = !!sessionState.backForwardListState.currentIndex;
2164 if (hasBackForwardList) {
2165 m_backForwardList->restoreFromState(WTF::move(sessionState.backForwardListState));
2167 for (const auto& entry : m_backForwardList->entries())
2168 process().registerNewWebBackForwardListItem(entry.get());
2170 process().send(Messages::WebPage::RestoreSession(m_backForwardList->itemStates()), m_pageID);
2172 // The back / forward list was restored from a sessionState so we don't want to snapshot the current
2173 // page when navigating away. Suppress navigation snapshotting until the next load has committed.
2174 m_suppressNavigationSnapshotting = true;
2177 // FIXME: Navigating should be separate from state restoration.
2179 m_sessionRestorationRenderTreeSize = sessionState.renderTreeSize;
2180 if (!m_sessionRestorationRenderTreeSize)
2181 m_hitRenderTreeSizeThreshold = true; // If we didn't get data on renderTreeSize, just don't fire the milestone.
2183 if (!sessionState.provisionalURL.isNull())
2184 return loadRequest(sessionState.provisionalURL);
2186 if (hasBackForwardList) {
2187 // FIXME: Do we have to null check the back forward list item here?
2188 if (WebBackForwardListItem* item = m_backForwardList->currentItem())
2189 return goToBackForwardItem(item);
2196 bool WebPageProxy::supportsTextZoom() const
2198 // FIXME (118840): This should also return false for standalone media and plug-in documents.
2199 if (!m_mainFrame || m_mainFrame->isDisplayingStandaloneImageDocument())
2205 void WebPageProxy::setTextZoomFactor(double zoomFactor)
2210 if (m_textZoomFactor == zoomFactor)
2213 m_textZoomFactor = zoomFactor;
2214 m_process->send(Messages::WebPage::SetTextZoomFactor(m_textZoomFactor), m_pageID);
2217 void WebPageProxy::setPageZoomFactor(double zoomFactor)
2222 if (m_pageZoomFactor == zoomFactor)
2225 m_pageZoomFactor = zoomFactor;
2226 m_process->send(Messages::WebPage::SetPageZoomFactor(m_pageZoomFactor), m_pageID);
2229 void WebPageProxy::setPageAndTextZoomFactors(double pageZoomFactor, double textZoomFactor)
2234 if (m_pageZoomFactor == pageZoomFactor && m_textZoomFactor == textZoomFactor)
2237 m_pageZoomFactor = pageZoomFactor;
2238 m_textZoomFactor = textZoomFactor;
2239 m_process->send(Messages::WebPage::SetPageAndTextZoomFactors(m_pageZoomFactor, m_textZoomFactor), m_pageID);
2242 double WebPageProxy::pageZoomFactor() const
2244 // Zoom factor for non-PDF pages persists across page loads. We maintain a separate member variable for PDF
2245 // zoom which ensures that we don't use the PDF zoom for a normal page.
2246 if (m_mainFramePluginHandlesPageScaleGesture)
2247 return m_pluginZoomFactor;
2248 return m_pageZoomFactor;
2251 double WebPageProxy::pageScaleFactor() const
2253 // PDF documents use zoom and scale factors to size themselves appropriately in the window. We store them
2254 // separately but decide which to return based on the main frame.
2255 if (m_mainFramePluginHandlesPageScaleGesture)
2256 return m_pluginScaleFactor;
2257 return m_pageScaleFactor;
2260 void WebPageProxy::scalePage(double scale, const IntPoint& origin)
2267 m_pageScaleFactor = scale;
2268 m_process->send(Messages::WebPage::ScalePage(scale, origin), m_pageID);
2271 void WebPageProxy::scalePageInViewCoordinates(double scale, const IntPoint& centerInViewCoordinates)
2278 m_pageScaleFactor = scale;
2279 m_process->send(Messages::WebPage::ScalePageInViewCoordinates(scale, centerInViewCoordinates), m_pageID);
2282 void WebPageProxy::scaleView(double scale)
2289 m_viewScaleFactor = scale;
2290 m_process->send(Messages::WebPage::ScaleView(scale), m_pageID);
2293 void WebPageProxy::setIntrinsicDeviceScaleFactor(float scaleFactor)
2295 if (m_intrinsicDeviceScaleFactor == scaleFactor)
2298 m_intrinsicDeviceScaleFactor = scaleFactor;
2301 m_drawingArea->deviceScaleFactorDidChange();
2304 void WebPageProxy::windowScreenDidChange(PlatformDisplayID displayID)
2309 m_process->send(Messages::WebPage::WindowScreenDidChange(displayID), m_pageID);
2312 float WebPageProxy::deviceScaleFactor() const
2314 if (m_customDeviceScaleFactor)
2315 return m_customDeviceScaleFactor;
2316 return m_intrinsicDeviceScaleFactor;
2319 void WebPageProxy::setCustomDeviceScaleFactor(float customScaleFactor)
2324 // FIXME: Remove this once we bump cairo requirements to support HiDPI.
2325 // https://bugs.webkit.org/show_bug.cgi?id=133378
2326 #if USE(CAIRO) && !HAVE(CAIRO_SURFACE_SET_DEVICE_SCALE)
2330 if (m_customDeviceScaleFactor == customScaleFactor)
2333 float oldScaleFactor = deviceScaleFactor();
2335 m_customDeviceScaleFactor = customScaleFactor;
2337 if (deviceScaleFactor() != oldScaleFactor)
2338 m_drawingArea->deviceScaleFactorDidChange();
2341 void WebPageProxy::setUseFixedLayout(bool fixed)
2346 // This check is fine as the value is initialized in the web
2347 // process as part of the creation parameters.
2348 if (fixed == m_useFixedLayout)
2351 m_useFixedLayout = fixed;
2353 m_fixedLayoutSize = IntSize();
2354 m_process->send(Messages::WebPage::SetUseFixedLayout(fixed), m_pageID);
2357 void WebPageProxy::setFixedLayoutSize(const IntSize& size)
2362 if (size == m_fixedLayoutSize)
2365 m_fixedLayoutSize = size;
2366 m_process->send(Messages::WebPage::SetFixedLayoutSize(size), m_pageID);
2369 void WebPageProxy::listenForLayoutMilestones(WebCore::LayoutMilestones milestones)
2374 m_wantsSessionRestorationRenderTreeSizeThresholdEvent = milestones & WebCore::ReachedSessionRestorationRenderTreeSizeThreshold;
2376 m_process->send(Messages::WebPage::ListenForLayoutMilestones(milestones), m_pageID);
2379 void WebPageProxy::setSuppressScrollbarAnimations(bool suppressAnimations)
2384 if (suppressAnimations == m_suppressScrollbarAnimations)
2387 m_suppressScrollbarAnimations = suppressAnimations;
2388 m_process->send(Messages::WebPage::SetSuppressScrollbarAnimations(suppressAnimations), m_pageID);
2391 bool WebPageProxy::rubberBandsAtLeft() const
2393 return m_rubberBandsAtLeft;
2396 void WebPageProxy::setRubberBandsAtLeft(bool rubberBandsAtLeft)
2398 m_rubberBandsAtLeft = rubberBandsAtLeft;
2401 bool WebPageProxy::rubberBandsAtRight() const
2403 return m_rubberBandsAtRight;
2406 void WebPageProxy::setRubberBandsAtRight(bool rubberBandsAtRight)
2408 m_rubberBandsAtRight = rubberBandsAtRight;
2411 bool WebPageProxy::rubberBandsAtTop() const
2413 return m_rubberBandsAtTop;
2416 void WebPageProxy::setRubberBandsAtTop(bool rubberBandsAtTop)
2418 m_rubberBandsAtTop = rubberBandsAtTop;
2421 bool WebPageProxy::rubberBandsAtBottom() const
2423 return m_rubberBandsAtBottom;
2426 void WebPageProxy::setRubberBandsAtBottom(bool rubberBandsAtBottom)
2428 m_rubberBandsAtBottom = rubberBandsAtBottom;
2431 void WebPageProxy::setEnableVerticalRubberBanding(bool enableVerticalRubberBanding)
2433 if (enableVerticalRubberBanding == m_enableVerticalRubberBanding)
2436 m_enableVerticalRubberBanding = enableVerticalRubberBanding;
2440 m_process->send(Messages::WebPage::SetEnableVerticalRubberBanding(enableVerticalRubberBanding), m_pageID);
2443 bool WebPageProxy::verticalRubberBandingIsEnabled() const
2445 return m_enableVerticalRubberBanding;
2448 void WebPageProxy::setEnableHorizontalRubberBanding(bool enableHorizontalRubberBanding)
2450 if (enableHorizontalRubberBanding == m_enableHorizontalRubberBanding)
2453 m_enableHorizontalRubberBanding = enableHorizontalRubberBanding;
2457 m_process->send(Messages::WebPage::SetEnableHorizontalRubberBanding(enableHorizontalRubberBanding), m_pageID);
2460 bool WebPageProxy::horizontalRubberBandingIsEnabled() const
2462 return m_enableHorizontalRubberBanding;
2465 void WebPageProxy::setBackgroundExtendsBeyondPage(bool backgroundExtendsBeyondPage)
2467 if (backgroundExtendsBeyondPage == m_backgroundExtendsBeyondPage)
2470 m_backgroundExtendsBeyondPage = backgroundExtendsBeyondPage;
2474 m_process->send(Messages::WebPage::SetBackgroundExtendsBeyondPage(backgroundExtendsBeyondPage), m_pageID);
2477 bool WebPageProxy::backgroundExtendsBeyondPage() const
2479 return m_backgroundExtendsBeyondPage;
2482 void WebPageProxy::setPaginationMode(WebCore::Pagination::Mode mode)
2484 if (mode == m_paginationMode)
2487 m_paginationMode = mode;
2491 m_process->send(Messages::WebPage::SetPaginationMode(mode), m_pageID);
2494 void WebPageProxy::setPaginationBehavesLikeColumns(bool behavesLikeColumns)
2496 if (behavesLikeColumns == m_paginationBehavesLikeColumns)
2499 m_paginationBehavesLikeColumns = behavesLikeColumns;
2503 m_process->send(Messages::WebPage::SetPaginationBehavesLikeColumns(behavesLikeColumns), m_pageID);
2506 void WebPageProxy::setPageLength(double pageLength)
2508 if (pageLength == m_pageLength)
2511 m_pageLength = pageLength;
2515 m_process->send(Messages::WebPage::SetPageLength(pageLength), m_pageID);
2518 void WebPageProxy::setGapBetweenPages(double gap)
2520 if (gap == m_gapBetweenPages)
2523 m_gapBetweenPages = gap;
2527 m_process->send(Messages::WebPage::SetGapBetweenPages(gap), m_pageID);
2530 void WebPageProxy::pageScaleFactorDidChange(double scaleFactor)
2532 m_pageScaleFactor = scaleFactor;
2535 void WebPageProxy::pluginScaleFactorDidChange(double pluginScaleFactor)
2537 m_pluginScaleFactor = pluginScaleFactor;
2540 void WebPageProxy::pluginZoomFactorDidChange(double pluginZoomFactor)
2542 m_pluginZoomFactor = pluginZoomFactor;
2545 void WebPageProxy::findStringMatches(const String& string, FindOptions options, unsigned maxMatchCount)
2547 if (string.isEmpty()) {
2548 didFindStringMatches(string, Vector<Vector<WebCore::IntRect>> (), 0);
2552 m_process->send(Messages::WebPage::FindStringMatches(string, options, maxMatchCount), m_pageID);
2555 void WebPageProxy::findString(const String& string, FindOptions options, unsigned maxMatchCount)
2557 m_process->send(Messages::WebPage::FindString(string, options, maxMatchCount), m_pageID);
2560 void WebPageProxy::getImageForFindMatch(int32_t matchIndex)
2562 m_process->send(Messages::WebPage::GetImageForFindMatch(matchIndex), m_pageID);
2565 void WebPageProxy::selectFindMatch(int32_t matchIndex)
2567 m_process->send(Messages::WebPage::SelectFindMatch(matchIndex), m_pageID);
2570 void WebPageProxy::hideFindUI()
2572 m_process->send(Messages::WebPage::HideFindUI(), m_pageID);
2575 void WebPageProxy::countStringMatches(const String& string, FindOptions options, unsigned maxMatchCount)
2580 m_process->send(Messages::WebPage::CountStringMatches(string, options, maxMatchCount), m_pageID);
2583 void WebPageProxy::runJavaScriptInMainFrame(const String& script, std::function<void (API::SerializedScriptValue*, bool hadException, const ExceptionDetails&, CallbackBase::Error)> callbackFunction)
2586 callbackFunction(nullptr, false, { }, CallbackBase::Error::Unknown);
2590 uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), m_process->throttler().backgroundActivityToken());
2591 m_process->send(Messages::WebPage::RunJavaScriptInMainFrame(script, callbackID), m_pageID);
2594 void WebPageProxy::getRenderTreeExternalRepresentation(std::function<void (const String&, CallbackBase::Error)> callbackFunction)
2597 callbackFunction(String(), CallbackBase::Error::Unknown);
2601 uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), m_process->throttler().backgroundActivityToken());
2602 m_process->send(Messages::WebPage::GetRenderTreeExternalRepresentation(callbackID), m_pageID);
2605 void WebPageProxy::getSourceForFrame(WebFrameProxy* frame, std::function<void (const String&, CallbackBase::Error)> callbackFunction)
2608 callbackFunction(String(), CallbackBase::Error::Unknown);
2612 uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), m_process->throttler().backgroundActivityToken());
2613 m_loadDependentStringCallbackIDs.add(callbackID);
2614 m_process->send(Messages::WebPage::GetSourceForFrame(frame->frameID(), callbackID), m_pageID);
2617 void WebPageProxy::getContentsAsString(std::function<void (const String&, CallbackBase::Error)> callbackFunction)
2620 callbackFunction(String(), CallbackBase::Error::Unknown);
2624 uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), m_process->throttler().backgroundActivityToken());
2625 m_loadDependentStringCallbackIDs.add(callbackID);
2626 m_process->send(Messages::WebPage::GetContentsAsString(callbackID), m_pageID);
2629 void WebPageProxy::getBytecodeProfile(std::function<void (const String&, CallbackBase::Error)> callbackFunction)
2632 callbackFunction(String(), CallbackBase::Error::Unknown);
2636 uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), m_process->throttler().backgroundActivityToken());
2637 m_loadDependentStringCallbackIDs.add(callbackID);
2638 m_process->send(Messages::WebPage::GetBytecodeProfile(callbackID), m_pageID);
2642 void WebPageProxy::getContentsAsMHTMLData(std::function<void (API::Data*, CallbackBase::Error)> callbackFunction)
2645 callbackFunction(nullptr, CallbackBase::Error::Unknown);
2649 uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), m_process->throttler().backgroundActivityToken());
2650 m_process->send(Messages::WebPage::GetContentsAsMHTMLData(callbackID), m_pageID);
2654 void WebPageProxy::getSelectionOrContentsAsString(std::function<void (const String&, CallbackBase::Error)> callbackFunction)
2657 callbackFunction(String(), CallbackBase::Error::Unknown);
2661 uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), m_process->throttler().backgroundActivityToken());
2662 m_process->send(Messages::WebPage::GetSelectionOrContentsAsString(callbackID), m_pageID);
2665 void WebPageProxy::getSelectionAsWebArchiveData(std::function<void (API::Data*, CallbackBase::Error)> callbackFunction)
2668 callbackFunction(nullptr, CallbackBase::Error::Unknown);
2672 uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), m_process->throttler().backgroundActivityToken());
2673 m_process->send(Messages::WebPage::GetSelectionAsWebArchiveData(callbackID), m_pageID);
2676 void WebPageProxy::getMainResourceDataOfFrame(WebFrameProxy* frame, std::function<void (API::Data*, CallbackBase::Error)> callbackFunction)
2678 if (!isValid() || !frame) {
2679 callbackFunction(nullptr, CallbackBase::Error::Unknown);
2683 uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), m_process->throttler().backgroundActivityToken());
2684 m_process->send(Messages::WebPage::GetMainResourceDataOfFrame(frame->frameID(), callbackID), m_pageID);
2687 void WebPageProxy::getResourceDataFromFrame(WebFrameProxy* frame, API::URL* resourceURL, std::function<void (API::Data*, CallbackBase::Error)> callbackFunction)
2690 callbackFunction(nullptr, CallbackBase::Error::Unknown);
2694 uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), m_process->throttler().backgroundActivityToken());
2695 m_process->send(Messages::WebPage::GetResourceDataFromFrame(frame->frameID(), resourceURL->string(), callbackID), m_pageID);
2698 void WebPageProxy::getWebArchiveOfFrame(WebFrameProxy* frame, std::function<void (API::Data*, CallbackBase::Error)> callbackFunction)
2701 callbackFunction(nullptr, CallbackBase::Error::Unknown);
2705 uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), m_process->throttler().backgroundActivityToken());
2706 m_process->send(Messages::WebPage::GetWebArchiveOfFrame(frame->frameID(), callbackID), m_pageID);
2709 void WebPageProxy::forceRepaint(PassRefPtr<VoidCallback> prpCallback)
2711 RefPtr<VoidCallback> callback = prpCallback;
2713 // FIXME: If the page is invalid we should not call the callback. It'd be better to just return false from forceRepaint.
2714 callback->invalidate(CallbackBase::Error::OwnerWasInvalidated);
2718 uint64_t callbackID = callback->callbackID();
2719 m_callbacks.put(callback);
2720 m_drawingArea->waitForBackingStoreUpdateOnNextPaint();
2721 m_process->send(Messages::WebPage::ForceRepaint(callbackID), m_pageID);
2724 void WebPageProxy::preferencesDidChange()
2729 #if ENABLE(INSPECTOR_SERVER)
2730 if (m_preferences->developerExtrasEnabled())
2731 inspector()->enableRemoteInspection();
2734 updateProccessSuppressionState();
2736 m_pageClient.preferencesDidChange();
2738 // FIXME: It probably makes more sense to send individual preference changes.
2739 // However, WebKitTestRunner depends on getting a preference change notification
2740 // even if nothing changed in UI process, so that overrides get removed.
2742 // Preferences need to be updated during synchronous printing to make "print backgrounds" preference work when toggled from a print dialog checkbox.
2743 m_process->send(Messages::WebPage::PreferencesDidChange(preferencesStore()), m_pageID, m_isPerformingDOMPrintOperation ? IPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
2746 void WebPageProxy::didCreateMainFrame(uint64_t frameID)
2748 PageClientProtector protector(m_pageClient);
2750 MESSAGE_CHECK(!m_mainFrame);
2751 MESSAGE_CHECK(m_process->canCreateFrame(frameID));
2753 m_mainFrame = WebFrameProxy::create(this, frameID);
2755 // Add the frame to the process wide map.
2756 m_process->frameCreated(frameID, m_mainFrame.get());
2759 void WebPageProxy::didCreateSubframe(uint64_t frameID)
2761 PageClientProtector protector(m_pageClient);
2763 MESSAGE_CHECK(m_mainFrame);
2764 MESSAGE_CHECK(m_process->canCreateFrame(frameID));
2766 RefPtr<WebFrameProxy> subFrame = WebFrameProxy::create(this, frameID);
2768 // Add the frame to the process wide map.
2769 m_process->frameCreated(frameID, subFrame.get());
2772 double WebPageProxy::estimatedProgress() const
2774 return m_pageLoadState.estimatedProgress();
2777 void WebPageProxy::didStartProgress()
2779 PageClientProtector protector(m_pageClient);
2781 auto transaction = m_pageLoadState.transaction();
2782 m_pageLoadState.didStartProgress(transaction);
2784 m_pageLoadState.commitChanges();
2785 m_loaderClient->didStartProgress(*this);
2788 void WebPageProxy::didChangeProgress(double value)
2790 PageClientProtector protector(m_pageClient);
2792 auto transaction = m_pageLoadState.transaction();
2793 m_pageLoadState.didChangeProgress(transaction, value);
2795 m_pageLoadState.commitChanges();
2796 m_loaderClient->didChangeProgress(*this);
2799 void WebPageProxy::didFinishProgress()
2801 PageClientProtector protector(m_pageClient);
2803 auto transaction = m_pageLoadState.transaction();
2804 m_pageLoadState.didFinishProgress(transaction);
2806 m_pageLoadState.commitChanges();
2807 m_loaderClient->didFinishProgress(*this);
2810 void WebPageProxy::setNetworkRequestsInProgress(bool networkRequestsInProgress)
2812 auto transaction = m_pageLoadState.transaction();
2813 m_pageLoadState.setNetworkRequestsInProgress(transaction, networkRequestsInProgress);
2816 void WebPageProxy::didDestroyNavigation(uint64_t navigationID)
2818 PageClientProtector protector(m_pageClient);
2820 // FIXME: Message check the navigationID.
2821 m_navigationState->didDestroyNavigation(navigationID);
2824 void WebPageProxy::didStartProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& url, const String& unreachableURL, const UserData& userData)
2826 PageClientProtector protector(m_pageClient);
2828 auto transaction = m_pageLoadState.transaction();
2830 m_pageLoadState.clearPendingAPIRequestURL(transaction);
2832 WebFrameProxy* frame = m_process->webFrame(frameID);
2833 MESSAGE_CHECK(frame);
2834 MESSAGE_CHECK_URL(url);
2836 // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache.
2837 RefPtr<API::Navigation> navigation;
2838 if (frame->isMainFrame() && navigationID)
2839 navigation = &navigationState().navigation(navigationID);
2841 if (frame->isMainFrame())
2842 m_pageLoadState.didStartProvisionalLoad(transaction, url, unreachableURL);
2844 frame->setUnreachableURL(unreachableURL);
2845 frame->didStartProvisionalLoad(url);
2847 m_pageLoadState.commitChanges();
2848 if (m_navigationClient) {
2849 if (frame->isMainFrame())
2850 m_navigationClient->didStartProvisionalNavigation(*this, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get());
2852 m_loaderClient->didStartProvisionalLoadForFrame(*this, *frame, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get());
2855 void WebPageProxy::didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& url, const UserData& userData)
2857 PageClientProtector protector(m_pageClient);
2859 WebFrameProxy* frame = m_process->webFrame(frameID);
2860 MESSAGE_CHECK(frame);
2861 MESSAGE_CHECK_URL(url);
2863 // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache.
2864 RefPtr<API::Navigation> navigation;
2865 if (frame->isMainFrame() && navigationID)
2866 navigation = &navigationState().navigation(navigationID);
2868 auto transaction = m_pageLoadState.transaction();
2870 if (frame->isMainFrame())
2871 m_pageLoadState.didReceiveServerRedirectForProvisionalLoad(transaction, url);
2873 frame->didReceiveServerRedirectForProvisionalLoad(url);
2875 m_pageLoadState.commitChanges();
2876 if (m_navigationClient) {
2877 if (frame->isMainFrame())
2878 m_navigationClient->didReceiveServerRedirectForProvisionalNavigation(*this, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get());
2880 m_loaderClient->didReceiveServerRedirectForProvisionalLoadForFrame(*this, *frame, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get());
2883 void WebPageProxy::didChangeProvisionalURLForFrame(uint64_t frameID, uint64_t, const String& url)
2885 PageClientProtector protector(m_pageClient);
2887 WebFrameProxy* frame = m_process->webFrame(frameID);
2888 MESSAGE_CHECK(frame);
2889 MESSAGE_CHECK(frame->frameLoadState().state() == FrameLoadState::State::Provisional);
2890 MESSAGE_CHECK_URL(url);
2892 auto transaction = m_pageLoadState.transaction();
2894 // Internally, we handle this the same way we handle a server redirect. There are no client callbacks
2895 // for this, but if this is the main frame, clients may observe a change to the page's URL.
2896 if (frame->isMainFrame())
2897 m_pageLoadState.didReceiveServerRedirectForProvisionalLoad(transaction, url);
2899 frame->didReceiveServerRedirectForProvisionalLoad(url);
2902 void WebPageProxy::didFailProvisionalLoadForFrame(uint64_t frameID, const SecurityOriginData& frameSecurityOrigin, uint64_t navigationID, const String& provisionalURL, const ResourceError& error, const UserData& userData)
2904 PageClientProtector protector(m_pageClient);
2906 WebFrameProxy* frame = m_process->webFrame(frameID);
2907 MESSAGE_CHECK(frame);
2909 // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache.
2910 RefPtr<API::Navigation> navigation;
2911 if (frame->isMainFrame() && navigationID)
2912 navigation = navigationState().takeNavigation(navigationID);
2914 auto transaction = m_pageLoadState.transaction();
2916 if (frame->isMainFrame())
2917 m_pageLoadState.didFailProvisionalLoad(transaction);
2919 frame->didFailProvisionalLoad();
2921 m_pageLoadState.commitChanges();
2923 ASSERT(!m_failingProvisionalLoadURL);
2924 m_failingProvisionalLoadURL = provisionalURL;
2926 if (m_navigationClient) {
2927 if (frame->isMainFrame())
2928 m_navigationClient->didFailProvisionalNavigationWithError(*this, *frame, navigation.get(), error, m_process->transformHandlesToObjects(userData.object()).get());
2930 // FIXME: Get the main frame's current navigation.
2931 m_navigationClient->didFailProvisionalLoadInSubframeWithError(*this, *frame, frameSecurityOrigin, nullptr, error, m_process->transformHandlesToObjects(userData.object()).get());
2934 m_loaderClient->didFailProvisionalLoadWithErrorForFrame(*this, *frame, navigation.get(), error, m_process->transformHandlesToObjects(userData.object()).get());
2936 m_failingProvisionalLoadURL = { };
2939 void WebPageProxy::clearLoadDependentCallbacks()
2941 Vector<uint64_t> callbackIDsCopy;
2942 copyToVector(m_loadDependentStringCallbackIDs, callbackIDsCopy);
2943 m_loadDependentStringCallbackIDs.clear();
2945 for (size_t i = 0; i < callbackIDsCopy.size(); ++i) {
2946 auto callback = m_callbacks.take<StringCallback>(callbackIDsCopy[i]);
2948 callback->invalidate();
2952 void WebPageProxy::didCommitLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& mimeType, bool frameHasCustomContentProvider, bool pluginHandlesPageScaleGesture, uint32_t opaqueFrameLoadType, const WebCore::CertificateInfo& certificateInfo, bool containsPluginDocument, const UserData& userData)
2954 PageClientProtector protector(m_pageClient);
2956 WebFrameProxy* frame = m_process->webFrame(frameID);
2957 MESSAGE_CHECK(frame);
2959 // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache.
2960 RefPtr<API::Navigation> navigation;
2961 if (frame->isMainFrame() && navigationID)
2962 navigation = &navigationState().navigation(navigationID);
2965 if (frame->isMainFrame()) {
2966 m_hasReceivedLayerTreeTransactionAfterDidCommitLoad = false;
2967 m_firstLayerTreeTransactionIdAfterDidCommitLoad = downcast<RemoteLayerTreeDrawingAreaProxy>(*drawingArea()).nextLayerTreeTransactionID();
2971 auto transaction = m_pageLoadState.transaction();
2972 bool markPageInsecure = m_treatsSHA1CertificatesAsInsecure && certificateInfo.containsNonRootSHA1SignedCertificate();
2973 Ref<WebCertificateInfo> webCertificateInfo = WebCertificateInfo::create(certificateInfo);
2974 if (frame->isMainFrame()) {
2975 m_pageLoadState.didCommitLoad(transaction, webCertificateInfo, markPageInsecure);
2976 m_suppressNavigationSnapshotting = false;
2977 } else if (markPageInsecure)
2978 m_pageLoadState.didDisplayOrRunInsecureContent(transaction);
2981 // FIXME (bug 59111): didCommitLoadForFrame comes too late when restoring a page from b/f cache, making us disable secure event mode in password fields.
2982 // FIXME: A load going on in one frame shouldn't affect text editing in other frames on the page.
2983 m_pageClient.resetSecureInputState();
2984 m_pageClient.dismissContentRelativeChildWindows();
2987 clearLoadDependentCallbacks();
2989 frame->didCommitLoad(mimeType, webCertificateInfo, containsPluginDocument);
2991 if (frame->isMainFrame()) {
2992 m_mainFrameHasCustomContentProvider = frameHasCustomContentProvider;
2994 if (m_mainFrameHasCustomContentProvider) {
2995 // Always assume that the main frame is pinned here, since the custom representation view will handle
2996 // any wheel events and dispatch them to the WKView when necessary.
2997 m_mainFrameIsPinnedToLeftSide = true;
2998 m_mainFrameIsPinnedToRightSide = true;
2999 m_mainFrameIsPinnedToTopSide = true;
3000 m_mainFrameIsPinnedToBottomSide = true;
3002 m_uiClient->pinnedStateDidChange(*this);
3004 m_pageClient.didCommitLoadForMainFrame(mimeType, frameHasCustomContentProvider);
3007 // Even if WebPage has the default pageScaleFactor (and therefore doesn't reset it),
3008 // WebPageProxy's cache of the value can get out of sync (e.g. in the case where a
3009 // plugin is handling page scaling itself) so we should reset it to the default
3010 // for standard main frame loads.
3011 if (frame->isMainFrame()) {
3012 m_mainFramePluginHandlesPageScaleGesture = pluginHandlesPageScaleGesture;
3014 if (static_cast<FrameLoadType>(opaqueFrameLoadType) == FrameLoadType::Standard) {
3015 m_pageScaleFactor = 1;
3016 m_pluginScaleFactor = 1;
3020 m_pageLoadState.commitChanges();
3021 if (m_navigationClient) {
3022 if (frame->isMainFrame())
3023 m_navigationClient->didCommitNavigation(*this, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get());
3025 m_loaderClient->didCommitLoadForFrame(*this, *frame, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get());
3028 void WebPageProxy::didFinishDocumentLoadForFrame(uint64_t frameID, uint64_t navigationID, const UserData& userData)
3030 PageClientProtector protector(m_pageClient);
3032 WebFrameProxy* frame = m_process->webFrame(frameID);
3033 MESSAGE_CHECK(frame);
3035 // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache.
3036 RefPtr<API::Navigation> navigation;
3037 if (frame->isMainFrame() && navigationID)
3038 navigation = &navigationState().navigation(navigationID);
3040 if (m_navigationClient) {
3041 if (frame->isMainFrame())
3042 m_navigationClient->didFinishDocumentLoad(*this, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get());
3044 m_loaderClient->didFinishDocumentLoadForFrame(*this, *frame, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get());
3047 void WebPageProxy::didFinishLoadForFrame(uint64_t frameID, uint64_t navigationID, const UserData& userData)
3049 PageClientProtector protector(m_pageClient);
3051 WebFrameProxy* frame = m_process->webFrame(frameID);
3052 MESSAGE_CHECK(frame);
3054 // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache.
3055 RefPtr<API::Navigation> navigation;
3056 if (frame->isMainFrame() && navigationID)
3057 navigation = &navigationState().navigation(navigationID);
3059 auto transaction = m_pageLoadState.transaction();
3061 bool isMainFrame = frame->isMainFrame();
3063 m_pageLoadState.didFinishLoad(transaction);
3065 frame->didFinishLoad();
3067 m_pageLoadState.commitChanges();
3068 if (m_navigationClient) {
3070 m_navigationClient->didFinishNavigation(*this, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get());
3072 m_loaderClient->didFinishLoadForFrame(*this, *frame, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get());
3075 m_pageClient.didFinishLoadForMainFrame();
3078 void WebPageProxy::didFailLoadForFrame(uint64_t frameID, uint64_t navigationID, const ResourceError& error, const UserData& userData)
3080 PageClientProtector protector(m_pageClient);
3082 WebFrameProxy* frame = m_process->webFrame(frameID);
3083 MESSAGE_CHECK(frame);
3085 // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache.
3086 RefPtr<API::Navigation> navigation;
3087 if (frame->isMainFrame() && navigationID)
3088 navigation = &navigationState().navigation(navigationID);
3090 clearLoadDependentCallbacks();
3092 auto transaction = m_pageLoadState.transaction();
3094 bool isMainFrame = frame->isMainFrame();
3097 m_pageLoadState.didFailLoad(transaction);
3099 frame->didFailLoad();
3101 m_pageLoadState.commitChanges();
3102 if (m_navigationClient) {
3103 if (frame->isMainFrame())
3104 m_navigationClient->didFailNavigationWithError(*this, *frame, navigation.get(), error, m_process->transformHandlesToObjects(userData.object()).get());
3106 m_loaderClient->didFailLoadWithErrorForFrame(*this, *frame, navigation.get(), error, m_process->transformHandlesToObjects(userData.object()).get());
3109 m_pageClient.didFailLoadForMainFrame();
3112 void WebPageProxy::didSameDocumentNavigationForFrame(uint64_t frameID, uint64_t navigationID, uint32_t opaqueSameDocumentNavigationType, const String& url, const UserData& userData)
3114 PageClientProtector protector(m_pageClient);
3116 WebFrameProxy* frame = m_process->webFrame(frameID);
3117 MESSAGE_CHECK(frame);
3118 MESSAGE_CHECK_URL(url);
3120 // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache.
3121 RefPtr<API::Navigation> navigation;
3122 if (frame->isMainFrame() && navigationID)
3123 navigation = &navigationState().navigation(navigationID);
3125 auto transaction = m_pageLoadState.transaction();
3127 bool isMainFrame = frame->isMainFrame();
3129 m_pageLoadState.didSameDocumentNavigation(transaction, url);
3131 m_pageLoadState.clearPendingAPIRequestURL(transaction);
3132 frame->didSameDocumentNavigation(url);
3134 m_pageLoadState.commitChanges();
3136 SameDocumentNavigationType navigationType = static_cast<SameDocumentNavigationType>(opaqueSameDocumentNavigationType);
3137 if (m_navigationClient) {
3139 m_navigationClient->didSameDocumentNavigation(*this, navigation.get(), navigationType, m_process->transformHandlesToObjects(userData.object()).get());
3141 m_loaderClient->didSameDocumentNavigationForFrame(*this, *frame, navigation.get(), navigationType, m_process->transformHandlesToObjects(userData.object()).get());
3144 m_pageClient.didSameDocumentNavigationForMainFrame(navigationType);
3147 void WebPageProxy::didReceiveTitleForFrame(uint64_t frameID, const String& title, const UserData& userData)
3149 PageClientProtector protector(m_pageClient);
3151 WebFrameProxy* frame = m_process->webFrame(frameID);
3152 MESSAGE_CHECK(frame);
3154 auto transaction = m_pageLoadState.transaction();
3156 if (frame->isMainFrame())
3157 m_pageLoadState.setTitle(transaction, title);
3159 frame->didChangeTitle(title);
3161 m_pageLoadState.commitChanges();
3162 m_loaderClient->didReceiveTitleForFrame(*this, title, *frame, m_process->transformHandlesToObjects(userData.object()).get());
3165 void WebPageProxy::didFirstLayoutForFrame(uint64_t frameID, const UserData& userData)
3167 PageClientProtector protector(m_pageClient);
3169 WebFrameProxy* frame = m_process->webFrame(frameID);
3170 MESSAGE_CHECK(frame);
3172 m_loaderClient->didFirstLayoutForFrame(*this, *frame, m_process->transformHandlesToObjects(userData.object()).get());
3175 void WebPageProxy::didFirstVisuallyNonEmptyLayoutForFrame(uint64_t frameID, const UserData& userData)
3177 PageClientProtector protector(m_pageClient);
3179 WebFrameProxy* frame = m_process->webFrame(frameID);
3180 MESSAGE_CHECK(frame);
3182 m_loaderClient->didFirstVisuallyNonEmptyLayoutForFrame(*this, *frame, m_process->transformHandlesToObjects(userData.object()).get());
3184 if (frame->isMainFrame())
3185 m_pageClient.didFirstVisuallyNonEmptyLayoutForMainFrame();
3188 void WebPageProxy::didLayoutForCustomContentProvider()
3190 didLayout(DidFirstLayout | DidFirstVisuallyNonEmptyLayout | DidHitRelevantRepaintedObjectsAreaThreshold);
3193 void WebPageProxy::didLayout(uint32_t layoutMilestones)
3195 PageClientProtector protector(m_pageClient);
3197 if (m_navigationClient)
3198 m_navigationClient->renderingProgressDidChange(*this, static_cast<LayoutMilestones>(layoutMilestones));
3200 m_loaderClient->didLayout(*this, static_cast<LayoutMilestones>(layoutMilestones));
3203 void WebPageProxy::didDisplayInsecureContentForFrame(uint64_t frameID, const UserData& userData)
3205 PageClientProtector protector(m_pageClient);
3207 WebFrameProxy* frame = m_process->webFrame(frameID);
3208 MESSAGE_CHECK(frame);
3210 auto transaction = m_pageLoadState.transaction();
3211 m_pageLoadState.didDisplayOrRunInsecureContent(transaction);
3213 m_pageLoadState.commitChanges();
3214 m_loaderClient->didDisplayInsecureContentForFrame(*this, *frame, m_process->transformHandlesToObjects(userData.object()).get());
3217 void WebPageProxy::didRunInsecureContentForFrame(uint64_t frameID, const UserData& userData)
3219 PageClientProtector protector(m_pageClient);
3221 WebFrameProxy* frame = m_process->webFrame(frameID);
3222 MESSAGE_CHECK(frame);
3224 auto transaction = m_pageLoadState.transaction();
3225 m_pageLoadState.didDisplayOrRunInsecureContent(transaction);
3227 m_pageLoadState.commitChanges();
3228 m_loaderClient->didRunInsecureContentForFrame(*this, *frame, m_process->transformHandlesToObjects(userData.object()).get());
3231 void WebPageProxy::didDetectXSSForFrame(uint64_t frameID, const UserData& userData)
3233 PageClientProtector protector(m_pageClient);
3235 WebFrameProxy* frame = m_process->webFrame(frameID);
3236 MESSAGE_CHECK(frame);
3238 m_loaderClient->didDetectXSSForFrame(*this, *frame, m_process->transformHandlesToObjects(userData.object()).get());
3241 void WebPageProxy::frameDidBecomeFrameSet(uint64_t frameID, bool value)
3243 PageClientProtector protector(m_pageClient);
3245 WebFrameProxy* frame = m_process->webFrame(frameID);
3246 MESSAGE_CHECK(frame);
3248 frame->setIsFrameSet(value);
3249 if (frame->isMainFrame())
3250 m_frameSetLargestFrame = value ? m_mainFrame : 0;
3253 void WebPageProxy::decidePolicyForNavigationAction(uint64_t frameID, const SecurityOriginData& frameSecurityOrigin, uint64_t navigationID, const NavigationActionData& navigationActionData, uint64_t originatingFrameID, const SecurityOriginData& originatingFrameSecurityOrigin, const WebCore::ResourceRequest& originalRequest, const ResourceRequest& request, uint64_t listenerID, const UserData& userData, bool& receivedPolicyAction, uint64_t& newNavigationID, uint64_t& policyAction, uint64_t& downloadID)
3255 PageClientProtector protector(m_pageClient);
3257 auto transaction = m_pageLoadState.transaction();
3259 if (request.url() != m_pageLoadState.pendingAPIRequestURL())
3260 m_pageLoadState.clearPendingAPIRequestURL(transaction);
3262 WebFrameProxy* frame = m_process->webFrame(frameID);
3263 MESSAGE_CHECK(frame);
3264 MESSAGE_CHECK_URL(request.url());
3265 MESSAGE_CHECK_URL(originalRequest.url());
3267 WebFrameProxy* originatingFrame = m_process->webFrame(originatingFrameID);
3269 Ref<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
3270 if (!navigationID && frame->isMainFrame()) {
3271 auto navigation = m_navigationState->createLoadRequestNavigation(request);
3272 newNavigationID = navigation->navigationID();
3273 listener->setNavigation(WTF::move(navigation));
3276 #if ENABLE(CONTENT_FILTERING)
3277 if (frame->didHandleContentFilterUnblockNavigation(request)) {
3278 receivedPolicyAction = true;
3279 policyAction = PolicyIgnore;
3284 ASSERT(!m_inDecidePolicyForNavigationAction);
3286 m_inDecidePolicyForNavigationAction = true;
3287 m_syncNavigationActionPolicyActionIsValid = false;
3289 if (m_navigationClient) {
3290 RefPtr<API::FrameInfo> destinationFrameInfo;
3291 RefPtr<API::FrameInfo> sourceFrameInfo;
3294 destinationFrameInfo = API::FrameInfo::create(*frame, frameSecurityOrigin.securityOrigin());
3296 if (originatingFrame == frame)
3297 sourceFrameInfo = destinationFrameInfo;
3298 else if (originatingFrame)
3299 sourceFrameInfo = API::FrameInfo::create(*originatingFrame, originatingFrameSecurityOrigin.securityOrigin());
3301 bool shouldOpenAppLinks = !m_shouldSuppressAppLinksInNextNavigationPolicyDecision && (!destinationFrameInfo || destinationFrameInfo->isMainFrame()) && !hostsAreEqual(URL(ParsedURLString, m_mainFrame->url()), request.url());
3303 auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.get(), destinationFrameInfo.get(), request, originalRequest.url(), shouldOpenAppLinks);
3305 m_navigationClient->decidePolicyForNavigationAction(*this, navigationAction.get(), WTF::move(listener), m_process->transformHandlesToObjects(userData.object()).get());
3307 m_policyClient->decidePolicyForNavigationAction(*this, frame, navigationActionData, originatingFrame, originalRequest, request, WTF::move(listener), m_process->transformHandlesToObjects(userData.object()).get());
3309 m_shouldSuppressAppLinksInNextNavigationPolicyDecision = false;
3310 m_inDecidePolicyForNavigationAction = false;
3312 // Check if we received a policy decision already. If we did, we can just pass it back.
3313 receivedPolicyAction = m_syncNavigationActionPolicyActionIsValid;
3314 if (m_syncNavigationActionPolicyActionIsValid) {
3315 policyAction = m_syncNavigationActionPolicyAction;
3316 downloadID = m_syncNavigationActionPolicyDownloadID;
3320 void WebPageProxy::decidePolicyForNewWindowAction(uint64_t frameID, const SecurityOriginData& frameSecurityOrigin, const NavigationActionData& navigationActionData, const ResourceRequest& request, const String& frameName, uint64_t listenerID, const UserData& userData)
3322 PageClientProtector protector(m_pageClient);
3324 WebFrameProxy* frame = m_process->webFrame(frameID);
3325 MESSAGE_CHECK(frame);
3326 MESSAGE_CHECK_URL(request.url());
3328 Ref<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
3330 if (m_navigationClient) {
3331 RefPtr<API::FrameInfo> sourceFrameInfo;
3333 sourceFrameInfo = API::FrameInfo::create(*frame, frameSecurityOrigin.securityOrigin());
3335 bool shouldOpenAppLinks = !hostsAreEqual(URL(ParsedURLString, m_mainFrame->url()), request.url());
3336 auto navigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.get(), nullptr, request, request.url(), shouldOpenAppLinks);
3338 m_navigationClient->decidePolicyForNavigationAction(*this, navigationAction.get(), WTF::move(listener), m_process->transformHandlesToObjects(userData.object()).get());
3341 m_policyClient->decidePolicyForNewWindowAction(*this, *frame, navigationActionData, request, frameName, WTF::move(listener), m_process->transformHandlesToObjects(userData.object()).get());
3344 void WebPageProxy::decidePolicyForResponse(uint64_t frameID, const SecurityOriginData& frameSecurityOrigin, const ResourceResponse& response, const ResourceRequest& request, bool canShowMIMEType, uint64_t listenerID, const UserData& userData)
3346 PageClientProtector protector(m_pageClient);
3348 WebFrameProxy* frame = m_process->webFrame(frameID);
3349 MESSAGE_CHECK(frame);
3350 MESSAGE_CHECK_URL(request.url());
3351 MESSAGE_CHECK_URL(response.url());
3353 Ref<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
3355 if (m_navigationClient) {
3356 auto navigationResponse = API::NavigationResponse::create(API::FrameInfo::create(*frame, frameSecurityOrigin.securityOrigin()).get(), request, response, canShowMIMEType);
3357 m_navigationClient->decidePolicyForNavigationResponse(*this, navigationResponse.get(), WTF::move(listener), m_process->transformHandlesToObjects(userData.object()).get());
3359 m_policyClient->decidePolicyForResponse(*this, *frame, response, request, canShowMIMEType, WTF::move(listener), m_process->transformHandlesToObjects(userData.object()).get());
3362 void WebPageProxy::decidePolicyForResponseSync(uint64_t frameID, const SecurityOriginData& frameSecurityOrigin, const ResourceResponse& response, const ResourceRequest& request, bool canShowMIMEType, uint64_t listenerID, const UserData& userData, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID)
3364 PageClientProtector protector(m_pageClient);
3366 ASSERT(!m_inDecidePolicyForResponseSync);
3368 m_inDecidePolicyForResponseSync = true;
3369 m_decidePolicyForResponseRequest = &request;
3370 m_syncMimeTypePolicyActionIsValid = false;
3372 decidePolicyForResponse(frameID, frameSecurityOrigin, response, request, canShowMIMEType, listenerID, userData);
3374 m_inDecidePolicyForResponseSync = false;
3375 m_decidePolicyForResponseRequest = 0;
3377 // Check if we received a policy decision already. If we did, we can just pass it back.
3378 receivedPolicyAction = m_syncMimeTypePolicyActionIsValid;
3379 if (m_syncMimeTypePolicyActionIsValid) {
3380 policyAction = m_syncMimeTypePolicyAction;
3381 downloadID = m_syncMimeTypePolicyDownloadID;
3385 void WebPageProxy::unableToImplementPolicy(uint64_t frameID, const ResourceError& error, const UserData& userData)
3387 PageClientProtector protector(m_pageClient);
3389 WebFrameProxy* frame = m_process->webFrame(frameID);
3390 MESSAGE_CHECK(frame);
3392 m_policyClient->unableToImplementPolicy(*this, *frame, error, m_process->transformHandlesToObjects(userData.object()).get());
3397 void WebPageProxy::willSubmitForm(uint64_t frameID, uint64_t sourceFrameID, const Vector<std::pair<String, String>>& textFieldValues, uint64_t listenerID, const UserData& userData)
3399 WebFrameProxy* frame = m_process->webFrame(frameID);
3400 MESSAGE_CHECK(frame);
3402 WebFrameProxy* sourceFrame = m_process->webFrame(sourceFrameID);
3403 MESSAGE_CHECK(sourceFrame);
3405 Ref<WebFormSubmissionListenerProxy> listener = frame->setUpFormSubmissionListenerProxy(listenerID);
3406 m_formClient->willSubmitForm(*this, *frame, *sourceFrame, textFieldValues, m_process->transformHandlesToObjects(userData.object()).get(), listener.get());
3409 void WebPageProxy::didNavigateWithNavigationData(const WebNavigationDataStore& store, uint64_t frameID)
3411 PageClientProtector protector(m_pageClient);
3413 WebFrameProxy* frame = m_process->webFrame(frameID);
3414 MESSAGE_CHECK(frame);
3415 MESSAGE_CHECK(frame->page() == this);
3417 if (m_historyClient) {
3418 if (frame->isMainFrame())
3419 m_historyClient->didNavigateWithNavigationData(*this, store);
3421 m_loaderClient->didNavigateWithNavigationData(*this, store, *frame);
3422 process().processPool().historyClient().didNavigateWithNavigationData(process().processPool(), *this, store, *frame);
3425 void WebPageProxy::didPerformClientRedirect(const String& sourceURLString, const String& destinationURLString, uint64_t frameID)
3427 PageClientProtector protector(m_pageClient);
3429 if (sourceURLString.isEmpty() || destinationURLString.isEmpty())
3432 WebFrameProxy* frame = m_process->webFrame(frameID);
3433 MESSAGE_CHECK(frame);
3434 MESSAGE_CHECK(frame->page() == this);
3436 MESSAGE_CHECK_URL(sourceURLString);
3437 MESSAGE_CHECK_URL(destinationURLString);
3439 if (m_historyClient) {
3440 if (frame->isMainFrame())
3441 m_historyClient->didPerformClientRedirect(*this, sourceURLString, destinationURLString);
3443 m_loaderClient->didPerformClientRedirect(*this, sourceURLString, destinationURLString, *frame);
3444 process().processPool().historyClient().didPerformClientRedirect(process().processPool(), *this, sourceURLString, destinationURLString, *frame);
3447 void WebPageProxy::didPerformServerRedirect(const String& sourceURLString, const String& destinationURLString, uint64_t frameID)
3449 PageClientProtector protector(m_pageClient);
3451 if (sourceURLString.isEmpty() || destinationURLString.isEmpty())
3454 WebFrameProxy* frame = m_process->webFrame(frameID);
3455 MESSAGE_CHECK(frame);
3456 MESSAGE_CHECK(frame->page() == this);
3458 MESSAGE_CHECK_URL(sourceURLString);
3459 MESSAGE_CHECK_URL(destinationURLString);
3461 if (m_historyClient) {
3462 if (frame->isMainFrame())
3463 m_historyClient->didPerformServerRedirect(*this, sourceURLString, destinationURLString);
3465 m_loaderClient->didPerformServerRedirect(*this, sourceURLString, destinationURLString, *frame);
3466 process().processPool().historyClient().didPerformServerRedirect(process().processPool(), *this, sourceURLString, destinationURLString, *frame);
3469 void WebPageProxy::didUpdateHistoryTitle(const String& title, const String& url, uint64_t frameID)
3471 PageClientProtector protector(m_pageClient);
3473 WebFrameProxy* frame = m_process->webFrame(frameID);
3474 MESSAGE_CHECK(frame);
3475 MESSAGE_CHECK(frame->page() == this);
3477 MESSAGE_CHECK_URL(url);
3479 if (m_historyClient) {
3480 if (frame->isMainFrame())
3481 m_historyClient->didUpdateHistoryTitle(*this, title, url);
3483 m_loaderClient->didUpdateHistoryTitle(*this, title, url, *frame);
3484 process().processPool().historyClient().didUpdateHistoryTitle(process().processPool(), *this, title, url, *frame);
3489 void WebPageProxy::createNewPage(uint64_t frameID, const SecurityOriginData& securityOriginData, const ResourceRequest& request, const WindowFeatures& windowFeatures, const NavigationActionData& navigationActionData, uint64_t& newPageID, WebPageCreationParameters& newPageParameters)
3491 WebFrameProxy* frame = m_process->webFrame(frameID);
3492 MESSAGE_CHECK(frame);
3494 auto mainFrameURL = m_mainFrame->url();
3496 RefPtr<WebPageProxy> newPage = m_uiClient->createNewPage(this, frame, securityOriginData, request, windowFeatures, navigationActionData);
3502 newPageID = newPage->pageID();
3503 newPageParameters = newPage->creationParameters();
3505 WebsiteDataStore::cloneSessionData(*this, *newPage);
3506 newPage->m_shouldSuppressAppLinksInNextNavigationPolicyDecision = hostsAreEqual(URL(ParsedURLString, mainFrameURL), request.url());
3509 void WebPageProxy::showPage()
3511 m_uiClient->showPage(this);
3514 void WebPageProxy::fullscreenMayReturnToInline()
3516 m_uiClient->fullscreenMayReturnToInline(this);
3519 void WebPageProxy::didEnterFullscreen()
3521 m_uiClient->didEnterFullscreen(this);
3524 void WebPageProxy::didExitFullscreen()
3526 m_uiClient->didExitFullscreen(this);
3529 void WebPageProxy::closePage(bool stopResponsivenessTimer)
3531 if (stopResponsivenessTimer)
3532 m_process->responsivenessTimer().stop();
3534 m_pageClient.clearAllEditCommands();
3535 m_uiClient->close(this);
3538 void WebPageProxy::runJavaScriptAlert(uint64_t frameID, const SecurityOriginData& securityOrigin, const String& message, RefPtr<Messages::WebPageProxy::RunJavaScriptAlert::DelayedReply> reply)
3540 WebFrameProxy* frame = m_process->webFrame(frameID);
3541 MESSAGE_CHECK(frame);
3543 // Since runJavaScriptAlert() can spin a nested run loop we need to turn off the responsiveness timer.
3544 m_process->responsivenessTimer().stop();
3546 m_uiClient->runJavaScriptAlert(this, message, frame, securityOrigin, [reply]{ reply->send(); });
3549 void WebPageProxy::runJavaScriptConfirm(uint64_t frameID, const SecurityOriginData& securityOrigin, const String& message, RefPtr<Messages::WebPageProxy::RunJavaScriptConfirm::DelayedReply> reply)
3551 WebFrameProxy* frame = m_process->webFrame(frameID);
3552 MESSAGE_CHECK(frame);
3554 // Since runJavaScriptConfirm() can spin a nested run loop we need to turn off the responsiveness timer.
3555 m_process->responsivenessTimer().stop();
3557 m_uiClient->runJavaScriptConfirm(this, message, frame, securityOrigin, [reply](bool result) { reply->send(result); });
3560 void WebPageProxy::runJavaScriptPrompt(uint64_t frameID, const SecurityOriginData& securityOrigin, const String& message, const String& defaultValue, RefPtr<Messages::WebPageProxy::RunJavaScriptPrompt::DelayedReply> reply)
3562 WebFrameProxy* frame = m_process->webFrame(frameID);
3563 MESSAGE_CHECK(frame);
3565 // Since runJavaScriptPrompt() can spin a nested run loop we need to turn off the responsiveness timer.
3566 m_process->responsivenessTimer().stop();
3568 m_uiClient->runJavaScriptPrompt(this, message, defaultValue, frame, securityOrigin, [reply](const String& result) { reply->send(result); });
3571 void WebPageProxy::setStatusText(const String& text)
3573 m_uiClient->setStatusText(this, text);
3576 void WebPageProxy::mouseDidMoveOverElement(const WebHitTestResultData& hitTestResultData, uint32_t opaqueModifiers, const UserData& userData)
3578 m_lastMouseMoveHitTestResult = API::HitTestResult::create(hitTestResultData);
3580 WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
3582 m_uiClient->mouseDidMoveOverElement(this, hitTestResultData, modifiers, m_process->transformHandlesToObjects(userData.object()).get());
3585 void WebPageProxy::connectionWillOpen(IPC::Connection& connection)
3587 ASSERT(&connection == m_process->connection());
3589 m_webProcessLifetimeTracker.connectionWillOpen(connection);
3592 void WebPageProxy::webProcessWillShutDown()
3594 m_webProcessLifetimeTracker.webProcessWillShutDown();
3597 void WebPageProxy::processDidFinishLaunching()
3599 ASSERT(m_process->state() == WebProcessProxy::State::Running);
3601 if (m_userContentController)
3602 m_process->addWebUserContentControllerProxy(*m_userContentController);
3603 m_process->addVisitedLinkStore(m_visitedLinkStore);
3606 #if ENABLE(NETSCAPE_PLUGIN_API)
3607 void WebPageProxy::unavailablePluginButtonClicked(uint32_t opaquePluginUnavailabilityReason, const String& mimeType, const String& pluginURLString, const String& pluginspageAttributeURLString, const String& frameURLString, const String& pageURLString)
3609 MESSAGE_CHECK_URL(pluginURLString);
3610 MESSAGE_CHECK_URL(pluginspageAttributeURLString);
3611 MESSAGE_CHECK_URL(frameURLString);
3612 MESSAGE_CHECK_URL(pageURLString);
3614 RefPtr<API::Dictionary> pluginInformation;
3615 String newMimeType = mimeType;
3616 PluginModuleInfo plugin = m_process->processPool().pluginInfoStore().findPlugin(newMimeType, URL(URL(), pluginURLString));
3617 pluginInformation = createPluginInformationDictionary(plugin, frameURLString, mimeType, pageURLString, pluginspageAttributeURLString, pluginURLString);
3619 WKPluginUnavailabilityReason pluginUnavailabilityReason = kWKPluginUnavailabilityReasonPluginMissing;
3620 switch (static_cast<RenderEmbeddedObject::PluginUnavailabilityReason>(opaquePluginUnavailabilityReason)) {
3621 case RenderEmbeddedObject::PluginMissing:
3622 pluginUnavailabilityReason = kWKPluginUnavailabilityReasonPluginMissing;
3624 case RenderEmbeddedObject::InsecurePluginVersion:
3625 pluginUnavailabilityReason = kWKPluginUnavailabilityReasonInsecurePluginVersion;
3627 case RenderEmbeddedObject::PluginCrashed:
3628 pluginUnavailabilityReason = kWKPluginUnavailabilityReasonPluginCrashed;
3630 case RenderEmbeddedObject::PluginBlockedByContentSecurityPolicy:
3631 ASSERT_NOT_REACHED();
3634 m_uiClient->unavailablePluginButtonClicked(this, pluginUnavailabilityReason, pluginInformation.get());
3636 #endif // ENABLE(NETSCAPE_PLUGIN_API)
3639 void WebPageProxy::webGLPolicyForURL(const String& url, uint32_t& loadPolicy)
3641 loadPolicy = static_cast<uint32_t>(m_loaderClient->webGLLoadPolicy(*this, url));
3644 void WebPageProxy::resolveWebGLPolicyForURL(const String& url, uint32_t& loadPolicy)
3646 loadPolicy = static_cast<uint32_t>(m_loaderClient->resolveWebGLLoadPolicy(*this, url));
3648 #endif // ENABLE(WEBGL)
3650 void WebPageProxy::setToolbarsAreVisible(bool toolbarsAreVisible)
3652 m_uiClient->setToolbarsAreVisible(this, toolbarsAreVisible);
3655 void WebPageProxy::getToolbarsAreVisible(bool& toolbarsAreVisible)
3657 toolbarsAreVisible = m_uiClient->toolbarsAreVisible(this);
3660 void WebPageProxy::setMenuBarIsVisible(bool menuBarIsVisible)
3662 m_uiClient->setMenuBarIsVisible(this, menuBarIsVisible);
3665 void WebPageProxy::getMenuBarIsVisible(bool& menuBarIsVisible)
3667 menuBarIsVisible = m_uiClient->menuBarIsVisible(this);
3670 void WebPageProxy::setStatusBarIsVisible(bool statusBarIsVisible)
3672 m_uiClient->setStatusBarIsVisible(this, statusBarIsVisible);
3675 void WebPageProxy::getStatusBarIsVisible(bool& statusBarIsVisible)
3677 statusBarIsVisible = m_uiClient->statusBarIsVisible(this);
3680 void WebPageProxy::setIsResizable(bool isResizable)
3682 m_uiClient->setIsResizable(this, isResizable);
3685 void WebPageProxy::getIsResizable(bool& isResizable)
3687 isResizable = m_uiClient->isResizable(this);
3690 void WebPageProxy::setWindowFrame(const FloatRect& newWindowFrame)
3692 m_uiClient->setWindowFrame(this, m_pageClient.convertToDeviceSpace(newWindowFrame));
3695 void WebPageProxy::getWindowFrame(FloatRect& newWindowFrame)
3697 newWindowFrame = m_pageClient.convertToUserSpace(m_uiClient->windowFrame(this));
3700 void WebPageProxy::screenToRootView(const IntPoint& screenPoint, IntPoint& windowPoint)
3702 windowPoint = m_pageClient.screenToRootView(screenPoint);
3705 void WebPageProxy::rootViewToScreen(const IntRect& viewRect, IntRect& result)
3707 result = m_pageClient.rootViewToScreen(viewRect);
3711 void WebPageProxy::accessibilityScreenToRootView(const IntPoint& screenPoint, IntPoint& windowPoint)
3713 windowPoint = m_pageClient.accessibilityScreenToRootView(screenPoint);
3716 void WebPageProxy::rootViewToAccessibilityScreen(const IntRect& viewRect, IntRect& result)
3718 result = m_pageClient.rootViewToAccessibilityScreen(viewRect);
3722 void WebPageProxy::runBeforeUnloadConfirmPanel(const String& message, uint64_t frameID, bool& shouldClose)
3724 WebFrameProxy* frame = m_process->webFrame(frameID);
3725 MESSAGE_CHECK(frame);
3727 // Since runBeforeUnloadConfirmPanel() can spin a nested run loop we need to turn off the responsiveness timer.
3728 m_process->responsivenessTimer().stop();
3730 shouldClose = m_uiClient->runBeforeUnloadConfirmPanel(this, message, frame);
3733 #if USE(COORDINATED_GRAPHICS_MULTIPROCESS)
3734 void WebPageProxy::pageDidRequestScroll(const IntPoint& point)
3736 m_pageClient.pageDidRequestScroll(point);
3739 void WebPageProxy::pageTransitionViewportReady()
3741 m_pageClient.pageTransitionViewportReady();
3744 void WebPageProxy::didRenderFrame(const WebCore::IntSize& contentsSize, const WebCore::IntRect& coveredRect)
3746 m_pageClient.didRenderFrame(contentsSize, coveredRect);
3749 void WebPageProxy::commitPageTransitionViewport()
3754 process().send(Messages::WebPage::CommitPageTransitionViewport(), m_pageID);
3758 void WebPageProxy::didChangeViewportProperties(const ViewportAttributes& attr)
3760 m_pageClient.didChangeViewportProperties(attr);
3763 void WebPageProxy::pageDidScroll()
3765 m_uiClient->pageDidScroll(this);
3768 void WebPageProxy::runOpenPanel(uint64_t frameID, const FileChooserSettings& settings)
3770 if (m_openPanelResultListener) {
3771 m_openPanelResultListener->invalidate();
3772 m_openPanelResultListener = nullptr;
3775 WebFrameProxy* frame = m_process->webFrame(frameID);
3776 MESSAGE_CHECK(frame);
3778 RefPtr<WebOpenPanelParameters> parameters = WebOpenPanelParameters::create(settings);
3779 m_openPanelResultListener = WebOpenPanelResultListenerProxy::create(this);
3781 // Since runOpenPanel() can spin a nested run loop we need to turn off the responsiveness timer.
3782 m_process->responsivenessTimer().stop();
3784 if (!m_uiClient->runOpenPanel(this, frame, parameters.get(), m_openPanelResultListener.get())) {
3785 if (!m_pageClient.handleRunOpenPanel(this, frame, parameters.get(), m_openPanelResultListener.get()))
3786 didCancelForOpenPanel();
3790 void WebPageProxy::printFrame(uint64_t frameID)
3792 ASSERT(!m_isPerformingDOMPrintOperation);
3793 m_isPerformingDOMPrintOperation = true;
3795 WebFrameProxy* frame = m_process->webFrame(frameID);
3796 MESSAGE_CHECK(frame);
3798 m_uiClient->printFrame(this, frame);
3800 endPrinting(); // Send a message synchronously while m_isPerformingDOMPrintOperation is still true.
3801 m_isPerformingDOMPrintOperation = false;
3804 void WebPageProxy::printMainFrame()
3806 printFrame(m_mainFrame->frameID());
3809 void WebPageProxy::setMediaVolume(float volume)
3811 if (volume == m_mediaVolume)
3814 m_mediaVolume = volume;
3819 m_process->send(Messages::WebPage::SetMediaVolume(volume), m_pageID);
3822 void WebPageProxy::setMuted(bool muted)
3824 if (m_muted == muted)
3832 m_process->send(Messages::WebPage::SetMuted(muted), m_pageID);
3835 #if ENABLE(MEDIA_SESSION)
3836 void WebPageProxy::handleMediaEvent(MediaEventType eventType)
3841 m_process->send(Messages::WebPage::HandleMediaEvent(eventType), m_pageID);
3844 void WebPageProxy::setVolumeOfMediaElement(double volume, uint64_t elementID)
3849 m_process->send(Messages::WebPage::SetVolumeOfMediaElement(volume, elementID), m_pageID);
3853 void WebPageProxy::setMayStartMediaWhenInWindow(bool mayStartMedia)
3855 if (mayStartMedia == m_mayStartMediaWhenInWindow)
3858 m_mayStartMediaWhenInWindow = mayStartMedia;
3863 process().send(Messages::WebPage::SetMayStartMediaWhenInWindow(mayStartMedia), m_pageID);
3866 void WebPageProxy::handleDownloadRequest(DownloadProxy* download)
3868 m_pageClient.handleDownloadRequest(download);
3871 void WebPageProxy::didChangeContentSize(const IntSize& size)
3873 m_pageClient.didChangeContentSize(size);
3876 #if ENABLE(INPUT_TYPE_COLOR)
3877 void WebPageProxy::showColorPicker(const WebCore::Color& initialColor, const IntRect& elementRect)
3879 #if ENABLE(INPUT_TYPE_COLOR_POPOVER)
3880 // A new popover color well needs to be created (and the previous one destroyed) for
3881 // each activation of a color element.
3882 m_colorPicker = nullptr;
3885 m_colorPicker = m_pageClient.createColorPicker(this, initialColor, elementRect);
3886 m_colorPicker->showColorPicker(initialColor);
3889 void WebPageProxy::setColorPickerColor(const WebCore::Color& color)
3891 ASSERT(m_colorPicker);
3893 m_colorPicker->setSelectedColor(color);
3896 void WebPageProxy::endColorPicker()
3898 ASSERT(m_colorPicker);
3900 m_colorPicker->endPicker();
3903 void WebPageProxy::didChooseColor(const WebCore::Color& color)
3908 m_process->send(Messages::WebPage::DidChooseColor(color), m_pageID);
3911 void WebPageProxy::didEndColorPicker()
3916 #if ENABLE(INPUT_TYPE_COLOR)
3917 if (m_colorPicker) {
3918 m_colorPicker->invalidate();
3919 m_colorPicker = nullptr;
3923 m_process->send(Messages::WebPage::DidEndColorPicker(), m_pageID);
3928 WebInspectorProxy* WebPageProxy::inspector()
3930 if (isClosed() || !isValid())
3932 return m_inspector.get();
3935 #if ENABLE(FULLSCREEN_API)
3936 WebFullScreenManagerProxy* WebPageProxy::fullScreenManager()
3938 return m_fullScreenManager.get();
3943 RefPtr<WebVideoFullscreenManagerProxy> WebPageProxy::videoFullscreenManager()
3945 return m_videoFullscreenManager;
3948 bool WebPageProxy::allowsMediaDocumentInlinePlayback() const
3950 return m_allowsMediaDocumentInlinePlayback;
3953 void WebPageProxy::setAllowsMediaDocumentInlinePlayback(bool allows)
3955 if (m_allowsMediaDocumentInlinePlayback == allows)
3957 m_allowsMediaDocumentInlinePlayback = allows;
3959 m_process->send(Messages::WebPage::SetAllowsMediaDocumentInlinePlayback(allows), m_pageID);
3965 void WebPageProxy::backForwardAddItem(uint64_t itemID)
3967 m_backForwardList->addItem(m_process->webBackForwardItem(itemID));
3970 void WebPageProxy::backForwardGoToItem(uint64_t itemID, SandboxExtension::Handle& sandboxExtensionHandle)
3972 WebBackForwardListItem* item = m_process->webBackForwardItem(itemID);
3976 bool createdExtension = maybeInitializeSandboxExtensionHandle(URL(URL(), item->url()), sandboxExtensionHandle);
3977 if (createdExtension)
3978 m_process->willAcquireUniversalFileReadSandboxExtension();
3979 m_backForwardList->goToItem(item);
3982 void WebPageProxy::backForwardItemAtIndex(int32_t index, uint64_t& itemID)
3984 WebBackForwardListItem* item = m_backForwardList->itemAtIndex(index);
3985 itemID = item ? item->itemID() : 0;
3988 void WebPageProxy::backForwardBackListCount(int32_t& count)
3990 count = m_backForwardList->backListCount();
3993 void WebPageProxy::backForwardForwardListCount(int32_t& count)
3995 count = m_backForwardList->forwardListCount();
3998 void WebPageProxy::compositionWasCanceled(const EditorState& editorState)
4001 m_pageClient.notifyInputContextAboutDiscardedComposition();
4003 editorStateChanged(editorState);
4008 void WebPageProxy::registerEditCommandForUndo(uint64_t commandID, uint32_t editAction)
4010 registerEditCommand(WebEditCommandProxy::create(commandID, static_cast<EditAction>(editAction), this), Undo);
4013 void WebPageProxy::registerInsertionUndoGrouping()
4015 #if USE(INSERTION_UNDO_GROUPING)
4016 m_pageClient.registerInsertionUndoGrouping();
4020 void WebPageProxy::canUndoRedo(uint32_t action, bool& result)
4022 result = m_pageClient.canUndoRedo(static_cast<UndoOrRedo>(action));
4025 void WebPageProxy::executeUndoRedo(uint32_t action, bool& result)
4027 m_pageClient.executeUndoRedo(static_cast<UndoOrRedo>(action));
4031 void WebPageProxy::clearAllEditCommands()
4033 m_pageClient.clearAllEditCommands();
4036 void WebPageProxy::didCountStringMatches(const String& string, uint32_t matchCount)
4038 m_findClient->didCountStringMatches(this, string, matchCount);
4041 void WebPageProxy::didGetImageForFindMatch(const ShareableBitmap::Handle& contentImageHandle, uint32_t matchIndex)
4043 m_findMatchesClient->didGetImageForMatchResult(this, WebImage::create(ShareableBitmap::create(contentImageHandle)).get(), matchIndex);
4046 void WebPageProxy::setTextIndicator(const TextIndicatorData& indicatorData, uint64_t lifetime)
4048 // FIXME: Make TextIndicatorWindow a platform-independent presentational thing ("TextIndicatorPresentation"?).
4050 m_pageClient.setTextIndicator(TextIndicator::create(indicatorData), static_cast<TextIndicatorWindowLifetime>(lifetime));
4052 ASSERT_NOT_REACHED();
4056 void WebPageProxy::clearTextIndicator()
4059 m_pageClient.clearTextIndicator(TextIndicatorWindowDismissalAnimation::FadeOut);
4061 ASSERT_NOT_REACHED();
4065 void WebPageProxy::setTextIndicatorAnimationProgress(float progress)
4068 m_pageClient.setTextIndicatorAnimationProgress(progress);
4070 ASSERT_NOT_REACHED();
4074 void WebPageProxy::didFindString(const String& string, const Vector<WebCore::IntRect>& matchRects, uint32_t matchCount, int32_t matchIndex)
4076 m_findClient->didFindString(this, string, matchRects, matchCount, matchIndex);
4079 void WebPageProxy::didFindStringMatches(const String& string, const Vector<Vector<WebCore::IntRect>>& matchRects, int32_t firstIndexAfterSelection)
4081 m_findMatchesClient->didFindStringMatches(this, string, matchRects, firstIndexAfterSelection);
4084 void WebPageProxy::didFailToFindString(const String& string)
4086 m_findClient->didFailToFindString(this, string);
4089 bool WebPageProxy::sendMessage(std::unique_ptr<IPC::MessageEncoder> encoder, unsigned messageSendFlags)
4091 return m_process->sendMessage(WTF::move(encoder), messageSendFlags);
4094 IPC::Connection* WebPageProxy::messageSenderConnection()
4096 return m_process->connection();
4099 uint64_t WebPageProxy::messageSenderDestinationID()
4104 void WebPageProxy::valueChangedForPopupMenu(WebPopupMenuProxy*, int32_t newSelectedIndex)
4106 m_process->send(Messages::WebPage::DidChangeSelectedIndexForActivePopupMenu(newSelectedIndex), m_pageID);
4109 void WebPageProxy::setTextFromItemForPopupMenu(WebPopupMenuProxy*, int32_t index)
4111 m_process->send(Messages::WebPage::SetTextForActivePopupMenu(index), m_pageID);
4114 NativeWebMouseEvent* WebPageProxy::currentlyProcessedMouseDownEvent()
4116 return m_currentlyProcessedMouseDownEvent.get();
4119 void WebPageProxy::postMessageToInjectedBundle(const String& messageName, API::Object* messageBody)
4121 process().send(Messages::WebPage::PostInjectedBundleMessage(messageName, UserData(process().transformObjectsToHandles(messageBody).get())), m_pageID);
4125 void WebPageProxy::failedToShowPopupMenu()
4127 m_process->send(Messages::WebPage::FailedToShowPopupMenu(), m_pageID);
4131 void WebPageProxy::showPopupMenu(const IntRect& rect, uint64_t textDirection, const Vector<WebPopupItem>& items, int32_t selectedIndex, const PlatformPopupMenuData& data)
4133 if (m_activePopupMenu) {
4135 m_uiPopupMenuClient.hidePopupMenu(this);
4137 m_activePopupMenu->hidePopupMenu();
4139 m_activePopupMenu->invalidate();
4140 m_activePopupMenu = nullptr;
4143 m_activePopupMenu = m_pageClient.createPopupMenuProxy(*this);
4145 if (!m_activePopupMenu)
4148 // Since showPopupMenu() can spin a nested run loop we need to turn off the responsiveness timer.
4149 m_process->responsivenessTimer().stop();
4153 m_uiPopupMenuClient.showPopupMenu(this, m_activePopupMenu.get(), rect, static_cast<TextDirection>(textDirection), m_pageScaleFactor, items, selectedIndex);
4156 // Showing a popup menu runs a nested runloop, which can handle messages that cause |this| to get closed.
4157 Ref<WebPageProxy> protect(*this);
4158 m_activePopupMenu->showPopupMenu(rect, static_cast<TextDirection>(textDirection), m_pageScaleFactor, items, data, selectedIndex);
4162 void WebPageProxy::hidePopupMenu()
4164 if (!m_activePopupMenu)
4168 m_uiPopupMenuClient.hidePopupMenu(this);
4170 m_activePopupMenu->hidePopupMenu();
4172 m_activePopupMenu->invalidate();
4173 m_activePopupMenu = nullptr;
4176 #if ENABLE(CONTEXT_MENUS)
4177 void WebPageProxy::showContextMenu(const ContextMenuContextData& contextMenuContextData, const UserData& userData)
4179 // Showing a context menu runs a nested runloop, which can handle messages that cause |this| to get closed.
4180 Ref<WebPageProxy> protect(*this);
4182 internalShowContextMenu(contextMenuContextData, userData);
4184 // No matter the result of internalShowContextMenu, always notify the WebProcess that the menu is hidden so it starts handling mouse events again.
4185 m_process->send(Messages::WebPage::ContextMenuHidden(), m_pageID);
4188 void WebPageProxy::internalShowContextMenu(const ContextMenuContextData& contextMenuContextData, const UserData& userData)
4190 m_activeContextMenuContextData = contextMenuContextData;
4192 m_activeContextMenu = m_pageClient.createContextMenuProxy(*this, contextMenuContextData, userData);
4193 if (!m_activeContextMenu)
4196 // Since showContextMenu() can spin a nested run loop we need to turn off the responsiveness timer.
4197 m_process->responsivenessTimer().stop();
4199 m_activeContextMenu->show();
4202 void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& item)
4204 // Application custom items don't need to round-trip through to WebCore in the WebProcess.
4205 if (item.action() >= ContextMenuItemBaseApplicationTag) {
4206 m_contextMenuClient->customContextMenuItemSelected(*this, item);
4211 if (item.action() == ContextMenuItemTagSmartCopyPaste) {
4212 setSmartInsertDeleteEnabled(!isSmartInsertDeleteEnabled());
4215 if (item.action() == ContextMenuItemTagSmartQuotes) {
4216 TextChecker::setAutomaticQuoteSubstitutionEnabled(!TextChecker::state().isAutomaticQuoteSubstitutionEnabled);
4217 m_process->updateTextCheckerState();
4220 if (item.action() == ContextMenuItemTagSmartDashes) {
4221 TextChecker::setAutomaticDashSubstitutionEnabled(!TextChecker::state().isAutomaticDashSubstitutionEnabled);
4222 m_process->updateTextCheckerState();
4225 if (item.action() == ContextMenuItemTagSmartLinks) {
4226 TextChecker::setAutomaticLinkDetectionEnabled(!TextChecker::state().isAutomaticLinkDetectionEnabled);
4227 m_process->updateTextCheckerState();
4230 if (item.action() == ContextMenuItemTagTextReplacement) {
4231 TextChecker::setAutomaticTextReplacementEnabled(!TextChecker::state().isAutomaticTextReplacementEnabled);
4232 m_process->updateTextCheckerState();
4235 if (item.action() == ContextMenuItemTagCorrectSpellingAutomatically) {
4236 TextChecker::setAutomaticSpellingCorrectionEnabled(!TextChecker::state().isAutomaticSpellingCorrectionEnabled);
4237 m_process->updateTextCheckerState();
4240 if (item.action() == ContextMenuItemTagShowSubstitutions) {
4241 TextChecker::toggleSubstitutionsPanelIsShowing();
4245 if (item.action() == ContextMenuItemTagDownloadImageToDisk) {
4246 m_process->processPool().download(this, URL(URL(), m_activeContextMenuContextData.webHitTestResultData().absoluteImageURL));
4249 if (item.action() == ContextMenuItemTagDownloadLinkToDisk) {
4250 m_process->processPool().download(this, URL(URL(), m_activeContextMenuContextData.webHitTestResultData().absoluteLinkURL));
4253 if (item.action() == ContextMenuItemTagDownloadMediaToDisk) {
4254 m_process->processPool().download(this, URL(URL(), m_activeContextMenuContextData.webHitTestResultData().absoluteMediaURL));
4257 if (item.action() == ContextMenuItemTagCheckSpellingWhileTyping) {
4258 TextChecker::setContinuousSpellCheckingEnabled(!TextChecker::state().isContinuousSpellCheckingEnabled);
4259 m_process->updateTextCheckerState();
4262 if (item.action() == ContextMenuItemTagCheckGrammarWithSpelling) {
4263 TextChecker::setGrammarCheckingEnabled(!TextChecker::state().isGrammarCheckingEnabled);
4264 m_process->updateTextCheckerState();