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