WK2: Support Accessibility
[WebKit-https.git] / WebKit2 / UIProcess / WebPageProxy.cpp
1 /*
2  * Copyright (C) 2010 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 "WebPageProxy.h"
27
28 #include "AuthenticationChallengeProxy.h"
29 #include "AuthenticationDecisionListener.h"
30 #include "DataReference.h"
31 #include "DrawingAreaProxy.h"
32 #include "FindIndicator.h"
33 #include "MessageID.h"
34 #include "NativeWebKeyboardEvent.h"
35 #include "PageClient.h"
36 #include "StringPairVector.h"
37 #include "WKContextPrivate.h"
38 #include "WebBackForwardList.h"
39 #include "WebBackForwardListItem.h"
40 #include "WebCertificateInfo.h"
41 #include "WebContext.h"
42 #include "WebContextMenuProxy.h"
43 #include "WebContextUserMessageCoders.h"
44 #include "WebCoreArgumentCoders.h"
45 #include "WebData.h"
46 #include "WebEditCommandProxy.h"
47 #include "WebEvent.h"
48 #include "WebFormSubmissionListenerProxy.h"
49 #include "WebFramePolicyListenerProxy.h"
50 #include "WebOpenPanelResultListenerProxy.h"
51 #include "WebPageCreationParameters.h"
52 #include "WebPageGroup.h"
53 #include "WebPageGroupData.h"
54 #include "WebPageMessages.h"
55 #include "WebPopupItem.h"
56 #include "WebPopupMenuProxy.h"
57 #include "WebPreferences.h"
58 #include "WebProcessManager.h"
59 #include "WebProcessMessages.h"
60 #include "WebProcessProxy.h"
61 #include "WebProtectionSpace.h"
62 #include "WebSecurityOrigin.h"
63 #include "WebURLRequest.h"
64 #include <WebCore/FloatRect.h>
65 #include <WebCore/MIMETypeRegistry.h>
66 #include <WebCore/WindowFeatures.h>
67 #include <stdio.h>
68
69 #ifndef NDEBUG
70 #include <wtf/RefCountedLeakCounter.h>
71 #endif
72
73 // This controls what strategy we use for mouse wheel coalesing.
74 #define MERGE_WHEEL_EVENTS 0
75
76 #define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, process()->connection())
77
78 using namespace WebCore;
79
80 namespace WebKit {
81
82 #ifndef NDEBUG
83 static WTF::RefCountedLeakCounter webPageProxyCounter("WebPageProxy");
84 #endif
85
86 PassRefPtr<WebPageProxy> WebPageProxy::create(WebContext* context, WebPageGroup* pageGroup, uint64_t pageID)
87 {
88     return adoptRef(new WebPageProxy(context, pageGroup, pageID));
89 }
90
91 WebPageProxy::WebPageProxy(WebContext* context, WebPageGroup* pageGroup, uint64_t pageID)
92     : m_pageClient(0)
93     , m_context(context)
94     , m_pageGroup(pageGroup)
95     , m_mainFrame(0)
96     , m_userAgent(standardUserAgent())
97     , m_estimatedProgress(0.0)
98     , m_isInWindow(false)
99     , m_backForwardList(WebBackForwardList::create(this))
100     , m_textZoomFactor(1)
101     , m_pageZoomFactor(1)
102     , m_viewScaleFactor(1)
103     , m_drawsBackground(true)
104     , m_drawsTransparentBackground(false)
105     , m_isValid(true)
106     , m_isClosed(false)
107     , m_inDecidePolicyForMIMEType(false)
108     , m_syncMimeTypePolicyActionIsValid(false)
109     , m_syncMimeTypePolicyAction(PolicyUse)
110     , m_syncMimeTypePolicyDownloadID(0)
111     , m_processingWheelEvent(false)
112     , m_processingMouseMoveEvent(false)
113     , m_pageID(pageID)
114     , m_mainFrameHasCustomRepresentation(false)
115 {
116 #ifndef NDEBUG
117     webPageProxyCounter.increment();
118 #endif
119
120     WebContext::statistics().wkPageCount++;
121
122     m_pageGroup->addPage(this);
123 }
124
125 WebPageProxy::~WebPageProxy()
126 {
127     WebContext::statistics().wkPageCount--;
128
129     m_pageGroup->removePage(this);
130
131 #ifndef NDEBUG
132     webPageProxyCounter.decrement();
133 #endif
134 }
135
136 WebProcessProxy* WebPageProxy::process() const
137 {
138     return m_context->process();
139 }
140
141 bool WebPageProxy::isValid()
142 {
143     // A page that has been explicitly closed is never valid.
144     if (m_isClosed)
145         return false;
146
147     return m_isValid;
148 }
149
150 void WebPageProxy::setPageClient(PageClient* pageClient)
151 {
152     m_pageClient = pageClient;
153 }
154
155 void WebPageProxy::setDrawingArea(PassOwnPtr<DrawingAreaProxy> drawingArea)
156 {
157     if (drawingArea == m_drawingArea)
158         return;
159
160     m_drawingArea = drawingArea;
161 }
162
163 void WebPageProxy::initializeLoaderClient(const WKPageLoaderClient* loadClient)
164 {
165     m_loaderClient.initialize(loadClient);
166 }
167
168 void WebPageProxy::initializePolicyClient(const WKPagePolicyClient* policyClient)
169 {
170     m_policyClient.initialize(policyClient);
171 }
172
173 void WebPageProxy::initializeFormClient(const WKPageFormClient* formClient)
174 {
175     m_formClient.initialize(formClient);
176 }
177
178 void WebPageProxy::initializeResourceLoadClient(const WKPageResourceLoadClient* client)
179 {
180     m_resourceLoadClient.initialize(client);
181 }
182
183 void WebPageProxy::initializeUIClient(const WKPageUIClient* client)
184 {
185     m_uiClient.initialize(client);
186 }
187
188 void WebPageProxy::initializeFindClient(const WKPageFindClient* client)
189 {
190     m_findClient.initialize(client);
191 }
192
193 void WebPageProxy::initializeContextMenuClient(const WKPageContextMenuClient* client)
194 {
195     m_contextMenuClient.initialize(client);
196 }
197
198 void WebPageProxy::relaunch()
199 {
200     m_isValid = true;
201     context()->relaunchProcessIfNecessary();
202     process()->addExistingWebPage(this, m_pageID);
203
204     m_pageClient->didRelaunchProcess();
205 }
206
207 void WebPageProxy::initializeWebPage(const IntSize& size)
208 {
209     if (!isValid()) {
210         relaunch();
211         return;
212     }
213
214     ASSERT(m_drawingArea);
215     process()->send(Messages::WebProcess::CreateWebPage(m_pageID, creationParameters(size)), 0);
216 }
217
218 void WebPageProxy::reinitializeWebPage(const WebCore::IntSize& size)
219 {
220     if (!isValid())
221         return;
222
223     ASSERT(m_drawingArea);
224     process()->send(Messages::WebProcess::CreateWebPage(m_pageID, creationParameters(size)), 0);
225 }
226
227 void WebPageProxy::close()
228 {
229     if (!isValid())
230         return;
231
232     m_isClosed = true;
233
234     process()->disconnectFramesFromPage(this);
235     m_mainFrame = 0;
236
237 #if ENABLE(INSPECTOR)
238     if (m_inspector) {
239         m_inspector->invalidate();
240         m_inspector = 0;
241     }
242 #endif
243
244     if (m_openPanelResultListener) {
245         m_openPanelResultListener->invalidate();
246         m_openPanelResultListener = 0;
247     }
248
249     m_toolTip = String();
250
251     invalidateCallbackMap(m_dataCallbacks);
252     invalidateCallbackMap(m_stringCallbacks);
253
254     Vector<WebEditCommandProxy*> editCommandVector;
255     copyToVector(m_editCommandSet, editCommandVector);
256     m_editCommandSet.clear();
257     for (size_t i = 0, size = editCommandVector.size(); i < size; ++i)
258         editCommandVector[i]->invalidate();
259
260     m_activePopupMenu = 0;
261
262     m_estimatedProgress = 0.0;
263     
264     m_loaderClient.initialize(0);
265     m_policyClient.initialize(0);
266     m_uiClient.initialize(0);
267
268     m_drawingArea.clear();
269
270     process()->send(Messages::WebPage::Close(), m_pageID);
271     process()->removeWebPage(m_pageID);
272 }
273
274 bool WebPageProxy::tryClose()
275 {
276     if (!isValid())
277         return true;
278
279     process()->send(Messages::WebPage::TryClose(), m_pageID);
280     return false;
281 }
282
283 static void initializeSandboxExtensionHandle(const KURL& url, SandboxExtension::Handle& sandboxExtensionHandle)
284 {
285     if (!url.isLocalFile())
286         return;
287
288     SandboxExtension::createHandle("/", SandboxExtension::ReadOnly, sandboxExtensionHandle);
289 }
290
291 void WebPageProxy::loadURL(const String& url)
292 {
293     if (!isValid())
294         relaunch();
295
296     SandboxExtension::Handle sandboxExtensionHandle;
297     initializeSandboxExtensionHandle(KURL(KURL(), url), sandboxExtensionHandle);
298     process()->send(Messages::WebPage::LoadURL(url, sandboxExtensionHandle), m_pageID);
299 }
300
301 void WebPageProxy::loadURLRequest(WebURLRequest* urlRequest)
302 {
303     if (!isValid())
304         relaunch();
305
306     SandboxExtension::Handle sandboxExtensionHandle;
307     initializeSandboxExtensionHandle(urlRequest->resourceRequest().url(), sandboxExtensionHandle);
308     process()->send(Messages::WebPage::LoadURLRequest(urlRequest->resourceRequest(), sandboxExtensionHandle), m_pageID);
309 }
310
311 void WebPageProxy::loadHTMLString(const String& htmlString, const String& baseURL)
312 {
313     if (!isValid())
314         return;
315     process()->send(Messages::WebPage::LoadHTMLString(htmlString, baseURL), m_pageID);
316 }
317
318 void WebPageProxy::loadAlternateHTMLString(const String& htmlString, const String& baseURL, const String& unreachableURL)
319 {
320     if (!isValid())
321         return;
322
323     if (!m_mainFrame)
324         return;
325
326     m_mainFrame->setUnreachableURL(unreachableURL);
327     process()->send(Messages::WebPage::LoadAlternateHTMLString(htmlString, baseURL, unreachableURL), m_pageID);
328 }
329
330 void WebPageProxy::loadPlainTextString(const String& string)
331 {
332     if (!isValid())
333         return;
334     process()->send(Messages::WebPage::LoadPlainTextString(string), m_pageID);
335 }
336
337 void WebPageProxy::stopLoading()
338 {
339     if (!isValid())
340         return;
341     process()->send(Messages::WebPage::StopLoading(), m_pageID);
342 }
343
344 void WebPageProxy::reload(bool reloadFromOrigin)
345 {
346     if (!isValid())
347         return;
348     process()->send(Messages::WebPage::Reload(reloadFromOrigin), m_pageID);
349 }
350
351 void WebPageProxy::goForward()
352 {
353     if (!isValid())
354         return;
355
356     if (!canGoForward())
357         return;
358
359     process()->send(Messages::WebPage::GoForward(m_backForwardList->forwardItem()->itemID()), m_pageID);
360 }
361
362 bool WebPageProxy::canGoForward() const
363 {
364     return m_backForwardList->forwardItem();
365 }
366
367 void WebPageProxy::goBack()
368 {
369     if (!isValid())
370         return;
371
372     if (!canGoBack())
373         return;
374
375     process()->send(Messages::WebPage::GoBack(m_backForwardList->backItem()->itemID()), m_pageID);
376 }
377
378 bool WebPageProxy::canGoBack() const
379 {
380     return m_backForwardList->backItem();
381 }
382
383 void WebPageProxy::goToBackForwardItem(WebBackForwardListItem* item)
384 {
385     if (!isValid())
386         return;
387
388     process()->send(Messages::WebPage::GoToBackForwardItem(item->itemID()), m_pageID);
389 }
390
391 void WebPageProxy::didChangeBackForwardList()
392 {
393     m_loaderClient.didChangeBackForwardList(this);
394 }
395
396     
397 bool WebPageProxy::canShowMIMEType(const String& mimeType) const
398 {
399     if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType))
400         return true;
401
402     if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType))
403         return true;
404     
405     String newMimeType = mimeType;
406     PluginInfoStore::Plugin plugin = context()->pluginInfoStore()->findPlugin(newMimeType, KURL());
407     if (!plugin.path.isNull())
408         return true;
409
410     return false;
411 }
412
413 void WebPageProxy::setDrawsBackground(bool drawsBackground)
414 {
415     if (m_drawsBackground == drawsBackground)
416         return;
417
418     m_drawsBackground = drawsBackground;
419
420     if (isValid())
421         process()->send(Messages::WebPage::SetDrawsBackground(drawsBackground), m_pageID);
422 }
423
424 void WebPageProxy::setDrawsTransparentBackground(bool drawsTransparentBackground)
425 {
426     if (m_drawsTransparentBackground == drawsTransparentBackground)
427         return;
428
429     m_drawsTransparentBackground = drawsTransparentBackground;
430
431     if (isValid())
432         process()->send(Messages::WebPage::SetDrawsTransparentBackground(drawsTransparentBackground), m_pageID);
433 }
434
435 void WebPageProxy::setFocused(bool isFocused)
436 {
437     if (!isValid())
438         return;
439     process()->send(Messages::WebPage::SetFocused(isFocused), m_pageID);
440 }
441
442 void WebPageProxy::setInitialFocus(bool forward)
443 {
444     if (!isValid())
445         return;
446     process()->send(Messages::WebPage::SetInitialFocus(forward), m_pageID);
447 }
448
449 void WebPageProxy::setActive(bool active)
450 {
451     if (!isValid())
452         return;
453     process()->send(Messages::WebPage::SetActive(active), m_pageID);
454 }
455
456 void WebPageProxy::setWindowResizerSize(const IntSize& windowResizerSize)
457 {
458     if (!isValid())
459         return;
460     process()->send(Messages::WebPage::SetWindowResizerSize(windowResizerSize), m_pageID);
461 }
462
463 void WebPageProxy::validateMenuItem(const String& commandName)
464 {
465     if (!isValid())
466         return;
467     process()->send(Messages::WebPage::ValidateMenuItem(commandName), m_pageID);
468 }
469     
470 void WebPageProxy::executeEditCommand(const String& commandName)
471 {
472     if (!isValid())
473         return;
474
475     process()->send(Messages::WebPage::ExecuteEditCommand(commandName), m_pageID);
476 }
477     
478 void WebPageProxy::setIsInWindow(bool isInWindow)
479 {
480     if (m_isInWindow == isInWindow)
481         return;
482     
483     m_isInWindow = isInWindow;
484     if (!isValid())
485         return;
486     process()->send(Messages::WebPage::SetIsInWindow(isInWindow), m_pageID);
487 }
488
489 #if PLATFORM(MAC)
490 void WebPageProxy::updateWindowIsVisible(bool windowIsVisible)
491 {
492     if (!isValid())
493         return;
494     process()->send(Messages::WebPage::SetWindowIsVisible(windowIsVisible), m_pageID);
495 }
496
497 void WebPageProxy::windowAndViewFramesChanged(const IntRect& windowFrameInScreenCoordinates, const IntRect& viewFrameInWindowCoordinates, const IntPoint& accessibilityViewCoordinates)
498 {
499     if (!isValid())
500         return;
501
502     process()->send(Messages::WebPage::WindowAndViewFramesChanged(windowFrameInScreenCoordinates, viewFrameInWindowCoordinates, accessibilityViewCoordinates), m_pageID);
503 }
504
505 void WebPageProxy::getMarkedRange(uint64_t& location, uint64_t& length)
506 {
507     process()->sendSync(Messages::WebPage::GetMarkedRange(), Messages::WebPage::GetMarkedRange::Reply(location, length), m_pageID);
508 }
509     
510 uint64_t WebPageProxy::characterIndexForPoint(const IntPoint point)
511 {
512     uint64_t result;
513     process()->sendSync(Messages::WebPage::CharacterIndexForPoint(point), Messages::WebPage::CharacterIndexForPoint::Reply(result), m_pageID);
514     return result;
515 }
516
517 WebCore::IntRect WebPageProxy::firstRectForCharacterRange(uint64_t location, uint64_t length)
518 {
519     IntRect resultRect;
520     process()->sendSync(Messages::WebPage::FirstRectForCharacterRange(location, length), Messages::WebPage::FirstRectForCharacterRange::Reply(resultRect), m_pageID);
521     return resultRect;
522 }
523 #elif PLATFORM(WIN)
524 WebCore::IntRect WebPageProxy::firstRectForCharacterInSelectedRange(int characterPosition)
525 {
526     IntRect resultRect;
527     process()->sendSync(Messages::WebPage::FirstRectForCharacterInSelectedRange(characterPosition), Messages::WebPage::FirstRectForCharacterInSelectedRange::Reply(resultRect), m_pageID);
528     return resultRect;
529 }
530
531 String WebPageProxy::getSelectedText()
532 {
533     String text;
534     process()->sendSync(Messages::WebPage::GetSelectedText(), Messages::WebPage::GetSelectedText::Reply(text), m_pageID);
535     return text;
536 }
537 #endif
538
539 #if ENABLE(TILED_BACKING_STORE)
540 void WebPageProxy::setActualVisibleContentRect(const IntRect& rect)
541 {
542     if (!isValid())
543         return;
544
545     process()->send(Messages::WebPage::SetActualVisibleContentRect(rect), m_pageID);
546 }
547 #endif
548
549 void WebPageProxy::handleMouseEvent(const WebMouseEvent& event)
550 {
551     if (!isValid())
552         return;
553
554     // NOTE: This does not start the responsiveness timer because mouse move should not indicate interaction.
555     if (event.type() != WebEvent::MouseMove)
556         process()->responsivenessTimer()->start();
557     else {
558         if (m_processingMouseMoveEvent) {
559             m_nextMouseMoveEvent = adoptPtr(new WebMouseEvent(event));
560             return;
561         }
562
563         m_processingMouseMoveEvent = true;
564     }
565
566     process()->send(Messages::WebPage::MouseEvent(event), m_pageID);
567 }
568
569 static PassOwnPtr<WebWheelEvent> coalesceWheelEvents(WebWheelEvent* oldNextWheelEvent, const WebWheelEvent& newWheelEvent)
570 {
571 #if MERGE_WHEEL_EVENTS
572     // Merge model: Combine wheel event deltas (and wheel ticks) into a single wheel event.
573     if (!oldNextWheelEvent)
574         return adoptPtr(new WebWheelEvent(newWheelEvent));
575
576     if (oldNextWheelEvent->position() != newWheelEvent.position() || oldNextWheelEvent->modifiers() != newWheelEvent.modifiers() || oldNextWheelEvent->granularity() != newWheelEvent.granularity())
577         return adoptPtr(new WebWheelEvent(newWheelEvent));
578
579     FloatSize mergedDelta = oldNextWheelEvent->delta() + newWheelEvent.delta();
580     FloatSize mergedWheelTicks = oldNextWheelEvent->wheelTicks() + newWheelEvent.wheelTicks();
581
582     return adoptPtr(new WebWheelEvent(WebEvent::Wheel, newWheelEvent.position(), newWheelEvent.globalPosition(), mergedDelta, mergedWheelTicks, newWheelEvent.granularity(), newWheelEvent.modifiers(), newWheelEvent.timestamp()));
583 #else
584     // Simple model: Just keep the last event, dropping all interim events.
585     return adoptPtr(new WebWheelEvent(newWheelEvent));
586 #endif
587 }
588
589 void WebPageProxy::handleWheelEvent(const WebWheelEvent& event)
590 {
591     if (!isValid())
592         return;
593
594     if (m_processingWheelEvent) {
595         m_nextWheelEvent = coalesceWheelEvents(m_nextWheelEvent.get(), event);
596         return;
597     }
598
599     process()->responsivenessTimer()->start();
600     process()->send(Messages::WebPage::WheelEvent(event), m_pageID);
601     m_processingWheelEvent = true;
602 }
603
604 void WebPageProxy::handleKeyboardEvent(const NativeWebKeyboardEvent& event)
605 {
606     if (!isValid())
607         return;
608
609     m_keyEventQueue.append(event);
610
611     process()->responsivenessTimer()->start();
612     process()->send(Messages::WebPage::KeyEvent(event), m_pageID);
613 }
614
615 #if ENABLE(TOUCH_EVENTS)
616 void WebPageProxy::handleTouchEvent(const WebTouchEvent& event)
617 {
618     if (!isValid())
619         return;
620     process()->send(Messages::WebPage::TouchEvent(event), m_pageID); 
621 }
622 #endif
623
624 void WebPageProxy::receivedPolicyDecision(PolicyAction action, WebFrameProxy* frame, uint64_t listenerID)
625 {
626     if (!isValid())
627         return;
628
629     uint64_t downloadID = 0;
630     if (action == PolicyDownload) {
631         // Create a download proxy.
632         downloadID = context()->createDownloadProxy();
633     }
634
635     // If we received a policy decision while in decidePolicyForMIMEType the decision will 
636     // be sent back to the web process by decidePolicyForMIMEType. 
637     if (m_inDecidePolicyForMIMEType) {
638         m_syncMimeTypePolicyActionIsValid = true;
639         m_syncMimeTypePolicyAction = action;
640         m_syncMimeTypePolicyDownloadID = downloadID;
641         return;
642     }
643
644     process()->send(Messages::WebPage::DidReceivePolicyDecision(frame->frameID(), listenerID, action, downloadID), m_pageID);
645 }
646
647 String WebPageProxy::pageTitle() const
648 {
649     // Return the null string if there is no main frame (e.g. nothing has been loaded in the page yet, WebProcess has
650     // crashed, page has been closed).
651     if (!m_mainFrame)
652         return String();
653
654     return m_mainFrame->title();
655 }
656
657 void WebPageProxy::setUserAgent(const String& userAgent)
658 {
659     if (m_userAgent == userAgent)
660         return;
661     m_userAgent = userAgent;
662
663     if (!isValid())
664         return;
665     process()->send(Messages::WebPage::SetUserAgent(m_userAgent), m_pageID);
666 }
667
668 void WebPageProxy::setApplicationNameForUserAgent(const String& applicationName)
669 {
670     if (m_applicationNameForUserAgent == applicationName)
671         return;
672
673     m_applicationNameForUserAgent = applicationName;
674     if (!m_customUserAgent.isEmpty())
675         return;
676
677     setUserAgent(standardUserAgent(m_applicationNameForUserAgent));
678 }
679
680 void WebPageProxy::setCustomUserAgent(const String& customUserAgent)
681 {
682     if (m_customUserAgent == customUserAgent)
683         return;
684
685     m_customUserAgent = customUserAgent;
686
687     if (m_customUserAgent.isEmpty()) {
688         setUserAgent(standardUserAgent(m_applicationNameForUserAgent));
689         return;
690     }
691
692     setUserAgent(m_customUserAgent);
693 }
694
695 bool WebPageProxy::supportsTextEncoding() const
696 {
697     return !m_mainFrameHasCustomRepresentation && m_mainFrame && !m_mainFrame->isDisplayingStandaloneImageDocument();
698 }
699
700 void WebPageProxy::setCustomTextEncodingName(const String& encodingName)
701 {
702     if (m_customTextEncodingName == encodingName)
703         return;
704     m_customTextEncodingName = encodingName;
705
706     if (!isValid())
707         return;
708     process()->send(Messages::WebPage::SetCustomTextEncodingName(encodingName), m_pageID);
709 }
710
711 void WebPageProxy::terminateProcess()
712 {
713     if (!isValid())
714         return;
715
716     process()->terminate();
717 }
718
719 #if !PLATFORM(CF) || defined(BUILDING_QT__)
720 PassRefPtr<WebData> WebPageProxy::sessionStateData(WebPageProxySessionStateFilterCallback, void* context) const
721 {
722     // FIXME: Return session state data for saving Page state.
723     return 0;
724 }
725
726 void WebPageProxy::restoreFromSessionStateData(WebData*)
727 {
728     // FIXME: Restore the Page from the passed in session state data.
729 }
730 #endif
731
732 void WebPageProxy::setTextZoomFactor(double zoomFactor)
733 {
734     if (!isValid())
735         return;
736
737     if (m_textZoomFactor == zoomFactor)
738         return;
739
740     m_textZoomFactor = zoomFactor;
741     process()->send(Messages::WebPage::SetTextZoomFactor(m_textZoomFactor), m_pageID); 
742 }
743
744 void WebPageProxy::setPageZoomFactor(double zoomFactor)
745 {
746     if (!isValid())
747         return;
748
749     if (m_pageZoomFactor == zoomFactor)
750         return;
751
752     m_pageZoomFactor = zoomFactor;
753     process()->send(Messages::WebPage::SetPageZoomFactor(m_pageZoomFactor), m_pageID); 
754 }
755
756 void WebPageProxy::setPageAndTextZoomFactors(double pageZoomFactor, double textZoomFactor)
757 {
758     if (!isValid())
759         return;
760
761     if (m_pageZoomFactor == pageZoomFactor && m_textZoomFactor == textZoomFactor)
762         return;
763
764     m_pageZoomFactor = pageZoomFactor;
765     m_textZoomFactor = textZoomFactor;
766     process()->send(Messages::WebPage::SetPageAndTextZoomFactors(m_pageZoomFactor, m_textZoomFactor), m_pageID); 
767 }
768
769 void WebPageProxy::scaleWebView(double scale, const IntPoint& origin)
770 {
771     if (!isValid())
772         return;
773
774     if (m_viewScaleFactor == scale)
775         return;
776
777     m_viewScaleFactor = scale;
778     process()->send(Messages::WebPage::ScaleWebView(scale, origin), m_pageID);
779 }
780
781 void WebPageProxy::findString(const String& string, FindOptions options, unsigned maxMatchCount)
782 {
783     process()->send(Messages::WebPage::FindString(string, options, maxMatchCount), m_pageID);
784 }
785
786 void WebPageProxy::hideFindUI()
787 {
788     process()->send(Messages::WebPage::HideFindUI(), m_pageID);
789 }
790
791 void WebPageProxy::countStringMatches(const String& string, FindOptions options, unsigned maxMatchCount)
792 {
793     process()->send(Messages::WebPage::CountStringMatches(string, options, maxMatchCount), m_pageID);
794 }
795     
796 void WebPageProxy::runJavaScriptInMainFrame(const String& script, PassRefPtr<StringCallback> prpCallback)
797 {
798     RefPtr<StringCallback> callback = prpCallback;
799     uint64_t callbackID = callback->callbackID();
800     m_stringCallbacks.set(callbackID, callback.get());
801     process()->send(Messages::WebPage::RunJavaScriptInMainFrame(script, callbackID), m_pageID);
802 }
803
804 void WebPageProxy::getRenderTreeExternalRepresentation(PassRefPtr<StringCallback> prpCallback)
805 {
806     RefPtr<StringCallback> callback = prpCallback;
807     uint64_t callbackID = callback->callbackID();
808     m_stringCallbacks.set(callbackID, callback.get());
809     process()->send(Messages::WebPage::GetRenderTreeExternalRepresentation(callbackID), m_pageID);
810 }
811
812 void WebPageProxy::getSourceForFrame(WebFrameProxy* frame, PassRefPtr<StringCallback> prpCallback)
813 {
814     RefPtr<StringCallback> callback = prpCallback;
815     uint64_t callbackID = callback->callbackID();
816     m_stringCallbacks.set(callbackID, callback.get());
817     process()->send(Messages::WebPage::GetSourceForFrame(frame->frameID(), callbackID), m_pageID);
818 }
819
820 void WebPageProxy::getContentsAsString(PassRefPtr<StringCallback> prpCallback)
821 {
822     RefPtr<StringCallback> callback = prpCallback;
823     uint64_t callbackID = callback->callbackID();
824     m_stringCallbacks.set(callbackID, callback.get());
825     process()->send(Messages::WebPage::GetContentsAsString(callbackID), m_pageID);
826 }
827
828 void WebPageProxy::getSelectionOrContentsAsString(PassRefPtr<StringCallback> prpCallback)
829 {
830     RefPtr<StringCallback> callback = prpCallback;
831     uint64_t callbackID = callback->callbackID();
832     m_stringCallbacks.set(callbackID, callback.get());
833     process()->send(Messages::WebPage::GetSelectionOrContentsAsString(callbackID), m_pageID);
834 }
835
836 void WebPageProxy::getMainResourceDataOfFrame(WebFrameProxy* frame, PassRefPtr<DataCallback> prpCallback)
837 {
838     RefPtr<DataCallback> callback = prpCallback;
839     uint64_t callbackID = callback->callbackID();
840     m_dataCallbacks.set(callbackID, callback.get());
841     process()->send(Messages::WebPage::GetMainResourceDataOfFrame(frame->frameID(), callbackID), m_pageID);
842 }
843
844 void WebPageProxy::getWebArchiveOfFrame(WebFrameProxy* frame, PassRefPtr<DataCallback> prpCallback)
845 {
846     RefPtr<DataCallback> callback = prpCallback;
847     uint64_t callbackID = callback->callbackID();
848     m_dataCallbacks.set(callbackID, callback.get());
849     process()->send(Messages::WebPage::GetWebArchiveOfFrame(frame->frameID(), callbackID), m_pageID);
850 }
851
852 void WebPageProxy::preferencesDidChange()
853 {
854     if (!isValid())
855         return;
856
857     // FIXME: It probably makes more sense to send individual preference changes.
858     // However, WebKitTestRunner depends on getting a preference change notification
859     // even if nothing changed in UI process, so that overrides get removed.
860     process()->send(Messages::WebPage::PreferencesDidChange(pageGroup()->preferences()->store()), m_pageID);
861 }
862
863 #if ENABLE(TILED_BACKING_STORE)
864 void WebPageProxy::setResizesToContentsUsingLayoutSize(const WebCore::IntSize& targetLayoutSize)
865 {
866     process()->send(Messages::WebPage::SetResizesToContentsUsingLayoutSize(targetLayoutSize), m_pageID);
867 }
868 #endif
869
870 void WebPageProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
871 {
872     if (messageID.is<CoreIPC::MessageClassDrawingAreaProxyLegacy>()) {
873         m_drawingArea->didReceiveMessage(connection, messageID, arguments);
874         return;
875     }
876
877 #if ENABLE(INSPECTOR)
878     if (messageID.is<CoreIPC::MessageClassWebInspectorProxy>()) {
879         if (WebInspectorProxy* inspector = this->inspector())
880             inspector->didReceiveWebInspectorProxyMessage(connection, messageID, arguments);
881         return;
882     }
883 #endif
884
885     didReceiveWebPageProxyMessage(connection, messageID, arguments);
886 }
887
888 void WebPageProxy::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, CoreIPC::ArgumentEncoder* reply)
889 {
890     if (messageID.is<CoreIPC::MessageClassDrawingAreaProxyLegacy>()) {
891         m_drawingArea->didReceiveSyncMessage(connection, messageID, arguments, reply);
892         return;
893     }
894
895 #if ENABLE(INSPECTOR)
896     if (messageID.is<CoreIPC::MessageClassWebInspectorProxy>()) {
897         if (WebInspectorProxy* inspector = this->inspector())
898             inspector->didReceiveSyncWebInspectorProxyMessage(connection, messageID, arguments, reply);
899         return;
900     }
901 #endif
902
903     // FIXME: Do something with reply.
904     didReceiveSyncWebPageProxyMessage(connection, messageID, arguments, reply);
905 }
906
907 #if PLATFORM(MAC)
908 void WebPageProxy::interpretKeyEvent(uint32_t type, Vector<KeypressCommand>& commandsList, uint32_t selectionStart, uint32_t selectionEnd, Vector<CompositionUnderline>& underlines)
909 {
910     m_pageClient->interceptKeyEvent(m_keyEventQueue.first(), commandsList, selectionStart, selectionEnd, underlines);
911 }
912 #endif
913
914 void WebPageProxy::didCreateMainFrame(uint64_t frameID)
915 {
916     MESSAGE_CHECK(!m_mainFrame);
917     MESSAGE_CHECK(process()->canCreateFrame(frameID));
918
919     m_mainFrame = WebFrameProxy::create(this, frameID);
920
921     // Add the frame to the process wide map.
922     process()->frameCreated(frameID, m_mainFrame.get());
923 }
924
925 void WebPageProxy::didCreateSubframe(uint64_t frameID, uint64_t parentFrameID)
926 {
927     MESSAGE_CHECK(m_mainFrame);
928
929     WebFrameProxy* parentFrame = process()->webFrame(parentFrameID);
930     MESSAGE_CHECK(parentFrame);
931     MESSAGE_CHECK(parentFrame->isDescendantOf(m_mainFrame.get()));
932
933     MESSAGE_CHECK(process()->canCreateFrame(frameID));
934     
935     RefPtr<WebFrameProxy> subFrame = WebFrameProxy::create(this, frameID);
936
937     // Add the frame to the process wide map.
938     process()->frameCreated(frameID, subFrame.get());
939
940     // Insert the frame into the frame hierarchy.
941     parentFrame->appendChild(subFrame.get());
942 }
943
944 void WebPageProxy::didSaveFrameToPageCache(uint64_t frameID)
945 {
946     MESSAGE_CHECK(m_mainFrame);
947
948     WebFrameProxy* subframe = process()->webFrame(frameID);
949     MESSAGE_CHECK(subframe);
950     MESSAGE_CHECK(subframe->isDescendantOf(m_mainFrame.get()));
951
952     subframe->didRemoveFromHierarchy();
953 }
954
955 void WebPageProxy::didRestoreFrameFromPageCache(uint64_t frameID, uint64_t parentFrameID)
956 {
957     MESSAGE_CHECK(m_mainFrame);
958
959     WebFrameProxy* subframe = process()->webFrame(frameID);
960     MESSAGE_CHECK(subframe);
961     MESSAGE_CHECK(!subframe->parentFrame());
962     MESSAGE_CHECK(subframe->page() == m_mainFrame->page());
963
964     WebFrameProxy* parentFrame = process()->webFrame(parentFrameID);
965     MESSAGE_CHECK(parentFrame);
966     MESSAGE_CHECK(parentFrame->isDescendantOf(m_mainFrame.get()));
967
968     // Insert the frame into the frame hierarchy.
969     parentFrame->appendChild(subframe);
970 }
971
972 void WebPageProxy::didStartProgress()
973 {
974     m_estimatedProgress = 0.0;
975     
976     m_loaderClient.didStartProgress(this);
977 }
978
979 void WebPageProxy::didChangeProgress(double value)
980 {
981     m_estimatedProgress = value;
982     
983     m_loaderClient.didChangeProgress(this);
984 }
985
986 void WebPageProxy::didFinishProgress()
987 {
988     m_estimatedProgress = 1.0;
989
990     m_loaderClient.didFinishProgress(this);
991 }
992
993 void WebPageProxy::didStartProvisionalLoadForFrame(uint64_t frameID, const String& url, bool loadingSubstituteDataForUnreachableURL, CoreIPC::ArgumentDecoder* arguments)
994 {
995     RefPtr<APIObject> userData;
996     WebContextUserMessageDecoder messageDecoder(userData, context());
997     if (!arguments->decode(messageDecoder))
998         return;
999
1000     WebFrameProxy* frame = process()->webFrame(frameID);
1001     MESSAGE_CHECK(frame);
1002
1003     if (!loadingSubstituteDataForUnreachableURL)
1004         frame->setUnreachableURL(String());
1005
1006     frame->didStartProvisionalLoad(url);
1007     m_loaderClient.didStartProvisionalLoadForFrame(this, frame, userData.get());
1008 }
1009
1010 void WebPageProxy::didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, const String& url, CoreIPC::ArgumentDecoder* arguments)
1011 {
1012     RefPtr<APIObject> userData;
1013     WebContextUserMessageDecoder messageDecoder(userData, context());
1014     if (!arguments->decode(messageDecoder))
1015         return;
1016
1017     WebFrameProxy* frame = process()->webFrame(frameID);
1018     MESSAGE_CHECK(frame);
1019
1020     frame->didReceiveServerRedirectForProvisionalLoad(url);
1021
1022     m_loaderClient.didReceiveServerRedirectForProvisionalLoadForFrame(this, frame, userData.get());
1023 }
1024
1025 void WebPageProxy::didFailProvisionalLoadForFrame(uint64_t frameID, const ResourceError& error, CoreIPC::ArgumentDecoder* arguments)
1026 {
1027     RefPtr<APIObject> userData;
1028     WebContextUserMessageDecoder messageDecoder(userData, context());
1029     if (!arguments->decode(messageDecoder))
1030         return;
1031
1032     WebFrameProxy* frame = process()->webFrame(frameID);
1033     MESSAGE_CHECK(frame);
1034
1035     frame->didFailProvisionalLoad();
1036
1037     m_loaderClient.didFailProvisionalLoadWithErrorForFrame(this, frame, error, userData.get());
1038 }
1039
1040 void WebPageProxy::didCommitLoadForFrame(uint64_t frameID, const String& mimeType, bool frameHasCustomRepresentation, const PlatformCertificateInfo& certificateInfo, CoreIPC::ArgumentDecoder* arguments)
1041 {
1042     RefPtr<APIObject> userData;
1043     WebContextUserMessageDecoder messageDecoder(userData, context());
1044     if (!arguments->decode(messageDecoder))
1045         return;
1046
1047     WebFrameProxy* frame = process()->webFrame(frameID);
1048     MESSAGE_CHECK(frame);
1049
1050     frame->didCommitLoad(mimeType, certificateInfo);
1051
1052     if (frame->isMainFrame()) {
1053         m_mainFrameHasCustomRepresentation = frameHasCustomRepresentation;
1054         m_pageClient->didCommitLoadForMainFrame(frameHasCustomRepresentation);
1055     }
1056
1057     m_loaderClient.didCommitLoadForFrame(this, frame, userData.get());
1058 }
1059
1060 void WebPageProxy::didFinishDocumentLoadForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1061 {
1062     RefPtr<APIObject> userData;
1063     WebContextUserMessageDecoder messageDecoder(userData, context());
1064     if (!arguments->decode(messageDecoder))
1065         return;
1066
1067     WebFrameProxy* frame = process()->webFrame(frameID);
1068     MESSAGE_CHECK(frame);
1069
1070     m_loaderClient.didFinishDocumentLoadForFrame(this, frame, userData.get());
1071 }
1072
1073 void WebPageProxy::didFinishLoadForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1074 {
1075     RefPtr<APIObject> userData;
1076     WebContextUserMessageDecoder messageDecoder(userData, context());
1077     if (!arguments->decode(messageDecoder))
1078         return;
1079
1080     WebFrameProxy* frame = process()->webFrame(frameID);
1081     MESSAGE_CHECK(frame);
1082
1083     frame->didFinishLoad();
1084
1085     m_loaderClient.didFinishLoadForFrame(this, frame, userData.get());
1086 }
1087
1088 void WebPageProxy::didFailLoadForFrame(uint64_t frameID, const ResourceError& error, CoreIPC::ArgumentDecoder* arguments)
1089 {
1090     RefPtr<APIObject> userData;
1091     WebContextUserMessageDecoder messageDecoder(userData, context());
1092     if (!arguments->decode(messageDecoder))
1093         return;
1094
1095     WebFrameProxy* frame = process()->webFrame(frameID);
1096     MESSAGE_CHECK(frame);
1097
1098     frame->didFailLoad();
1099
1100     m_loaderClient.didFailLoadWithErrorForFrame(this, frame, error, userData.get());
1101 }
1102
1103 void WebPageProxy::didSameDocumentNavigationForFrame(uint64_t frameID, uint32_t opaqueSameDocumentNavigationType, const String& url, CoreIPC::ArgumentDecoder* arguments)
1104 {
1105     RefPtr<APIObject> userData;
1106     WebContextUserMessageDecoder messageDecoder(userData, context());
1107     if (!arguments->decode(messageDecoder))
1108         return;
1109
1110     WebFrameProxy* frame = process()->webFrame(frameID);
1111     MESSAGE_CHECK(frame);
1112
1113     frame->didSameDocumentNavigation(url);
1114
1115     m_loaderClient.didSameDocumentNavigationForFrame(this, frame, static_cast<SameDocumentNavigationType>(opaqueSameDocumentNavigationType), userData.get());
1116 }
1117
1118 void WebPageProxy::didReceiveTitleForFrame(uint64_t frameID, const String& title, CoreIPC::ArgumentDecoder* arguments)
1119 {
1120     RefPtr<APIObject> userData;
1121     WebContextUserMessageDecoder messageDecoder(userData, context());
1122     if (!arguments->decode(messageDecoder))
1123         return;
1124
1125     WebFrameProxy* frame = process()->webFrame(frameID);
1126     MESSAGE_CHECK(frame);
1127
1128     frame->didChangeTitle(title);
1129     
1130     m_loaderClient.didReceiveTitleForFrame(this, title, frame, userData.get());
1131 }
1132
1133 void WebPageProxy::didFirstLayoutForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1134 {
1135     RefPtr<APIObject> userData;
1136     WebContextUserMessageDecoder messageDecoder(userData, context());
1137     if (!arguments->decode(messageDecoder))
1138         return;
1139
1140     WebFrameProxy* frame = process()->webFrame(frameID);
1141     MESSAGE_CHECK(frame);
1142
1143     m_loaderClient.didFirstLayoutForFrame(this, frame, userData.get());
1144 }
1145
1146 void WebPageProxy::didFirstVisuallyNonEmptyLayoutForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1147 {
1148     RefPtr<APIObject> userData;
1149     WebContextUserMessageDecoder messageDecoder(userData, context());
1150     if (!arguments->decode(messageDecoder))
1151         return;
1152
1153     WebFrameProxy* frame = process()->webFrame(frameID);
1154     MESSAGE_CHECK(frame);
1155
1156     m_loaderClient.didFirstVisuallyNonEmptyLayoutForFrame(this, frame, userData.get());
1157 }
1158
1159 void WebPageProxy::didRemoveFrameFromHierarchy(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1160 {
1161     RefPtr<APIObject> userData;
1162     WebContextUserMessageDecoder messageDecoder(userData, context());
1163     if (!arguments->decode(messageDecoder))
1164         return;
1165
1166     WebFrameProxy* frame = process()->webFrame(frameID);
1167     MESSAGE_CHECK(frame);
1168
1169     frame->didRemoveFromHierarchy();
1170
1171     m_loaderClient.didRemoveFrameFromHierarchy(this, frame, userData.get());
1172 }
1173
1174 void WebPageProxy::didDisplayInsecureContentForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1175 {
1176     RefPtr<APIObject> userData;
1177     WebContextUserMessageDecoder messageDecoder(userData, context());
1178     if (!arguments->decode(messageDecoder))
1179         return;
1180
1181     WebFrameProxy* frame = process()->webFrame(frameID);
1182     MESSAGE_CHECK(frame);
1183
1184     m_loaderClient.didDisplayInsecureContentForFrame(this, frame, userData.get());
1185 }
1186
1187 void WebPageProxy::didRunInsecureContentForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
1188 {
1189     RefPtr<APIObject> userData;
1190     WebContextUserMessageDecoder messageDecoder(userData, context());
1191     if (!arguments->decode(messageDecoder))
1192         return;
1193
1194     WebFrameProxy* frame = process()->webFrame(frameID);
1195     MESSAGE_CHECK(frame);
1196
1197     m_loaderClient.didRunInsecureContentForFrame(this, frame, userData.get());
1198 }
1199
1200 void WebPageProxy::didReceiveAccessibilityPageToken(const CoreIPC::DataReference& data)
1201 {
1202 #if PLATFORM(MAC)
1203     m_pageClient->accessibilityChildTokenReceived(data);
1204 #endif
1205 }
1206     
1207 void WebPageProxy::frameDidBecomeFrameSet(uint64_t frameID, bool value)
1208 {
1209     WebFrameProxy* frame = process()->webFrame(frameID);
1210     MESSAGE_CHECK(frame);
1211
1212     frame->setIsFrameSet(value);
1213 }
1214
1215 // PolicyClient
1216
1217 void WebPageProxy::decidePolicyForNavigationAction(uint64_t frameID, uint32_t opaqueNavigationType, uint32_t opaqueModifiers, int32_t opaqueMouseButton, const String& url, uint64_t listenerID)
1218 {
1219     WebFrameProxy* frame = process()->webFrame(frameID);
1220     MESSAGE_CHECK(frame);
1221
1222     NavigationType navigationType = static_cast<NavigationType>(opaqueNavigationType);
1223     WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
1224     WebMouseEvent::Button mouseButton = static_cast<WebMouseEvent::Button>(opaqueMouseButton);
1225     
1226     RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
1227     if (!m_policyClient.decidePolicyForNavigationAction(this, navigationType, modifiers, mouseButton, url, frame, listener.get()))
1228         listener->use();
1229 }
1230
1231 void WebPageProxy::decidePolicyForNewWindowAction(uint64_t frameID, uint32_t opaqueNavigationType, uint32_t opaqueModifiers, int32_t opaqueMouseButton, const String& url, uint64_t listenerID)
1232 {
1233     WebFrameProxy* frame = process()->webFrame(frameID);
1234     MESSAGE_CHECK(frame);
1235
1236     NavigationType navigationType = static_cast<NavigationType>(opaqueNavigationType);
1237     WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
1238     WebMouseEvent::Button mouseButton = static_cast<WebMouseEvent::Button>(opaqueMouseButton);
1239
1240     RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
1241     if (!m_policyClient.decidePolicyForNewWindowAction(this, navigationType, modifiers, mouseButton, url, frame, listener.get()))
1242         listener->use();
1243 }
1244
1245 void WebPageProxy::decidePolicyForMIMEType(uint64_t frameID, const String& MIMEType, const String& url, uint64_t listenerID, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID)
1246 {
1247     WebFrameProxy* frame = process()->webFrame(frameID);
1248     MESSAGE_CHECK(frame);
1249
1250     RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
1251
1252     ASSERT(!m_inDecidePolicyForMIMEType);
1253
1254     m_inDecidePolicyForMIMEType = true;
1255     m_syncMimeTypePolicyActionIsValid = false;
1256
1257     if (!m_policyClient.decidePolicyForMIMEType(this, MIMEType, url, frame, listener.get()))
1258         listener->use();
1259
1260     m_inDecidePolicyForMIMEType = false;
1261
1262     // Check if we received a policy decision already. If we did, we can just pass it back.
1263     if (m_syncMimeTypePolicyActionIsValid) {
1264         receivedPolicyAction = true;
1265         policyAction = m_syncMimeTypePolicyAction;
1266         downloadID = m_syncMimeTypePolicyDownloadID;
1267     }
1268 }
1269
1270 // FormClient
1271
1272 void WebPageProxy::willSubmitForm(uint64_t frameID, uint64_t sourceFrameID, const StringPairVector& textFieldValues, uint64_t listenerID, CoreIPC::ArgumentDecoder* arguments)
1273 {
1274     RefPtr<APIObject> userData;
1275     WebContextUserMessageDecoder messageDecoder(userData, context());
1276     if (!arguments->decode(messageDecoder))
1277         return;
1278
1279     WebFrameProxy* frame = process()->webFrame(frameID);
1280     MESSAGE_CHECK(frame);
1281
1282     WebFrameProxy* sourceFrame = process()->webFrame(sourceFrameID);
1283     MESSAGE_CHECK(sourceFrame);
1284
1285     RefPtr<WebFormSubmissionListenerProxy> listener = frame->setUpFormSubmissionListenerProxy(listenerID);
1286     if (!m_formClient.willSubmitForm(this, frame, sourceFrame, textFieldValues.stringPairVector(), userData.get(), listener.get()))
1287         listener->continueSubmission();
1288 }
1289
1290 // ResourceLoad Client
1291
1292 void WebPageProxy::didInitiateLoadForResource(uint64_t frameID, uint64_t resourceIdentifier, const ResourceRequest& request)
1293 {
1294     WebFrameProxy* frame = process()->webFrame(frameID);
1295     MESSAGE_CHECK(frame);
1296
1297     m_resourceLoadClient.didInitiateLoadForResource(this, frame, resourceIdentifier, request);
1298 }
1299
1300 void WebPageProxy::didSendRequestForResource(uint64_t frameID, uint64_t resourceIdentifier, const ResourceRequest& request, const ResourceResponse& redirectResponse)
1301 {
1302     WebFrameProxy* frame = process()->webFrame(frameID);
1303     MESSAGE_CHECK(frame);
1304
1305     m_resourceLoadClient.didSendRequestForResource(this, frame, resourceIdentifier, request, redirectResponse);
1306 }
1307
1308 void WebPageProxy::didReceiveResponseForResource(uint64_t frameID, uint64_t resourceIdentifier, const ResourceResponse& response)
1309 {
1310     WebFrameProxy* frame = process()->webFrame(frameID);
1311     MESSAGE_CHECK(frame);
1312
1313     m_resourceLoadClient.didReceiveResponseForResource(this, frame, resourceIdentifier, response);
1314 }
1315
1316 void WebPageProxy::didReceiveContentLengthForResource(uint64_t frameID, uint64_t resourceIdentifier, uint64_t contentLength)
1317 {
1318     WebFrameProxy* frame = process()->webFrame(frameID);
1319     MESSAGE_CHECK(frame);
1320
1321     m_resourceLoadClient.didReceiveContentLengthForResource(this, frame, resourceIdentifier, contentLength);
1322 }
1323
1324 void WebPageProxy::didFinishLoadForResource(uint64_t frameID, uint64_t resourceIdentifier)
1325 {
1326     WebFrameProxy* frame = process()->webFrame(frameID);
1327     MESSAGE_CHECK(frame);
1328
1329     m_resourceLoadClient.didFinishLoadForResource(this, frame, resourceIdentifier);
1330 }
1331
1332 void WebPageProxy::didFailLoadForResource(uint64_t frameID, uint64_t resourceIdentifier, const ResourceError& error)
1333 {
1334     WebFrameProxy* frame = process()->webFrame(frameID);
1335     MESSAGE_CHECK(frame);
1336
1337     m_resourceLoadClient.didFailLoadForResource(this, frame, resourceIdentifier, error);
1338 }
1339
1340 // UIClient
1341
1342 void WebPageProxy::createNewPage(const WindowFeatures& windowFeatures, uint32_t opaqueModifiers, int32_t opaqueMouseButton, uint64_t& newPageID, WebPageCreationParameters& newPageParameters)
1343 {
1344     RefPtr<WebPageProxy> newPage = m_uiClient.createNewPage(this, windowFeatures, static_cast<WebEvent::Modifiers>(opaqueModifiers), static_cast<WebMouseEvent::Button>(opaqueMouseButton));
1345     if (newPage) {
1346         newPageID = newPage->pageID();
1347         newPageParameters = newPage->creationParameters(newPage->drawingArea()->size());
1348     } else
1349         newPageID = 0;
1350 }
1351     
1352 void WebPageProxy::showPage()
1353 {
1354     m_uiClient.showPage(this);
1355 }
1356
1357 void WebPageProxy::closePage()
1358 {
1359     m_uiClient.close(this);
1360 }
1361
1362 void WebPageProxy::runJavaScriptAlert(uint64_t frameID, const String& message)
1363 {
1364     WebFrameProxy* frame = process()->webFrame(frameID);
1365     MESSAGE_CHECK(frame);
1366
1367     m_uiClient.runJavaScriptAlert(this, message, frame);
1368 }
1369
1370 void WebPageProxy::runJavaScriptConfirm(uint64_t frameID, const String& message, bool& result)
1371 {
1372     WebFrameProxy* frame = process()->webFrame(frameID);
1373     MESSAGE_CHECK(frame);
1374
1375     result = m_uiClient.runJavaScriptConfirm(this, message, frame);
1376 }
1377
1378 void WebPageProxy::runJavaScriptPrompt(uint64_t frameID, const String& message, const String& defaultValue, String& result)
1379 {
1380     WebFrameProxy* frame = process()->webFrame(frameID);
1381     MESSAGE_CHECK(frame);
1382
1383     result = m_uiClient.runJavaScriptPrompt(this, message, defaultValue, frame);
1384 }
1385
1386 void WebPageProxy::setStatusText(const String& text)
1387 {
1388     m_uiClient.setStatusText(this, text);
1389 }
1390
1391 void WebPageProxy::mouseDidMoveOverElement(uint32_t opaqueModifiers, CoreIPC::ArgumentDecoder* arguments)
1392 {
1393     RefPtr<APIObject> userData;
1394     WebContextUserMessageDecoder messageDecoder(userData, context());
1395     if (!arguments->decode(messageDecoder))
1396         return;
1397
1398     WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
1399
1400     m_uiClient.mouseDidMoveOverElement(this, modifiers, userData.get());
1401 }
1402
1403 void WebPageProxy::missingPluginButtonClicked(const String& mimeType, const String& url)
1404 {
1405     m_uiClient.missingPluginButtonClicked(this, mimeType, url);
1406 }
1407
1408 void WebPageProxy::setToolbarsAreVisible(bool toolbarsAreVisible)
1409 {
1410     m_uiClient.setToolbarsAreVisible(this, toolbarsAreVisible);
1411 }
1412
1413 void WebPageProxy::getToolbarsAreVisible(bool& toolbarsAreVisible)
1414 {
1415     toolbarsAreVisible = m_uiClient.toolbarsAreVisible(this);
1416 }
1417
1418 void WebPageProxy::setMenuBarIsVisible(bool menuBarIsVisible)
1419 {
1420     m_uiClient.setMenuBarIsVisible(this, menuBarIsVisible);
1421 }
1422
1423 void WebPageProxy::getMenuBarIsVisible(bool& menuBarIsVisible)
1424 {
1425     menuBarIsVisible = m_uiClient.menuBarIsVisible(this);
1426 }
1427
1428 void WebPageProxy::setStatusBarIsVisible(bool statusBarIsVisible)
1429 {
1430     m_uiClient.setStatusBarIsVisible(this, statusBarIsVisible);
1431 }
1432
1433 void WebPageProxy::getStatusBarIsVisible(bool& statusBarIsVisible)
1434 {
1435     statusBarIsVisible = m_uiClient.statusBarIsVisible(this);
1436 }
1437
1438 void WebPageProxy::setIsResizable(bool isResizable)
1439 {
1440     m_uiClient.setIsResizable(this, isResizable);
1441 }
1442
1443 void WebPageProxy::getIsResizable(bool& isResizable)
1444 {
1445     isResizable = m_uiClient.isResizable(this);
1446 }
1447
1448 void WebPageProxy::setWindowFrame(const FloatRect& newWindowFrame)
1449 {
1450     m_uiClient.setWindowFrame(this, m_pageClient->convertToDeviceSpace(newWindowFrame));
1451 }
1452
1453 void WebPageProxy::getWindowFrame(FloatRect& newWindowFrame)
1454 {
1455     newWindowFrame = m_pageClient->convertToUserSpace(m_uiClient.windowFrame(this));
1456 }
1457
1458 void WebPageProxy::canRunBeforeUnloadConfirmPanel(bool& canRun)
1459 {
1460     canRun = m_uiClient.canRunBeforeUnloadConfirmPanel();
1461 }
1462
1463 void WebPageProxy::runBeforeUnloadConfirmPanel(const String& message, uint64_t frameID, bool& shouldClose)
1464 {
1465     WebFrameProxy* frame = process()->webFrame(frameID);
1466     MESSAGE_CHECK(frame);
1467
1468     shouldClose = m_uiClient.runBeforeUnloadConfirmPanel(this, message, frame);
1469 }
1470
1471 #if ENABLE(TILED_BACKING_STORE)
1472 void WebPageProxy::pageDidRequestScroll(const IntSize& delta)
1473 {
1474     m_pageClient->pageDidRequestScroll(delta);
1475 }
1476 #endif
1477
1478 void WebPageProxy::didChangeViewportData(const ViewportArguments& args)
1479 {
1480     m_pageClient->setViewportArguments(args);
1481 }
1482
1483 void WebPageProxy::pageDidScroll()
1484 {
1485     m_uiClient.pageDidScroll(this);
1486 }
1487
1488 void WebPageProxy::runOpenPanel(uint64_t frameID, const WebOpenPanelParameters::Data& data)
1489 {
1490     if (m_openPanelResultListener) {
1491         m_openPanelResultListener->invalidate();
1492         m_openPanelResultListener = 0;
1493     }
1494
1495     WebFrameProxy* frame = process()->webFrame(frameID);
1496     MESSAGE_CHECK(frame);
1497
1498     m_openPanelResultListener = WebOpenPanelResultListenerProxy::create(this);
1499
1500     if (!m_uiClient.runOpenPanel(this, frame, data, m_openPanelResultListener.get()))
1501         didCancelForOpenPanel();
1502 }
1503
1504 #if PLATFORM(QT)
1505 void WebPageProxy::didChangeContentsSize(const WebCore::IntSize& size)
1506 {
1507     m_pageClient->didChangeContentsSize(size);
1508 }
1509
1510 void WebPageProxy::didFindZoomableArea(const WebCore::IntRect& area)
1511 {
1512     m_pageClient->didFindZoomableArea(area);
1513 }
1514
1515 void WebPageProxy::findZoomableAreaForPoint(const WebCore::IntPoint& point)
1516 {
1517     if (!isValid())
1518         return;
1519
1520     process()->send(Messages::WebPage::FindZoomableAreaForPoint(point), m_pageID);
1521 }
1522 #endif
1523
1524 void WebPageProxy::didDraw()
1525 {
1526     m_uiClient.didDraw(this);
1527 }
1528
1529 // Inspector
1530
1531 #if ENABLE(INSPECTOR)
1532
1533 WebInspectorProxy* WebPageProxy::inspector()
1534 {
1535     if (isClosed() || !isValid())
1536         return 0;
1537     if (!m_inspector)
1538         m_inspector = WebInspectorProxy::create(this);
1539     return m_inspector.get();
1540 }
1541
1542 #endif
1543
1544 // BackForwardList
1545
1546 void WebPageProxy::backForwardAddItem(uint64_t itemID)
1547 {
1548     m_backForwardList->addItem(process()->webBackForwardItem(itemID));
1549 }
1550
1551 void WebPageProxy::backForwardGoToItem(uint64_t itemID)
1552 {
1553     m_backForwardList->goToItem(process()->webBackForwardItem(itemID));
1554 }
1555
1556 void WebPageProxy::backForwardItemAtIndex(int32_t index, uint64_t& itemID)
1557 {
1558     WebBackForwardListItem* item = m_backForwardList->itemAtIndex(index);
1559     itemID = item ? item->itemID() : 0;
1560 }
1561
1562 void WebPageProxy::backForwardBackListCount(int32_t& count)
1563 {
1564     count = m_backForwardList->backListCount();
1565 }
1566
1567 void WebPageProxy::backForwardForwardListCount(int32_t& count)
1568 {
1569     count = m_backForwardList->forwardListCount();
1570 }
1571
1572 void WebPageProxy::selectionStateChanged(const SelectionState& selectionState)
1573 {
1574     m_selectionState = selectionState;
1575 }
1576
1577 #if PLATFORM(MAC)
1578 // Complex text input support for plug-ins.
1579 void WebPageProxy::sendComplexTextInputToPlugin(uint64_t pluginComplexTextInputIdentifier, const String& textInput)
1580 {
1581     if (!isValid())
1582         return;
1583     
1584     process()->send(Messages::WebPage::SendComplexTextInputToPlugin(pluginComplexTextInputIdentifier, textInput), m_pageID);
1585 }
1586 #endif
1587
1588 #if PLATFORM(WIN)
1589 void WebPageProxy::didChangeCompositionSelection(bool hasComposition)
1590 {
1591     m_pageClient->compositionSelectionChanged(hasComposition);
1592 }
1593
1594 void WebPageProxy::confirmComposition(const String& compositionString)
1595 {
1596     process()->send(Messages::WebPage::ConfirmComposition(compositionString), m_pageID);
1597 }
1598
1599 void WebPageProxy::setComposition(const String& compositionString, Vector<WebCore::CompositionUnderline>& underlines, int cursorPosition)
1600 {
1601     process()->send(Messages::WebPage::SetComposition(compositionString, underlines, cursorPosition), m_pageID);
1602 }
1603 #endif
1604     
1605 // Undo management
1606
1607 void WebPageProxy::registerEditCommandForUndo(uint64_t commandID, uint32_t editAction)
1608 {
1609     registerEditCommand(WebEditCommandProxy::create(commandID, static_cast<EditAction>(editAction), this), Undo);
1610 }
1611
1612 void WebPageProxy::clearAllEditCommands()
1613 {
1614     m_pageClient->clearAllEditCommands();
1615 }
1616
1617 void WebPageProxy::didCountStringMatches(const String& string, uint32_t matchCount)
1618 {
1619     m_findClient.didCountStringMatches(this, string, matchCount);
1620 }
1621
1622 void WebPageProxy::setFindIndicator(const FloatRect& selectionRect, const Vector<FloatRect>& textRects, const SharedMemory::Handle& contentImageHandle, bool fadeOut)
1623 {
1624     RefPtr<FindIndicator> findIndicator = FindIndicator::create(selectionRect, textRects, contentImageHandle);
1625     m_pageClient->setFindIndicator(findIndicator.release(), fadeOut);
1626 }
1627
1628 void WebPageProxy::didFindString(const String& string, uint32_t matchCount)
1629 {
1630     m_findClient.didFindString(this, string, matchCount);
1631 }
1632
1633 void WebPageProxy::didFailToFindString(const String& string)
1634 {
1635     m_findClient.didFailToFindString(this, string);
1636 }
1637
1638 void WebPageProxy::valueChangedForPopupMenu(WebPopupMenuProxy*, int32_t newSelectedIndex)
1639 {
1640     process()->send(Messages::WebPage::DidChangeSelectedIndexForActivePopupMenu(newSelectedIndex), m_pageID);
1641 }
1642
1643 void WebPageProxy::setTextFromItemForPopupMenu(WebPopupMenuProxy*, int32_t index)
1644 {
1645     process()->send(Messages::WebPage::SetTextForActivePopupMenu(index), m_pageID);
1646 }
1647
1648 void WebPageProxy::showPopupMenu(const IntRect& rect, const Vector<WebPopupItem>& items, int32_t selectedIndex, const PlatformPopupMenuData& data)
1649 {
1650     if (m_activePopupMenu)
1651         m_activePopupMenu->hidePopupMenu();
1652     else
1653         m_activePopupMenu = m_pageClient->createPopupMenuProxy(this);
1654
1655     m_activePopupMenu->showPopupMenu(rect, items, data, selectedIndex);
1656     m_activePopupMenu = 0;
1657 }
1658
1659 void WebPageProxy::hidePopupMenu()
1660 {
1661     if (!m_activePopupMenu)
1662         return;
1663
1664     m_activePopupMenu->hidePopupMenu();
1665     m_activePopupMenu = 0;
1666 }
1667
1668 void WebPageProxy::showContextMenu(const WebCore::IntPoint& menuLocation, const Vector<WebContextMenuItemData>& proposedItems, CoreIPC::ArgumentDecoder* arguments)
1669 {
1670     RefPtr<APIObject> userData;
1671     WebContextUserMessageDecoder messageDecoder(userData, context());
1672     if (!arguments->decode(messageDecoder))
1673         return;
1674
1675     if (m_activeContextMenu)
1676         m_activeContextMenu->hideContextMenu();
1677     else
1678         m_activeContextMenu = m_pageClient->createContextMenuProxy(this);
1679
1680     // Give the PageContextMenuClient one last swipe at changing the menu.
1681     Vector<WebContextMenuItemData> items;
1682         
1683     if (!m_contextMenuClient.getContextMenuFromProposedMenu(this, proposedItems, items, userData.get())) {
1684         m_activeContextMenu->showContextMenu(menuLocation, proposedItems);
1685         return;
1686     }
1687     
1688     if (items.size())
1689         m_activeContextMenu->showContextMenu(menuLocation, items);
1690 }
1691
1692 void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& item)
1693 {
1694     // Application custom items don't need to round-trip through to WebCore in the WebProcess.
1695     if (item.action() >= ContextMenuItemBaseApplicationTag) {
1696         m_contextMenuClient.customContextMenuItemSelected(this, item);
1697         return;
1698     }
1699     
1700     process()->send(Messages::WebPage::DidSelectItemFromActiveContextMenu(item), m_pageID);
1701 }
1702
1703 void WebPageProxy::didChooseFilesForOpenPanel(const Vector<String>& fileURLs)
1704 {
1705     if (!isValid())
1706         return;
1707
1708     // FIXME: This also needs to send a sandbox extension for these paths.
1709     process()->send(Messages::WebPage::DidChooseFilesForOpenPanel(fileURLs), m_pageID);
1710
1711     m_openPanelResultListener->invalidate();
1712     m_openPanelResultListener = 0;
1713 }
1714
1715 void WebPageProxy::didCancelForOpenPanel()
1716 {
1717     if (!isValid())
1718         return;
1719
1720     process()->send(Messages::WebPage::DidCancelForOpenPanel(), m_pageID);
1721     
1722     m_openPanelResultListener->invalidate();
1723     m_openPanelResultListener = 0;
1724 }
1725
1726 void WebPageProxy::unmarkAllMisspellings()
1727 {
1728     process()->send(Messages::WebPage::UnmarkAllMisspellings(), m_pageID);
1729 }
1730
1731 void WebPageProxy::unmarkAllBadGrammar()
1732 {
1733     process()->send(Messages::WebPage::UnmarkAllBadGrammar(), m_pageID);
1734 }
1735
1736 void WebPageProxy::registerEditCommand(PassRefPtr<WebEditCommandProxy> commandProxy, UndoOrRedo undoOrRedo)
1737 {
1738     m_pageClient->registerEditCommand(commandProxy, undoOrRedo);
1739 }
1740
1741 void WebPageProxy::addEditCommand(WebEditCommandProxy* command)
1742 {
1743     m_editCommandSet.add(command);
1744 }
1745
1746 void WebPageProxy::removeEditCommand(WebEditCommandProxy* command)
1747 {
1748     m_editCommandSet.remove(command);
1749
1750     if (!isValid())
1751         return;
1752     process()->send(Messages::WebPage::DidRemoveEditCommand(command->commandID()), m_pageID);
1753 }
1754
1755 // Other
1756
1757 void WebPageProxy::takeFocus(bool direction)
1758 {
1759     m_pageClient->takeFocus(direction);
1760 }
1761
1762 void WebPageProxy::setToolTip(const String& toolTip)
1763 {
1764     String oldToolTip = m_toolTip;
1765     m_toolTip = toolTip;
1766     m_pageClient->toolTipChanged(oldToolTip, m_toolTip);
1767 }
1768
1769 void WebPageProxy::setCursor(const WebCore::Cursor& cursor)
1770 {
1771     m_pageClient->setCursor(cursor);
1772 }
1773
1774 void WebPageProxy::didValidateMenuItem(const String& commandName, bool isEnabled, int32_t state)
1775 {
1776     m_pageClient->setEditCommandState(commandName, isEnabled, state);
1777 }
1778
1779 void WebPageProxy::didReceiveEvent(uint32_t opaqueType, bool handled)
1780 {
1781     WebEvent::Type type = static_cast<WebEvent::Type>(opaqueType);
1782
1783     switch (type) {
1784     case WebEvent::MouseMove:
1785         break;
1786
1787     case WebEvent::MouseDown:
1788     case WebEvent::MouseUp:
1789     case WebEvent::Wheel:
1790     case WebEvent::KeyDown:
1791     case WebEvent::KeyUp:
1792     case WebEvent::RawKeyDown:
1793     case WebEvent::Char:
1794         process()->responsivenessTimer()->stop();
1795         break;
1796     }
1797
1798     switch (type) {
1799     case WebEvent::MouseMove:
1800         m_processingMouseMoveEvent = false;
1801         if (m_nextMouseMoveEvent) {
1802             handleMouseEvent(*m_nextMouseMoveEvent);
1803             m_nextMouseMoveEvent = nullptr;
1804         }
1805         break;
1806     case WebEvent::MouseDown:
1807     case WebEvent::MouseUp:
1808         break;
1809
1810     case WebEvent::Wheel: {
1811         m_processingWheelEvent = false;
1812         if (m_nextWheelEvent) {
1813             handleWheelEvent(*m_nextWheelEvent);
1814             m_nextWheelEvent = nullptr;
1815         }
1816         break;
1817     }
1818
1819     case WebEvent::KeyDown:
1820     case WebEvent::KeyUp:
1821     case WebEvent::RawKeyDown:
1822     case WebEvent::Char: {
1823         NativeWebKeyboardEvent event = m_keyEventQueue.first();
1824         MESSAGE_CHECK(type == event.type());
1825
1826         m_keyEventQueue.removeFirst();
1827
1828         if (handled)
1829             break;
1830
1831         m_pageClient->didNotHandleKeyEvent(event);
1832         m_uiClient.didNotHandleKeyEvent(this, event);
1833         break;
1834     }
1835     }
1836 }
1837
1838 void WebPageProxy::dataCallback(const CoreIPC::DataReference& dataReference, uint64_t callbackID)
1839 {
1840     RefPtr<DataCallback> callback = m_dataCallbacks.take(callbackID);
1841     if (!callback) {
1842         // FIXME: Log error or assert.
1843         return;
1844     }
1845
1846     callback->performCallbackWithReturnValue(WebData::create(dataReference.data(), dataReference.size()).get());
1847 }
1848
1849 void WebPageProxy::stringCallback(const String& resultString, uint64_t callbackID)
1850 {
1851     RefPtr<StringCallback> callback = m_stringCallbacks.take(callbackID);
1852     if (!callback) {
1853         // FIXME: Log error or assert.
1854         return;
1855     }
1856
1857     callback->performCallbackWithReturnValue(resultString.impl());
1858 }
1859
1860 #if PLATFORM(MAC)
1861 void WebPageProxy::sendAccessibilityPresenterToken(const CoreIPC::DataReference& token)
1862 {
1863     if (!isValid())
1864         return;
1865
1866     process()->send(Messages::WebPage::SendAccessibilityPresenterToken(token), m_pageID);
1867 }
1868 #endif
1869
1870 void WebPageProxy::focusedFrameChanged(uint64_t frameID)
1871 {
1872     if (!frameID) {
1873         m_focusedFrame = 0;
1874         return;
1875     }
1876
1877     WebFrameProxy* frame = process()->webFrame(frameID);
1878     MESSAGE_CHECK(frame);
1879
1880     m_focusedFrame = frame;
1881 }
1882
1883 #if USE(ACCELERATED_COMPOSITING)
1884 void WebPageProxy::didChangeAcceleratedCompositing(bool compositing, DrawingAreaInfo& drawingAreaInfo)
1885 {
1886     if (compositing)
1887         didEnterAcceleratedCompositing();
1888     else
1889         didLeaveAcceleratedCompositing();
1890
1891     drawingAreaInfo = drawingArea()->info();
1892 }
1893 #endif
1894
1895 void WebPageProxy::processDidBecomeUnresponsive()
1896 {
1897     m_loaderClient.processDidBecomeUnresponsive(this);
1898 }
1899
1900 void WebPageProxy::processDidBecomeResponsive()
1901 {
1902     m_loaderClient.processDidBecomeResponsive(this);
1903 }
1904
1905 void WebPageProxy::processDidCrash()
1906 {
1907     ASSERT(m_pageClient);
1908
1909     m_isValid = false;
1910
1911     if (m_mainFrame)
1912         m_urlAtProcessExit = m_mainFrame->url();
1913
1914     m_mainFrame = 0;
1915
1916 #if ENABLE(INSPECTOR)
1917     if (m_inspector) {
1918         m_inspector->invalidate();
1919         m_inspector = 0;
1920     }
1921 #endif
1922
1923     if (m_openPanelResultListener) {
1924         m_openPanelResultListener->invalidate();
1925         m_openPanelResultListener = 0;
1926     }
1927
1928     m_toolTip = String();
1929
1930     invalidateCallbackMap(m_dataCallbacks);
1931     invalidateCallbackMap(m_stringCallbacks);
1932
1933     Vector<WebEditCommandProxy*> editCommandVector;
1934     copyToVector(m_editCommandSet, editCommandVector);
1935     m_editCommandSet.clear();
1936     for (size_t i = 0, size = editCommandVector.size(); i < size; ++i)
1937         editCommandVector[i]->invalidate();
1938     m_pageClient->clearAllEditCommands();
1939
1940     m_activePopupMenu = 0;
1941
1942     m_estimatedProgress = 0.0;
1943
1944     m_pageClient->processDidCrash();
1945     m_loaderClient.processDidCrash(this);
1946 }
1947
1948 WebPageCreationParameters WebPageProxy::creationParameters(const IntSize& size) const
1949 {
1950     WebPageCreationParameters parameters;
1951     parameters.viewSize = size;
1952     parameters.drawingAreaInfo = m_drawingArea->info();
1953     parameters.store = m_pageGroup->preferences()->store();
1954     parameters.pageGroupData = m_pageGroup->data();
1955     parameters.drawsBackground = m_drawsBackground;
1956     parameters.drawsTransparentBackground = m_drawsTransparentBackground;
1957     parameters.userAgent = userAgent();
1958
1959 #if PLATFORM(WIN)
1960     parameters.nativeWindow = m_pageClient->nativeWindow();
1961 #endif
1962
1963     return parameters;
1964 }
1965
1966 #if USE(ACCELERATED_COMPOSITING)
1967 void WebPageProxy::didEnterAcceleratedCompositing()
1968 {
1969     m_pageClient->pageDidEnterAcceleratedCompositing();
1970 }
1971
1972 void WebPageProxy::didLeaveAcceleratedCompositing()
1973 {
1974     m_pageClient->pageDidLeaveAcceleratedCompositing();
1975 }
1976 #endif // USE(ACCELERATED_COMPOSITING)
1977
1978 void WebPageProxy::backForwardClear()
1979 {
1980     m_backForwardList->clear();
1981 }
1982
1983 void WebPageProxy::canAuthenticateAgainstProtectionSpaceInFrame(uint64_t frameID, const WebCore::ProtectionSpace& coreProtectionSpace, bool& canAuthenticate)
1984 {
1985     WebFrameProxy* frame = process()->webFrame(frameID);
1986     MESSAGE_CHECK(frame);
1987
1988     RefPtr<WebProtectionSpace> protectionSpace = WebProtectionSpace::create(coreProtectionSpace);
1989     
1990     canAuthenticate = m_loaderClient.canAuthenticateAgainstProtectionSpaceInFrame(this, frame, protectionSpace.get());
1991 }
1992
1993 void WebPageProxy::didReceiveAuthenticationChallenge(uint64_t frameID, const WebCore::AuthenticationChallenge& coreChallenge, uint64_t challengeID)
1994 {
1995     WebFrameProxy* frame = process()->webFrame(frameID);
1996     MESSAGE_CHECK(frame);
1997
1998     RefPtr<AuthenticationChallengeProxy> authenticationChallenge = AuthenticationChallengeProxy::create(coreChallenge, challengeID, this);
1999     
2000     m_loaderClient.didReceiveAuthenticationChallengeInFrame(this, frame, authenticationChallenge.get());
2001 }
2002
2003 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)
2004 {
2005     WebFrameProxy* frame = process()->webFrame(frameID);
2006     MESSAGE_CHECK(frame);
2007
2008     RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::create(originIdentifier);
2009
2010     newQuota = m_uiClient.exceededDatabaseQuota(this, frame, origin.get(), databaseName, displayName, currentQuota, currentUsage, expectedUsage);
2011 }
2012
2013 void WebPageProxy::didFinishLoadingDataForCustomRepresentation(const CoreIPC::DataReference& dataReference)
2014 {
2015     m_pageClient->didFinishLoadingDataForCustomRepresentation(dataReference);
2016 }
2017
2018 #if PLATFORM(MAC)
2019 void WebPageProxy::setComplexTextInputEnabled(uint64_t pluginComplexTextInputIdentifier, bool complexTextInputEnabled)
2020 {
2021     m_pageClient->setComplexTextInputEnabled(pluginComplexTextInputIdentifier, complexTextInputEnabled);
2022 }
2023 #endif
2024
2025 } // namespace WebKit