Add keypad layout that has number variation
[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; Tizen 2.1; sdk) AppleWebKit/537.3 (KHTML, like Gecko) Version/2.1 Mobile Safari/537.3");
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 (!inputMethodContext)
245         return;
246
247     inputMethodContext->setUseInputMethod(active);
248 }
249
250 int WebPageProxy::getCursorOffset()
251 {
252     if (!isValid())
253         return 0;
254
255     int offset = 0;
256     process()->sendSync(Messages::WebPage::GetCursorOffset(), Messages::WebPage::GetCursorOffset::Reply(offset), m_pageID);
257     return offset;
258 }
259
260 void WebPageProxy::getSurroundingTextAndCursorOffset(String& text, int& offset)
261 {
262     if (!isValid())
263         return;
264
265     process()->sendSync(Messages::WebPage::GetSurroundingTextAndCursorOffset(), Messages::WebPage::GetSurroundingTextAndCursorOffset::Reply(text, offset), m_pageID);
266 }
267
268 IntRect WebPageProxy::getSelectionRect(bool isOnlyEditable)
269 {
270     IntRect rect;
271     process()->sendSync(Messages::WebPage::GetSelectionRect(isOnlyEditable), Messages::WebPage::GetSelectionRect::Reply(rect), m_pageID);
272     return rect;
273 }
274
275 void WebPageProxy::deleteSurroundingText(int offset, int count)
276 {
277     if (!isValid())
278         return;
279
280     process()->send(Messages::WebPage::DeleteSurroundingText(offset, count), m_pageID);
281 }
282
283 void WebPageProxy::didCancelComposition()
284 {
285     m_didCancelCompositionFromWebProcess = true;
286     InputMethodContextEfl* inputMethodContext = static_cast<PageClientImpl*>(m_pageClient)->viewImpl()->inputMethodContext();
287     if (inputMethodContext)
288         inputMethodContext->resetIMFContext();
289     m_didCancelCompositionFromWebProcess = false;
290 }
291
292 void WebPageProxy::removeInputMethodContext(uintptr_t id)
293 {
294     InputMethodContextEfl* inputMethodContext = static_cast<PageClientImpl*>(m_pageClient)->viewImpl()->inputMethodContext();
295     if (!inputMethodContext)
296         return;
297
298     inputMethodContext->removeIMFContext(id);
299 }
300 #endif // #if ENABLE(TIZEN_ISF_PORT)
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         m_editorState = EditorState();
359         m_editorState.isContentEditable = active;
360         m_pageClient->updateTextInputState();
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_CONTEXT_MENU_WEBKIT_2)
428 void WebPageProxy::hideContextMenu()
429 {
430     if (m_activeContextMenu)
431         m_activeContextMenu->hideContextMenu();
432 }
433
434 String WebPageProxy::contextMenuAbsoluteLinkURLString()
435 {
436     if (!m_activeContextMenu)
437         return String();
438
439     return m_activeContextMenuHitTestResultData.absoluteLinkURL;
440 }
441
442 String WebPageProxy::contextMenuAbsoluteImageURLString()
443 {
444     if (!m_activeContextMenu)
445         return String();
446
447     return m_activeContextMenuHitTestResultData.absoluteImageURL;
448 }
449 #endif
450
451 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
452 void WebPageProxy::pasteContextMenuSelected()
453 {
454     static_cast<PageClientImpl*>(m_pageClient)->pasteContextMenuSelected();
455 }
456
457 void WebPageProxy::didSelectPasteMenuFromContextMenu(const String& data, const String& type)
458 {
459     if (!isValid())
460         return;
461
462 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
463     process()->send(Messages::WebPage::SetClipboardDataForPaste(data, type), m_pageID);
464 #endif
465     WebContextMenuItemData item(ActionType, ContextMenuItemTagPaste, String("Paste"), true, false);
466     process()->send(Messages::WebPage::DidSelectItemFromActiveContextMenu(item), m_pageID);
467 }
468 #endif
469
470 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
471 void WebPageProxy::setClipboardData(const String& data, const String& type)
472 {
473     static_cast<PageClientImpl*>(m_pageClient)->setClipboardData(data, type);
474 }
475
476 void WebPageProxy::clearClipboardData()
477 {
478     static_cast<PageClientImpl*>(m_pageClient)->clearClipboardData();
479 }
480 #endif
481
482 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
483 void WebPageProxy::executePasteFromClipboardItem(const String& data, const String& type)
484 {
485     if (!isValid())
486         return;
487
488 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
489     process()->send(Messages::WebPage::SetClipboardDataForPaste(data, type), m_pageID);
490 #endif
491     process()->send(Messages::WebPage::ExecuteEditCommandWithArgument("Paste", data), m_pageID);
492 }
493
494 void WebPageProxy::clipboardContextMenuSelected()
495 {
496     static_cast<PageClientImpl*>(m_pageClient)->clipboardContextMenuSelected();
497 }
498 #endif
499
500 #if ENABLE(TIZEN_REMOTE_WEB_INSPECTOR)
501 uint32_t WebPageProxy::startInspectorServer(uint32_t port)
502 {
503     if (!isValid())
504         return 0;
505
506     uint32_t assignedPort = 0;
507     process()->sendSync(Messages::WebPage::StartInspectorServer(port), Messages::WebPage::StartInspectorServer::Reply(assignedPort), m_pageID);
508     return assignedPort;
509 }
510
511 bool WebPageProxy::stopInspectorServer()
512 {
513     if (!isValid())
514         return false;
515
516     bool result = false;
517     process()->sendSync(Messages::WebPage::StopInspectorServer(), Messages::WebPage::StopInspectorServer::Reply(result), m_pageID);
518     return result;
519 }
520 #endif
521
522 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
523 void WebPageProxy::createPagesToPDF(const IntSize& surfaceSize, const IntSize& contentsSize, const String& fileName)
524 {
525     process()->send(Messages::WebPage::CreatePagesToPDF(surfaceSize, contentsSize, fileName), m_pageID);
526 }
527 #endif
528
529 #if ENABLE(TIZEN_WEB_STORAGE)
530 #if ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
531 void WebPageProxy::getWebStorageQuotaBytes(PassRefPtr<WebStorageQuotaCallback> prpCallback)
532 {
533     RefPtr<WebStorageQuotaCallback> callback = prpCallback;
534     if (!isValid()) {
535         callback->invalidate();
536         return;
537     }
538
539     uint64_t callbackID = callback->callbackID();
540     m_quotaCallbacks.set(callbackID, callback.get());
541     process()->send(Messages::WebPage::GetStorageQuotaBytes(callbackID), m_pageID);
542 }
543
544 void WebPageProxy::didGetWebStorageQuotaBytes(const uint32_t quota, uint64_t callbackID)
545 {
546     RefPtr<WebStorageQuotaCallback> callback = m_quotaCallbacks.take(callbackID);
547     if (!callback) {
548         // FIXME: Log error or assert.
549         // this can validly happen if a load invalidated the callback, though
550         return;
551     }
552
553     m_quotaCallbacks.remove(callbackID);
554
555     RefPtr<WebUInt32> uint32Object = WebUInt32::create(quota);
556     callback->performCallbackWithReturnValue(uint32Object.release().leakRef());
557 }
558 #endif
559
560 void WebPageProxy::setWebStorageQuotaBytes(uint32_t quota)
561 {
562     if (!isValid())
563         return;
564
565     process()->send(Messages::WebPage::SetStorageQuotaBytes(quota), m_pageID, 0);
566 }
567 #endif
568
569 void WebPageProxy::scale(double scaleFactor, const IntPoint& origin)
570 {
571 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
572     static_cast<PageClientImpl*>(m_pageClient)->scaleContents(scaleFactor, origin);
573 #else
574     scalePage(scaleFactor, origin);
575 #endif
576 }
577
578 void WebPageProxy::scaleImage(double scaleFactor, const IntPoint& origin)
579 {
580 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
581     static_cast<PageClientImpl*>(m_pageClient)->scaleImage(scaleFactor, origin);
582 #else
583     scalePage(scaleFactor, origin);
584 #endif
585 }
586
587 double WebPageProxy::scaleFactor()
588 {
589 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
590     return static_cast<PageClientImpl*>(m_pageClient)->scaleFactor();
591 #else
592     return pageScaleFactor();
593 #endif
594 }
595
596 #if ENABLE(TIZEN_ORIENTATION_EVENTS)
597 void WebPageProxy::sendOrientationChangeEvent(int orientation)
598 {
599     process()->send(Messages::WebPage::SendOrientationChangeEvent(orientation), m_pageID, 0);
600 }
601 #endif
602
603 void WebPageProxy::suspendPainting()
604 {
605     if (!isValid())
606         return;
607
608     process()->send(Messages::DrawingArea::SuspendPainting(), m_pageID);
609 }
610
611 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
612 void WebPageProxy::suspendPaintingOfInactiveView()
613 {
614     if (!isValid() || isViewVisible())
615         return;
616
617     process()->send(Messages::DrawingArea::SuspendPainting(), m_pageID);
618 }
619 #endif
620
621 void WebPageProxy::resumePainting()
622 {
623     if (!isValid())
624         return;
625
626     process()->send(Messages::DrawingArea::ResumePainting(), m_pageID);
627 }
628
629 void WebPageProxy::suspendJavaScriptAndResource()
630 {
631     if (!isValid())
632         return;
633
634     process()->send(Messages::WebPage::SuspendJavaScriptAndResources(), m_pageID);
635 }
636
637 void WebPageProxy::resumeJavaScriptAndResource()
638 {
639     if (!isValid())
640         return;
641
642     process()->send(Messages::WebPage::ResumeJavaScriptAndResources(), m_pageID);
643 }
644
645 #if ENABLE(TIZEN_PLUGIN_SUSPEND_RESUME)
646 void WebPageProxy::suspendPlugin()
647 {
648     if (!isValid())
649         return;
650
651     process()->send(Messages::WebPage::SuspendPlugin(), m_pageID);
652 }
653
654 void WebPageProxy::resumePlugin()
655 {
656     if (!isValid())
657         return;
658
659     process()->send(Messages::WebPage::ResumePlugin(), m_pageID);
660 }
661 #endif
662
663 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
664 bool WebPageProxy::scrollOverflow(const FloatPoint& offset)
665 {
666     if (!isValid())
667         return false;
668
669 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
670     if (static_cast<PageClientImpl*>(m_pageClient)->isScrollableLayerFocused())
671         return drawingArea()->layerTreeCoordinatorProxy()->setOffsetForFocusedScrollingContentsLayer(offset);
672 #endif
673     if (static_cast<PageClientImpl*>(m_pageClient)->isScrollableNodeFocused()) {
674         bool scrolled = false;
675         process()->sendSync(Messages::WebPage::ScrollOverflow(offset), Messages::WebPage::ScrollOverflow::Reply(scrolled), m_pageID);
676         return scrolled;
677     }
678
679     return false;
680 }
681
682 bool WebPageProxy::setPressedNodeAtPoint(const IntPoint& point, bool checkOverflowLayer, WebLayerID& webLayerID)
683 {
684     if (!isValid())
685         return false;
686
687     bool pressed = false;
688     process()->sendSync(Messages::WebPage::SetPressedNodeAtPoint(point, checkOverflowLayer), Messages::WebPage::SetPressedNodeAtPoint::Reply(pressed, webLayerID), m_pageID);
689
690     return pressed;
691 }
692
693 void WebPageProxy::setOverflowResult(bool pressed, uint32_t webLayerID)
694 {
695     static_cast<PageClientImpl*>(m_pageClient)->setOverflowResult(pressed, webLayerID);
696 }
697 #endif
698
699 void WebPageProxy::executeEditCommandWithArgument(const String& commandName, const String& argument)
700 {
701     if (!isValid())
702         return;
703
704     DEFINE_STATIC_LOCAL(String, ignoreSpellingCommandName, ("ignoreSpelling"));
705     if (commandName == ignoreSpellingCommandName)
706         ++m_pendingLearnOrIgnoreWordMessageCount;
707
708     process()->send(Messages::WebPage::ExecuteEditCommandWithArgument(commandName, argument), m_pageID);
709 }
710
711 void WebPageProxy::replyJavaScriptAlert()
712 {
713     if (!m_alertReply)
714         return;
715
716     m_alertReply->send();
717     m_alertReply = nullptr;
718 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
719     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
720 #endif
721 }
722
723 void WebPageProxy::replyJavaScriptConfirm(bool result)
724 {
725     if (!m_confirmReply)
726         return;
727
728     m_confirmReply->send(result);
729     m_confirmReply = nullptr;
730 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
731     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
732 #endif
733 }
734
735 void WebPageProxy::replyJavaScriptPrompt(const String& result)
736 {
737     if (!m_promptReply)
738         return;
739
740     m_promptReply->send(result);
741     m_promptReply = nullptr;
742 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
743     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
744 #endif
745 }
746
747 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
748 void WebPageProxy::replyBeforeUnloadConfirmPanel(bool result)
749 {
750     if (!m_beforeUnloadConfirmPanelReply)
751         return;
752
753     m_beforeUnloadConfirmPanelReply->send(result);
754     m_beforeUnloadConfirmPanelReply = nullptr;
755 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
756     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
757 #endif
758 }
759 #endif
760
761 #if ENABLE(TIZEN_ON_AUTHENTICATION_REQUESTED)
762 void WebPageProxy::replyReceiveAuthenticationChallengeInFrame(bool result)
763 {
764     if (!m_AuthReply)
765         return;
766
767     m_AuthReply->send(result);
768     m_AuthReply = nullptr;
769 }
770 #endif
771
772 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
773 void WebPageProxy::replyPolicyForCertificateError(bool result)
774 {
775     if (!m_allowedReply)
776         return;
777
778     m_allowedReply->send(result);
779     m_allowedReply = nullptr;
780 }
781 #endif
782
783 #if PLUGIN_ARCHITECTURE(X11)
784 void WebPageProxy::createPluginContainer(uint64_t& windowID)
785 {
786     notImplemented();
787 }
788
789 void WebPageProxy::windowedPluginGeometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, uint64_t windowID)
790 {
791     notImplemented();
792 }
793 #endif
794
795 void WebPageProxy::didRenderFrame()
796 {
797     static_cast<PageClientImpl*>(m_pageClient)->didRenderFrame();
798 }
799
800 void WebPageProxy::setBackgroundColor(double red, double green, double blue, double alpha)
801 {
802     static_cast<PageClientImpl*>(m_pageClient)->setBackgroundColor(red, green, blue, alpha);
803 }
804
805 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
806 bool WebPageProxy::makeContextCurrent()
807 {
808     return static_cast<PageClientImpl*>(m_pageClient)->makeContextCurrent();
809 }
810 #endif
811
812 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
813 void WebPageProxy::getTextStyleStateForSelection()
814 {
815     process()->send(Messages::WebPage::GetTextStyleStateForSelection(), m_pageID, 0);
816 }
817
818 void WebPageProxy::didGetTextStyleStateForSelection(int underlineState, int italicState, int boldState)
819 {
820     static_cast<PageClientImpl*>(m_pageClient)->didGetTextStyleStateForSelection(underlineState, italicState, boldState);
821 }
822 #endif
823
824 #if ENABLE(TIZEN_ICON_DATABASE)
825 void WebPageProxy::didReceiveIcon()
826 {
827     static_cast<PageClientImpl*>(m_pageClient)->didReceiveIcon();
828 }
829 #endif
830
831 #if ENABLE(TIZEN_MULTIPLE_SELECT)
832 void WebPageProxy::valueChangedForPopupMenuMultiple(WebPopupMenuProxy*, Vector<int32_t> newSelectedIndex)
833 {
834     process()->send(Messages::WebPage::DidChangeSelectedIndexForActivePopupMenuMultiple(newSelectedIndex), m_pageID);
835 }
836 #endif
837
838 #if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
839 void WebPageProxy::pageDidRequestRestoreVisibleContentRect(const IntPoint& point, float scale)
840 {
841     m_pageClient->pageDidRequestRestoreVisibleContentRect(point, scale);
842 }
843 #endif
844
845 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
846 void WebPageProxy::saveSerializedHTMLDataForMainPage(const String& serializedData, const String& fileName)
847 {
848     static_cast<PageClientImpl*>(m_pageClient)->saveSerializedHTMLDataForMainPage(serializedData, fileName);
849 }
850
851 void WebPageProxy::saveSubresourcesData(Vector<WebSubresourceTizen> subresourceData)
852 {
853     static_cast<PageClientImpl*>(m_pageClient)->saveSubresourcesData(subresourceData);
854 }
855
856 void WebPageProxy::startOfflinePageSave(String subresourceFolderName)
857 {
858     if (!isValid())
859         return;
860
861     process()->send(Messages::WebPage::StartOfflinePageSave(subresourceFolderName), m_pageID);
862 }
863 #endif
864
865 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
866 bool WebPageProxy::selectClosestWord(const IntPoint& point, bool isStartedTextSelectionFromOutside)
867 {
868     if (!isValid())
869         return false;
870
871     bool result = false;
872     process()->sendSync(Messages::WebPage::SelectClosestWord(point, isStartedTextSelectionFromOutside), Messages::WebPage::SelectClosestWord::Reply(result), m_pageID);
873     return result;
874 }
875
876 bool WebPageProxy::setLeftSelection(const IntPoint& point)
877 {
878     if (!isValid())
879         return false;
880
881     bool result = false;
882     process()->sendSync(Messages::WebPage::SetLeftSelection(point), Messages::WebPage::SetLeftSelection::Reply(result), m_pageID);
883     return result;
884 }
885
886 bool WebPageProxy::setRightSelection(const IntPoint& point)
887 {
888     if (!isValid())
889         return false;
890
891     bool result;
892     process()->sendSync(Messages::WebPage::SetRightSelection(point), Messages::WebPage::SetRightSelection::Reply(result), m_pageID);
893     return result;
894 }
895
896 bool WebPageProxy::getSelectionHandlers(IntRect& leftRect, IntRect& rightRect)
897 {
898     if (!isValid())
899         return false;
900
901     bool result = false;
902     process()->sendSync(Messages::WebPage::GetSelectionHandlers(), Messages::WebPage::GetSelectionHandlers::Reply(leftRect, rightRect), m_pageID);
903     if (!leftRect.size().isZero() || !rightRect.size().isZero())
904         result = true;
905
906     return result;
907 }
908
909 String WebPageProxy::getSelectionText()
910 {
911     String ret;
912     if (!isValid())
913         return ret;
914
915     process()->sendSync(Messages::WebPage::GetSelectionText(), Messages::WebPage::GetSelectionText::Reply(ret), m_pageID);
916     return ret;
917 }
918
919 bool WebPageProxy::selectionRangeClear()
920 {
921     if (!isValid())
922         return false;
923
924     bool result = false;
925     process()->sendSync(Messages::WebPage::SelectionRangeClear(), Messages::WebPage::SelectionRangeClear::Reply(result), m_pageID);
926     return result;
927 }
928
929 bool WebPageProxy::scrollContentByCharacter(const IntPoint& point, SelectionDirection direction)
930 {
931     if (!isValid())
932         return false;
933
934     bool result = false;
935     process()->sendSync(Messages::WebPage::ScrollContentByCharacter(point, direction), Messages::WebPage::ScrollContentByCharacter::Reply(result), m_pageID);
936     return result;
937 }
938 #endif
939
940 #if ENABLE(TIZEN_LINK_MAGNIFIER)
941 void WebPageProxy::getLinkMagnifierRect(const WebCore::IntPoint& position, const WebCore::IntSize& size)
942 {
943     process()->send(Messages::WebPage::GetLinkMagnifierRect(position, size), m_pageID);
944 }
945
946 void WebPageProxy::didGetLinkMagnifierRect(const IntPoint& position, const IntRect& rect)
947 {
948     if (!rect.isEmpty())
949         LinkMagnifierProxy::linkMagnifier().show(EwkViewImpl::fromEvasObject(viewWidget()), position, rect);
950     else
951         openLink(position);
952 }
953
954 void WebPageProxy::openLink(const IntPoint& position)
955 {
956 #if ENABLE(GESTURE_EVENTS)
957     IntPoint globalPosition(EwkViewImpl::fromEvasObject(viewWidget())->transformToScreen().mapPoint(position));
958     WebGestureEvent gesture(WebEvent::GestureSingleTap, position, globalPosition, WebEvent::Modifiers(0), ecore_time_get());
959     handleGestureEvent(gesture);
960 #endif
961 }
962 #endif
963
964 #if ENABLE(TIZEN_SCREEN_READER)
965 void WebPageProxy::raiseTapEvent(const IntPoint& position)
966 {
967 #if ENABLE(GESTURE_EVENTS)
968     IntPoint globalPosition = EwkViewImpl::fromEvasObject(viewWidget())->transformToScreen().mapPoint(position);
969     process()->send(Messages::WebPage::RaiseTapEvent(position, globalPosition), m_pageID);
970 #else
971     UNUSED_PARAM(position);
972 #endif
973 }
974
975 bool WebPageProxy::moveScreenReaderFocus(bool forward)
976 {
977     bool result;
978     process()->sendSync(Messages::WebPage::MoveScreenReaderFocus(forward), Messages::WebPage::MoveScreenReaderFocus::Reply(result), m_pageID);
979     return result;
980 }
981
982 void WebPageProxy::moveScreenReaderFocusByPoint(const IntPoint& point)
983 {
984     process()->send(Messages::WebPage::MoveScreenReaderFocusByPoint(point), m_pageID);
985 }
986
987 void WebPageProxy::recalcScreenReaderFocusRect()
988 {
989     if (!ScreenReaderProxy::screenReader().isEnabled())
990         return;
991
992     process()->send(Messages::WebPage::RecalcScreenReaderFocusRect(), m_pageID);
993 }
994
995 void WebPageProxy::clearScreenReader()
996 {
997     process()->send(Messages::WebPage::ClearScreenReader(), m_pageID);
998 }
999
1000 void WebPageProxy::didScreenReaderFocusRectChanged(const IntRect& rect)
1001 {
1002 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
1003     FocusRing* focusRing = ewkViewGetFocusRing(viewWidget());
1004     if (!focusRing)
1005         return;
1006
1007     if (!rect.isEmpty())
1008         focusRing->show(rect);
1009     else
1010         focusRing->hide(false);
1011 #else
1012     UNUSED_PARAM(rect);
1013 #endif
1014 }
1015
1016 void WebPageProxy::didScreenReaderTextChanged(const String& text)
1017 {
1018     ScreenReaderProxy::screenReader().setText(text);
1019 }
1020 #endif
1021
1022 #if ENABLE(TIZEN_CSP)
1023 void WebPageProxy::setContentSecurityPolicy(const String& policy, WebCore::ContentSecurityPolicy::HeaderType type)
1024 {
1025     process()->send(Messages::WebPage::SetContentSecurityPolicy(policy, type), m_pageID);
1026 }
1027 #endif
1028
1029 #if ENABLE(TIZEN_APPLICATION_CACHE)
1030 void WebPageProxy::requestApplicationCachePermission(uint64_t frameID, const String& originIdentifier, PassRefPtr<Messages::WebPageProxy::RequestApplicationCachePermission::DelayedReply> allow)
1031 {
1032     WebFrameProxy* frame = process()->webFrame(frameID);
1033     MESSAGE_CHECK(frame);
1034
1035     // Since requestApplicationCachePermission() can spin a nested run loop we need to turn off the responsiveness timer.
1036     process()->responsivenessTimer()->stop();
1037
1038     m_applicationCacheReply = allow;
1039 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1040     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(true);
1041 #endif
1042     RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier);
1043
1044     if (!m_tizenClient.decidePolicyForApplicationCachePermissionRequest(this, origin.get(), frame))
1045         replyApplicationCachePermission(true);
1046 }
1047
1048 void WebPageProxy::replyApplicationCachePermission(bool allow)
1049 {
1050     if (!m_applicationCacheReply)
1051         return;
1052
1053     m_applicationCacheReply->send(allow);
1054     m_applicationCacheReply = nullptr;
1055 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1056     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
1057 #endif
1058 }
1059 #endif
1060
1061 #if ENABLE(TIZEN_INDEXED_DATABASE)
1062 void WebPageProxy::exceededIndexedDatabaseQuota(uint64_t frameID, const String& originIdentifier, int64_t currentUsage, PassRefPtr<Messages::WebPageProxy::ExceededIndexedDatabaseQuota::DelayedReply> reply)
1063 {
1064     WebFrameProxy* frame = process()->webFrame(frameID);
1065     MESSAGE_CHECK(frame);
1066
1067     // Since exceededIndexedDatabaseQuota() can spin a nested run loop we need to turn off the responsiveness timer.
1068     process()->responsivenessTimer()->stop();
1069
1070     m_exceededIndexedDatabaseQuotaReply = reply;
1071 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1072     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(true);
1073 #endif
1074
1075     RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier);
1076
1077     if (!m_tizenClient.exceededIndexedDatabaseQuota(this, origin.get(), currentUsage, frame))
1078         replyExceededIndexedDatabaseQuota(false);
1079 }
1080
1081 void WebPageProxy::replyExceededIndexedDatabaseQuota(bool allow)
1082 {
1083     if (!m_exceededIndexedDatabaseQuotaReply)
1084         return;
1085
1086     m_exceededIndexedDatabaseQuotaReply->send(allow);
1087     m_exceededIndexedDatabaseQuotaReply = nullptr;
1088 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1089     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
1090 #endif
1091 }
1092 #endif
1093
1094 #if ENABLE(TIZEN_SQL_DATABASE)
1095 void WebPageProxy::replyExceededDatabaseQuota(bool allow)
1096 {
1097     if (!m_exceededDatabaseQuotaReply) {
1098         TIZEN_LOGE("m_exceededDatabaseQuotaReply does not exist");
1099         return;
1100     }
1101
1102     m_exceededDatabaseQuotaReply->send(allow);
1103     m_exceededDatabaseQuotaReply = nullptr;
1104 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1105     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
1106 #endif
1107 }
1108 #endif
1109
1110 #if ENABLE(TIZEN_FILE_SYSTEM)
1111 void WebPageProxy::exceededLocalFileSystemQuota(uint64_t frameID, const String& originIdentifier, int64_t currentUsage, PassRefPtr<Messages::WebPageProxy::ExceededLocalFileSystemQuota::DelayedReply> reply)
1112 {
1113     WebFrameProxy* frame = process()->webFrame(frameID);
1114     MESSAGE_CHECK(frame);
1115
1116     // Since exceededLocalFileSystemQuota() can spin a nested run loop we need to turn off the responsiveness timer.
1117     process()->responsivenessTimer()->stop();
1118     m_exceededLocalFileSystemQuotaReply = reply;
1119 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1120     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(true);
1121 #endif
1122
1123     RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier);
1124
1125     if (!m_tizenClient.exceededLocalFileSystemQuota(this, origin.get(), currentUsage, frame))
1126         replyExceededLocalFileSystemQuota(false);
1127 }
1128
1129 void WebPageProxy::replyExceededLocalFileSystemQuota(bool allow)
1130 {
1131     if (!m_exceededLocalFileSystemQuotaReply)
1132         return;
1133
1134     m_exceededLocalFileSystemQuotaReply->send(allow);
1135     m_exceededLocalFileSystemQuotaReply = nullptr;
1136 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1137     process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
1138 #endif
1139 }
1140 #endif
1141
1142 #endif // #if OS(TIZEN)
1143
1144 void WebPageProxy::handleInputMethodKeydown(bool& handled)
1145 {
1146 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1147     handled = m_keyEventQueue.first().forwardedEvent.isFiltered();
1148 #else
1149     handled = m_keyEventQueue.first().isFiltered();
1150 #endif
1151 }
1152
1153 void WebPageProxy::confirmComposition(const String& compositionString)
1154 {
1155     if (!isValid())
1156         return;
1157
1158 #if ENABLE(TIZEN_ISF_PORT)
1159     if (m_didCancelCompositionFromWebProcess)
1160         return;
1161 #endif
1162
1163     process()->send(Messages::WebPage::ConfirmComposition(compositionString), m_pageID, 0);
1164 }
1165
1166 void WebPageProxy::setComposition(const String& compositionString, Vector<WebCore::CompositionUnderline>& underlines, int cursorPosition)
1167 {
1168     if (!isValid())
1169         return;
1170
1171 #if ENABLE(TIZEN_REDUCE_KEY_LAGGING)
1172     // Suspend layout&paint at the key input, and resume layout&paint after 150 ms.
1173     suspendActiveDOMObjectsAndAnimations();
1174     if (m_pageContentResumeTimer)
1175         ecore_timer_del(m_pageContentResumeTimer);
1176     m_pageContentResumeTimer = ecore_timer_add(150.0/1000.0, pageContentResumeTimerFired, this);
1177 #endif
1178
1179     process()->send(Messages::WebPage::SetComposition(compositionString, underlines, cursorPosition), m_pageID, 0);
1180 }
1181
1182 void WebPageProxy::cancelComposition()
1183 {
1184     if (!isValid())
1185         return;
1186
1187     process()->send(Messages::WebPage::CancelComposition(), m_pageID, 0);
1188 }
1189
1190 #if ENABLE(TIZEN_USE_SETTINGS_FONT)
1191 void WebPageProxy::useSettingsFont()
1192 {
1193     process()->send(Messages::WebPage::UseSettingsFont(), m_pageID, 0);
1194 }
1195 #endif
1196
1197 } // namespace WebKit