Reviewed and landed by Sam Weinig.
[WebKit-https.git] / Source / WebKit2 / UIProcess / WebPageProxy.cpp
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 "DrawingAreaProxy.h"
33 #include "FindIndicator.h"
34 #include "MessageID.h"
35 #include "NativeWebKeyboardEvent.h"
36 #include "PageClient.h"
37 #include "PrintInfo.h"
38 #include "SessionState.h"
39 #include "StringPairVector.h"
40 #include "TextChecker.h"
41 #include "TextCheckerState.h"
42 #include "WKContextPrivate.h"
43 #include "WebBackForwardList.h"
44 #include "WebBackForwardListItem.h"
45 #include "WebCertificateInfo.h"
46 #include "WebContext.h"
47 #include "WebContextMenuProxy.h"
48 #include "WebContextUserMessageCoders.h"
49 #include "WebCoreArgumentCoders.h"
50 #include "WebData.h"
51 #include "WebEditCommandProxy.h"
52 #include "WebEvent.h"
53 #include "WebFormSubmissionListenerProxy.h"
54 #include "WebFramePolicyListenerProxy.h"
55 #include "WebOpenPanelResultListenerProxy.h"
56 #include "WebPageCreationParameters.h"
57 #include "WebPageGroup.h"
58 #include "WebPageGroupData.h"
59 #include "WebPageMessages.h"
60 #include "WebPopupItem.h"
61 #include "WebPopupMenuProxy.h"
62 #include "WebPreferences.h"
63 #include "WebProcessManager.h"
64 #include "WebProcessMessages.h"
65 #include "WebProcessProxy.h"
66 #include "WebProtectionSpace.h"
67 #include "WebSecurityOrigin.h"
68 #include "WebURLRequest.h"
69 #if PLATFORM(WIN)
70 #include "WebDragSource.h"
71 #include <WebCore/BitmapInfo.h>
72 #include <WebCore/COMPtr.h>
73 #include <WebCore/WCDataObject.h>
74 #include <shlobj.h>
75 #endif
76 #include <WebCore/DragData.h>
77 #include <WebCore/FloatRect.h>
78 #include <WebCore/MIMETypeRegistry.h>
79 #include <WebCore/WindowFeatures.h>
80 #include <stdio.h>
81
82 #ifndef NDEBUG
83 #include <wtf/RefCountedLeakCounter.h>
84 #endif
85
86 // This controls what strategy we use for mouse wheel coalesing.
87 #define MERGE_WHEEL_EVENTS 0
88
89 #define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, process()->connection())
90
91 using namespace WebCore;
92
93 namespace WebKit {
94
95 #ifndef NDEBUG
96 static WTF::RefCountedLeakCounter webPageProxyCounter("WebPageProxy");
97 #endif
98
99 PassRefPtr<WebPageProxy> WebPageProxy::create(PageClient* pageClient, WebContext* context, WebPageGroup* pageGroup, uint64_t pageID)
100 {
101     return adoptRef(new WebPageProxy(pageClient, context, pageGroup, pageID));
102 }
103
104 WebPageProxy::WebPageProxy(PageClient* pageClient, WebContext* context, WebPageGroup* pageGroup, uint64_t pageID)
105     : m_pageClient(pageClient)
106     , m_context(context)
107     , m_pageGroup(pageGroup)
108     , m_mainFrame(0)
109     , m_userAgent(standardUserAgent())
110     , m_geolocationPermissionRequestManager(this)
111     , m_estimatedProgress(0)
112     , m_isInWindow(m_pageClient->isViewInWindow())
113     , m_isVisible(m_pageClient->isViewVisible())
114     , m_backForwardList(WebBackForwardList::create(this))
115     , m_textZoomFactor(1)
116     , m_pageZoomFactor(1)
117     , m_viewScaleFactor(1)
118     , m_drawsBackground(true)
119     , m_drawsTransparentBackground(false)
120     , m_useFixedLayout(false)
121     , m_isValid(true)
122     , m_isClosed(false)
123     , m_isInPrintingMode(false)
124     , m_isPerformingDOMPrintOperation(false)
125     , m_inDecidePolicyForMIMEType(false)
126     , m_syncMimeTypePolicyActionIsValid(false)
127     , m_syncMimeTypePolicyAction(PolicyUse)
128     , m_syncMimeTypePolicyDownloadID(0)
129     , m_inDecidePolicyForNavigationAction(false)
130     , m_syncNavigationActionPolicyActionIsValid(false)
131     , m_syncNavigationActionPolicyAction(PolicyUse)
132     , m_processingWheelEvent(false)
133     , m_processingMouseMoveEvent(false)
134     , m_pageID(pageID)
135 #if PLATFORM(MAC)
136     , m_isSmartInsertDeleteEnabled(TextChecker::isSmartInsertDeleteEnabled())
137 #endif
138     , m_spellDocumentTag(0)
139     , m_hasSpellDocumentTag(false)
140     , m_pendingLearnOrIgnoreWordMessageCount(0)
141     , m_mainFrameHasCustomRepresentation(false)
142     , m_currentDragOperation(DragOperationNone)
143     , m_mainFrameHasHorizontalScrollbar(false)
144     , m_mainFrameHasVerticalScrollbar(false)
145 {
146 #ifndef NDEBUG
147     webPageProxyCounter.increment();
148 #endif
149
150     WebContext::statistics().wkPageCount++;
151
152     m_pageGroup->addPage(this);
153 }
154
155 WebPageProxy::~WebPageProxy()
156 {
157     WebContext::statistics().wkPageCount--;
158
159     if (m_hasSpellDocumentTag)
160         TextChecker::closeSpellDocumentWithTag(m_spellDocumentTag);
161
162     m_pageGroup->removePage(this);
163
164 #ifndef NDEBUG
165     webPageProxyCounter.decrement();
166 #endif
167 }
168
169 WebProcessProxy* WebPageProxy::process() const
170 {
171     return m_context->process();
172 }
173
174 bool WebPageProxy::isValid()
175 {
176     // A page that has been explicitly closed is never valid.
177     if (m_isClosed)
178         return false;
179
180     return m_isValid;
181 }
182
183 void WebPageProxy::setDrawingArea(PassOwnPtr<DrawingAreaProxy> drawingArea)
184 {
185     if (drawingArea == m_drawingArea)
186         return;
187
188     m_drawingArea = drawingArea;
189 }
190
191 void WebPageProxy::initializeLoaderClient(const WKPageLoaderClient* loadClient)
192 {
193     m_loaderClient.initialize(loadClient);
194 }
195
196 void WebPageProxy::initializePolicyClient(const WKPagePolicyClient* policyClient)
197 {
198     m_policyClient.initialize(policyClient);
199 }
200
201 void WebPageProxy::initializeFormClient(const WKPageFormClient* formClient)
202 {
203     m_formClient.initialize(formClient);
204 }
205
206 void WebPageProxy::initializeResourceLoadClient(const WKPageResourceLoadClient* client)
207 {
208     m_resourceLoadClient.initialize(client);
209 }
210
211 void WebPageProxy::initializeUIClient(const WKPageUIClient* client)
212 {
213     m_uiClient.initialize(client);
214 }
215
216 void WebPageProxy::initializeFindClient(const WKPageFindClient* client)
217 {
218     m_findClient.initialize(client);
219 }
220
221 void WebPageProxy::initializeContextMenuClient(const WKPageContextMenuClient* client)
222 {
223     m_contextMenuClient.initialize(client);
224 }
225
226 void WebPageProxy::reattachToWebProcess()
227 {
228     m_isValid = true;
229
230     context()->relaunchProcessIfNecessary();
231     process()->addExistingWebPage(this, m_pageID);
232
233     initializeWebPage();
234
235     m_pageClient->didRelaunchProcess();
236 }
237
238 void WebPageProxy::reattachToWebProcessWithItem(WebBackForwardListItem* item)
239 {
240     if (item && item != m_backForwardList->currentItem())
241         m_backForwardList->goToItem(item);
242     
243     reattachToWebProcess();
244
245     if (!item)
246         return;
247
248     SandboxExtension::Handle sandboxExtensionHandle;
249     initializeSandboxExtensionHandle(KURL(KURL(), item->url()), sandboxExtensionHandle);
250     process()->send(Messages::WebPage::GoToBackForwardItem(item->itemID(), sandboxExtensionHandle), m_pageID);
251 }
252
253 void WebPageProxy::initializeWebPage()
254 {
255     ASSERT(isValid());
256
257     BackForwardListItemVector items = m_backForwardList->entries();
258     for (size_t i = 0; i < items.size(); ++i)
259         process()->registerNewWebBackForwardListItem(items[i].get());
260
261     m_drawingArea = m_pageClient->createDrawingAreaProxy();
262     ASSERT(m_drawingArea);
263
264     process()->send(Messages::WebProcess::CreateWebPage(m_pageID, creationParameters()), 0);
265 }
266
267 void WebPageProxy::close()
268 {
269     if (!isValid())
270         return;
271
272     m_isClosed = true;
273
274     m_backForwardList->pageClosed();
275     m_pageClient->pageClosed();
276
277     process()->disconnectFramesFromPage(this);
278     m_mainFrame = 0;
279
280 #if ENABLE(INSPECTOR)
281     if (m_inspector) {
282         m_inspector->invalidate();
283         m_inspector = 0;
284     }
285 #endif
286
287     if (m_openPanelResultListener) {
288         m_openPanelResultListener->invalidate();
289         m_openPanelResultListener = 0;
290     }
291
292     m_geolocationPermissionRequestManager.invalidateRequests();
293
294     m_toolTip = String();
295
296     m_mainFrameHasHorizontalScrollbar = false;
297     m_mainFrameHasVerticalScrollbar = false;
298
299     invalidateCallbackMap(m_voidCallbacks);
300     invalidateCallbackMap(m_dataCallbacks);
301     invalidateCallbackMap(m_stringCallbacks);
302     invalidateCallbackMap(m_computedPagesCallbacks);
303
304     Vector<WebEditCommandProxy*> editCommandVector;
305     copyToVector(m_editCommandSet, editCommandVector);
306     m_editCommandSet.clear();
307     for (size_t i = 0, size = editCommandVector.size(); i < size; ++i)
308         editCommandVector[i]->invalidate();
309
310     m_activePopupMenu = 0;
311
312     m_estimatedProgress = 0.0;
313     
314     m_loaderClient.initialize(0);
315     m_policyClient.initialize(0);
316     m_uiClient.initialize(0);
317
318     m_drawingArea.clear();
319
320     process()->send(Messages::WebPage::Close(), m_pageID);
321     process()->removeWebPage(m_pageID);
322 }
323
324 bool WebPageProxy::tryClose()
325 {
326     if (!isValid())
327         return true;
328
329     process()->send(Messages::WebPage::TryClose(), m_pageID);
330     return false;
331 }
332
333 void WebPageProxy::initializeSandboxExtensionHandle(const KURL& url, SandboxExtension::Handle& sandboxExtensionHandle)
334 {
335     if (!url.isLocalFile())
336         return;
337
338     // Don't give the inspector full access to the file system.
339     if (WebInspectorProxy::isInspectorPage(this))
340         return;
341
342     SandboxExtension::createHandle("/", SandboxExtension::ReadOnly, sandboxExtensionHandle);
343 }
344
345 void WebPageProxy::loadURL(const String& url)
346 {
347     setPendingAPIRequestURL(url);
348
349     if (!isValid())
350         reattachToWebProcess();
351
352     SandboxExtension::Handle sandboxExtensionHandle;
353     initializeSandboxExtensionHandle(KURL(KURL(), url), sandboxExtensionHandle);
354     process()->send(Messages::WebPage::LoadURL(url, sandboxExtensionHandle), m_pageID);
355 }
356
357 void WebPageProxy::loadURLRequest(WebURLRequest* urlRequest)
358 {
359     setPendingAPIRequestURL(urlRequest->resourceRequest().url());
360
361     if (!isValid())
362         reattachToWebProcess();
363
364     SandboxExtension::Handle sandboxExtensionHandle;
365     initializeSandboxExtensionHandle(urlRequest->resourceRequest().url(), sandboxExtensionHandle);
366     process()->send(Messages::WebPage::LoadURLRequest(urlRequest->resourceRequest(), sandboxExtensionHandle), m_pageID);
367 }
368
369 void WebPageProxy::loadHTMLString(const String& htmlString, const String& baseURL)
370 {
371     if (!isValid())
372         return;
373     process()->send(Messages::WebPage::LoadHTMLString(htmlString, baseURL), m_pageID);
374 }
375
376 void WebPageProxy::loadAlternateHTMLString(const String& htmlString, const String& baseURL, const String& unreachableURL)
377 {
378     if (!isValid())
379         return;
380
381     if (!m_mainFrame)
382         return;
383
384     m_mainFrame->setUnreachableURL(unreachableURL);
385     process()->send(Messages::WebPage::LoadAlternateHTMLString(htmlString, baseURL, unreachableURL), m_pageID);
386 }
387
388 void WebPageProxy::loadPlainTextString(const String& string)
389 {
390     if (!isValid())
391         return;
392     process()->send(Messages::WebPage::LoadPlainTextString(string), m_pageID);
393 }
394
395 void WebPageProxy::stopLoading()
396 {
397     if (!isValid())
398         return;
399     process()->send(Messages::WebPage::StopLoading(), m_pageID);
400 }
401
402 void WebPageProxy::reload(bool reloadFromOrigin)
403 {
404     if (m_backForwardList->currentItem())
405         setPendingAPIRequestURL(m_backForwardList->currentItem()->url());
406
407     if (!isValid()) {
408         reattachToWebProcessWithItem(m_backForwardList->currentItem());
409         return;
410     }
411
412     process()->send(Messages::WebPage::Reload(reloadFromOrigin), m_pageID);
413 }
414
415 void WebPageProxy::goForward()
416 {
417     if (isValid() && !canGoForward())
418         return;
419
420     WebBackForwardListItem* forwardItem = m_backForwardList->forwardItem();
421     if (forwardItem)
422         setPendingAPIRequestURL(forwardItem->url());
423
424     if (!isValid()) {
425         reattachToWebProcessWithItem(forwardItem);
426         return;
427     }
428
429     SandboxExtension::Handle sandboxExtensionHandle;
430     initializeSandboxExtensionHandle(KURL(KURL(), forwardItem->url()), sandboxExtensionHandle);
431     process()->send(Messages::WebPage::GoForward(forwardItem->itemID(), sandboxExtensionHandle), m_pageID);
432 }
433
434 bool WebPageProxy::canGoForward() const
435 {
436     return m_backForwardList->forwardItem();
437 }
438
439 void WebPageProxy::goBack()
440 {
441     if (isValid() && !canGoBack())
442         return;
443
444     WebBackForwardListItem* backItem = m_backForwardList->backItem();
445     if (backItem)
446         setPendingAPIRequestURL(backItem->url());
447
448     if (!isValid()) {
449         reattachToWebProcessWithItem(backItem);
450         return;
451     }
452
453     SandboxExtension::Handle sandboxExtensionHandle;
454     initializeSandboxExtensionHandle(KURL(KURL(), backItem->url()), sandboxExtensionHandle);
455     process()->send(Messages::WebPage::GoBack(backItem->itemID(), sandboxExtensionHandle), m_pageID);
456 }
457
458 bool WebPageProxy::canGoBack() const
459 {
460     return m_backForwardList->backItem();
461 }
462
463 void WebPageProxy::goToBackForwardItem(WebBackForwardListItem* item)
464 {
465     if (!isValid()) {
466         reattachToWebProcessWithItem(item);
467         return;
468     }
469
470     SandboxExtension::Handle sandboxExtensionHandle;
471     initializeSandboxExtensionHandle(KURL(KURL(), item->url()), sandboxExtensionHandle);
472     process()->send(Messages::WebPage::GoToBackForwardItem(item->itemID(), sandboxExtensionHandle), m_pageID);
473 }
474
475 void WebPageProxy::didChangeBackForwardList(WebBackForwardListItem* added, Vector<RefPtr<APIObject> >* removed)
476 {
477     m_loaderClient.didChangeBackForwardList(this, added, removed);
478 }
479
480     
481 bool WebPageProxy::canShowMIMEType(const String& mimeType) const
482 {
483     if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType))
484         return true;
485
486     if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType))
487         return true;
488     
489     String newMimeType = mimeType;
490     PluginInfoStore::Plugin plugin = context()->pluginInfoStore()->findPlugin(newMimeType, KURL());
491     if (!plugin.path.isNull())
492         return true;
493
494     return false;
495 }
496
497 void WebPageProxy::setDrawsBackground(bool drawsBackground)
498 {
499     if (m_drawsBackground == drawsBackground)
500         return;
501
502     m_drawsBackground = drawsBackground;
503
504     if (isValid())
505         process()->send(Messages::WebPage::SetDrawsBackground(drawsBackground), m_pageID);
506 }
507
508 void WebPageProxy::setDrawsTransparentBackground(bool drawsTransparentBackground)
509 {
510     if (m_drawsTransparentBackground == drawsTransparentBackground)
511         return;
512
513     m_drawsTransparentBackground = drawsTransparentBackground;
514
515     if (isValid())
516         process()->send(Messages::WebPage::SetDrawsTransparentBackground(drawsTransparentBackground), m_pageID);
517 }
518
519 void WebPageProxy::viewWillStartLiveResize()
520 {
521     process()->send(Messages::WebPage::ViewWillStartLiveResize(), m_pageID);
522 }
523
524 void WebPageProxy::viewWillEndLiveResize()
525 {
526     process()->send(Messages::WebPage::ViewWillEndLiveResize(), m_pageID);
527 }
528
529 void WebPageProxy::setViewNeedsDisplay(const IntRect& rect)
530 {
531     m_pageClient->setViewNeedsDisplay(rect);
532 }
533
534 void WebPageProxy::displayView()
535 {
536     m_pageClient->displayView();
537 }
538
539 void WebPageProxy::scrollView(const IntRect& scrollRect, const IntSize& scrollOffset)
540 {
541     m_pageClient->scrollView(scrollRect, scrollOffset);
542 }
543
544 void WebPageProxy::viewStateDidChange(ViewStateFlags flags)
545 {
546     if (!isValid())
547         return;
548
549     if (flags & ViewIsFocused)
550         process()->send(Messages::WebPage::SetFocused(m_pageClient->isViewFocused()), m_pageID);
551
552     if (flags & ViewWindowIsActive)
553         process()->send(Messages::WebPage::SetActive(m_pageClient->isViewWindowActive()), m_pageID);
554
555     if (flags & ViewIsVisible) {
556         bool isVisible = m_pageClient->isViewVisible();
557         if (isVisible != m_isVisible) {
558             m_isVisible = isVisible;
559             m_drawingArea->visibilityDidChange();
560             m_drawingArea->setPageIsVisible(isVisible);
561         }
562     }
563
564     if (flags & ViewIsInWindow) {
565         bool isInWindow = m_pageClient->isViewInWindow();
566         if (m_isInWindow != isInWindow) {
567             m_isInWindow = isInWindow;
568             process()->send(Messages::WebPage::SetIsInWindow(isInWindow), m_pageID);
569         }
570     }
571 }
572
573 IntSize WebPageProxy::viewSize() const
574 {
575     return m_pageClient->viewSize();
576 }
577
578 void WebPageProxy::setInitialFocus(bool forward)
579 {
580     if (!isValid())
581         return;
582     process()->send(Messages::WebPage::SetInitialFocus(forward), m_pageID);
583 }
584
585 void WebPageProxy::setWindowResizerSize(const IntSize& windowResizerSize)
586 {
587     if (!isValid())
588         return;
589     process()->send(Messages::WebPage::SetWindowResizerSize(windowResizerSize), m_pageID);
590 }
591
592 void WebPageProxy::validateMenuItem(const String& commandName)
593 {
594     if (!isValid())
595         return;
596     process()->send(Messages::WebPage::ValidateMenuItem(commandName), m_pageID);
597 }
598     
599 void WebPageProxy::executeEditCommand(const String& commandName)
600 {
601     if (!isValid())
602         return;
603
604     process()->send(Messages::WebPage::ExecuteEditCommand(commandName), m_pageID);
605 }
606     
607 #if PLATFORM(MAC)
608 void WebPageProxy::updateWindowIsVisible(bool windowIsVisible)
609 {
610     if (!isValid())
611         return;
612     process()->send(Messages::WebPage::SetWindowIsVisible(windowIsVisible), m_pageID);
613 }
614
615 void WebPageProxy::windowAndViewFramesChanged(const IntRect& windowFrameInScreenCoordinates, const IntRect& viewFrameInWindowCoordinates, const IntPoint& accessibilityViewCoordinates)
616 {
617     if (!isValid())
618         return;
619
620     process()->send(Messages::WebPage::WindowAndViewFramesChanged(windowFrameInScreenCoordinates, viewFrameInWindowCoordinates, accessibilityViewCoordinates), m_pageID);
621 }
622
623 void WebPageProxy::getMarkedRange(uint64_t& location, uint64_t& length)
624 {
625     process()->sendSync(Messages::WebPage::GetMarkedRange(), Messages::WebPage::GetMarkedRange::Reply(location, length), m_pageID);
626 }
627     
628 uint64_t WebPageProxy::characterIndexForPoint(const IntPoint point)
629 {
630     uint64_t result;
631     process()->sendSync(Messages::WebPage::CharacterIndexForPoint(point), Messages::WebPage::CharacterIndexForPoint::Reply(result), m_pageID);
632     return result;
633 }
634
635 WebCore::IntRect WebPageProxy::firstRectForCharacterRange(uint64_t location, uint64_t length)
636 {
637     IntRect resultRect;
638     process()->sendSync(Messages::WebPage::FirstRectForCharacterRange(location, length), Messages::WebPage::FirstRectForCharacterRange::Reply(resultRect), m_pageID);
639     return resultRect;
640 }
641 #elif PLATFORM(WIN)
642 WebCore::IntRect WebPageProxy::firstRectForCharacterInSelectedRange(int characterPosition)
643 {
644     IntRect resultRect;
645     process()->sendSync(Messages::WebPage::FirstRectForCharacterInSelectedRange(characterPosition), Messages::WebPage::FirstRectForCharacterInSelectedRange::Reply(resultRect), m_pageID);
646     return resultRect;
647 }
648
649 String WebPageProxy::getSelectedText()
650 {
651     String text;
652     process()->sendSync(Messages::WebPage::GetSelectedText(), Messages::WebPage::GetSelectedText::Reply(text), m_pageID);
653     return text;
654 }
655 #endif
656
657 #if ENABLE(TILED_BACKING_STORE)
658 void WebPageProxy::setActualVisibleContentRect(const IntRect& rect)
659 {
660     if (!isValid())
661         return;
662
663     process()->send(Messages::WebPage::SetActualVisibleContentRect(rect), m_pageID);
664 }
665 #endif
666
667 void WebPageProxy::performDragControllerAction(DragControllerAction action, WebCore::DragData* dragData, const String& dragStorageName)
668 {
669     if (!isValid())
670         return;
671 #if PLATFORM(WIN)
672     // FIXME: We should pass the drag data map only on DragEnter.
673     process()->send(Messages::WebPage::PerformDragControllerAction(action, dragData->clientPosition(), dragData->globalPosition(),
674         dragData->draggingSourceOperationMask(), dragData->dragDataMap(), dragData->flags()), m_pageID);
675 #else
676     process()->send(Messages::WebPage::PerformDragControllerAction(action, dragData->clientPosition(), dragData->globalPosition(), dragData->draggingSourceOperationMask(), dragStorageName, dragData->flags()), m_pageID);
677 #endif
678 }
679
680 void WebPageProxy::didPerformDragControllerAction(uint64_t resultOperation)
681 {
682     m_currentDragOperation = static_cast<DragOperation>(resultOperation);
683 }
684
685 #if PLATFORM(MAC)
686 void WebPageProxy::setDragImage(const WebCore::IntPoint& clientPosition, const IntSize& imageSize, const SharedMemory::Handle& dragImageHandle, bool isLinkDrag)
687 {
688     RefPtr<ShareableBitmap> dragImage = ShareableBitmap::create(imageSize, dragImageHandle);
689     if (!dragImage)
690         return;
691     
692     m_pageClient->setDragImage(clientPosition, imageSize, dragImage.release(), isLinkDrag);
693 }
694 #endif
695
696 #if PLATFORM(WIN)
697
698 void WebPageProxy::startDragDrop(const IntPoint& imageOrigin, const IntPoint& dragPoint, uint64_t okEffect, 
699     const HashMap<UINT, Vector<String> >& dataMap, const IntSize& dragImageSize, const SharedMemory::Handle& dragImageHandle, bool isLinkDrag)
700 {
701     COMPtr<WCDataObject> dataObject;
702     WCDataObject::createInstance(&dataObject, dataMap);
703
704     RefPtr<SharedMemory> memoryBuffer = SharedMemory::create(dragImageHandle, SharedMemory::ReadOnly);
705     if (!memoryBuffer)
706         return;
707
708     RefPtr<WebDragSource> source = WebDragSource::createInstance();
709     if (!source)
710         return;
711
712     COMPtr<IDragSourceHelper> helper;
713     if (FAILED(::CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER, IID_IDragSourceHelper, reinterpret_cast<LPVOID*>(&helper))))
714         return;
715
716     BitmapInfo bitmapInfo = BitmapInfo::create(dragImageSize);
717     void* bits;
718     OwnPtr<HBITMAP> hbmp(::CreateDIBSection(0, &bitmapInfo, DIB_RGB_COLORS, &bits, 0, 0));
719     memcpy(bits, memoryBuffer->data(), memoryBuffer->size());
720
721     SHDRAGIMAGE sdi;
722     sdi.sizeDragImage.cx = bitmapInfo.bmiHeader.biWidth;
723     sdi.sizeDragImage.cy = bitmapInfo.bmiHeader.biHeight;
724     sdi.crColorKey = 0xffffffff;
725     sdi.hbmpDragImage = hbmp.leakPtr();
726     sdi.ptOffset.x = dragPoint.x() - imageOrigin.x();
727     sdi.ptOffset.y = dragPoint.y() - imageOrigin.y();
728     if (isLinkDrag)
729         sdi.ptOffset.y = bitmapInfo.bmiHeader.biHeight - sdi.ptOffset.y;
730
731     helper->InitializeFromBitmap(&sdi, dataObject.get());
732
733     DWORD effect = DROPEFFECT_NONE;
734
735     DragOperation operation = DragOperationNone;
736     if (::DoDragDrop(dataObject.get(), source.get(), okEffect, &effect) == DRAGDROP_S_DROP) {
737         if (effect & DROPEFFECT_COPY)
738             operation = DragOperationCopy;
739         else if (effect & DROPEFFECT_LINK)
740             operation = DragOperationLink;
741         else if (effect & DROPEFFECT_MOVE)
742             operation = DragOperationMove;
743     }
744     POINT globalPoint;
745     ::GetCursorPos(&globalPoint);
746     POINT localPoint = globalPoint;
747     ::ScreenToClient(m_pageClient->nativeWindow(), &localPoint);
748
749     dragEnded(localPoint, globalPoint, operation);
750 }
751 #endif
752
753 void WebPageProxy::dragEnded(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition, uint64_t operation)
754 {
755     if (!isValid())
756         return;
757     process()->send(Messages::WebPage::DragEnded(clientPosition, globalPosition, operation), m_pageID);
758 }
759
760 void WebPageProxy::handleMouseEvent(const WebMouseEvent& event)
761 {
762     if (!isValid())
763         return;
764
765     // NOTE: This does not start the responsiveness timer because mouse move should not indicate interaction.
766     if (event.type() != WebEvent::MouseMove)
767         process()->responsivenessTimer()->start();
768     else {
769         if (m_processingMouseMoveEvent) {
770             m_nextMouseMoveEvent = adoptPtr(new WebMouseEvent(event));
771             return;
772         }
773
774         m_processingMouseMoveEvent = true;
775     }
776
777     process()->send(Messages::WebPage::MouseEvent(event), m_pageID);
778 }
779
780 static PassOwnPtr<WebWheelEvent> coalesceWheelEvents(WebWheelEvent* oldNextWheelEvent, const WebWheelEvent& newWheelEvent)
781 {
782 #if MERGE_WHEEL_EVENTS
783     // Merge model: Combine wheel event deltas (and wheel ticks) into a single wheel event.
784     if (!oldNextWheelEvent)
785         return adoptPtr(new WebWheelEvent(newWheelEvent));
786
787     if (oldNextWheelEvent->position() != newWheelEvent.position() || oldNextWheelEvent->modifiers() != newWheelEvent.modifiers() || oldNextWheelEvent->granularity() != newWheelEvent.granularity())
788         return adoptPtr(new WebWheelEvent(newWheelEvent));
789
790     FloatSize mergedDelta = oldNextWheelEvent->delta() + newWheelEvent.delta();
791     FloatSize mergedWheelTicks = oldNextWheelEvent->wheelTicks() + newWheelEvent.wheelTicks();
792
793     return adoptPtr(new WebWheelEvent(WebEvent::Wheel, newWheelEvent.position(), newWheelEvent.globalPosition(), mergedDelta, mergedWheelTicks, newWheelEvent.granularity(), newWheelEvent.modifiers(), newWheelEvent.timestamp()));
794 #else
795     // Simple model: Just keep the last event, dropping all interim events.
796     return adoptPtr(new WebWheelEvent(newWheelEvent));
797 #endif
798 }
799
800 void WebPageProxy::handleWheelEvent(const WebWheelEvent& event)
801 {
802     if (!isValid())
803         return;
804
805     if (m_processingWheelEvent) {
806         m_nextWheelEvent = coalesceWheelEvents(m_nextWheelEvent.get(), event);
807         return;
808     }
809
810     process()->responsivenessTimer()->start();
811     process()->send(Messages::WebPage::WheelEvent(event), m_pageID);
812     m_processingWheelEvent = true;
813 }
814
815 void WebPageProxy::handleKeyboardEvent(const NativeWebKeyboardEvent& event)
816 {
817     if (!isValid())
818         return;
819
820     m_keyEventQueue.append(event);
821
822     process()->responsivenessTimer()->start();
823     process()->send(Messages::WebPage::KeyEvent(event), m_pageID);
824 }
825
826 #if ENABLE(GESTURE_EVENTS)
827 void WebPageProxy::handleGestureEvent(const WebGestureEvent& event)
828 {
829     if (!isValid())
830         return;
831
832     process()->responsivenessTimer()->start();
833     process()->send(Messages::WebPage::GestureEvent(event), m_pageID);
834 }
835 #endif
836
837 #if ENABLE(TOUCH_EVENTS)
838 void WebPageProxy::handleTouchEvent(const WebTouchEvent& event)
839 {
840     if (!isValid())
841         return;
842     process()->send(Messages::WebPage::TouchEvent(event), m_pageID); 
843 }
844 #endif
845
846 void WebPageProxy::receivedPolicyDecision(PolicyAction action, WebFrameProxy* frame, uint64_t listenerID)
847 {
848     if (!isValid())
849         return;
850
851     uint64_t downloadID = 0;
852     if (action == PolicyDownload) {
853         // Create a download proxy.
854         downloadID = context()->createDownloadProxy();
855     }
856
857     // If we received a policy decision while in decidePolicyForMIMEType the decision will 
858     // be sent back to the web process by decidePolicyForMIMEType. 
859     if (m_inDecidePolicyForMIMEType) {
860         m_syncMimeTypePolicyActionIsValid = true;
861         m_syncMimeTypePolicyAction = action;
862         m_syncMimeTypePolicyDownloadID = downloadID;
863         return;
864     }
865
866     // If we received a policy decision while in decidePolicyForNavigationAction the decision will 
867     // be sent back to the web process by decidePolicyForNavigationAction. 
868     if (m_inDecidePolicyForNavigationAction) {
869         m_syncNavigationActionPolicyActionIsValid = true;
870         m_syncNavigationActionPolicyAction = action;
871         return;
872     }
873     
874     process()->send(Messages::WebPage::DidReceivePolicyDecision(frame->frameID(), listenerID, action, downloadID), m_pageID);
875 }
876
877 String WebPageProxy::pageTitle() const
878 {
879     // Return the null string if there is no main frame (e.g. nothing has been loaded in the page yet, WebProcess has
880     // crashed, page has been closed).
881     if (!m_mainFrame)
882         return String();
883
884     return m_mainFrame->title();
885 }
886
887 void WebPageProxy::setUserAgent(const String& userAgent)
888 {
889     if (m_userAgent == userAgent)
890         return;
891     m_userAgent = userAgent;
892
893     if (!isValid())
894         return;
895     process()->send(Messages::WebPage::SetUserAgent(m_userAgent), m_pageID);
896 }
897
898 void WebPageProxy::setApplicationNameForUserAgent(const String& applicationName)
899 {
900     if (m_applicationNameForUserAgent == applicationName)
901         return;
902
903     m_applicationNameForUserAgent = applicationName;
904     if (!m_customUserAgent.isEmpty())
905         return;
906
907     setUserAgent(standardUserAgent(m_applicationNameForUserAgent));
908 }
909
910 void WebPageProxy::setCustomUserAgent(const String& customUserAgent)
911 {
912     if (m_customUserAgent == customUserAgent)
913         return;
914
915     m_customUserAgent = customUserAgent;
916
917     if (m_customUserAgent.isEmpty()) {
918         setUserAgent(standardUserAgent(m_applicationNameForUserAgent));
919         return;
920     }
921
922     setUserAgent(m_customUserAgent);
923 }
924
925 bool WebPageProxy::supportsTextEncoding() const
926 {
927     return !m_mainFrameHasCustomRepresentation && m_mainFrame && !m_mainFrame->isDisplayingStandaloneImageDocument();
928 }
929
930 void WebPageProxy::setCustomTextEncodingName(const String& encodingName)
931 {
932     if (m_customTextEncodingName == encodingName)
933         return;
934     m_customTextEncodingName = encodingName;
935
936     if (!isValid())
937         return;
938     process()->send(Messages::WebPage::SetCustomTextEncodingName(encodingName), m_pageID);
939 }
940
941 void WebPageProxy::terminateProcess()
942 {
943     if (!isValid())
944         return;
945
946     process()->terminate();
947 }
948
949 #if !PLATFORM(CF) || defined(BUILDING_QT__)
950 PassRefPtr<WebData> WebPageProxy::sessionStateData(WebPageProxySessionStateFilterCallback, void* context) const
951 {
952     // FIXME: Return session state data for saving Page state.
953     return 0;
954 }
955
956 void WebPageProxy::restoreFromSessionStateData(WebData*)
957 {
958     // FIXME: Restore the Page from the passed in session state data.
959 }
960 #endif
961
962 bool WebPageProxy::supportsTextZoom() const
963 {
964     if (m_mainFrameHasCustomRepresentation)
965         return false;
966
967     // FIXME: This should also return false for standalone media and plug-in documents.
968     if (!m_mainFrame || m_mainFrame->isDisplayingStandaloneImageDocument())
969         return false;
970
971     return true;
972 }
973  
974 void WebPageProxy::setTextZoomFactor(double zoomFactor)
975 {
976     if (!isValid())
977         return;
978
979     if (m_mainFrameHasCustomRepresentation)
980         return;
981
982     if (m_textZoomFactor == zoomFactor)
983         return;
984
985     m_textZoomFactor = zoomFactor;
986     process()->send(Messages::WebPage::SetTextZoomFactor(m_textZoomFactor), m_pageID); 
987 }
988
989 double WebPageProxy::pageZoomFactor() const
990 {
991     return m_mainFrameHasCustomRepresentation ? m_pageClient->customRepresentationZoomFactor() : m_pageZoomFactor;
992 }
993
994 void WebPageProxy::setPageZoomFactor(double zoomFactor)
995 {
996     if (!isValid())
997         return;
998
999     if (m_mainFrameHasCustomRepresentation) {
1000         m_pageClient->setCustomRepresentationZoomFactor(zoomFactor);
1001         return;
1002     }
1003
1004     if (m_pageZoomFactor == zoomFactor)
1005         return;
1006
1007     m_pageZoomFactor = zoomFactor;
1008     process()->send(Messages::WebPage::SetPageZoomFactor(m_pageZoomFactor), m_pageID); 
1009 }
1010
1011 void WebPageProxy::setPageAndTextZoomFactors(double pageZoomFactor, double textZoomFactor)
1012 {
1013     if (!isValid())
1014         return;
1015
1016     if (m_mainFrameHasCustomRepresentation) {
1017         m_pageClient->setCustomRepresentationZoomFactor(pageZoomFactor);
1018         return;
1019     }
1020
1021     if (m_pageZoomFactor == pageZoomFactor && m_textZoomFactor == textZoomFactor)
1022         return;
1023
1024     m_pageZoomFactor = pageZoomFactor;
1025     m_textZoomFactor = textZoomFactor;
1026     process()->send(Messages::WebPage::SetPageAndTextZoomFactors(m_pageZoomFactor, m_textZoomFactor), m_pageID); 
1027 }
1028
1029 void WebPageProxy::scaleWebView(double scale, const IntPoint& origin)
1030 {
1031     if (!isValid())
1032         return;
1033
1034     process()->send(Messages::WebPage::ScaleWebView(scale, origin), m_pageID);
1035 }
1036
1037 void WebPageProxy::setUseFixedLayout(bool fixed)
1038 {
1039     if (!isValid())
1040         return;
1041
1042     if (fixed == m_useFixedLayout)
1043         return;
1044
1045     m_useFixedLayout = fixed;
1046     if (!fixed)
1047         m_fixedLayoutSize = IntSize();
1048     process()->send(Messages::WebPage::SetUseFixedLayout(fixed), m_pageID);
1049 }
1050
1051 void WebPageProxy::setFixedLayoutSize(const IntSize& size)
1052 {
1053     if (!isValid())
1054         return;
1055
1056     if (size == m_fixedLayoutSize)
1057         return;
1058
1059     m_fixedLayoutSize = size;
1060     process()->send(Messages::WebPage::SetFixedLayoutSize(size), m_pageID);
1061 }
1062
1063 void WebPageProxy::viewScaleFactorDidChange(double scaleFactor)
1064 {
1065     m_viewScaleFactor = scaleFactor;
1066 }
1067
1068 void WebPageProxy::findString(const String& string, FindOptions options, unsigned maxMatchCount)
1069 {
1070     process()->send(Messages::WebPage::FindString(string, options, maxMatchCount), m_pageID);
1071 }
1072
1073 void WebPageProxy::hideFindUI()
1074 {
1075     process()->send(Messages::WebPage::HideFindUI(), m_pageID);
1076 }
1077
1078 void WebPageProxy::countStringMatches(const String& string, FindOptions options, unsigned maxMatchCount)
1079 {
1080     process()->send(Messages::WebPage::CountStringMatches(string, options, maxMatchCount), m_pageID);
1081 }
1082     
1083 void WebPageProxy::runJavaScriptInMainFrame(const String& script, PassRefPtr<StringCallback> prpCallback)
1084 {
1085     RefPtr<StringCallback> callback = prpCallback;
1086     uint64_t callbackID = callback->callbackID();
1087     m_stringCallbacks.set(callbackID, callback.get());
1088     process()->send(Messages::WebPage::RunJavaScriptInMainFrame(script, callbackID), m_pageID);
1089 }
1090
1091 void WebPageProxy::getRenderTreeExternalRepresentation(PassRefPtr<StringCallback> prpCallback)
1092 {
1093     RefPtr<StringCallback> callback = prpCallback;
1094     uint64_t callbackID = callback->callbackID();
1095     m_stringCallbacks.set(callbackID, callback.get());
1096     process()->send(Messages::WebPage::GetRenderTreeExternalRepresentation(callbackID), m_pageID);
1097 }
1098
1099 void WebPageProxy::getSourceForFrame(WebFrameProxy* frame, PassRefPtr<StringCallback> prpCallback)
1100 {
1101     RefPtr<StringCallback> callback = prpCallback;
1102     uint64_t callbackID = callback->callbackID();
1103     m_stringCallbacks.set(callbackID, callback.get());
1104     process()->send(Messages::WebPage::GetSourceForFrame(frame->frameID(), callbackID), m_pageID);
1105 }
1106
1107 void WebPageProxy::getContentsAsString(PassRefPtr<StringCallback> prpCallback)
1108 {
1109     RefPtr<StringCallback> callback = prpCallback;
1110     uint64_t callbackID = callback->callbackID();
1111     m_stringCallbacks.set(callbackID, callback.get());
1112     process()->send(Messages::WebPage::GetContentsAsString(callbackID), m_pageID);
1113 }
1114
1115 void WebPageProxy::getSelectionOrContentsAsString(PassRefPtr<StringCallback> prpCallback)
1116 {
1117     RefPtr<StringCallback> callback = prpCallback;
1118     uint64_t callbackID = callback->callbackID();
1119     m_stringCallbacks.set(callbackID, callback.get());
1120     process()->send(Messages::WebPage::GetSelectionOrContentsAsString(callbackID), m_pageID);
1121 }
1122
1123 void WebPageProxy::getMainResourceDataOfFrame(WebFrameProxy* frame, PassRefPtr<DataCallback> prpCallback)
1124 {
1125     RefPtr<DataCallback> callback = prpCallback;
1126     uint64_t callbackID = callback->callbackID();
1127     m_dataCallbacks.set(callbackID, callback.get());
1128     process()->send(Messages::WebPage::GetMainResourceDataOfFrame(frame->frameID(), callbackID), m_pageID);
1129 }
1130
1131 void WebPageProxy::getResourceDataFromFrame(WebFrameProxy* frame, WebURL* resourceURL, PassRefPtr<DataCallback> prpCallback)
1132 {
1133     RefPtr<DataCallback> callback = prpCallback;
1134     uint64_t callbackID = callback->callbackID();
1135     m_dataCallbacks.set(callbackID, callback.get());
1136     process()->send(Messages::WebPage::GetResourceDataFromFrame(frame->frameID(), resourceURL->string(), callbackID), m_pageID);
1137 }
1138
1139 void WebPageProxy::getWebArchiveOfFrame(WebFrameProxy* frame, PassRefPtr<DataCallback> prpCallback)
1140 {
1141     RefPtr<DataCallback> callback = prpCallback;
1142     uint64_t callbackID = callback->callbackID();
1143     m_dataCallbacks.set(callbackID, callback.get());
1144     process()->send(Messages::WebPage::GetWebArchiveOfFrame(frame->frameID(), callbackID), m_pageID);
1145 }
1146
1147 void WebPageProxy::forceRepaint(PassRefPtr<VoidCallback> prpCallback)
1148 {
1149     RefPtr<VoidCallback> callback = prpCallback;
1150
1151     if (!isValid()) {
1152         callback->invalidate();
1153         return;
1154     }
1155
1156     uint64_t callbackID = callback->callbackID();
1157     m_voidCallbacks.set(callbackID, callback.get());
1158     process()->send(Messages::WebPage::ForceRepaint(callbackID), m_pageID); 
1159 }
1160
1161 void WebPageProxy::preferencesDidChange()
1162 {
1163     if (!isValid())
1164         return;
1165
1166     // FIXME: It probably makes more sense to send individual preference changes.
1167     // However, WebKitTestRunner depends on getting a preference change notification
1168     // even if nothing changed in UI process, so that overrides get removed.
1169     process()->send(Messages::WebPage::PreferencesDidChange(pageGroup()->preferences()->store()), m_pageID);
1170 }
1171
1172 #if ENABLE(TILED_BACKING_STORE)
1173 void WebPageProxy::setResizesToContentsUsingLayoutSize(const WebCore::IntSize& targetLayoutSize)
1174 {
1175     process()->send(Messages::WebPage::SetResizesToContentsUsingLayoutSize(targetLayoutSize), m_pageID);
1176 }
1177 #endif
1178
1179 void WebPageProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
1180 {
1181 #if PLATFORM(MAC) || PLATFORM(WIN)
1182     if (messageID.is<CoreIPC::MessageClassDrawingAreaProxy>()) {
1183         m_drawingArea->didReceiveDrawingAreaProxyMessage(connection, messageID, arguments);
1184         return;
1185     }
1186 #endif
1187
1188     if (messageID.is<CoreIPC::MessageClassDrawingAreaProxyLegacy>()) {
1189         m_drawingArea->didReceiveMessage(connection, messageID, arguments);
1190         return;
1191     }
1192
1193 #if ENABLE(INSPECTOR)
1194     if (messageID.is<CoreIPC::MessageClassWebInspectorProxy>()) {
1195         if (WebInspectorProxy* inspector = this->inspector())
1196             inspector->didReceiveWebInspectorProxyMessage(connection, messageID, arguments);
1197         return;
1198     }
1199 #endif
1200
1201     didReceiveWebPageProxyMessage(connection, messageID, arguments);
1202 }
1203
1204 void WebPageProxy::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, CoreIPC::ArgumentEncoder* reply)
1205 {
1206     if (messageID.is<CoreIPC::MessageClassDrawingAreaProxyLegacy>()) {
1207         m_drawingArea->didReceiveSyncMessage(connection, messageID, arguments, reply);
1208         return;
1209     }
1210
1211 #if ENABLE(INSPECTOR)
1212     if (messageID.is<CoreIPC::MessageClassWebInspectorProxy>()) {
1213         if (WebInspectorProxy* inspector = this->inspector())
1214             inspector->didReceiveSyncWebInspectorProxyMessage(connection, messageID, arguments, reply);
1215         return;
1216     }
1217 #endif
1218
1219     // FIXME: Do something with reply.
1220     didReceiveSyncWebPageProxyMessage(connection, messageID, arguments, reply);
1221 }
1222
1223 #if PLATFORM(MAC)
1224 void WebPageProxy::interpretKeyEvent(uint32_t type, Vector<KeypressCommand>& commandsList, uint32_t selectionStart, uint32_t selectionEnd, Vector<CompositionUnderline>& underlines)
1225 {
1226     m_pageClient->interceptKeyEvent(m_keyEventQueue.first(), commandsList, selectionStart, selectionEnd, underlines);
1227 }
1228 #endif
1229
1230 void WebPageProxy::didCreateMainFrame(uint64_t frameID)
1231 {
1232     MESSAGE_CHECK(!m_mainFrame);
1233     MESSAGE_CHECK(process()->canCreateFrame(frameID));
1234
1235     m_mainFrame = WebFrameProxy::create(this, frameID);
1236
1237     // Add the frame to the process wide map.
1238     process()->frameCreated(frameID, m_mainFrame.get());
1239 }
1240
1241 void WebPageProxy::didCreateSubframe(uint64_t frameID, uint64_t parentFrameID)
1242 {
1243     MESSAGE_CHECK(m_mainFrame);
1244
1245     WebFrameProxy* parentFrame = process()->webFrame(parentFrameID);
1246     MESSAGE_CHECK(parentFrame);
1247     MESSAGE_CHECK(parentFrame->isDescendantOf(m_mainFrame.get()));
1248
1249     MESSAGE_CHECK(process()->canCreateFrame(frameID));
1250     
1251     RefPtr<WebFrameProxy> subFrame = WebFrameProxy::create(this, frameID);
1252
1253     // Add the frame to the process wide map.
1254     process()->frameCreated(frameID, subFrame.get());
1255
1256     // Insert the frame into the frame hierarchy.
1257     parentFrame->appendChild(subFrame.get());
1258 }
1259
1260 static bool isDisconnectedFrame(WebFrameProxy* frame)
1261 {
1262     return !frame->page() || !frame->page()->mainFrame() || !frame->isDescendantOf(frame->page()->mainFrame());
1263 }
1264
1265 void WebPageProxy::didSaveFrameToPageCache(uint64_t frameID)
1266 {
1267     MESSAGE_CHECK(m_mainFrame);
1268
1269     WebFrameProxy* subframe = process()->webFrame(frameID);
1270     MESSAGE_CHECK(subframe);
1271
1272     if (isDisconnectedFrame(subframe))
1273         return;
1274
1275     MESSAGE_CHECK(subframe->isDescendantOf(m_mainFrame.get()));
1276
1277     subframe->didRemoveFromHierarchy();
1278 }
1279
1280 void WebPageProxy::didRestoreFrameFromPageCache(uint64_t frameID, uint64_t parentFrameID)
1281 {
1282     MESSAGE_CHECK(m_mainFrame);
1283
1284     WebFrameProxy* subframe = process()->webFrame(frameID);
1285     MESSAGE_CHECK(subframe);
1286     MESSAGE_CHECK(!subframe->parentFrame());
1287     MESSAGE_CHECK(subframe->page() == m_mainFrame->page());
1288
1289     WebFrameProxy* parentFrame = process()->webFrame(parentFrameID);
1290     MESSAGE_CHECK(parentFrame);
1291     MESSAGE_CHECK(parentFrame->isDescendantOf(m_mainFrame.get()));
1292
1293     // Insert the frame into the frame hierarchy.
1294     parentFrame->appendChild(subframe);
1295 }
1296
1297
1298 // Always start progress at initialProgressValue. This helps provide feedback as
1299 // soon as a load starts.
1300
1301 static const double initialProgressValue = 0.1;
1302
1303 double WebPageProxy::estimatedProgress() const
1304 {
1305     if (!pendingAPIRequestURL().isNull())
1306         return initialProgressValue;
1307     return m_estimatedProgress; 
1308 }
1309
1310 void WebPageProxy::didStartProgress()
1311 {
1312     m_estimatedProgress = initialProgressValue;
1313
1314     m_loaderClient.didStartProgress(this);
1315 }
1316
1317 void WebPageProxy::didChangeProgress(double value)
1318 {
1319     m_estimatedProgress = value;
1320
1321     m_loaderClient.didChangeProgress(this);
1322 }
1323
1324 void WebPageProxy::didFinishProgress()
1325 {
1326     m_estimatedProgress = 1.0;
1327
1328     m_loaderClient.didFinishProgress(this);
1329 }
1330
1331 void WebPageProxy::didStartProvisionalLoadForFrame(uint64_t frameID, const String& url, bool loadingSubstituteDataForUnreachableURL, CoreIPC::ArgumentDecoder* arguments)
1332 {
1333     clearPendingAPIRequestURL();
1334
1335     RefPtr<APIObject> userData;
1336     WebContextUserMessageDecoder messageDecoder(userData, context());
1337     if (!arguments->decode(messageDecoder))
1338         return;
1339
1340     WebFrameProxy* frame = process()->webFrame(frameID);
1341     MESSAGE_CHECK(frame);
1342
1343     if (!loadingSubstituteDataForUnreachableURL)
1344         frame->setUnreachableURL(String());
1345
1346     frame->didStartProvisionalLoad(url);
1347     m_loaderClient.didStartProvisionalLoadForFrame(this, frame, userData.get());
1348 }
1349
1350 void WebPageProxy::didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, const String& url, CoreIPC::ArgumentDecoder* arguments)
1351 {
1352     RefPtr<APIObject> userData;
1353     WebContextUserMessageDecoder messageDecoder(userData, context());
1354     if (!arguments->decode(messageDecoder))
1355         return;
1356
1357     WebFrameProxy* frame = process()->webFrame(frameID);
1358     MESSAGE_CHECK(frame);
1359
1360     frame->didReceiveServerRedirectForProvisionalLoad(url);
1361
1362     m_loaderClient.didReceiveServerRedirectForProvisionalLoadForFrame(this, frame, userData.get());
1363 }
1364
1365 void WebPageProxy::didFailProvisionalLoadForFrame(uint64_t frameID, const ResourceError& error, CoreIPC::ArgumentDecoder* arguments)
1366 {
1367     RefPtr<APIObject> userData;
1368     WebContextUserMessageDecoder messageDecoder(userData, context());
1369     if (!arguments->decode(messageDecoder))
1370         return;
1371
1372     WebFrameProxy* frame = process()->webFrame(frameID);
1373     MESSAGE_CHECK(frame);
1374
1375     frame->didFailProvisionalLoad();
1376
1377     m_loaderClient.didFailProvisionalLoadWithErrorForFrame(this, frame, error, userData.get());
1378 }
1379
1380 void WebPageProxy::didCommitLoadForFrame(uint64_t frameID, const String& mimeType, bool frameHasCustomRepresentation, const PlatformCertificateInfo& certificateInfo, CoreIPC::ArgumentDecoder* arguments)
1381 {
1382     RefPtr<APIObject> userData;
1383     WebContextUserMessageDecoder messageDecoder(userData, context());
1384     if (!arguments->decode(messageDecoder))
1385         return;
1386
1387     WebFrameProxy* frame = process()->webFrame(frameID);
1388     MESSAGE_CHECK(frame);
1389
1390     frame->didCommitLoad(mimeType, certificateInfo);
1391
1392     if (frame->isMainFrame()) {
1393         m_mainFrameHasCustomRepresentation = frameHasCustomRepresentation;
1394         m_pageClient->didCommitLoadForMainFrame(frameHasCustomRepresentation);
1395     }
1396
1397     m_loaderClient.didCommitLoadForFrame(this, frame, userData.get());
1398 }
1399
1400 void WebPageProxy::didFinishDocumentLoadForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1401 {
1402     RefPtr<APIObject> userData;
1403     WebContextUserMessageDecoder messageDecoder(userData, context());
1404     if (!arguments->decode(messageDecoder))
1405         return;
1406
1407     WebFrameProxy* frame = process()->webFrame(frameID);
1408     MESSAGE_CHECK(frame);
1409
1410     m_loaderClient.didFinishDocumentLoadForFrame(this, frame, userData.get());
1411 }
1412
1413 void WebPageProxy::didFinishLoadForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1414 {
1415     RefPtr<APIObject> userData;
1416     WebContextUserMessageDecoder messageDecoder(userData, context());
1417     if (!arguments->decode(messageDecoder))
1418         return;
1419
1420     WebFrameProxy* frame = process()->webFrame(frameID);
1421     MESSAGE_CHECK(frame);
1422
1423     frame->didFinishLoad();
1424
1425     m_loaderClient.didFinishLoadForFrame(this, frame, userData.get());
1426 }
1427
1428 void WebPageProxy::didFailLoadForFrame(uint64_t frameID, const ResourceError& error, CoreIPC::ArgumentDecoder* arguments)
1429 {
1430     RefPtr<APIObject> userData;
1431     WebContextUserMessageDecoder messageDecoder(userData, context());
1432     if (!arguments->decode(messageDecoder))
1433         return;
1434
1435     WebFrameProxy* frame = process()->webFrame(frameID);
1436     MESSAGE_CHECK(frame);
1437
1438     frame->didFailLoad();
1439
1440     m_loaderClient.didFailLoadWithErrorForFrame(this, frame, error, userData.get());
1441 }
1442
1443 void WebPageProxy::didSameDocumentNavigationForFrame(uint64_t frameID, uint32_t opaqueSameDocumentNavigationType, const String& url, CoreIPC::ArgumentDecoder* arguments)
1444 {
1445     RefPtr<APIObject> userData;
1446     WebContextUserMessageDecoder messageDecoder(userData, context());
1447     if (!arguments->decode(messageDecoder))
1448         return;
1449
1450     WebFrameProxy* frame = process()->webFrame(frameID);
1451     MESSAGE_CHECK(frame);
1452
1453     frame->didSameDocumentNavigation(url);
1454
1455     m_loaderClient.didSameDocumentNavigationForFrame(this, frame, static_cast<SameDocumentNavigationType>(opaqueSameDocumentNavigationType), userData.get());
1456 }
1457
1458 void WebPageProxy::didReceiveTitleForFrame(uint64_t frameID, const String& title, CoreIPC::ArgumentDecoder* arguments)
1459 {
1460     RefPtr<APIObject> userData;
1461     WebContextUserMessageDecoder messageDecoder(userData, context());
1462     if (!arguments->decode(messageDecoder))
1463         return;
1464
1465     WebFrameProxy* frame = process()->webFrame(frameID);
1466     MESSAGE_CHECK(frame);
1467
1468     frame->didChangeTitle(title);
1469     
1470     m_loaderClient.didReceiveTitleForFrame(this, title, frame, userData.get());
1471 }
1472
1473 void WebPageProxy::didFirstLayoutForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1474 {
1475     RefPtr<APIObject> userData;
1476     WebContextUserMessageDecoder messageDecoder(userData, context());
1477     if (!arguments->decode(messageDecoder))
1478         return;
1479
1480     WebFrameProxy* frame = process()->webFrame(frameID);
1481     MESSAGE_CHECK(frame);
1482
1483     m_loaderClient.didFirstLayoutForFrame(this, frame, userData.get());
1484 }
1485
1486 void WebPageProxy::didFirstVisuallyNonEmptyLayoutForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1487 {
1488     RefPtr<APIObject> userData;
1489     WebContextUserMessageDecoder messageDecoder(userData, context());
1490     if (!arguments->decode(messageDecoder))
1491         return;
1492
1493     WebFrameProxy* frame = process()->webFrame(frameID);
1494     MESSAGE_CHECK(frame);
1495
1496     m_loaderClient.didFirstVisuallyNonEmptyLayoutForFrame(this, frame, userData.get());
1497 }
1498
1499 void WebPageProxy::didRemoveFrameFromHierarchy(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1500 {
1501     RefPtr<APIObject> userData;
1502     WebContextUserMessageDecoder messageDecoder(userData, context());
1503     if (!arguments->decode(messageDecoder))
1504         return;
1505
1506     WebFrameProxy* frame = process()->webFrame(frameID);
1507     MESSAGE_CHECK(frame);
1508
1509     frame->didRemoveFromHierarchy();
1510
1511     m_loaderClient.didRemoveFrameFromHierarchy(this, frame, userData.get());
1512 }
1513
1514 void WebPageProxy::didDisplayInsecureContentForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1515 {
1516     RefPtr<APIObject> userData;
1517     WebContextUserMessageDecoder messageDecoder(userData, context());
1518     if (!arguments->decode(messageDecoder))
1519         return;
1520
1521     WebFrameProxy* frame = process()->webFrame(frameID);
1522     MESSAGE_CHECK(frame);
1523
1524     m_loaderClient.didDisplayInsecureContentForFrame(this, frame, userData.get());
1525 }
1526
1527 void WebPageProxy::didRunInsecureContentForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1528 {
1529     RefPtr<APIObject> userData;
1530     WebContextUserMessageDecoder messageDecoder(userData, context());
1531     if (!arguments->decode(messageDecoder))
1532         return;
1533
1534     WebFrameProxy* frame = process()->webFrame(frameID);
1535     MESSAGE_CHECK(frame);
1536
1537     m_loaderClient.didRunInsecureContentForFrame(this, frame, userData.get());
1538 }
1539
1540 void WebPageProxy::frameDidBecomeFrameSet(uint64_t frameID, bool value)
1541 {
1542     WebFrameProxy* frame = process()->webFrame(frameID);
1543     MESSAGE_CHECK(frame);
1544
1545     frame->setIsFrameSet(value);
1546     if (frame->isMainFrame())
1547         m_frameSetLargestFrame = value ? m_mainFrame : 0;
1548 }
1549
1550 // PolicyClient
1551 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)
1552 {
1553     RefPtr<APIObject> userData;
1554     WebContextUserMessageDecoder messageDecoder(userData, context());
1555     if (!arguments->decode(messageDecoder))
1556         return;
1557
1558     if (request.url() != pendingAPIRequestURL())
1559         clearPendingAPIRequestURL();
1560
1561     WebFrameProxy* frame = process()->webFrame(frameID);
1562     MESSAGE_CHECK(frame);
1563
1564     NavigationType navigationType = static_cast<NavigationType>(opaqueNavigationType);
1565     WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
1566     WebMouseEvent::Button mouseButton = static_cast<WebMouseEvent::Button>(opaqueMouseButton);
1567     
1568     RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
1569
1570     ASSERT(!m_inDecidePolicyForNavigationAction);
1571
1572     m_inDecidePolicyForNavigationAction = true;
1573     m_syncNavigationActionPolicyActionIsValid = false;
1574     
1575     if (!m_policyClient.decidePolicyForNavigationAction(this, frame, navigationType, modifiers, mouseButton, request, listener.get(), userData.get()))
1576         listener->use();
1577
1578     m_inDecidePolicyForNavigationAction = false;
1579
1580     // Check if we received a policy decision already. If we did, we can just pass it back.
1581     if (m_syncNavigationActionPolicyActionIsValid) {
1582         receivedPolicyAction = true;
1583         policyAction = m_syncNavigationActionPolicyAction;
1584     }
1585 }
1586
1587 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)
1588 {
1589     RefPtr<APIObject> userData;
1590     WebContextUserMessageDecoder messageDecoder(userData, context());
1591     if (!arguments->decode(messageDecoder))
1592         return;
1593
1594     WebFrameProxy* frame = process()->webFrame(frameID);
1595     MESSAGE_CHECK(frame);
1596
1597     NavigationType navigationType = static_cast<NavigationType>(opaqueNavigationType);
1598     WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
1599     WebMouseEvent::Button mouseButton = static_cast<WebMouseEvent::Button>(opaqueMouseButton);
1600
1601     RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
1602     if (!m_policyClient.decidePolicyForNewWindowAction(this, frame, navigationType, modifiers, mouseButton, request, frameName, listener.get(), userData.get()))
1603         listener->use();
1604 }
1605
1606 void WebPageProxy::decidePolicyForMIMEType(uint64_t frameID, const String& MIMEType, const ResourceRequest& request, uint64_t listenerID, CoreIPC::ArgumentDecoder* arguments, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID)
1607 {
1608     RefPtr<APIObject> userData;
1609     WebContextUserMessageDecoder messageDecoder(userData, context());
1610     if (!arguments->decode(messageDecoder))
1611         return;
1612
1613     WebFrameProxy* frame = process()->webFrame(frameID);
1614     MESSAGE_CHECK(frame);
1615
1616     RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
1617
1618     ASSERT(!m_inDecidePolicyForMIMEType);
1619
1620     m_inDecidePolicyForMIMEType = true;
1621     m_syncMimeTypePolicyActionIsValid = false;
1622
1623     if (!m_policyClient.decidePolicyForMIMEType(this, frame, MIMEType, request, listener.get(), 0 /*userData*/))
1624         listener->use();
1625
1626     m_inDecidePolicyForMIMEType = false;
1627
1628     // Check if we received a policy decision already. If we did, we can just pass it back.
1629     if (m_syncMimeTypePolicyActionIsValid) {
1630         receivedPolicyAction = true;
1631         policyAction = m_syncMimeTypePolicyAction;
1632         downloadID = m_syncMimeTypePolicyDownloadID;
1633     }
1634 }
1635
1636 // FormClient
1637
1638 void WebPageProxy::willSubmitForm(uint64_t frameID, uint64_t sourceFrameID, const StringPairVector& textFieldValues, uint64_t listenerID, CoreIPC::ArgumentDecoder* arguments)
1639 {
1640     RefPtr<APIObject> userData;
1641     WebContextUserMessageDecoder messageDecoder(userData, context());
1642     if (!arguments->decode(messageDecoder))
1643         return;
1644
1645     WebFrameProxy* frame = process()->webFrame(frameID);
1646     MESSAGE_CHECK(frame);
1647
1648     WebFrameProxy* sourceFrame = process()->webFrame(sourceFrameID);
1649     MESSAGE_CHECK(sourceFrame);
1650
1651     RefPtr<WebFormSubmissionListenerProxy> listener = frame->setUpFormSubmissionListenerProxy(listenerID);
1652     if (!m_formClient.willSubmitForm(this, frame, sourceFrame, textFieldValues.stringPairVector(), userData.get(), listener.get()))
1653         listener->continueSubmission();
1654 }
1655
1656 // ResourceLoad Client
1657
1658 void WebPageProxy::didInitiateLoadForResource(uint64_t frameID, uint64_t resourceIdentifier, const ResourceRequest& request, bool pageIsProvisionallyLoading)
1659 {
1660     WebFrameProxy* frame = process()->webFrame(frameID);
1661     MESSAGE_CHECK(frame);
1662
1663     m_resourceLoadClient.didInitiateLoadForResource(this, frame, resourceIdentifier, request, pageIsProvisionallyLoading);
1664 }
1665
1666 void WebPageProxy::didSendRequestForResource(uint64_t frameID, uint64_t resourceIdentifier, const ResourceRequest& request, const ResourceResponse& redirectResponse)
1667 {
1668     WebFrameProxy* frame = process()->webFrame(frameID);
1669     MESSAGE_CHECK(frame);
1670
1671     m_resourceLoadClient.didSendRequestForResource(this, frame, resourceIdentifier, request, redirectResponse);
1672 }
1673
1674 void WebPageProxy::didReceiveResponseForResource(uint64_t frameID, uint64_t resourceIdentifier, const ResourceResponse& response)
1675 {
1676     WebFrameProxy* frame = process()->webFrame(frameID);
1677     MESSAGE_CHECK(frame);
1678
1679     m_resourceLoadClient.didReceiveResponseForResource(this, frame, resourceIdentifier, response);
1680 }
1681
1682 void WebPageProxy::didReceiveContentLengthForResource(uint64_t frameID, uint64_t resourceIdentifier, uint64_t contentLength)
1683 {
1684     WebFrameProxy* frame = process()->webFrame(frameID);
1685     MESSAGE_CHECK(frame);
1686
1687     m_resourceLoadClient.didReceiveContentLengthForResource(this, frame, resourceIdentifier, contentLength);
1688 }
1689
1690 void WebPageProxy::didFinishLoadForResource(uint64_t frameID, uint64_t resourceIdentifier)
1691 {
1692     WebFrameProxy* frame = process()->webFrame(frameID);
1693     MESSAGE_CHECK(frame);
1694
1695     m_resourceLoadClient.didFinishLoadForResource(this, frame, resourceIdentifier);
1696 }
1697
1698 void WebPageProxy::didFailLoadForResource(uint64_t frameID, uint64_t resourceIdentifier, const ResourceError& error)
1699 {
1700     WebFrameProxy* frame = process()->webFrame(frameID);
1701     MESSAGE_CHECK(frame);
1702
1703     m_resourceLoadClient.didFailLoadForResource(this, frame, resourceIdentifier, error);
1704 }
1705
1706 // UIClient
1707
1708 void WebPageProxy::createNewPage(const WindowFeatures& windowFeatures, uint32_t opaqueModifiers, int32_t opaqueMouseButton, uint64_t& newPageID, WebPageCreationParameters& newPageParameters)
1709 {
1710     RefPtr<WebPageProxy> newPage = m_uiClient.createNewPage(this, windowFeatures, static_cast<WebEvent::Modifiers>(opaqueModifiers), static_cast<WebMouseEvent::Button>(opaqueMouseButton));
1711     if (newPage) {
1712         newPageID = newPage->pageID();
1713         newPageParameters = newPage->creationParameters();
1714     } else
1715         newPageID = 0;
1716 }
1717     
1718 void WebPageProxy::showPage()
1719 {
1720     m_uiClient.showPage(this);
1721 }
1722
1723 void WebPageProxy::closePage()
1724 {
1725     m_uiClient.close(this);
1726 }
1727
1728 void WebPageProxy::runJavaScriptAlert(uint64_t frameID, const String& message)
1729 {
1730     WebFrameProxy* frame = process()->webFrame(frameID);
1731     MESSAGE_CHECK(frame);
1732
1733     m_uiClient.runJavaScriptAlert(this, message, frame);
1734 }
1735
1736 void WebPageProxy::runJavaScriptConfirm(uint64_t frameID, const String& message, bool& result)
1737 {
1738     WebFrameProxy* frame = process()->webFrame(frameID);
1739     MESSAGE_CHECK(frame);
1740
1741     result = m_uiClient.runJavaScriptConfirm(this, message, frame);
1742 }
1743
1744 void WebPageProxy::runJavaScriptPrompt(uint64_t frameID, const String& message, const String& defaultValue, String& result)
1745 {
1746     WebFrameProxy* frame = process()->webFrame(frameID);
1747     MESSAGE_CHECK(frame);
1748
1749     result = m_uiClient.runJavaScriptPrompt(this, message, defaultValue, frame);
1750 }
1751
1752 void WebPageProxy::setStatusText(const String& text)
1753 {
1754     m_uiClient.setStatusText(this, text);
1755 }
1756
1757 void WebPageProxy::mouseDidMoveOverElement(uint32_t opaqueModifiers, CoreIPC::ArgumentDecoder* arguments)
1758 {
1759     RefPtr<APIObject> userData;
1760     WebContextUserMessageDecoder messageDecoder(userData, context());
1761     if (!arguments->decode(messageDecoder))
1762         return;
1763
1764     WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
1765
1766     m_uiClient.mouseDidMoveOverElement(this, modifiers, userData.get());
1767 }
1768
1769 void WebPageProxy::missingPluginButtonClicked(const String& mimeType, const String& url)
1770 {
1771     m_uiClient.missingPluginButtonClicked(this, mimeType, url);
1772 }
1773
1774 void WebPageProxy::setToolbarsAreVisible(bool toolbarsAreVisible)
1775 {
1776     m_uiClient.setToolbarsAreVisible(this, toolbarsAreVisible);
1777 }
1778
1779 void WebPageProxy::getToolbarsAreVisible(bool& toolbarsAreVisible)
1780 {
1781     toolbarsAreVisible = m_uiClient.toolbarsAreVisible(this);
1782 }
1783
1784 void WebPageProxy::setMenuBarIsVisible(bool menuBarIsVisible)
1785 {
1786     m_uiClient.setMenuBarIsVisible(this, menuBarIsVisible);
1787 }
1788
1789 void WebPageProxy::getMenuBarIsVisible(bool& menuBarIsVisible)
1790 {
1791     menuBarIsVisible = m_uiClient.menuBarIsVisible(this);
1792 }
1793
1794 void WebPageProxy::setStatusBarIsVisible(bool statusBarIsVisible)
1795 {
1796     m_uiClient.setStatusBarIsVisible(this, statusBarIsVisible);
1797 }
1798
1799 void WebPageProxy::getStatusBarIsVisible(bool& statusBarIsVisible)
1800 {
1801     statusBarIsVisible = m_uiClient.statusBarIsVisible(this);
1802 }
1803
1804 void WebPageProxy::setIsResizable(bool isResizable)
1805 {
1806     m_uiClient.setIsResizable(this, isResizable);
1807 }
1808
1809 void WebPageProxy::getIsResizable(bool& isResizable)
1810 {
1811     isResizable = m_uiClient.isResizable(this);
1812 }
1813
1814 void WebPageProxy::setWindowFrame(const FloatRect& newWindowFrame)
1815 {
1816     m_uiClient.setWindowFrame(this, m_pageClient->convertToDeviceSpace(newWindowFrame));
1817 }
1818
1819 void WebPageProxy::getWindowFrame(FloatRect& newWindowFrame)
1820 {
1821     newWindowFrame = m_pageClient->convertToUserSpace(m_uiClient.windowFrame(this));
1822 }
1823
1824 void WebPageProxy::canRunBeforeUnloadConfirmPanel(bool& canRun)
1825 {
1826     canRun = m_uiClient.canRunBeforeUnloadConfirmPanel();
1827 }
1828
1829 void WebPageProxy::runBeforeUnloadConfirmPanel(const String& message, uint64_t frameID, bool& shouldClose)
1830 {
1831     WebFrameProxy* frame = process()->webFrame(frameID);
1832     MESSAGE_CHECK(frame);
1833
1834     shouldClose = m_uiClient.runBeforeUnloadConfirmPanel(this, message, frame);
1835 }
1836
1837 #if ENABLE(TILED_BACKING_STORE)
1838 void WebPageProxy::pageDidRequestScroll(const IntSize& delta)
1839 {
1840     m_pageClient->pageDidRequestScroll(delta);
1841 }
1842 #endif
1843
1844 void WebPageProxy::didChangeViewportData(const ViewportArguments& args)
1845 {
1846     m_pageClient->setViewportArguments(args);
1847 }
1848
1849 void WebPageProxy::pageDidScroll()
1850 {
1851     m_uiClient.pageDidScroll(this);
1852 }
1853
1854 void WebPageProxy::runOpenPanel(uint64_t frameID, const WebOpenPanelParameters::Data& data)
1855 {
1856     if (m_openPanelResultListener) {
1857         m_openPanelResultListener->invalidate();
1858         m_openPanelResultListener = 0;
1859     }
1860
1861     WebFrameProxy* frame = process()->webFrame(frameID);
1862     MESSAGE_CHECK(frame);
1863
1864     m_openPanelResultListener = WebOpenPanelResultListenerProxy::create(this);
1865
1866     if (!m_uiClient.runOpenPanel(this, frame, data, m_openPanelResultListener.get()))
1867         didCancelForOpenPanel();
1868 }
1869
1870 void WebPageProxy::printFrame(uint64_t frameID)
1871 {
1872     ASSERT(!m_isPerformingDOMPrintOperation);
1873     m_isPerformingDOMPrintOperation = true;
1874
1875     WebFrameProxy* frame = process()->webFrame(frameID);
1876     MESSAGE_CHECK(frame);
1877
1878     m_uiClient.printFrame(this, frame);
1879
1880     m_isPerformingDOMPrintOperation = false;
1881 }
1882
1883 #if PLATFORM(QT)
1884 void WebPageProxy::didChangeContentsSize(const WebCore::IntSize& size)
1885 {
1886     m_pageClient->didChangeContentsSize(size);
1887 }
1888
1889 void WebPageProxy::didFindZoomableArea(const WebCore::IntRect& area)
1890 {
1891     m_pageClient->didFindZoomableArea(area);
1892 }
1893
1894 void WebPageProxy::findZoomableAreaForPoint(const WebCore::IntPoint& point)
1895 {
1896     if (!isValid())
1897         return;
1898
1899     process()->send(Messages::WebPage::FindZoomableAreaForPoint(point), m_pageID);
1900 }
1901 #endif
1902
1903 void WebPageProxy::didDraw()
1904 {
1905     m_uiClient.didDraw(this);
1906 }
1907
1908 // Inspector
1909
1910 #if ENABLE(INSPECTOR)
1911
1912 WebInspectorProxy* WebPageProxy::inspector()
1913 {
1914     if (isClosed() || !isValid())
1915         return 0;
1916     if (!m_inspector)
1917         m_inspector = WebInspectorProxy::create(this);
1918     return m_inspector.get();
1919 }
1920
1921 #endif
1922
1923 // BackForwardList
1924
1925 void WebPageProxy::backForwardAddItem(uint64_t itemID)
1926 {
1927     m_backForwardList->addItem(process()->webBackForwardItem(itemID));
1928 }
1929
1930 void WebPageProxy::backForwardGoToItem(uint64_t itemID)
1931 {
1932     m_backForwardList->goToItem(process()->webBackForwardItem(itemID));
1933 }
1934
1935 void WebPageProxy::backForwardItemAtIndex(int32_t index, uint64_t& itemID)
1936 {
1937     WebBackForwardListItem* item = m_backForwardList->itemAtIndex(index);
1938     itemID = item ? item->itemID() : 0;
1939 }
1940
1941 void WebPageProxy::backForwardBackListCount(int32_t& count)
1942 {
1943     count = m_backForwardList->backListCount();
1944 }
1945
1946 void WebPageProxy::backForwardForwardListCount(int32_t& count)
1947 {
1948     count = m_backForwardList->forwardListCount();
1949 }
1950
1951 void WebPageProxy::selectionStateChanged(const SelectionState& selectionState)
1952 {
1953     m_selectionState = selectionState;
1954 }
1955
1956 #if PLATFORM(MAC)
1957 // Complex text input support for plug-ins.
1958 void WebPageProxy::sendComplexTextInputToPlugin(uint64_t pluginComplexTextInputIdentifier, const String& textInput)
1959 {
1960     if (!isValid())
1961         return;
1962     
1963     process()->send(Messages::WebPage::SendComplexTextInputToPlugin(pluginComplexTextInputIdentifier, textInput), m_pageID);
1964 }
1965 #endif
1966
1967 #if PLATFORM(WIN)
1968 void WebPageProxy::didChangeCompositionSelection(bool hasComposition)
1969 {
1970     m_pageClient->compositionSelectionChanged(hasComposition);
1971 }
1972
1973 void WebPageProxy::confirmComposition(const String& compositionString)
1974 {
1975     process()->send(Messages::WebPage::ConfirmComposition(compositionString), m_pageID);
1976 }
1977
1978 void WebPageProxy::setComposition(const String& compositionString, Vector<WebCore::CompositionUnderline>& underlines, int cursorPosition)
1979 {
1980     process()->send(Messages::WebPage::SetComposition(compositionString, underlines, cursorPosition), m_pageID);
1981 }
1982 #endif
1983     
1984 // Undo management
1985
1986 void WebPageProxy::registerEditCommandForUndo(uint64_t commandID, uint32_t editAction)
1987 {
1988     registerEditCommand(WebEditCommandProxy::create(commandID, static_cast<EditAction>(editAction), this), Undo);
1989 }
1990
1991 void WebPageProxy::clearAllEditCommands()
1992 {
1993     m_pageClient->clearAllEditCommands();
1994 }
1995
1996 void WebPageProxy::didCountStringMatches(const String& string, uint32_t matchCount)
1997 {
1998     m_findClient.didCountStringMatches(this, string, matchCount);
1999 }
2000
2001 void WebPageProxy::setFindIndicator(const FloatRect& selectionRectInWindowCoordinates, const Vector<FloatRect>& textRectsInSelectionRectCoordinates, const SharedMemory::Handle& contentImageHandle, bool fadeOut)
2002 {
2003     RefPtr<FindIndicator> findIndicator = FindIndicator::create(selectionRectInWindowCoordinates, textRectsInSelectionRectCoordinates, contentImageHandle);
2004     m_pageClient->setFindIndicator(findIndicator.release(), fadeOut);
2005 }
2006
2007 void WebPageProxy::didFindString(const String& string, uint32_t matchCount)
2008 {
2009     m_findClient.didFindString(this, string, matchCount);
2010 }
2011
2012 void WebPageProxy::didFailToFindString(const String& string)
2013 {
2014     m_findClient.didFailToFindString(this, string);
2015 }
2016
2017 void WebPageProxy::valueChangedForPopupMenu(WebPopupMenuProxy*, int32_t newSelectedIndex)
2018 {
2019     process()->send(Messages::WebPage::DidChangeSelectedIndexForActivePopupMenu(newSelectedIndex), m_pageID);
2020 }
2021
2022 void WebPageProxy::setTextFromItemForPopupMenu(WebPopupMenuProxy*, int32_t index)
2023 {
2024     process()->send(Messages::WebPage::SetTextForActivePopupMenu(index), m_pageID);
2025 }
2026
2027 void WebPageProxy::showPopupMenu(const IntRect& rect, uint64_t textDirection, const Vector<WebPopupItem>& items, int32_t selectedIndex, const PlatformPopupMenuData& data)
2028 {
2029     if (m_activePopupMenu) {
2030         m_activePopupMenu->hidePopupMenu();
2031         m_activePopupMenu->invalidate();
2032         m_activePopupMenu = 0;
2033     }
2034
2035     m_activePopupMenu = m_pageClient->createPopupMenuProxy(this);
2036
2037 #if PLATFORM(WIN)
2038     // On Windows, we're about to run our own message pump in showPopupMenu(), so turn off the responsiveness timer.
2039     process()->responsivenessTimer()->stop();
2040 #endif
2041
2042     RefPtr<WebPopupMenuProxy> protectedActivePopupMenu = m_activePopupMenu;
2043
2044     protectedActivePopupMenu->showPopupMenu(rect, static_cast<TextDirection>(textDirection), items, data, selectedIndex);
2045     protectedActivePopupMenu->invalidate();
2046     protectedActivePopupMenu = 0;
2047 }
2048
2049 void WebPageProxy::hidePopupMenu()
2050 {
2051     if (!m_activePopupMenu)
2052         return;
2053
2054     m_activePopupMenu->hidePopupMenu();
2055     m_activePopupMenu->invalidate();
2056     m_activePopupMenu = 0;
2057 }
2058
2059 void WebPageProxy::showContextMenu(const IntPoint& menuLocation, const ContextMenuState& contextMenuState, const Vector<WebContextMenuItemData>& proposedItems, CoreIPC::ArgumentDecoder* arguments)
2060 {
2061     RefPtr<APIObject> userData;
2062     WebContextUserMessageDecoder messageDecoder(userData, context());
2063     if (!arguments->decode(messageDecoder))
2064         return;
2065
2066     m_activeContextMenuState = contextMenuState;
2067
2068     if (m_activeContextMenu)
2069         m_activeContextMenu->hideContextMenu();
2070     else
2071         m_activeContextMenu = m_pageClient->createContextMenuProxy(this);
2072
2073     // Give the PageContextMenuClient one last swipe at changing the menu.
2074     Vector<WebContextMenuItemData> items;
2075         
2076     if (!m_contextMenuClient.getContextMenuFromProposedMenu(this, proposedItems, items, userData.get())) {
2077         m_activeContextMenu->showContextMenu(menuLocation, proposedItems);
2078         return;
2079     }
2080     
2081     if (items.size())
2082         m_activeContextMenu->showContextMenu(menuLocation, items);
2083 }
2084
2085 void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& item)
2086 {
2087     // Application custom items don't need to round-trip through to WebCore in the WebProcess.
2088     if (item.action() >= ContextMenuItemBaseApplicationTag) {
2089         m_contextMenuClient.customContextMenuItemSelected(this, item);
2090         return;
2091     }
2092
2093 #if PLATFORM(MAC)
2094     if (item.action() == ContextMenuItemTagSmartCopyPaste) {
2095         setSmartInsertDeleteEnabled(!isSmartInsertDeleteEnabled());
2096         return;
2097     }
2098     if (item.action() == ContextMenuItemTagSmartQuotes) {
2099         TextChecker::setAutomaticQuoteSubstitutionEnabled(!TextChecker::state().isAutomaticQuoteSubstitutionEnabled);
2100         process()->updateTextCheckerState();
2101         return;
2102     }
2103     if (item.action() == ContextMenuItemTagSmartDashes) {
2104         TextChecker::setAutomaticDashSubstitutionEnabled(!TextChecker::state().isAutomaticDashSubstitutionEnabled);
2105         process()->updateTextCheckerState();
2106         return;
2107     }
2108     if (item.action() == ContextMenuItemTagSmartLinks) {
2109         TextChecker::setAutomaticLinkDetectionEnabled(!TextChecker::state().isAutomaticLinkDetectionEnabled);
2110         process()->updateTextCheckerState();
2111         return;
2112     }
2113     if (item.action() == ContextMenuItemTagTextReplacement) {
2114         TextChecker::setAutomaticTextReplacementEnabled(!TextChecker::state().isAutomaticTextReplacementEnabled);
2115         process()->updateTextCheckerState();
2116         return;
2117     }
2118 #endif
2119     if (item.action() == ContextMenuItemTagDownloadImageToDisk) {
2120         m_context->download(this, KURL(KURL(), m_activeContextMenuState.absoluteImageURLString));
2121         return;    
2122     }
2123     if (item.action() == ContextMenuItemTagDownloadLinkToDisk) {
2124         m_context->download(this, KURL(KURL(), m_activeContextMenuState.absoluteLinkURLString));
2125         return;
2126     }
2127     
2128     if (item.action() == ContextMenuItemTagLearnSpelling || item.action() == ContextMenuItemTagIgnoreSpelling)
2129         ++m_pendingLearnOrIgnoreWordMessageCount;
2130
2131     process()->send(Messages::WebPage::DidSelectItemFromActiveContextMenu(item), m_pageID);
2132 }
2133
2134 void WebPageProxy::didChooseFilesForOpenPanel(const Vector<String>& fileURLs)
2135 {
2136     if (!isValid())
2137         return;
2138
2139 #if ENABLE(WEB_PROCESS_SANDBOX)
2140     // FIXME: The sandbox extensions should be sent with the DidChooseFilesForOpenPanel message. This
2141     // is gated on a way of passing SandboxExtension::Handles in a Vector.
2142     for (size_t i = 0; i < fileURLs.size(); ++i) {
2143         SandboxExtension::Handle sandboxExtensionHandle;
2144         SandboxExtension::createHandle(fileURLs[i], SandboxExtension::ReadOnly, sandboxExtensionHandle);
2145         process()->send(Messages::WebPage::ExtendSandboxForFileFromOpenPanel(sandboxExtensionHandle), m_pageID);
2146     }
2147 #endif
2148
2149     process()->send(Messages::WebPage::DidChooseFilesForOpenPanel(fileURLs), m_pageID);
2150
2151     m_openPanelResultListener->invalidate();
2152     m_openPanelResultListener = 0;
2153 }
2154
2155 void WebPageProxy::didCancelForOpenPanel()
2156 {
2157     if (!isValid())
2158         return;
2159
2160     process()->send(Messages::WebPage::DidCancelForOpenPanel(), m_pageID);
2161     
2162     m_openPanelResultListener->invalidate();
2163     m_openPanelResultListener = 0;
2164 }
2165
2166 void WebPageProxy::advanceToNextMisspelling(bool startBeforeSelection)
2167 {
2168     process()->send(Messages::WebPage::AdvanceToNextMisspelling(startBeforeSelection), m_pageID);
2169 }
2170
2171 void WebPageProxy::changeSpellingToWord(const String& word)
2172 {
2173     if (word.isEmpty())
2174         return;
2175
2176     process()->send(Messages::WebPage::ChangeSpellingToWord(word), m_pageID);
2177 }
2178
2179 void WebPageProxy::unmarkAllMisspellings()
2180 {
2181     process()->send(Messages::WebPage::UnmarkAllMisspellings(), m_pageID);
2182 }
2183
2184 void WebPageProxy::unmarkAllBadGrammar()
2185 {
2186     process()->send(Messages::WebPage::UnmarkAllBadGrammar(), m_pageID);
2187 }
2188
2189 #if PLATFORM(MAC)
2190 void WebPageProxy::uppercaseWord()
2191 {
2192     process()->send(Messages::WebPage::UppercaseWord(), m_pageID);
2193 }
2194
2195 void WebPageProxy::lowercaseWord()
2196 {
2197     process()->send(Messages::WebPage::LowercaseWord(), m_pageID);
2198 }
2199
2200 void WebPageProxy::capitalizeWord()
2201 {
2202     process()->send(Messages::WebPage::CapitalizeWord(), m_pageID);
2203 }
2204
2205 void WebPageProxy::setSmartInsertDeleteEnabled(bool isSmartInsertDeleteEnabled)
2206
2207     if (m_isSmartInsertDeleteEnabled == isSmartInsertDeleteEnabled)
2208         return;
2209
2210     TextChecker::setSmartInsertDeleteEnabled(isSmartInsertDeleteEnabled);
2211     m_isSmartInsertDeleteEnabled = isSmartInsertDeleteEnabled;
2212     process()->send(Messages::WebPage::SetSmartInsertDeleteEnabled(isSmartInsertDeleteEnabled), m_pageID);
2213 }
2214 #endif
2215
2216 void WebPageProxy::registerEditCommand(PassRefPtr<WebEditCommandProxy> commandProxy, UndoOrRedo undoOrRedo)
2217 {
2218     m_pageClient->registerEditCommand(commandProxy, undoOrRedo);
2219 }
2220
2221 void WebPageProxy::addEditCommand(WebEditCommandProxy* command)
2222 {
2223     m_editCommandSet.add(command);
2224 }
2225
2226 void WebPageProxy::removeEditCommand(WebEditCommandProxy* command)
2227 {
2228     m_editCommandSet.remove(command);
2229
2230     if (!isValid())
2231         return;
2232     process()->send(Messages::WebPage::DidRemoveEditCommand(command->commandID()), m_pageID);
2233 }
2234
2235 int64_t WebPageProxy::spellDocumentTag()
2236 {
2237     if (!m_hasSpellDocumentTag) {
2238         m_spellDocumentTag = TextChecker::uniqueSpellDocumentTag();
2239         m_hasSpellDocumentTag = true;
2240     }
2241
2242     return m_spellDocumentTag;
2243 }
2244
2245 void WebPageProxy::checkTextOfParagraph(const String& text, uint64_t checkingTypes, Vector<TextCheckingResult>& results)
2246 {
2247     results = TextChecker::checkTextOfParagraph(spellDocumentTag(), text.characters(), text.length(), checkingTypes);
2248 }
2249
2250 void WebPageProxy::updateSpellingUIWithMisspelledWord(const String& misspelledWord)
2251 {
2252     TextChecker::updateSpellingUIWithMisspelledWord(misspelledWord);
2253 }
2254
2255 void WebPageProxy::getGuessesForWord(const String& word, const String& context, Vector<String>& guesses)
2256 {
2257     TextChecker::getGuessesForWord(spellDocumentTag(), word, context, guesses);
2258 }
2259
2260 void WebPageProxy::learnWord(const String& word)
2261 {
2262     MESSAGE_CHECK(m_pendingLearnOrIgnoreWordMessageCount);
2263     --m_pendingLearnOrIgnoreWordMessageCount;
2264
2265     TextChecker::learnWord(word);
2266 }
2267
2268 void WebPageProxy::ignoreWord(const String& word)
2269 {
2270     MESSAGE_CHECK(m_pendingLearnOrIgnoreWordMessageCount);
2271     --m_pendingLearnOrIgnoreWordMessageCount;
2272
2273     TextChecker::ignoreWord(spellDocumentTag(), word);
2274 }
2275
2276 // Other
2277
2278 void WebPageProxy::takeFocus(bool direction)
2279 {
2280     m_pageClient->takeFocus(direction);
2281 }
2282
2283 void WebPageProxy::setToolTip(const String& toolTip)
2284 {
2285     String oldToolTip = m_toolTip;
2286     m_toolTip = toolTip;
2287     m_pageClient->toolTipChanged(oldToolTip, m_toolTip);
2288 }
2289
2290 void WebPageProxy::setCursor(const WebCore::Cursor& cursor)
2291 {
2292     m_pageClient->setCursor(cursor);
2293 }
2294
2295 void WebPageProxy::didValidateMenuItem(const String& commandName, bool isEnabled, int32_t state)
2296 {
2297     m_pageClient->setEditCommandState(commandName, isEnabled, state);
2298 }
2299
2300 void WebPageProxy::didReceiveEvent(uint32_t opaqueType, bool handled)
2301 {
2302     WebEvent::Type type = static_cast<WebEvent::Type>(opaqueType);
2303
2304     switch (type) {
2305     case WebEvent::MouseMove:
2306         break;
2307
2308     case WebEvent::MouseDown:
2309     case WebEvent::MouseUp:
2310     case WebEvent::Wheel:
2311     case WebEvent::KeyDown:
2312     case WebEvent::KeyUp:
2313     case WebEvent::RawKeyDown:
2314     case WebEvent::Char:
2315 #if ENABLE(GESTURE_EVENTS)
2316     case WebEvent::GestureScrollBegin:
2317     case WebEvent::GestureScrollEnd:
2318 #endif
2319         process()->responsivenessTimer()->stop();
2320         break;
2321     }
2322
2323     switch (type) {
2324     case WebEvent::MouseMove:
2325         m_processingMouseMoveEvent = false;
2326         if (m_nextMouseMoveEvent) {
2327             handleMouseEvent(*m_nextMouseMoveEvent);
2328             m_nextMouseMoveEvent = nullptr;
2329         }
2330         break;
2331     case WebEvent::MouseDown:
2332     case WebEvent::MouseUp:
2333 #if ENABLE(GESTURE_EVENTS)
2334     case WebEvent::GestureScrollBegin:
2335     case WebEvent::GestureScrollEnd:
2336 #endif
2337         break;
2338
2339     case WebEvent::Wheel: {
2340         m_processingWheelEvent = false;
2341         if (m_nextWheelEvent) {
2342             handleWheelEvent(*m_nextWheelEvent);
2343             m_nextWheelEvent = nullptr;
2344         }
2345         break;
2346     }
2347
2348     case WebEvent::KeyDown:
2349     case WebEvent::KeyUp:
2350     case WebEvent::RawKeyDown:
2351     case WebEvent::Char: {
2352         NativeWebKeyboardEvent event = m_keyEventQueue.first();
2353         MESSAGE_CHECK(type == event.type());
2354
2355         m_keyEventQueue.removeFirst();
2356
2357         m_pageClient->doneWithKeyEvent(event, handled);
2358
2359         if (handled)
2360             break;
2361
2362         m_uiClient.didNotHandleKeyEvent(this, event);
2363         break;
2364     }
2365     }
2366 }
2367
2368 void WebPageProxy::voidCallback(uint64_t callbackID)
2369 {
2370     RefPtr<VoidCallback> callback = m_voidCallbacks.take(callbackID);
2371     if (!callback) {
2372         // FIXME: Log error or assert.
2373         return;
2374     }
2375
2376     callback->performCallback();
2377 }
2378
2379 void WebPageProxy::dataCallback(const CoreIPC::DataReference& dataReference, uint64_t callbackID)
2380 {
2381     RefPtr<DataCallback> callback = m_dataCallbacks.take(callbackID);
2382     if (!callback) {
2383         // FIXME: Log error or assert.
2384         return;
2385     }
2386
2387     callback->performCallbackWithReturnValue(WebData::create(dataReference.data(), dataReference.size()).get());
2388 }
2389
2390 void WebPageProxy::stringCallback(const String& resultString, uint64_t callbackID)
2391 {
2392     RefPtr<StringCallback> callback = m_stringCallbacks.take(callbackID);
2393     if (!callback) {
2394         // FIXME: Log error or assert.
2395         return;
2396     }
2397
2398     callback->performCallbackWithReturnValue(resultString.impl());
2399 }
2400
2401 void WebPageProxy::computedPagesCallback(const Vector<WebCore::IntRect>& pageRects, double totalScaleFactorForPrinting, uint64_t callbackID)
2402 {
2403     RefPtr<ComputedPagesCallback> callback = m_computedPagesCallbacks.take(callbackID);
2404     if (!callback) {
2405         // FIXME: Log error or assert.
2406         return;
2407     }
2408
2409     callback->performCallbackWithReturnValue(pageRects, totalScaleFactorForPrinting);
2410 }
2411
2412 #if PLATFORM(MAC)
2413     
2414 void WebPageProxy::registerWebProcessAccessibilityToken(const CoreIPC::DataReference& data)
2415 {
2416     m_pageClient->accessibilityWebProcessTokenReceived(data);
2417 }    
2418     
2419 void WebPageProxy::registerUIProcessAccessibilityTokens(const CoreIPC::DataReference& elementToken, const CoreIPC::DataReference& windowToken)
2420 {
2421     if (!isValid())
2422         return;
2423
2424     process()->send(Messages::WebPage::RegisterUIProcessAccessibilityTokens(elementToken, windowToken), m_pageID);
2425 }
2426 #endif
2427
2428 void WebPageProxy::focusedFrameChanged(uint64_t frameID)
2429 {
2430     if (!frameID) {
2431         m_focusedFrame = 0;
2432         return;
2433     }
2434
2435     WebFrameProxy* frame = process()->webFrame(frameID);
2436     MESSAGE_CHECK(frame);
2437
2438     m_focusedFrame = frame;
2439 }
2440
2441 void WebPageProxy::frameSetLargestFrameChanged(uint64_t frameID)
2442 {
2443     if (!frameID) {
2444         m_frameSetLargestFrame = 0;
2445         return;
2446     }
2447
2448     WebFrameProxy* frame = process()->webFrame(frameID);
2449     MESSAGE_CHECK(frame);
2450
2451     m_frameSetLargestFrame = frame;
2452 }
2453
2454 #if USE(ACCELERATED_COMPOSITING)
2455 void WebPageProxy::didChangeAcceleratedCompositing(bool compositing, DrawingAreaInfo& drawingAreaInfo)
2456 {
2457     if (compositing)
2458         didEnterAcceleratedCompositing();
2459     else
2460         didLeaveAcceleratedCompositing();
2461
2462     drawingAreaInfo = drawingArea()->info();
2463 }
2464 #endif
2465
2466 void WebPageProxy::processDidBecomeUnresponsive()
2467 {
2468     m_loaderClient.processDidBecomeUnresponsive(this);
2469 }
2470
2471 void WebPageProxy::processDidBecomeResponsive()
2472 {
2473     m_loaderClient.processDidBecomeResponsive(this);
2474 }
2475
2476 void WebPageProxy::processDidCrash()
2477 {
2478     ASSERT(m_pageClient);
2479
2480     m_isValid = false;
2481
2482     if (m_mainFrame)
2483         m_urlAtProcessExit = m_mainFrame->url();
2484
2485     m_mainFrame = 0;
2486
2487     m_drawingArea = nullptr;
2488
2489 #if ENABLE(INSPECTOR)
2490     if (m_inspector) {
2491         m_inspector->invalidate();
2492         m_inspector = 0;
2493     }
2494 #endif
2495
2496     if (m_openPanelResultListener) {
2497         m_openPanelResultListener->invalidate();
2498         m_openPanelResultListener = 0;
2499     }
2500
2501     m_geolocationPermissionRequestManager.invalidateRequests();
2502
2503     m_toolTip = String();
2504
2505     m_mainFrameHasHorizontalScrollbar = false;
2506     m_mainFrameHasVerticalScrollbar = false;
2507
2508     invalidateCallbackMap(m_voidCallbacks);
2509     invalidateCallbackMap(m_dataCallbacks);
2510     invalidateCallbackMap(m_stringCallbacks);
2511     invalidateCallbackMap(m_computedPagesCallbacks);
2512
2513     Vector<WebEditCommandProxy*> editCommandVector;
2514     copyToVector(m_editCommandSet, editCommandVector);
2515     m_editCommandSet.clear();
2516     for (size_t i = 0, size = editCommandVector.size(); i < size; ++i)
2517         editCommandVector[i]->invalidate();
2518     m_pageClient->clearAllEditCommands();
2519
2520     m_activePopupMenu = 0;
2521
2522     m_estimatedProgress = 0.0;
2523
2524     m_pendingLearnOrIgnoreWordMessageCount = 0;
2525
2526     m_pageClient->processDidCrash();
2527     m_loaderClient.processDidCrash(this);
2528 }
2529
2530 WebPageCreationParameters WebPageProxy::creationParameters() const
2531 {
2532     WebPageCreationParameters parameters;
2533
2534     parameters.viewSize = m_pageClient->viewSize();
2535     parameters.isActive = m_pageClient->isViewWindowActive();
2536     parameters.isFocused = m_pageClient->isViewFocused();
2537     parameters.isVisible = m_pageClient->isViewVisible();
2538     parameters.isInWindow = m_pageClient->isViewInWindow();
2539     parameters.drawingAreaInfo = m_drawingArea->info();
2540     parameters.store = m_pageGroup->preferences()->store();
2541     parameters.pageGroupData = m_pageGroup->data();
2542     parameters.drawsBackground = m_drawsBackground;
2543     parameters.drawsTransparentBackground = m_drawsTransparentBackground;
2544     parameters.useFixedLayout = m_useFixedLayout;
2545     parameters.fixedLayoutSize = m_fixedLayoutSize;
2546     parameters.userAgent = userAgent();
2547     parameters.sessionState = SessionState(m_backForwardList->entries(), m_backForwardList->currentIndex());
2548     parameters.highestUsedBackForwardItemID = WebBackForwardListItem::highedUsedItemID();
2549     parameters.canRunModal = m_uiClient.canRunModal();
2550
2551 #if PLATFORM(MAC)
2552     parameters.isSmartInsertDeleteEnabled = m_isSmartInsertDeleteEnabled;
2553 #endif
2554
2555 #if PLATFORM(WIN)
2556     parameters.nativeWindow = m_pageClient->nativeWindow();
2557 #endif
2558
2559     return parameters;
2560 }
2561
2562 #if USE(ACCELERATED_COMPOSITING)
2563 void WebPageProxy::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
2564 {
2565     m_pageClient->enterAcceleratedCompositingMode(layerTreeContext);
2566 }
2567
2568 void WebPageProxy::exitAcceleratedCompositingMode()
2569 {
2570     m_pageClient->exitAcceleratedCompositingMode();
2571 }
2572
2573 void WebPageProxy::didEnterAcceleratedCompositing()
2574 {
2575     m_pageClient->pageDidEnterAcceleratedCompositing();
2576 }
2577
2578 void WebPageProxy::didLeaveAcceleratedCompositing()
2579 {
2580     m_pageClient->pageDidLeaveAcceleratedCompositing();
2581 }
2582
2583 #endif // USE(ACCELERATED_COMPOSITING)
2584
2585 void WebPageProxy::backForwardClear()
2586 {
2587     m_backForwardList->clear();
2588 }
2589
2590 void WebPageProxy::canAuthenticateAgainstProtectionSpaceInFrame(uint64_t frameID, const WebCore::ProtectionSpace& coreProtectionSpace, bool& canAuthenticate)
2591 {
2592     WebFrameProxy* frame = process()->webFrame(frameID);
2593     MESSAGE_CHECK(frame);
2594
2595     RefPtr<WebProtectionSpace> protectionSpace = WebProtectionSpace::create(coreProtectionSpace);
2596     
2597     canAuthenticate = m_loaderClient.canAuthenticateAgainstProtectionSpaceInFrame(this, frame, protectionSpace.get());
2598 }
2599
2600 void WebPageProxy::didReceiveAuthenticationChallenge(uint64_t frameID, const WebCore::AuthenticationChallenge& coreChallenge, uint64_t challengeID)
2601 {
2602     WebFrameProxy* frame = process()->webFrame(frameID);
2603     MESSAGE_CHECK(frame);
2604
2605     RefPtr<AuthenticationChallengeProxy> authenticationChallenge = AuthenticationChallengeProxy::create(coreChallenge, challengeID, this);
2606     
2607     m_loaderClient.didReceiveAuthenticationChallengeInFrame(this, frame, authenticationChallenge.get());
2608 }
2609
2610 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)
2611 {
2612     WebFrameProxy* frame = process()->webFrame(frameID);
2613     MESSAGE_CHECK(frame);
2614
2615     RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::create(originIdentifier);
2616
2617     newQuota = m_uiClient.exceededDatabaseQuota(this, frame, origin.get(), databaseName, displayName, currentQuota, currentUsage, expectedUsage);
2618 }
2619
2620 void WebPageProxy::requestGeolocationPermissionForFrame(uint64_t geolocationID, uint64_t frameID, String originIdentifier)
2621 {
2622     WebFrameProxy* frame = process()->webFrame(frameID);
2623     MESSAGE_CHECK(frame);
2624
2625     RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::create(originIdentifier);
2626     RefPtr<GeolocationPermissionRequestProxy> request = m_geolocationPermissionRequestManager.createRequest(geolocationID);
2627
2628     if (!m_uiClient.decidePolicyForGeolocationPermissionRequest(this, frame, origin.get(), request.get()))
2629         request->deny();
2630 }
2631
2632 float WebPageProxy::headerHeight(WebFrameProxy* frame)
2633 {
2634     return m_uiClient.headerHeight(this, frame);
2635 }
2636
2637 float WebPageProxy::footerHeight(WebFrameProxy* frame)
2638 {
2639     return m_uiClient.footerHeight(this, frame);
2640 }
2641
2642 void WebPageProxy::drawHeader(WebFrameProxy* frame, const FloatRect& rect)
2643 {
2644     m_uiClient.drawHeader(this, frame, rect);
2645 }
2646
2647 void WebPageProxy::drawFooter(WebFrameProxy* frame, const FloatRect& rect)
2648 {
2649     m_uiClient.drawFooter(this, frame, rect);
2650 }
2651
2652 void WebPageProxy::didCompleteRubberBandForMainFrame(const IntSize& initialOverhang)
2653 {
2654     m_uiClient.didCompleteRubberBandForMainFrame(this, initialOverhang);
2655 }
2656
2657 void WebPageProxy::didChangeScrollbarsForMainFrame(bool hasHorizontalScrollbar, bool hasVerticalScrollbar)
2658 {
2659     m_mainFrameHasHorizontalScrollbar = hasHorizontalScrollbar;
2660     m_mainFrameHasVerticalScrollbar = hasVerticalScrollbar;
2661
2662     m_pageClient->didChangeScrollbarsForMainFrame();
2663 }
2664
2665 void WebPageProxy::didFinishLoadingDataForCustomRepresentation(const CoreIPC::DataReference& dataReference)
2666 {
2667     m_pageClient->didFinishLoadingDataForCustomRepresentation(dataReference);
2668 }
2669
2670 #if PLATFORM(MAC)
2671 void WebPageProxy::setComplexTextInputEnabled(uint64_t pluginComplexTextInputIdentifier, bool complexTextInputEnabled)
2672 {
2673     m_pageClient->setComplexTextInputEnabled(pluginComplexTextInputIdentifier, complexTextInputEnabled);
2674 }
2675
2676 void WebPageProxy::setAutodisplay(bool newState)
2677 {
2678     m_pageClient->setAutodisplay(newState);
2679 }
2680 #endif
2681
2682 void WebPageProxy::backForwardRemovedItem(uint64_t itemID)
2683 {
2684     process()->send(Messages::WebPage::DidRemoveBackForwardItem(itemID), m_pageID);
2685 }
2686
2687 void WebPageProxy::beginPrinting(WebFrameProxy* frame, const PrintInfo& printInfo)
2688 {
2689     if (m_isInPrintingMode)
2690         return;
2691
2692     m_isInPrintingMode = true;
2693     process()->send(Messages::WebPage::BeginPrinting(frame->frameID(), printInfo), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
2694 }
2695
2696 void WebPageProxy::endPrinting()
2697 {
2698     if (!m_isInPrintingMode)
2699         return;
2700
2701     m_isInPrintingMode = false;
2702     process()->send(Messages::WebPage::EndPrinting(), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
2703 }
2704
2705 void WebPageProxy::computePagesForPrinting(WebFrameProxy* frame, const PrintInfo& printInfo, PassRefPtr<ComputedPagesCallback> callback)
2706 {
2707     uint64_t callbackID = callback->callbackID();
2708     m_computedPagesCallbacks.set(callbackID, callback.get());
2709     m_isInPrintingMode = true;
2710     process()->send(Messages::WebPage::ComputePagesForPrinting(frame->frameID(), printInfo, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
2711 }
2712
2713 #if PLATFORM(MAC)
2714 void WebPageProxy::drawRectToPDF(WebFrameProxy* frame, const IntRect& rect, PassRefPtr<DataCallback> callback)
2715 {
2716     uint64_t callbackID = callback->callbackID();
2717     m_dataCallbacks.set(callbackID, callback.get());
2718     process()->send(Messages::WebPage::DrawRectToPDF(frame->frameID(), rect, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
2719 }
2720
2721 void WebPageProxy::drawPagesToPDF(WebFrameProxy* frame, uint32_t first, uint32_t count, PassRefPtr<DataCallback> callback)
2722 {
2723     uint64_t callbackID = callback->callbackID();
2724     m_dataCallbacks.set(callbackID, callback.get());
2725     process()->send(Messages::WebPage::DrawPagesToPDF(frame->frameID(), first, count, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
2726 }
2727 #endif
2728
2729 } // namespace WebKit