760d5dc4ebd84d1260e68993e880a67c8e64cffd
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / WebPageProxy.cpp
1 /*
2  * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
3  * Copyright (C) 2012 Intel Corporation. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24  * THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include "config.h"
28 #include "WebPageProxy.h"
29
30 #include "AuthenticationChallengeProxy.h"
31 #include "AuthenticationDecisionListener.h"
32 #include "DataReference.h"
33 #include "DownloadProxy.h"
34 #include "DrawingAreaProxy.h"
35 #include "EventDispatcherMessages.h"
36 #include "FindIndicator.h"
37 #include "Logging.h"
38 #include "MessageID.h"
39 #include "NativeWebKeyboardEvent.h"
40 #include "NativeWebMouseEvent.h"
41 #include "NativeWebWheelEvent.h"
42 #include "NotificationPermissionRequest.h"
43 #include "NotificationPermissionRequestManager.h"
44 #include "PageClient.h"
45 #include "PrintInfo.h"
46 #include "SessionState.h"
47 #include "StringPairVector.h"
48 #include "TextChecker.h"
49 #include "TextCheckerState.h"
50 #include "WKContextPrivate.h"
51 #include "WebBackForwardList.h"
52 #include "WebBackForwardListItem.h"
53 #include "WebCertificateInfo.h"
54 #include "WebContext.h"
55 #include "WebContextMenuProxy.h"
56 #include "WebContextUserMessageCoders.h"
57 #include "WebCoreArgumentCoders.h"
58 #include "WebData.h"
59 #include "WebEditCommandProxy.h"
60 #include "WebEvent.h"
61 #include "WebFormSubmissionListenerProxy.h"
62 #include "WebFramePolicyListenerProxy.h"
63 #include "WebFullScreenManagerProxy.h"
64 #include "WebInspectorProxy.h"
65 #include "WebNotificationManagerProxy.h"
66 #include "WebOpenPanelResultListenerProxy.h"
67 #include "WebPageCreationParameters.h"
68 #include "WebPageGroup.h"
69 #include "WebPageGroupData.h"
70 #include "WebPageMessages.h"
71 #include "WebPopupItem.h"
72 #include "WebPopupMenuProxy.h"
73 #include "WebPreferences.h"
74 #include "WebProcessMessages.h"
75 #include "WebProcessProxy.h"
76 #include "WebProtectionSpace.h"
77 #include "WebSecurityOrigin.h"
78 #include "WebURLRequest.h"
79 #include <WebCore/DragController.h>
80 #include <WebCore/DragData.h>
81 #include <WebCore/DragSession.h>
82 #include <WebCore/FloatRect.h>
83 #include <WebCore/FocusDirection.h>
84 #include <WebCore/MIMETypeRegistry.h>
85 #include <WebCore/TextCheckerClient.h>
86 #include <WebCore/WindowFeatures.h>
87 #include <stdio.h>
88
89 #if USE(UI_SIDE_COMPOSITING)
90 #include "LayerTreeHostProxyMessages.h"
91 #endif
92
93 #if PLATFORM(QT)
94 #include "ArgumentCodersQt.h"
95 #endif
96
97 #if PLATFORM(GTK)
98 #include "ArgumentCodersGtk.h"
99 #endif
100
101 #ifndef NDEBUG
102 #include <wtf/RefCountedLeakCounter.h>
103 #endif
104
105 #if ENABLE(TIZEN_ISF_PORT)
106 #include <WebCore/Logging.h>
107 #endif
108
109 // This controls what strategy we use for mouse wheel coalescing.
110 #define MERGE_WHEEL_EVENTS 1
111
112 #define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, m_process->connection())
113 #define MESSAGE_CHECK_URL(url) MESSAGE_CHECK_BASE(m_process->checkURLReceivedFromWebProcess(url), m_process->connection())
114
115 using namespace WebCore;
116
117 // Represents the number of wheel events we can hold in the queue before we start pushing them preemptively.
118 static const unsigned wheelEventQueueSizeThreshold = 10;
119
120 namespace WebKit {
121
122 WKPageDebugPaintFlags WebPageProxy::s_debugPaintFlags = 0;
123
124 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, webPageProxyCounter, ("WebPageProxy"));
125
126 #if !LOG_DISABLED
127 static const char* webKeyboardEventTypeString(WebEvent::Type type)
128 {
129     switch (type) {
130     case WebEvent::KeyDown:
131         return "KeyDown";
132     
133     case WebEvent::KeyUp:
134         return "KeyUp";
135     
136     case WebEvent::RawKeyDown:
137         return "RawKeyDown";
138     
139     case WebEvent::Char:
140         return "Char";
141     
142     default:
143         ASSERT_NOT_REACHED();
144         return "<unknown>";
145     }
146 }
147 #endif // !LOG_DISABLED
148
149 PassRefPtr<WebPageProxy> WebPageProxy::create(PageClient* pageClient, PassRefPtr<WebProcessProxy> process, WebPageGroup* pageGroup, uint64_t pageID)
150 {
151     return adoptRef(new WebPageProxy(pageClient, process, pageGroup, pageID));
152 }
153
154 WebPageProxy::WebPageProxy(PageClient* pageClient, PassRefPtr<WebProcessProxy> process, WebPageGroup* pageGroup, uint64_t pageID)
155     : m_pageClient(pageClient)
156     , m_process(process)
157     , m_pageGroup(pageGroup)
158     , m_mainFrame(0)
159     , m_userAgent(standardUserAgent())
160     , m_geolocationPermissionRequestManager(this)
161     , m_notificationPermissionRequestManager(this)
162 #if ENABLE(TIZEN_MEDIA_STREAM)
163     , m_userMediaPermissionRequestManager(this)
164 #endif
165     , m_estimatedProgress(0)
166     , m_isInWindow(m_pageClient->isViewInWindow())
167     , m_isVisible(m_pageClient->isViewVisible())
168     , m_backForwardList(WebBackForwardList::create(this))
169     , m_loadStateAtProcessExit(WebFrameProxy::LoadStateFinished)
170     , m_textZoomFactor(1)
171     , m_pageZoomFactor(1)
172     , m_pageScaleFactor(1)
173     , m_intrinsicDeviceScaleFactor(1)
174     , m_customDeviceScaleFactor(0)
175 #if HAVE(LAYER_HOSTING_IN_WINDOW_SERVER)
176     , m_layerHostingMode(LayerHostingModeInWindowServer)
177 #else
178     , m_layerHostingMode(LayerHostingModeDefault)
179 #endif
180     , m_drawsBackground(true)
181     , m_drawsTransparentBackground(false)
182     , m_areMemoryCacheClientCallsEnabled(true)
183     , m_useFixedLayout(false)
184     , m_paginationMode(Page::Pagination::Unpaginated)
185     , m_paginationBehavesLikeColumns(false)
186     , m_pageLength(0)
187     , m_gapBetweenPages(0)
188     , m_isValid(true)
189     , m_isClosed(false)
190     , m_isInPrintingMode(false)
191     , m_isPerformingDOMPrintOperation(false)
192     , m_inDecidePolicyForResponse(false)
193     , m_syncMimeTypePolicyActionIsValid(false)
194     , m_syncMimeTypePolicyAction(PolicyUse)
195     , m_syncMimeTypePolicyDownloadID(0)
196     , m_inDecidePolicyForNavigationAction(false)
197     , m_syncNavigationActionPolicyActionIsValid(false)
198     , m_syncNavigationActionPolicyAction(PolicyUse)
199     , m_syncNavigationActionPolicyDownloadID(0)
200     , m_processingMouseMoveEvent(false)
201 #if ENABLE(TOUCH_EVENTS)
202     , m_needTouchEvents(false)
203 #endif
204     , m_pageID(pageID)
205     , m_isPageSuspended(false)
206 #if PLATFORM(MAC)
207     , m_isSmartInsertDeleteEnabled(TextChecker::isSmartInsertDeleteEnabled())
208 #endif
209     , m_spellDocumentTag(0)
210     , m_hasSpellDocumentTag(false)
211     , m_pendingLearnOrIgnoreWordMessageCount(0)
212     , m_mainFrameHasCustomRepresentation(false)
213     , m_mainFrameHasHorizontalScrollbar(false)
214     , m_mainFrameHasVerticalScrollbar(false)
215     , m_canShortCircuitHorizontalWheelEvents(true)
216     , m_mainFrameIsPinnedToLeftSide(false)
217     , m_mainFrameIsPinnedToRightSide(false)
218     , m_pageCount(0)
219     , m_renderTreeSize(0)
220     , m_shouldSendEventsSynchronously(false)
221     , m_mediaVolume(1)
222 #if ENABLE(PAGE_VISIBILITY_API)
223     , m_visibilityState(PageVisibilityStateVisible)
224 #endif
225 {
226 #ifndef NDEBUG
227     webPageProxyCounter.increment();
228 #endif
229
230     WebContext::statistics().wkPageCount++;
231
232     m_pageGroup->addPage(this);
233 }
234
235 WebPageProxy::~WebPageProxy()
236 {
237     if (!m_isClosed)
238         close();
239
240     WebContext::statistics().wkPageCount--;
241
242     if (m_hasSpellDocumentTag)
243         TextChecker::closeSpellDocumentWithTag(m_spellDocumentTag);
244
245     m_pageGroup->removePage(this);
246
247 #ifndef NDEBUG
248     webPageProxyCounter.decrement();
249 #endif
250 }
251
252 WebProcessProxy* WebPageProxy::process() const
253 {
254     return m_process.get();
255 }
256
257 PlatformProcessIdentifier WebPageProxy::processIdentifier() const
258 {
259     if (!m_process)
260         return 0;
261
262     return m_process->processIdentifier();
263 }
264
265 bool WebPageProxy::isValid()
266 {
267     // A page that has been explicitly closed is never valid.
268     if (m_isClosed)
269         return false;
270
271     return m_isValid;
272 }
273
274 void WebPageProxy::initializeLoaderClient(const WKPageLoaderClient* loadClient)
275 {
276     m_loaderClient.initialize(loadClient);
277     
278     if (!loadClient)
279         return;
280
281     process()->send(Messages::WebPage::SetWillGoToBackForwardItemCallbackEnabled(loadClient->version > 0), m_pageID);
282 }
283
284 void WebPageProxy::initializePolicyClient(const WKPagePolicyClient* policyClient)
285 {
286     m_policyClient.initialize(policyClient);
287 }
288
289 void WebPageProxy::initializeFormClient(const WKPageFormClient* formClient)
290 {
291     m_formClient.initialize(formClient);
292 }
293
294 void WebPageProxy::initializeResourceLoadClient(const WKPageResourceLoadClient* client)
295 {
296     m_resourceLoadClient.initialize(client);
297 }
298
299 void WebPageProxy::initializeUIClient(const WKPageUIClient* client)
300 {
301     if (!isValid())
302         return;
303
304     m_uiClient.initialize(client);
305
306     process()->send(Messages::WebPage::SetCanRunBeforeUnloadConfirmPanel(m_uiClient.canRunBeforeUnloadConfirmPanel()), m_pageID);
307     process()->send(Messages::WebPage::SetCanRunModal(m_uiClient.canRunModal()), m_pageID);
308 }
309
310 void WebPageProxy::initializeFindClient(const WKPageFindClient* client)
311 {
312     m_findClient.initialize(client);
313 }
314
315 #if ENABLE(CONTEXT_MENUS)
316 void WebPageProxy::initializeContextMenuClient(const WKPageContextMenuClient* client)
317 {
318     m_contextMenuClient.initialize(client);
319 }
320 #endif
321
322 void WebPageProxy::reattachToWebProcess()
323 {
324     ASSERT(!isValid());
325
326     m_isValid = true;
327
328     m_process = m_process->context()->relaunchProcessIfNecessary();
329     process()->addExistingWebPage(this, m_pageID);
330
331     initializeWebPage();
332
333     m_pageClient->didRelaunchProcess();
334     m_drawingArea->waitForBackingStoreUpdateOnNextPaint();
335 }
336
337 void WebPageProxy::reattachToWebProcessWithItem(WebBackForwardListItem* item)
338 {
339     if (item && item != m_backForwardList->currentItem())
340         m_backForwardList->goToItem(item);
341     
342     reattachToWebProcess();
343
344     if (!item)
345         return;
346
347     process()->send(Messages::WebPage::GoToBackForwardItem(item->itemID()), m_pageID);
348     process()->responsivenessTimer()->start();
349 }
350
351 void WebPageProxy::initializeWebPage()
352 {
353     ASSERT(isValid());
354
355     BackForwardListItemVector items = m_backForwardList->entries();
356     for (size_t i = 0; i < items.size(); ++i)
357         process()->registerNewWebBackForwardListItem(items[i].get());
358
359     m_drawingArea = m_pageClient->createDrawingAreaProxy();
360     ASSERT(m_drawingArea);
361
362 #if ENABLE(INSPECTOR_SERVER)
363     if (m_pageGroup->preferences()->developerExtrasEnabled())
364         inspector()->enableRemoteInspection();
365 #endif
366
367     process()->send(Messages::WebProcess::CreateWebPage(m_pageID, creationParameters()), 0);
368
369 #if ENABLE(PAGE_VISIBILITY_API)
370     process()->send(Messages::WebPage::SetVisibilityState(m_visibilityState, /* isInitialState */ true), m_pageID);
371 #endif
372 }
373
374 void WebPageProxy::close()
375 {
376     if (!isValid())
377         return;
378
379     m_isClosed = true;
380
381     m_backForwardList->pageClosed();
382     m_pageClient->pageClosed();
383
384     process()->disconnectFramesFromPage(this);
385     m_mainFrame = 0;
386
387 #if ENABLE(INSPECTOR)
388     if (m_inspector) {
389         m_inspector->invalidate();
390         m_inspector = 0;
391     }
392 #endif
393
394 #if ENABLE(FULLSCREEN_API)
395     if (m_fullScreenManager) {
396         m_fullScreenManager->invalidate();
397         m_fullScreenManager = 0;
398     }
399 #endif
400
401     if (m_openPanelResultListener) {
402         m_openPanelResultListener->invalidate();
403         m_openPanelResultListener = 0;
404     }
405
406 #if ENABLE(INPUT_TYPE_COLOR)
407     if (m_colorChooser) {
408         m_colorChooser->invalidate();
409         m_colorChooser = nullptr;
410     }
411 #endif
412
413 #if ENABLE(GEOLOCATION)
414     m_geolocationPermissionRequestManager.invalidateRequests();
415 #endif
416
417     m_notificationPermissionRequestManager.invalidateRequests();
418 #if ENABLE(TIZEN_MEDIA_STREAM)
419     m_userMediaPermissionRequestManager.invalidateRequests();
420 #endif
421
422     m_toolTip = String();
423
424     m_mainFrameHasHorizontalScrollbar = false;
425     m_mainFrameHasVerticalScrollbar = false;
426
427     m_mainFrameIsPinnedToLeftSide = false;
428     m_mainFrameIsPinnedToRightSide = false;
429
430     m_visibleScrollerThumbRect = IntRect();
431
432 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
433     invalidateCallbackMap(m_booleanCallbacks);
434 #endif
435     invalidateCallbackMap(m_voidCallbacks);
436     invalidateCallbackMap(m_dataCallbacks);
437     invalidateCallbackMap(m_stringCallbacks);
438     m_loadDependentStringCallbackIDs.clear();
439     invalidateCallbackMap(m_scriptValueCallbacks);
440     invalidateCallbackMap(m_computedPagesCallbacks);
441 #if PLATFORM(GTK)
442     invalidateCallbackMap(m_printFinishedCallbacks);
443 #endif
444
445     Vector<WebEditCommandProxy*> editCommandVector;
446     copyToVector(m_editCommandSet, editCommandVector);
447     m_editCommandSet.clear();
448     for (size_t i = 0, size = editCommandVector.size(); i < size; ++i)
449         editCommandVector[i]->invalidate();
450
451     m_activePopupMenu = 0;
452
453     m_estimatedProgress = 0.0;
454     
455     m_loaderClient.initialize(0);
456     m_policyClient.initialize(0);
457     m_uiClient.initialize(0);
458
459     m_drawingArea = nullptr;
460
461     process()->send(Messages::WebPage::Close(), m_pageID);
462     process()->removeWebPage(m_pageID);
463 }
464
465 bool WebPageProxy::tryClose()
466 {
467     if (!isValid())
468         return true;
469
470     process()->send(Messages::WebPage::TryClose(), m_pageID);
471     process()->responsivenessTimer()->start();
472     return false;
473 }
474
475 bool WebPageProxy::maybeInitializeSandboxExtensionHandle(const KURL& url, SandboxExtension::Handle& sandboxExtensionHandle)
476 {
477     if (!url.isLocalFile())
478         return false;
479
480 #if ENABLE(INSPECTOR)
481     // Don't give the inspector full access to the file system.
482     if (WebInspectorProxy::isInspectorPage(this))
483         return false;
484 #endif
485
486     SandboxExtension::createHandle("/", SandboxExtension::ReadOnly, sandboxExtensionHandle);
487     return true;
488 }
489
490 void WebPageProxy::loadURL(const String& url)
491 {
492     setPendingAPIRequestURL(url);
493
494     if (!isValid())
495         reattachToWebProcess();
496
497     SandboxExtension::Handle sandboxExtensionHandle;
498     bool createdExtension = maybeInitializeSandboxExtensionHandle(KURL(KURL(), url), sandboxExtensionHandle);
499     if (createdExtension)
500         process()->willAcquireUniversalFileReadSandboxExtension();
501     process()->send(Messages::WebPage::LoadURL(url, sandboxExtensionHandle), m_pageID);
502     process()->responsivenessTimer()->start();
503 }
504
505 void WebPageProxy::loadURLRequest(WebURLRequest* urlRequest)
506 {
507     setPendingAPIRequestURL(urlRequest->resourceRequest().url());
508
509     if (!isValid())
510         reattachToWebProcess();
511
512     SandboxExtension::Handle sandboxExtensionHandle;
513     bool createdExtension = maybeInitializeSandboxExtensionHandle(urlRequest->resourceRequest().url(), sandboxExtensionHandle);
514     if (createdExtension)
515         process()->willAcquireUniversalFileReadSandboxExtension();
516     process()->send(Messages::WebPage::LoadURLRequest(urlRequest->resourceRequest(), sandboxExtensionHandle), m_pageID);
517     process()->responsivenessTimer()->start();
518 }
519
520 void WebPageProxy::loadHTMLString(const String& htmlString, const String& baseURL)
521 {
522     if (!isValid())
523         reattachToWebProcess();
524
525     process()->assumeReadAccessToBaseURL(baseURL);
526     process()->send(Messages::WebPage::LoadHTMLString(htmlString, baseURL), m_pageID);
527     process()->responsivenessTimer()->start();
528 }
529
530 void WebPageProxy::loadAlternateHTMLString(const String& htmlString, const String& baseURL, const String& unreachableURL)
531 {
532     if (!isValid())
533         reattachToWebProcess();
534
535     if (m_mainFrame)
536         m_mainFrame->setUnreachableURL(unreachableURL);
537
538     process()->assumeReadAccessToBaseURL(baseURL);
539     process()->send(Messages::WebPage::LoadAlternateHTMLString(htmlString, baseURL, unreachableURL), m_pageID);
540     process()->responsivenessTimer()->start();
541 }
542
543 void WebPageProxy::loadPlainTextString(const String& string)
544 {
545     if (!isValid())
546         reattachToWebProcess();
547
548     process()->send(Messages::WebPage::LoadPlainTextString(string), m_pageID);
549     process()->responsivenessTimer()->start();
550 }
551
552 void WebPageProxy::loadWebArchiveData(const WebData* webArchiveData)
553 {
554     if (!isValid())
555         reattachToWebProcess();
556
557     process()->send(Messages::WebPage::LoadWebArchiveData(webArchiveData->dataReference()), m_pageID);
558     process()->responsivenessTimer()->start();
559 }
560
561 #if OS(TIZEN)
562 void WebPageProxy::loadContentsbyMimeType(const WebData* contents, const String& mimeType, const String& encoding, const String& baseURL)
563 {
564     if (!isValid())
565         reattachToWebProcess();
566
567     process()->assumeReadAccessToBaseURL(baseURL);
568     process()->send(Messages::WebPage::LoadContentsbyMimeType(contents->dataReference(), mimeType, encoding, baseURL), m_pageID);
569     process()->responsivenessTimer()->start();
570 }
571 #endif
572
573 void WebPageProxy::stopLoading()
574 {
575     if (!isValid())
576         return;
577
578     process()->send(Messages::WebPage::StopLoading(), m_pageID);
579     process()->responsivenessTimer()->start();
580 }
581
582 void WebPageProxy::reload(bool reloadFromOrigin)
583 {
584     SandboxExtension::Handle sandboxExtensionHandle;
585
586     if (m_backForwardList->currentItem()) {
587         String url = m_backForwardList->currentItem()->url();
588         setPendingAPIRequestURL(url);
589
590         // We may not have an extension yet if back/forward list was reinstated after a WebProcess crash or a browser relaunch
591         bool createdExtension = maybeInitializeSandboxExtensionHandle(KURL(KURL(), url), sandboxExtensionHandle);
592         if (createdExtension)
593             process()->willAcquireUniversalFileReadSandboxExtension();
594     }
595
596     if (!isValid()) {
597         reattachToWebProcessWithItem(m_backForwardList->currentItem());
598         return;
599     }
600
601     process()->send(Messages::WebPage::Reload(reloadFromOrigin, sandboxExtensionHandle), m_pageID);
602     process()->responsivenessTimer()->start();
603 }
604
605 void WebPageProxy::goForward()
606 {
607     if (isValid() && !canGoForward())
608         return;
609
610     WebBackForwardListItem* forwardItem = m_backForwardList->forwardItem();
611     if (!forwardItem)
612         return;
613
614     setPendingAPIRequestURL(forwardItem->url());
615
616     if (!isValid()) {
617         reattachToWebProcessWithItem(forwardItem);
618         return;
619     }
620
621     process()->send(Messages::WebPage::GoForward(forwardItem->itemID()), m_pageID);
622     process()->responsivenessTimer()->start();
623 }
624
625 bool WebPageProxy::canGoForward() const
626 {
627     return m_backForwardList->forwardItem();
628 }
629
630 void WebPageProxy::goBack()
631 {
632     if (isValid() && !canGoBack())
633         return;
634
635     WebBackForwardListItem* backItem = m_backForwardList->backItem();
636     if (!backItem)
637         return;
638
639     setPendingAPIRequestURL(backItem->url());
640
641     if (!isValid()) {
642         reattachToWebProcessWithItem(backItem);
643         return;
644     }
645
646     process()->send(Messages::WebPage::GoBack(backItem->itemID()), m_pageID);
647     process()->responsivenessTimer()->start();
648 }
649
650 bool WebPageProxy::canGoBack() const
651 {
652     return m_backForwardList->backItem();
653 }
654
655 void WebPageProxy::goToBackForwardItem(WebBackForwardListItem* item)
656 {
657     if (!isValid()) {
658         reattachToWebProcessWithItem(item);
659         return;
660     }
661     
662     setPendingAPIRequestURL(item->url());
663
664     process()->send(Messages::WebPage::GoToBackForwardItem(item->itemID()), m_pageID);
665     process()->responsivenessTimer()->start();
666 }
667
668 void WebPageProxy::tryRestoreScrollPosition()
669 {
670     if (!isValid())
671         return;
672
673     process()->send(Messages::WebPage::TryRestoreScrollPosition(), m_pageID);
674 }
675
676 void WebPageProxy::didChangeBackForwardList(WebBackForwardListItem* added, Vector<RefPtr<APIObject> >* removed)
677 {
678     m_loaderClient.didChangeBackForwardList(this, added, removed);
679 }
680
681 void WebPageProxy::shouldGoToBackForwardListItem(uint64_t itemID, bool& shouldGoToBackForwardItem)
682 {
683     WebBackForwardListItem* item = process()->webBackForwardItem(itemID);
684     shouldGoToBackForwardItem = item && m_loaderClient.shouldGoToBackForwardListItem(this, item);
685 }
686
687 void WebPageProxy::willGoToBackForwardListItem(uint64_t itemID, CoreIPC::ArgumentDecoder* arguments)
688 {
689     RefPtr<APIObject> userData;
690     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
691     if (!arguments->decode(messageDecoder))
692         return;
693
694     if (WebBackForwardListItem* item = process()->webBackForwardItem(itemID))
695         m_loaderClient.willGoToBackForwardListItem(this, item, userData.get());
696 }
697
698 String WebPageProxy::activeURL() const
699 {
700     // If there is a currently pending url, it is the active URL,
701     // even when there's no main frame yet, as it might be the
702     // first API request.
703     if (!m_pendingAPIRequestURL.isNull())
704         return m_pendingAPIRequestURL;
705
706     if (!m_mainFrame)
707         return String();
708
709     if (!m_mainFrame->unreachableURL().isEmpty())
710         return m_mainFrame->unreachableURL();
711
712     switch (m_mainFrame->loadState()) {
713     case WebFrameProxy::LoadStateProvisional:
714         return m_mainFrame->provisionalURL();
715     case WebFrameProxy::LoadStateCommitted:
716     case WebFrameProxy::LoadStateFinished:
717         return m_mainFrame->url();
718     }
719
720     ASSERT_NOT_REACHED();
721     return String();
722 }
723
724 String WebPageProxy::provisionalURL() const
725 {
726     if (!m_mainFrame)
727         return String();
728     return m_mainFrame->provisionalURL();
729 }
730
731 String WebPageProxy::committedURL() const
732 {
733     if (!m_mainFrame)
734         return String();
735
736     return m_mainFrame->url();
737 }
738
739 bool WebPageProxy::canShowMIMEType(const String& mimeType) const
740 {
741     if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType))
742         return true;
743
744     if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType))
745         return true;
746
747     if (mimeType.startsWith("text/", false))
748         return !MIMETypeRegistry::isUnsupportedTextMIMEType(mimeType);
749
750 #if ENABLE(TIZEN_FIX_PLUGIN_DOWNLOAD)
751     // check plugin mime types if the plugin option is enabled
752     if (arePluginsEnabled()) {
753         String newMimeType = mimeType;
754         PluginModuleInfo plugin = m_process->context()->pluginInfoStore().findPlugin(newMimeType, KURL());
755         if (!plugin.path.isNull())
756             return true;
757     }
758 #else // ENABLE(TIZEN_FIX_PLUGIN_DOWNLOAD)
759     String newMimeType = mimeType;
760     PluginModuleInfo plugin = m_process->context()->pluginInfoStore().findPlugin(newMimeType, KURL());
761     if (!plugin.path.isNull())
762         return true;
763 #endif // ENABLE(TIZEN_FIX_PLUGIN_DOWNLOAD)
764
765     return false;
766 }
767
768 void WebPageProxy::setDrawsBackground(bool drawsBackground)
769 {
770     if (m_drawsBackground == drawsBackground)
771         return;
772
773     m_drawsBackground = drawsBackground;
774
775     if (isValid())
776         process()->send(Messages::WebPage::SetDrawsBackground(drawsBackground), m_pageID);
777 }
778
779 void WebPageProxy::setDrawsTransparentBackground(bool drawsTransparentBackground)
780 {
781     if (m_drawsTransparentBackground == drawsTransparentBackground)
782         return;
783
784     m_drawsTransparentBackground = drawsTransparentBackground;
785
786     if (isValid())
787         process()->send(Messages::WebPage::SetDrawsTransparentBackground(drawsTransparentBackground), m_pageID);
788 }
789
790 void WebPageProxy::viewWillStartLiveResize()
791 {
792     if (!isValid())
793         return;
794     process()->send(Messages::WebPage::ViewWillStartLiveResize(), m_pageID);
795 }
796
797 void WebPageProxy::viewWillEndLiveResize()
798 {
799     if (!isValid())
800         return;
801     process()->send(Messages::WebPage::ViewWillEndLiveResize(), m_pageID);
802 }
803
804 void WebPageProxy::setViewNeedsDisplay(const IntRect& rect)
805 {
806     m_pageClient->setViewNeedsDisplay(rect);
807 }
808
809 void WebPageProxy::displayView()
810 {
811     m_pageClient->displayView();
812 }
813
814 void WebPageProxy::scrollView(const IntRect& scrollRect, const IntSize& scrollOffset)
815 {
816     m_pageClient->scrollView(scrollRect, scrollOffset);
817 }
818
819 void WebPageProxy::viewStateDidChange(ViewStateFlags flags)
820 {
821     if (!isValid())
822         return;
823
824     if (flags & ViewIsFocused)
825         process()->send(Messages::WebPage::SetFocused(m_pageClient->isViewFocused()), m_pageID);
826
827     if (flags & ViewWindowIsActive)
828         process()->send(Messages::WebPage::SetActive(m_pageClient->isViewWindowActive()), m_pageID);
829
830     if (flags & ViewIsVisible) {
831         bool isVisible = m_pageClient->isViewVisible();
832         if (isVisible != m_isVisible) {
833             m_isVisible = isVisible;
834             m_drawingArea->visibilityDidChange();
835
836             if (!m_isVisible) {
837                 // If we've started the responsiveness timer as part of telling the web process to update the backing store
838                 // state, it might not send back a reply (since it won't paint anything if the web page is hidden) so we
839                 // stop the unresponsiveness timer here.
840                 process()->responsivenessTimer()->stop();
841             }
842         }
843     }
844
845     if (flags & ViewIsInWindow) {
846         bool isInWindow = m_pageClient->isViewInWindow();
847         if (m_isInWindow != isInWindow) {
848             m_isInWindow = isInWindow;
849             process()->send(Messages::WebPage::SetIsInWindow(isInWindow), m_pageID);
850         }
851
852         if (isInWindow) {
853             LayerHostingMode layerHostingMode = m_pageClient->viewLayerHostingMode();
854             if (m_layerHostingMode != layerHostingMode) {
855                 m_layerHostingMode = layerHostingMode;
856                 m_drawingArea->layerHostingModeDidChange();
857             }
858         }
859     }
860
861 #if ENABLE(PAGE_VISIBILITY_API)
862     PageVisibilityState visibilityState = PageVisibilityStateHidden;
863
864     if (m_pageClient->isViewVisible())
865         visibilityState = PageVisibilityStateVisible;
866
867     if (visibilityState != m_visibilityState) {
868         m_visibilityState = visibilityState;
869         process()->send(Messages::WebPage::SetVisibilityState(visibilityState, false), m_pageID);
870     }
871 #endif
872
873     updateBackingStoreDiscardableState();
874 }
875
876 IntSize WebPageProxy::viewSize() const
877 {
878     return m_pageClient->viewSize();
879 }
880
881 void WebPageProxy::setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent& keyboardEvent)
882 {
883     if (!isValid())
884         return;
885     process()->send(Messages::WebPage::SetInitialFocus(forward, isKeyboardEventValid, keyboardEvent), m_pageID);
886 }
887
888 void WebPageProxy::setWindowResizerSize(const IntSize& windowResizerSize)
889 {
890     if (!isValid())
891         return;
892     process()->send(Messages::WebPage::SetWindowResizerSize(windowResizerSize), m_pageID);
893 }
894     
895 void WebPageProxy::clearSelection()
896 {
897     if (!isValid())
898         return;
899     process()->send(Messages::WebPage::ClearSelection(), m_pageID);
900 }
901
902 void WebPageProxy::validateCommand(const String& commandName, PassRefPtr<ValidateCommandCallback> callback)
903 {
904     if (!isValid()) {
905         callback->invalidate();
906         return;
907     }
908
909     uint64_t callbackID = callback->callbackID();
910     m_validateCommandCallbacks.set(callbackID, callback.get());
911     process()->send(Messages::WebPage::ValidateCommand(commandName, callbackID), m_pageID);
912 }
913
914 void WebPageProxy::setMaintainsInactiveSelection(bool newValue)
915 {
916     m_maintainsInactiveSelection = newValue;
917 }
918     
919 void WebPageProxy::executeEditCommand(const String& commandName)
920 {
921     if (!isValid())
922         return;
923
924     DEFINE_STATIC_LOCAL(String, ignoreSpellingCommandName, ("ignoreSpelling"));
925     if (commandName == ignoreSpellingCommandName)
926         ++m_pendingLearnOrIgnoreWordMessageCount;
927
928     process()->send(Messages::WebPage::ExecuteEditCommand(commandName), m_pageID);
929 }
930     
931 #if USE(TILED_BACKING_STORE)
932 void WebPageProxy::setViewportSize(const IntSize& size)
933 {
934     if (!isValid())
935         return;
936
937     process()->send(Messages::WebPage::SetViewportSize(size), m_pageID);
938 }
939 #endif
940
941 #if ENABLE(DRAG_SUPPORT)
942 void WebPageProxy::dragEntered(DragData* dragData, const String& dragStorageName)
943 {
944     SandboxExtension::Handle sandboxExtensionHandle;
945     SandboxExtension::HandleArray sandboxExtensionHandleEmptyArray;
946     performDragControllerAction(DragControllerActionEntered, dragData, dragStorageName, sandboxExtensionHandle, sandboxExtensionHandleEmptyArray);
947 }
948
949 void WebPageProxy::dragUpdated(DragData* dragData, const String& dragStorageName)
950 {
951     SandboxExtension::Handle sandboxExtensionHandle;
952     SandboxExtension::HandleArray sandboxExtensionHandleEmptyArray;
953     performDragControllerAction(DragControllerActionUpdated, dragData, dragStorageName, sandboxExtensionHandle, sandboxExtensionHandleEmptyArray);
954 }
955
956 void WebPageProxy::dragExited(DragData* dragData, const String& dragStorageName)
957 {
958     SandboxExtension::Handle sandboxExtensionHandle;
959     SandboxExtension::HandleArray sandboxExtensionHandleEmptyArray;
960     performDragControllerAction(DragControllerActionExited, dragData, dragStorageName, sandboxExtensionHandle, sandboxExtensionHandleEmptyArray);
961 }
962
963 void WebPageProxy::performDrag(DragData* dragData, const String& dragStorageName, const SandboxExtension::Handle& sandboxExtensionHandle, const SandboxExtension::HandleArray& sandboxExtensionsForUpload)
964 {
965     performDragControllerAction(DragControllerActionPerformDrag, dragData, dragStorageName, sandboxExtensionHandle, sandboxExtensionsForUpload);
966 }
967
968 void WebPageProxy::performDragControllerAction(DragControllerAction action, DragData* dragData, const String& dragStorageName, const SandboxExtension::Handle& sandboxExtensionHandle, const SandboxExtension::HandleArray& sandboxExtensionsForUpload)
969 {
970     if (!isValid())
971         return;
972 #if PLATFORM(WIN)
973     // FIXME: We should pass the drag data map only on DragEnter.
974     process()->send(Messages::WebPage::PerformDragControllerAction(action, dragData->clientPosition(), dragData->globalPosition(),
975         dragData->draggingSourceOperationMask(), dragData->dragDataMap(), dragData->flags()), m_pageID);
976 #elif PLATFORM(QT) || PLATFORM(GTK)
977     process()->send(Messages::WebPage::PerformDragControllerAction(action, *dragData), m_pageID);
978 #else
979     process()->send(Messages::WebPage::PerformDragControllerAction(action, dragData->clientPosition(), dragData->globalPosition(), dragData->draggingSourceOperationMask(), dragStorageName, dragData->flags(), sandboxExtensionHandle, sandboxExtensionsForUpload), m_pageID);
980 #endif
981 }
982
983 void WebPageProxy::didPerformDragControllerAction(WebCore::DragSession dragSession)
984 {
985     m_currentDragSession = dragSession;
986 }
987
988 #if PLATFORM(QT) || PLATFORM(GTK)
989 void WebPageProxy::startDrag(const DragData& dragData, const ShareableBitmap::Handle& dragImageHandle)
990 {
991     RefPtr<ShareableBitmap> dragImage = 0;
992     if (!dragImageHandle.isNull()) {
993         dragImage = ShareableBitmap::create(dragImageHandle);
994     if (!dragImage)
995         return;
996     }
997
998     m_pageClient->startDrag(dragData, dragImage.release());
999 }
1000 #endif
1001
1002 void WebPageProxy::dragEnded(const IntPoint& clientPosition, const IntPoint& globalPosition, uint64_t operation)
1003 {
1004     if (!isValid())
1005         return;
1006     process()->send(Messages::WebPage::DragEnded(clientPosition, globalPosition, operation), m_pageID);
1007 }
1008 #endif // ENABLE(DRAG_SUPPORT)
1009
1010 void WebPageProxy::handleMouseEvent(const NativeWebMouseEvent& event)
1011 {
1012     if (!isValid())
1013         return;
1014
1015 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1016     if (isWaitingForJavaScriptPopupReply())
1017         return;
1018 #endif
1019
1020     // NOTE: This does not start the responsiveness timer because mouse move should not indicate interaction.
1021     if (event.type() != WebEvent::MouseMove)
1022         process()->responsivenessTimer()->start();
1023     else {
1024         if (m_processingMouseMoveEvent) {
1025             m_nextMouseMoveEvent = adoptPtr(new NativeWebMouseEvent(event));
1026             return;
1027         }
1028
1029         m_processingMouseMoveEvent = true;
1030     }
1031
1032     // <https://bugs.webkit.org/show_bug.cgi?id=57904> We need to keep track of the mouse down event in the case where we
1033     // display a popup menu for select elements. When the user changes the selected item,
1034     // we fake a mouse up event by using this stored down event. This event gets cleared
1035     // when the mouse up message is received from WebProcess.
1036     if (event.type() == WebEvent::MouseDown)
1037         m_currentlyProcessedMouseDownEvent = adoptPtr(new NativeWebMouseEvent(event));
1038
1039 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
1040     // We have to hide text-selection's context menu when other area is clicked.
1041     // In case of normal context menu, it is hided by elm_ctxpopup's logic.
1042     if (event.type() == WebEvent::MouseDown)
1043         hideContextMenu();
1044 #endif
1045
1046 #if ENABLE(TIZEN_ISF_PORT)
1047     if (event.type() == WebEvent::MouseDown)
1048         m_pageClient->handleInputMethodMousePress();
1049 #endif
1050
1051     if (m_shouldSendEventsSynchronously) {
1052         bool handled = false;
1053         process()->sendSync(Messages::WebPage::MouseEventSyncForTesting(event), Messages::WebPage::MouseEventSyncForTesting::Reply(handled), m_pageID);
1054         didReceiveEvent(event.type(), handled);
1055     } else
1056         process()->send(Messages::WebPage::MouseEvent(event), m_pageID);
1057 }
1058
1059 #if MERGE_WHEEL_EVENTS
1060 static bool canCoalesce(const WebWheelEvent& a, const WebWheelEvent& b)
1061 {
1062     if (a.position() != b.position())
1063         return false;
1064     if (a.globalPosition() != b.globalPosition())
1065         return false;
1066     if (a.modifiers() != b.modifiers())
1067         return false;
1068     if (a.granularity() != b.granularity())
1069         return false;
1070 #if PLATFORM(MAC)
1071     if (a.phase() != b.phase())
1072         return false;
1073     if (a.momentumPhase() != b.momentumPhase())
1074         return false;
1075     if (a.hasPreciseScrollingDeltas() != b.hasPreciseScrollingDeltas())
1076         return false;
1077 #endif
1078
1079     return true;
1080 }
1081
1082 static WebWheelEvent coalesce(const WebWheelEvent& a, const WebWheelEvent& b)
1083 {
1084     ASSERT(canCoalesce(a, b));
1085
1086     FloatSize mergedDelta = a.delta() + b.delta();
1087     FloatSize mergedWheelTicks = a.wheelTicks() + b.wheelTicks();
1088
1089 #if PLATFORM(MAC)
1090     FloatSize mergedUnacceleratedScrollingDelta = a.unacceleratedScrollingDelta() + b.unacceleratedScrollingDelta();
1091
1092     return WebWheelEvent(WebEvent::Wheel, b.position(), b.globalPosition(), mergedDelta, mergedWheelTicks, b.granularity(), b.directionInvertedFromDevice(), b.phase(), b.momentumPhase(), b.hasPreciseScrollingDeltas(), b.scrollCount(), mergedUnacceleratedScrollingDelta, b.modifiers(), b.timestamp());
1093 #else
1094     return WebWheelEvent(WebEvent::Wheel, b.position(), b.globalPosition(), mergedDelta, mergedWheelTicks, b.granularity(), b.modifiers(), b.timestamp());
1095 #endif
1096 }
1097 #endif // MERGE_WHEEL_EVENTS
1098
1099 static WebWheelEvent coalescedWheelEvent(Deque<NativeWebWheelEvent>& queue, Vector<NativeWebWheelEvent>& coalescedEvents)
1100 {
1101     ASSERT(!queue.isEmpty());
1102     ASSERT(coalescedEvents.isEmpty());
1103
1104 #if MERGE_WHEEL_EVENTS
1105     NativeWebWheelEvent firstEvent = queue.takeFirst();
1106     coalescedEvents.append(firstEvent);
1107
1108     WebWheelEvent event = firstEvent;
1109     while (!queue.isEmpty() && canCoalesce(event, queue.first())) {
1110         NativeWebWheelEvent firstEvent = queue.takeFirst();
1111         coalescedEvents.append(firstEvent);
1112         event = coalesce(event, firstEvent);
1113     }
1114
1115     return event;
1116 #else
1117     while (!queue.isEmpty())
1118         coalescedEvents.append(queue.takeFirst());
1119     return coalescedEvents.last();
1120 #endif
1121 }
1122
1123 void WebPageProxy::handleWheelEvent(const NativeWebWheelEvent& event)
1124 {
1125     if (!isValid())
1126         return;
1127
1128 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1129     if (isWaitingForJavaScriptPopupReply())
1130         return;
1131 #endif
1132
1133     if (!m_currentlyProcessedWheelEvents.isEmpty()) {
1134         m_wheelEventQueue.append(event);
1135         if (m_wheelEventQueue.size() < wheelEventQueueSizeThreshold)
1136             return;
1137         // The queue has too many wheel events, so push a new event.
1138     }
1139
1140     if (!m_wheelEventQueue.isEmpty()) {
1141         processNextQueuedWheelEvent();
1142         return;
1143     }
1144
1145     OwnPtr<Vector<NativeWebWheelEvent> > coalescedWheelEvent = adoptPtr(new Vector<NativeWebWheelEvent>);
1146     coalescedWheelEvent->append(event);
1147     m_currentlyProcessedWheelEvents.append(coalescedWheelEvent.release());
1148     sendWheelEvent(event);
1149 }
1150
1151 void WebPageProxy::processNextQueuedWheelEvent()
1152 {
1153     OwnPtr<Vector<NativeWebWheelEvent> > nextCoalescedEvent = adoptPtr(new Vector<NativeWebWheelEvent>);
1154     WebWheelEvent nextWheelEvent = coalescedWheelEvent(m_wheelEventQueue, *nextCoalescedEvent.get());
1155     m_currentlyProcessedWheelEvents.append(nextCoalescedEvent.release());
1156     sendWheelEvent(nextWheelEvent);
1157 }
1158
1159 void WebPageProxy::sendWheelEvent(const WebWheelEvent& event)
1160 {
1161     process()->responsivenessTimer()->start();
1162
1163     if (m_shouldSendEventsSynchronously) {
1164         bool handled = false;
1165         process()->sendSync(Messages::WebPage::WheelEventSyncForTesting(event), Messages::WebPage::WheelEventSyncForTesting::Reply(handled), m_pageID);
1166         didReceiveEvent(event.type(), handled);
1167         return;
1168     }
1169
1170     process()->send(Messages::EventDispatcher::WheelEvent(m_pageID, event, canGoBack(), canGoForward()), 0);
1171 }
1172
1173 void WebPageProxy::handleKeyboardEvent(const NativeWebKeyboardEvent& event)
1174 {
1175     if (!isValid())
1176         return;
1177     
1178 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1179     if (isWaitingForJavaScriptPopupReply())
1180         return;
1181 #endif
1182
1183     LOG(KeyHandling, "WebPageProxy::handleKeyboardEvent: %s", webKeyboardEventTypeString(event.type()));
1184
1185     m_keyEventQueue.append(event);
1186
1187     process()->responsivenessTimer()->start();
1188     if (m_shouldSendEventsSynchronously) {
1189         bool handled = false;
1190         process()->sendSync(Messages::WebPage::KeyEventSyncForTesting(event), Messages::WebPage::KeyEventSyncForTesting::Reply(handled), m_pageID);
1191         didReceiveEvent(event.type(), handled);
1192     } else
1193         process()->send(Messages::WebPage::KeyEvent(event), m_pageID);
1194 }
1195
1196 #if ENABLE(GESTURE_EVENTS)
1197 void WebPageProxy::handleGestureEvent(const WebGestureEvent& event)
1198 {
1199     if (!isValid())
1200         return;
1201
1202     m_gestureEventQueue.append(event);
1203
1204     process()->responsivenessTimer()->start();
1205     process()->send(Messages::EventDispatcher::GestureEvent(m_pageID, event), 0);
1206 }
1207 #endif
1208
1209 #if ENABLE(TOUCH_EVENTS)
1210 #if PLATFORM(QT)
1211 void WebPageProxy::handlePotentialActivation(const IntPoint& touchPoint, const IntSize& touchArea)
1212 {
1213     process()->send(Messages::WebPage::HighlightPotentialActivation(touchPoint, touchArea), m_pageID);
1214 }
1215 #endif
1216
1217 void WebPageProxy::handleTouchEvent(const NativeWebTouchEvent& event)
1218 {
1219     if (!isValid())
1220         return;
1221
1222     // If the page is suspended, which should be the case during panning, pinching
1223     // and animation on the page itself (kinetic scrolling, tap to zoom) etc, then
1224     // we do not send any of the events to the page even if is has listeners.
1225     if (m_needTouchEvents && !m_isPageSuspended) {
1226 #if OS(TIZEN)
1227         // Do not send the TouchMove event if last TouchMove is not processed yet.
1228         // TouchMove event will be sent too many times without below codes,
1229         // and it will affect Web Applications' performance.
1230         if (event.type() == WebEvent::TouchMove
1231             && !m_touchEventQueue.isEmpty()
1232             && m_touchEventQueue.last().forwardedEvent.type() == event.type())
1233             return;
1234 #endif
1235         m_touchEventQueue.append(event);
1236         process()->responsivenessTimer()->start();
1237         if (m_shouldSendEventsSynchronously) {
1238             bool handled = false;
1239             process()->sendSync(Messages::WebPage::TouchEventSyncForTesting(event), Messages::WebPage::TouchEventSyncForTesting::Reply(handled), m_pageID);
1240             didReceiveEvent(event.type(), handled);
1241         } else
1242             process()->send(Messages::WebPage::TouchEvent(event), m_pageID);
1243     } else {
1244         if (m_touchEventQueue.isEmpty()) {
1245             bool isEventHandled = false;
1246             m_pageClient->doneWithTouchEvent(event, isEventHandled);
1247         } else {
1248             // We attach the incoming events to the newest queued event so that all
1249             // the events are delivered in the correct order when the event is dequed.
1250             QueuedTouchEvents& lastEvent = m_touchEventQueue.last();
1251             lastEvent.deferredTouchEvents.append(event);
1252         }
1253     }
1254 }
1255 #endif
1256
1257 #if ENABLE(TIZEN_VIBRATION)
1258 void WebPageProxy::vibrate(uint64_t time)
1259 {
1260     m_pageClient->vibrate(time);
1261 }
1262
1263 void WebPageProxy::cancelVibration()
1264 {
1265     m_pageClient->cancelVibration();
1266 }
1267 #endif
1268
1269 #if ENABLE(SCREEN_ORIENTATION_SUPPORT) && ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT)
1270 void WebPageProxy::lockOrientation(int willLockOrientation, bool& result)
1271 {
1272     result = m_pageClient->lockOrientation(willLockOrientation);
1273 }
1274 void WebPageProxy::unlockOrientation()
1275 {
1276     m_pageClient->unlockOrientation();
1277 }
1278 #endif
1279
1280 void WebPageProxy::scrollBy(ScrollDirection direction, ScrollGranularity granularity)
1281 {
1282     if (!isValid())
1283         return;
1284
1285     process()->send(Messages::WebPage::ScrollBy(direction, granularity), m_pageID);
1286 }
1287
1288 void WebPageProxy::centerSelectionInVisibleArea()
1289 {
1290     if (!isValid())
1291         return;
1292
1293     process()->send(Messages::WebPage::CenterSelectionInVisibleArea(), m_pageID);
1294 }
1295
1296 void WebPageProxy::receivedPolicyDecision(PolicyAction action, WebFrameProxy* frame, uint64_t listenerID)
1297 {
1298     if (!isValid())
1299         return;
1300
1301     if (action == PolicyIgnore)
1302         clearPendingAPIRequestURL();
1303
1304     uint64_t downloadID = 0;
1305     if (action == PolicyDownload) {
1306         // Create a download proxy.
1307         DownloadProxy* download = m_process->context()->createDownloadProxy();
1308         downloadID = download->downloadID();
1309 #if PLATFORM(QT)
1310         // Our design does not suppport downloads without a WebPage.
1311         handleDownloadRequest(download);
1312 #endif
1313     }
1314
1315     // If we received a policy decision while in decidePolicyForResponse the decision will
1316     // be sent back to the web process by decidePolicyForResponse.
1317     if (m_inDecidePolicyForResponse) {
1318         m_syncMimeTypePolicyActionIsValid = true;
1319         m_syncMimeTypePolicyAction = action;
1320         m_syncMimeTypePolicyDownloadID = downloadID;
1321         return;
1322     }
1323
1324     // If we received a policy decision while in decidePolicyForNavigationAction the decision will 
1325     // be sent back to the web process by decidePolicyForNavigationAction. 
1326     if (m_inDecidePolicyForNavigationAction) {
1327         m_syncNavigationActionPolicyActionIsValid = true;
1328         m_syncNavigationActionPolicyAction = action;
1329         m_syncNavigationActionPolicyDownloadID = downloadID;
1330         return;
1331     }
1332     
1333     process()->send(Messages::WebPage::DidReceivePolicyDecision(frame->frameID(), listenerID, action, downloadID), m_pageID);
1334 }
1335
1336 String WebPageProxy::pageTitle() const
1337 {
1338     // Return the null string if there is no main frame (e.g. nothing has been loaded in the page yet, WebProcess has
1339     // crashed, page has been closed).
1340     if (!m_mainFrame)
1341         return String();
1342
1343     return m_mainFrame->title();
1344 }
1345
1346 void WebPageProxy::setUserAgent(const String& userAgent)
1347 {
1348     if (m_userAgent == userAgent)
1349         return;
1350     m_userAgent = userAgent;
1351
1352     if (!isValid())
1353         return;
1354     process()->send(Messages::WebPage::SetUserAgent(m_userAgent), m_pageID);
1355 }
1356
1357 void WebPageProxy::setApplicationNameForUserAgent(const String& applicationName)
1358 {
1359     if (m_applicationNameForUserAgent == applicationName)
1360         return;
1361
1362     m_applicationNameForUserAgent = applicationName;
1363     if (!m_customUserAgent.isEmpty())
1364         return;
1365
1366     setUserAgent(standardUserAgent(m_applicationNameForUserAgent));
1367 }
1368
1369 void WebPageProxy::setCustomUserAgent(const String& customUserAgent)
1370 {
1371     if (m_customUserAgent == customUserAgent)
1372         return;
1373
1374     m_customUserAgent = customUserAgent;
1375
1376     if (m_customUserAgent.isEmpty()) {
1377         setUserAgent(standardUserAgent(m_applicationNameForUserAgent));
1378         return;
1379     }
1380
1381     setUserAgent(m_customUserAgent);
1382 }
1383
1384 void WebPageProxy::resumeActiveDOMObjectsAndAnimations()
1385 {
1386     if (!isValid() || !m_isPageSuspended)
1387         return;
1388
1389     m_isPageSuspended = false;
1390
1391     process()->send(Messages::WebPage::ResumeActiveDOMObjectsAndAnimations(), m_pageID);
1392 }
1393
1394 void WebPageProxy::suspendActiveDOMObjectsAndAnimations()
1395 {
1396     if (!isValid() || m_isPageSuspended)
1397         return;
1398
1399     m_isPageSuspended = true;
1400
1401     process()->send(Messages::WebPage::SuspendActiveDOMObjectsAndAnimations(), m_pageID);
1402 }
1403
1404 bool WebPageProxy::supportsTextEncoding() const
1405 {
1406     return !m_mainFrameHasCustomRepresentation && m_mainFrame && !m_mainFrame->isDisplayingStandaloneImageDocument();
1407 }
1408
1409 void WebPageProxy::setCustomTextEncodingName(const String& encodingName)
1410 {
1411     if (m_customTextEncodingName == encodingName)
1412         return;
1413     m_customTextEncodingName = encodingName;
1414
1415     if (!isValid())
1416         return;
1417     process()->send(Messages::WebPage::SetCustomTextEncodingName(encodingName), m_pageID);
1418 }
1419
1420 void WebPageProxy::terminateProcess()
1421 {
1422     // NOTE: This uses a check of m_isValid rather than calling isValid() since
1423     // we want this to run even for pages being closed or that already closed.
1424     if (!m_isValid)
1425         return;
1426
1427     process()->terminate();
1428 }
1429
1430 #if !USE(CF) || defined(BUILDING_QT__)
1431 PassRefPtr<WebData> WebPageProxy::sessionStateData(WebPageProxySessionStateFilterCallback, void* context) const
1432 {
1433     // FIXME: Return session state data for saving Page state.
1434     return 0;
1435 }
1436
1437 void WebPageProxy::restoreFromSessionStateData(WebData*)
1438 {
1439     // FIXME: Restore the Page from the passed in session state data.
1440 }
1441 #endif
1442
1443 bool WebPageProxy::supportsTextZoom() const
1444 {
1445     if (m_mainFrameHasCustomRepresentation)
1446         return false;
1447
1448     // FIXME: This should also return false for standalone media and plug-in documents.
1449     if (!m_mainFrame || m_mainFrame->isDisplayingStandaloneImageDocument())
1450         return false;
1451
1452     return true;
1453 }
1454  
1455 void WebPageProxy::setTextZoomFactor(double zoomFactor)
1456 {
1457     if (!isValid())
1458         return;
1459
1460     if (m_mainFrameHasCustomRepresentation)
1461         return;
1462
1463     if (m_textZoomFactor == zoomFactor)
1464         return;
1465
1466     m_textZoomFactor = zoomFactor;
1467     process()->send(Messages::WebPage::SetTextZoomFactor(m_textZoomFactor), m_pageID); 
1468 }
1469
1470 double WebPageProxy::pageZoomFactor() const
1471 {
1472     return m_mainFrameHasCustomRepresentation ? m_pageClient->customRepresentationZoomFactor() : m_pageZoomFactor;
1473 }
1474
1475 void WebPageProxy::setPageZoomFactor(double zoomFactor)
1476 {
1477     if (!isValid())
1478         return;
1479
1480     if (m_mainFrameHasCustomRepresentation) {
1481         m_pageClient->setCustomRepresentationZoomFactor(zoomFactor);
1482         return;
1483     }
1484
1485     if (m_pageZoomFactor == zoomFactor)
1486         return;
1487
1488     m_pageZoomFactor = zoomFactor;
1489     process()->send(Messages::WebPage::SetPageZoomFactor(m_pageZoomFactor), m_pageID); 
1490 }
1491
1492 void WebPageProxy::setPageAndTextZoomFactors(double pageZoomFactor, double textZoomFactor)
1493 {
1494     if (!isValid())
1495         return;
1496
1497     if (m_mainFrameHasCustomRepresentation) {
1498         m_pageClient->setCustomRepresentationZoomFactor(pageZoomFactor);
1499         return;
1500     }
1501
1502     if (m_pageZoomFactor == pageZoomFactor && m_textZoomFactor == textZoomFactor)
1503         return;
1504
1505     m_pageZoomFactor = pageZoomFactor;
1506     m_textZoomFactor = textZoomFactor;
1507     process()->send(Messages::WebPage::SetPageAndTextZoomFactors(m_pageZoomFactor, m_textZoomFactor), m_pageID); 
1508 }
1509
1510 void WebPageProxy::scalePage(double scale, const IntPoint& origin)
1511 {
1512     if (!isValid())
1513         return;
1514
1515     process()->send(Messages::WebPage::ScalePage(scale, origin), m_pageID);
1516 #if OS(TIZEN)
1517     m_pageClient->setRequestedScaleFactor(scale);
1518 #endif
1519 }
1520
1521 void WebPageProxy::setIntrinsicDeviceScaleFactor(float scaleFactor)
1522 {
1523     if (m_intrinsicDeviceScaleFactor == scaleFactor)
1524         return;
1525
1526     m_intrinsicDeviceScaleFactor = scaleFactor;
1527
1528     if (m_drawingArea)
1529         m_drawingArea->deviceScaleFactorDidChange();
1530 }
1531
1532 void WebPageProxy::windowScreenDidChange(PlatformDisplayID displayID)
1533 {
1534     if (!isValid())
1535         return;
1536
1537     process()->send(Messages::WebPage::WindowScreenDidChange(displayID), m_pageID);
1538 }
1539
1540 float WebPageProxy::deviceScaleFactor() const
1541 {
1542     if (m_customDeviceScaleFactor)
1543         return m_customDeviceScaleFactor;
1544     return m_intrinsicDeviceScaleFactor;
1545 }
1546
1547 void WebPageProxy::setCustomDeviceScaleFactor(float customScaleFactor)
1548 {
1549     if (!isValid())
1550         return;
1551
1552     if (m_customDeviceScaleFactor == customScaleFactor)
1553         return;
1554
1555     float oldScaleFactor = deviceScaleFactor();
1556
1557     m_customDeviceScaleFactor = customScaleFactor;
1558
1559     if (deviceScaleFactor() != oldScaleFactor)
1560         m_drawingArea->deviceScaleFactorDidChange();
1561 }
1562
1563 void WebPageProxy::setUseFixedLayout(bool fixed)
1564 {
1565     if (!isValid())
1566         return;
1567
1568     // This check is fine as the value is initialized in the web
1569     // process as part of the creation parameters.
1570     if (fixed == m_useFixedLayout)
1571         return;
1572
1573     m_useFixedLayout = fixed;
1574     if (!fixed)
1575         m_fixedLayoutSize = IntSize();
1576     process()->send(Messages::WebPage::SetUseFixedLayout(fixed), m_pageID);
1577 }
1578
1579 void WebPageProxy::setFixedLayoutSize(const IntSize& size)
1580 {
1581     if (!isValid())
1582         return;
1583
1584     if (size == m_fixedLayoutSize)
1585         return;
1586
1587     m_fixedLayoutSize = size;
1588     process()->send(Messages::WebPage::SetFixedLayoutSize(size), m_pageID);
1589 }
1590
1591 void WebPageProxy::setPaginationMode(WebCore::Page::Pagination::Mode mode)
1592 {
1593     if (mode == m_paginationMode)
1594         return;
1595
1596     m_paginationMode = mode;
1597
1598     if (!isValid())
1599         return;
1600     process()->send(Messages::WebPage::SetPaginationMode(mode), m_pageID);
1601 }
1602
1603 void WebPageProxy::setPaginationBehavesLikeColumns(bool behavesLikeColumns)
1604 {
1605     if (behavesLikeColumns == m_paginationBehavesLikeColumns)
1606         return;
1607
1608     m_paginationBehavesLikeColumns = behavesLikeColumns;
1609
1610     if (!isValid())
1611         return;
1612     process()->send(Messages::WebPage::SetPaginationBehavesLikeColumns(behavesLikeColumns), m_pageID);
1613 }
1614
1615 void WebPageProxy::setPageLength(double pageLength)
1616 {
1617     if (pageLength == m_pageLength)
1618         return;
1619
1620     m_pageLength = pageLength;
1621
1622     if (!isValid())
1623         return;
1624     process()->send(Messages::WebPage::SetPageLength(pageLength), m_pageID);
1625 }
1626
1627 void WebPageProxy::setGapBetweenPages(double gap)
1628 {
1629     if (gap == m_gapBetweenPages)
1630         return;
1631
1632     m_gapBetweenPages = gap;
1633
1634     if (!isValid())
1635         return;
1636     process()->send(Messages::WebPage::SetGapBetweenPages(gap), m_pageID);
1637 }
1638
1639 void WebPageProxy::pageScaleFactorDidChange(double scaleFactor)
1640 {
1641     m_pageScaleFactor = scaleFactor;
1642     m_pageClient->pageScaleFactorDidChange();
1643 }
1644
1645 void WebPageProxy::setMemoryCacheClientCallsEnabled(bool memoryCacheClientCallsEnabled)
1646 {
1647     if (!isValid())
1648         return;
1649
1650     if (m_areMemoryCacheClientCallsEnabled == memoryCacheClientCallsEnabled)
1651         return;
1652
1653     m_areMemoryCacheClientCallsEnabled = memoryCacheClientCallsEnabled;
1654     process()->send(Messages::WebPage::SetMemoryCacheMessagesEnabled(memoryCacheClientCallsEnabled), m_pageID);
1655 }
1656
1657 void WebPageProxy::findString(const String& string, FindOptions options, unsigned maxMatchCount)
1658 {
1659     if (m_mainFrameHasCustomRepresentation)
1660         m_pageClient->findStringInCustomRepresentation(string, options, maxMatchCount);
1661     else
1662         process()->send(Messages::WebPage::FindString(string, options, maxMatchCount), m_pageID);
1663 }
1664
1665 void WebPageProxy::hideFindUI()
1666 {
1667     process()->send(Messages::WebPage::HideFindUI(), m_pageID);
1668 }
1669
1670 void WebPageProxy::countStringMatches(const String& string, FindOptions options, unsigned maxMatchCount)
1671 {
1672     if (m_mainFrameHasCustomRepresentation) {
1673         m_pageClient->countStringMatchesInCustomRepresentation(string, options, maxMatchCount);
1674         return;
1675     }
1676
1677     if (!isValid())
1678         return;
1679
1680     process()->send(Messages::WebPage::CountStringMatches(string, options, maxMatchCount), m_pageID);
1681 }
1682
1683 void WebPageProxy::runJavaScriptInMainFrame(const String& script, PassRefPtr<ScriptValueCallback> prpCallback)
1684 {
1685     RefPtr<ScriptValueCallback> callback = prpCallback;
1686     if (!isValid()) {
1687         callback->invalidate();
1688         return;
1689     }
1690
1691     uint64_t callbackID = callback->callbackID();
1692     m_scriptValueCallbacks.set(callbackID, callback.get());
1693     process()->send(Messages::WebPage::RunJavaScriptInMainFrame(script, callbackID), m_pageID);
1694 }
1695
1696 void WebPageProxy::getRenderTreeExternalRepresentation(PassRefPtr<StringCallback> prpCallback)
1697 {
1698     RefPtr<StringCallback> callback = prpCallback;
1699     if (!isValid()) {
1700         callback->invalidate();
1701         return;
1702     }
1703     
1704     uint64_t callbackID = callback->callbackID();
1705     m_stringCallbacks.set(callbackID, callback.get());
1706     process()->send(Messages::WebPage::GetRenderTreeExternalRepresentation(callbackID), m_pageID);
1707 }
1708
1709 void WebPageProxy::getSourceForFrame(WebFrameProxy* frame, PassRefPtr<StringCallback> prpCallback)
1710 {
1711     RefPtr<StringCallback> callback = prpCallback;
1712     if (!isValid()) {
1713         callback->invalidate();
1714         return;
1715     }
1716     
1717     uint64_t callbackID = callback->callbackID();
1718     m_loadDependentStringCallbackIDs.add(callbackID);
1719     m_stringCallbacks.set(callbackID, callback.get());
1720     process()->send(Messages::WebPage::GetSourceForFrame(frame->frameID(), callbackID), m_pageID);
1721 }
1722
1723 void WebPageProxy::getContentsAsString(PassRefPtr<StringCallback> prpCallback)
1724 {
1725     RefPtr<StringCallback> callback = prpCallback;
1726     if (!isValid()) {
1727         callback->invalidate();
1728         return;
1729     }
1730     
1731     uint64_t callbackID = callback->callbackID();
1732     m_loadDependentStringCallbackIDs.add(callbackID);
1733     m_stringCallbacks.set(callbackID, callback.get());
1734     process()->send(Messages::WebPage::GetContentsAsString(callbackID), m_pageID);
1735 }
1736
1737 void WebPageProxy::getSelectionOrContentsAsString(PassRefPtr<StringCallback> prpCallback)
1738 {
1739     RefPtr<StringCallback> callback = prpCallback;
1740     if (!isValid()) {
1741         callback->invalidate();
1742         return;
1743     }
1744     
1745     uint64_t callbackID = callback->callbackID();
1746     m_stringCallbacks.set(callbackID, callback.get());
1747     process()->send(Messages::WebPage::GetSelectionOrContentsAsString(callbackID), m_pageID);
1748 }
1749
1750 void WebPageProxy::getMainResourceDataOfFrame(WebFrameProxy* frame, PassRefPtr<DataCallback> prpCallback)
1751 {
1752     RefPtr<DataCallback> callback = prpCallback;
1753     if (!isValid()) {
1754         callback->invalidate();
1755         return;
1756     }
1757     
1758     uint64_t callbackID = callback->callbackID();
1759     m_dataCallbacks.set(callbackID, callback.get());
1760     process()->send(Messages::WebPage::GetMainResourceDataOfFrame(frame->frameID(), callbackID), m_pageID);
1761 }
1762
1763 void WebPageProxy::getResourceDataFromFrame(WebFrameProxy* frame, WebURL* resourceURL, PassRefPtr<DataCallback> prpCallback)
1764 {
1765     RefPtr<DataCallback> callback = prpCallback;
1766     if (!isValid()) {
1767         callback->invalidate();
1768         return;
1769     }
1770     
1771     uint64_t callbackID = callback->callbackID();
1772     m_dataCallbacks.set(callbackID, callback.get());
1773     process()->send(Messages::WebPage::GetResourceDataFromFrame(frame->frameID(), resourceURL->string(), callbackID), m_pageID);
1774 }
1775
1776 void WebPageProxy::getWebArchiveOfFrame(WebFrameProxy* frame, PassRefPtr<DataCallback> prpCallback)
1777 {
1778     RefPtr<DataCallback> callback = prpCallback;
1779     if (!isValid()) {
1780         callback->invalidate();
1781         return;
1782     }
1783     
1784     uint64_t callbackID = callback->callbackID();
1785     m_dataCallbacks.set(callbackID, callback.get());
1786     process()->send(Messages::WebPage::GetWebArchiveOfFrame(frame->frameID(), callbackID), m_pageID);
1787 }
1788
1789 void WebPageProxy::forceRepaint(PassRefPtr<VoidCallback> prpCallback)
1790 {
1791     RefPtr<VoidCallback> callback = prpCallback;
1792     if (!isValid()) {
1793         callback->invalidate();
1794         return;
1795     }
1796
1797     uint64_t callbackID = callback->callbackID();
1798     m_voidCallbacks.set(callbackID, callback.get());
1799     m_drawingArea->waitForBackingStoreUpdateOnNextPaint();
1800     process()->send(Messages::WebPage::ForceRepaint(callbackID), m_pageID); 
1801 }
1802
1803 void WebPageProxy::preferencesDidChange()
1804 {
1805     if (!isValid())
1806         return;
1807
1808 #if ENABLE(INSPECTOR_SERVER)
1809     if (m_pageGroup->preferences()->developerExtrasEnabled())
1810         inspector()->enableRemoteInspection();
1811 #endif
1812
1813     // FIXME: It probably makes more sense to send individual preference changes.
1814     // However, WebKitTestRunner depends on getting a preference change notification
1815     // even if nothing changed in UI process, so that overrides get removed.
1816
1817     // Preferences need to be updated during synchronous printing to make "print backgrounds" preference work when toggled from a print dialog checkbox.
1818     process()->send(Messages::WebPage::PreferencesDidChange(pageGroup()->preferences()->store()), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
1819 }
1820
1821 void WebPageProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
1822 {
1823     if (messageID.is<CoreIPC::MessageClassDrawingAreaProxy>()) {
1824         m_drawingArea->didReceiveDrawingAreaProxyMessage(connection, messageID, arguments);
1825         return;
1826     }
1827
1828 #if USE(UI_SIDE_COMPOSITING)
1829     if (messageID.is<CoreIPC::MessageClassLayerTreeHostProxy>()) {
1830         m_drawingArea->didReceiveLayerTreeHostProxyMessage(connection, messageID, arguments);
1831         return;
1832     }
1833 #endif
1834
1835 #if ENABLE(INSPECTOR)
1836     if (messageID.is<CoreIPC::MessageClassWebInspectorProxy>()) {
1837         if (WebInspectorProxy* inspector = this->inspector())
1838             inspector->didReceiveWebInspectorProxyMessage(connection, messageID, arguments);
1839         return;
1840     }
1841 #endif
1842
1843 #if ENABLE(FULLSCREEN_API)
1844     if (messageID.is<CoreIPC::MessageClassWebFullScreenManagerProxy>()) {
1845         fullScreenManager()->didReceiveMessage(connection, messageID, arguments);
1846         return;
1847     }
1848 #endif
1849
1850     didReceiveWebPageProxyMessage(connection, messageID, arguments);
1851 }
1852
1853 void WebPageProxy::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, OwnPtr<CoreIPC::ArgumentEncoder>& reply)
1854 {
1855 #if ENABLE(INSPECTOR)
1856     if (messageID.is<CoreIPC::MessageClassWebInspectorProxy>()) {
1857         if (WebInspectorProxy* inspector = this->inspector())
1858             inspector->didReceiveSyncWebInspectorProxyMessage(connection, messageID, arguments, reply);
1859         return;
1860     }
1861 #endif
1862
1863 #if ENABLE(FULLSCREEN_API)
1864     if (messageID.is<CoreIPC::MessageClassWebFullScreenManagerProxy>()) {
1865         fullScreenManager()->didReceiveSyncMessage(connection, messageID, arguments, reply);
1866         return;
1867     }
1868 #endif
1869
1870     // FIXME: Do something with reply.
1871     didReceiveSyncWebPageProxyMessage(connection, messageID, arguments, reply);
1872 }
1873
1874 void WebPageProxy::didCreateMainFrame(uint64_t frameID)
1875 {
1876     MESSAGE_CHECK(!m_mainFrame);
1877     MESSAGE_CHECK(process()->canCreateFrame(frameID));
1878
1879     m_mainFrame = WebFrameProxy::create(this, frameID);
1880
1881     // Add the frame to the process wide map.
1882     process()->frameCreated(frameID, m_mainFrame.get());
1883 }
1884
1885 void WebPageProxy::didCreateSubframe(uint64_t frameID, uint64_t parentFrameID)
1886 {
1887     MESSAGE_CHECK(m_mainFrame);
1888
1889     WebFrameProxy* parentFrame = process()->webFrame(parentFrameID);
1890     MESSAGE_CHECK(parentFrame);
1891     MESSAGE_CHECK(parentFrame->isDescendantOf(m_mainFrame.get()));
1892
1893     MESSAGE_CHECK(process()->canCreateFrame(frameID));
1894     
1895     RefPtr<WebFrameProxy> subFrame = WebFrameProxy::create(this, frameID);
1896
1897     // Add the frame to the process wide map.
1898     process()->frameCreated(frameID, subFrame.get());
1899
1900     // Insert the frame into the frame hierarchy.
1901     parentFrame->appendChild(subFrame.get());
1902 }
1903
1904 static bool isDisconnectedFrame(WebFrameProxy* frame)
1905 {
1906     return !frame->page() || !frame->page()->mainFrame() || !frame->isDescendantOf(frame->page()->mainFrame());
1907 }
1908
1909 void WebPageProxy::didSaveFrameToPageCache(uint64_t frameID)
1910 {
1911     MESSAGE_CHECK(m_mainFrame);
1912
1913     WebFrameProxy* subframe = process()->webFrame(frameID);
1914     MESSAGE_CHECK(subframe);
1915
1916     if (isDisconnectedFrame(subframe))
1917         return;
1918
1919     MESSAGE_CHECK(subframe->isDescendantOf(m_mainFrame.get()));
1920
1921     subframe->didRemoveFromHierarchy();
1922 }
1923
1924 void WebPageProxy::didRestoreFrameFromPageCache(uint64_t frameID, uint64_t parentFrameID)
1925 {
1926     MESSAGE_CHECK(m_mainFrame);
1927
1928     WebFrameProxy* subframe = process()->webFrame(frameID);
1929     MESSAGE_CHECK(subframe);
1930     MESSAGE_CHECK(!subframe->parentFrame());
1931     MESSAGE_CHECK(subframe->page() == m_mainFrame->page());
1932
1933     WebFrameProxy* parentFrame = process()->webFrame(parentFrameID);
1934     MESSAGE_CHECK(parentFrame);
1935     MESSAGE_CHECK(parentFrame->isDescendantOf(m_mainFrame.get()));
1936
1937     // Insert the frame into the frame hierarchy.
1938     parentFrame->appendChild(subframe);
1939 }
1940
1941
1942 // Always start progress at initialProgressValue. This helps provide feedback as
1943 // soon as a load starts.
1944
1945 static const double initialProgressValue = 0.1;
1946
1947 double WebPageProxy::estimatedProgress() const
1948 {
1949     if (!pendingAPIRequestURL().isNull())
1950         return initialProgressValue;
1951     return m_estimatedProgress; 
1952 }
1953
1954 void WebPageProxy::didStartProgress()
1955 {
1956     m_estimatedProgress = initialProgressValue;
1957
1958 #if OS(TIZEN)
1959     //FIXME: After ewk_view_loader_client is implemented,
1960     // consider this line to move to loaderClient.
1961     m_pageClient->didStartProgress();
1962 #endif
1963
1964     m_loaderClient.didStartProgress(this);
1965 }
1966
1967 void WebPageProxy::didChangeProgress(double value)
1968 {
1969     m_estimatedProgress = value;
1970
1971     m_loaderClient.didChangeProgress(this);
1972 }
1973
1974 void WebPageProxy::didFinishProgress()
1975 {
1976     m_estimatedProgress = 1.0;
1977
1978 #if OS(TIZEN)
1979     //FIXME: consider to move this to loaderClient.
1980     m_pageClient->didFinishProgress();
1981 #endif
1982
1983     m_loaderClient.didFinishProgress(this);
1984 }
1985
1986 void WebPageProxy::didStartProvisionalLoadForFrame(uint64_t frameID, const String& url, const String& unreachableURL, CoreIPC::ArgumentDecoder* arguments)
1987 {
1988     clearPendingAPIRequestURL();
1989
1990     RefPtr<APIObject> userData;
1991     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
1992     if (!arguments->decode(messageDecoder))
1993         return;
1994
1995     WebFrameProxy* frame = process()->webFrame(frameID);
1996     MESSAGE_CHECK(frame);
1997     MESSAGE_CHECK_URL(url);
1998
1999     frame->setUnreachableURL(unreachableURL);
2000
2001     frame->didStartProvisionalLoad(url);
2002     m_loaderClient.didStartProvisionalLoadForFrame(this, frame, userData.get());
2003 }
2004
2005 void WebPageProxy::didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, const String& url, CoreIPC::ArgumentDecoder* arguments)
2006 {
2007     RefPtr<APIObject> userData;
2008     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2009     if (!arguments->decode(messageDecoder))
2010         return;
2011
2012     WebFrameProxy* frame = process()->webFrame(frameID);
2013     MESSAGE_CHECK(frame);
2014     MESSAGE_CHECK_URL(url);
2015
2016     frame->didReceiveServerRedirectForProvisionalLoad(url);
2017
2018     m_loaderClient.didReceiveServerRedirectForProvisionalLoadForFrame(this, frame, userData.get());
2019 }
2020
2021 void WebPageProxy::didFailProvisionalLoadForFrame(uint64_t frameID, const ResourceError& error, CoreIPC::ArgumentDecoder* arguments)
2022 {
2023     RefPtr<APIObject> userData;
2024     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2025     if (!arguments->decode(messageDecoder))
2026         return;
2027
2028     WebFrameProxy* frame = process()->webFrame(frameID);
2029     MESSAGE_CHECK(frame);
2030
2031     frame->didFailProvisionalLoad();
2032
2033     m_loaderClient.didFailProvisionalLoadWithErrorForFrame(this, frame, error, userData.get());
2034 }
2035
2036 void WebPageProxy::clearLoadDependentCallbacks()
2037 {
2038     Vector<uint64_t> callbackIDsCopy;
2039     copyToVector(m_loadDependentStringCallbackIDs, callbackIDsCopy);
2040     m_loadDependentStringCallbackIDs.clear();
2041
2042     for (size_t i = 0; i < callbackIDsCopy.size(); ++i) {
2043         RefPtr<StringCallback> callback = m_stringCallbacks.take(callbackIDsCopy[i]);
2044         if (callback)
2045             callback->invalidate();
2046     }
2047 }
2048
2049 void WebPageProxy::didCommitLoadForFrame(uint64_t frameID, const String& mimeType, bool frameHasCustomRepresentation, const PlatformCertificateInfo& certificateInfo, CoreIPC::ArgumentDecoder* arguments)
2050 {
2051     RefPtr<APIObject> userData;
2052     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2053     if (!arguments->decode(messageDecoder))
2054         return;
2055
2056     WebFrameProxy* frame = process()->webFrame(frameID);
2057     MESSAGE_CHECK(frame);
2058
2059 #if PLATFORM(MAC)
2060     // FIXME (bug 59111): didCommitLoadForFrame comes too late when restoring a page from b/f cache, making us disable secure event mode in password fields.
2061     // FIXME (bug 59121): A load going on in one frame shouldn't affect typing in sibling frames.
2062     m_pageClient->resetTextInputState();
2063 #if !defined(BUILDING_ON_SNOW_LEOPARD)
2064     // FIXME: Should this be moved inside resetTextInputState()?
2065     dismissCorrectionPanel(ReasonForDismissingAlternativeTextIgnored);
2066     m_pageClient->dismissDictionaryLookupPanel();
2067 #endif
2068 #endif
2069
2070     clearLoadDependentCallbacks();
2071
2072     frame->didCommitLoad(mimeType, certificateInfo);
2073
2074     if (frame->isMainFrame()) {
2075         m_mainFrameHasCustomRepresentation = frameHasCustomRepresentation;
2076
2077         if (m_mainFrameHasCustomRepresentation) {
2078             // Always assume that the main frame is pinned here, since the custom representation view will handle
2079             // any wheel events and dispatch them to the WKView when necessary.
2080             m_mainFrameIsPinnedToLeftSide = true;
2081             m_mainFrameIsPinnedToRightSide = true;
2082         }
2083         m_pageClient->didCommitLoadForMainFrame(frameHasCustomRepresentation);
2084     }
2085
2086     m_loaderClient.didCommitLoadForFrame(this, frame, userData.get());
2087 }
2088
2089 void WebPageProxy::didFinishDocumentLoadForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
2090 {
2091     RefPtr<APIObject> userData;
2092     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2093     if (!arguments->decode(messageDecoder))
2094         return;
2095
2096     WebFrameProxy* frame = process()->webFrame(frameID);
2097     MESSAGE_CHECK(frame);
2098
2099     m_loaderClient.didFinishDocumentLoadForFrame(this, frame, userData.get());
2100 }
2101
2102 void WebPageProxy::didFinishLoadForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
2103 {
2104     RefPtr<APIObject> userData;
2105     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2106     if (!arguments->decode(messageDecoder))
2107         return;
2108
2109     WebFrameProxy* frame = process()->webFrame(frameID);
2110     MESSAGE_CHECK(frame);
2111
2112     frame->didFinishLoad();
2113
2114 #if OS(TIZEN)
2115     if (frame->isMainFrame())
2116         m_pageClient->didFinishLoadForMainFrame();
2117 #endif
2118
2119     m_loaderClient.didFinishLoadForFrame(this, frame, userData.get());
2120 }
2121
2122 void WebPageProxy::didFailLoadForFrame(uint64_t frameID, const ResourceError& error, CoreIPC::ArgumentDecoder* arguments)
2123 {
2124     RefPtr<APIObject> userData;
2125     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2126     if (!arguments->decode(messageDecoder))
2127         return;
2128
2129     WebFrameProxy* frame = process()->webFrame(frameID);
2130     MESSAGE_CHECK(frame);
2131
2132     clearLoadDependentCallbacks();
2133
2134     frame->didFailLoad();
2135
2136     m_loaderClient.didFailLoadWithErrorForFrame(this, frame, error, userData.get());
2137 }
2138
2139 void WebPageProxy::didSameDocumentNavigationForFrame(uint64_t frameID, uint32_t opaqueSameDocumentNavigationType, const String& url, CoreIPC::ArgumentDecoder* arguments)
2140 {
2141     RefPtr<APIObject> userData;
2142     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2143     if (!arguments->decode(messageDecoder))
2144         return;
2145
2146     WebFrameProxy* frame = process()->webFrame(frameID);
2147     MESSAGE_CHECK(frame);
2148     MESSAGE_CHECK_URL(url);
2149
2150     clearPendingAPIRequestURL();
2151     frame->didSameDocumentNavigation(url);
2152
2153 #if ENABLE(TIZEN_ISF_PORT)
2154     if (m_pageClient->getInputMethodState()) {
2155         LOG(ISF, "%s\n", __func__);
2156         setInputMethodState(false, String(), String());
2157     }
2158 #endif
2159
2160     m_loaderClient.didSameDocumentNavigationForFrame(this, frame, static_cast<SameDocumentNavigationType>(opaqueSameDocumentNavigationType), userData.get());
2161 }
2162
2163 void WebPageProxy::didReceiveTitleForFrame(uint64_t frameID, const String& title, CoreIPC::ArgumentDecoder* arguments)
2164 {
2165     RefPtr<APIObject> userData;
2166     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2167     if (!arguments->decode(messageDecoder))
2168         return;
2169
2170     WebFrameProxy* frame = process()->webFrame(frameID);
2171     MESSAGE_CHECK(frame);
2172
2173     frame->didChangeTitle(title);
2174     
2175     m_loaderClient.didReceiveTitleForFrame(this, title, frame, userData.get());
2176 }
2177
2178 void WebPageProxy::didFirstLayoutForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
2179 {
2180     RefPtr<APIObject> userData;
2181     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2182     if (!arguments->decode(messageDecoder))
2183         return;
2184
2185     WebFrameProxy* frame = process()->webFrame(frameID);
2186     MESSAGE_CHECK(frame);
2187
2188     m_loaderClient.didFirstLayoutForFrame(this, frame, userData.get());
2189 }
2190
2191 void WebPageProxy::didFirstVisuallyNonEmptyLayoutForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
2192 {
2193     RefPtr<APIObject> userData;
2194     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2195     if (!arguments->decode(messageDecoder))
2196         return;
2197
2198     WebFrameProxy* frame = process()->webFrame(frameID);
2199     MESSAGE_CHECK(frame);
2200
2201 #if OS(TIZEN)
2202     if (frame->isMainFrame())
2203         m_pageClient->didFirstVisuallyNonEmptyLayoutForMainFrame();
2204 #endif
2205
2206     m_loaderClient.didFirstVisuallyNonEmptyLayoutForFrame(this, frame, userData.get());
2207 }
2208
2209 void WebPageProxy::didNewFirstVisuallyNonEmptyLayout(CoreIPC::ArgumentDecoder* arguments)
2210 {
2211     RefPtr<APIObject> userData;
2212     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2213     if (!arguments->decode(messageDecoder))
2214         return;
2215
2216     m_loaderClient.didNewFirstVisuallyNonEmptyLayout(this, userData.get());
2217 }
2218
2219 void WebPageProxy::didRemoveFrameFromHierarchy(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
2220 {
2221     RefPtr<APIObject> userData;
2222     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2223     if (!arguments->decode(messageDecoder))
2224         return;
2225
2226     WebFrameProxy* frame = process()->webFrame(frameID);
2227     MESSAGE_CHECK(frame);
2228
2229     frame->didRemoveFromHierarchy();
2230
2231     m_loaderClient.didRemoveFrameFromHierarchy(this, frame, userData.get());
2232 }
2233
2234 void WebPageProxy::didDisplayInsecureContentForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
2235 {
2236     RefPtr<APIObject> userData;
2237     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2238     if (!arguments->decode(messageDecoder))
2239         return;
2240
2241     WebFrameProxy* frame = process()->webFrame(frameID);
2242     MESSAGE_CHECK(frame);
2243
2244     m_loaderClient.didDisplayInsecureContentForFrame(this, frame, userData.get());
2245 }
2246
2247 void WebPageProxy::didRunInsecureContentForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
2248 {
2249     RefPtr<APIObject> userData;
2250     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2251     if (!arguments->decode(messageDecoder))
2252         return;
2253
2254     WebFrameProxy* frame = process()->webFrame(frameID);
2255     MESSAGE_CHECK(frame);
2256
2257     m_loaderClient.didRunInsecureContentForFrame(this, frame, userData.get());
2258 }
2259
2260 void WebPageProxy::didDetectXSSForFrame(uint64_t frameID, CoreIPC::ArgumentDecoder* arguments)
2261 {
2262     RefPtr<APIObject> userData;
2263     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2264     if (!arguments->decode(messageDecoder))
2265         return;
2266
2267     WebFrameProxy* frame = process()->webFrame(frameID);
2268     MESSAGE_CHECK(frame);
2269
2270     m_loaderClient.didDetectXSSForFrame(this, frame, userData.get());
2271 }
2272
2273 void WebPageProxy::frameDidBecomeFrameSet(uint64_t frameID, bool value)
2274 {
2275     WebFrameProxy* frame = process()->webFrame(frameID);
2276     MESSAGE_CHECK(frame);
2277
2278     frame->setIsFrameSet(value);
2279     if (frame->isMainFrame())
2280         m_frameSetLargestFrame = value ? m_mainFrame : 0;
2281 }
2282
2283 // PolicyClient
2284 void WebPageProxy::decidePolicyForNavigationAction(uint64_t frameID, uint32_t opaqueNavigationType, uint32_t opaqueModifiers, int32_t opaqueMouseButton, const ResourceRequest& request, uint64_t listenerID, CoreIPC::ArgumentDecoder* arguments, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID)
2285 {
2286     RefPtr<APIObject> userData;
2287     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2288     if (!arguments->decode(messageDecoder))
2289         return;
2290
2291     if (request.url() != pendingAPIRequestURL())
2292         clearPendingAPIRequestURL();
2293
2294     WebFrameProxy* frame = process()->webFrame(frameID);
2295     MESSAGE_CHECK(frame);
2296     MESSAGE_CHECK_URL(request.url());
2297
2298     NavigationType navigationType = static_cast<NavigationType>(opaqueNavigationType);
2299     WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
2300     WebMouseEvent::Button mouseButton = static_cast<WebMouseEvent::Button>(opaqueMouseButton);
2301     
2302     RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
2303
2304     ASSERT(!m_inDecidePolicyForNavigationAction);
2305
2306     m_inDecidePolicyForNavigationAction = true;
2307     m_syncNavigationActionPolicyActionIsValid = false;
2308     
2309     if (!m_policyClient.decidePolicyForNavigationAction(this, frame, navigationType, modifiers, mouseButton, request, listener.get(), userData.get()))
2310         listener->use();
2311
2312     m_inDecidePolicyForNavigationAction = false;
2313
2314     // Check if we received a policy decision already. If we did, we can just pass it back.
2315     receivedPolicyAction = m_syncNavigationActionPolicyActionIsValid;
2316     if (m_syncNavigationActionPolicyActionIsValid) {
2317         policyAction = m_syncNavigationActionPolicyAction;
2318         downloadID = m_syncNavigationActionPolicyDownloadID;
2319     }
2320 }
2321
2322 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)
2323 {
2324     RefPtr<APIObject> userData;
2325     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2326     if (!arguments->decode(messageDecoder))
2327         return;
2328
2329     WebFrameProxy* frame = process()->webFrame(frameID);
2330     MESSAGE_CHECK(frame);
2331     MESSAGE_CHECK_URL(request.url());
2332
2333     NavigationType navigationType = static_cast<NavigationType>(opaqueNavigationType);
2334     WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
2335     WebMouseEvent::Button mouseButton = static_cast<WebMouseEvent::Button>(opaqueMouseButton);
2336
2337     RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
2338     if (!m_policyClient.decidePolicyForNewWindowAction(this, frame, navigationType, modifiers, mouseButton, request, frameName, listener.get(), userData.get()))
2339         listener->use();
2340 }
2341
2342 void WebPageProxy::decidePolicyForResponse(uint64_t frameID, const ResourceResponse& response, const ResourceRequest& request, uint64_t listenerID, CoreIPC::ArgumentDecoder* arguments, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID)
2343 {
2344     RefPtr<APIObject> userData;
2345     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2346     if (!arguments->decode(messageDecoder))
2347         return;
2348
2349     WebFrameProxy* frame = process()->webFrame(frameID);
2350     MESSAGE_CHECK(frame);
2351     MESSAGE_CHECK_URL(request.url());
2352     MESSAGE_CHECK_URL(response.url());
2353     
2354     RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
2355
2356     ASSERT(!m_inDecidePolicyForResponse);
2357
2358     m_inDecidePolicyForResponse = true;
2359     m_syncMimeTypePolicyActionIsValid = false;
2360
2361     if (!m_policyClient.decidePolicyForResponse(this, frame, response, request, listener.get(), userData.get()))
2362         listener->use();
2363
2364     m_inDecidePolicyForResponse = false;
2365
2366     // Check if we received a policy decision already. If we did, we can just pass it back.
2367     receivedPolicyAction = m_syncMimeTypePolicyActionIsValid;
2368     if (m_syncMimeTypePolicyActionIsValid) {
2369         policyAction = m_syncMimeTypePolicyAction;
2370         downloadID = m_syncMimeTypePolicyDownloadID;
2371     }
2372 }
2373
2374 void WebPageProxy::unableToImplementPolicy(uint64_t frameID, const ResourceError& error, CoreIPC::ArgumentDecoder* arguments)
2375 {
2376     RefPtr<APIObject> userData;
2377     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2378     if (!arguments->decode(messageDecoder))
2379         return;
2380     
2381     WebFrameProxy* frame = process()->webFrame(frameID);
2382     MESSAGE_CHECK(frame);
2383
2384     m_policyClient.unableToImplementPolicy(this, frame, error, userData.get());
2385 }
2386
2387 // FormClient
2388
2389 void WebPageProxy::willSubmitForm(uint64_t frameID, uint64_t sourceFrameID, const StringPairVector& textFieldValues, uint64_t listenerID, CoreIPC::ArgumentDecoder* arguments)
2390 {
2391     RefPtr<APIObject> userData;
2392     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2393     if (!arguments->decode(messageDecoder))
2394         return;
2395
2396     WebFrameProxy* frame = process()->webFrame(frameID);
2397     MESSAGE_CHECK(frame);
2398
2399     WebFrameProxy* sourceFrame = process()->webFrame(sourceFrameID);
2400     MESSAGE_CHECK(sourceFrame);
2401
2402     RefPtr<WebFormSubmissionListenerProxy> listener = frame->setUpFormSubmissionListenerProxy(listenerID);
2403     if (!m_formClient.willSubmitForm(this, frame, sourceFrame, textFieldValues.stringPairVector(), userData.get(), listener.get()))
2404         listener->continueSubmission();
2405 }
2406
2407 // ResourceLoad Client
2408
2409 void WebPageProxy::didInitiateLoadForResource(uint64_t frameID, uint64_t resourceIdentifier, const ResourceRequest& request, bool pageIsProvisionallyLoading)
2410 {
2411     WebFrameProxy* frame = process()->webFrame(frameID);
2412     MESSAGE_CHECK(frame);
2413     MESSAGE_CHECK_URL(request.url());
2414
2415     m_resourceLoadClient.didInitiateLoadForResource(this, frame, resourceIdentifier, request, pageIsProvisionallyLoading);
2416 }
2417
2418 void WebPageProxy::didSendRequestForResource(uint64_t frameID, uint64_t resourceIdentifier, const ResourceRequest& request, const ResourceResponse& redirectResponse)
2419 {
2420     WebFrameProxy* frame = process()->webFrame(frameID);
2421     MESSAGE_CHECK(frame);
2422     MESSAGE_CHECK_URL(request.url());
2423
2424     m_resourceLoadClient.didSendRequestForResource(this, frame, resourceIdentifier, request, redirectResponse);
2425 }
2426
2427 void WebPageProxy::didReceiveResponseForResource(uint64_t frameID, uint64_t resourceIdentifier, const ResourceResponse& response)
2428 {
2429     WebFrameProxy* frame = process()->webFrame(frameID);
2430     MESSAGE_CHECK(frame);
2431     MESSAGE_CHECK_URL(response.url());
2432
2433     m_resourceLoadClient.didReceiveResponseForResource(this, frame, resourceIdentifier, response);
2434 }
2435
2436 void WebPageProxy::didReceiveContentLengthForResource(uint64_t frameID, uint64_t resourceIdentifier, uint64_t contentLength)
2437 {
2438     WebFrameProxy* frame = process()->webFrame(frameID);
2439     MESSAGE_CHECK(frame);
2440
2441     m_resourceLoadClient.didReceiveContentLengthForResource(this, frame, resourceIdentifier, contentLength);
2442 }
2443
2444 void WebPageProxy::didFinishLoadForResource(uint64_t frameID, uint64_t resourceIdentifier)
2445 {
2446     WebFrameProxy* frame = process()->webFrame(frameID);
2447     MESSAGE_CHECK(frame);
2448
2449     m_resourceLoadClient.didFinishLoadForResource(this, frame, resourceIdentifier);
2450 }
2451
2452 void WebPageProxy::didFailLoadForResource(uint64_t frameID, uint64_t resourceIdentifier, const ResourceError& error)
2453 {
2454     WebFrameProxy* frame = process()->webFrame(frameID);
2455     MESSAGE_CHECK(frame);
2456
2457     m_resourceLoadClient.didFailLoadForResource(this, frame, resourceIdentifier, error);
2458 }
2459
2460 // UIClient
2461
2462 void WebPageProxy::createNewPage(const ResourceRequest& request, const WindowFeatures& windowFeatures, uint32_t opaqueModifiers, int32_t opaqueMouseButton, uint64_t& newPageID, WebPageCreationParameters& newPageParameters)
2463 {
2464     RefPtr<WebPageProxy> newPage = m_uiClient.createNewPage(this, request, windowFeatures, static_cast<WebEvent::Modifiers>(opaqueModifiers), static_cast<WebMouseEvent::Button>(opaqueMouseButton));
2465     if (newPage) {
2466         newPageID = newPage->pageID();
2467         newPageParameters = newPage->creationParameters();
2468     } else
2469         newPageID = 0;
2470 }
2471     
2472 void WebPageProxy::showPage()
2473 {
2474     m_uiClient.showPage(this);
2475 }
2476
2477 void WebPageProxy::closePage(bool stopResponsivenessTimer)
2478 {
2479     if (stopResponsivenessTimer)
2480         process()->responsivenessTimer()->stop();
2481
2482     m_pageClient->clearAllEditCommands();
2483     m_uiClient.close(this);
2484 }
2485
2486 #if OS(TIZEN)
2487 void WebPageProxy::runJavaScriptAlert(uint64_t frameID, const String& message, PassRefPtr<Messages::WebPageProxy::RunJavaScriptAlert::DelayedReply> reply)
2488 {
2489     WebFrameProxy* frame = process()->webFrame(frameID);
2490     MESSAGE_CHECK(frame);
2491
2492     // Since runJavaScriptAlert() can spin a nested run loop we need to turn off the responsiveness timer.
2493     process()->responsivenessTimer()->stop();
2494
2495     m_alertReply = reply;
2496 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
2497     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(true);
2498 #endif
2499     if (!m_uiClient.runJavaScriptAlert(this, message, frame))
2500         replyJavaScriptAlert();
2501 }
2502
2503 void WebPageProxy::runJavaScriptConfirm(uint64_t frameID, const String& message, PassRefPtr<Messages::WebPageProxy::RunJavaScriptConfirm::DelayedReply> reply)
2504 {
2505     WebFrameProxy* frame = process()->webFrame(frameID);
2506     MESSAGE_CHECK(frame);
2507
2508     // Since runJavaScriptConfirm() can spin a nested run loop we need to turn off the responsiveness timer.
2509     process()->responsivenessTimer()->stop();
2510
2511     m_confirmReply = reply;
2512 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
2513     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(true);
2514 #endif
2515     if (!m_uiClient.runJavaScriptConfirm(this, message, frame))
2516         replyJavaScriptConfirm(false);
2517 }
2518
2519 void WebPageProxy::runJavaScriptPrompt(uint64_t frameID, const String& message, const String& defaultValue, PassRefPtr<Messages::WebPageProxy::RunJavaScriptPrompt::DelayedReply> reply)
2520 {
2521     WebFrameProxy* frame = process()->webFrame(frameID);
2522     MESSAGE_CHECK(frame);
2523
2524     // Since runJavaScriptPrompt() can spin a nested run loop we need to turn off the responsiveness timer.
2525     process()->responsivenessTimer()->stop();
2526
2527     m_promptReply = reply;
2528 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
2529     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(true);
2530 #endif
2531     if (!m_uiClient.runJavaScriptPrompt(this, message, defaultValue, frame))
2532         replyJavaScriptPrompt(String());
2533 }
2534 #else
2535 void WebPageProxy::runJavaScriptAlert(uint64_t frameID, const String& message)
2536 {
2537     WebFrameProxy* frame = process()->webFrame(frameID);
2538     MESSAGE_CHECK(frame);
2539
2540     // Since runJavaScriptAlert() can spin a nested run loop we need to turn off the responsiveness timer.
2541     process()->responsivenessTimer()->stop();
2542
2543     m_uiClient.runJavaScriptAlert(this, message, frame);
2544 }
2545
2546 void WebPageProxy::runJavaScriptConfirm(uint64_t frameID, const String& message, bool& result)
2547 {
2548     WebFrameProxy* frame = process()->webFrame(frameID);
2549     MESSAGE_CHECK(frame);
2550
2551     // Since runJavaScriptConfirm() can spin a nested run loop we need to turn off the responsiveness timer.
2552     process()->responsivenessTimer()->stop();
2553
2554     result = m_uiClient.runJavaScriptConfirm(this, message, frame);
2555 }
2556
2557 void WebPageProxy::runJavaScriptPrompt(uint64_t frameID, const String& message, const String& defaultValue, String& result)
2558 {
2559     WebFrameProxy* frame = process()->webFrame(frameID);
2560     MESSAGE_CHECK(frame);
2561
2562     // Since runJavaScriptPrompt() can spin a nested run loop we need to turn off the responsiveness timer.
2563     process()->responsivenessTimer()->stop();
2564
2565     result = m_uiClient.runJavaScriptPrompt(this, message, defaultValue, frame);
2566 }
2567 #endif
2568
2569 void WebPageProxy::shouldInterruptJavaScript(bool& result)
2570 {
2571     // Since shouldInterruptJavaScript() can spin a nested run loop we need to turn off the responsiveness timer.
2572     process()->responsivenessTimer()->stop();
2573
2574     result = m_uiClient.shouldInterruptJavaScript(this);
2575 }
2576
2577 void WebPageProxy::setStatusText(const String& text)
2578 {
2579     m_uiClient.setStatusText(this, text);
2580 }
2581
2582 void WebPageProxy::mouseDidMoveOverElement(const WebHitTestResult::Data& hitTestResultData, uint32_t opaqueModifiers, CoreIPC::ArgumentDecoder* arguments)
2583 {
2584     RefPtr<APIObject> userData;
2585     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
2586     if (!arguments->decode(messageDecoder))
2587         return;
2588
2589     WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
2590
2591     m_uiClient.mouseDidMoveOverElement(this, hitTestResultData, modifiers, userData.get());
2592 }
2593
2594 void WebPageProxy::unavailablePluginButtonClicked(uint32_t opaquePluginUnavailabilityReason, const String& mimeType, const String& url, const String& pluginsPageURL)
2595 {
2596     MESSAGE_CHECK_URL(url);
2597     MESSAGE_CHECK_URL(pluginsPageURL);
2598
2599     WKPluginUnavailabilityReason pluginUnavailabilityReason = static_cast<WKPluginUnavailabilityReason>(opaquePluginUnavailabilityReason);
2600     m_uiClient.unavailablePluginButtonClicked(this, pluginUnavailabilityReason, mimeType, url, pluginsPageURL);
2601 }
2602
2603 void WebPageProxy::setToolbarsAreVisible(bool toolbarsAreVisible)
2604 {
2605     m_uiClient.setToolbarsAreVisible(this, toolbarsAreVisible);
2606 }
2607
2608 void WebPageProxy::getToolbarsAreVisible(bool& toolbarsAreVisible)
2609 {
2610     toolbarsAreVisible = m_uiClient.toolbarsAreVisible(this);
2611 }
2612
2613 void WebPageProxy::setMenuBarIsVisible(bool menuBarIsVisible)
2614 {
2615     m_uiClient.setMenuBarIsVisible(this, menuBarIsVisible);
2616 }
2617
2618 void WebPageProxy::getMenuBarIsVisible(bool& menuBarIsVisible)
2619 {
2620     menuBarIsVisible = m_uiClient.menuBarIsVisible(this);
2621 }
2622
2623 void WebPageProxy::setStatusBarIsVisible(bool statusBarIsVisible)
2624 {
2625     m_uiClient.setStatusBarIsVisible(this, statusBarIsVisible);
2626 }
2627
2628 void WebPageProxy::getStatusBarIsVisible(bool& statusBarIsVisible)
2629 {
2630     statusBarIsVisible = m_uiClient.statusBarIsVisible(this);
2631 }
2632
2633 void WebPageProxy::setIsResizable(bool isResizable)
2634 {
2635     m_uiClient.setIsResizable(this, isResizable);
2636 }
2637
2638 void WebPageProxy::getIsResizable(bool& isResizable)
2639 {
2640     isResizable = m_uiClient.isResizable(this);
2641 }
2642
2643 void WebPageProxy::setWindowFrame(const FloatRect& newWindowFrame)
2644 {
2645     m_uiClient.setWindowFrame(this, m_pageClient->convertToDeviceSpace(newWindowFrame));
2646 }
2647
2648 void WebPageProxy::getWindowFrame(FloatRect& newWindowFrame)
2649 {
2650     newWindowFrame = m_pageClient->convertToUserSpace(m_uiClient.windowFrame(this));
2651 }
2652     
2653 void WebPageProxy::screenToWindow(const IntPoint& screenPoint, IntPoint& windowPoint)
2654 {
2655     windowPoint = m_pageClient->screenToWindow(screenPoint);
2656 }
2657     
2658 void WebPageProxy::windowToScreen(const IntRect& viewRect, IntRect& result)
2659 {
2660     result = m_pageClient->windowToScreen(viewRect);
2661 }
2662     
2663 void WebPageProxy::runBeforeUnloadConfirmPanel(const String& message, uint64_t frameID, bool& shouldClose)
2664 {
2665     WebFrameProxy* frame = process()->webFrame(frameID);
2666     MESSAGE_CHECK(frame);
2667
2668     // Since runBeforeUnloadConfirmPanel() can spin a nested run loop we need to turn off the responsiveness timer.
2669     process()->responsivenessTimer()->stop();
2670
2671     shouldClose = m_uiClient.runBeforeUnloadConfirmPanel(this, message, frame);
2672 }
2673
2674 #if USE(TILED_BACKING_STORE)
2675 void WebPageProxy::pageDidRequestScroll(const IntPoint& point)
2676 {
2677     m_pageClient->pageDidRequestScroll(point);
2678 }
2679 #endif
2680
2681 void WebPageProxy::didChangeViewportProperties(const ViewportAttributes& attr)
2682 {
2683     m_pageClient->didChangeViewportProperties(attr);
2684 }
2685
2686 void WebPageProxy::pageDidScroll()
2687 {
2688     m_uiClient.pageDidScroll(this);
2689 #if PLATFORM(MAC) && !defined(BUILDING_ON_SNOW_LEOPARD)
2690     dismissCorrectionPanel(ReasonForDismissingAlternativeTextIgnored);
2691 #endif
2692 }
2693
2694 void WebPageProxy::runOpenPanel(uint64_t frameID, const FileChooserSettings& settings)
2695 {
2696     if (m_openPanelResultListener) {
2697         m_openPanelResultListener->invalidate();
2698         m_openPanelResultListener = 0;
2699     }
2700
2701     WebFrameProxy* frame = process()->webFrame(frameID);
2702     MESSAGE_CHECK(frame);
2703
2704     RefPtr<WebOpenPanelParameters> parameters = WebOpenPanelParameters::create(settings);
2705     m_openPanelResultListener = WebOpenPanelResultListenerProxy::create(this);
2706
2707     // Since runOpenPanel() can spin a nested run loop we need to turn off the responsiveness timer.
2708     process()->responsivenessTimer()->stop();
2709
2710     if (!m_uiClient.runOpenPanel(this, frame, parameters.get(), m_openPanelResultListener.get()))
2711         didCancelForOpenPanel();
2712 }
2713
2714 void WebPageProxy::printFrame(uint64_t frameID)
2715 {
2716     ASSERT(!m_isPerformingDOMPrintOperation);
2717     m_isPerformingDOMPrintOperation = true;
2718
2719     WebFrameProxy* frame = process()->webFrame(frameID);
2720     MESSAGE_CHECK(frame);
2721
2722     m_uiClient.printFrame(this, frame);
2723
2724     endPrinting(); // Send a message synchronously while m_isPerformingDOMPrintOperation is still true.
2725     m_isPerformingDOMPrintOperation = false;
2726 }
2727
2728 void WebPageProxy::printMainFrame()
2729 {
2730     printFrame(m_mainFrame->frameID());
2731 }
2732
2733 #if ENABLE(TIZEN_REGISTER_PROTOCOL_HANDLER)
2734 void WebPageProxy::registerProtocolHandler(const String& scheme, const String& baseURL, const String& url, const String& title)
2735 {
2736     m_pageClient->registerProtocolHandler(scheme, baseURL, url, title);
2737 }
2738 #endif
2739
2740 #if ENABLE(TIZEN_REGISTER_CONTENT_HANDLER)
2741 void WebPageProxy::registerContentHandler(const String& mimeType, const String& baseURL, const String& url, const String& title)
2742 {
2743     m_pageClient->registerContentHandler(mimeType, baseURL, url, title);
2744 }
2745 #endif
2746
2747 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
2748 void WebPageProxy::getStandaloneStatus(bool& standalone)
2749 {
2750     standalone = m_pageClient->getStandaloneStatus();
2751 }
2752
2753 void WebPageProxy::getWebAppCapable(PassRefPtr<BooleanCallback> prpCallback)
2754 {
2755     RefPtr<BooleanCallback> callback = prpCallback;
2756     if (!isValid()) {
2757         callback->invalidate();
2758         return;
2759     }
2760
2761     uint64_t callbackID = callback->callbackID();
2762     m_booleanCallbacks.set(callbackID, callback.get());
2763     process()->send(Messages::WebPage::GetWebAppCapable(callbackID), m_pageID);
2764 }
2765
2766 void WebPageProxy::didGetWebAppCapable(const bool capable, uint64_t callbackID)
2767 {
2768     RefPtr<BooleanCallback> callback = m_booleanCallbacks.take(callbackID);
2769     if (!callback) {
2770         // FIXME: Log error or assert.
2771         // this can validly happen if a load invalidated the callback, though
2772         return;
2773     }
2774
2775     m_booleanCallbacks.remove(callbackID);
2776     callback->performCallbackWithReturnValue(WebBoolean::create(capable).leakRef());
2777 }
2778
2779 void WebPageProxy::getWebAppIconURL(PassRefPtr<StringCallback> prpCallback)
2780 {
2781     RefPtr<StringCallback> callback = prpCallback;
2782     if (!isValid()) {
2783         callback->invalidate();
2784         return;
2785     }
2786
2787     uint64_t callbackID = callback->callbackID();
2788     m_stringCallbacks.set(callbackID, callback.get());
2789     process()->send(Messages::WebPage::GetWebAppIconURL(callbackID), m_pageID);
2790 }
2791
2792 void WebPageProxy::didGetWebAppIconURL(const String& iconURL, uint64_t callbackID)
2793 {
2794     RefPtr<StringCallback> callback = m_stringCallbacks.take(callbackID);
2795     if (!callback) {
2796         // FIXME: Log error or assert.
2797         // this can validly happen if a load invalidated the callback, though
2798         return;
2799     }
2800
2801     m_stringCallbacks.remove(callbackID);
2802     callback->performCallbackWithReturnValue(iconURL.impl());
2803 }
2804 #endif
2805
2806 void WebPageProxy::setMediaVolume(float volume)
2807 {
2808     if (volume == m_mediaVolume)
2809         return;
2810     
2811     m_mediaVolume = volume;
2812     
2813     if (!isValid())
2814         return;
2815     
2816     process()->send(Messages::WebPage::SetMediaVolume(volume), m_pageID);    
2817 }
2818
2819 #if PLATFORM(QT)
2820 void WebPageProxy::didChangeContentsSize(const IntSize& size)
2821 {
2822     m_pageClient->didChangeContentsSize(size);
2823 }
2824
2825 void WebPageProxy::didFindZoomableArea(const IntPoint& target, const IntRect& area)
2826 {
2827     m_pageClient->didFindZoomableArea(target, area);
2828 }
2829
2830 void WebPageProxy::findZoomableAreaForPoint(const IntPoint& point, const IntSize& area)
2831 {
2832     if (!isValid())
2833         return;
2834
2835     process()->send(Messages::WebPage::FindZoomableAreaForPoint(point, area), m_pageID);
2836 }
2837
2838 void WebPageProxy::didReceiveMessageFromNavigatorQtObject(const String& contents)
2839 {
2840     m_pageClient->didReceiveMessageFromNavigatorQtObject(contents);
2841 }
2842
2843 void WebPageProxy::handleDownloadRequest(DownloadProxy* download)
2844 {
2845     m_pageClient->handleDownloadRequest(download);
2846 }
2847
2848 void WebPageProxy::authenticationRequiredRequest(const String& hostname, const String& realm, const String& prefilledUsername, String& username, String& password)
2849 {
2850     m_pageClient->handleAuthenticationRequiredRequest(hostname, realm, prefilledUsername, username, password);
2851 }
2852
2853 void WebPageProxy::proxyAuthenticationRequiredRequest(const String& hostname, uint16_t port, const String& prefilledUsername, String& username, String& password)
2854 {
2855     m_pageClient->handleProxyAuthenticationRequiredRequest(hostname, port, prefilledUsername, username, password);
2856 }
2857
2858 void WebPageProxy::certificateVerificationRequest(const String& hostname, bool& ignoreErrors)
2859 {
2860     m_pageClient->handleCertificateVerificationRequest(hostname, ignoreErrors);
2861 }
2862 #endif // PLATFORM(QT).
2863
2864 #if OS(TIZEN)
2865 void WebPageProxy::didFindZoomableArea(const IntPoint& target, const IntRect& area)
2866 {
2867     m_pageClient->didFindZoomableArea(target, area);
2868 }
2869
2870 void WebPageProxy::findZoomableAreaForPoint(const IntPoint& point, const IntSize& area)
2871 {
2872     if (!isValid())
2873         return;
2874
2875     process()->send(Messages::WebPage::FindZoomableAreaForPoint(point, area), m_pageID);
2876 }
2877 #endif // #if OS(TIZEN)
2878
2879 #if ENABLE(TOUCH_EVENTS)
2880 void WebPageProxy::needTouchEvents(bool needTouchEvents)
2881 {
2882     m_needTouchEvents = needTouchEvents;
2883 }
2884 #endif
2885
2886 #if ENABLE(INPUT_TYPE_COLOR)
2887 void WebPageProxy::showColorChooser(const WebCore::Color& initialColor)
2888 {
2889     ASSERT(!m_colorChooser);
2890
2891     m_colorChooser = m_pageClient->createColorChooserProxy(this, initialColor);
2892 }
2893
2894 void WebPageProxy::setColorChooserColor(const WebCore::Color& color)
2895 {
2896     ASSERT(m_colorChooser);
2897
2898     m_colorChooser->setSelectedColor(color);
2899 }
2900
2901 void WebPageProxy::endColorChooser()
2902 {
2903     ASSERT(m_colorChooser);
2904
2905     m_colorChooser->endChooser();
2906 }
2907
2908 void WebPageProxy::didChooseColor(const WebCore::Color& color)
2909 {
2910     if (!isValid())
2911         return;
2912
2913     process()->send(Messages::WebPage::DidChooseColor(color), m_pageID);
2914 }
2915
2916 void WebPageProxy::didEndColorChooser()
2917 {
2918     if (!isValid())
2919         return;
2920
2921     ASSERT(m_colorChooser);
2922
2923 #if !ENABLE(TIZEN_INPUT_COLOR_PICKER) // prevent crash when the color chooser closed
2924     m_colorChooser->invalidate();
2925 #endif
2926     m_colorChooser = nullptr;
2927
2928     process()->send(Messages::WebPage::DidEndColorChooser(), m_pageID);
2929 }
2930 #endif
2931
2932 void WebPageProxy::didDraw()
2933 {
2934     m_uiClient.didDraw(this);
2935 }
2936
2937 // Inspector
2938
2939 #if ENABLE(INSPECTOR)
2940
2941 WebInspectorProxy* WebPageProxy::inspector()
2942 {
2943     if (isClosed() || !isValid())
2944         return 0;
2945     if (!m_inspector)
2946         m_inspector = WebInspectorProxy::create(this);
2947     return m_inspector.get();
2948 }
2949
2950 #endif
2951
2952 #if ENABLE(FULLSCREEN_API)
2953 WebFullScreenManagerProxy* WebPageProxy::fullScreenManager()
2954 {
2955     if (!m_fullScreenManager)
2956         m_fullScreenManager = WebFullScreenManagerProxy::create(this);
2957     return m_fullScreenManager.get();
2958 }
2959 #endif
2960
2961 // BackForwardList
2962
2963 void WebPageProxy::backForwardAddItem(uint64_t itemID)
2964 {
2965     m_backForwardList->addItem(process()->webBackForwardItem(itemID));
2966 }
2967
2968 void WebPageProxy::backForwardGoToItem(uint64_t itemID, SandboxExtension::Handle& sandboxExtensionHandle)
2969 {
2970     WebBackForwardListItem* item = process()->webBackForwardItem(itemID);
2971     if (!item)
2972         return;
2973
2974     bool createdExtension = maybeInitializeSandboxExtensionHandle(KURL(KURL(), item->url()), sandboxExtensionHandle);
2975     if (createdExtension)
2976         process()->willAcquireUniversalFileReadSandboxExtension();
2977     m_backForwardList->goToItem(item);
2978 }
2979
2980 void WebPageProxy::backForwardItemAtIndex(int32_t index, uint64_t& itemID)
2981 {
2982     WebBackForwardListItem* item = m_backForwardList->itemAtIndex(index);
2983     itemID = item ? item->itemID() : 0;
2984 }
2985
2986 void WebPageProxy::backForwardBackListCount(int32_t& count)
2987 {
2988     count = m_backForwardList->backListCount();
2989 }
2990
2991 void WebPageProxy::backForwardForwardListCount(int32_t& count)
2992 {
2993     count = m_backForwardList->forwardListCount();
2994 }
2995
2996 void WebPageProxy::editorStateChanged(const EditorState& editorState)
2997 {
2998 #if PLATFORM(MAC)
2999     bool couldChangeSecureInputState = m_editorState.isInPasswordField != editorState.isInPasswordField || m_editorState.selectionIsNone;
3000 #endif
3001
3002     m_editorState = editorState;
3003
3004 #if PLATFORM(MAC)
3005     m_pageClient->updateTextInputState(couldChangeSecureInputState);
3006 #elif PLATFORM(QT)
3007     m_pageClient->updateTextInputState();
3008 #endif
3009
3010 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
3011     m_pageClient->updateTextSelection();
3012 #endif
3013 }
3014
3015 // Undo management
3016
3017 void WebPageProxy::registerEditCommandForUndo(uint64_t commandID, uint32_t editAction)
3018 {
3019     registerEditCommand(WebEditCommandProxy::create(commandID, static_cast<EditAction>(editAction), this), Undo);
3020 }
3021
3022 void WebPageProxy::canUndoRedo(uint32_t action, bool& result)
3023 {
3024     result = m_pageClient->canUndoRedo(static_cast<UndoOrRedo>(action));
3025 }
3026
3027 void WebPageProxy::executeUndoRedo(uint32_t action, bool& result)
3028 {
3029     m_pageClient->executeUndoRedo(static_cast<UndoOrRedo>(action));
3030     result = true;
3031 }
3032
3033 void WebPageProxy::clearAllEditCommands()
3034 {
3035     m_pageClient->clearAllEditCommands();
3036 }
3037
3038 void WebPageProxy::didCountStringMatches(const String& string, uint32_t matchCount)
3039 {
3040     m_findClient.didCountStringMatches(this, string, matchCount);
3041 }
3042
3043 void WebPageProxy::setFindIndicator(const FloatRect& selectionRectInWindowCoordinates, const Vector<FloatRect>& textRectsInSelectionRectCoordinates, float contentImageScaleFactor, const ShareableBitmap::Handle& contentImageHandle, bool fadeOut, bool animate)
3044 {
3045     RefPtr<FindIndicator> findIndicator = FindIndicator::create(selectionRectInWindowCoordinates, textRectsInSelectionRectCoordinates, contentImageScaleFactor, contentImageHandle);
3046     m_pageClient->setFindIndicator(findIndicator.release(), fadeOut, animate);
3047 }
3048
3049 void WebPageProxy::didFindString(const String& string, uint32_t matchCount)
3050 {
3051     m_findClient.didFindString(this, string, matchCount);
3052 }
3053
3054 void WebPageProxy::didFailToFindString(const String& string)
3055 {
3056     m_findClient.didFailToFindString(this, string);
3057 }
3058
3059 void WebPageProxy::valueChangedForPopupMenu(WebPopupMenuProxy*, int32_t newSelectedIndex)
3060 {
3061     process()->send(Messages::WebPage::DidChangeSelectedIndexForActivePopupMenu(newSelectedIndex), m_pageID);
3062 }
3063
3064 void WebPageProxy::setTextFromItemForPopupMenu(WebPopupMenuProxy*, int32_t index)
3065 {
3066     process()->send(Messages::WebPage::SetTextForActivePopupMenu(index), m_pageID);
3067 }
3068
3069 NativeWebMouseEvent* WebPageProxy::currentlyProcessedMouseDownEvent()
3070 {
3071     return m_currentlyProcessedMouseDownEvent.get();
3072 }
3073
3074 #if PLATFORM(GTK)
3075 void WebPageProxy::failedToShowPopupMenu()
3076 {
3077     process()->send(Messages::WebPage::FailedToShowPopupMenu(), m_pageID);
3078 }
3079 #endif
3080
3081 void WebPageProxy::showPopupMenu(const IntRect& rect, uint64_t textDirection, const Vector<WebPopupItem>& items, int32_t selectedIndex, const PlatformPopupMenuData& data)
3082 {
3083     if (m_activePopupMenu) {
3084         m_activePopupMenu->hidePopupMenu();
3085         m_activePopupMenu->invalidate();
3086         m_activePopupMenu = 0;
3087     }
3088
3089     m_activePopupMenu = m_pageClient->createPopupMenuProxy(this);
3090
3091     // Since showPopupMenu() can spin a nested run loop we need to turn off the responsiveness timer.
3092     process()->responsivenessTimer()->stop();
3093
3094     RefPtr<WebPopupMenuProxy> protectedActivePopupMenu = m_activePopupMenu;
3095
3096     protectedActivePopupMenu->showPopupMenu(rect, static_cast<TextDirection>(textDirection), m_pageScaleFactor, items, data, selectedIndex);
3097 #if !PLATFORM(EFL)
3098     protectedActivePopupMenu->invalidate();
3099 #endif
3100     protectedActivePopupMenu = 0;
3101 }
3102
3103 void WebPageProxy::hidePopupMenu()
3104 {
3105     if (!m_activePopupMenu)
3106         return;
3107
3108     m_activePopupMenu->hidePopupMenu();
3109     m_activePopupMenu->invalidate();
3110     m_activePopupMenu = 0;
3111 }
3112
3113 #if ENABLE(CONTEXT_MENUS)
3114 void WebPageProxy::showContextMenu(const IntPoint& menuLocation, const WebHitTestResult::Data& hitTestResultData, const Vector<WebContextMenuItemData>& proposedItems, CoreIPC::ArgumentDecoder* arguments)
3115 {
3116     internalShowContextMenu(menuLocation, hitTestResultData, proposedItems, arguments);
3117     
3118     // No matter the result of internalShowContextMenu, always notify the WebProcess that the menu is hidden so it starts handling mouse events again.
3119     process()->send(Messages::WebPage::ContextMenuHidden(), m_pageID);
3120 #if ENABLE(TOUCH_EVENTS) && ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
3121     // Cancel touch event when ContextMenu is shown.
3122     m_pageClient->cancelTouchEvent();
3123 #endif
3124 }
3125
3126 void WebPageProxy::internalShowContextMenu(const IntPoint& menuLocation, const WebHitTestResult::Data& hitTestResultData, const Vector<WebContextMenuItemData>& proposedItems, CoreIPC::ArgumentDecoder* arguments)
3127 {
3128     RefPtr<APIObject> userData;
3129     WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
3130     if (!arguments->decode(messageDecoder))
3131         return;
3132
3133     m_activeContextMenuHitTestResultData = hitTestResultData;
3134
3135     if (m_activeContextMenu) {
3136         m_activeContextMenu->hideContextMenu();
3137         m_activeContextMenu = 0;
3138     }
3139
3140     m_activeContextMenu = m_pageClient->createContextMenuProxy(this);
3141
3142     // Since showContextMenu() can spin a nested run loop we need to turn off the responsiveness timer.
3143     process()->responsivenessTimer()->stop();
3144
3145     // Give the PageContextMenuClient one last swipe at changing the menu.
3146     Vector<WebContextMenuItemData> items;
3147     if (!m_contextMenuClient.getContextMenuFromProposedMenu(this, proposedItems, items, hitTestResultData, userData.get()))
3148         m_activeContextMenu->showContextMenu(menuLocation, proposedItems);
3149     else
3150         m_activeContextMenu->showContextMenu(menuLocation, items);
3151     
3152     m_contextMenuClient.contextMenuDismissed(this);
3153 }
3154
3155 void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& item)
3156 {
3157     // Application custom items don't need to round-trip through to WebCore in the WebProcess.
3158     if (item.action() >= ContextMenuItemBaseApplicationTag) {
3159         m_contextMenuClient.customContextMenuItemSelected(this, item);
3160 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
3161         m_pageClient->setIsTextSelectionMode(false);
3162 #endif
3163         return;
3164     }
3165
3166 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
3167     if (item.action() == ContextMenuItemTagPaste)
3168         m_pageClient->setIsTextSelectionMode(false);
3169 #endif
3170
3171 #if PLATFORM(MAC)
3172     if (item.action() == ContextMenuItemTagSmartCopyPaste) {
3173         setSmartInsertDeleteEnabled(!isSmartInsertDeleteEnabled());
3174         return;
3175     }
3176     if (item.action() == ContextMenuItemTagSmartQuotes) {
3177         TextChecker::setAutomaticQuoteSubstitutionEnabled(!TextChecker::state().isAutomaticQuoteSubstitutionEnabled);
3178         process()->updateTextCheckerState();
3179         return;
3180     }
3181     if (item.action() == ContextMenuItemTagSmartDashes) {
3182         TextChecker::setAutomaticDashSubstitutionEnabled(!TextChecker::state().isAutomaticDashSubstitutionEnabled);
3183         process()->updateTextCheckerState();
3184         return;
3185     }
3186     if (item.action() == ContextMenuItemTagSmartLinks) {
3187         TextChecker::setAutomaticLinkDetectionEnabled(!TextChecker::state().isAutomaticLinkDetectionEnabled);
3188         process()->updateTextCheckerState();
3189         return;
3190     }
3191     if (item.action() == ContextMenuItemTagTextReplacement) {
3192         TextChecker::setAutomaticTextReplacementEnabled(!TextChecker::state().isAutomaticTextReplacementEnabled);
3193         process()->updateTextCheckerState();
3194         return;
3195     }
3196     if (item.action() == ContextMenuItemTagCorrectSpellingAutomatically) {
3197         TextChecker::setAutomaticSpellingCorrectionEnabled(!TextChecker::state().isAutomaticSpellingCorrectionEnabled);
3198         process()->updateTextCheckerState();
3199         return;        
3200     }
3201     if (item.action() == ContextMenuItemTagShowSubstitutions) {
3202         TextChecker::toggleSubstitutionsPanelIsShowing();
3203         return;
3204     }
3205 #endif
3206     if (item.action() == ContextMenuItemTagDownloadImageToDisk) {
3207         m_process->context()->download(this, KURL(KURL(), m_activeContextMenuHitTestResultData.absoluteImageURL));
3208         return;    
3209     }
3210     if (item.action() == ContextMenuItemTagDownloadLinkToDisk) {
3211         m_process->context()->download(this, KURL(KURL(), m_activeContextMenuHitTestResultData.absoluteLinkURL));
3212         return;
3213     }
3214     if (item.action() == ContextMenuItemTagCheckSpellingWhileTyping) {
3215         TextChecker::setContinuousSpellCheckingEnabled(!TextChecker::state().isContinuousSpellCheckingEnabled);
3216         process()->updateTextCheckerState();
3217         return;
3218     }
3219     if (item.action() == ContextMenuItemTagCheckGrammarWithSpelling) {
3220         TextChecker::setGrammarCheckingEnabled(!TextChecker::state().isGrammarCheckingEnabled);
3221         process()->updateTextCheckerState();
3222         return;
3223     }
3224     if (item.action() == ContextMenuItemTagShowSpellingPanel) {
3225         if (!TextChecker::spellingUIIsShowing())
3226             advanceToNextMisspelling(true);
3227         TextChecker::toggleSpellingUIIsShowing();
3228         return;
3229     }
3230     if (item.action() == ContextMenuItemTagLearnSpelling || item.action() == ContextMenuItemTagIgnoreSpelling)
3231         ++m_pendingLearnOrIgnoreWordMessageCount;
3232
3233 #if ENABLE(TIZEN_WEBKIT_PASTEBOARD)
3234     if (item.action() == ContextMenuItemTagPaste) {
3235         // process paste after getting data from clipboard.
3236         pasteWithClipboard();
3237         return;
3238     }
3239 #endif
3240
3241 #if ENABLE(CONTEXT_MENUS)
3242     process()->send(Messages::WebPage::DidSelectItemFromActiveContextMenu(item), m_pageID);
3243 #endif
3244 }
3245 #endif // ENABLE(CONTEXT_MENUS)
3246
3247 void WebPageProxy::didChooseFilesForOpenPanel(const Vector<String>& fileURLs)
3248 {
3249     if (!isValid())
3250         return;
3251
3252 #if ENABLE(WEB_PROCESS_SANDBOX)
3253     // FIXME: The sandbox extensions should be sent with the DidChooseFilesForOpenPanel message. This
3254     // is gated on a way of passing SandboxExtension::Handles in a Vector.
3255     for (size_t i = 0; i < fileURLs.size(); ++i) {
3256         SandboxExtension::Handle sandboxExtensionHandle;
3257         SandboxExtension::createHandle(fileURLs[i], SandboxExtension::ReadOnly, sandboxExtensionHandle);
3258         process()->send(Messages::WebPage::ExtendSandboxForFileFromOpenPanel(sandboxExtensionHandle), m_pageID);
3259     }
3260 #endif
3261
3262     process()->send(Messages::WebPage::DidChooseFilesForOpenPanel(fileURLs), m_pageID);
3263
3264     m_openPanelResultListener->invalidate();
3265     m_openPanelResultListener = 0;
3266 }
3267
3268 void WebPageProxy::didCancelForOpenPanel()
3269 {
3270     if (!isValid())
3271         return;
3272
3273     process()->send(Messages::WebPage::DidCancelForOpenPanel(), m_pageID);
3274     
3275     m_openPanelResultListener->invalidate();
3276     m_openPanelResultListener = 0;
3277 }
3278
3279 void WebPageProxy::advanceToNextMisspelling(bool startBeforeSelection) const
3280 {
3281     process()->send(Messages::WebPage::AdvanceToNextMisspelling(startBeforeSelection), m_pageID);
3282 }
3283
3284 void WebPageProxy::changeSpellingToWord(const String& word) const
3285 {
3286     if (word.isEmpty())
3287         return;
3288
3289     process()->send(Messages::WebPage::ChangeSpellingToWord(word), m_pageID);
3290 }
3291
3292 void WebPageProxy::registerEditCommand(PassRefPtr<WebEditCommandProxy> commandProxy, UndoOrRedo undoOrRedo)
3293 {
3294     m_pageClient->registerEditCommand(commandProxy, undoOrRedo);
3295 }
3296
3297 void WebPageProxy::addEditCommand(WebEditCommandProxy* command)
3298 {
3299     m_editCommandSet.add(command);
3300 }
3301
3302 void WebPageProxy::removeEditCommand(WebEditCommandProxy* command)
3303 {
3304     m_editCommandSet.remove(command);
3305
3306     if (!isValid())
3307         return;
3308     process()->send(Messages::WebPage::DidRemoveEditCommand(command->commandID()), m_pageID);
3309 }
3310
3311 bool WebPageProxy::isValidEditCommand(WebEditCommandProxy* command)
3312 {
3313     return m_editCommandSet.find(command) != m_editCommandSet.end();
3314 }
3315
3316 int64_t WebPageProxy::spellDocumentTag()
3317 {
3318     if (!m_hasSpellDocumentTag) {
3319         m_spellDocumentTag = TextChecker::uniqueSpellDocumentTag(this);
3320         m_hasSpellDocumentTag = true;
3321     }
3322
3323     return m_spellDocumentTag;
3324 }
3325
3326 #if USE(UNIFIED_TEXT_CHECKING)
3327 void WebPageProxy::checkTextOfParagraph(const String& text, uint64_t checkingTypes, Vector<TextCheckingResult>& results)
3328 {
3329     results = TextChecker::checkTextOfParagraph(spellDocumentTag(), text.characters(), text.length(), checkingTypes);
3330 }
3331 #endif
3332
3333 void WebPageProxy::checkSpellingOfString(const String& text, int32_t& misspellingLocation, int32_t& misspellingLength)
3334 {
3335     TextChecker::checkSpellingOfString(spellDocumentTag(), text.characters(), text.length(), misspellingLocation, misspellingLength);
3336 }
3337
3338 void WebPageProxy::checkGrammarOfString(const String& text, Vector<GrammarDetail>& grammarDetails, int32_t& badGrammarLocation, int32_t& badGrammarLength)
3339 {
3340     TextChecker::checkGrammarOfString(spellDocumentTag(), text.characters(), text.length(), grammarDetails, badGrammarLocation, badGrammarLength);
3341 }
3342
3343 void WebPageProxy::spellingUIIsShowing(bool& isShowing)
3344 {
3345     isShowing = TextChecker::spellingUIIsShowing();
3346 }
3347
3348 void WebPageProxy::updateSpellingUIWithMisspelledWord(const String& misspelledWord)
3349 {
3350     TextChecker::updateSpellingUIWithMisspelledWord(spellDocumentTag(), misspelledWord);
3351 }
3352
3353 void WebPageProxy::updateSpellingUIWithGrammarString(const String& badGrammarPhrase, const GrammarDetail& grammarDetail)
3354 {
3355     TextChecker::updateSpellingUIWithGrammarString(spellDocumentTag(), badGrammarPhrase, grammarDetail);
3356 }
3357
3358 void WebPageProxy::getGuessesForWord(const String& word, const String& context, Vector<String>& guesses)
3359 {
3360     TextChecker::getGuessesForWord(spellDocumentTag(), word, context, guesses);
3361 }
3362
3363 void WebPageProxy::learnWord(const String& word)
3364 {
3365     MESSAGE_CHECK(m_pendingLearnOrIgnoreWordMessageCount);
3366     --m_pendingLearnOrIgnoreWordMessageCount;
3367
3368     TextChecker::learnWord(spellDocumentTag(), word);
3369 }
3370
3371 void WebPageProxy::ignoreWord(const String& word)
3372 {
3373     MESSAGE_CHECK(m_pendingLearnOrIgnoreWordMessageCount);
3374     --m_pendingLearnOrIgnoreWordMessageCount;
3375
3376     TextChecker::ignoreWord(spellDocumentTag(), word);
3377 }
3378
3379 // Other
3380
3381 void WebPageProxy::setFocus(bool focused)
3382 {
3383     if (focused)
3384         m_uiClient.focus(this);
3385     else
3386         m_uiClient.unfocus(this);
3387 }
3388
3389 void WebPageProxy::takeFocus(uint32_t direction)
3390 {
3391     m_uiClient.takeFocus(this, (static_cast<FocusDirection>(direction) == FocusDirectionForward) ? kWKFocusDirectionForward : kWKFocusDirectionBackward);
3392 }
3393
3394 void WebPageProxy::setToolTip(const String& toolTip)
3395 {
3396     String oldToolTip = m_toolTip;
3397     m_toolTip = toolTip;
3398     m_pageClient->toolTipChanged(oldToolTip, m_toolTip);
3399 }
3400
3401 void WebPageProxy::setCursor(const WebCore::Cursor& cursor)
3402 {
3403     m_pageClient->setCursor(cursor);
3404 }
3405
3406 void WebPageProxy::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
3407 {
3408     m_pageClient->setCursorHiddenUntilMouseMoves(hiddenUntilMouseMoves);
3409 }
3410
3411 void WebPageProxy::didReceiveEvent(uint32_t opaqueType, bool handled)
3412 {
3413     WebEvent::Type type = static_cast<WebEvent::Type>(opaqueType);
3414
3415     switch (type) {
3416     case WebEvent::NoType:
3417     case WebEvent::MouseMove:
3418         break;
3419
3420     case WebEvent::MouseDown:
3421     case WebEvent::MouseUp:
3422     case WebEvent::Wheel:
3423     case WebEvent::KeyDown:
3424     case WebEvent::KeyUp:
3425     case WebEvent::RawKeyDown:
3426     case WebEvent::Char:
3427 #if ENABLE(GESTURE_EVENTS)
3428     case WebEvent::GestureScrollBegin:
3429     case WebEvent::GestureScrollEnd:
3430     case WebEvent::GestureSingleTap:
3431 #endif
3432 #if ENABLE(TOUCH_EVENTS)
3433     case WebEvent::TouchStart:
3434     case WebEvent::TouchMove:
3435     case WebEvent::TouchEnd:
3436     case WebEvent::TouchCancel:
3437 #endif
3438         process()->responsivenessTimer()->stop();
3439         break;
3440     }
3441
3442     switch (type) {
3443     case WebEvent::NoType:
3444         break;
3445     case WebEvent::MouseMove:
3446         m_processingMouseMoveEvent = false;
3447         if (m_nextMouseMoveEvent) {
3448             handleMouseEvent(*m_nextMouseMoveEvent);
3449             m_nextMouseMoveEvent = nullptr;
3450         }
3451         break;
3452     case WebEvent::MouseDown:
3453         break;
3454 #if ENABLE(GESTURE_EVENTS)
3455     case WebEvent::GestureScrollBegin:
3456     case WebEvent::GestureScrollEnd:
3457     case WebEvent::GestureSingleTap: {
3458         WebGestureEvent event = m_gestureEventQueue.first();
3459         MESSAGE_CHECK(type == event.type());
3460
3461         m_gestureEventQueue.removeFirst();
3462         m_pageClient->doneWithGestureEvent(event, handled);
3463         break;
3464     }
3465 #endif
3466     case WebEvent::MouseUp:
3467         m_currentlyProcessedMouseDownEvent = nullptr;
3468         break;
3469
3470     case WebEvent::Wheel: {
3471         ASSERT(!m_currentlyProcessedWheelEvents.isEmpty());
3472
3473         OwnPtr<Vector<NativeWebWheelEvent> > oldestCoalescedEvent = m_currentlyProcessedWheelEvents.takeFirst();
3474
3475         // FIXME: Dispatch additional events to the didNotHandleWheelEvent client function.
3476         if (!handled && m_uiClient.implementsDidNotHandleWheelEvent())
3477             m_uiClient.didNotHandleWheelEvent(this, oldestCoalescedEvent->last());
3478
3479         if (!m_wheelEventQueue.isEmpty())
3480             processNextQueuedWheelEvent();
3481         break;
3482     }
3483
3484     case WebEvent::KeyDown:
3485     case WebEvent::KeyUp:
3486     case WebEvent::RawKeyDown:
3487     case WebEvent::Char: {
3488         LOG(KeyHandling, "WebPageProxy::didReceiveEvent: %s", webKeyboardEventTypeString(type));
3489
3490         NativeWebKeyboardEvent event = m_keyEventQueue.first();
3491         MESSAGE_CHECK(type == event.type());
3492
3493         m_keyEventQueue.removeFirst();
3494
3495         m_pageClient->doneWithKeyEvent(event, handled);
3496
3497         if (handled)
3498             break;
3499
3500         if (m_uiClient.implementsDidNotHandleKeyEvent())
3501             m_uiClient.didNotHandleKeyEvent(this, event);
3502 #if PLATFORM(WIN)
3503         else
3504             ::TranslateMessage(event.nativeEvent());
3505 #endif
3506         break;
3507     }
3508 #if ENABLE(TOUCH_EVENTS)
3509     case WebEvent::TouchStart:
3510     case WebEvent::TouchMove:
3511     case WebEvent::TouchEnd:
3512     case WebEvent::TouchCancel: {
3513         QueuedTouchEvents queuedEvents = m_touchEventQueue.first();
3514         MESSAGE_CHECK(type == queuedEvents.forwardedEvent.type());
3515         m_touchEventQueue.removeFirst();
3516
3517         m_pageClient->doneWithTouchEvent(queuedEvents.forwardedEvent, handled);
3518         for (size_t i = 0; i < queuedEvents.deferredTouchEvents.size(); ++i) {
3519             bool isEventHandled = false;
3520             m_pageClient->doneWithTouchEvent(queuedEvents.deferredTouchEvents.at(i), isEventHandled);
3521         }
3522         break;
3523     }
3524 #endif
3525     }
3526 }
3527
3528 void WebPageProxy::stopResponsivenessTimer()
3529 {
3530     process()->responsivenessTimer()->stop();
3531 }
3532
3533 void WebPageProxy::voidCallback(uint64_t callbackID)
3534 {
3535     RefPtr<VoidCallback> callback = m_voidCallbacks.take(callbackID);
3536     if (!callback) {
3537         // FIXME: Log error or assert.
3538         return;
3539     }
3540
3541     callback->performCallback();
3542 }
3543
3544 void WebPageProxy::dataCallback(const CoreIPC::DataReference& dataReference, uint64_t callbackID)
3545 {
3546     RefPtr<DataCallback> callback = m_dataCallbacks.take(callbackID);
3547     if (!callback) {
3548         // FIXME: Log error or assert.
3549         return;
3550     }
3551
3552     callback->performCallbackWithReturnValue(WebData::create(dataReference.data(), dataReference.size()).get());
3553 }
3554
3555 void WebPageProxy::stringCallback(const String& resultString, uint64_t callbackID)
3556 {
3557     RefPtr<StringCallback> callback = m_stringCallbacks.take(callbackID);
3558     if (!callback) {
3559         // FIXME: Log error or assert.
3560         // this can validly happen if a load invalidated the callback, though
3561         return;
3562     }
3563
3564     m_loadDependentStringCallbackIDs.remove(callbackID);
3565
3566     callback->performCallbackWithReturnValue(resultString.impl());
3567 }
3568
3569 void WebPageProxy::scriptValueCallback(const CoreIPC::DataReference& dataReference, uint64_t callbackID)
3570 {
3571     RefPtr<ScriptValueCallback> callback = m_scriptValueCallbacks.take(callbackID);
3572     if (!callback) {
3573         // FIXME: Log error or assert.
3574         return;
3575     }
3576
3577     Vector<uint8_t> data;
3578     data.reserveInitialCapacity(dataReference.size());
3579     data.append(dataReference.data(), dataReference.size());
3580
3581     callback->performCallbackWithReturnValue(data.size() ? WebSerializedScriptValue::adopt(data).get() : 0);
3582 }
3583
3584 void WebPageProxy::computedPagesCallback(const Vector<IntRect>& pageRects, double totalScaleFactorForPrinting, uint64_t callbackID)
3585 {
3586     RefPtr<ComputedPagesCallback> callback = m_computedPagesCallbacks.take(callbackID);
3587     if (!callback) {
3588         // FIXME: Log error or assert.
3589         return;
3590     }
3591
3592     callback->performCallbackWithReturnValue(pageRects, totalScaleFactorForPrinting);
3593 }
3594
3595 void WebPageProxy::validateCommandCallback(const String& commandName, bool isEnabled, int state, uint64_t callbackID)
3596 {
3597     RefPtr<ValidateCommandCallback> callback = m_validateCommandCallbacks.take(callbackID);
3598     if (!callback) {
3599         // FIXME: Log error or assert.
3600         return;
3601     }
3602
3603     callback->performCallbackWithReturnValue(commandName.impl(), isEnabled, state);
3604 }
3605
3606 #if PLATFORM(GTK)
3607 void WebPageProxy::printFinishedCallback(const ResourceError& printError, uint64_t callbackID)
3608 {
3609     RefPtr<PrintFinishedCallback> callback = m_printFinishedCallbacks.take(callbackID);
3610     if (!callback) {
3611         // FIXME: Log error or assert.
3612         return;
3613     }
3614
3615     RefPtr<WebError> error = WebError::create(printError);
3616     callback->performCallbackWithReturnValue(error.get());
3617 }
3618 #endif
3619
3620 void WebPageProxy::focusedFrameChanged(uint64_t frameID)
3621 {
3622     if (!frameID) {
3623         m_focusedFrame = 0;
3624         return;
3625     }
3626
3627     WebFrameProxy* frame = process()->webFrame(frameID);
3628     MESSAGE_CHECK(frame);
3629
3630     m_focusedFrame = frame;
3631 }
3632
3633 void WebPageProxy::frameSetLargestFrameChanged(uint64_t frameID)
3634 {
3635     if (!frameID) {
3636         m_frameSetLargestFrame = 0;
3637         return;
3638     }
3639
3640     WebFrameProxy* frame = process()->webFrame(frameID);
3641     MESSAGE_CHECK(frame);
3642
3643     m_frameSetLargestFrame = frame;
3644 }
3645
3646 void WebPageProxy::processDidBecomeUnresponsive()
3647 {
3648     if (!isValid())
3649         return;
3650
3651     updateBackingStoreDiscardableState();
3652
3653     m_loaderClient.processDidBecomeUnresponsive(this);
3654 }
3655
3656 void WebPageProxy::interactionOccurredWhileProcessUnresponsive()
3657 {
3658     if (!isValid())
3659         return;
3660
3661     m_loaderClient.interactionOccurredWhileProcessUnresponsive(this);
3662 }
3663
3664 void WebPageProxy::processDidBecomeResponsive()
3665 {
3666     if (!isValid())
3667         return;
3668     
3669     updateBackingStoreDiscardableState();
3670
3671     m_loaderClient.processDidBecomeResponsive(this);
3672 }
3673
3674 void WebPageProxy::processDidCrash()
3675 {
3676     ASSERT(m_pageClient);
3677
3678     m_isValid = false;
3679     m_isPageSuspended = false;
3680
3681     if (m_mainFrame) {
3682         m_urlAtProcessExit = m_mainFrame->url();
3683         m_loadStateAtProcessExit = m_mainFrame->loadState();
3684     }
3685
3686     m_mainFrame = nullptr;
3687     m_drawingArea = nullptr;
3688
3689 #if ENABLE(INSPECTOR)
3690     if (m_inspector) {
3691         m_inspector->invalidate();
3692         m_inspector = nullptr;
3693     }
3694 #endif
3695
3696 #if ENABLE(FULLSCREEN_API)
3697     if (m_fullScreenManager) {
3698         m_fullScreenManager->invalidate();
3699         m_fullScreenManager = nullptr;
3700     }
3701 #endif
3702
3703     if (m_openPanelResultListener) {
3704         m_openPanelResultListener->invalidate();
3705         m_openPanelResultListener = nullptr;
3706     }
3707
3708 #if ENABLE(INPUT_TYPE_COLOR)
3709     if (m_colorChooser) {
3710         m_colorChooser->invalidate();
3711         m_colorChooser = nullptr;
3712     }
3713 #endif
3714
3715 #if ENABLE(GEOLOCATION)
3716     m_geolocationPermissionRequestManager.invalidateRequests();
3717 #endif
3718
3719     m_notificationPermissionRequestManager.invalidateRequests();
3720
3721     m_toolTip = String();
3722
3723     m_mainFrameHasHorizontalScrollbar = false;
3724     m_mainFrameHasVerticalScrollbar = false;
3725
3726     m_mainFrameIsPinnedToLeftSide = false;
3727     m_mainFrameIsPinnedToRightSide = false;
3728
3729     m_visibleScrollerThumbRect = IntRect();
3730
3731 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
3732     invalidateCallbackMap(m_booleanCallbacks);
3733 #endif
3734     invalidateCallbackMap(m_voidCallbacks);
3735     invalidateCallbackMap(m_dataCallbacks);
3736     invalidateCallbackMap(m_stringCallbacks);
3737     m_loadDependentStringCallbackIDs.clear();
3738     invalidateCallbackMap(m_scriptValueCallbacks);
3739     invalidateCallbackMap(m_computedPagesCallbacks);
3740     invalidateCallbackMap(m_validateCommandCallbacks);
3741 #if PLATFORM(GTK)
3742     invalidateCallbackMap(m_printFinishedCallbacks);
3743 #endif
3744
3745     Vector<WebEditCommandProxy*> editCommandVector;
3746     copyToVector(m_editCommandSet, editCommandVector);
3747     m_editCommandSet.clear();
3748     for (size_t i = 0, size = editCommandVector.size(); i < size; ++i)
3749         editCommandVector[i]->invalidate();
3750     m_pageClient->clearAllEditCommands();
3751
3752     m_activePopupMenu = 0;
3753
3754     m_estimatedProgress = 0.0;
3755
3756     m_pendingLearnOrIgnoreWordMessageCount = 0;
3757
3758     m_pageClient->processDidCrash();
3759     m_loaderClient.processDidCrash(this);
3760
3761     if (!m_isValid) {
3762         // If the call out to the loader client didn't cause the web process to be relaunched, 
3763         // we'll call setNeedsDisplay on the view so that we won't have the old contents showing.
3764         // If the call did cause the web process to be relaunched, we'll keep the old page contents showing
3765         // until the new web process has painted its contents.
3766         setViewNeedsDisplay(IntRect(IntPoint(), viewSize()));
3767     }
3768
3769     // Can't expect DidReceiveEvent notifications from a crashed web process.
3770     m_keyEventQueue.clear();
3771     
3772     m_wheelEventQueue.clear();
3773     m_currentlyProcessedWheelEvents.clear();
3774
3775     m_nextMouseMoveEvent = nullptr;
3776     m_currentlyProcessedMouseDownEvent = nullptr;
3777
3778     m_processingMouseMoveEvent = false;
3779
3780 #if ENABLE(TOUCH_EVENTS)
3781     m_needTouchEvents = false;
3782     m_touchEventQueue.clear();
3783 #endif
3784
3785 #if PLATFORM(MAC) && !defined(BUILDING_ON_SNOW_LEOPARD)
3786     dismissCorrectionPanel(ReasonForDismissingAlternativeTextIgnored);
3787     m_pageClient->dismissDictionaryLookupPanel();
3788 #endif
3789 }
3790
3791 WebPageCreationParameters WebPageProxy::creationParameters() const
3792 {
3793     WebPageCreationParameters parameters;
3794
3795     parameters.viewSize = m_pageClient->viewSize();
3796     parameters.isActive = m_pageClient->isViewWindowActive();
3797     parameters.isFocused = m_pageClient->isViewFocused();
3798     parameters.isVisible = m_pageClient->isViewVisible();
3799     parameters.isInWindow = m_pageClient->isViewInWindow();
3800     parameters.drawingAreaType = m_drawingArea->type();
3801     parameters.store = m_pageGroup->preferences()->store();
3802     parameters.pageGroupData = m_pageGroup->data();
3803     parameters.drawsBackground = m_drawsBackground;
3804     parameters.drawsTransparentBackground = m_drawsTransparentBackground;
3805     parameters.areMemoryCacheClientCallsEnabled = m_areMemoryCacheClientCallsEnabled;
3806     parameters.useFixedLayout = m_useFixedLayout;
3807     parameters.fixedLayoutSize = m_fixedLayoutSize;
3808     parameters.paginationMode = m_paginationMode;
3809     parameters.paginationBehavesLikeColumns = m_paginationBehavesLikeColumns;
3810     parameters.pageLength = m_pageLength;
3811     parameters.gapBetweenPages = m_gapBetweenPages;
3812     parameters.userAgent = userAgent();
3813     parameters.sessionState = SessionState(m_backForwardList->entries(), m_backForwardList->currentIndex());
3814     parameters.highestUsedBackForwardItemID = WebBackForwardListItem::highedUsedItemID();
3815     parameters.canRunBeforeUnloadConfirmPanel = m_uiClient.canRunBeforeUnloadConfirmPanel();
3816     parameters.canRunModal = m_uiClient.canRunModal();
3817     parameters.deviceScaleFactor = m_intrinsicDeviceScaleFactor;
3818     parameters.mediaVolume = m_mediaVolume;
3819
3820 #if PLATFORM(MAC)
3821     parameters.isSmartInsertDeleteEnabled = m_isSmartInsertDeleteEnabled;
3822     parameters.layerHostingMode = m_layerHostingMode;
3823 #endif
3824
3825 #if PLATFORM(WIN)
3826     parameters.nativeWindow = m_pageClient->nativeWindow();
3827 #endif
3828     return parameters;
3829 }
3830
3831 #if USE(ACCELERATED_COMPOSITING)
3832 void WebPageProxy::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
3833 {
3834     m_pageClient->enterAcceleratedCompositingMode(layerTreeContext);
3835 }
3836
3837 void WebPageProxy::exitAcceleratedCompositingMode()
3838 {
3839     m_pageClient->exitAcceleratedCompositingMode();
3840 }
3841
3842 void WebPageProxy::updateAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
3843 {
3844     m_pageClient->updateAcceleratedCompositingMode(layerTreeContext);
3845 }
3846 #endif // USE(ACCELERATED_COMPOSITING)
3847
3848 void WebPageProxy::backForwardClear()
3849 {
3850     m_backForwardList->clear();
3851 }
3852
3853 void WebPageProxy::canAuthenticateAgainstProtectionSpaceInFrame(uint64_t frameID, const ProtectionSpace& coreProtectionSpace, bool& canAuthenticate)
3854 {
3855     WebFrameProxy* frame = process()->webFrame(frameID);
3856     MESSAGE_CHECK(frame);
3857
3858     RefPtr<WebProtectionSpace> protectionSpace = WebProtectionSpace::create(coreProtectionSpace);
3859     
3860     canAuthenticate = m_loaderClient.canAuthenticateAgainstProtectionSpaceInFrame(this, frame, protectionSpace.get());
3861 }
3862
3863 void WebPageProxy::didReceiveAuthenticationChallenge(uint64_t frameID, const AuthenticationChallenge& coreChallenge, uint64_t challengeID)
3864 {
3865     WebFrameProxy* frame = process()->webFrame(frameID);
3866     MESSAGE_CHECK(frame);
3867
3868     RefPtr<AuthenticationChallengeProxy> authenticationChallenge = AuthenticationChallengeProxy::create(coreChallenge, challengeID, process());
3869     
3870     m_loaderClient.didReceiveAuthenticationChallengeInFrame(this, frame, authenticationChallenge.get());
3871 }
3872
3873 void WebPageProxy::exceededDatabaseQuota(uint64_t frameID, const String& originIdentifier, const String& databaseName, const String& displayName, uint64_t currentQuota, uint64_t currentOriginUsage, uint64_t currentDatabaseUsage, uint64_t expectedUsage, uint64_t& newQuota)
3874 {
3875     WebFrameProxy* frame = process()->webFrame(frameID);
3876     MESSAGE_CHECK(frame);
3877
3878     RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier);
3879
3880     newQuota = m_uiClient.exceededDatabaseQuota(this, frame, origin.get(), databaseName, displayName, currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage);
3881 }
3882
3883 void WebPageProxy::requestGeolocationPermissionForFrame(uint64_t geolocationID, uint64_t frameID, String originIdentifier)
3884 {
3885     WebFrameProxy* frame = process()->webFrame(frameID);
3886     MESSAGE_CHECK(frame);
3887
3888     // FIXME: Geolocation should probably be using toString() as its string representation instead of databaseIdentifier().
3889     RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier);
3890     RefPtr<GeolocationPermissionRequestProxy> request = m_geolocationPermissionRequestManager.createRequest(geolocationID);
3891
3892     if (!m_uiClient.decidePolicyForGeolocationPermissionRequest(this, frame, origin.get(), request.get()))
3893         request->deny();
3894 }
3895
3896 void WebPageProxy::requestNotificationPermission(uint64_t requestID, const String& originString)
3897 {
3898     if (!isRequestIDValid(requestID))
3899         return;
3900
3901     RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromString(originString);
3902     RefPtr<NotificationPermissionRequest> request = m_notificationPermissionRequestManager.createRequest(requestID);
3903     
3904     if (!m_uiClient.decidePolicyForNotificationPermissionRequest(this, origin.get(), request.get()))
3905         request->deny();
3906 }
3907
3908 void WebPageProxy::showNotification(const String& title, const String& body, const String& iconURL, const String& tag, const String& originString, uint64_t notificationID)
3909 {
3910     m_process->context()->notificationManagerProxy()->show(this, title, body, iconURL, tag, originString, notificationID);
3911 }
3912
3913 #if ENABLE(TIZEN_MEDIA_STREAM)
3914 void WebPageProxy::requestUserMediaPermission(uint64_t requestID)
3915 {
3916     if (!isRequestIDValid(requestID))
3917         return;
3918
3919     RefPtr<UserMediaPermissionRequest> request = m_userMediaPermissionRequestManager.createRequest(requestID);
3920
3921     if (!m_tizenClient.decidePolicyForUserMediaPermissionRequest(this, request.get()))
3922         request->deny();
3923 }
3924 #endif
3925
3926 float WebPageProxy::headerHeight(WebFrameProxy* frame)
3927 {
3928     if (frame->isDisplayingPDFDocument())
3929         return 0;
3930     return m_uiClient.headerHeight(this, frame);
3931 }
3932
3933 float WebPageProxy::footerHeight(WebFrameProxy* frame)
3934 {
3935     if (frame->isDisplayingPDFDocument())
3936         return 0;
3937     return m_uiClient.footerHeight(this, frame);
3938 }
3939
3940 void WebPageProxy::drawHeader(WebFrameProxy* frame, const FloatRect& rect)
3941 {
3942     if (frame->isDisplayingPDFDocument())
3943         return;
3944     m_uiClient.drawHeader(this, frame, rect);
3945 }
3946
3947 void WebPageProxy::drawFooter(WebFrameProxy* frame, const FloatRect& rect)
3948 {
3949     if (frame->isDisplayingPDFDocument())
3950         return;
3951     m_uiClient.drawFooter(this, frame, rect);
3952 }
3953
3954 void WebPageProxy::runModal()
3955 {
3956     // Since runModal() can (and probably will) spin a nested run loop we need to turn off the responsiveness timer.
3957     process()->responsivenessTimer()->stop();
3958
3959     m_uiClient.runModal(this);
3960 }
3961
3962 void WebPageProxy::notifyScrollerThumbIsVisibleInRect(const IntRect& scrollerThumb)
3963 {
3964     m_visibleScrollerThumbRect = scrollerThumb;
3965 }
3966
3967 void WebPageProxy::recommendedScrollbarStyleDidChange(int32_t newStyle)
3968 {
3969 #if PLATFORM(MAC)
3970     m_pageClient->recommendedScrollbarStyleDidChange(newStyle);
3971 #endif
3972 }
3973
3974 void WebPageProxy::didChangeScrollbarsForMainFrame(bool hasHorizontalScrollbar, bool hasVerticalScrollbar)
3975 {
3976     m_mainFrameHasHorizontalScrollbar = hasHorizontalScrollbar;
3977     m_mainFrameHasVerticalScrollbar = hasVerticalScrollbar;
3978
3979     m_pageClient->didChangeScrollbarsForMainFrame();
3980 }
3981
3982 void WebPageProxy::didChangeScrollOffsetPinningForMainFrame(bool pinnedToLeftSide, bool pinnedToRightSide)
3983 {
3984     m_mainFrameIsPinnedToLeftSide = pinnedToLeftSide;
3985     m_mainFrameIsPinnedToRightSide = pinnedToRightSide;
3986 }
3987
3988 void WebPageProxy::didChangePageCount(unsigned pageCount)
3989 {
3990     m_pageCount = pageCount;
3991 }
3992
3993 void WebPageProxy::didFailToInitializePlugin(const String& mimeType)
3994 {
3995     m_loaderClient.didFailToInitializePlugin(this, mimeType);
3996 }
3997
3998 void WebPageProxy::didBlockInsecurePluginVersion(const String& mimeType, const String& urlString)
3999 {
4000     String pluginIdentifier;
4001     String pluginVersion;
4002     String newMimeType = mimeType;
4003
4004 #if PLATFORM(MAC)
4005     PluginModuleInfo plugin = m_process->context()->pluginInfoStore().findPlugin(newMimeType, KURL(KURL(), urlString));
4006
4007     pluginIdentifier = plugin.bundleIdentifier;
4008     pluginVersion = plugin.versionString;
4009 #endif
4010
4011     m_loaderClient.didBlockInsecurePluginVersion(this, newMimeType, pluginIdentifier, pluginVersion);
4012 }
4013
4014 bool WebPageProxy::willHandleHorizontalScrollEvents() const
4015 {
4016     return !m_canShortCircuitHorizontalWheelEvents;
4017 }
4018
4019 void WebPageProxy::didFinishLoadingDataForCustomRepresentation(const String& suggestedFilename, const CoreIPC::DataReference& dataReference)
4020 {
4021     m_pageClient->didFinishLoadingDataForCustomRepresentation(suggestedFilename, dataReference);
4022 }
4023
4024 void WebPageProxy::backForwardRemovedItem(uint64_t itemID)
4025 {
4026     process()->send(Messages::WebPage::DidRemoveBackForwardItem(itemID), m_pageID);
4027 }
4028
4029 void WebPageProxy::beginPrinting(WebFrameProxy* frame, const PrintInfo& printInfo)
4030 {
4031     if (m_isInPrintingMode)
4032         return;
4033
4034     m_isInPrintingMode = true;
4035     process()->send(Messages::WebPage::BeginPrinting(frame->frameID(), printInfo), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
4036 }
4037
4038 void WebPageProxy::endPrinting()
4039 {
4040     if (!m_isInPrintingMode)
4041         return;
4042
4043     m_isInPrintingMode = false;
4044     process()->send(Messages::WebPage::EndPrinting(), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
4045 }
4046
4047 void WebPageProxy::computePagesForPrinting(WebFrameProxy* frame, const PrintInfo& printInfo, PassRefPtr<ComputedPagesCallback> prpCallback)
4048 {
4049     RefPtr<ComputedPagesCallback> callback = prpCallback;
4050     if (!isValid()) {
4051         callback->invalidate();
4052         return;
4053     }
4054
4055     uint64_t callbackID = callback->callbackID();
4056     m_computedPagesCallbacks.set(callbackID, callback.get());
4057     m_isInPrintingMode = true;
4058     process()->send(Messages::WebPage::ComputePagesForPrinting(frame->frameID(), printInfo, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
4059 }
4060
4061 #if PLATFORM(MAC) || PLATFORM(WIN)
4062 void WebPageProxy::drawRectToPDF(WebFrameProxy* frame, const PrintInfo& printInfo, const IntRect& rect, PassRefPtr<DataCallback> prpCallback)
4063 {
4064     RefPtr<DataCallback> callback = prpCallback;
4065     if (!isValid()) {
4066         callback->invalidate();
4067         return;
4068     }
4069     
4070     uint64_t callbackID = callback->callbackID();
4071     m_dataCallbacks.set(callbackID, callback.get());
4072     process()->send(Messages::WebPage::DrawRectToPDF(frame->frameID(), printInfo, rect, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
4073 }
4074
4075 void WebPageProxy::drawPagesToPDF(WebFrameProxy* frame, const PrintInfo& printInfo, uint32_t first, uint32_t count, PassRefPtr<DataCallback> prpCallback)
4076 {
4077     RefPtr<DataCallback> callback = prpCallback;
4078     if (!isValid()) {
4079         callback->invalidate();
4080         return;
4081     }
4082     
4083     uint64_t callbackID = callback->callbackID();
4084     m_dataCallbacks.set(callbackID, callback.get());
4085     process()->send(Messages::WebPage::DrawPagesToPDF(frame->frameID(), printInfo, first, count, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
4086 }
4087 #elif PLATFORM(GTK)
4088 void WebPageProxy::drawPagesForPrinting(WebFrameProxy* frame, const PrintInfo& printInfo, PassRefPtr<PrintFinishedCallback> didPrintCallback)
4089 {
4090     RefPtr<PrintFinishedCallback> callback = didPrintCallback;
4091     if (!isValid()) {
4092         callback->invalidate();
4093         return;
4094     }
4095
4096     uint64_t callbackID = callback->callbackID();
4097     m_printFinishedCallbacks.set(callbackID, callback.get());
4098     m_isInPrintingMode = true;
4099     process()->send(Messages::WebPage::DrawPagesForPrinting(frame->frameID(), printInfo, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
4100 }
4101 #endif
4102
4103 void WebPageProxy::flashBackingStoreUpdates(const Vector<IntRect>& updateRects)
4104 {
4105     m_pageClient->flashBackingStoreUpdates(updateRects);
4106 }
4107
4108 void WebPageProxy::updateBackingStoreDiscardableState()
4109 {
4110     ASSERT(isValid());
4111
4112     bool isDiscardable;
4113
4114     if (!process()->responsivenessTimer()->isResponsive())
4115         isDiscardable = false;
4116     else
4117         isDiscardable = !m_pageClient->isViewWindowActive() || !isViewVisible();
4118
4119     m_drawingArea->setBackingStoreIsDiscardable(isDiscardable);
4120 }
4121
4122 Color WebPageProxy::viewUpdatesFlashColor()
4123 {
4124     return Color(0, 200, 255);
4125 }
4126
4127 Color WebPageProxy::backingStoreUpdatesFlashColor()
4128 {
4129     return Color(200, 0, 255);
4130 }
4131
4132 void WebPageProxy::saveDataToFileInDownloadsFolder(const String& suggestedFilename, const String& mimeType, const String& originatingURLString, WebData* data)
4133 {
4134     m_uiClient.saveDataToFileInDownloadsFolder(this, suggestedFilename, mimeType, originatingURLString, data);
4135 }
4136
4137 void WebPageProxy::linkClicked(const String& url, const WebMouseEvent& event)
4138 {
4139     process()->send(Messages::WebPage::LinkClicked(url, event), m_pageID, 0);
4140 }
4141
4142 #if PLATFORM(MAC)
4143
4144 void WebPageProxy::substitutionsPanelIsShowing(bool& isShowing)
4145 {
4146     isShowing = TextChecker::substitutionsPanelIsShowing();
4147 }
4148
4149 #if !defined(BUILDING_ON_SNOW_LEOPARD)
4150 void WebPageProxy::showCorrectionPanel(int32_t panelType, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings)
4151 {
4152     m_pageClient->showCorrectionPanel((AlternativeTextType)panelType, boundingBoxOfReplacedString, replacedString, replacementString, alternativeReplacementStrings);
4153 }
4154
4155 void WebPageProxy::dismissCorrectionPanel(int32_t reason)
4156 {
4157     m_pageClient->dismissCorrectionPanel((ReasonForDismissingAlternativeText)reason);
4158 }
4159
4160 void WebPageProxy::dismissCorrectionPanelSoon(int32_t reason, String& result)
4161 {
4162     result = m_pageClient->dismissCorrectionPanelSoon((ReasonForDismissingAlternativeText)reason);
4163 }
4164
4165 void WebPageProxy::recordAutocorrectionResponse(int32_t responseType, const String& replacedString, const String& replacementString)
4166 {
4167     m_pageClient->recordAutocorrectionResponse((AutocorrectionResponseType)responseType, replacedString, replacementString);
4168 }
4169 #endif // !defined(BUILDING_ON_SNOW_LEOPARD)
4170
4171 void WebPageProxy::handleAlternativeTextUIResult(const String& result)
4172 {
4173 #if !defined(BUILDING_ON_SNOW_LEOPARD)
4174     if (!isClosed())
4175         process()->send(Messages::WebPage::HandleAlternativeTextUIResult(result), m_pageID, 0);
4176 #endif
4177 }
4178 #endif // PLATFORM(MAC)
4179
4180 #if ENABLE(TIZEN_PAGE_VISIBILITY_API)
4181 void WebPageProxy::setPageVisibility(WebCore::PageVisibilityState pageVisibilityState, bool isInitialState)
4182 {
4183     process()->send(Messages::WebPage::SetVisibilityState(static_cast<uint32_t>(pageVisibilityState), isInitialState), m_pageID);
4184 }
4185 #endif
4186
4187 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
4188 void WebPageProxy::updateLayoutAndScaleIfNeeded()
4189 {
4190     m_pageClient->updateLayoutAndScaleIfNeeded();
4191 }
4192 #endif
4193
4194 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
4195 void WebPageProxy::decidePolicyForCertificateError(bool isTrusted, const String& url, const String& certificate, int error, bool& canContinue)
4196 {
4197     canContinue = m_tizenClient.decidePolicyForCertificateError(this, isTrusted, url, certificate, error);
4198 }
4199 #endif
4200
4201 } // namespace WebKit