Merge "Add copySurfaceTye argument to copySurface function." into tizen_2.1
[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, const String& type, const String& value)
242 {
243     static_cast<PageClientImpl*>(m_pageClient)->setInputMethodState(active, type, value);
244 }
245 #else
246 void WebPageProxy::setInputMethodState(bool active)
247 {
248     //FIXME : it should be contributable
249     static_cast<PageClientImpl*>(m_pageClient)->setInputMethodState(active);
250 }
251 #endif
252
253 #if ENABLE(TIZEN_ISF_PORT)
254 int WebPageProxy::getCursorOffset()
255 {
256     if (!isValid())
257         return 0;
258
259     int offset = 0;
260     process()->sendSync(Messages::WebPage::GetCursorOffset(), Messages::WebPage::GetCursorOffset::Reply(offset), m_pageID);
261     return offset;
262 }
263
264 void WebPageProxy::getSurroundingTextAndCursorOffset(String& text, int& offset)
265 {
266     if (!isValid())
267         return;
268
269     process()->sendSync(Messages::WebPage::GetSurroundingTextAndCursorOffset(), Messages::WebPage::GetSurroundingTextAndCursorOffset::Reply(text, offset), m_pageID);
270 }
271
272 IntRect WebPageProxy::getSelectionRect(bool isOnlyEditable)
273 {
274     IntRect rect;
275     process()->sendSync(Messages::WebPage::GetSelectionRect(isOnlyEditable), Messages::WebPage::GetSelectionRect::Reply(rect), m_pageID);
276     return rect;
277 }
278
279 void WebPageProxy::deleteSurroundingText(int offset, int count)
280 {
281     if (!isValid())
282         return;
283
284     process()->send(Messages::WebPage::DeleteSurroundingText(offset, count), m_pageID);
285 }
286
287 void WebPageProxy::updateCursorOffset(int offset)
288 {
289     static_cast<PageClientImpl*>(m_pageClient)->updateCursorOffset(offset);
290 }
291
292 void WebPageProxy::didCancelComposition()
293 {
294     m_didCancelCompositionFromWebProcess = true;
295     InputMethodContextEfl* inputMethodContext = static_cast<PageClientImpl*>(m_pageClient)->viewImpl()->inputMethodContext();
296     if (inputMethodContext)
297         inputMethodContext->resetIMFContext();
298     m_didCancelCompositionFromWebProcess = false;
299 }
300 #endif
301
302 void WebPageProxy::requestUpdateFormNavigation()
303 {
304     if (!isValid())
305         return;
306
307     process()->send(Messages::WebPage::RequestUpdateFormNavigation(), m_pageID);
308 }
309
310 void WebPageProxy::moveFocus(int newIndex)
311 {
312     if (!isValid())
313         return;
314
315     process()->send(Messages::WebPage::MoveFocus(newIndex), m_pageID);
316 }
317
318 void WebPageProxy::updateFormNavigation(int length, int offset)
319 {
320     static_cast<PageClientImpl*>(m_pageClient)->updateFormNavigation(length, offset);
321 }
322
323 #if ENABLE(TIZEN_REDUCE_KEY_LAGGING)
324 Eina_Bool WebPageProxy::pageContentResumeTimerFired(void* data)
325 {
326     static_cast<WebPageProxy*>(data)->resumeActiveDOMObjectsAndAnimations();
327     static_cast<WebPageProxy*>(data)->m_pageContentResumeTimer = 0;
328     return ECORE_CALLBACK_CANCEL;
329 }
330 #endif
331
332 #if ENABLE(TIZEN_TEXT_CARET_HANDLING_WK2)
333 void WebPageProxy::setCaretPosition(const WebCore::IntPoint& pos)
334 {
335     if (!isValid())
336         return;
337
338     process()->send(Messages::WebPage::SetCaretPosition(pos), m_pageID);
339 }
340
341 void WebPageProxy::getCaretPosition(WebCore::IntRect& rect)
342 {
343     if (!isValid())
344         return;
345
346     process()->sendSync(Messages::WebPage::GetCaretPosition(), Messages::WebPage::GetCaretPosition::Reply(rect), m_pageID);
347 }
348 #endif
349
350 #if ENABLE(TIZEN_PLUGIN_CUSTOM_REQUEST)
351 void WebPageProxy::processPluginCustomRequest(const String& request, const String& msg)
352 {
353     if (String("requestKeyboard,plugin") == request) {
354         bool active = false;
355         if (String("show") == msg)
356             active = true;
357 #if ENABLE(TIZEN_ISF_PORT)
358         setInputMethodState(active, "plugin", String());
359 #else
360         setInputMethodState(active);
361 #endif
362     }
363 #if ENABLE(TIZEN_JSBRIDGE_PLUGIN)
364     else if (String("requestToNative,json") == request)
365         m_tizenClient.processJSBridgePlugin(this, request, msg);
366 #endif
367 }
368 #endif
369
370
371 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION) || ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
372 void WebPageProxy::setFocusedInputElementValue(const String& inputValue)
373 {
374     if (!isValid())
375         return;
376
377     process()->send(Messages::WebPage::SetFocusedInputElementValue(inputValue), m_pageID);
378 }
379
380 String WebPageProxy::getFocusedInputElementValue()
381 {
382     if (!isValid())
383         return String();
384
385     String inputValue;
386     process()->sendSync(Messages::WebPage::GetFocusedInputElementValue(), Messages::WebPage::GetFocusedInputElementValue::Reply(inputValue), m_pageID);
387     return inputValue;
388 }
389 #endif
390
391 #if ENABLE(TIZEN_DATALIST_ELEMENT)
392 Vector<String> WebPageProxy::getFocusedInputElementDataList()
393 {
394     if (!isValid())
395         return Vector<String>();
396
397     Vector<String> optionList;
398     process()->sendSync(Messages::WebPage::GetFocusedInputElementDataList(), Messages::WebPage::GetFocusedInputElementDataList::Reply(optionList), m_pageID);
399     return optionList;
400 }
401 #endif
402
403 void WebPageProxy::focusedNodeChanged(const IntRect& focusedNodeRect)
404 {
405     static_cast<PageClientImpl*>(m_pageClient)->setFocusedNodeRect(focusedNodeRect);
406 }
407
408 void WebPageProxy::initializeTizenClient(const WKPageTizenClient* client)
409 {
410     m_tizenClient.initialize(client);
411 }
412
413 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
414 WebHitTestResult::Data WebPageProxy::hitTestResultAtPoint(const IntPoint& point, int hitTestMode)
415 {
416     WebHitTestResult::Data hitTestResultData;
417     if (!isValid())
418         return hitTestResultData;
419
420     process()->sendSync(Messages::WebPage::HitTestResultAtPoint(point, hitTestMode),
421                         Messages::WebPage::HitTestResultAtPoint::Reply(hitTestResultData), m_pageID);
422
423     return hitTestResultData;
424 }
425 #endif
426
427 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
428 void WebPageProxy::recordingSurfaceSetEnableSet(bool enable)
429 {
430     if (!isValid())
431         return;
432
433     process()->send(Messages::WebPage::RecordingSurfaceSetEnableSet(enable), m_pageID, 0);
434 }
435 #endif
436
437 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
438 void WebPageProxy::hideContextMenu()
439 {
440     if (m_activeContextMenu)
441         m_activeContextMenu->hideContextMenu();
442 }
443
444 String WebPageProxy::contextMenuAbsoluteLinkURLString()
445 {
446     if (!m_activeContextMenu)
447         return String();
448
449     return m_activeContextMenuHitTestResultData.absoluteLinkURL;
450 }
451
452 String WebPageProxy::contextMenuAbsoluteImageURLString()
453 {
454     if (!m_activeContextMenu)
455         return String();
456
457     return m_activeContextMenuHitTestResultData.absoluteImageURL;
458 }
459 #endif
460
461 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
462 void WebPageProxy::pasteContextMenuSelected()
463 {
464     static_cast<PageClientImpl*>(m_pageClient)->pasteContextMenuSelected();
465 }
466
467 void WebPageProxy::didSelectPasteMenuFromContextMenu(const String& data, const String& type)
468 {
469     if (!isValid())
470         return;
471
472 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
473     process()->send(Messages::WebPage::SetClipboardDataForPaste(data, type), m_pageID);
474 #endif
475     WebContextMenuItemData item(ActionType, ContextMenuItemTagPaste, String("Paste"), true, false);
476     process()->send(Messages::WebPage::DidSelectItemFromActiveContextMenu(item), m_pageID);
477 }
478 #endif
479
480 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
481 void WebPageProxy::setClipboardData(const String& data, const String& type)
482 {
483     static_cast<PageClientImpl*>(m_pageClient)->setClipboardData(data, type);
484 }
485
486 void WebPageProxy::clearClipboardData()
487 {
488     static_cast<PageClientImpl*>(m_pageClient)->clearClipboardData();
489 }
490 #endif
491
492 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
493 void WebPageProxy::executePasteFromClipboardItem(const String& data, const String& type)
494 {
495     if (!isValid())
496         return;
497
498 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
499     process()->send(Messages::WebPage::SetClipboardDataForPaste(data, type), m_pageID);
500 #endif
501     process()->send(Messages::WebPage::ExecuteEditCommandWithArgument("Paste", data), m_pageID);
502 }
503
504 void WebPageProxy::clipboardContextMenuSelected()
505 {
506     static_cast<PageClientImpl*>(m_pageClient)->clipboardContextMenuSelected();
507 }
508 #endif
509
510 #if ENABLE(TIZEN_WEBKIT2_REMOTE_WEB_INSPECTOR)
511 uint32_t WebPageProxy::startInspectorServer(uint32_t port)
512 {
513     if (!isValid())
514         return 0;
515
516     uint32_t assignedPort = 0;
517     process()->sendSync(Messages::WebPage::StartInspectorServer(port), Messages::WebPage::StartInspectorServer::Reply(assignedPort), m_pageID);
518     return assignedPort;
519 }
520
521 bool WebPageProxy::stopInspectorServer()
522 {
523     if (!isValid())
524         return false;
525
526     bool result = false;
527     process()->sendSync(Messages::WebPage::StopInspectorServer(), Messages::WebPage::StopInspectorServer::Reply(result), m_pageID);
528     return result;
529 }
530 #endif
531
532 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
533 void WebPageProxy::createPagesToPDF(const IntSize& surfaceSize, const IntSize& contentsSize, const String& fileName)
534 {
535     process()->send(Messages::WebPage::CreatePagesToPDF(surfaceSize, contentsSize, fileName), m_pageID);
536 }
537 #endif
538
539 #if ENABLE(TIZEN_WEB_STORAGE)
540 #if ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
541 void WebPageProxy::getWebStorageQuotaBytes(PassRefPtr<WebStorageQuotaCallback> prpCallback)
542 {
543     RefPtr<WebStorageQuotaCallback> callback = prpCallback;
544     if (!isValid()) {
545         callback->invalidate();
546         return;
547     }
548
549     uint64_t callbackID = callback->callbackID();
550     m_quotaCallbacks.set(callbackID, callback.get());
551     process()->send(Messages::WebPage::GetStorageQuotaBytes(callbackID), m_pageID);
552 }
553
554 void WebPageProxy::didGetWebStorageQuotaBytes(const uint32_t quota, uint64_t callbackID)
555 {
556     RefPtr<WebStorageQuotaCallback> callback = m_quotaCallbacks.take(callbackID);
557     if (!callback) {
558         // FIXME: Log error or assert.
559         // this can validly happen if a load invalidated the callback, though
560         return;
561     }
562
563     m_quotaCallbacks.remove(callbackID);
564
565     RefPtr<WebUInt32> uint32Object = WebUInt32::create(quota);
566     callback->performCallbackWithReturnValue(uint32Object.release().leakRef());
567 }
568 #endif
569
570 void WebPageProxy::setWebStorageQuotaBytes(uint32_t quota)
571 {
572     if (!isValid())
573         return;
574
575     process()->send(Messages::WebPage::SetStorageQuotaBytes(quota), m_pageID, 0);
576 }
577 #endif
578
579 void WebPageProxy::scale(double scaleFactor, const IntPoint& origin)
580 {
581 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
582     static_cast<PageClientImpl*>(m_pageClient)->scaleContents(scaleFactor, origin);
583 #else
584     scalePage(scaleFactor, origin);
585 #endif
586 }
587
588 void WebPageProxy::scaleImage(double scaleFactor, const IntPoint& origin)
589 {
590 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
591     static_cast<PageClientImpl*>(m_pageClient)->scaleImage(scaleFactor, origin);
592 #else
593     scalePage(scaleFactor, origin);
594 #endif
595 }
596
597 double WebPageProxy::scaleFactor()
598 {
599 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
600     return static_cast<PageClientImpl*>(m_pageClient)->scaleFactor();
601 #else
602     return pageScaleFactor();
603 #endif
604 }
605
606 #if ENABLE(TIZEN_ORIENTATION_EVENTS)
607 void WebPageProxy::sendOrientationChangeEvent(int orientation)
608 {
609     process()->send(Messages::WebPage::SendOrientationChangeEvent(orientation), m_pageID, 0);
610 }
611 #endif
612
613 void WebPageProxy::suspendPainting()
614 {
615     if (!isValid())
616         return;
617
618     process()->send(Messages::DrawingArea::SuspendPainting(), m_pageID);
619 }
620
621 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
622 void WebPageProxy::suspendPaintingOfInactiveView()
623 {
624     if (!isValid() || isViewVisible())
625         return;
626
627     process()->send(Messages::DrawingArea::SuspendPainting(), m_pageID);
628 }
629 #endif
630
631 void WebPageProxy::resumePainting()
632 {
633     if (!isValid())
634         return;
635
636     process()->send(Messages::DrawingArea::ResumePainting(), m_pageID);
637 }
638
639 void WebPageProxy::suspendJavaScriptAndResource()
640 {
641     if (!isValid())
642         return;
643
644     process()->send(Messages::WebPage::SuspendJavaScriptAndResources(), m_pageID);
645 }
646
647 void WebPageProxy::resumeJavaScriptAndResource()
648 {
649     if (!isValid())
650         return;
651
652     process()->send(Messages::WebPage::ResumeJavaScriptAndResources(), m_pageID);
653 }
654
655 #if ENABLE(TIZEN_PLUGIN_SUSPEND_RESUME)
656 void WebPageProxy::suspendPlugin()
657 {
658     if (!isValid())
659         return;
660
661     process()->send(Messages::WebPage::SuspendPlugin(), m_pageID);
662 }
663
664 void WebPageProxy::resumePlugin()
665 {
666     if (!isValid())
667         return;
668
669     process()->send(Messages::WebPage::ResumePlugin(), m_pageID);
670 }
671 #endif
672
673 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
674 bool WebPageProxy::scrollOverflow(const FloatPoint& offset)
675 {
676     if (!isValid())
677         return false;
678
679 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
680     if (static_cast<PageClientImpl*>(m_pageClient)->isScrollableLayerFocused())
681         return drawingArea()->layerTreeCoordinatorProxy()->setOffsetForFocusedScrollingContentsLayer(offset);
682 #endif
683     if (static_cast<PageClientImpl*>(m_pageClient)->isScrollableNodeFocused()) {
684         bool scrolled = false;
685         process()->sendSync(Messages::WebPage::ScrollOverflow(offset), Messages::WebPage::ScrollOverflow::Reply(scrolled), m_pageID);
686         return scrolled;
687     }
688
689     return false;
690 }
691
692 bool WebPageProxy::setPressedNodeAtPoint(const IntPoint& point, bool checkOverflowLayer, WebLayerID& webLayerID)
693 {
694     if (!isValid())
695         return false;
696
697     bool pressed = false;
698     process()->sendSync(Messages::WebPage::SetPressedNodeAtPoint(point, checkOverflowLayer), Messages::WebPage::SetPressedNodeAtPoint::Reply(pressed, webLayerID), m_pageID);
699
700     return pressed;
701 }
702
703 void WebPageProxy::setOverflowResult(bool pressed, uint32_t webLayerID)
704 {
705     static_cast<PageClientImpl*>(m_pageClient)->setOverflowResult(pressed, webLayerID);
706 }
707 #endif
708
709 void WebPageProxy::executeEditCommandWithArgument(const String& commandName, const String& argument)
710 {
711     if (!isValid())
712         return;
713
714     DEFINE_STATIC_LOCAL(String, ignoreSpellingCommandName, ("ignoreSpelling"));
715     if (commandName == ignoreSpellingCommandName)
716         ++m_pendingLearnOrIgnoreWordMessageCount;
717
718     process()->send(Messages::WebPage::ExecuteEditCommandWithArgument(commandName, argument), m_pageID);
719 }
720
721 void WebPageProxy::replyJavaScriptAlert()
722 {
723     if (!m_alertReply)
724         return;
725
726     m_alertReply->send();
727     m_alertReply = nullptr;
728 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
729     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
730 #endif
731 }
732
733 void WebPageProxy::replyJavaScriptConfirm(bool result)
734 {
735     if (!m_confirmReply)
736         return;
737
738     m_confirmReply->send(result);
739     m_confirmReply = nullptr;
740 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
741     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
742 #endif
743 }
744
745 void WebPageProxy::replyJavaScriptPrompt(const String& result)
746 {
747     if (!m_promptReply)
748         return;
749
750     m_promptReply->send(result);
751     m_promptReply = nullptr;
752 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
753     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
754 #endif
755 }
756
757 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
758 void WebPageProxy::replyBeforeUnloadConfirmPanel(bool result)
759 {
760     if (!m_beforeUnloadConfirmPanelReply)
761         return;
762
763     m_beforeUnloadConfirmPanelReply->send(result);
764     m_beforeUnloadConfirmPanelReply = nullptr;
765 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
766     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
767 #endif
768 }
769 #endif
770
771 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
772 void WebPageProxy::replyPolicyForCertificateError(bool result)
773 {
774     if (!m_allowedReply)
775         return;
776
777     m_allowedReply->send(result);
778     m_allowedReply = nullptr;
779 }
780 #endif
781
782 #if PLUGIN_ARCHITECTURE(X11)
783 void WebPageProxy::createPluginContainer(uint64_t& windowID)
784 {
785     notImplemented();
786 }
787
788 void WebPageProxy::windowedPluginGeometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, uint64_t windowID)
789 {
790     notImplemented();
791 }
792 #endif
793
794 void WebPageProxy::didRenderFrame()
795 {
796     static_cast<PageClientImpl*>(m_pageClient)->didRenderFrame();
797 }
798
799 void WebPageProxy::setBackgroundColor(double red, double green, double blue, double alpha)
800 {
801     static_cast<PageClientImpl*>(m_pageClient)->setBackgroundColor(red, green, blue, alpha);
802 }
803
804 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
805 bool WebPageProxy::makeContextCurrent()
806 {
807     return static_cast<PageClientImpl*>(m_pageClient)->makeContextCurrent();
808 }
809 #endif
810
811 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
812 void WebPageProxy::getTextStyleStateForSelection()
813 {
814     process()->send(Messages::WebPage::GetTextStyleStateForSelection(), m_pageID, 0);
815 }
816
817 void WebPageProxy::didGetTextStyleStateForSelection(int underlineState, int italicState, int boldState)
818 {
819     static_cast<PageClientImpl*>(m_pageClient)->didGetTextStyleStateForSelection(underlineState, italicState, boldState);
820 }
821 #endif
822
823 #if ENABLE(TIZEN_ICON_DATABASE)
824 void WebPageProxy::didReceiveIcon()
825 {
826     static_cast<PageClientImpl*>(m_pageClient)->didReceiveIcon();
827 }
828 #endif
829
830 #if ENABLE(TIZEN_MULTIPLE_SELECT)
831 void WebPageProxy::valueChangedForPopupMenuMultiple(WebPopupMenuProxy*, Vector<int32_t> newSelectedIndex)
832 {
833     process()->send(Messages::WebPage::DidChangeSelectedIndexForActivePopupMenuMultiple(newSelectedIndex), m_pageID);
834 }
835 #endif
836
837 #if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
838 void WebPageProxy::pageDidRequestRestoreVisibleContentRect(const IntPoint& point, float scale)
839 {
840     m_pageClient->pageDidRequestRestoreVisibleContentRect(point, scale);
841 }
842 #endif
843
844 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
845 void WebPageProxy::saveSerializedHTMLDataForMainPage(const String& serializedData, const String& fileName)
846 {
847     static_cast<PageClientImpl*>(m_pageClient)->saveSerializedHTMLDataForMainPage(serializedData, fileName);
848 }
849
850 void WebPageProxy::saveSubresourcesData(Vector<WebSubresourceTizen> subresourceData)
851 {
852     static_cast<PageClientImpl*>(m_pageClient)->saveSubresourcesData(subresourceData);
853 }
854
855 void WebPageProxy::startOfflinePageSave(String subresourceFolderName)
856 {
857     if (!isValid())
858         return;
859
860     process()->send(Messages::WebPage::StartOfflinePageSave(subresourceFolderName), m_pageID);
861 }
862 #endif
863
864 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
865 bool WebPageProxy::selectClosestWord(const IntPoint& point, bool isStartedTextSelectionFromOutside)
866 {
867     if (!isValid())
868         return false;
869
870     bool result = false;
871     process()->sendSync(Messages::WebPage::SelectClosestWord(point, isStartedTextSelectionFromOutside), Messages::WebPage::SelectClosestWord::Reply(result), m_pageID);
872     return result;
873 }
874
875 bool WebPageProxy::setLeftSelection(const IntPoint& point)
876 {
877     if (!isValid())
878         return false;
879
880     bool result = false;
881     process()->sendSync(Messages::WebPage::SetLeftSelection(point), Messages::WebPage::SetLeftSelection::Reply(result), m_pageID);
882     return result;
883 }
884
885 bool WebPageProxy::setRightSelection(const IntPoint& point)
886 {
887     if (!isValid())
888         return false;
889
890     bool result;
891     process()->sendSync(Messages::WebPage::SetRightSelection(point), Messages::WebPage::SetRightSelection::Reply(result), m_pageID);
892     return result;
893 }
894
895 bool WebPageProxy::getSelectionHandlers(IntRect& leftRect, IntRect& rightRect)
896 {
897     if (!isValid())
898         return false;
899
900     bool result = false;
901     process()->sendSync(Messages::WebPage::GetSelectionHandlers(), Messages::WebPage::GetSelectionHandlers::Reply(leftRect, rightRect), m_pageID);
902     if (!leftRect.size().isZero() || !rightRect.size().isZero())
903         result = true;
904
905     return result;
906 }
907
908 String WebPageProxy::getSelectionText()
909 {
910     String ret;
911     if (!isValid())
912         return ret;
913
914     process()->sendSync(Messages::WebPage::GetSelectionText(), Messages::WebPage::GetSelectionText::Reply(ret), m_pageID);
915     return ret;
916 }
917
918 bool WebPageProxy::selectionRangeClear()
919 {
920     if (!isValid())
921         return false;
922
923     bool result = false;
924     process()->sendSync(Messages::WebPage::SelectionRangeClear(), Messages::WebPage::SelectionRangeClear::Reply(result), m_pageID);
925     return result;
926 }
927 #endif
928
929 #if ENABLE(TIZEN_LINK_MAGNIFIER)
930 void WebPageProxy::getLinkMagnifierRect(const WebCore::IntPoint& position, const WebCore::IntSize& size)
931 {
932     process()->send(Messages::WebPage::GetLinkMagnifierRect(position, size), m_pageID);
933 }
934
935 void WebPageProxy::didGetLinkMagnifierRect(const IntPoint& position, const IntRect& rect)
936 {
937     if (!rect.isEmpty())
938         LinkMagnifierProxy::linkMagnifier().show(EwkViewImpl::fromEvasObject(viewWidget()), position, rect);
939     else
940         openLink(position);
941 }
942
943 void WebPageProxy::openLink(const IntPoint& position)
944 {
945 #if ENABLE(GESTURE_EVENTS)
946     IntPoint globalPosition(EwkViewImpl::fromEvasObject(viewWidget())->transformToScreen().mapPoint(position));
947     WebGestureEvent gesture(WebEvent::GestureSingleTap, position, globalPosition, WebEvent::Modifiers(0), ecore_time_get());
948     handleGestureEvent(gesture);
949 #endif
950 }
951 #endif
952
953 #if ENABLE(TIZEN_SCREEN_READER)
954 void WebPageProxy::raiseTapEvent(const IntPoint& position)
955 {
956 #if ENABLE(GESTURE_EVENTS)
957     IntPoint globalPosition = EwkViewImpl::fromEvasObject(viewWidget())->transformToScreen().mapPoint(position);
958     process()->send(Messages::WebPage::RaiseTapEvent(position, globalPosition), m_pageID);
959 #else
960     UNUSED_PARAM(position);
961 #endif
962 }
963
964 bool WebPageProxy::moveScreenReaderFocus(bool forward)
965 {
966     bool result;
967     process()->sendSync(Messages::WebPage::MoveScreenReaderFocus(forward), Messages::WebPage::MoveScreenReaderFocus::Reply(result), m_pageID);
968     return result;
969 }
970
971 void WebPageProxy::moveScreenReaderFocusByPoint(const IntPoint& point)
972 {
973     process()->send(Messages::WebPage::MoveScreenReaderFocusByPoint(point), m_pageID);
974 }
975
976 void WebPageProxy::recalcScreenReaderFocusRect()
977 {
978     if (!ScreenReaderProxy::screenReader().isEnabled())
979         return;
980
981     process()->send(Messages::WebPage::RecalcScreenReaderFocusRect(), m_pageID);
982 }
983
984 void WebPageProxy::clearScreenReader()
985 {
986     process()->send(Messages::WebPage::ClearScreenReader(), m_pageID);
987 }
988
989 void WebPageProxy::didScreenReaderFocusRectChanged(const IntRect& rect)
990 {
991 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
992     FocusRing* focusRing = ewkViewGetFocusRing(viewWidget());
993     if (!focusRing)
994         return;
995
996     if (!rect.isEmpty())
997         focusRing->show(rect);
998     else
999         focusRing->hide(false);
1000 #else
1001     UNUSED_PARAM(rect);
1002 #endif
1003 }
1004
1005 void WebPageProxy::didScreenReaderTextChanged(const String& text)
1006 {
1007     ScreenReaderProxy::screenReader().setText(text);
1008 }
1009 #endif
1010
1011 #if ENABLE(TIZEN_CSP)
1012 void WebPageProxy::setContentSecurityPolicy(const String& policy, WebCore::ContentSecurityPolicy::HeaderType type)
1013 {
1014     process()->send(Messages::WebPage::SetContentSecurityPolicy(policy, type), m_pageID);
1015 }
1016 #endif
1017
1018 #if ENABLE(TIZEN_APPLICATION_CACHE)
1019 void WebPageProxy::requestApplicationCachePermission(uint64_t frameID, const String& originIdentifier, PassRefPtr<Messages::WebPageProxy::RequestApplicationCachePermission::DelayedReply> allow)
1020 {
1021     WebFrameProxy* frame = process()->webFrame(frameID);
1022     MESSAGE_CHECK(frame);
1023
1024     // Since requestApplicationCachePermission() can spin a nested run loop we need to turn off the responsiveness timer.
1025     process()->responsivenessTimer()->stop();
1026
1027     m_applicationCacheReply = allow;
1028 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1029     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(true);
1030 #endif
1031     RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier);
1032
1033     if (!m_tizenClient.decidePolicyForApplicationCachePermissionRequest(this, origin.get(), frame))
1034         replyApplicationCachePermission(false);
1035 }
1036
1037 void WebPageProxy::replyApplicationCachePermission(bool allow)
1038 {
1039     if (!m_applicationCacheReply)
1040         return;
1041
1042     m_applicationCacheReply->send(allow);
1043     m_applicationCacheReply = nullptr;
1044 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1045     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
1046 #endif
1047 }
1048 #endif
1049
1050 #if ENABLE(TIZEN_INDEXED_DATABASE)
1051 void WebPageProxy::exceededIndexedDatabaseQuota(uint64_t frameID, const String& originIdentifier, int64_t currentUsage, PassRefPtr<Messages::WebPageProxy::ExceededIndexedDatabaseQuota::DelayedReply> reply)
1052 {
1053     WebFrameProxy* frame = process()->webFrame(frameID);
1054     MESSAGE_CHECK(frame);
1055
1056     // Since exceededIndexedDatabaseQuota() can spin a nested run loop we need to turn off the responsiveness timer.
1057     process()->responsivenessTimer()->stop();
1058
1059     m_exceededIndexedDatabaseQuotaReply = reply;
1060 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1061     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(true);
1062 #endif
1063
1064     RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier);
1065
1066     if (!m_tizenClient.exceededIndexedDatabaseQuota(this, origin.get(), currentUsage, frame))
1067         replyExceededIndexedDatabaseQuota(false);
1068 }
1069
1070 void WebPageProxy::replyExceededIndexedDatabaseQuota(bool allow)
1071 {
1072     if (!m_exceededIndexedDatabaseQuotaReply)
1073         return;
1074
1075     m_exceededIndexedDatabaseQuotaReply->send(allow);
1076     m_exceededIndexedDatabaseQuotaReply = nullptr;
1077 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1078     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
1079 #endif
1080 }
1081 #endif
1082
1083 #endif // #if OS(TIZEN)
1084
1085 void WebPageProxy::handleInputMethodKeydown(bool& handled)
1086 {
1087 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1088     handled = m_keyEventQueue.first().forwardedEvent.isFiltered();
1089 #else
1090     handled = m_keyEventQueue.first().isFiltered();
1091 #endif
1092 }
1093
1094 void WebPageProxy::confirmComposition(const String& compositionString)
1095 {
1096     if (!isValid())
1097         return;
1098
1099 #if ENABLE(TIZEN_ISF_PORT)
1100     if (m_didCancelCompositionFromWebProcess)
1101         return;
1102 #endif
1103
1104     process()->send(Messages::WebPage::ConfirmComposition(compositionString), m_pageID, 0);
1105 }
1106
1107 void WebPageProxy::setComposition(const String& compositionString, Vector<WebCore::CompositionUnderline>& underlines, int cursorPosition)
1108 {
1109     if (!isValid())
1110         return;
1111
1112 #if ENABLE(TIZEN_REDUCE_KEY_LAGGING)
1113     // Suspend layout&paint at the key input, and resume layout&paint after 150 ms.
1114     suspendActiveDOMObjectsAndAnimations();
1115     if (m_pageContentResumeTimer)
1116         ecore_timer_del(m_pageContentResumeTimer);
1117     m_pageContentResumeTimer = ecore_timer_add(150.0/1000.0, pageContentResumeTimerFired, this);
1118 #endif
1119
1120     process()->send(Messages::WebPage::SetComposition(compositionString, underlines, cursorPosition), m_pageID, 0);
1121 }
1122
1123 void WebPageProxy::cancelComposition()
1124 {
1125     if (!isValid())
1126         return;
1127
1128     process()->send(Messages::WebPage::CancelComposition(), m_pageID, 0);
1129 }
1130
1131 } // namespace WebKit