Fix IME issue in twitter application
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / efl / WebPageProxyEfl.cpp
1 /*
2  * Copyright (C) 2011 Samsung Electronics
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "WebPageProxy.h"
28
29 #include "EwkViewImpl.h"
30 #include "NativeWebKeyboardEvent.h"
31 #include "NotImplemented.h"
32 #include "PageClientImpl.h"
33 #include "WebPageMessages.h"
34 #include "WebProcessProxy.h"
35
36 #include <sys/utsname.h>
37
38 #if OS(TIZEN)
39 #include "DrawingAreaMessages.h"
40
41 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
42 #include "LayerTreeCoordinatorProxy.h"
43 #endif
44 #include "NativeWebKeyboardEvent.h"
45 #include "WebImage.h"
46 #include "WebPageMessages.h"
47 #include "WebProcessProxy.h"
48 #include <WebCore/IntSize.h>
49 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
50 #include "WebContextMenuProxy.h"
51 #include "ewk_view_private.h"
52 #endif
53
54 #define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, m_process->connection())
55
56 #if ENABLE(TIZEN_LINK_MAGNIFIER)
57 #include "LinkMagnifierProxy.h"
58 #endif
59
60 #if ENABLE(TIZEN_SCREEN_READER)
61 #include "ScreenReaderProxy.h"
62 #include "ewk_view_private.h"
63 #endif
64
65 #if ENABLE(TIZEN_CSP)
66 #include <WebCore/ContentSecurityPolicy.h>
67 #endif
68
69 using namespace WebCore;
70 #endif
71
72 namespace WebKit {
73
74 Evas_Object* WebPageProxy::viewWidget()
75 {
76     return static_cast<PageClientImpl*>(m_pageClient)->viewImpl()->view();
77 }
78
79 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
80 {
81 #if OS(TIZEN)
82     return String::fromUTF8("Mozilla/5.0 (Linux; U; Tizen 2.0; en-us) AppleWebKit/537.1 (KHTML, like Gecko) Mobile TizenBrowser/2.0");
83 #endif
84
85     WTF::String platform;
86     WTF::String version;
87     WTF::String osVersion;
88
89 #if PLATFORM(X11)
90     platform = "X11";
91 #else
92     platform = "Unknown";
93 #endif
94     version = makeString(String::number(WEBKIT_USER_AGENT_MAJOR_VERSION), '.',
95                          String::number(WEBKIT_USER_AGENT_MINOR_VERSION), '+');
96     struct utsname name;
97     if (uname(&name) != -1)
98         osVersion = WTF::String(name.sysname) + " " + WTF::String(name.machine);
99     else
100         osVersion = "Unknown";
101
102     if (applicationNameForUserAgent.isEmpty())
103         return makeString("Mozilla/5.0 (", platform, "; ", osVersion, ") AppleWebKit/", version,
104                " (KHTML, like Gecko) Version/5.0 Safari/", version);
105
106     return makeString("Mozilla/5.0 (", platform, "; ", osVersion, ") AppleWebKit/", version,
107            " (KHTML, like Gecko) Version/5.0 Safari/", version, applicationNameForUserAgent);
108 }
109
110 void WebPageProxy::getEditorCommandsForKeyEvent(Vector<WTF::String>& commandsList)
111 {
112     notImplemented();
113 }
114
115 void WebPageProxy::saveRecentSearches(const String&, const Vector<String>&)
116 {
117     notImplemented();
118 }
119
120 void WebPageProxy::loadRecentSearches(const String&, Vector<String>&)
121 {
122     notImplemented();
123 }
124
125 void WebPageProxy::setThemePath(const String& themePath)
126 {
127     process()->send(Messages::WebPage::SetThemePath(themePath), m_pageID, 0);
128 }
129
130 #if ENABLE(TIZEN_CUSTOM_HEADERS)
131 void WebPageProxy::addCustomHeader(const String& name, const String& value)
132 {
133     if (name.isEmpty())
134         return;
135
136     if (value.isEmpty())
137         return;
138
139     if (!isValid())
140         return;
141
142     process()->send(Messages::WebPage::AddCustomHeader(name, value), m_pageID);
143 }
144
145 void WebPageProxy::removeCustomHeader(const String& name)
146 {
147     if (name.isEmpty())
148         return;
149
150     if (!isValid())
151         return;
152
153     process()->send(Messages::WebPage::RemoveCustomHeader(name), m_pageID);
154 }
155
156 void WebPageProxy::clearCustomHeaders()
157 {
158     if (!isValid())
159         return;
160
161     process()->send(Messages::WebPage::ClearCustomHeaders(), m_pageID);
162 }
163 #endif
164
165 #if OS(TIZEN)
166 bool WebPageProxy::scrollMainFrameBy(const IntSize& scrollOffset)
167 {
168 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
169     return static_cast<PageClientImpl*>(m_pageClient)->scrollBy(scrollOffset);
170 #else
171     if (!isValid())
172         return false;
173
174     process()->send(Messages::WebPage::ScrollMainFrameBy(scrollOffset), m_pageID);
175     return true;
176 #endif
177 }
178
179 void WebPageProxy::scrollMainFrameTo(const IntPoint& scrollPosition)
180 {
181 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
182     static_cast<PageClientImpl*>(m_pageClient)->scrollTo(scrollPosition);
183 #else
184     if (!isValid())
185         return;
186
187     process()->send(Messages::WebPage::ScrollMainFrameTo(scrollPosition), m_pageID);
188 #endif
189 }
190
191 void WebPageProxy::didChangeScrollPositionForMainFrame(const IntPoint& scrollPosition)
192 {
193 #if !ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
194     m_scrollPosition = scrollPosition;
195 #endif
196 }
197
198 void WebPageProxy::didChangeContentsSize(const IntSize& size)
199 {
200     if (m_contentsSize == size)
201         return;
202
203     m_contentsSize = size;
204     m_pageClient->didChangeContentsSize(size);
205 }
206
207 PassRefPtr<WebImage> WebPageProxy::createSnapshot(const IntRect& rect, float scaleFactor)
208 {
209     if (!isValid())
210         return 0;
211
212     ShareableBitmap::Handle snapshotHandle;
213     // Do not wait for more than a second (arbitrary) for the WebProcess to get the snapshot so
214     // that the UI Process is not permanently stuck waiting on a potentially crashing Web Process.
215     static const double createSnapshotSyncMessageTimeout = 1.0;
216 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
217     float baseScaleFactor = static_cast<PageClientImpl*>(m_pageClient)->scaleFactor();
218     scaleFactor = scaleFactor * baseScaleFactor;
219
220     IntRect visibleContentRect = static_cast<PageClientImpl*>(m_pageClient)->visibleContentRect();
221     IntRect scaledRect = rect;
222     scaledRect.move(visibleContentRect.x(), visibleContentRect.y());
223     scaledRect.scale(1/baseScaleFactor);
224     process()->sendSync(Messages::WebPage::CreateSnapshot(scaledRect, scaleFactor), Messages::WebPage::CreateSnapshot::Reply(snapshotHandle), m_pageID, createSnapshotSyncMessageTimeout);
225 #else
226     process()->sendSync(Messages::WebPage::CreateSnapshot(rect, scaleFactor), Messages::WebPage::CreateSnapshot::Reply(snapshotHandle), m_pageID, createSnapshotSyncMessageTimeout);
227 #endif
228     if (snapshotHandle.isNull())
229         return 0;
230     return WebImage::create(ShareableBitmap::create(snapshotHandle));
231 }
232
233 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
234 void WebPageProxy::textChangeInTextField(const String& name, const String& value)
235 {
236     static_cast<PageClientImpl*>(m_pageClient)->textChangeInTextField(name, value);
237 }
238 #endif
239
240 #if ENABLE(TIZEN_ISF_PORT)
241 void WebPageProxy::setInputMethodState(bool active)
242 {
243     InputMethodContextEfl* inputMethodContext = static_cast<PageClientImpl*>(m_pageClient)->viewImpl()->inputMethodContext();
244     if (!active)
245         return;
246
247     inputMethodContext->setTryToShow(true);
248     inputMethodContext->updateTextInputState();
249     inputMethodContext->setTryToShow(false);
250 }
251
252 int WebPageProxy::getCursorOffset()
253 {
254     if (!isValid())
255         return 0;
256
257     int offset = 0;
258     process()->sendSync(Messages::WebPage::GetCursorOffset(), Messages::WebPage::GetCursorOffset::Reply(offset), m_pageID);
259     return offset;
260 }
261
262 void WebPageProxy::getSurroundingTextAndCursorOffset(String& text, int& offset)
263 {
264     if (!isValid())
265         return;
266
267     process()->sendSync(Messages::WebPage::GetSurroundingTextAndCursorOffset(), Messages::WebPage::GetSurroundingTextAndCursorOffset::Reply(text, offset), m_pageID);
268 }
269
270 IntRect WebPageProxy::getSelectionRect(bool isOnlyEditable)
271 {
272     IntRect rect;
273     process()->sendSync(Messages::WebPage::GetSelectionRect(isOnlyEditable), Messages::WebPage::GetSelectionRect::Reply(rect), m_pageID);
274     return rect;
275 }
276
277 void WebPageProxy::deleteSurroundingText(int offset, int count)
278 {
279     if (!isValid())
280         return;
281
282     process()->send(Messages::WebPage::DeleteSurroundingText(offset, count), m_pageID);
283 }
284
285 void WebPageProxy::didCancelComposition()
286 {
287     m_didCancelCompositionFromWebProcess = true;
288     InputMethodContextEfl* inputMethodContext = static_cast<PageClientImpl*>(m_pageClient)->viewImpl()->inputMethodContext();
289     if (inputMethodContext)
290         inputMethodContext->resetIMFContext();
291     m_didCancelCompositionFromWebProcess = false;
292 }
293 #endif
294
295 void WebPageProxy::requestUpdateFormNavigation()
296 {
297     if (!isValid())
298         return;
299
300     process()->send(Messages::WebPage::RequestUpdateFormNavigation(), m_pageID);
301 }
302
303 void WebPageProxy::moveFocus(int newIndex)
304 {
305     if (!isValid())
306         return;
307
308     process()->send(Messages::WebPage::MoveFocus(newIndex), m_pageID);
309 }
310
311 void WebPageProxy::updateFormNavigation(int length, int offset)
312 {
313     static_cast<PageClientImpl*>(m_pageClient)->updateFormNavigation(length, offset);
314 }
315
316 #if ENABLE(TIZEN_REDUCE_KEY_LAGGING)
317 Eina_Bool WebPageProxy::pageContentResumeTimerFired(void* data)
318 {
319     static_cast<WebPageProxy*>(data)->resumeActiveDOMObjectsAndAnimations();
320     static_cast<WebPageProxy*>(data)->m_pageContentResumeTimer = 0;
321     return ECORE_CALLBACK_CANCEL;
322 }
323 #endif
324
325 #if ENABLE(TIZEN_TEXT_CARET_HANDLING_WK2)
326 void WebPageProxy::setCaretPosition(const WebCore::IntPoint& pos)
327 {
328     if (!isValid())
329         return;
330
331     process()->send(Messages::WebPage::SetCaretPosition(pos), m_pageID);
332 }
333
334 void WebPageProxy::getCaretPosition(WebCore::IntRect& rect)
335 {
336     if (!isValid())
337         return;
338
339     process()->sendSync(Messages::WebPage::GetCaretPosition(), Messages::WebPage::GetCaretPosition::Reply(rect), m_pageID);
340 }
341 #endif
342
343 #if ENABLE(TIZEN_PLUGIN_CUSTOM_REQUEST)
344 void WebPageProxy::processPluginCustomRequest(const String& request, const String& msg)
345 {
346     if (String("requestKeyboard,plugin") == request) {
347         bool active = false;
348         if (String("show") == msg)
349             active = true;
350 #if ENABLE(TIZEN_ISF_PORT)
351         m_editorState = EditorState();
352         m_editorState.isContentEditable = active;
353         m_pageClient->updateTextInputState();
354 #endif
355     }
356 #if ENABLE(TIZEN_JSBRIDGE_PLUGIN)
357     else if (String("requestToNative,json") == request)
358         m_tizenClient.processJSBridgePlugin(this, request, msg);
359 #endif
360 }
361 #endif
362
363
364 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION) || ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
365 void WebPageProxy::setFocusedInputElementValue(const String& inputValue)
366 {
367     if (!isValid())
368         return;
369
370     process()->send(Messages::WebPage::SetFocusedInputElementValue(inputValue), m_pageID);
371 }
372
373 String WebPageProxy::getFocusedInputElementValue()
374 {
375     if (!isValid())
376         return String();
377
378     String inputValue;
379     process()->sendSync(Messages::WebPage::GetFocusedInputElementValue(), Messages::WebPage::GetFocusedInputElementValue::Reply(inputValue), m_pageID);
380     return inputValue;
381 }
382 #endif
383
384 #if ENABLE(TIZEN_DATALIST_ELEMENT)
385 Vector<String> WebPageProxy::getFocusedInputElementDataList()
386 {
387     if (!isValid())
388         return Vector<String>();
389
390     Vector<String> optionList;
391     process()->sendSync(Messages::WebPage::GetFocusedInputElementDataList(), Messages::WebPage::GetFocusedInputElementDataList::Reply(optionList), m_pageID);
392     return optionList;
393 }
394 #endif
395
396 void WebPageProxy::focusedNodeChanged(const IntRect& focusedNodeRect)
397 {
398     static_cast<PageClientImpl*>(m_pageClient)->setFocusedNodeRect(focusedNodeRect);
399 }
400
401 void WebPageProxy::initializeTizenClient(const WKPageTizenClient* client)
402 {
403     m_tizenClient.initialize(client);
404 }
405
406 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
407 WebHitTestResult::Data WebPageProxy::hitTestResultAtPoint(const IntPoint& point, int hitTestMode)
408 {
409     WebHitTestResult::Data hitTestResultData;
410     if (!isValid())
411         return hitTestResultData;
412
413     process()->sendSync(Messages::WebPage::HitTestResultAtPoint(point, hitTestMode),
414                         Messages::WebPage::HitTestResultAtPoint::Reply(hitTestResultData), m_pageID);
415
416     return hitTestResultData;
417 }
418 #endif
419
420 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
421 void WebPageProxy::recordingSurfaceSetEnableSet(bool enable)
422 {
423     if (!isValid())
424         return;
425
426     process()->send(Messages::WebPage::RecordingSurfaceSetEnableSet(enable), m_pageID, 0);
427 }
428 #endif
429
430 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
431 void WebPageProxy::hideContextMenu()
432 {
433     if (m_activeContextMenu)
434         m_activeContextMenu->hideContextMenu();
435 }
436
437 String WebPageProxy::contextMenuAbsoluteLinkURLString()
438 {
439     if (!m_activeContextMenu)
440         return String();
441
442     return m_activeContextMenuHitTestResultData.absoluteLinkURL;
443 }
444
445 String WebPageProxy::contextMenuAbsoluteImageURLString()
446 {
447     if (!m_activeContextMenu)
448         return String();
449
450     return m_activeContextMenuHitTestResultData.absoluteImageURL;
451 }
452 #endif
453
454 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
455 void WebPageProxy::pasteContextMenuSelected()
456 {
457     static_cast<PageClientImpl*>(m_pageClient)->pasteContextMenuSelected();
458 }
459
460 void WebPageProxy::didSelectPasteMenuFromContextMenu(const String& data, const String& type)
461 {
462     if (!isValid())
463         return;
464
465 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
466     process()->send(Messages::WebPage::SetClipboardDataForPaste(data, type), m_pageID);
467 #endif
468     WebContextMenuItemData item(ActionType, ContextMenuItemTagPaste, String("Paste"), true, false);
469     process()->send(Messages::WebPage::DidSelectItemFromActiveContextMenu(item), m_pageID);
470 }
471 #endif
472
473 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
474 void WebPageProxy::setClipboardData(const String& data, const String& type)
475 {
476     static_cast<PageClientImpl*>(m_pageClient)->setClipboardData(data, type);
477 }
478
479 void WebPageProxy::clearClipboardData()
480 {
481     static_cast<PageClientImpl*>(m_pageClient)->clearClipboardData();
482 }
483 #endif
484
485 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
486 void WebPageProxy::executePasteFromClipboardItem(const String& data, const String& type)
487 {
488     if (!isValid())
489         return;
490
491 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
492     process()->send(Messages::WebPage::SetClipboardDataForPaste(data, type), m_pageID);
493 #endif
494     process()->send(Messages::WebPage::ExecuteEditCommandWithArgument("Paste", data), m_pageID);
495 }
496
497 void WebPageProxy::clipboardContextMenuSelected()
498 {
499     static_cast<PageClientImpl*>(m_pageClient)->clipboardContextMenuSelected();
500 }
501 #endif
502
503 #if ENABLE(TIZEN_WEBKIT2_REMOTE_WEB_INSPECTOR)
504 uint32_t WebPageProxy::startInspectorServer(uint32_t port)
505 {
506     if (!isValid())
507         return 0;
508
509     uint32_t assignedPort = 0;
510     process()->sendSync(Messages::WebPage::StartInspectorServer(port), Messages::WebPage::StartInspectorServer::Reply(assignedPort), m_pageID);
511     return assignedPort;
512 }
513
514 bool WebPageProxy::stopInspectorServer()
515 {
516     if (!isValid())
517         return false;
518
519     bool result = false;
520     process()->sendSync(Messages::WebPage::StopInspectorServer(), Messages::WebPage::StopInspectorServer::Reply(result), m_pageID);
521     return result;
522 }
523 #endif
524
525 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
526 void WebPageProxy::createPagesToPDF(const IntSize& surfaceSize, const IntSize& contentsSize, const String& fileName)
527 {
528     process()->send(Messages::WebPage::CreatePagesToPDF(surfaceSize, contentsSize, fileName), m_pageID);
529 }
530 #endif
531
532 #if ENABLE(TIZEN_WEB_STORAGE)
533 #if ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
534 void WebPageProxy::getWebStorageQuotaBytes(PassRefPtr<WebStorageQuotaCallback> prpCallback)
535 {
536     RefPtr<WebStorageQuotaCallback> callback = prpCallback;
537     if (!isValid()) {
538         callback->invalidate();
539         return;
540     }
541
542     uint64_t callbackID = callback->callbackID();
543     m_quotaCallbacks.set(callbackID, callback.get());
544     process()->send(Messages::WebPage::GetStorageQuotaBytes(callbackID), m_pageID);
545 }
546
547 void WebPageProxy::didGetWebStorageQuotaBytes(const uint32_t quota, uint64_t callbackID)
548 {
549     RefPtr<WebStorageQuotaCallback> callback = m_quotaCallbacks.take(callbackID);
550     if (!callback) {
551         // FIXME: Log error or assert.
552         // this can validly happen if a load invalidated the callback, though
553         return;
554     }
555
556     m_quotaCallbacks.remove(callbackID);
557
558     RefPtr<WebUInt32> uint32Object = WebUInt32::create(quota);
559     callback->performCallbackWithReturnValue(uint32Object.release().leakRef());
560 }
561 #endif
562
563 void WebPageProxy::setWebStorageQuotaBytes(uint32_t quota)
564 {
565     if (!isValid())
566         return;
567
568     process()->send(Messages::WebPage::SetStorageQuotaBytes(quota), m_pageID, 0);
569 }
570 #endif
571
572 void WebPageProxy::scale(double scaleFactor, const IntPoint& origin)
573 {
574 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
575     static_cast<PageClientImpl*>(m_pageClient)->scaleContents(scaleFactor, origin);
576 #else
577     scalePage(scaleFactor, origin);
578 #endif
579 }
580
581 void WebPageProxy::scaleImage(double scaleFactor, const IntPoint& origin)
582 {
583 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
584     static_cast<PageClientImpl*>(m_pageClient)->scaleImage(scaleFactor, origin);
585 #else
586     scalePage(scaleFactor, origin);
587 #endif
588 }
589
590 double WebPageProxy::scaleFactor()
591 {
592 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
593     return static_cast<PageClientImpl*>(m_pageClient)->scaleFactor();
594 #else
595     return pageScaleFactor();
596 #endif
597 }
598
599 #if ENABLE(TIZEN_ORIENTATION_EVENTS)
600 void WebPageProxy::sendOrientationChangeEvent(int orientation)
601 {
602     process()->send(Messages::WebPage::SendOrientationChangeEvent(orientation), m_pageID, 0);
603 }
604 #endif
605
606 void WebPageProxy::suspendPainting()
607 {
608     if (!isValid())
609         return;
610
611     process()->send(Messages::DrawingArea::SuspendPainting(), m_pageID);
612 }
613
614 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
615 void WebPageProxy::suspendPaintingOfInactiveView()
616 {
617     if (!isValid() || isViewVisible())
618         return;
619
620     process()->send(Messages::DrawingArea::SuspendPainting(), m_pageID);
621 }
622 #endif
623
624 void WebPageProxy::resumePainting()
625 {
626     if (!isValid())
627         return;
628
629     process()->send(Messages::DrawingArea::ResumePainting(), m_pageID);
630 }
631
632 void WebPageProxy::suspendJavaScriptAndResource()
633 {
634     if (!isValid())
635         return;
636
637     process()->send(Messages::WebPage::SuspendJavaScriptAndResources(), m_pageID);
638 }
639
640 void WebPageProxy::resumeJavaScriptAndResource()
641 {
642     if (!isValid())
643         return;
644
645     process()->send(Messages::WebPage::ResumeJavaScriptAndResources(), m_pageID);
646 }
647
648 #if ENABLE(TIZEN_PLUGIN_SUSPEND_RESUME)
649 void WebPageProxy::suspendPlugin()
650 {
651     if (!isValid())
652         return;
653
654     process()->send(Messages::WebPage::SuspendPlugin(), m_pageID);
655 }
656
657 void WebPageProxy::resumePlugin()
658 {
659     if (!isValid())
660         return;
661
662     process()->send(Messages::WebPage::ResumePlugin(), m_pageID);
663 }
664 #endif
665
666 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
667 bool WebPageProxy::scrollOverflow(const FloatPoint& offset)
668 {
669     if (!isValid())
670         return false;
671
672 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
673     if (static_cast<PageClientImpl*>(m_pageClient)->isScrollableLayerFocused())
674         return drawingArea()->layerTreeCoordinatorProxy()->setOffsetForFocusedScrollingContentsLayer(offset);
675 #endif
676     if (static_cast<PageClientImpl*>(m_pageClient)->isScrollableNodeFocused()) {
677         bool scrolled = false;
678         process()->sendSync(Messages::WebPage::ScrollOverflow(offset), Messages::WebPage::ScrollOverflow::Reply(scrolled), m_pageID);
679         return scrolled;
680     }
681
682     return false;
683 }
684
685 bool WebPageProxy::setPressedNodeAtPoint(const IntPoint& point, bool checkOverflowLayer, WebLayerID& webLayerID)
686 {
687     if (!isValid())
688         return false;
689
690     bool pressed = false;
691     process()->sendSync(Messages::WebPage::SetPressedNodeAtPoint(point, checkOverflowLayer), Messages::WebPage::SetPressedNodeAtPoint::Reply(pressed, webLayerID), m_pageID);
692
693     return pressed;
694 }
695
696 void WebPageProxy::setOverflowResult(bool pressed, uint32_t webLayerID)
697 {
698     static_cast<PageClientImpl*>(m_pageClient)->setOverflowResult(pressed, webLayerID);
699 }
700 #endif
701
702 void WebPageProxy::executeEditCommandWithArgument(const String& commandName, const String& argument)
703 {
704     if (!isValid())
705         return;
706
707     DEFINE_STATIC_LOCAL(String, ignoreSpellingCommandName, ("ignoreSpelling"));
708     if (commandName == ignoreSpellingCommandName)
709         ++m_pendingLearnOrIgnoreWordMessageCount;
710
711     process()->send(Messages::WebPage::ExecuteEditCommandWithArgument(commandName, argument), m_pageID);
712 }
713
714 void WebPageProxy::replyJavaScriptAlert()
715 {
716     if (!m_alertReply)
717         return;
718
719     m_alertReply->send();
720     m_alertReply = nullptr;
721 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
722     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
723 #endif
724 }
725
726 void WebPageProxy::replyJavaScriptConfirm(bool result)
727 {
728     if (!m_confirmReply)
729         return;
730
731     m_confirmReply->send(result);
732     m_confirmReply = nullptr;
733 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
734     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
735 #endif
736 }
737
738 void WebPageProxy::replyJavaScriptPrompt(const String& result)
739 {
740     if (!m_promptReply)
741         return;
742
743     m_promptReply->send(result);
744     m_promptReply = nullptr;
745 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
746     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
747 #endif
748 }
749
750 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
751 void WebPageProxy::replyBeforeUnloadConfirmPanel(bool result)
752 {
753     if (!m_beforeUnloadConfirmPanelReply)
754         return;
755
756     m_beforeUnloadConfirmPanelReply->send(result);
757     m_beforeUnloadConfirmPanelReply = nullptr;
758 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
759     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
760 #endif
761 }
762 #endif
763
764 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
765 void WebPageProxy::replyPolicyForCertificateError(bool result)
766 {
767     if (!m_allowedReply)
768         return;
769
770     m_allowedReply->send(result);
771     m_allowedReply = nullptr;
772 }
773 #endif
774
775 #if PLUGIN_ARCHITECTURE(X11)
776 void WebPageProxy::createPluginContainer(uint64_t& windowID)
777 {
778     notImplemented();
779 }
780
781 void WebPageProxy::windowedPluginGeometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, uint64_t windowID)
782 {
783     notImplemented();
784 }
785 #endif
786
787 void WebPageProxy::didRenderFrame()
788 {
789     static_cast<PageClientImpl*>(m_pageClient)->didRenderFrame();
790 }
791
792 void WebPageProxy::setBackgroundColor(double red, double green, double blue, double alpha)
793 {
794     static_cast<PageClientImpl*>(m_pageClient)->setBackgroundColor(red, green, blue, alpha);
795 }
796
797 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
798 bool WebPageProxy::makeContextCurrent()
799 {
800     return static_cast<PageClientImpl*>(m_pageClient)->makeContextCurrent();
801 }
802 #endif
803
804 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
805 void WebPageProxy::getTextStyleStateForSelection()
806 {
807     process()->send(Messages::WebPage::GetTextStyleStateForSelection(), m_pageID, 0);
808 }
809
810 void WebPageProxy::didGetTextStyleStateForSelection(int underlineState, int italicState, int boldState)
811 {
812     static_cast<PageClientImpl*>(m_pageClient)->didGetTextStyleStateForSelection(underlineState, italicState, boldState);
813 }
814 #endif
815
816 #if ENABLE(TIZEN_ICON_DATABASE)
817 void WebPageProxy::didReceiveIcon()
818 {
819     static_cast<PageClientImpl*>(m_pageClient)->didReceiveIcon();
820 }
821 #endif
822
823 #if ENABLE(TIZEN_MULTIPLE_SELECT)
824 void WebPageProxy::valueChangedForPopupMenuMultiple(WebPopupMenuProxy*, Vector<int32_t> newSelectedIndex)
825 {
826     process()->send(Messages::WebPage::DidChangeSelectedIndexForActivePopupMenuMultiple(newSelectedIndex), m_pageID);
827 }
828 #endif
829
830 #if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
831 void WebPageProxy::pageDidRequestRestoreVisibleContentRect(const IntPoint& point, float scale)
832 {
833     m_pageClient->pageDidRequestRestoreVisibleContentRect(point, scale);
834 }
835 #endif
836
837 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
838 void WebPageProxy::saveSerializedHTMLDataForMainPage(const String& serializedData, const String& fileName)
839 {
840     static_cast<PageClientImpl*>(m_pageClient)->saveSerializedHTMLDataForMainPage(serializedData, fileName);
841 }
842
843 void WebPageProxy::saveSubresourcesData(Vector<WebSubresourceTizen> subresourceData)
844 {
845     static_cast<PageClientImpl*>(m_pageClient)->saveSubresourcesData(subresourceData);
846 }
847
848 void WebPageProxy::startOfflinePageSave(String subresourceFolderName)
849 {
850     if (!isValid())
851         return;
852
853     process()->send(Messages::WebPage::StartOfflinePageSave(subresourceFolderName), m_pageID);
854 }
855 #endif
856
857 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
858 bool WebPageProxy::selectClosestWord(const IntPoint& point, bool isStartedTextSelectionFromOutside)
859 {
860     if (!isValid())
861         return false;
862
863     bool result = false;
864     process()->sendSync(Messages::WebPage::SelectClosestWord(point, isStartedTextSelectionFromOutside), Messages::WebPage::SelectClosestWord::Reply(result), m_pageID);
865     return result;
866 }
867
868 bool WebPageProxy::setLeftSelection(const IntPoint& point)
869 {
870     if (!isValid())
871         return false;
872
873     bool result = false;
874     process()->sendSync(Messages::WebPage::SetLeftSelection(point), Messages::WebPage::SetLeftSelection::Reply(result), m_pageID);
875     return result;
876 }
877
878 bool WebPageProxy::setRightSelection(const IntPoint& point)
879 {
880     if (!isValid())
881         return false;
882
883     bool result;
884     process()->sendSync(Messages::WebPage::SetRightSelection(point), Messages::WebPage::SetRightSelection::Reply(result), m_pageID);
885     return result;
886 }
887
888 bool WebPageProxy::getSelectionHandlers(IntRect& leftRect, IntRect& rightRect)
889 {
890     if (!isValid())
891         return false;
892
893     bool result = false;
894     process()->sendSync(Messages::WebPage::GetSelectionHandlers(), Messages::WebPage::GetSelectionHandlers::Reply(leftRect, rightRect), m_pageID);
895     if (!leftRect.size().isZero() || !rightRect.size().isZero())
896         result = true;
897
898     return result;
899 }
900
901 String WebPageProxy::getSelectionText()
902 {
903     String ret;
904     if (!isValid())
905         return ret;
906
907     process()->sendSync(Messages::WebPage::GetSelectionText(), Messages::WebPage::GetSelectionText::Reply(ret), m_pageID);
908     return ret;
909 }
910
911 bool WebPageProxy::selectionRangeClear()
912 {
913     if (!isValid())
914         return false;
915
916     bool result = false;
917     process()->sendSync(Messages::WebPage::SelectionRangeClear(), Messages::WebPage::SelectionRangeClear::Reply(result), m_pageID);
918     return result;
919 }
920
921 bool WebPageProxy::scrollContentByCharacter(const IntPoint& point, SelectionDirection direction)
922 {
923     if (!isValid())
924         return false;
925
926     bool result = false;
927     process()->sendSync(Messages::WebPage::ScrollContentByCharacter(point, direction), Messages::WebPage::ScrollContentByCharacter::Reply(result), m_pageID);
928     return result;
929 }
930 #endif
931
932 #if ENABLE(TIZEN_LINK_MAGNIFIER)
933 void WebPageProxy::getLinkMagnifierRect(const WebCore::IntPoint& position, const WebCore::IntSize& size)
934 {
935     process()->send(Messages::WebPage::GetLinkMagnifierRect(position, size), m_pageID);
936 }
937
938 void WebPageProxy::didGetLinkMagnifierRect(const IntPoint& position, const IntRect& rect)
939 {
940     if (!rect.isEmpty())
941         LinkMagnifierProxy::linkMagnifier().show(EwkViewImpl::fromEvasObject(viewWidget()), position, rect);
942     else
943         openLink(position);
944 }
945
946 void WebPageProxy::openLink(const IntPoint& position)
947 {
948 #if ENABLE(GESTURE_EVENTS)
949     IntPoint globalPosition(EwkViewImpl::fromEvasObject(viewWidget())->transformToScreen().mapPoint(position));
950     WebGestureEvent gesture(WebEvent::GestureSingleTap, position, globalPosition, WebEvent::Modifiers(0), ecore_time_get());
951     handleGestureEvent(gesture);
952 #endif
953 }
954 #endif
955
956 #if ENABLE(TIZEN_SCREEN_READER)
957 void WebPageProxy::raiseTapEvent(const IntPoint& position)
958 {
959 #if ENABLE(GESTURE_EVENTS)
960     IntPoint globalPosition = EwkViewImpl::fromEvasObject(viewWidget())->transformToScreen().mapPoint(position);
961     process()->send(Messages::WebPage::RaiseTapEvent(position, globalPosition), m_pageID);
962 #else
963     UNUSED_PARAM(position);
964 #endif
965 }
966
967 bool WebPageProxy::moveScreenReaderFocus(bool forward)
968 {
969     bool result;
970     process()->sendSync(Messages::WebPage::MoveScreenReaderFocus(forward), Messages::WebPage::MoveScreenReaderFocus::Reply(result), m_pageID);
971     return result;
972 }
973
974 void WebPageProxy::moveScreenReaderFocusByPoint(const IntPoint& point)
975 {
976     process()->send(Messages::WebPage::MoveScreenReaderFocusByPoint(point), m_pageID);
977 }
978
979 void WebPageProxy::recalcScreenReaderFocusRect()
980 {
981     if (!ScreenReaderProxy::screenReader().isEnabled())
982         return;
983
984     process()->send(Messages::WebPage::RecalcScreenReaderFocusRect(), m_pageID);
985 }
986
987 void WebPageProxy::clearScreenReader()
988 {
989     process()->send(Messages::WebPage::ClearScreenReader(), m_pageID);
990 }
991
992 void WebPageProxy::didScreenReaderFocusRectChanged(const IntRect& rect)
993 {
994 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
995     FocusRing* focusRing = ewkViewGetFocusRing(viewWidget());
996     if (!focusRing)
997         return;
998
999     if (!rect.isEmpty())
1000         focusRing->show(rect);
1001     else
1002         focusRing->hide(false);
1003 #else
1004     UNUSED_PARAM(rect);
1005 #endif
1006 }
1007
1008 void WebPageProxy::didScreenReaderTextChanged(const String& text)
1009 {
1010     ScreenReaderProxy::screenReader().setText(text);
1011 }
1012 #endif
1013
1014 #if ENABLE(TIZEN_CSP)
1015 void WebPageProxy::setContentSecurityPolicy(const String& policy, WebCore::ContentSecurityPolicy::HeaderType type)
1016 {
1017     process()->send(Messages::WebPage::SetContentSecurityPolicy(policy, type), m_pageID);
1018 }
1019 #endif
1020
1021 #if ENABLE(TIZEN_APPLICATION_CACHE)
1022 void WebPageProxy::requestApplicationCachePermission(uint64_t frameID, const String& originIdentifier, PassRefPtr<Messages::WebPageProxy::RequestApplicationCachePermission::DelayedReply> allow)
1023 {
1024     WebFrameProxy* frame = process()->webFrame(frameID);
1025     MESSAGE_CHECK(frame);
1026
1027     // Since requestApplicationCachePermission() can spin a nested run loop we need to turn off the responsiveness timer.
1028     process()->responsivenessTimer()->stop();
1029
1030     m_applicationCacheReply = allow;
1031 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1032     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(true);
1033 #endif
1034     RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier);
1035
1036     if (!m_tizenClient.decidePolicyForApplicationCachePermissionRequest(this, origin.get(), frame))
1037         replyApplicationCachePermission(true);
1038 }
1039
1040 void WebPageProxy::replyApplicationCachePermission(bool allow)
1041 {
1042     if (!m_applicationCacheReply)
1043         return;
1044
1045     m_applicationCacheReply->send(allow);
1046     m_applicationCacheReply = nullptr;
1047 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1048     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
1049 #endif
1050 }
1051 #endif
1052
1053 #if ENABLE(TIZEN_INDEXED_DATABASE)
1054 void WebPageProxy::exceededIndexedDatabaseQuota(uint64_t frameID, const String& originIdentifier, int64_t currentUsage, PassRefPtr<Messages::WebPageProxy::ExceededIndexedDatabaseQuota::DelayedReply> reply)
1055 {
1056     WebFrameProxy* frame = process()->webFrame(frameID);
1057     MESSAGE_CHECK(frame);
1058
1059     // Since exceededIndexedDatabaseQuota() can spin a nested run loop we need to turn off the responsiveness timer.
1060     process()->responsivenessTimer()->stop();
1061
1062     m_exceededIndexedDatabaseQuotaReply = reply;
1063 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1064     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(true);
1065 #endif
1066
1067     RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier);
1068
1069     if (!m_tizenClient.exceededIndexedDatabaseQuota(this, origin.get(), currentUsage, frame))
1070         replyExceededIndexedDatabaseQuota(false);
1071 }
1072
1073 void WebPageProxy::replyExceededIndexedDatabaseQuota(bool allow)
1074 {
1075     if (!m_exceededIndexedDatabaseQuotaReply)
1076         return;
1077
1078     m_exceededIndexedDatabaseQuotaReply->send(allow);
1079     m_exceededIndexedDatabaseQuotaReply = nullptr;
1080 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1081     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
1082 #endif
1083 }
1084 #endif
1085
1086 #endif // #if OS(TIZEN)
1087
1088 void WebPageProxy::handleInputMethodKeydown(bool& handled)
1089 {
1090 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1091     handled = m_keyEventQueue.first().forwardedEvent.isFiltered();
1092 #else
1093     handled = m_keyEventQueue.first().isFiltered();
1094 #endif
1095 }
1096
1097 void WebPageProxy::confirmComposition(const String& compositionString)
1098 {
1099     if (!isValid())
1100         return;
1101
1102 #if ENABLE(TIZEN_ISF_PORT)
1103     if (m_didCancelCompositionFromWebProcess)
1104         return;
1105 #endif
1106
1107     process()->send(Messages::WebPage::ConfirmComposition(compositionString), m_pageID, 0);
1108 }
1109
1110 void WebPageProxy::setComposition(const String& compositionString, Vector<WebCore::CompositionUnderline>& underlines, int cursorPosition)
1111 {
1112     if (!isValid())
1113         return;
1114
1115 #if ENABLE(TIZEN_REDUCE_KEY_LAGGING)
1116     // Suspend layout&paint at the key input, and resume layout&paint after 150 ms.
1117     suspendActiveDOMObjectsAndAnimations();
1118     if (m_pageContentResumeTimer)
1119         ecore_timer_del(m_pageContentResumeTimer);
1120     m_pageContentResumeTimer = ecore_timer_add(150.0/1000.0, pageContentResumeTimerFired, this);
1121 #endif
1122
1123     process()->send(Messages::WebPage::SetComposition(compositionString, underlines, cursorPosition), m_pageID, 0);
1124 }
1125
1126 void WebPageProxy::cancelComposition()
1127 {
1128     if (!isValid())
1129         return;
1130
1131     process()->send(Messages::WebPage::CancelComposition(), m_pageID, 0);
1132 }
1133
1134 } // namespace WebKit