1 /*
2  * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "config.h"
27 #include "WebPageProxy.h"
28 
29 #include "AuthenticationChallengeProxy.h"
30 #include "AuthenticationDecisionListener.h"
31 #include "DataReference.h"
32 #include "DownloadProxy.h"
33 #include "DrawingAreaProxy.h"
34 #include "FindIndicator.h"
35 #include "MessageID.h"
36 #include "NativeWebKeyboardEvent.h"
37 #include "NativeWebMouseEvent.h"
38 #include "NativeWebWheelEvent.h"
39 #include "PageClient.h"
40 #include "PrintInfo.h"
41 #include "SessionState.h"
42 #include "StringPairVector.h"
43 #include "TextChecker.h"
44 #include "TextCheckerState.h"
45 #include "WKContextPrivate.h"
46 #include "WebBackForwardList.h"
47 #include "WebBackForwardListItem.h"
48 #include "WebCertificateInfo.h"
49 #include "WebContext.h"
50 #include "WebContextMenuProxy.h"
51 #include "WebContextUserMessageCoders.h"
52 #include "WebCoreArgumentCoders.h"
53 #include "WebData.h"
54 #include "WebEditCommandProxy.h"
55 #include "WebEvent.h"
56 #include "WebFormSubmissionListenerProxy.h"
57 #include "WebFramePolicyListenerProxy.h"
58 #include "WebFullScreenManagerProxy.h"
59 #include "WebInspectorProxy.h"
60 #include "WebOpenPanelResultListenerProxy.h"
61 #include "WebPageCreationParameters.h"
62 #include "WebPageGroup.h"
63 #include "WebPageGroupData.h"
64 #include "WebPageMessages.h"
65 #include "WebPopupItem.h"
66 #include "WebPopupMenuProxy.h"
67 #include "WebPreferences.h"
68 #include "WebProcessMessages.h"
69 #include "WebProcessProxy.h"
70 #include "WebProtectionSpace.h"
71 #include "WebSecurityOrigin.h"
72 #include "WebURLRequest.h"
73 #include <WebCore/DragData.h>
74 #include <WebCore/FloatRect.h>
75 #include <WebCore/FocusDirection.h>
76 #include <WebCore/MIMETypeRegistry.h>
77 #include <WebCore/WindowFeatures.h>
78 #include <stdio.h>
79 
80 #if PLATFORM(WIN)
81 #include "WebDragSource.h"
82 #include <WebCore/BitmapInfo.h>
83 #include <WebCore/COMPtr.h>
84 #include <WebCore/WCDataObject.h>
85 #include <shlobj.h>
86 #endif
87 
88 #ifndef NDEBUG
89 #include <wtf/RefCountedLeakCounter.h>
90 #endif
91 
92 // This controls what strategy we use for mouse wheel coalesing.
93 #define MERGE_WHEEL_EVENTS 0
94 
95 #define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, process()->connection())
96 
97 using namespace WebCore;
98 
99 namespace WebKit {
100 
101 WKPageDebugPaintFlags WebPageProxy::s_debugPaintFlags = 0;
102 
103 #ifndef NDEBUG
104 static WTF::RefCountedLeakCounter webPageProxyCounter("WebPageProxy");
105 #endif
106 
create(PageClient * pageClient,PassRefPtr<WebProcessProxy> process,WebPageGroup * pageGroup,uint64_t pageID)107 PassRefPtr<WebPageProxy> WebPageProxy::create(PageClient* pageClient, PassRefPtr<WebProcessProxy> process, WebPageGroup* pageGroup, uint64_t pageID)
108 {
109     return adoptRef(new WebPageProxy(pageClient, process, pageGroup, pageID));
110 }
111 
WebPageProxy(PageClient * pageClient,PassRefPtr<WebProcessProxy> process,WebPageGroup * pageGroup,uint64_t pageID)112 WebPageProxy::WebPageProxy(PageClient* pageClient, PassRefPtr<WebProcessProxy> process, WebPageGroup* pageGroup, uint64_t pageID)
113     : m_pageClient(pageClient)
114     , m_process(process)
115     , m_pageGroup(pageGroup)
116     , m_mainFrame(0)
117     , m_userAgent(standardUserAgent())
118     , m_geolocationPermissionRequestManager(this)
119     , m_estimatedProgress(0)
120     , m_isInWindow(m_pageClient->isViewInWindow())
121     , m_isVisible(m_pageClient->isViewVisible())
122     , m_backForwardList(WebBackForwardList::create(this))
123     , m_textZoomFactor(1)
124     , m_pageZoomFactor(1)
125     , m_viewScaleFactor(1)
126     , m_drawsBackground(true)
127     , m_drawsTransparentBackground(false)
128     , m_areMemoryCacheClientCallsEnabled(true)
129     , m_useFixedLayout(false)
130     , m_isValid(true)
131     , m_isClosed(false)
132     , m_isInPrintingMode(false)
133     , m_isPerformingDOMPrintOperation(false)
134     , m_inDecidePolicyForMIMEType(false)
135     , m_syncMimeTypePolicyActionIsValid(false)
136     , m_syncMimeTypePolicyAction(PolicyUse)
137     , m_syncMimeTypePolicyDownloadID(0)
138     , m_inDecidePolicyForNavigationAction(false)
139     , m_syncNavigationActionPolicyActionIsValid(false)
140     , m_syncNavigationActionPolicyAction(PolicyUse)
141     , m_syncNavigationActionPolicyDownloadID(0)
142     , m_processingMouseMoveEvent(false)
143     , m_pageID(pageID)
144 #if PLATFORM(MAC)
145     , m_isSmartInsertDeleteEnabled(TextChecker::isSmartInsertDeleteEnabled())
146 #endif
147     , m_spellDocumentTag(0)
148     , m_hasSpellDocumentTag(false)
149     , m_pendingLearnOrIgnoreWordMessageCount(0)
150     , m_mainFrameHasCustomRepresentation(false)
151     , m_currentDragOperation(DragOperationNone)
152     , m_mainFrameHasHorizontalScrollbar(false)
153     , m_mainFrameHasVerticalScrollbar(false)
154     , m_mainFrameIsPinnedToLeftSide(false)
155     , m_mainFrameIsPinnedToRightSide(false)
156 {
157 #ifndef NDEBUG
158     webPageProxyCounter.increment();
159 #endif
160 
161     WebContext::statistics().wkPageCount++;
162 
163     m_pageGroup->addPage(this);
164 }
165 
~WebPageProxy()166 WebPageProxy::~WebPageProxy()
167 {
168     if (!m_isClosed)
169         close();
170 
171     WebContext::statistics().wkPageCount--;
172 
173     if (m_hasSpellDocumentTag)
174         TextChecker::closeSpellDocumentWithTag(m_spellDocumentTag);
175 
176     m_pageGroup->removePage(this);
177 
178 #ifndef NDEBUG
179     webPageProxyCounter.decrement();
180 #endif
181 }
182 
process() const183 WebProcessProxy* WebPageProxy::process() const
184 {
185     return m_process.get();
186 }
187 
isValid()188 bool WebPageProxy::isValid()
189 {
190     // A page that has been explicitly closed is never valid.
191     if (m_isClosed)
192         return false;
193 
194     return m_isValid;
195 }
196 
initializeLoaderClient(const WKPageLoaderClient * loadClient)197 void WebPageProxy::initializeLoaderClient(const WKPageLoaderClient* loadClient)
198 {
199     m_loaderClient.initialize(loadClient);
200 }
201 
initializePolicyClient(const WKPagePolicyClient * policyClient)202 void WebPageProxy::initializePolicyClient(const WKPagePolicyClient* policyClient)
203 {
204     m_policyClient.initialize(policyClient);
205 }
206 
initializeFormClient(const WKPageFormClient * formClient)207 void WebPageProxy::initializeFormClient(const WKPageFormClient* formClient)
208 {
209     m_formClient.initialize(formClient);
210 }
211 
initializeResourceLoadClient(const WKPageResourceLoadClient * client)212 void WebPageProxy::initializeResourceLoadClient(const WKPageResourceLoadClient* client)
213 {
214     m_resourceLoadClient.initialize(client);
215 }
216 
initializeUIClient(const WKPageUIClient * client)217 void WebPageProxy::initializeUIClient(const WKPageUIClient* client)
218 {
219     if (!isValid())
220         return;
221 
222     m_uiClient.initialize(client);
223 
224     process()->send(Messages::WebPage::SetCanRunBeforeUnloadConfirmPanel(m_uiClient.canRunBeforeUnloadConfirmPanel()), m_pageID);
225     process()->send(Messages::WebPage::SetCanRunModal(m_uiClient.canRunModal()), m_pageID);
226 }
227 
initializeFindClient(const WKPageFindClient * client)228 void WebPageProxy::initializeFindClient(const WKPageFindClient* client)
229 {
230     m_findClient.initialize(client);
231 }
232 
initializeContextMenuClient(const WKPageContextMenuClient * client)233 void WebPageProxy::initializeContextMenuClient(const WKPageContextMenuClient* client)
234 {
235     m_contextMenuClient.initialize(client);
236 }
237 
reattachToWebProcess()238 void WebPageProxy::reattachToWebProcess()
239 {
240     ASSERT(!isValid());
241 
242     m_isValid = true;
243 
244     m_process = m_process->context()->relaunchProcessIfNecessary();
245     process()->addExistingWebPage(this, m_pageID);
246 
247     initializeWebPage();
248 
249     m_pageClient->didRelaunchProcess();
250 }
251 
reattachToWebProcessWithItem(WebBackForwardListItem * item)252 void WebPageProxy::reattachToWebProcessWithItem(WebBackForwardListItem* item)
253 {
254     if (item && item != m_backForwardList->currentItem())
255         m_backForwardList->goToItem(item);
256 
257     reattachToWebProcess();
258 
259     if (!item)
260         return;
261 
262     SandboxExtension::Handle sandboxExtensionHandle;
263     initializeSandboxExtensionHandle(KURL(KURL(), item->url()), sandboxExtensionHandle);
264     process()->send(Messages::WebPage::GoToBackForwardItem(item->itemID(), sandboxExtensionHandle), m_pageID);
265     process()->responsivenessTimer()->start();
266 }
267 
initializeWebPage()268 void WebPageProxy::initializeWebPage()
269 {
270     ASSERT(isValid());
271 
272     BackForwardListItemVector items = m_backForwardList->entries();
273     for (size_t i = 0; i < items.size(); ++i)
274         process()->registerNewWebBackForwardListItem(items[i].get());
275 
276     m_drawingArea = m_pageClient->createDrawingAreaProxy();
277     ASSERT(m_drawingArea);
278 
279     process()->send(Messages::WebProcess::CreateWebPage(m_pageID, creationParameters()), 0);
280 }
281 
close()282 void WebPageProxy::close()
283 {
284     if (!isValid())
285         return;
286 
287     m_isClosed = true;
288 
289     m_backForwardList->pageClosed();
290     m_pageClient->pageClosed();
291 
292     process()->disconnectFramesFromPage(this);
293     m_mainFrame = 0;
294 
295 #if ENABLE(INSPECTOR)
296     if (m_inspector) {
297         m_inspector->invalidate();
298         m_inspector = 0;
299     }
300 #endif
301 
302 #if ENABLE(FULLSCREEN_API)
303     if (m_fullScreenManager) {
304         m_fullScreenManager->invalidate();
305         m_fullScreenManager = 0;
306     }
307 #endif
308 
309     if (m_openPanelResultListener) {
310         m_openPanelResultListener->invalidate();
311         m_openPanelResultListener = 0;
312     }
313 
314     m_geolocationPermissionRequestManager.invalidateRequests();
315 
316     m_toolTip = String();
317 
318     m_mainFrameHasHorizontalScrollbar = false;
319     m_mainFrameHasVerticalScrollbar = false;
320 
321     m_mainFrameIsPinnedToLeftSide = false;
322     m_mainFrameIsPinnedToRightSide = false;
323 
324     m_visibleScrollerThumbRect = IntRect();
325 
326     invalidateCallbackMap(m_voidCallbacks);
327     invalidateCallbackMap(m_dataCallbacks);
328     invalidateCallbackMap(m_stringCallbacks);
329     m_loadDependentStringCallbackIDs.clear();
330     invalidateCallbackMap(m_scriptValueCallbacks);
331     invalidateCallbackMap(m_computedPagesCallbacks);
332 
333     Vector<WebEditCommandProxy*> editCommandVector;
334     copyToVector(m_editCommandSet, editCommandVector);
335     m_editCommandSet.clear();
336     for (size_t i = 0, size = editCommandVector.size(); i < size; ++i)
337         editCommandVector[i]->invalidate();
338 
339     m_activePopupMenu = 0;
340 
341     m_estimatedProgress = 0.0;
342 
343     m_loaderClient.initialize(0);
344     m_policyClient.initialize(0);
345     m_uiClient.initialize(0);
346 
347     m_drawingArea.clear();
348 
349     process()->send(Messages::WebPage::Close(), m_pageID);
350     process()->removeWebPage(m_pageID);
351 }
352 
tryClose()353 bool WebPageProxy::tryClose()
354 {
355     if (!isValid())
356         return true;
357 
358     process()->send(Messages::WebPage::TryClose(), m_pageID);
359     process()->responsivenessTimer()->start();
360     return false;
361 }
362 
initializeSandboxExtensionHandle(const KURL & url,SandboxExtension::Handle & sandboxExtensionHandle)363 void WebPageProxy::initializeSandboxExtensionHandle(const KURL& url, SandboxExtension::Handle& sandboxExtensionHandle)
364 {
365     if (!url.isLocalFile())
366         return;
367 
368     // Don't give the inspector full access to the file system.
369     if (WebInspectorProxy::isInspectorPage(this))
370         return;
371 
372     SandboxExtension::createHandle("/", SandboxExtension::ReadOnly, sandboxExtensionHandle);
373 }
374 
loadURL(const String & url)375 void WebPageProxy::loadURL(const String& url)
376 {
377     setPendingAPIRequestURL(url);
378 
379     if (!isValid())
380         reattachToWebProcess();
381 
382     SandboxExtension::Handle sandboxExtensionHandle;
383     initializeSandboxExtensionHandle(KURL(KURL(), url), sandboxExtensionHandle);
384     process()->send(Messages::WebPage::LoadURL(url, sandboxExtensionHandle), m_pageID);
385     process()->responsivenessTimer()->start();
386 }
387 
loadURLRequest(WebURLRequest * urlRequest)388 void WebPageProxy::loadURLRequest(WebURLRequest* urlRequest)
389 {
390     setPendingAPIRequestURL(urlRequest->resourceRequest().url());
391 
392     if (!isValid())
393         reattachToWebProcess();
394 
395     SandboxExtension::Handle sandboxExtensionHandle;
396     initializeSandboxExtensionHandle(urlRequest->resourceRequest().url(), sandboxExtensionHandle);
397     process()->send(Messages::WebPage::LoadURLRequest(urlRequest->resourceRequest(), sandboxExtensionHandle), m_pageID);
398     process()->responsivenessTimer()->start();
399 }
400 
loadHTMLString(const String & htmlString,const String & baseURL)401 void WebPageProxy::loadHTMLString(const String& htmlString, const String& baseURL)
402 {
403     if (!isValid())
404         reattachToWebProcess();
405 
406     process()->send(Messages::WebPage::LoadHTMLString(htmlString, baseURL), m_pageID);
407     process()->responsivenessTimer()->start();
408 }
409 
loadAlternateHTMLString(const String & htmlString,const String & baseURL,const String & unreachableURL)410 void WebPageProxy::loadAlternateHTMLString(const String& htmlString, const String& baseURL, const String& unreachableURL)
411 {
412     if (!isValid())
413         reattachToWebProcess();
414 
415     if (m_mainFrame)
416         m_mainFrame->setUnreachableURL(unreachableURL);
417 
418     process()->send(Messages::WebPage::LoadAlternateHTMLString(htmlString, baseURL, unreachableURL), m_pageID);
419     process()->responsivenessTimer()->start();
420 }
421 
loadPlainTextString(const String & string)422 void WebPageProxy::loadPlainTextString(const String& string)
423 {
424     if (!isValid())
425         reattachToWebProcess();
426 
427     process()->send(Messages::WebPage::LoadPlainTextString(string), m_pageID);
428     process()->responsivenessTimer()->start();
429 }
430 
stopLoading()431 void WebPageProxy::stopLoading()
432 {
433     if (!isValid())
434         return;
435 
436     process()->send(Messages::WebPage::StopLoading(), m_pageID);
437     process()->responsivenessTimer()->start();
438 }
439 
reload(bool reloadFromOrigin)440 void WebPageProxy::reload(bool reloadFromOrigin)
441 {
442     if (m_backForwardList->currentItem())
443         setPendingAPIRequestURL(m_backForwardList->currentItem()->url());
444 
445     if (!isValid()) {
446         reattachToWebProcessWithItem(m_backForwardList->currentItem());
447         return;
448     }
449 
450     process()->send(Messages::WebPage::Reload(reloadFromOrigin), m_pageID);
451     process()->responsivenessTimer()->start();
452 }
453 
goForward()454 void WebPageProxy::goForward()
455 {
456     if (isValid() && !canGoForward())
457         return;
458 
459     WebBackForwardListItem* forwardItem = m_backForwardList->forwardItem();
460     if (forwardItem)
461         setPendingAPIRequestURL(forwardItem->url());
462 
463     if (!isValid()) {
464         reattachToWebProcessWithItem(forwardItem);
465         return;
466     }
467 
468     SandboxExtension::Handle sandboxExtensionHandle;
469     initializeSandboxExtensionHandle(KURL(KURL(), forwardItem->url()), sandboxExtensionHandle);
470     process()->send(Messages::WebPage::GoForward(forwardItem->itemID(), sandboxExtensionHandle), m_pageID);
471     process()->responsivenessTimer()->start();
472 }
473 
canGoForward() const474 bool WebPageProxy::canGoForward() const
475 {
476     return m_backForwardList->forwardItem();
477 }
478 
goBack()479 void WebPageProxy::goBack()
480 {
481     if (isValid() && !canGoBack())
482         return;
483 
484     WebBackForwardListItem* backItem = m_backForwardList->backItem();
485     if (backItem)
486         setPendingAPIRequestURL(backItem->url());
487 
488     if (!isValid()) {
489         reattachToWebProcessWithItem(backItem);
490         return;
491     }
492 
493     SandboxExtension::Handle sandboxExtensionHandle;
494     initializeSandboxExtensionHandle(KURL(KURL(), backItem->url()), sandboxExtensionHandle);
495     process()->send(Messages::WebPage::GoBack(backItem->itemID(), sandboxExtensionHandle), m_pageID);
496     process()->responsivenessTimer()->start();
497 }
498 
canGoBack() const499 bool WebPageProxy::canGoBack() const
500 {
501     return m_backForwardList->backItem();
502 }
503 
goToBackForwardItem(WebBackForwardListItem * item)504 void WebPageProxy::goToBackForwardItem(WebBackForwardListItem* item)
505 {
506     if (!isValid()) {
507         reattachToWebProcessWithItem(item);
508         return;
509     }
510 
511     setPendingAPIRequestURL(item->url());
512 
513     SandboxExtension::Handle sandboxExtensionHandle;
514     initializeSandboxExtensionHandle(KURL(KURL(), item->url()), sandboxExtensionHandle);
515     process()->send(Messages::WebPage::GoToBackForwardItem(item->itemID(), sandboxExtensionHandle), m_pageID);
516     process()->responsivenessTimer()->start();
517 }
518 
didChangeBackForwardList(WebBackForwardListItem * added,Vector<RefPtr<APIObject>> * removed)519 void WebPageProxy::didChangeBackForwardList(WebBackForwardListItem* added, Vector<RefPtr<APIObject> >* removed)
520 {
521     m_loaderClient.didChangeBackForwardList(this, added, removed);
522 }
523 
shouldGoToBackForwardListItem(uint64_t itemID,bool & shouldGoToBackForwardItem)524 void WebPageProxy::shouldGoToBackForwardListItem(uint64_t itemID, bool& shouldGoToBackForwardItem)
525 {
526     WebBackForwardListItem* item = process()->webBackForwardItem(itemID);
527     shouldGoToBackForwardItem = item && m_loaderClient.shouldGoToBackForwardListItem(this, item);
528 }
529 
canShowMIMEType(const String & mimeType) const530 bool WebPageProxy::canShowMIMEType(const String& mimeType) const
531 {
532     if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType))
533         return true;
534 
535     if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType))
536         return true;
537 
538     if (mimeType.startsWith("text/", false))
539         return !MIMETypeRegistry::isUnsupportedTextMIMEType(mimeType);
540 
541     String newMimeType = mimeType;
542     PluginInfoStore::Plugin plugin = m_process->context()->pluginInfoStore()->findPlugin(newMimeType, KURL());
543     if (!plugin.path.isNull())
544         return true;
545 
546     return false;
547 }
548 
setDrawsBackground(bool drawsBackground)549 void WebPageProxy::setDrawsBackground(bool drawsBackground)
550 {
551     if (m_drawsBackground == drawsBackground)
552         return;
553 
554     m_drawsBackground = drawsBackground;
555 
556     if (isValid())
557         process()->send(Messages::WebPage::SetDrawsBackground(drawsBackground), m_pageID);
558 }
559 
setDrawsTransparentBackground(bool drawsTransparentBackground)560 void WebPageProxy::setDrawsTransparentBackground(bool drawsTransparentBackground)
561 {
562     if (m_drawsTransparentBackground == drawsTransparentBackground)
563         return;
564 
565     m_drawsTransparentBackground = drawsTransparentBackground;
566 
567     if (isValid())
568         process()->send(Messages::WebPage::SetDrawsTransparentBackground(drawsTransparentBackground), m_pageID);
569 }
570 
viewWillStartLiveResize()571 void WebPageProxy::viewWillStartLiveResize()
572 {
573     if (!isValid())
574         return;
575     process()->send(Messages::WebPage::ViewWillStartLiveResize(), m_pageID);
576 }
577 
viewWillEndLiveResize()578 void WebPageProxy::viewWillEndLiveResize()
579 {
580     if (!isValid())
581         return;
582     process()->send(Messages::WebPage::ViewWillEndLiveResize(), m_pageID);
583 }
584 
setViewNeedsDisplay(const IntRect & rect)585 void WebPageProxy::setViewNeedsDisplay(const IntRect& rect)
586 {
587     m_pageClient->setViewNeedsDisplay(rect);
588 }
589 
displayView()590 void WebPageProxy::displayView()
591 {
592     m_pageClient->displayView();
593 }
594 
scrollView(const IntRect & scrollRect,const IntSize & scrollOffset)595 void WebPageProxy::scrollView(const IntRect& scrollRect, const IntSize& scrollOffset)
596 {
597     m_pageClient->scrollView(scrollRect, scrollOffset);
598 }
599 
viewStateDidChange(ViewStateFlags flags)600 void WebPageProxy::viewStateDidChange(ViewStateFlags flags)
601 {
602     if (!isValid())
603         return;
604 
605     if (flags & ViewIsFocused)
606         process()->send(Messages::WebPage::SetFocused(m_pageClient->isViewFocused()), m_pageID);
607 
608     if (flags & ViewWindowIsActive)
609         process()->send(Messages::WebPage::SetActive(m_pageClient->isViewWindowActive()), m_pageID);
610 
611     if (flags & ViewIsVisible) {
612         bool isVisible = m_pageClient->isViewVisible();
613         if (isVisible != m_isVisible) {
614             m_isVisible = isVisible;
615             m_drawingArea->visibilityDidChange();
616             m_drawingArea->setPageIsVisible(isVisible);
617         }
618     }
619 
620     if (flags & ViewIsInWindow) {
621         bool isInWindow = m_pageClient->isViewInWindow();
622         if (m_isInWindow != isInWindow) {
623             m_isInWindow = isInWindow;
624             process()->send(Messages::WebPage::SetIsInWindow(isInWindow), m_pageID);
625         }
626     }
627 
628     if (flags & (ViewWindowIsActive | ViewIsVisible))
629         updateBackingStoreDiscardableState();
630 }
631 
viewSize() const632 IntSize WebPageProxy::viewSize() const
633 {
634     return m_pageClient->viewSize();
635 }
636 
setInitialFocus(bool forward)637 void WebPageProxy::setInitialFocus(bool forward)
638 {
639     if (!isValid())
640         return;
641     process()->send(Messages::WebPage::SetInitialFocus(forward), m_pageID);
642 }
643 
setWindowResizerSize(const IntSize & windowResizerSize)644 void WebPageProxy::setWindowResizerSize(const IntSize& windowResizerSize)
645 {
646     if (!isValid())
647         return;
648     process()->send(Messages::WebPage::SetWindowResizerSize(windowResizerSize), m_pageID);
649 }
650 
clearSelection()651 void WebPageProxy::clearSelection()
652 {
653     if (!isValid())
654         return;
655     process()->send(Messages::WebPage::ClearSelection(), m_pageID);
656 }
657 
validateCommand(const String & commandName,PassRefPtr<ValidateCommandCallback> callback)658 void WebPageProxy::validateCommand(const String& commandName, PassRefPtr<ValidateCommandCallback> callback)
659 {
660     if (!isValid()) {
661         callback->invalidate();
662         return;
663     }
664 
665     uint64_t callbackID = callback->callbackID();
666     m_validateCommandCallbacks.set(callbackID, callback.get());
667     process()->send(Messages::WebPage::ValidateCommand(commandName, callbackID), m_pageID);
668 }
669 
setMaintainsInactiveSelection(bool newValue)670 void WebPageProxy::setMaintainsInactiveSelection(bool newValue)
671 {
672     m_maintainsInactiveSelection = newValue;
673 }
674 
executeEditCommand(const String & commandName)675 void WebPageProxy::executeEditCommand(const String& commandName)
676 {
677     if (!isValid())
678         return;
679 
680     process()->send(Messages::WebPage::ExecuteEditCommand(commandName), m_pageID);
681 }
682 
683 #if PLATFORM(WIN)
firstRectForCharacterInSelectedRange(int characterPosition)684 IntRect WebPageProxy::firstRectForCharacterInSelectedRange(int characterPosition)
685 {
686     if (!isValid())
687         return IntRect();
688 
689     IntRect resultRect;
690     process()->sendSync(Messages::WebPage::FirstRectForCharacterInSelectedRange(characterPosition), Messages::WebPage::FirstRectForCharacterInSelectedRange::Reply(resultRect), m_pageID);
691     return resultRect;
692 }
693 
getSelectedText()694 String WebPageProxy::getSelectedText()
695 {
696     if (!isValid())
697         return String();
698 
699     String text;
700     process()->sendSync(Messages::WebPage::GetSelectedText(), Messages::WebPage::GetSelectedText::Reply(text), m_pageID);
701     return text;
702 }
703 
gestureWillBegin(const IntPoint & point)704 bool WebPageProxy::gestureWillBegin(const IntPoint& point)
705 {
706     if (!isValid())
707         return false;
708 
709     bool canBeginPanning = false;
710     process()->sendSync(Messages::WebPage::GestureWillBegin(point), Messages::WebPage::GestureWillBegin::Reply(canBeginPanning), m_pageID);
711     return canBeginPanning;
712 }
713 
gestureDidScroll(const IntSize & size)714 void WebPageProxy::gestureDidScroll(const IntSize& size)
715 {
716     process()->send(Messages::WebPage::GestureDidScroll(size), m_pageID);
717 }
718 
gestureDidEnd()719 void WebPageProxy::gestureDidEnd()
720 {
721     process()->send(Messages::WebPage::GestureDidEnd(), m_pageID);
722 }
723 
setGestureReachedScrollingLimit(bool limitReached)724 void WebPageProxy::setGestureReachedScrollingLimit(bool limitReached)
725 {
726     m_pageClient->setGestureReachedScrollingLimit(limitReached);
727 }
728 #endif
729 
730 #if ENABLE(TILED_BACKING_STORE)
setActualVisibleContentRect(const IntRect & rect)731 void WebPageProxy::setActualVisibleContentRect(const IntRect& rect)
732 {
733     if (!isValid())
734         return;
735 
736     process()->send(Messages::WebPage::SetActualVisibleContentRect(rect), m_pageID);
737 }
738 #endif
739 
dragEntered(WebCore::DragData * dragData,const String & dragStorageName)740 void WebPageProxy::dragEntered(WebCore::DragData* dragData, const String& dragStorageName)
741 {
742     SandboxExtension::Handle sandboxExtensionHandle;
743     performDragControllerAction(DragControllerActionEntered, dragData, dragStorageName, sandboxExtensionHandle);
744 }
745 
dragUpdated(WebCore::DragData * dragData,const String & dragStorageName)746 void WebPageProxy::dragUpdated(WebCore::DragData* dragData, const String& dragStorageName)
747 {
748     SandboxExtension::Handle sandboxExtensionHandle;
749     performDragControllerAction(DragControllerActionUpdated, dragData, dragStorageName, sandboxExtensionHandle);
750 }
751 
dragExited(WebCore::DragData * dragData,const String & dragStorageName)752 void WebPageProxy::dragExited(WebCore::DragData* dragData, const String& dragStorageName)
753 {
754     SandboxExtension::Handle sandboxExtensionHandle;
755     performDragControllerAction(DragControllerActionExited, dragData, dragStorageName, sandboxExtensionHandle);
756 }
757 
performDrag(WebCore::DragData * dragData,const String & dragStorageName,const SandboxExtension::Handle & sandboxExtensionHandle)758 void WebPageProxy::performDrag(WebCore::DragData* dragData, const String& dragStorageName, const SandboxExtension::Handle& sandboxExtensionHandle)
759 {
760     performDragControllerAction(DragControllerActionPerformDrag, dragData, dragStorageName, sandboxExtensionHandle);
761 }
762 
performDragControllerAction(DragControllerAction action,WebCore::DragData * dragData,const String & dragStorageName,const SandboxExtension::Handle & sandboxExtensionHandle)763 void WebPageProxy::performDragControllerAction(DragControllerAction action, WebCore::DragData* dragData, const String& dragStorageName, const SandboxExtension::Handle& sandboxExtensionHandle)
764 {
765     if (!isValid())
766         return;
767 #if PLATFORM(WIN)
768     // FIXME: We should pass the drag data map only on DragEnter.
769     process()->send(Messages::WebPage::PerformDragControllerAction(action, dragData->clientPosition(), dragData->globalPosition(),
770         dragData->draggingSourceOperationMask(), dragData->dragDataMap(), dragData->flags()), m_pageID);
771 #else
772     process()->send(Messages::WebPage::PerformDragControllerAction(action, dragData->clientPosition(), dragData->globalPosition(), dragData->draggingSourceOperationMask(), dragStorageName, dragData->flags(), sandboxExtensionHandle), m_pageID);
773 #endif
774 }
775 
didPerformDragControllerAction(uint64_t resultOperation)776 void WebPageProxy::didPerformDragControllerAction(uint64_t resultOperation)
777 {
778     m_currentDragOperation = static_cast<DragOperation>(resultOperation);
779 }
780 
781 #if PLATFORM(WIN)
782 
startDragDrop(const IntPoint & imageOrigin,const IntPoint & dragPoint,uint64_t okEffect,const HashMap<UINT,Vector<String>> & dataMap,const IntSize & dragImageSize,const SharedMemory::Handle & dragImageHandle,bool isLinkDrag)783 void WebPageProxy::startDragDrop(const IntPoint& imageOrigin, const IntPoint& dragPoint, uint64_t okEffect,
784     const HashMap<UINT, Vector<String> >& dataMap, const IntSize& dragImageSize, const SharedMemory::Handle& dragImageHandle, bool isLinkDrag)
785 {
786     COMPtr<WCDataObject> dataObject;
787     WCDataObject::createInstance(&dataObject, dataMap);
788 
789     RefPtr<SharedMemory> memoryBuffer = SharedMemory::create(dragImageHandle, SharedMemory::ReadOnly);
790     if (!memoryBuffer)
791         return;
792 
793     RefPtr<WebDragSource> source = WebDragSource::createInstance();
794     if (!source)
795         return;
796 
797     COMPtr<IDragSourceHelper> helper;
798     if (FAILED(::CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER, IID_IDragSourceHelper, reinterpret_cast<LPVOID*>(&helper))))
799         return;
800 
801     BitmapInfo bitmapInfo = BitmapInfo::create(dragImageSize);
802     void* bits;
803     OwnPtr<HBITMAP> hbmp = adoptPtr(::CreateDIBSection(0, &bitmapInfo, DIB_RGB_COLORS, &bits, 0, 0));
804     memcpy(bits, memoryBuffer->data(), memoryBuffer->size());
805 
806     SHDRAGIMAGE sdi;
807     sdi.sizeDragImage.cx = bitmapInfo.bmiHeader.biWidth;
808     sdi.sizeDragImage.cy = bitmapInfo.bmiHeader.biHeight;
809     sdi.crColorKey = 0xffffffff;
810     sdi.hbmpDragImage = hbmp.leakPtr();
811     sdi.ptOffset.x = dragPoint.x() - imageOrigin.x();
812     sdi.ptOffset.y = dragPoint.y() - imageOrigin.y();
813     if (isLinkDrag)
814         sdi.ptOffset.y = bitmapInfo.bmiHeader.biHeight - sdi.ptOffset.y;
815 
816     helper->InitializeFromBitmap(&sdi, dataObject.get());
817 
818     DWORD effect = DROPEFFECT_NONE;
819 
820     DragOperation operation = DragOperationNone;
821     if (::DoDragDrop(dataObject.get(), source.get(), okEffect, &effect) == DRAGDROP_S_DROP) {
822         if (effect & DROPEFFECT_COPY)
823             operation = DragOperationCopy;
824         else if (effect & DROPEFFECT_LINK)
825             operation = DragOperationLink;
826         else if (effect & DROPEFFECT_MOVE)
827             operation = DragOperationMove;
828     }
829     POINT globalPoint;
830     ::GetCursorPos(&globalPoint);
831     POINT localPoint = globalPoint;
832     ::ScreenToClient(m_pageClient->nativeWindow(), &localPoint);
833 
834     dragEnded(localPoint, globalPoint, operation);
835 }
836 #endif
837 
dragEnded(const WebCore::IntPoint & clientPosition,const WebCore::IntPoint & globalPosition,uint64_t operation)838 void WebPageProxy::dragEnded(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition, uint64_t operation)
839 {
840     if (!isValid())
841         return;
842     process()->send(Messages::WebPage::DragEnded(clientPosition, globalPosition, operation), m_pageID);
843 }
844 
handleMouseEvent(const NativeWebMouseEvent & event)845 void WebPageProxy::handleMouseEvent(const NativeWebMouseEvent& event)
846 {
847     if (!isValid())
848         return;
849 
850     // NOTE: This does not start the responsiveness timer because mouse move should not indicate interaction.
851     if (event.type() != WebEvent::MouseMove)
852         process()->responsivenessTimer()->start();
853     else {
854         if (m_processingMouseMoveEvent) {
855             m_nextMouseMoveEvent = adoptPtr(new NativeWebMouseEvent(event));
856             return;
857         }
858 
859         m_processingMouseMoveEvent = true;
860     }
861 
862     // <https://bugs.webkit.org/show_bug.cgi?id=57904> We need to keep track of the mouse down event in the case where we
863     // display a popup menu for select elements. When the user changes the selected item,
864     // we fake a mouse up event by using this stored down event. This event gets cleared
865     // when the mouse up message is received from WebProcess.
866     if (event.type() == WebEvent::MouseDown)
867         m_currentlyProcessedMouseDownEvent = adoptPtr(new NativeWebMouseEvent(event));
868 
869     process()->send(Messages::WebPage::MouseEvent(event), m_pageID);
870 }
871 
coalesceWheelEvents(NativeWebWheelEvent * oldNextWheelEvent,const NativeWebWheelEvent & newWheelEvent)872 static PassOwnPtr<NativeWebWheelEvent> coalesceWheelEvents(NativeWebWheelEvent* oldNextWheelEvent, const NativeWebWheelEvent& newWheelEvent)
873 {
874 #if MERGE_WHEEL_EVENTS
875     // Merge model: Combine wheel event deltas (and wheel ticks) into a single wheel event.
876     if (!oldNextWheelEvent)
877         return adoptPtr(new NativeWebWheelEvent(newWheelEvent));
878 
879     if (oldNextWheelEvent->position() != newWheelEvent.position() || oldNextWheelEvent->modifiers() != newWheelEvent.modifiers() || oldNextWheelEvent->granularity() != newWheelEvent.granularity())
880         return adoptPtr(new NativeWebWheelEvent(newWheelEvent));
881 
882     FloatSize mergedDelta = oldNextWheelEvent->delta() + newWheelEvent.delta();
883     FloatSize mergedWheelTicks = oldNextWheelEvent->wheelTicks() + newWheelEvent.wheelTicks();
884 
885     // FIXME: This won't compile, if we ever turn on MERGE_WHEEL_EVENTS we'll have to generate a NativeWebWheelEvent synthetically for each platform.
886     return adoptPtr(new NativeWebWheelEvent(WebEvent::Wheel, newWheelEvent.position(), newWheelEvent.globalPosition(), mergedDelta, mergedWheelTicks, newWheelEvent.granularity(), newWheelEvent.modifiers(), newWheelEvent.timestamp()));
887 #else
888     // Simple model: Just keep the last event, dropping all interim events.
889     return adoptPtr(new NativeWebWheelEvent(newWheelEvent));
890 #endif
891 }
892 
handleWheelEvent(const NativeWebWheelEvent & event)893 void WebPageProxy::handleWheelEvent(const NativeWebWheelEvent& event)
894 {
895     if (!isValid())
896         return;
897 
898     if (m_currentlyProcessedWheelEvent) {
899         m_nextWheelEvent = coalesceWheelEvents(m_nextWheelEvent.get(), event);
900         return;
901     }
902 
903     m_currentlyProcessedWheelEvent = adoptPtr(new NativeWebWheelEvent(event));
904 
905     process()->responsivenessTimer()->start();
906     process()->send(Messages::WebPage::WheelEvent(event), m_pageID);
907 }
908 
handleKeyboardEvent(const NativeWebKeyboardEvent & event)909 void WebPageProxy::handleKeyboardEvent(const NativeWebKeyboardEvent& event)
910 {
911     if (!isValid())
912         return;
913 
914     m_keyEventQueue.append(event);
915 
916     process()->responsivenessTimer()->start();
917     process()->send(Messages::WebPage::KeyEvent(event), m_pageID);
918 }
919 
920 #if ENABLE(GESTURE_EVENTS)
handleGestureEvent(const WebGestureEvent & event)921 void WebPageProxy::handleGestureEvent(const WebGestureEvent& event)
922 {
923     if (!isValid())
924         return;
925 
926     process()->responsivenessTimer()->start();
927     process()->send(Messages::WebPage::GestureEvent(event), m_pageID);
928 }
929 #endif
930 
931 #if ENABLE(TOUCH_EVENTS)
handleTouchEvent(const WebTouchEvent & event)932 void WebPageProxy::handleTouchEvent(const WebTouchEvent& event)
933 {
934     if (!isValid())
935         return;
936     process()->send(Messages::WebPage::TouchEvent(event), m_pageID);
937 }
938 #endif
939 
scrollBy(ScrollDirection direction,ScrollGranularity granularity)940 void WebPageProxy::scrollBy(ScrollDirection direction, ScrollGranularity granularity)
941 {
942     if (!isValid())
943         return;
944 
945     process()->send(Messages::WebPage::ScrollBy(direction, granularity), m_pageID);
946 }
947 
receivedPolicyDecision(PolicyAction action,WebFrameProxy * frame,uint64_t listenerID)948 void WebPageProxy::receivedPolicyDecision(PolicyAction action, WebFrameProxy* frame, uint64_t listenerID)
949 {
950     if (!isValid())
951         return;
952 
953     uint64_t downloadID = 0;
954     if (action == PolicyDownload) {
955         // Create a download proxy.
956         downloadID = m_process->context()->createDownloadProxy()->downloadID();
957     }
958 
959     // If we received a policy decision while in decidePolicyForMIMEType the decision will
960     // be sent back to the web process by decidePolicyForMIMEType.
961     if (m_inDecidePolicyForMIMEType) {
962         m_syncMimeTypePolicyActionIsValid = true;
963         m_syncMimeTypePolicyAction = action;
964         m_syncMimeTypePolicyDownloadID = downloadID;
965         return;
966     }
967 
968     // If we received a policy decision while in decidePolicyForNavigationAction the decision will
969     // be sent back to the web process by decidePolicyForNavigationAction.
970     if (m_inDecidePolicyForNavigationAction) {
971         m_syncNavigationActionPolicyActionIsValid = true;
972         m_syncNavigationActionPolicyAction = action;
973         m_syncNavigationActionPolicyDownloadID = downloadID;
974         return;
975     }
976 
977     process()->send(Messages::WebPage::DidReceivePolicyDecision(frame->frameID(), listenerID, action, downloadID), m_pageID);
978 }
979 
pageTitle() const980 String WebPageProxy::pageTitle() const
981 {
982     // Return the null string if there is no main frame (e.g. nothing has been loaded in the page yet, WebProcess has
983     // crashed, page has been closed).
984     if (!m_mainFrame)
985         return String();
986 
987     return m_mainFrame->title();
988 }
989 
setUserAgent(const String & userAgent)990 void WebPageProxy::setUserAgent(const String& userAgent)
991 {
992     if (m_userAgent == userAgent)
993         return;
994     m_userAgent = userAgent;
995 
996     if (!isValid())
997         return;
998     process()->send(Messages::WebPage::SetUserAgent(m_userAgent), m_pageID);
999 }
1000 
setApplicationNameForUserAgent(const String & applicationName)1001 void WebPageProxy::setApplicationNameForUserAgent(const String& applicationName)
1002 {
1003     if (m_applicationNameForUserAgent == applicationName)
1004         return;
1005 
1006     m_applicationNameForUserAgent = applicationName;
1007     if (!m_customUserAgent.isEmpty())
1008         return;
1009 
1010     setUserAgent(standardUserAgent(m_applicationNameForUserAgent));
1011 }
1012 
setCustomUserAgent(const String & customUserAgent)1013 void WebPageProxy::setCustomUserAgent(const String& customUserAgent)
1014 {
1015     if (m_customUserAgent == customUserAgent)
1016         return;
1017 
1018     m_customUserAgent = customUserAgent;
1019 
1020     if (m_customUserAgent.isEmpty()) {
1021         setUserAgent(standardUserAgent(m_applicationNameForUserAgent));
1022         return;
1023     }
1024 
1025     setUserAgent(m_customUserAgent);
1026 }
1027 
supportsTextEncoding() const1028 bool WebPageProxy::supportsTextEncoding() const
1029 {
1030     return !m_mainFrameHasCustomRepresentation && m_mainFrame && !m_mainFrame->isDisplayingStandaloneImageDocument();
1031 }
1032 
setCustomTextEncodingName(const String & encodingName)1033 void WebPageProxy::setCustomTextEncodingName(const String& encodingName)
1034 {
1035     if (m_customTextEncodingName == encodingName)
1036         return;
1037     m_customTextEncodingName = encodingName;
1038 
1039     if (!isValid())
1040         return;
1041     process()->send(Messages::WebPage::SetCustomTextEncodingName(encodingName), m_pageID);
1042 }
1043 
terminateProcess()1044 void WebPageProxy::terminateProcess()
1045 {
1046     if (!isValid())
1047         return;
1048 
1049     process()->terminate();
1050 }
1051 
1052 #if !USE(CF) || defined(BUILDING_QT__)
sessionStateData(WebPageProxySessionStateFilterCallback,void * context) const1053 PassRefPtr<WebData> WebPageProxy::sessionStateData(WebPageProxySessionStateFilterCallback, void* context) const
1054 {
1055     // FIXME: Return session state data for saving Page state.
1056     return 0;
1057 }
1058 
restoreFromSessionStateData(WebData *)1059 void WebPageProxy::restoreFromSessionStateData(WebData*)
1060 {
1061     // FIXME: Restore the Page from the passed in session state data.
1062 }
1063 #endif
1064 
supportsTextZoom() const1065 bool WebPageProxy::supportsTextZoom() const
1066 {
1067     if (m_mainFrameHasCustomRepresentation)
1068         return false;
1069 
1070     // FIXME: This should also return false for standalone media and plug-in documents.
1071     if (!m_mainFrame || m_mainFrame->isDisplayingStandaloneImageDocument())
1072         return false;
1073 
1074     return true;
1075 }
1076 
setTextZoomFactor(double zoomFactor)1077 void WebPageProxy::setTextZoomFactor(double zoomFactor)
1078 {
1079     if (!isValid())
1080         return;
1081 
1082     if (m_mainFrameHasCustomRepresentation)
1083         return;
1084 
1085     if (m_textZoomFactor == zoomFactor)
1086         return;
1087 
1088     m_textZoomFactor = zoomFactor;
1089     process()->send(Messages::WebPage::SetTextZoomFactor(m_textZoomFactor), m_pageID);
1090 }
1091 
pageZoomFactor() const1092 double WebPageProxy::pageZoomFactor() const
1093 {
1094     return m_mainFrameHasCustomRepresentation ? m_pageClient->customRepresentationZoomFactor() : m_pageZoomFactor;
1095 }
1096 
setPageZoomFactor(double zoomFactor)1097 void WebPageProxy::setPageZoomFactor(double zoomFactor)
1098 {
1099     if (!isValid())
1100         return;
1101 
1102     if (m_mainFrameHasCustomRepresentation) {
1103         m_pageClient->setCustomRepresentationZoomFactor(zoomFactor);
1104         return;
1105     }
1106 
1107     if (m_pageZoomFactor == zoomFactor)
1108         return;
1109 
1110     m_pageZoomFactor = zoomFactor;
1111     process()->send(Messages::WebPage::SetPageZoomFactor(m_pageZoomFactor), m_pageID);
1112 }
1113 
setPageAndTextZoomFactors(double pageZoomFactor,double textZoomFactor)1114 void WebPageProxy::setPageAndTextZoomFactors(double pageZoomFactor, double textZoomFactor)
1115 {
1116     if (!isValid())
1117         return;
1118 
1119     if (m_mainFrameHasCustomRepresentation) {
1120         m_pageClient->setCustomRepresentationZoomFactor(pageZoomFactor);
1121         return;
1122     }
1123 
1124     if (m_pageZoomFactor == pageZoomFactor && m_textZoomFactor == textZoomFactor)
1125         return;
1126 
1127     m_pageZoomFactor = pageZoomFactor;
1128     m_textZoomFactor = textZoomFactor;
1129     process()->send(Messages::WebPage::SetPageAndTextZoomFactors(m_pageZoomFactor, m_textZoomFactor), m_pageID);
1130 }
1131 
scaleWebView(double scale,const IntPoint & origin)1132 void WebPageProxy::scaleWebView(double scale, const IntPoint& origin)
1133 {
1134     if (!isValid())
1135         return;
1136 
1137     process()->send(Messages::WebPage::ScaleWebView(scale, origin), m_pageID);
1138 }
1139 
setUseFixedLayout(bool fixed)1140 void WebPageProxy::setUseFixedLayout(bool fixed)
1141 {
1142     if (!isValid())
1143         return;
1144 
1145     if (fixed == m_useFixedLayout)
1146         return;
1147 
1148     m_useFixedLayout = fixed;
1149     if (!fixed)
1150         m_fixedLayoutSize = IntSize();
1151     process()->send(Messages::WebPage::SetUseFixedLayout(fixed), m_pageID);
1152 }
1153 
setFixedLayoutSize(const IntSize & size)1154 void WebPageProxy::setFixedLayoutSize(const IntSize& size)
1155 {
1156     if (!isValid())
1157         return;
1158 
1159     if (size == m_fixedLayoutSize)
1160         return;
1161 
1162     m_fixedLayoutSize = size;
1163     process()->send(Messages::WebPage::SetFixedLayoutSize(size), m_pageID);
1164 }
1165 
viewScaleFactorDidChange(double scaleFactor)1166 void WebPageProxy::viewScaleFactorDidChange(double scaleFactor)
1167 {
1168     m_viewScaleFactor = scaleFactor;
1169 }
1170 
setMemoryCacheClientCallsEnabled(bool memoryCacheClientCallsEnabled)1171 void WebPageProxy::setMemoryCacheClientCallsEnabled(bool memoryCacheClientCallsEnabled)
1172 {
1173     if (!isValid())
1174         return;
1175 
1176     if (m_areMemoryCacheClientCallsEnabled == memoryCacheClientCallsEnabled)
1177         return;
1178 
1179     m_areMemoryCacheClientCallsEnabled = memoryCacheClientCallsEnabled;
1180     process()->send(Messages::WebPage::SetMemoryCacheMessagesEnabled(memoryCacheClientCallsEnabled), m_pageID);
1181 }
1182 
findString(const String & string,FindOptions options,unsigned maxMatchCount)1183 void WebPageProxy::findString(const String& string, FindOptions options, unsigned maxMatchCount)
1184 {
1185     if (m_mainFrameHasCustomRepresentation)
1186         m_pageClient->findStringInCustomRepresentation(string, options, maxMatchCount);
1187     else
1188         process()->send(Messages::WebPage::FindString(string, options, maxMatchCount), m_pageID);
1189 }
1190 
hideFindUI()1191 void WebPageProxy::hideFindUI()
1192 {
1193     process()->send(Messages::WebPage::HideFindUI(), m_pageID);
1194 }
1195 
countStringMatches(const String & string,FindOptions options,unsigned maxMatchCount)1196 void WebPageProxy::countStringMatches(const String& string, FindOptions options, unsigned maxMatchCount)
1197 {
1198     if (m_mainFrameHasCustomRepresentation) {
1199         m_pageClient->countStringMatchesInCustomRepresentation(string, options, maxMatchCount);
1200         return;
1201     }
1202 
1203     if (!isValid())
1204         return;
1205 
1206     process()->send(Messages::WebPage::CountStringMatches(string, options, maxMatchCount), m_pageID);
1207 }
1208 
runJavaScriptInMainFrame(const String & script,PassRefPtr<ScriptValueCallback> prpCallback)1209 void WebPageProxy::runJavaScriptInMainFrame(const String& script, PassRefPtr<ScriptValueCallback> prpCallback)
1210 {
1211     RefPtr<ScriptValueCallback> callback = prpCallback;
1212     if (!isValid()) {
1213         callback->invalidate();
1214         return;
1215     }
1216 
1217     uint64_t callbackID = callback->callbackID();
1218     m_scriptValueCallbacks.set(callbackID, callback.get());
1219     process()->send(Messages::WebPage::RunJavaScriptInMainFrame(script, callbackID), m_pageID);
1220 }
1221 
getRenderTreeExternalRepresentation(PassRefPtr<StringCallback> prpCallback)1222 void WebPageProxy::getRenderTreeExternalRepresentation(PassRefPtr<StringCallback> prpCallback)
1223 {
1224     RefPtr<StringCallback> callback = prpCallback;
1225     if (!isValid()) {
1226         callback->invalidate();
1227         return;
1228     }
1229 
1230     uint64_t callbackID = callback->callbackID();
1231     m_stringCallbacks.set(callbackID, callback.get());
1232     process()->send(Messages::WebPage::GetRenderTreeExternalRepresentation(callbackID), m_pageID);
1233 }
1234 
getSourceForFrame(WebFrameProxy * frame,PassRefPtr<StringCallback> prpCallback)1235 void WebPageProxy::getSourceForFrame(WebFrameProxy* frame, PassRefPtr<StringCallback> prpCallback)
1236 {
1237     RefPtr<StringCallback> callback = prpCallback;
1238     if (!isValid()) {
1239         callback->invalidate();
1240         return;
1241     }
1242 
1243     uint64_t callbackID = callback->callbackID();
1244     m_loadDependentStringCallbackIDs.add(callbackID);
1245     m_stringCallbacks.set(callbackID, callback.get());
1246     process()->send(Messages::WebPage::GetSourceForFrame(frame->frameID(), callbackID), m_pageID);
1247 }
1248 
getContentsAsString(PassRefPtr<StringCallback> prpCallback)1249 void WebPageProxy::getContentsAsString(PassRefPtr<StringCallback> prpCallback)
1250 {
1251     RefPtr<StringCallback> callback = prpCallback;
1252     if (!isValid()) {
1253         callback->invalidate();
1254         return;
1255     }
1256 
1257     uint64_t callbackID = callback->callbackID();
1258     m_loadDependentStringCallbackIDs.add(callbackID);
1259     m_stringCallbacks.set(callbackID, callback.get());
1260     process()->send(Messages::WebPage::GetContentsAsString(callbackID), m_pageID);
1261 }
1262 
getSelectionOrContentsAsString(PassRefPtr<StringCallback> prpCallback)1263 void WebPageProxy::getSelectionOrContentsAsString(PassRefPtr<StringCallback> prpCallback)
1264 {
1265     RefPtr<StringCallback> callback = prpCallback;
1266     if (!isValid()) {
1267         callback->invalidate();
1268         return;
1269     }
1270 
1271     uint64_t callbackID = callback->callbackID();
1272     m_stringCallbacks.set(callbackID, callback.get());
1273     process()->send(Messages::WebPage::GetSelectionOrContentsAsString(callbackID), m_pageID);
1274 }
1275 
getMainResourceDataOfFrame(WebFrameProxy * frame,PassRefPtr<DataCallback> prpCallback)1276 void WebPageProxy::getMainResourceDataOfFrame(WebFrameProxy* frame, PassRefPtr<DataCallback> prpCallback)
1277 {
1278     RefPtr<DataCallback> callback = prpCallback;
1279     if (!isValid()) {
1280         callback->invalidate();
1281         return;
1282     }
1283 
1284     uint64_t callbackID = callback->callbackID();
1285     m_dataCallbacks.set(callbackID, callback.get());
1286     process()->send(Messages::WebPage::GetMainResourceDataOfFrame(frame->frameID(), callbackID), m_pageID);
1287 }
1288 
getResourceDataFromFrame(WebFrameProxy * frame,WebURL * resourceURL,PassRefPtr<DataCallback> prpCallback)1289 void WebPageProxy::getResourceDataFromFrame(WebFrameProxy* frame, WebURL* resourceURL, PassRefPtr<DataCallback> prpCallback)
1290 {
1291     RefPtr<DataCallback> callback = prpCallback;
1292     if (!isValid()) {
1293         callback->invalidate();
1294         return;
1295     }
1296 
1297     uint64_t callbackID = callback->callbackID();
1298     m_dataCallbacks.set(callbackID, callback.get());
1299     process()->send(Messages::WebPage::GetResourceDataFromFrame(frame->frameID(), resourceURL->string(), callbackID), m_pageID);
1300 }
1301 
getWebArchiveOfFrame(WebFrameProxy * frame,PassRefPtr<DataCallback> prpCallback)1302 void WebPageProxy::getWebArchiveOfFrame(WebFrameProxy* frame, PassRefPtr<DataCallback> prpCallback)
1303 {
1304     RefPtr<DataCallback> callback = prpCallback;
1305     if (!isValid()) {
1306         callback->invalidate();
1307         return;
1308     }
1309 
1310     uint64_t callbackID = callback->callbackID();
1311     m_dataCallbacks.set(callbackID, callback.get());
1312     process()->send(Messages::WebPage::GetWebArchiveOfFrame(frame->frameID(), callbackID), m_pageID);
1313 }
1314 
forceRepaint(PassRefPtr<VoidCallback> prpCallback)1315 void WebPageProxy::forceRepaint(PassRefPtr<VoidCallback> prpCallback)
1316 {
1317     RefPtr<VoidCallback> callback = prpCallback;
1318     if (!isValid()) {
1319         callback->invalidate();
1320         return;
1321     }
1322 
1323     uint64_t callbackID = callback->callbackID();
1324     m_voidCallbacks.set(callbackID, callback.get());
1325     process()->send(Messages::WebPage::ForceRepaint(callbackID), m_pageID);
1326 }
1327 
preferencesDidChange()1328 void WebPageProxy::preferencesDidChange()
1329 {
1330     if (!isValid())
1331         return;
1332 
1333     // FIXME: It probably makes more sense to send individual preference changes.
1334     // However, WebKitTestRunner depends on getting a preference change notification
1335     // even if nothing changed in UI process, so that overrides get removed.
1336 
1337     // Preferences need to be updated during synchronous printing to make "print backgrounds" preference work when toggled from a print dialog checkbox.
1338     process()->send(Messages::WebPage::PreferencesDidChange(pageGroup()->preferences()->store()), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
1339 }
1340 
1341 #if ENABLE(TILED_BACKING_STORE)
setResizesToContentsUsingLayoutSize(const WebCore::IntSize & targetLayoutSize)1342 void WebPageProxy::setResizesToContentsUsingLayoutSize(const WebCore::IntSize& targetLayoutSize)
1343 {
1344     process()->send(Messages::WebPage::SetResizesToContentsUsingLayoutSize(targetLayoutSize), m_pageID);
1345 }
1346 #endif
1347 
didReceiveMessage(CoreIPC::Connection * connection,CoreIPC::MessageID messageID,CoreIPC::ArgumentDecoder * arguments)1348 void WebPageProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
1349 {
1350 #if PLATFORM(MAC) || PLATFORM(WIN) || PLATFORM(QT)
1351     if (messageID.is<CoreIPC::MessageClassDrawingAreaProxy>()) {
1352         m_drawingArea->didReceiveDrawingAreaProxyMessage(connection, messageID, arguments);
1353         return;
1354     }
1355 #endif
1356 
1357     if (messageID.is<CoreIPC::MessageClassDrawingAreaProxyLegacy>()) {
1358         m_drawingArea->didReceiveMessage(connection, messageID, arguments);
1359         return;
1360     }
1361 
1362 #if ENABLE(INSPECTOR)
1363     if (messageID.is<CoreIPC::MessageClassWebInspectorProxy>()) {
1364         if (WebInspectorProxy* inspector = this->inspector())
1365             inspector->didReceiveWebInspectorProxyMessage(connection, messageID, arguments);
1366         return;
1367     }
1368 #endif
1369 
1370 #if ENABLE(FULLSCREEN_API)
1371     if (messageID.is<CoreIPC::MessageClassWebFullScreenManagerProxy>()) {
1372         fullScreenManager()->didReceiveMessage(connection, messageID, arguments);
1373         return;
1374     }
1375 #endif
1376 
1377     didReceiveWebPageProxyMessage(connection, messageID, arguments);
1378 }
1379 
didReceiveSyncMessage(CoreIPC::Connection * connection,CoreIPC::MessageID messageID,CoreIPC::ArgumentDecoder * arguments,CoreIPC::ArgumentEncoder * reply)1380 void WebPageProxy::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, CoreIPC::ArgumentEncoder* reply)
1381 {
1382 #if ENABLE(INSPECTOR)
1383     if (messageID.is<CoreIPC::MessageClassWebInspectorProxy>()) {
1384         if (WebInspectorProxy* inspector = this->inspector())
1385             inspector->didReceiveSyncWebInspectorProxyMessage(connection, messageID, arguments, reply);
1386         return;
1387     }
1388 #endif
1389 
1390 #if ENABLE(FULLSCREEN_API)
1391     if (messageID.is<CoreIPC::MessageClassWebFullScreenManagerProxy>()) {
1392         fullScreenManager()->didReceiveSyncMessage(connection, messageID, arguments, reply);
1393         return;
1394     }
1395 #endif
1396 
1397     // FIXME: Do something with reply.
1398     didReceiveSyncWebPageProxyMessage(connection, messageID, arguments, reply);
1399 }
1400 
didCreateMainFrame(uint64_t frameID)1401 void WebPageProxy::didCreateMainFrame(uint64_t frameID)
1402 {
1403     MESSAGE_CHECK(!m_mainFrame);
1404     MESSAGE_CHECK(process()->canCreateFrame(frameID));
1405 
1406     m_mainFrame = WebFrameProxy::create(this, frameID);
1407 
1408     // Add the frame to the process wide map.
1409     process()->frameCreated(frameID, m_mainFrame.get());
1410 }
1411 
didCreateSubframe(uint64_t frameID,uint64_t parentFrameID)1412 void WebPageProxy::didCreateSubframe(uint64_t frameID, uint64_t parentFrameID)
1413 {
1414     MESSAGE_CHECK(m_mainFrame);
1415 
1416     WebFrameProxy* parentFrame = process()->webFrame(parentFrameID);
1417     MESSAGE_CHECK(parentFrame);
1418     MESSAGE_CHECK(parentFrame->isDescendantOf(m_mainFrame.get()));
1419 
1420     MESSAGE_CHECK(process()->canCreateFrame(frameID));
1421 
1422     RefPtr<WebFrameProxy> subFrame = WebFrameProxy::create(this, frameID);
1423 
1424     // Add the frame to the process wide map.
1425     process()->frameCreated(frameID, subFrame.get());
1426 
1427     // Insert the frame into the frame hierarchy.
1428     parentFrame->appendChild(subFrame.get());
1429 }
1430 
isDisconnectedFrame(WebFrameProxy * frame)1431 static bool isDisconnectedFrame(WebFrameProxy* frame)
1432 {
1433     return !frame->page() || !frame->page()->mainFrame() || !frame->isDescendantOf(frame->page()->mainFrame());
1434 }
1435 
didSaveFrameToPageCache(uint64_t frameID)1436 void WebPageProxy::didSaveFrameToPageCache(uint64_t frameID)
1437 {
1438     MESSAGE_CHECK(m_mainFrame);
1439 
1440     WebFrameProxy* subframe = process()->webFrame(frameID);
1441     MESSAGE_CHECK(subframe);
1442 
1443     if (isDisconnectedFrame(subframe))
1444         return;
1445 
1446     MESSAGE_CHECK(subframe->isDescendantOf(m_mainFrame.get()));
1447 
1448     subframe->didRemoveFromHierarchy();
1449 }
1450 
didRestoreFrameFromPageCache(uint64_t frameID,uint64_t parentFrameID)1451 void WebPageProxy::didRestoreFrameFromPageCache(uint64_t frameID, uint64_t parentFrameID)
1452 {
1453     MESSAGE_CHECK(m_mainFrame);
1454 
1455     WebFrameProxy* subframe = process()->webFrame(frameID);
1456     MESSAGE_CHECK(subframe);
1457     MESSAGE_CHECK(!subframe->parentFrame());
1458     MESSAGE_CHECK(subframe->page() == m_mainFrame->page());
1459 
1460     WebFrameProxy* parentFrame = process()->webFrame(parentFrameID);
1461     MESSAGE_CHECK(parentFrame);
1462     MESSAGE_CHECK(parentFrame->isDescendantOf(m_mainFrame.get()));
1463 
1464     // Insert the frame into the frame hierarchy.
1465     parentFrame->appendChild(subframe);
1466 }
1467 
1468 
1469 // Always start progress at initialProgressValue. This helps provide feedback as
1470 // soon as a load starts.
1471 
1472 static const double initialProgressValue = 0.1;
1473 
estimatedProgress() const1474 double WebPageProxy::estimatedProgress() const
1475 {
1476     if (!pendingAPIRequestURL().isNull())
1477         return initialProgressValue;
1478     return m_estimatedProgress;
1479 }
1480 
didStartProgress()1481 void WebPageProxy::didStartProgress()
1482 {
1483     m_estimatedProgress = initialProgressValue;
1484 
1485     m_loaderClient.didStartProgress(this);
1486 }
1487 
didChangeProgress(double value)1488 void WebPageProxy::didChangeProgress(double value)
1489 {
1490     m_estimatedProgress = value;
1491 
1492     m_loaderClient.didChangeProgress(this);
1493 }
1494 
didFinishProgress()1495 void WebPageProxy::didFinishProgress()
1496 {
1497     m_estimatedProgress = 1.0;
1498 
1499     m_loaderClient.didFinishProgress(this);
1500 }
1501 
didStartProvisionalLoadForFrame(uint64_t frameID,const String & url,const String & unreachableURL,CoreIPC::ArgumentDecoder * arguments)1502 void WebPageProxy::didStartProvisionalLoadForFrame(uint64_t frameID, const String& url, const String& unreachableURL, CoreIPC::ArgumentDecoder* arguments)
1503 {
1504     clearPendingAPIRequestURL();
1505 
1506     RefPtr<APIObject> userData;
1507     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1508     if (!arguments->decode(messageDecoder))
1509         return;
1510 
1511     WebFrameProxy* frame = process()->webFrame(frameID);
1512     MESSAGE_CHECK(frame);
1513 
1514     frame->setUnreachableURL(unreachableURL);
1515 
1516     frame->didStartProvisionalLoad(url);
1517     m_loaderClient.didStartProvisionalLoadForFrame(this, frame, userData.get());
1518 }
1519 
didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID,const String & url,CoreIPC::ArgumentDecoder * arguments)1520 void WebPageProxy::didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, const String& url, CoreIPC::ArgumentDecoder* arguments)
1521 {
1522     RefPtr<APIObject> userData;
1523     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1524     if (!arguments->decode(messageDecoder))
1525         return;
1526 
1527     WebFrameProxy* frame = process()->webFrame(frameID);
1528     MESSAGE_CHECK(frame);
1529 
1530     frame->didReceiveServerRedirectForProvisionalLoad(url);
1531 
1532     m_loaderClient.didReceiveServerRedirectForProvisionalLoadForFrame(this, frame, userData.get());
1533 }
1534 
didFailProvisionalLoadForFrame(uint64_t frameID,const ResourceError & error,CoreIPC::ArgumentDecoder * arguments)1535 void WebPageProxy::didFailProvisionalLoadForFrame(uint64_t frameID, const ResourceError& error, CoreIPC::ArgumentDecoder* arguments)
1536 {
1537     RefPtr<APIObject> userData;
1538     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1539     if (!arguments->decode(messageDecoder))
1540         return;
1541 
1542     WebFrameProxy* frame = process()->webFrame(frameID);
1543     MESSAGE_CHECK(frame);
1544 
1545     frame->didFailProvisionalLoad();
1546 
1547     m_loaderClient.didFailProvisionalLoadWithErrorForFrame(this, frame, error, userData.get());
1548 }
1549 
clearLoadDependentCallbacks()1550 void WebPageProxy::clearLoadDependentCallbacks()
1551 {
1552     Vector<uint64_t> callbackIDsCopy;
1553     copyToVector(m_loadDependentStringCallbackIDs, callbackIDsCopy);
1554     m_loadDependentStringCallbackIDs.clear();
1555 
1556     for (size_t i = 0; i < callbackIDsCopy.size(); ++i) {
1557         RefPtr<StringCallback> callback = m_stringCallbacks.take(callbackIDsCopy[i]);
1558         if (callback)
1559             callback->invalidate();
1560     }
1561 }
1562 
didCommitLoadForFrame(uint64_t frameID,const String & mimeType,bool frameHasCustomRepresentation,const PlatformCertificateInfo & certificateInfo,CoreIPC::ArgumentDecoder * arguments)1563 void WebPageProxy::didCommitLoadForFrame(uint64_t frameID, const String& mimeType, bool frameHasCustomRepresentation, const PlatformCertificateInfo& certificateInfo, CoreIPC::ArgumentDecoder* arguments)
1564 {
1565     RefPtr<APIObject> userData;
1566     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1567     if (!arguments->decode(messageDecoder))
1568         return;
1569 
1570     WebFrameProxy* frame = process()->webFrame(frameID);
1571     MESSAGE_CHECK(frame);
1572 
1573 #if PLATFORM(MAC)
1574     // FIXME (bug 59111): didCommitLoadForFrame comes too late when restoring a page from b/f cache, making us disable secure event mode in password fields.
1575     // FIXME (bug 59121): A load going on in one frame shouldn't affect typing in sibling frames.
1576     m_pageClient->resetTextInputState();
1577 #if !defined(BUILDING_ON_SNOW_LEOPARD)
1578     // FIXME: Should this be moved inside resetTextInputState()?
1579     dismissCorrectionPanel(ReasonForDismissingCorrectionPanelIgnored);
1580     m_pageClient->dismissDictionaryLookupPanel();
1581 #endif
1582 #endif
1583 
1584     clearLoadDependentCallbacks();
1585 
1586     frame->didCommitLoad(mimeType, certificateInfo);
1587 
1588     if (frame->isMainFrame()) {
1589         m_mainFrameHasCustomRepresentation = frameHasCustomRepresentation;
1590         m_pageClient->didCommitLoadForMainFrame(frameHasCustomRepresentation);
1591     }
1592 
1593     m_loaderClient.didCommitLoadForFrame(this, frame, userData.get());
1594 }
1595 
didFinishDocumentLoadForFrame(uint64_t frameID,CoreIPC::ArgumentDecoder * arguments)1596 void WebPageProxy::didFinishDocumentLoadForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1597 {
1598     RefPtr<APIObject> userData;
1599     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1600     if (!arguments->decode(messageDecoder))
1601         return;
1602 
1603     WebFrameProxy* frame = process()->webFrame(frameID);
1604     MESSAGE_CHECK(frame);
1605 
1606     m_loaderClient.didFinishDocumentLoadForFrame(this, frame, userData.get());
1607 }
1608 
didFinishLoadForFrame(uint64_t frameID,CoreIPC::ArgumentDecoder * arguments)1609 void WebPageProxy::didFinishLoadForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1610 {
1611     RefPtr<APIObject> userData;
1612     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1613     if (!arguments->decode(messageDecoder))
1614         return;
1615 
1616     WebFrameProxy* frame = process()->webFrame(frameID);
1617     MESSAGE_CHECK(frame);
1618 
1619     frame->didFinishLoad();
1620 
1621     m_loaderClient.didFinishLoadForFrame(this, frame, userData.get());
1622 }
1623 
didFailLoadForFrame(uint64_t frameID,const ResourceError & error,CoreIPC::ArgumentDecoder * arguments)1624 void WebPageProxy::didFailLoadForFrame(uint64_t frameID, const ResourceError& error, CoreIPC::ArgumentDecoder* arguments)
1625 {
1626     RefPtr<APIObject> userData;
1627     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1628     if (!arguments->decode(messageDecoder))
1629         return;
1630 
1631     WebFrameProxy* frame = process()->webFrame(frameID);
1632     MESSAGE_CHECK(frame);
1633 
1634     clearLoadDependentCallbacks();
1635 
1636     frame->didFailLoad();
1637 
1638     m_loaderClient.didFailLoadWithErrorForFrame(this, frame, error, userData.get());
1639 }
1640 
didSameDocumentNavigationForFrame(uint64_t frameID,uint32_t opaqueSameDocumentNavigationType,const String & url,CoreIPC::ArgumentDecoder * arguments)1641 void WebPageProxy::didSameDocumentNavigationForFrame(uint64_t frameID, uint32_t opaqueSameDocumentNavigationType, const String& url, CoreIPC::ArgumentDecoder* arguments)
1642 {
1643     RefPtr<APIObject> userData;
1644     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1645     if (!arguments->decode(messageDecoder))
1646         return;
1647 
1648     WebFrameProxy* frame = process()->webFrame(frameID);
1649     MESSAGE_CHECK(frame);
1650 
1651     frame->didSameDocumentNavigation(url);
1652 
1653     m_loaderClient.didSameDocumentNavigationForFrame(this, frame, static_cast<SameDocumentNavigationType>(opaqueSameDocumentNavigationType), userData.get());
1654 }
1655 
didReceiveTitleForFrame(uint64_t frameID,const String & title,CoreIPC::ArgumentDecoder * arguments)1656 void WebPageProxy::didReceiveTitleForFrame(uint64_t frameID, const String& title, CoreIPC::ArgumentDecoder* arguments)
1657 {
1658     RefPtr<APIObject> userData;
1659     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1660     if (!arguments->decode(messageDecoder))
1661         return;
1662 
1663     WebFrameProxy* frame = process()->webFrame(frameID);
1664     MESSAGE_CHECK(frame);
1665 
1666     frame->didChangeTitle(title);
1667 
1668     m_loaderClient.didReceiveTitleForFrame(this, title, frame, userData.get());
1669 }
1670 
didFirstLayoutForFrame(uint64_t frameID,CoreIPC::ArgumentDecoder * arguments)1671 void WebPageProxy::didFirstLayoutForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1672 {
1673     RefPtr<APIObject> userData;
1674     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1675     if (!arguments->decode(messageDecoder))
1676         return;
1677 
1678     WebFrameProxy* frame = process()->webFrame(frameID);
1679     MESSAGE_CHECK(frame);
1680 
1681     m_loaderClient.didFirstLayoutForFrame(this, frame, userData.get());
1682 }
1683 
didFirstVisuallyNonEmptyLayoutForFrame(uint64_t frameID,CoreIPC::ArgumentDecoder * arguments)1684 void WebPageProxy::didFirstVisuallyNonEmptyLayoutForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1685 {
1686     RefPtr<APIObject> userData;
1687     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1688     if (!arguments->decode(messageDecoder))
1689         return;
1690 
1691     WebFrameProxy* frame = process()->webFrame(frameID);
1692     MESSAGE_CHECK(frame);
1693 
1694     m_loaderClient.didFirstVisuallyNonEmptyLayoutForFrame(this, frame, userData.get());
1695 }
1696 
didRemoveFrameFromHierarchy(uint64_t frameID,CoreIPC::ArgumentDecoder * arguments)1697 void WebPageProxy::didRemoveFrameFromHierarchy(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1698 {
1699     RefPtr<APIObject> userData;
1700     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1701     if (!arguments->decode(messageDecoder))
1702         return;
1703 
1704     WebFrameProxy* frame = process()->webFrame(frameID);
1705     MESSAGE_CHECK(frame);
1706 
1707     frame->didRemoveFromHierarchy();
1708 
1709     m_loaderClient.didRemoveFrameFromHierarchy(this, frame, userData.get());
1710 }
1711 
didDisplayInsecureContentForFrame(uint64_t frameID,CoreIPC::ArgumentDecoder * arguments)1712 void WebPageProxy::didDisplayInsecureContentForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1713 {
1714     RefPtr<APIObject> userData;
1715     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1716     if (!arguments->decode(messageDecoder))
1717         return;
1718 
1719     WebFrameProxy* frame = process()->webFrame(frameID);
1720     MESSAGE_CHECK(frame);
1721 
1722     m_loaderClient.didDisplayInsecureContentForFrame(this, frame, userData.get());
1723 }
1724 
didRunInsecureContentForFrame(uint64_t frameID,CoreIPC::ArgumentDecoder * arguments)1725 void WebPageProxy::didRunInsecureContentForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1726 {
1727     RefPtr<APIObject> userData;
1728     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1729     if (!arguments->decode(messageDecoder))
1730         return;
1731 
1732     WebFrameProxy* frame = process()->webFrame(frameID);
1733     MESSAGE_CHECK(frame);
1734 
1735     m_loaderClient.didRunInsecureContentForFrame(this, frame, userData.get());
1736 }
1737 
frameDidBecomeFrameSet(uint64_t frameID,bool value)1738 void WebPageProxy::frameDidBecomeFrameSet(uint64_t frameID, bool value)
1739 {
1740     WebFrameProxy* frame = process()->webFrame(frameID);
1741     MESSAGE_CHECK(frame);
1742 
1743     frame->setIsFrameSet(value);
1744     if (frame->isMainFrame())
1745         m_frameSetLargestFrame = value ? m_mainFrame : 0;
1746 }
1747 
1748 // PolicyClient
decidePolicyForNavigationAction(uint64_t frameID,uint32_t opaqueNavigationType,uint32_t opaqueModifiers,int32_t opaqueMouseButton,const ResourceRequest & request,uint64_t listenerID,CoreIPC::ArgumentDecoder * arguments,bool & receivedPolicyAction,uint64_t & policyAction,uint64_t & downloadID)1749 void WebPageProxy::decidePolicyForNavigationAction(uint64_t frameID, uint32_t opaqueNavigationType, uint32_t opaqueModifiers, int32_t opaqueMouseButton, const ResourceRequest& request, uint64_t listenerID, CoreIPC::ArgumentDecoder* arguments, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID)
1750 {
1751     RefPtr<APIObject> userData;
1752     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1753     if (!arguments->decode(messageDecoder))
1754         return;
1755 
1756     if (request.url() != pendingAPIRequestURL())
1757         clearPendingAPIRequestURL();
1758 
1759     WebFrameProxy* frame = process()->webFrame(frameID);
1760     MESSAGE_CHECK(frame);
1761 
1762     NavigationType navigationType = static_cast<NavigationType>(opaqueNavigationType);
1763     WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
1764     WebMouseEvent::Button mouseButton = static_cast<WebMouseEvent::Button>(opaqueMouseButton);
1765 
1766     RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
1767 
1768     ASSERT(!m_inDecidePolicyForNavigationAction);
1769 
1770     m_inDecidePolicyForNavigationAction = true;
1771     m_syncNavigationActionPolicyActionIsValid = false;
1772 
1773     if (!m_policyClient.decidePolicyForNavigationAction(this, frame, navigationType, modifiers, mouseButton, request, listener.get(), userData.get()))
1774         listener->use();
1775 
1776     m_inDecidePolicyForNavigationAction = false;
1777 
1778     // Check if we received a policy decision already. If we did, we can just pass it back.
1779     receivedPolicyAction = m_syncNavigationActionPolicyActionIsValid;
1780     if (m_syncNavigationActionPolicyActionIsValid) {
1781         policyAction = m_syncNavigationActionPolicyAction;
1782         downloadID = m_syncNavigationActionPolicyDownloadID;
1783     }
1784 }
1785 
decidePolicyForNewWindowAction(uint64_t frameID,uint32_t opaqueNavigationType,uint32_t opaqueModifiers,int32_t opaqueMouseButton,const ResourceRequest & request,const String & frameName,uint64_t listenerID,CoreIPC::ArgumentDecoder * arguments)1786 void WebPageProxy::decidePolicyForNewWindowAction(uint64_t frameID, uint32_t opaqueNavigationType, uint32_t opaqueModifiers, int32_t opaqueMouseButton, const ResourceRequest& request, const String& frameName, uint64_t listenerID, CoreIPC::ArgumentDecoder* arguments)
1787 {
1788     RefPtr<APIObject> userData;
1789     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1790     if (!arguments->decode(messageDecoder))
1791         return;
1792 
1793     WebFrameProxy* frame = process()->webFrame(frameID);
1794     MESSAGE_CHECK(frame);
1795 
1796     NavigationType navigationType = static_cast<NavigationType>(opaqueNavigationType);
1797     WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
1798     WebMouseEvent::Button mouseButton = static_cast<WebMouseEvent::Button>(opaqueMouseButton);
1799 
1800     RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
1801     if (!m_policyClient.decidePolicyForNewWindowAction(this, frame, navigationType, modifiers, mouseButton, request, frameName, listener.get(), userData.get()))
1802         listener->use();
1803 }
1804 
decidePolicyForResponse(uint64_t frameID,const ResourceResponse & response,const ResourceRequest & request,uint64_t listenerID,CoreIPC::ArgumentDecoder * arguments,bool & receivedPolicyAction,uint64_t & policyAction,uint64_t & downloadID)1805 void WebPageProxy::decidePolicyForResponse(uint64_t frameID, const ResourceResponse& response, const ResourceRequest& request, uint64_t listenerID, CoreIPC::ArgumentDecoder* arguments, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID)
1806 {
1807     RefPtr<APIObject> userData;
1808     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1809     if (!arguments->decode(messageDecoder))
1810         return;
1811 
1812     WebFrameProxy* frame = process()->webFrame(frameID);
1813     MESSAGE_CHECK(frame);
1814 
1815     RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
1816 
1817     ASSERT(!m_inDecidePolicyForMIMEType);
1818 
1819     m_inDecidePolicyForMIMEType = true;
1820     m_syncMimeTypePolicyActionIsValid = false;
1821 
1822     if (!m_policyClient.decidePolicyForResponse(this, frame, response, request, listener.get(), userData.get()))
1823         listener->use();
1824 
1825     m_inDecidePolicyForMIMEType = false;
1826 
1827     // Check if we received a policy decision already. If we did, we can just pass it back.
1828     receivedPolicyAction = m_syncMimeTypePolicyActionIsValid;
1829     if (m_syncMimeTypePolicyActionIsValid) {
1830         policyAction = m_syncMimeTypePolicyAction;
1831         downloadID = m_syncMimeTypePolicyDownloadID;
1832     }
1833 }
1834 
unableToImplementPolicy(uint64_t frameID,const WebCore::ResourceError & error,CoreIPC::ArgumentDecoder * arguments)1835 void WebPageProxy::unableToImplementPolicy(uint64_t frameID, const WebCore::ResourceError& error, CoreIPC::ArgumentDecoder* arguments)
1836 {
1837     RefPtr<APIObject> userData;
1838     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1839     if (!arguments->decode(messageDecoder))
1840         return;
1841 
1842     WebFrameProxy* frame = process()->webFrame(frameID);
1843     MESSAGE_CHECK(frame);
1844 
1845     m_policyClient.unableToImplementPolicy(this, frame, error, userData.get());
1846 }
1847 
1848 // FormClient
1849 
willSubmitForm(uint64_t frameID,uint64_t sourceFrameID,const StringPairVector & textFieldValues,uint64_t listenerID,CoreIPC::ArgumentDecoder * arguments)1850 void WebPageProxy::willSubmitForm(uint64_t frameID, uint64_t sourceFrameID, const StringPairVector& textFieldValues, uint64_t listenerID, CoreIPC::ArgumentDecoder* arguments)
1851 {
1852     RefPtr<APIObject> userData;
1853     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1854     if (!arguments->decode(messageDecoder))
1855         return;
1856 
1857     WebFrameProxy* frame = process()->webFrame(frameID);
1858     MESSAGE_CHECK(frame);
1859 
1860     WebFrameProxy* sourceFrame = process()->webFrame(sourceFrameID);
1861     MESSAGE_CHECK(sourceFrame);
1862 
1863     RefPtr<WebFormSubmissionListenerProxy> listener = frame->setUpFormSubmissionListenerProxy(listenerID);
1864     if (!m_formClient.willSubmitForm(this, frame, sourceFrame, textFieldValues.stringPairVector(), userData.get(), listener.get()))
1865         listener->continueSubmission();
1866 }
1867 
1868 // ResourceLoad Client
1869 
didInitiateLoadForResource(uint64_t frameID,uint64_t resourceIdentifier,const ResourceRequest & request,bool pageIsProvisionallyLoading)1870 void WebPageProxy::didInitiateLoadForResource(uint64_t frameID, uint64_t resourceIdentifier, const ResourceRequest& request, bool pageIsProvisionallyLoading)
1871 {
1872     WebFrameProxy* frame = process()->webFrame(frameID);
1873     MESSAGE_CHECK(frame);
1874 
1875     m_resourceLoadClient.didInitiateLoadForResource(this, frame, resourceIdentifier, request, pageIsProvisionallyLoading);
1876 }
1877 
didSendRequestForResource(uint64_t frameID,uint64_t resourceIdentifier,const ResourceRequest & request,const ResourceResponse & redirectResponse)1878 void WebPageProxy::didSendRequestForResource(uint64_t frameID, uint64_t resourceIdentifier, const ResourceRequest& request, const ResourceResponse& redirectResponse)
1879 {
1880     WebFrameProxy* frame = process()->webFrame(frameID);
1881     MESSAGE_CHECK(frame);
1882 
1883     m_resourceLoadClient.didSendRequestForResource(this, frame, resourceIdentifier, request, redirectResponse);
1884 }
1885 
didReceiveResponseForResource(uint64_t frameID,uint64_t resourceIdentifier,const ResourceResponse & response)1886 void WebPageProxy::didReceiveResponseForResource(uint64_t frameID, uint64_t resourceIdentifier, const ResourceResponse& response)
1887 {
1888     WebFrameProxy* frame = process()->webFrame(frameID);
1889     MESSAGE_CHECK(frame);
1890 
1891     m_resourceLoadClient.didReceiveResponseForResource(this, frame, resourceIdentifier, response);
1892 }
1893 
didReceiveContentLengthForResource(uint64_t frameID,uint64_t resourceIdentifier,uint64_t contentLength)1894 void WebPageProxy::didReceiveContentLengthForResource(uint64_t frameID, uint64_t resourceIdentifier, uint64_t contentLength)
1895 {
1896     WebFrameProxy* frame = process()->webFrame(frameID);
1897     MESSAGE_CHECK(frame);
1898 
1899     m_resourceLoadClient.didReceiveContentLengthForResource(this, frame, resourceIdentifier, contentLength);
1900 }
1901 
didFinishLoadForResource(uint64_t frameID,uint64_t resourceIdentifier)1902 void WebPageProxy::didFinishLoadForResource(uint64_t frameID, uint64_t resourceIdentifier)
1903 {
1904     WebFrameProxy* frame = process()->webFrame(frameID);
1905     MESSAGE_CHECK(frame);
1906 
1907     m_resourceLoadClient.didFinishLoadForResource(this, frame, resourceIdentifier);
1908 }
1909 
didFailLoadForResource(uint64_t frameID,uint64_t resourceIdentifier,const ResourceError & error)1910 void WebPageProxy::didFailLoadForResource(uint64_t frameID, uint64_t resourceIdentifier, const ResourceError& error)
1911 {
1912     WebFrameProxy* frame = process()->webFrame(frameID);
1913     MESSAGE_CHECK(frame);
1914 
1915     m_resourceLoadClient.didFailLoadForResource(this, frame, resourceIdentifier, error);
1916 }
1917 
1918 // UIClient
1919 
createNewPage(const WindowFeatures & windowFeatures,uint32_t opaqueModifiers,int32_t opaqueMouseButton,uint64_t & newPageID,WebPageCreationParameters & newPageParameters)1920 void WebPageProxy::createNewPage(const WindowFeatures& windowFeatures, uint32_t opaqueModifiers, int32_t opaqueMouseButton, uint64_t& newPageID, WebPageCreationParameters& newPageParameters)
1921 {
1922     RefPtr<WebPageProxy> newPage = m_uiClient.createNewPage(this, windowFeatures, static_cast<WebEvent::Modifiers>(opaqueModifiers), static_cast<WebMouseEvent::Button>(opaqueMouseButton));
1923     if (newPage) {
1924         newPageID = newPage->pageID();
1925         newPageParameters = newPage->creationParameters();
1926     } else
1927         newPageID = 0;
1928 }
1929 
showPage()1930 void WebPageProxy::showPage()
1931 {
1932     m_uiClient.showPage(this);
1933 }
1934 
closePage()1935 void WebPageProxy::closePage()
1936 {
1937     m_uiClient.close(this);
1938 }
1939 
runJavaScriptAlert(uint64_t frameID,const String & message)1940 void WebPageProxy::runJavaScriptAlert(uint64_t frameID, const String& message)
1941 {
1942     WebFrameProxy* frame = process()->webFrame(frameID);
1943     MESSAGE_CHECK(frame);
1944 
1945     // Since runJavaScriptAlert() can spin a nested run loop we need to turn off the responsiveness timer.
1946     process()->responsivenessTimer()->stop();
1947 
1948     m_uiClient.runJavaScriptAlert(this, message, frame);
1949 }
1950 
runJavaScriptConfirm(uint64_t frameID,const String & message,bool & result)1951 void WebPageProxy::runJavaScriptConfirm(uint64_t frameID, const String& message, bool& result)
1952 {
1953     WebFrameProxy* frame = process()->webFrame(frameID);
1954     MESSAGE_CHECK(frame);
1955 
1956     // Since runJavaScriptConfirm() can spin a nested run loop we need to turn off the responsiveness timer.
1957     process()->responsivenessTimer()->stop();
1958 
1959     result = m_uiClient.runJavaScriptConfirm(this, message, frame);
1960 }
1961 
runJavaScriptPrompt(uint64_t frameID,const String & message,const String & defaultValue,String & result)1962 void WebPageProxy::runJavaScriptPrompt(uint64_t frameID, const String& message, const String& defaultValue, String& result)
1963 {
1964     WebFrameProxy* frame = process()->webFrame(frameID);
1965     MESSAGE_CHECK(frame);
1966 
1967     // Since runJavaScriptPrompt() can spin a nested run loop we need to turn off the responsiveness timer.
1968     process()->responsivenessTimer()->stop();
1969 
1970     result = m_uiClient.runJavaScriptPrompt(this, message, defaultValue, frame);
1971 }
1972 
shouldInterruptJavaScript(bool & result)1973 void WebPageProxy::shouldInterruptJavaScript(bool& result)
1974 {
1975     // Since shouldInterruptJavaScript() can spin a nested run loop we need to turn off the responsiveness timer.
1976     process()->responsivenessTimer()->stop();
1977 
1978     result = m_uiClient.shouldInterruptJavaScript(this);
1979 }
1980 
setStatusText(const String & text)1981 void WebPageProxy::setStatusText(const String& text)
1982 {
1983     m_uiClient.setStatusText(this, text);
1984 }
1985 
mouseDidMoveOverElement(uint32_t opaqueModifiers,CoreIPC::ArgumentDecoder * arguments)1986 void WebPageProxy::mouseDidMoveOverElement(uint32_t opaqueModifiers, CoreIPC::ArgumentDecoder* arguments)
1987 {
1988     RefPtr<APIObject> userData;
1989     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1990     if (!arguments->decode(messageDecoder))
1991         return;
1992 
1993     WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
1994 
1995     m_uiClient.mouseDidMoveOverElement(this, modifiers, userData.get());
1996 }
1997 
missingPluginButtonClicked(const String & mimeType,const String & url,const String & pluginsPageURL)1998 void WebPageProxy::missingPluginButtonClicked(const String& mimeType, const String& url, const String& pluginsPageURL)
1999 {
2000     m_uiClient.missingPluginButtonClicked(this, mimeType, url, pluginsPageURL);
2001 }
2002 
setToolbarsAreVisible(bool toolbarsAreVisible)2003 void WebPageProxy::setToolbarsAreVisible(bool toolbarsAreVisible)
2004 {
2005     m_uiClient.setToolbarsAreVisible(this, toolbarsAreVisible);
2006 }
2007 
getToolbarsAreVisible(bool & toolbarsAreVisible)2008 void WebPageProxy::getToolbarsAreVisible(bool& toolbarsAreVisible)
2009 {
2010     toolbarsAreVisible = m_uiClient.toolbarsAreVisible(this);
2011 }
2012 
setMenuBarIsVisible(bool menuBarIsVisible)2013 void WebPageProxy::setMenuBarIsVisible(bool menuBarIsVisible)
2014 {
2015     m_uiClient.setMenuBarIsVisible(this, menuBarIsVisible);
2016 }
2017 
getMenuBarIsVisible(bool & menuBarIsVisible)2018 void WebPageProxy::getMenuBarIsVisible(bool& menuBarIsVisible)
2019 {
2020     menuBarIsVisible = m_uiClient.menuBarIsVisible(this);
2021 }
2022 
setStatusBarIsVisible(bool statusBarIsVisible)2023 void WebPageProxy::setStatusBarIsVisible(bool statusBarIsVisible)
2024 {
2025     m_uiClient.setStatusBarIsVisible(this, statusBarIsVisible);
2026 }
2027 
getStatusBarIsVisible(bool & statusBarIsVisible)2028 void WebPageProxy::getStatusBarIsVisible(bool& statusBarIsVisible)
2029 {
2030     statusBarIsVisible = m_uiClient.statusBarIsVisible(this);
2031 }
2032 
setIsResizable(bool isResizable)2033 void WebPageProxy::setIsResizable(bool isResizable)
2034 {
2035     m_uiClient.setIsResizable(this, isResizable);
2036 }
2037 
getIsResizable(bool & isResizable)2038 void WebPageProxy::getIsResizable(bool& isResizable)
2039 {
2040     isResizable = m_uiClient.isResizable(this);
2041 }
2042 
setWindowFrame(const FloatRect & newWindowFrame)2043 void WebPageProxy::setWindowFrame(const FloatRect& newWindowFrame)
2044 {
2045     m_uiClient.setWindowFrame(this, m_pageClient->convertToDeviceSpace(newWindowFrame));
2046 }
2047 
getWindowFrame(FloatRect & newWindowFrame)2048 void WebPageProxy::getWindowFrame(FloatRect& newWindowFrame)
2049 {
2050     newWindowFrame = m_pageClient->convertToUserSpace(m_uiClient.windowFrame(this));
2051 }
2052 
windowToScreen(const IntRect & viewRect,IntRect & result)2053 void WebPageProxy::windowToScreen(const IntRect& viewRect, IntRect& result)
2054 {
2055     result = m_pageClient->windowToScreen(viewRect);
2056 }
2057 
runBeforeUnloadConfirmPanel(const String & message,uint64_t frameID,bool & shouldClose)2058 void WebPageProxy::runBeforeUnloadConfirmPanel(const String& message, uint64_t frameID, bool& shouldClose)
2059 {
2060     WebFrameProxy* frame = process()->webFrame(frameID);
2061     MESSAGE_CHECK(frame);
2062 
2063     shouldClose = m_uiClient.runBeforeUnloadConfirmPanel(this, message, frame);
2064 }
2065 
2066 #if ENABLE(TILED_BACKING_STORE)
pageDidRequestScroll(const IntPoint & point)2067 void WebPageProxy::pageDidRequestScroll(const IntPoint& point)
2068 {
2069     m_pageClient->pageDidRequestScroll(point);
2070 }
2071 #endif
2072 
didChangeViewportData(const ViewportArguments & args)2073 void WebPageProxy::didChangeViewportData(const ViewportArguments& args)
2074 {
2075     m_pageClient->setViewportArguments(args);
2076 }
2077 
pageDidScroll()2078 void WebPageProxy::pageDidScroll()
2079 {
2080     m_uiClient.pageDidScroll(this);
2081 #if PLATFORM(MAC) && !defined(BUILDING_ON_SNOW_LEOPARD)
2082     dismissCorrectionPanel(ReasonForDismissingCorrectionPanelIgnored);
2083 #endif
2084 }
2085 
runOpenPanel(uint64_t frameID,const WebOpenPanelParameters::Data & data)2086 void WebPageProxy::runOpenPanel(uint64_t frameID, const WebOpenPanelParameters::Data& data)
2087 {
2088     if (m_openPanelResultListener) {
2089         m_openPanelResultListener->invalidate();
2090         m_openPanelResultListener = 0;
2091     }
2092 
2093     WebFrameProxy* frame = process()->webFrame(frameID);
2094     MESSAGE_CHECK(frame);
2095 
2096     m_openPanelResultListener = WebOpenPanelResultListenerProxy::create(this);
2097 
2098     // Since runOpenPanel() can spin a nested run loop we need to turn off the responsiveness timer.
2099     process()->responsivenessTimer()->stop();
2100 
2101     if (!m_uiClient.runOpenPanel(this, frame, data, m_openPanelResultListener.get()))
2102         didCancelForOpenPanel();
2103 }
2104 
printFrame(uint64_t frameID)2105 void WebPageProxy::printFrame(uint64_t frameID)
2106 {
2107     ASSERT(!m_isPerformingDOMPrintOperation);
2108     m_isPerformingDOMPrintOperation = true;
2109 
2110     WebFrameProxy* frame = process()->webFrame(frameID);
2111     MESSAGE_CHECK(frame);
2112 
2113     m_uiClient.printFrame(this, frame);
2114 
2115     m_isPerformingDOMPrintOperation = false;
2116 }
2117 
2118 #if PLATFORM(QT)
didChangeContentsSize(const WebCore::IntSize & size)2119 void WebPageProxy::didChangeContentsSize(const WebCore::IntSize& size)
2120 {
2121     m_pageClient->didChangeContentsSize(size);
2122 }
2123 
didFindZoomableArea(const WebCore::IntRect & area)2124 void WebPageProxy::didFindZoomableArea(const WebCore::IntRect& area)
2125 {
2126     m_pageClient->didFindZoomableArea(area);
2127 }
2128 
findZoomableAreaForPoint(const WebCore::IntPoint & point)2129 void WebPageProxy::findZoomableAreaForPoint(const WebCore::IntPoint& point)
2130 {
2131     if (!isValid())
2132         return;
2133 
2134     process()->send(Messages::WebPage::FindZoomableAreaForPoint(point), m_pageID);
2135 }
2136 #endif
2137 
didDraw()2138 void WebPageProxy::didDraw()
2139 {
2140     m_uiClient.didDraw(this);
2141 }
2142 
2143 // Inspector
2144 
2145 #if ENABLE(INSPECTOR)
2146 
inspector()2147 WebInspectorProxy* WebPageProxy::inspector()
2148 {
2149     if (isClosed() || !isValid())
2150         return 0;
2151     if (!m_inspector)
2152         m_inspector = WebInspectorProxy::create(this);
2153     return m_inspector.get();
2154 }
2155 
2156 #endif
2157 
2158 #if ENABLE(FULLSCREEN_API)
fullScreenManager()2159 WebFullScreenManagerProxy* WebPageProxy::fullScreenManager()
2160 {
2161     if (!m_fullScreenManager)
2162         m_fullScreenManager = WebFullScreenManagerProxy::create(this);
2163     return m_fullScreenManager.get();
2164 }
2165 #endif
2166 
2167 // BackForwardList
2168 
backForwardAddItem(uint64_t itemID)2169 void WebPageProxy::backForwardAddItem(uint64_t itemID)
2170 {
2171     m_backForwardList->addItem(process()->webBackForwardItem(itemID));
2172 }
2173 
backForwardGoToItem(uint64_t itemID)2174 void WebPageProxy::backForwardGoToItem(uint64_t itemID)
2175 {
2176     m_backForwardList->goToItem(process()->webBackForwardItem(itemID));
2177 }
2178 
backForwardItemAtIndex(int32_t index,uint64_t & itemID)2179 void WebPageProxy::backForwardItemAtIndex(int32_t index, uint64_t& itemID)
2180 {
2181     WebBackForwardListItem* item = m_backForwardList->itemAtIndex(index);
2182     itemID = item ? item->itemID() : 0;
2183 }
2184 
backForwardBackListCount(int32_t & count)2185 void WebPageProxy::backForwardBackListCount(int32_t& count)
2186 {
2187     count = m_backForwardList->backListCount();
2188 }
2189 
backForwardForwardListCount(int32_t & count)2190 void WebPageProxy::backForwardForwardListCount(int32_t& count)
2191 {
2192     count = m_backForwardList->forwardListCount();
2193 }
2194 
editorStateChanged(const EditorState & editorState)2195 void WebPageProxy::editorStateChanged(const EditorState& editorState)
2196 {
2197 #if PLATFORM(MAC)
2198     bool couldChangeSecureInputState = m_editorState.isInPasswordField != editorState.isInPasswordField || m_editorState.selectionIsNone;
2199 #endif
2200 
2201     m_editorState = editorState;
2202 
2203 #if PLATFORM(MAC)
2204     m_pageClient->updateTextInputState(couldChangeSecureInputState);
2205 #endif
2206 }
2207 
2208 #if PLATFORM(WIN)
didChangeCompositionSelection(bool hasComposition)2209 void WebPageProxy::didChangeCompositionSelection(bool hasComposition)
2210 {
2211     m_pageClient->compositionSelectionChanged(hasComposition);
2212 }
2213 
confirmComposition(const String & compositionString)2214 void WebPageProxy::confirmComposition(const String& compositionString)
2215 {
2216     process()->send(Messages::WebPage::ConfirmComposition(compositionString), m_pageID);
2217 }
2218 
setComposition(const String & compositionString,Vector<WebCore::CompositionUnderline> & underlines,int cursorPosition)2219 void WebPageProxy::setComposition(const String& compositionString, Vector<WebCore::CompositionUnderline>& underlines, int cursorPosition)
2220 {
2221     process()->send(Messages::WebPage::SetComposition(compositionString, underlines, cursorPosition), m_pageID);
2222 }
2223 #endif
2224 
2225 // Undo management
2226 
registerEditCommandForUndo(uint64_t commandID,uint32_t editAction)2227 void WebPageProxy::registerEditCommandForUndo(uint64_t commandID, uint32_t editAction)
2228 {
2229     registerEditCommand(WebEditCommandProxy::create(commandID, static_cast<EditAction>(editAction), this), Undo);
2230 }
2231 
canUndoRedo(uint32_t action,bool & result)2232 void WebPageProxy::canUndoRedo(uint32_t action, bool& result)
2233 {
2234     result = m_pageClient->canUndoRedo(static_cast<UndoOrRedo>(action));
2235 }
2236 
executeUndoRedo(uint32_t action,bool & result)2237 void WebPageProxy::executeUndoRedo(uint32_t action, bool& result)
2238 {
2239     m_pageClient->executeUndoRedo(static_cast<UndoOrRedo>(action));
2240     result = true;
2241 }
2242 
clearAllEditCommands()2243 void WebPageProxy::clearAllEditCommands()
2244 {
2245     m_pageClient->clearAllEditCommands();
2246 }
2247 
didCountStringMatches(const String & string,uint32_t matchCount)2248 void WebPageProxy::didCountStringMatches(const String& string, uint32_t matchCount)
2249 {
2250     m_findClient.didCountStringMatches(this, string, matchCount);
2251 }
2252 
setFindIndicator(const FloatRect & selectionRectInWindowCoordinates,const Vector<FloatRect> & textRectsInSelectionRectCoordinates,const ShareableBitmap::Handle & contentImageHandle,bool fadeOut)2253 void WebPageProxy::setFindIndicator(const FloatRect& selectionRectInWindowCoordinates, const Vector<FloatRect>& textRectsInSelectionRectCoordinates, const ShareableBitmap::Handle& contentImageHandle, bool fadeOut)
2254 {
2255     RefPtr<FindIndicator> findIndicator = FindIndicator::create(selectionRectInWindowCoordinates, textRectsInSelectionRectCoordinates, contentImageHandle);
2256     m_pageClient->setFindIndicator(findIndicator.release(), fadeOut);
2257 }
2258 
didFindString(const String & string,uint32_t matchCount)2259 void WebPageProxy::didFindString(const String& string, uint32_t matchCount)
2260 {
2261     m_findClient.didFindString(this, string, matchCount);
2262 }
2263 
didFailToFindString(const String & string)2264 void WebPageProxy::didFailToFindString(const String& string)
2265 {
2266     m_findClient.didFailToFindString(this, string);
2267 }
2268 
valueChangedForPopupMenu(WebPopupMenuProxy *,int32_t newSelectedIndex)2269 void WebPageProxy::valueChangedForPopupMenu(WebPopupMenuProxy*, int32_t newSelectedIndex)
2270 {
2271     process()->send(Messages::WebPage::DidChangeSelectedIndexForActivePopupMenu(newSelectedIndex), m_pageID);
2272 }
2273 
setTextFromItemForPopupMenu(WebPopupMenuProxy *,int32_t index)2274 void WebPageProxy::setTextFromItemForPopupMenu(WebPopupMenuProxy*, int32_t index)
2275 {
2276     process()->send(Messages::WebPage::SetTextForActivePopupMenu(index), m_pageID);
2277 }
2278 
currentlyProcessedMouseDownEvent()2279 NativeWebMouseEvent* WebPageProxy::currentlyProcessedMouseDownEvent()
2280 {
2281     return m_currentlyProcessedMouseDownEvent.get();
2282 }
2283 
showPopupMenu(const IntRect & rect,uint64_t textDirection,const Vector<WebPopupItem> & items,int32_t selectedIndex,const PlatformPopupMenuData & data)2284 void WebPageProxy::showPopupMenu(const IntRect& rect, uint64_t textDirection, const Vector<WebPopupItem>& items, int32_t selectedIndex, const PlatformPopupMenuData& data)
2285 {
2286     if (m_activePopupMenu) {
2287         m_activePopupMenu->hidePopupMenu();
2288         m_activePopupMenu->invalidate();
2289         m_activePopupMenu = 0;
2290     }
2291 
2292     m_activePopupMenu = m_pageClient->createPopupMenuProxy(this);
2293 
2294     // Since showPopupMenu() can spin a nested run loop we need to turn off the responsiveness timer.
2295     process()->responsivenessTimer()->stop();
2296 
2297     RefPtr<WebPopupMenuProxy> protectedActivePopupMenu = m_activePopupMenu;
2298 
2299     protectedActivePopupMenu->showPopupMenu(rect, static_cast<TextDirection>(textDirection), m_viewScaleFactor, items, data, selectedIndex);
2300     protectedActivePopupMenu->invalidate();
2301     protectedActivePopupMenu = 0;
2302 }
2303 
hidePopupMenu()2304 void WebPageProxy::hidePopupMenu()
2305 {
2306     if (!m_activePopupMenu)
2307         return;
2308 
2309     m_activePopupMenu->hidePopupMenu();
2310     m_activePopupMenu->invalidate();
2311     m_activePopupMenu = 0;
2312 }
2313 
showContextMenu(const IntPoint & menuLocation,const ContextMenuState & contextMenuState,const Vector<WebContextMenuItemData> & proposedItems,CoreIPC::ArgumentDecoder * arguments)2314 void WebPageProxy::showContextMenu(const IntPoint& menuLocation, const ContextMenuState& contextMenuState, const Vector<WebContextMenuItemData>& proposedItems, CoreIPC::ArgumentDecoder* arguments)
2315 {
2316     internalShowContextMenu(menuLocation, contextMenuState, proposedItems, arguments);
2317 
2318     // No matter the result of internalShowContextMenu, always notify the WebProcess that the menu is hidden so it starts handling mouse events again.
2319     process()->send(Messages::WebPage::ContextMenuHidden(), m_pageID);
2320 }
2321 
internalShowContextMenu(const IntPoint & menuLocation,const ContextMenuState & contextMenuState,const Vector<WebContextMenuItemData> & proposedItems,CoreIPC::ArgumentDecoder * arguments)2322 void WebPageProxy::internalShowContextMenu(const IntPoint& menuLocation, const ContextMenuState& contextMenuState, const Vector<WebContextMenuItemData>& proposedItems, CoreIPC::ArgumentDecoder* arguments)
2323 {
2324     RefPtr<APIObject> userData;
2325     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2326     if (!arguments->decode(messageDecoder))
2327         return;
2328 
2329     m_activeContextMenuState = contextMenuState;
2330 
2331     if (m_activeContextMenu) {
2332         m_activeContextMenu->hideContextMenu();
2333         m_activeContextMenu = 0;
2334     }
2335 
2336     m_activeContextMenu = m_pageClient->createContextMenuProxy(this);
2337 
2338     // Since showContextMenu() can spin a nested run loop we need to turn off the responsiveness timer.
2339     process()->responsivenessTimer()->stop();
2340 
2341     // Give the PageContextMenuClient one last swipe at changing the menu.
2342     Vector<WebContextMenuItemData> items;
2343     if (!m_contextMenuClient.getContextMenuFromProposedMenu(this, proposedItems, items, userData.get()))
2344         m_activeContextMenu->showContextMenu(menuLocation, proposedItems);
2345     else
2346         m_activeContextMenu->showContextMenu(menuLocation, items);
2347 }
2348 
contextMenuItemSelected(const WebContextMenuItemData & item)2349 void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& item)
2350 {
2351     // Application custom items don't need to round-trip through to WebCore in the WebProcess.
2352     if (item.action() >= ContextMenuItemBaseApplicationTag) {
2353         m_contextMenuClient.customContextMenuItemSelected(this, item);
2354         return;
2355     }
2356 
2357 #if PLATFORM(MAC)
2358     if (item.action() == ContextMenuItemTagSmartCopyPaste) {
2359         setSmartInsertDeleteEnabled(!isSmartInsertDeleteEnabled());
2360         return;
2361     }
2362     if (item.action() == ContextMenuItemTagSmartQuotes) {
2363         TextChecker::setAutomaticQuoteSubstitutionEnabled(!TextChecker::state().isAutomaticQuoteSubstitutionEnabled);
2364         process()->updateTextCheckerState();
2365         return;
2366     }
2367     if (item.action() == ContextMenuItemTagSmartDashes) {
2368         TextChecker::setAutomaticDashSubstitutionEnabled(!TextChecker::state().isAutomaticDashSubstitutionEnabled);
2369         process()->updateTextCheckerState();
2370         return;
2371     }
2372     if (item.action() == ContextMenuItemTagSmartLinks) {
2373         TextChecker::setAutomaticLinkDetectionEnabled(!TextChecker::state().isAutomaticLinkDetectionEnabled);
2374         process()->updateTextCheckerState();
2375         return;
2376     }
2377     if (item.action() == ContextMenuItemTagTextReplacement) {
2378         TextChecker::setAutomaticTextReplacementEnabled(!TextChecker::state().isAutomaticTextReplacementEnabled);
2379         process()->updateTextCheckerState();
2380         return;
2381     }
2382     if (item.action() == ContextMenuItemTagCorrectSpellingAutomatically) {
2383         TextChecker::setAutomaticSpellingCorrectionEnabled(!TextChecker::state().isAutomaticSpellingCorrectionEnabled);
2384         process()->updateTextCheckerState();
2385         return;
2386     }
2387     if (item.action() == ContextMenuItemTagShowSubstitutions) {
2388         TextChecker::toggleSubstitutionsPanelIsShowing();
2389         return;
2390     }
2391 #endif
2392     if (item.action() == ContextMenuItemTagDownloadImageToDisk) {
2393         m_process->context()->download(this, KURL(KURL(), m_activeContextMenuState.absoluteImageURLString));
2394         return;
2395     }
2396     if (item.action() == ContextMenuItemTagDownloadLinkToDisk) {
2397         m_process->context()->download(this, KURL(KURL(), m_activeContextMenuState.absoluteLinkURLString));
2398         return;
2399     }
2400     if (item.action() == ContextMenuItemTagCheckSpellingWhileTyping) {
2401         TextChecker::setContinuousSpellCheckingEnabled(!TextChecker::state().isContinuousSpellCheckingEnabled);
2402         process()->updateTextCheckerState();
2403         return;
2404     }
2405     if (item.action() == ContextMenuItemTagCheckGrammarWithSpelling) {
2406         TextChecker::setGrammarCheckingEnabled(!TextChecker::state().isGrammarCheckingEnabled);
2407         process()->updateTextCheckerState();
2408         return;
2409     }
2410     if (item.action() == ContextMenuItemTagShowSpellingPanel) {
2411         if (!TextChecker::spellingUIIsShowing())
2412             advanceToNextMisspelling(true);
2413         TextChecker::toggleSpellingUIIsShowing();
2414         return;
2415     }
2416     if (item.action() == ContextMenuItemTagLearnSpelling || item.action() == ContextMenuItemTagIgnoreSpelling)
2417         ++m_pendingLearnOrIgnoreWordMessageCount;
2418 
2419     process()->send(Messages::WebPage::DidSelectItemFromActiveContextMenu(item), m_pageID);
2420 }
2421 
didChooseFilesForOpenPanel(const Vector<String> & fileURLs)2422 void WebPageProxy::didChooseFilesForOpenPanel(const Vector<String>& fileURLs)
2423 {
2424     if (!isValid())
2425         return;
2426 
2427 #if ENABLE(WEB_PROCESS_SANDBOX)
2428     // FIXME: The sandbox extensions should be sent with the DidChooseFilesForOpenPanel message. This
2429     // is gated on a way of passing SandboxExtension::Handles in a Vector.
2430     for (size_t i = 0; i < fileURLs.size(); ++i) {
2431         SandboxExtension::Handle sandboxExtensionHandle;
2432         SandboxExtension::createHandle(fileURLs[i], SandboxExtension::ReadOnly, sandboxExtensionHandle);
2433         process()->send(Messages::WebPage::ExtendSandboxForFileFromOpenPanel(sandboxExtensionHandle), m_pageID);
2434     }
2435 #endif
2436 
2437     process()->send(Messages::WebPage::DidChooseFilesForOpenPanel(fileURLs), m_pageID);
2438 
2439     m_openPanelResultListener->invalidate();
2440     m_openPanelResultListener = 0;
2441 }
2442 
didCancelForOpenPanel()2443 void WebPageProxy::didCancelForOpenPanel()
2444 {
2445     if (!isValid())
2446         return;
2447 
2448     process()->send(Messages::WebPage::DidCancelForOpenPanel(), m_pageID);
2449 
2450     m_openPanelResultListener->invalidate();
2451     m_openPanelResultListener = 0;
2452 }
2453 
advanceToNextMisspelling(bool startBeforeSelection) const2454 void WebPageProxy::advanceToNextMisspelling(bool startBeforeSelection) const
2455 {
2456     process()->send(Messages::WebPage::AdvanceToNextMisspelling(startBeforeSelection), m_pageID);
2457 }
2458 
changeSpellingToWord(const String & word) const2459 void WebPageProxy::changeSpellingToWord(const String& word) const
2460 {
2461     if (word.isEmpty())
2462         return;
2463 
2464     process()->send(Messages::WebPage::ChangeSpellingToWord(word), m_pageID);
2465 }
2466 
registerEditCommand(PassRefPtr<WebEditCommandProxy> commandProxy,UndoOrRedo undoOrRedo)2467 void WebPageProxy::registerEditCommand(PassRefPtr<WebEditCommandProxy> commandProxy, UndoOrRedo undoOrRedo)
2468 {
2469     m_pageClient->registerEditCommand(commandProxy, undoOrRedo);
2470 }
2471 
addEditCommand(WebEditCommandProxy * command)2472 void WebPageProxy::addEditCommand(WebEditCommandProxy* command)
2473 {
2474     m_editCommandSet.add(command);
2475 }
2476 
removeEditCommand(WebEditCommandProxy * command)2477 void WebPageProxy::removeEditCommand(WebEditCommandProxy* command)
2478 {
2479     m_editCommandSet.remove(command);
2480 
2481     if (!isValid())
2482         return;
2483     process()->send(Messages::WebPage::DidRemoveEditCommand(command->commandID()), m_pageID);
2484 }
2485 
isValidEditCommand(WebEditCommandProxy * command)2486 bool WebPageProxy::isValidEditCommand(WebEditCommandProxy* command)
2487 {
2488     return m_editCommandSet.find(command) != m_editCommandSet.end();
2489 }
2490 
spellDocumentTag()2491 int64_t WebPageProxy::spellDocumentTag()
2492 {
2493     if (!m_hasSpellDocumentTag) {
2494         m_spellDocumentTag = TextChecker::uniqueSpellDocumentTag(this);
2495         m_hasSpellDocumentTag = true;
2496     }
2497 
2498     return m_spellDocumentTag;
2499 }
2500 
2501 #if USE(UNIFIED_TEXT_CHECKING)
2502 
checkTextOfParagraph(const String & text,uint64_t checkingTypes,Vector<TextCheckingResult> & results)2503 void WebPageProxy::checkTextOfParagraph(const String& text, uint64_t checkingTypes, Vector<TextCheckingResult>& results)
2504 {
2505     results = TextChecker::checkTextOfParagraph(spellDocumentTag(), text.characters(), text.length(), checkingTypes);
2506 }
2507 
2508 #endif
2509 
checkSpellingOfString(const String & text,int32_t & misspellingLocation,int32_t & misspellingLength)2510 void WebPageProxy::checkSpellingOfString(const String& text, int32_t& misspellingLocation, int32_t& misspellingLength)
2511 {
2512     TextChecker::checkSpellingOfString(spellDocumentTag(), text.characters(), text.length(), misspellingLocation, misspellingLength);
2513 }
2514 
checkGrammarOfString(const String & text,Vector<WebCore::GrammarDetail> & grammarDetails,int32_t & badGrammarLocation,int32_t & badGrammarLength)2515 void WebPageProxy::checkGrammarOfString(const String& text, Vector<WebCore::GrammarDetail>& grammarDetails, int32_t& badGrammarLocation, int32_t& badGrammarLength)
2516 {
2517     TextChecker::checkGrammarOfString(spellDocumentTag(), text.characters(), text.length(), grammarDetails, badGrammarLocation, badGrammarLength);
2518 }
2519 
spellingUIIsShowing(bool & isShowing)2520 void WebPageProxy::spellingUIIsShowing(bool& isShowing)
2521 {
2522     isShowing = TextChecker::spellingUIIsShowing();
2523 }
2524 
updateSpellingUIWithMisspelledWord(const String & misspelledWord)2525 void WebPageProxy::updateSpellingUIWithMisspelledWord(const String& misspelledWord)
2526 {
2527     TextChecker::updateSpellingUIWithMisspelledWord(spellDocumentTag(), misspelledWord);
2528 }
2529 
updateSpellingUIWithGrammarString(const String & badGrammarPhrase,const GrammarDetail & grammarDetail)2530 void WebPageProxy::updateSpellingUIWithGrammarString(const String& badGrammarPhrase, const GrammarDetail& grammarDetail)
2531 {
2532     TextChecker::updateSpellingUIWithGrammarString(spellDocumentTag(), badGrammarPhrase, grammarDetail);
2533 }
2534 
getGuessesForWord(const String & word,const String & context,Vector<String> & guesses)2535 void WebPageProxy::getGuessesForWord(const String& word, const String& context, Vector<String>& guesses)
2536 {
2537     TextChecker::getGuessesForWord(spellDocumentTag(), word, context, guesses);
2538 }
2539 
learnWord(const String & word)2540 void WebPageProxy::learnWord(const String& word)
2541 {
2542     MESSAGE_CHECK(m_pendingLearnOrIgnoreWordMessageCount);
2543     --m_pendingLearnOrIgnoreWordMessageCount;
2544 
2545     TextChecker::learnWord(spellDocumentTag(), word);
2546 }
2547 
ignoreWord(const String & word)2548 void WebPageProxy::ignoreWord(const String& word)
2549 {
2550     MESSAGE_CHECK(m_pendingLearnOrIgnoreWordMessageCount);
2551     --m_pendingLearnOrIgnoreWordMessageCount;
2552 
2553     TextChecker::ignoreWord(spellDocumentTag(), word);
2554 }
2555 
2556 // Other
2557 
setFocus(bool focused)2558 void WebPageProxy::setFocus(bool focused)
2559 {
2560     if (focused)
2561         m_uiClient.focus(this);
2562     else
2563         m_uiClient.unfocus(this);
2564 }
2565 
takeFocus(uint32_t direction)2566 void WebPageProxy::takeFocus(uint32_t direction)
2567 {
2568     m_uiClient.takeFocus(this, (static_cast<FocusDirection>(direction) == FocusDirectionForward) ? kWKFocusDirectionForward : kWKFocusDirectionBackward);
2569 }
2570 
setToolTip(const String & toolTip)2571 void WebPageProxy::setToolTip(const String& toolTip)
2572 {
2573     String oldToolTip = m_toolTip;
2574     m_toolTip = toolTip;
2575     m_pageClient->toolTipChanged(oldToolTip, m_toolTip);
2576 }
2577 
setCursor(const WebCore::Cursor & cursor)2578 void WebPageProxy::setCursor(const WebCore::Cursor& cursor)
2579 {
2580     m_pageClient->setCursor(cursor);
2581 }
2582 
didReceiveEvent(uint32_t opaqueType,bool handled)2583 void WebPageProxy::didReceiveEvent(uint32_t opaqueType, bool handled)
2584 {
2585     WebEvent::Type type = static_cast<WebEvent::Type>(opaqueType);
2586 
2587     switch (type) {
2588     case WebEvent::NoType:
2589     case WebEvent::MouseMove:
2590         break;
2591 
2592     case WebEvent::MouseDown:
2593     case WebEvent::MouseUp:
2594     case WebEvent::Wheel:
2595     case WebEvent::KeyDown:
2596     case WebEvent::KeyUp:
2597     case WebEvent::RawKeyDown:
2598     case WebEvent::Char:
2599 #if ENABLE(GESTURE_EVENTS)
2600     case WebEvent::GestureScrollBegin:
2601     case WebEvent::GestureScrollEnd:
2602 #endif
2603         process()->responsivenessTimer()->stop();
2604         break;
2605     }
2606 
2607     switch (type) {
2608     case WebEvent::NoType:
2609         break;
2610     case WebEvent::MouseMove:
2611         m_processingMouseMoveEvent = false;
2612         if (m_nextMouseMoveEvent) {
2613             handleMouseEvent(*m_nextMouseMoveEvent);
2614             m_nextMouseMoveEvent = nullptr;
2615         }
2616         break;
2617     case WebEvent::MouseDown:
2618 #if ENABLE(GESTURE_EVENTS)
2619     case WebEvent::GestureScrollBegin:
2620     case WebEvent::GestureScrollEnd:
2621 #endif
2622         break;
2623     case WebEvent::MouseUp:
2624         m_currentlyProcessedMouseDownEvent = nullptr;
2625         break;
2626 
2627     case WebEvent::Wheel: {
2628         ASSERT(m_currentlyProcessedWheelEvent);
2629 
2630 #if PLATFORM(WIN)
2631         if (!handled && m_currentlyProcessedWheelEvent)
2632             wheelEventNotHandled(*m_currentlyProcessedWheelEvent);
2633 #endif
2634 
2635         m_currentlyProcessedWheelEvent = nullptr;
2636         if (m_nextWheelEvent) {
2637             handleWheelEvent(*m_nextWheelEvent);
2638             m_nextWheelEvent = nullptr;
2639         }
2640         break;
2641     }
2642 
2643     case WebEvent::KeyDown:
2644     case WebEvent::KeyUp:
2645     case WebEvent::RawKeyDown:
2646     case WebEvent::Char: {
2647         NativeWebKeyboardEvent event = m_keyEventQueue.first();
2648         MESSAGE_CHECK(type == event.type());
2649 
2650         m_keyEventQueue.removeFirst();
2651 
2652         m_pageClient->doneWithKeyEvent(event, handled);
2653 
2654         if (handled)
2655             break;
2656 
2657         if (m_uiClient.implementsDidNotHandleKeyEvent())
2658             m_uiClient.didNotHandleKeyEvent(this, event);
2659 #if PLATFORM(WIN)
2660         else
2661             ::TranslateMessage(event.nativeEvent());
2662 #endif
2663         break;
2664     }
2665     }
2666 }
2667 
stopResponsivenessTimer()2668 void WebPageProxy::stopResponsivenessTimer()
2669 {
2670     process()->responsivenessTimer()->stop();
2671 }
2672 
voidCallback(uint64_t callbackID)2673 void WebPageProxy::voidCallback(uint64_t callbackID)
2674 {
2675     RefPtr<VoidCallback> callback = m_voidCallbacks.take(callbackID);
2676     if (!callback) {
2677         // FIXME: Log error or assert.
2678         return;
2679     }
2680 
2681     callback->performCallback();
2682 }
2683 
dataCallback(const CoreIPC::DataReference & dataReference,uint64_t callbackID)2684 void WebPageProxy::dataCallback(const CoreIPC::DataReference& dataReference, uint64_t callbackID)
2685 {
2686     RefPtr<DataCallback> callback = m_dataCallbacks.take(callbackID);
2687     if (!callback) {
2688         // FIXME: Log error or assert.
2689         return;
2690     }
2691 
2692     callback->performCallbackWithReturnValue(WebData::create(dataReference.data(), dataReference.size()).get());
2693 }
2694 
stringCallback(const String & resultString,uint64_t callbackID)2695 void WebPageProxy::stringCallback(const String& resultString, uint64_t callbackID)
2696 {
2697     RefPtr<StringCallback> callback = m_stringCallbacks.take(callbackID);
2698     if (!callback) {
2699         // FIXME: Log error or assert.
2700         // this can validly happen if a load invalidated the callback, though
2701         return;
2702     }
2703 
2704     m_loadDependentStringCallbackIDs.remove(callbackID);
2705 
2706     callback->performCallbackWithReturnValue(resultString.impl());
2707 }
2708 
scriptValueCallback(const CoreIPC::DataReference & dataReference,uint64_t callbackID)2709 void WebPageProxy::scriptValueCallback(const CoreIPC::DataReference& dataReference, uint64_t callbackID)
2710 {
2711     RefPtr<ScriptValueCallback> callback = m_scriptValueCallbacks.take(callbackID);
2712     if (!callback) {
2713         // FIXME: Log error or assert.
2714         return;
2715     }
2716 
2717     Vector<uint8_t> data;
2718     data.reserveInitialCapacity(dataReference.size());
2719     data.append(dataReference.data(), dataReference.size());
2720 
2721     callback->performCallbackWithReturnValue(data.size() ? WebSerializedScriptValue::adopt(data).get() : 0);
2722 }
2723 
computedPagesCallback(const Vector<WebCore::IntRect> & pageRects,double totalScaleFactorForPrinting,uint64_t callbackID)2724 void WebPageProxy::computedPagesCallback(const Vector<WebCore::IntRect>& pageRects, double totalScaleFactorForPrinting, uint64_t callbackID)
2725 {
2726     RefPtr<ComputedPagesCallback> callback = m_computedPagesCallbacks.take(callbackID);
2727     if (!callback) {
2728         // FIXME: Log error or assert.
2729         return;
2730     }
2731 
2732     callback->performCallbackWithReturnValue(pageRects, totalScaleFactorForPrinting);
2733 }
2734 
validateCommandCallback(const String & commandName,bool isEnabled,int state,uint64_t callbackID)2735 void WebPageProxy::validateCommandCallback(const String& commandName, bool isEnabled, int state, uint64_t callbackID)
2736 {
2737     RefPtr<ValidateCommandCallback> callback = m_validateCommandCallbacks.take(callbackID);
2738     if (!callback) {
2739         // FIXME: Log error or assert.
2740         return;
2741     }
2742 
2743     callback->performCallbackWithReturnValue(commandName.impl(), isEnabled, state);
2744 }
2745 
focusedFrameChanged(uint64_t frameID)2746 void WebPageProxy::focusedFrameChanged(uint64_t frameID)
2747 {
2748     if (!frameID) {
2749         m_focusedFrame = 0;
2750         return;
2751     }
2752 
2753     WebFrameProxy* frame = process()->webFrame(frameID);
2754     MESSAGE_CHECK(frame);
2755 
2756     m_focusedFrame = frame;
2757 }
2758 
frameSetLargestFrameChanged(uint64_t frameID)2759 void WebPageProxy::frameSetLargestFrameChanged(uint64_t frameID)
2760 {
2761     if (!frameID) {
2762         m_frameSetLargestFrame = 0;
2763         return;
2764     }
2765 
2766     WebFrameProxy* frame = process()->webFrame(frameID);
2767     MESSAGE_CHECK(frame);
2768 
2769     m_frameSetLargestFrame = frame;
2770 }
2771 
processDidBecomeUnresponsive()2772 void WebPageProxy::processDidBecomeUnresponsive()
2773 {
2774     updateBackingStoreDiscardableState();
2775 
2776     m_loaderClient.processDidBecomeUnresponsive(this);
2777 }
2778 
processDidBecomeResponsive()2779 void WebPageProxy::processDidBecomeResponsive()
2780 {
2781     updateBackingStoreDiscardableState();
2782 
2783     m_loaderClient.processDidBecomeResponsive(this);
2784 }
2785 
processDidCrash()2786 void WebPageProxy::processDidCrash()
2787 {
2788     ASSERT(m_pageClient);
2789 
2790     m_isValid = false;
2791 
2792     m_mainFrame = nullptr;
2793     m_drawingArea = nullptr;
2794 
2795 #if ENABLE(INSPECTOR)
2796     if (m_inspector) {
2797         m_inspector->invalidate();
2798         m_inspector = nullptr;
2799     }
2800 #endif
2801 
2802 #if ENABLE(FULLSCREEN_API)
2803     if (m_fullScreenManager) {
2804         m_fullScreenManager->invalidate();
2805         m_fullScreenManager = nullptr;
2806     }
2807 #endif
2808 
2809     if (m_openPanelResultListener) {
2810         m_openPanelResultListener->invalidate();
2811         m_openPanelResultListener = nullptr;
2812     }
2813 
2814     m_geolocationPermissionRequestManager.invalidateRequests();
2815 
2816     m_toolTip = String();
2817 
2818     m_mainFrameHasHorizontalScrollbar = false;
2819     m_mainFrameHasVerticalScrollbar = false;
2820 
2821     m_mainFrameIsPinnedToLeftSide = false;
2822     m_mainFrameIsPinnedToRightSide = false;
2823 
2824     m_visibleScrollerThumbRect = IntRect();
2825 
2826     invalidateCallbackMap(m_voidCallbacks);
2827     invalidateCallbackMap(m_dataCallbacks);
2828     invalidateCallbackMap(m_stringCallbacks);
2829     m_loadDependentStringCallbackIDs.clear();
2830     invalidateCallbackMap(m_scriptValueCallbacks);
2831     invalidateCallbackMap(m_computedPagesCallbacks);
2832     invalidateCallbackMap(m_validateCommandCallbacks);
2833 
2834     Vector<WebEditCommandProxy*> editCommandVector;
2835     copyToVector(m_editCommandSet, editCommandVector);
2836     m_editCommandSet.clear();
2837     for (size_t i = 0, size = editCommandVector.size(); i < size; ++i)
2838         editCommandVector[i]->invalidate();
2839     m_pageClient->clearAllEditCommands();
2840 
2841     m_activePopupMenu = 0;
2842 
2843     m_estimatedProgress = 0.0;
2844 
2845     m_pendingLearnOrIgnoreWordMessageCount = 0;
2846 
2847     m_pageClient->processDidCrash();
2848     m_loaderClient.processDidCrash(this);
2849 
2850     // Can't expect DidReceiveEvent notifications from a crashed web process.
2851     m_keyEventQueue.clear();
2852     m_nextWheelEvent = nullptr;
2853     m_currentlyProcessedWheelEvent = nullptr;
2854     m_nextMouseMoveEvent = nullptr;
2855     m_currentlyProcessedMouseDownEvent = nullptr;
2856 
2857 #if PLATFORM(MAC) && !defined(BUILDING_ON_SNOW_LEOPARD)
2858     dismissCorrectionPanel(ReasonForDismissingCorrectionPanelIgnored);
2859     m_pageClient->dismissDictionaryLookupPanel();
2860 #endif
2861 }
2862 
creationParameters() const2863 WebPageCreationParameters WebPageProxy::creationParameters() const
2864 {
2865     WebPageCreationParameters parameters;
2866 
2867     parameters.viewSize = m_pageClient->viewSize();
2868     parameters.isActive = m_pageClient->isViewWindowActive();
2869     parameters.isFocused = m_pageClient->isViewFocused();
2870     parameters.isVisible = m_pageClient->isViewVisible();
2871     parameters.isInWindow = m_pageClient->isViewInWindow();
2872     parameters.drawingAreaType = m_drawingArea->type();
2873     parameters.store = m_pageGroup->preferences()->store();
2874     parameters.pageGroupData = m_pageGroup->data();
2875     parameters.drawsBackground = m_drawsBackground;
2876     parameters.drawsTransparentBackground = m_drawsTransparentBackground;
2877     parameters.areMemoryCacheClientCallsEnabled = m_areMemoryCacheClientCallsEnabled;
2878     parameters.useFixedLayout = m_useFixedLayout;
2879     parameters.fixedLayoutSize = m_fixedLayoutSize;
2880     parameters.userAgent = userAgent();
2881     parameters.sessionState = SessionState(m_backForwardList->entries(), m_backForwardList->currentIndex());
2882     parameters.highestUsedBackForwardItemID = WebBackForwardListItem::highedUsedItemID();
2883     parameters.canRunBeforeUnloadConfirmPanel = m_uiClient.canRunBeforeUnloadConfirmPanel();
2884     parameters.canRunModal = m_uiClient.canRunModal();
2885     parameters.userSpaceScaleFactor = m_pageClient->userSpaceScaleFactor();
2886 
2887 #if PLATFORM(MAC)
2888     parameters.isSmartInsertDeleteEnabled = m_isSmartInsertDeleteEnabled;
2889 #endif
2890 
2891 #if PLATFORM(WIN)
2892     parameters.nativeWindow = m_pageClient->nativeWindow();
2893 #endif
2894 
2895     return parameters;
2896 }
2897 
2898 #if USE(ACCELERATED_COMPOSITING)
enterAcceleratedCompositingMode(const LayerTreeContext & layerTreeContext)2899 void WebPageProxy::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
2900 {
2901     m_pageClient->enterAcceleratedCompositingMode(layerTreeContext);
2902 }
2903 
exitAcceleratedCompositingMode()2904 void WebPageProxy::exitAcceleratedCompositingMode()
2905 {
2906     m_pageClient->exitAcceleratedCompositingMode();
2907 }
2908 #endif // USE(ACCELERATED_COMPOSITING)
2909 
backForwardClear()2910 void WebPageProxy::backForwardClear()
2911 {
2912     m_backForwardList->clear();
2913 }
2914 
canAuthenticateAgainstProtectionSpaceInFrame(uint64_t frameID,const WebCore::ProtectionSpace & coreProtectionSpace,bool & canAuthenticate)2915 void WebPageProxy::canAuthenticateAgainstProtectionSpaceInFrame(uint64_t frameID, const WebCore::ProtectionSpace& coreProtectionSpace, bool& canAuthenticate)
2916 {
2917     WebFrameProxy* frame = process()->webFrame(frameID);
2918     MESSAGE_CHECK(frame);
2919 
2920     RefPtr<WebProtectionSpace> protectionSpace = WebProtectionSpace::create(coreProtectionSpace);
2921 
2922     canAuthenticate = m_loaderClient.canAuthenticateAgainstProtectionSpaceInFrame(this, frame, protectionSpace.get());
2923 }
2924 
didReceiveAuthenticationChallenge(uint64_t frameID,const WebCore::AuthenticationChallenge & coreChallenge,uint64_t challengeID)2925 void WebPageProxy::didReceiveAuthenticationChallenge(uint64_t frameID, const WebCore::AuthenticationChallenge& coreChallenge, uint64_t challengeID)
2926 {
2927     WebFrameProxy* frame = process()->webFrame(frameID);
2928     MESSAGE_CHECK(frame);
2929 
2930     RefPtr<AuthenticationChallengeProxy> authenticationChallenge = AuthenticationChallengeProxy::create(coreChallenge, challengeID, process());
2931 
2932     m_loaderClient.didReceiveAuthenticationChallengeInFrame(this, frame, authenticationChallenge.get());
2933 }
2934 
exceededDatabaseQuota(uint64_t frameID,const String & originIdentifier,const String & databaseName,const String & displayName,uint64_t currentQuota,uint64_t currentUsage,uint64_t expectedUsage,uint64_t & newQuota)2935 void WebPageProxy::exceededDatabaseQuota(uint64_t frameID, const String& originIdentifier, const String& databaseName, const String& displayName, uint64_t currentQuota, uint64_t currentUsage, uint64_t expectedUsage, uint64_t& newQuota)
2936 {
2937     WebFrameProxy* frame = process()->webFrame(frameID);
2938     MESSAGE_CHECK(frame);
2939 
2940     RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::create(originIdentifier);
2941 
2942     newQuota = m_uiClient.exceededDatabaseQuota(this, frame, origin.get(), databaseName, displayName, currentQuota, currentUsage, expectedUsage);
2943 }
2944 
requestGeolocationPermissionForFrame(uint64_t geolocationID,uint64_t frameID,String originIdentifier)2945 void WebPageProxy::requestGeolocationPermissionForFrame(uint64_t geolocationID, uint64_t frameID, String originIdentifier)
2946 {
2947     WebFrameProxy* frame = process()->webFrame(frameID);
2948     MESSAGE_CHECK(frame);
2949 
2950     RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::create(originIdentifier);
2951     RefPtr<GeolocationPermissionRequestProxy> request = m_geolocationPermissionRequestManager.createRequest(geolocationID);
2952 
2953     if (!m_uiClient.decidePolicyForGeolocationPermissionRequest(this, frame, origin.get(), request.get()))
2954         request->deny();
2955 }
2956 
headerHeight(WebFrameProxy * frame)2957 float WebPageProxy::headerHeight(WebFrameProxy* frame)
2958 {
2959     return m_uiClient.headerHeight(this, frame);
2960 }
2961 
footerHeight(WebFrameProxy * frame)2962 float WebPageProxy::footerHeight(WebFrameProxy* frame)
2963 {
2964     return m_uiClient.footerHeight(this, frame);
2965 }
2966 
drawHeader(WebFrameProxy * frame,const FloatRect & rect)2967 void WebPageProxy::drawHeader(WebFrameProxy* frame, const FloatRect& rect)
2968 {
2969     m_uiClient.drawHeader(this, frame, rect);
2970 }
2971 
drawFooter(WebFrameProxy * frame,const FloatRect & rect)2972 void WebPageProxy::drawFooter(WebFrameProxy* frame, const FloatRect& rect)
2973 {
2974     m_uiClient.drawFooter(this, frame, rect);
2975 }
2976 
didCompleteRubberBandForMainFrame(const IntSize & initialOverhang)2977 void WebPageProxy::didCompleteRubberBandForMainFrame(const IntSize& initialOverhang)
2978 {
2979     m_uiClient.didCompleteRubberBandForMainFrame(this, initialOverhang);
2980 }
2981 
notifyScrollerThumbIsVisibleInRect(const IntRect & scrollerThumb)2982 void WebPageProxy::notifyScrollerThumbIsVisibleInRect(const IntRect& scrollerThumb)
2983 {
2984     m_visibleScrollerThumbRect = scrollerThumb;
2985 }
2986 
didChangeScrollbarsForMainFrame(bool hasHorizontalScrollbar,bool hasVerticalScrollbar)2987 void WebPageProxy::didChangeScrollbarsForMainFrame(bool hasHorizontalScrollbar, bool hasVerticalScrollbar)
2988 {
2989     m_mainFrameHasHorizontalScrollbar = hasHorizontalScrollbar;
2990     m_mainFrameHasVerticalScrollbar = hasVerticalScrollbar;
2991 
2992     m_pageClient->didChangeScrollbarsForMainFrame();
2993 }
2994 
didChangeScrollOffsetPinningForMainFrame(bool pinnedToLeftSide,bool pinnedToRightSide)2995 void WebPageProxy::didChangeScrollOffsetPinningForMainFrame(bool pinnedToLeftSide, bool pinnedToRightSide)
2996 {
2997     m_mainFrameIsPinnedToLeftSide = pinnedToLeftSide;
2998     m_mainFrameIsPinnedToRightSide = pinnedToRightSide;
2999 }
3000 
didFailToInitializePlugin(const String & mimeType)3001 void WebPageProxy::didFailToInitializePlugin(const String& mimeType)
3002 {
3003     m_loaderClient.didFailToInitializePlugin(this, mimeType);
3004 }
3005 
didFinishLoadingDataForCustomRepresentation(const String & suggestedFilename,const CoreIPC::DataReference & dataReference)3006 void WebPageProxy::didFinishLoadingDataForCustomRepresentation(const String& suggestedFilename, const CoreIPC::DataReference& dataReference)
3007 {
3008     m_pageClient->didFinishLoadingDataForCustomRepresentation(suggestedFilename, dataReference);
3009 }
3010 
backForwardRemovedItem(uint64_t itemID)3011 void WebPageProxy::backForwardRemovedItem(uint64_t itemID)
3012 {
3013     process()->send(Messages::WebPage::DidRemoveBackForwardItem(itemID), m_pageID);
3014 }
3015 
beginPrinting(WebFrameProxy * frame,const PrintInfo & printInfo)3016 void WebPageProxy::beginPrinting(WebFrameProxy* frame, const PrintInfo& printInfo)
3017 {
3018     if (m_isInPrintingMode)
3019         return;
3020 
3021     m_isInPrintingMode = true;
3022     process()->send(Messages::WebPage::BeginPrinting(frame->frameID(), printInfo), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
3023 }
3024 
endPrinting()3025 void WebPageProxy::endPrinting()
3026 {
3027     if (!m_isInPrintingMode)
3028         return;
3029 
3030     m_isInPrintingMode = false;
3031     process()->send(Messages::WebPage::EndPrinting(), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
3032 }
3033 
computePagesForPrinting(WebFrameProxy * frame,const PrintInfo & printInfo,PassRefPtr<ComputedPagesCallback> prpCallback)3034 void WebPageProxy::computePagesForPrinting(WebFrameProxy* frame, const PrintInfo& printInfo, PassRefPtr<ComputedPagesCallback> prpCallback)
3035 {
3036     RefPtr<ComputedPagesCallback> callback = prpCallback;
3037     if (!isValid()) {
3038         callback->invalidate();
3039         return;
3040     }
3041 
3042     uint64_t callbackID = callback->callbackID();
3043     m_computedPagesCallbacks.set(callbackID, callback.get());
3044     m_isInPrintingMode = true;
3045     process()->send(Messages::WebPage::ComputePagesForPrinting(frame->frameID(), printInfo, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
3046 }
3047 
3048 #if PLATFORM(MAC) || PLATFORM(WIN)
drawRectToPDF(WebFrameProxy * frame,const IntRect & rect,PassRefPtr<DataCallback> prpCallback)3049 void WebPageProxy::drawRectToPDF(WebFrameProxy* frame, const IntRect& rect, PassRefPtr<DataCallback> prpCallback)
3050 {
3051     RefPtr<DataCallback> callback = prpCallback;
3052     if (!isValid()) {
3053         callback->invalidate();
3054         return;
3055     }
3056 
3057     uint64_t callbackID = callback->callbackID();
3058     m_dataCallbacks.set(callbackID, callback.get());
3059     process()->send(Messages::WebPage::DrawRectToPDF(frame->frameID(), rect, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
3060 }
3061 
drawPagesToPDF(WebFrameProxy * frame,uint32_t first,uint32_t count,PassRefPtr<DataCallback> prpCallback)3062 void WebPageProxy::drawPagesToPDF(WebFrameProxy* frame, uint32_t first, uint32_t count, PassRefPtr<DataCallback> prpCallback)
3063 {
3064     RefPtr<DataCallback> callback = prpCallback;
3065     if (!isValid()) {
3066         callback->invalidate();
3067         return;
3068     }
3069 
3070     uint64_t callbackID = callback->callbackID();
3071     m_dataCallbacks.set(callbackID, callback.get());
3072     process()->send(Messages::WebPage::DrawPagesToPDF(frame->frameID(), first, count, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
3073 }
3074 #endif
3075 
flashBackingStoreUpdates(const Vector<IntRect> & updateRects)3076 void WebPageProxy::flashBackingStoreUpdates(const Vector<IntRect>& updateRects)
3077 {
3078     m_pageClient->flashBackingStoreUpdates(updateRects);
3079 }
3080 
updateBackingStoreDiscardableState()3081 void WebPageProxy::updateBackingStoreDiscardableState()
3082 {
3083     bool isDiscardable;
3084 
3085     if (!process()->responsivenessTimer()->isResponsive())
3086         isDiscardable = false;
3087     else
3088         isDiscardable = !m_pageClient->isViewWindowActive() || !isViewVisible();
3089 
3090     m_drawingArea->setBackingStoreIsDiscardable(isDiscardable);
3091 }
3092 
viewUpdatesFlashColor()3093 Color WebPageProxy::viewUpdatesFlashColor()
3094 {
3095     return Color(0, 200, 255);
3096 }
3097 
backingStoreUpdatesFlashColor()3098 Color WebPageProxy::backingStoreUpdatesFlashColor()
3099 {
3100     return Color(200, 0, 255);
3101 }
3102 
saveDataToFileInDownloadsFolder(const String & suggestedFilename,const String & mimeType,const String & originatingURLString,WebData * data)3103 void WebPageProxy::saveDataToFileInDownloadsFolder(const String& suggestedFilename, const String& mimeType, const String& originatingURLString, WebData* data)
3104 {
3105     m_uiClient.saveDataToFileInDownloadsFolder(this, suggestedFilename, mimeType, originatingURLString, data);
3106 }
3107 
linkClicked(const String & url,const WebMouseEvent & event)3108 void WebPageProxy::linkClicked(const String& url, const WebMouseEvent& event)
3109 {
3110     process()->send(Messages::WebPage::LinkClicked(url, event), m_pageID, 0);
3111 }
3112 
createSnapshotOfVisibleContent()3113 PassRefPtr<WebImage> WebPageProxy::createSnapshotOfVisibleContent()
3114 {
3115     if (!isValid())
3116         return 0;
3117 
3118     ShareableBitmap::Handle snapshotHandle;
3119     // Do not wait for more than a second (arbitrary) for the WebProcess to get the snapshot so
3120     // that the UI Process is not permanently stuck waiting on a potentially crashing Web Process.
3121     static const double createSnapshotOfVisibleContentSyncMessageTimeout = 1.0;
3122     process()->sendSync(Messages::WebPage::CreateSnapshotOfVisibleContent(), Messages::WebPage::CreateSnapshotOfVisibleContent::Reply(snapshotHandle), m_pageID, createSnapshotOfVisibleContentSyncMessageTimeout);
3123     if (snapshotHandle.isNull())
3124         return 0;
3125     return WebImage::create(ShareableBitmap::create(snapshotHandle));
3126 }
3127 
3128 #if PLATFORM(MAC)
3129 
substitutionsPanelIsShowing(bool & isShowing)3130 void WebPageProxy::substitutionsPanelIsShowing(bool& isShowing)
3131 {
3132     isShowing = TextChecker::substitutionsPanelIsShowing();
3133 }
3134 
3135 #if !defined(BUILDING_ON_SNOW_LEOPARD)
showCorrectionPanel(int32_t panelType,const WebCore::FloatRect & boundingBoxOfReplacedString,const String & replacedString,const String & replacementString,const Vector<String> & alternativeReplacementStrings)3136 void WebPageProxy::showCorrectionPanel(int32_t panelType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings)
3137 {
3138     m_pageClient->showCorrectionPanel((WebCore::CorrectionPanelInfo::PanelType)panelType, boundingBoxOfReplacedString, replacedString, replacementString, alternativeReplacementStrings);
3139 }
3140 
dismissCorrectionPanel(int32_t reason)3141 void WebPageProxy::dismissCorrectionPanel(int32_t reason)
3142 {
3143     m_pageClient->dismissCorrectionPanel((WebCore::ReasonForDismissingCorrectionPanel)reason);
3144 }
3145 
dismissCorrectionPanelSoon(int32_t reason,String & result)3146 void WebPageProxy::dismissCorrectionPanelSoon(int32_t reason, String& result)
3147 {
3148     result = m_pageClient->dismissCorrectionPanelSoon((WebCore::ReasonForDismissingCorrectionPanel)reason);
3149 }
3150 
recordAutocorrectionResponse(int32_t responseType,const String & replacedString,const String & replacementString)3151 void WebPageProxy::recordAutocorrectionResponse(int32_t responseType, const String& replacedString, const String& replacementString)
3152 {
3153     m_pageClient->recordAutocorrectionResponse((WebCore::EditorClient::AutocorrectionResponseType)responseType, replacedString, replacementString);
3154 }
3155 #endif // !defined(BUILDING_ON_SNOW_LEOPARD)
3156 
handleCorrectionPanelResult(const String & result)3157 void WebPageProxy::handleCorrectionPanelResult(const String& result)
3158 {
3159 #if !defined(BUILDING_ON_SNOW_LEOPARD)
3160     if (!isClosed())
3161         process()->send(Messages::WebPage::HandleCorrectionPanelResult(result), m_pageID, 0);
3162 #endif
3163 }
3164 #endif // PLATFORM(MAC)
3165 
3166 } // namespace WebKit
3167