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