2 * Copyright (C) 2011 Samsung Electronics
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "WebPageProxy.h"
29 #include "NotImplemented.h"
30 #include "PageClientImpl.h"
32 #include <sys/utsname.h>
35 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
36 #include "LayerTreeHostProxy.h"
38 #include "NativeWebKeyboardEvent.h"
40 #include "WebPageMessages.h"
41 #include "WebProcessProxy.h"
42 #include <WebCore/IntSize.h>
43 #if ENABLE(TIZEN_SUPPORT_RSS_LINK_PARSING)
44 #include "WKPageTizen.h"
46 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
47 #include "WebContextMenuProxy.h"
50 using namespace WebCore;
55 Evas_Object* WebPageProxy::viewWidget()
57 return static_cast<PageClientImpl*>(m_pageClient)->viewWidget();
60 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
64 WTF::String osVersion;
71 version = makeString(String::number(WEBKIT_USER_AGENT_MAJOR_VERSION), '.',
72 String::number(WEBKIT_USER_AGENT_MINOR_VERSION), '+');
74 if (uname(&name) != -1)
75 osVersion = WTF::String(name.sysname) + " " + WTF::String(name.machine);
77 osVersion = "Unknown";
79 if (applicationNameForUserAgent.isEmpty())
80 return makeString("Mozilla/5.0 (", platform, "; ", osVersion, ") AppleWebKit/", version,
81 " (KHTML, like Gecko) Version/5.0 Safari/", version);
83 return makeString("Mozilla/5.0 (", platform, "; ", osVersion, ") AppleWebKit/", version,
84 " (KHTML, like Gecko) Version/5.0 Safari/", version, applicationNameForUserAgent);
87 void WebPageProxy::getEditorCommandsForKeyEvent(Vector<WTF::String>& commandsList)
92 void WebPageProxy::saveRecentSearches(const String&, const Vector<String>&)
97 void WebPageProxy::loadRecentSearches(const String&, Vector<String>&)
102 #if ENABLE(TIZEN_CUSTOM_HEADERS)
103 void WebPageProxy::addCustomHeader(const String& name, const String& value)
113 process()->send(Messages::WebPage::AddCustomHeader(name, value), m_pageID);
119 bool WebPageProxy::scrollMainFrameBy(const IntSize& scrollOffset)
121 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
122 return static_cast<PageClientImpl*>(m_pageClient)->scrollBy(scrollOffset);
127 process()->send(Messages::WebPage::ScrollMainFrameBy(scrollOffset), m_pageID);
132 void WebPageProxy::scrollMainFrameTo(const IntPoint& scrollPosition)
134 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
135 static_cast<PageClientImpl*>(m_pageClient)->scrollTo(scrollPosition);
140 process()->send(Messages::WebPage::ScrollMainFrameTo(scrollPosition), m_pageID);
144 void WebPageProxy::didChangeScrollPositionForMainFrame(const IntPoint& scrollPosition)
146 #if !ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
147 m_scrollPosition = scrollPosition;
151 void WebPageProxy::didChangeContentsSize(const IntSize& size)
153 if (m_contentsSize == size)
156 m_contentsSize = size;
157 m_pageClient->didChangeContentsSize(size);
160 PassRefPtr<WebImage> WebPageProxy::createSnapshot(const IntRect& rect, float scaleFactor)
165 ShareableBitmap::Handle snapshotHandle;
166 // Do not wait for more than a second (arbitrary) for the WebProcess to get the snapshot so
167 // that the UI Process is not permanently stuck waiting on a potentially crashing Web Process.
168 static const double createSnapshotSyncMessageTimeout = 1.0;
169 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
170 float baseScaleFactor = static_cast<PageClientImpl*>(m_pageClient)->scaleFactor();
171 scaleFactor = scaleFactor * baseScaleFactor;
172 IntPoint scrollPosition = static_cast<PageClientImpl*>(m_pageClient)->scrollPosition();
173 IntRect scaledRect = rect;
174 scaledRect.move(scrollPosition.x(), scrollPosition.y());
175 scaledRect.scale(1/baseScaleFactor);
176 process()->sendSync(Messages::WebPage::CreateSnapshot(scaledRect, scaleFactor), Messages::WebPage::CreateSnapshot::Reply(snapshotHandle), m_pageID, createSnapshotSyncMessageTimeout);
178 process()->sendSync(Messages::WebPage::CreateSnapshot(rect, scaleFactor), Messages::WebPage::CreateSnapshot::Reply(snapshotHandle), m_pageID, createSnapshotSyncMessageTimeout);
180 if (snapshotHandle.isNull())
182 return WebImage::create(ShareableBitmap::create(snapshotHandle));
185 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
186 void WebPageProxy::setInputMethodState(bool active, const AtomicString& inputType, const String& inputValue)
188 static_cast<PageClientImpl*>(m_pageClient)->setInputMethodState(active, inputType, inputValue);
191 void WebPageProxy::setInputMethodState(bool active)
193 //FIXME : it should be contributable
194 static_cast<PageClientImpl*>(m_pageClient)->setInputMethodState(active);
198 #if ENABLE(TIZEN_ISF_PORT)
199 void WebPageProxy::handleInputMethodMouseRelease()
201 static_cast<PageClientImpl*>(m_pageClient)->handleInputMethodMouseRelease();
204 void WebPageProxy::updateCursorPosition()
206 static_cast<PageClientImpl*>(m_pageClient)->setCursorPosition();
209 int WebPageProxy::getCursorOffsetPosition()
215 process()->sendSync(Messages::WebPage::GetCursorOffsetPosition(), Messages::WebPage::GetCursorOffsetPosition::Reply(offset), m_pageID);
219 String WebPageProxy::getContentOfPosition()
225 process()->sendSync(Messages::WebPage::GetContentOfPosition(), Messages::WebPage::GetContentOfPosition::Reply(content), m_pageID);
229 bool WebPageProxy::deleteSurroundingPosition()
235 process()->sendSync(Messages::WebPage::DeleteSurroundingPosition(), Messages::WebPage::DeleteSurroundingPosition::Reply(result), m_pageID);
239 void WebPageProxy::getInputMethodState(bool& state)
241 state = static_cast<PageClientImpl*>(m_pageClient)->getInputMethodState();
245 void WebPageProxy::requestUpdateFormNavigation()
250 process()->send(Messages::WebPage::RequestUpdateFormNavigation(), m_pageID);
253 void WebPageProxy::moveFocus(int newIndex)
258 process()->send(Messages::WebPage::MoveFocus(newIndex), m_pageID);
261 void WebPageProxy::updateFormNavigation(int length, int offset)
263 static_cast<PageClientImpl*>(m_pageClient)->updateFormNavigation(length, offset);
266 void WebPageProxy::handleInputMethodKeydown(bool& handled)
268 static_cast<PageClientImpl*>(m_pageClient)->handleInputMethodKeydown();
270 #if ENABLE(TIZEN_ISF_PORT)
271 NativeWebKeyboardEvent event = m_keyEventQueue.first();
272 handled = event.isFiltered();
276 void WebPageProxy::confirmComposition(const String& compositionString)
281 process()->send(Messages::WebPage::ConfirmComposition(compositionString), m_pageID);
284 void WebPageProxy::setComposition(const String& compositionString, Vector<CompositionUnderline>& underlines, int cursorPosition)
289 process()->send(Messages::WebPage::SetComposition(compositionString, underlines, cursorPosition), m_pageID);
291 #if ENABLE(TIZEN_TEXT_CARET_HANDLING_WK2)
292 void WebPageProxy::setCaretPosition(const WebCore::IntPoint& pos)
297 process()->send(Messages::WebPage::SetCaretPosition(pos), m_pageID);
300 void WebPageProxy::getCaretPosition(WebCore::IntRect& rect)
305 process()->sendSync(Messages::WebPage::GetCaretPosition(), Messages::WebPage::GetCaretPosition::Reply(rect), m_pageID);
308 #if ENABLE(TIZEN_MM_PLAYER)
309 void WebPageProxy::processHTML5Video(const String& url, const String& cookie)
311 m_tizenClient.processHTML5Video(this, url, cookie);
315 #if ENABLE(TIZEN_PLUGIN_CUSTOM_REQUEST)
316 void WebPageProxy::processPluginCustomRequest(const String& request, const String& msg)
318 if (String("requestKeyboard,plugin") == request) {
320 if (String("show") == msg)
322 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
323 AtomicString inputType;
324 WTF::String inputValue;
325 setInputMethodState(active, inputType,inputValue);
327 setInputMethodState(active);
329 // plugin does not use preedit.
330 if (active && static_cast<PageClientImpl*>(m_pageClient)->getIMFContext())
331 ecore_imf_context_prediction_allow_set(static_cast<PageClientImpl*>(m_pageClient)->getIMFContext(), false);
333 #if ENABLE(TIZEN_JSBRIDGE_PLUGIN)
334 else if (String("requestToNative,json") == request)
335 m_tizenClient.processJSBridgePlugin(this, request, msg);
341 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
342 void WebPageProxy::setFocusedInputElementValue(const String& inputValue)
347 process()->send(Messages::WebPage::SetFocusedInputElementValue(inputValue), m_pageID);
350 String WebPageProxy::getFocusedInputElementValue()
356 process()->sendSync(Messages::WebPage::GetFocusedInputElementValue(), Messages::WebPage::GetFocusedInputElementValue::Reply(inputValue), m_pageID);
361 #if ENABLE(TIZEN_DATALIST_ELEMENT)
362 Vector<String> WebPageProxy::getFocusedInputElementDataList()
365 return Vector<String>();
367 Vector<String> optionList;
368 process()->sendSync(Messages::WebPage::GetFocusedInputElementDataList(), Messages::WebPage::GetFocusedInputElementDataList::Reply(optionList), m_pageID);
373 void WebPageProxy::focusedNodeChanged(const IntRect& focusedNodeRect)
375 static_cast<PageClientImpl*>(m_pageClient)->setFocusedNodeRect(focusedNodeRect);
378 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
379 void WebPageProxy::updateScrollbar(const IntPoint& scrollPosition)
381 static_cast<PageClientImpl*>(m_pageClient)->updateScrollbar(scrollPosition);
385 void WebPageProxy::initializeTizenClient(const WKPageTizenClient* client)
387 m_tizenClient.initialize(client);
390 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
391 WebHitTestResult::Data WebPageProxy::hitTestResultAtPoint(const IntPoint& point, int hitTestMode)
393 WebHitTestResult::Data hitTestResultData;
395 return hitTestResultData;
397 process()->sendSync(Messages::WebPage::HitTestResultAtPoint(point, hitTestMode),
398 Messages::WebPage::HitTestResultAtPoint::Reply(hitTestResultData), m_pageID);
400 return hitTestResultData;
404 #if ENABLE(TIZEN_SUPPORT_RSS_LINK_PARSING)
405 void WebPageProxy::getRssItems(PassRefPtr<RssCallback> prpCallback)
407 RefPtr<RssCallback> callback = prpCallback;
409 callback->invalidate();
413 uint64_t callbackID = callback->callbackID();
414 m_rssCallbacks.set(callbackID, callback.get());
415 process()->send(Messages::WebPage::GetRssItems(callbackID), m_pageID);
418 void WebPageProxy::getRssItemsCallback(const Vector<WebKit::RssItemEfl>& rssItems, uint64_t callbackID)
420 RefPtr<RssCallback> callback = m_rssCallbacks.take(callbackID);
422 // FIXME: Log error or assert.
426 // Convert Vector<WebKit::RssItemEfl> to Eina_List which has WKRssItemEfl.
427 Eina_List* retList = 0;
428 for (size_t i = 0; i < rssItems.size(); ++i)
430 WKRssItemEfl* rssItem = static_cast<WKRssItemEfl*>(malloc(sizeof(WKRssItemEfl)));
431 rssItem->type = static_cast<LinkTypeEfl>(rssItems[i].type());
432 if (!rssItems[i].href().isEmpty())
433 rssItem->href = strdup(rssItems[i].href().utf8().data());
436 if (!rssItems[i].title().isEmpty())
437 rssItem->title = strdup(rssItems[i].title().utf8().data());
440 retList = eina_list_append(retList, rssItem);
443 callback->performCallbackWithReturnValue(retList);
447 EINA_LIST_FREE(retList, data) {
449 WKRssItemEfl* rssItem = static_cast<WKRssItemEfl*>(data);
451 free(const_cast<char*>(rssItem->href));
453 free(const_cast<char*>(rssItem->title));
458 #endif // #if ENABLE(TIZEN_SUPPORT_RSS_LINK_PARSING)
460 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
461 void WebPageProxy::recordingSurfaceSetEnableSet(bool enable)
466 process()->send(Messages::WebPage::RecordingSurfaceSetEnableSet(enable), m_pageID, 0);
470 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
471 void WebPageProxy::hideContextMenu()
473 if (m_activeContextMenu)
474 m_activeContextMenu->hideContextMenu();
477 String WebPageProxy::contextMenuAbsoluteLinkURLString()
479 if (!m_activeContextMenu)
482 return m_activeContextMenuHitTestResultData.absoluteLinkURL;
485 String WebPageProxy::contextMenuAbsoluteImageURLString()
487 if (!m_activeContextMenu)
490 return m_activeContextMenuHitTestResultData.absoluteImageURL;
494 #if ENABLE(TIZEN_WEBKIT_PASTEBOARD)
495 void WebPageProxy::writeDataToClipboardWithType(const String& data, uint64_t type)
497 static_cast<PageClientImpl*>(m_pageClient)->writeDataToClipboardWithType(data, static_cast<Pasteboard::PasteboardDataType>(type));
500 void WebPageProxy::pasteWithClipboard()
502 static_cast<PageClientImpl*>(m_pageClient)->pasteWithClipboard();
505 void WebPageProxy::sendPasteMessageWithData(const String& data, Pasteboard::PasteboardDataType type)
507 #if ENABLE(CONTEXT_MENUS)
511 process()->send(Messages::WebPage::SetDataToPasteboardWithType(data, static_cast<uint64_t>(type)), m_pageID);
512 WebContextMenuItemData item(ActionType, ContextMenuItemTagPaste, String("Paste"), true, false);
513 process()->send(Messages::WebPage::DidSelectItemFromActiveContextMenu(item), m_pageID);
518 #if ENABLE(TIZEN_WEBKIT2_REMOTE_WEB_INSPECTOR)
519 uint32_t WebPageProxy::startInspectorServer(uint32_t port)
524 uint32_t assignedPort = 0;
525 process()->sendSync(Messages::WebPage::StartInspectorServer(port), Messages::WebPage::StartInspectorServer::Reply(assignedPort), m_pageID);
529 bool WebPageProxy::stopInspectorServer()
535 process()->sendSync(Messages::WebPage::StopInspectorServer(), Messages::WebPage::StopInspectorServer::Reply(result), m_pageID);
540 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
541 void WebPageProxy::createPagesToPDF(const IntSize& size, const String& fileName)
543 process()->send(Messages::WebPage::CreatePagesToPDF(size, fileName), m_pageID);
547 #if ENABLE(TIZEN_WEB_STORAGE)
548 #if ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
549 void WebPageProxy::getWebStorageQuotaBytes(PassRefPtr<WebStorageQuotaCallback> prpCallback)
551 RefPtr<WebStorageQuotaCallback> callback = prpCallback;
553 callback->invalidate();
557 uint64_t callbackID = callback->callbackID();
558 m_quotaCallbacks.set(callbackID, callback.get());
559 process()->send(Messages::WebPage::GetStorageQuotaBytes(callbackID), m_pageID);
562 void WebPageProxy::didGetWebStorageQuotaBytes(const uint32_t quota, uint64_t callbackID)
564 RefPtr<WebStorageQuotaCallback> callback = m_quotaCallbacks.take(callbackID);
566 // FIXME: Log error or assert.
567 // this can validly happen if a load invalidated the callback, though
571 m_quotaCallbacks.remove(callbackID);
573 RefPtr<WebUInt32> uint32Object = WebUInt32::create(quota);
574 callback->performCallbackWithReturnValue(uint32Object.release().leakRef());
578 void WebPageProxy::setWebStorageQuotaBytes(uint32_t quota)
583 process()->send(Messages::WebPage::SetStorageQuotaBytes(quota), m_pageID, 0);
587 void WebPageProxy::scale(double scaleFactor, const IntPoint& origin)
589 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
590 static_cast<PageClientImpl*>(m_pageClient)->scaleContents(scaleFactor, origin);
592 scalePage(scaleFactor, origin);
596 void WebPageProxy::scaleImage(double scaleFactor, const IntPoint& origin, bool adjustToBoundary)
598 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
599 static_cast<PageClientImpl*>(m_pageClient)->scaleImage(scaleFactor, origin, adjustToBoundary);
601 scalePage(scaleFactor, origin);
605 double WebPageProxy::scaleFactor()
607 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
608 return static_cast<PageClientImpl*>(m_pageClient)->scaleFactor();
610 return pageScaleFactor();
614 #if ENABLE(TIZEN_ORIENTATION_EVENTS)
615 void WebPageProxy::sendOrientationChangeEvent(int orientation)
617 process()->send(Messages::WebPage::SendOrientationChangeEvent(orientation), m_pageID, 0);
621 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
622 bool WebPageProxy::scrollOverflow(const FloatPoint& offset)
624 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
625 return isValid() ? drawingArea()->layerTreeHostProxy()->setOffsetForFocusedScrollingContentsLayer(offset) : false;
627 bool scrolled = false;
631 process()->sendSync(Messages::WebPage::ScrollOverflow(offset), Messages::WebPage::ScrollOverflow::Reply(scrolled), m_pageID);
637 bool WebPageProxy::setPressedNodeAtPoint(const IntPoint& point)
639 bool pressed = false;
643 process()->sendSync(Messages::WebPage::SetPressedNodeAtPoint(point), Messages::WebPage::SetPressedNodeAtPoint::Reply(pressed), m_pageID);
649 void WebPageProxy::executeEditCommandWithArgument(const String& commandName, const String& argument)
654 DEFINE_STATIC_LOCAL(String, ignoreSpellingCommandName, ("ignoreSpelling"));
655 if (commandName == ignoreSpellingCommandName)
656 ++m_pendingLearnOrIgnoreWordMessageCount;
658 process()->send(Messages::WebPage::ExecuteEditCommandWithArgument(commandName, argument), m_pageID);
661 #if ENABLE(TIZEN_FIX_PLUGIN_DOWNLOAD)
662 bool WebPageProxy::arePluginsEnabled() const
664 bool enabled = false;
666 process()->sendSync(Messages::WebPage::ArePluginsEnabled(), Messages::WebPage::ArePluginsEnabled::Reply(enabled), m_pageID);
670 #endif // ENABLE(TIZEN_FIX_PLUGIN_DOWNLOAD)
672 void WebPageProxy::replyJavaScriptAlert()
677 m_alertReply->send();
678 m_alertReply = nullptr;
679 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
680 process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
684 void WebPageProxy::replyJavaScriptConfirm(bool result)
689 m_confirmReply->send(result);
690 m_confirmReply = nullptr;
691 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
692 process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
696 void WebPageProxy::replyJavaScriptPrompt(const String& result)
701 m_promptReply->send(result);
702 m_promptReply = nullptr;
703 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
704 process()->connection()->setForcelySetAllAsyncMessagesToDispatchEvenWhenWaitingForSyncReply(false);
708 #if PLUGIN_ARCHITECTURE(X11)
709 void WebPageProxy::createPluginContainer(uint64_t& windowID)
714 void WebPageProxy::windowedPluginGeometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, uint64_t windowID)
720 #if ENABLE(TIZEN_WEBKIT2_THEME_SET)
721 void WebPageProxy::setThemePath(const String& themePath)
723 process()->send(Messages::WebPage::SetThemePath(themePath), m_pageID, 0);
727 void WebPageProxy::didRenderFrame()
729 static_cast<PageClientImpl*>(m_pageClient)->didRenderFrame();
732 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
733 void WebPageProxy::setBackgroundColor(double red, double green, double blue, double alpha)
735 static_cast<PageClientImpl*>(m_pageClient)->setBackgroundColor(red, green, blue, alpha);
739 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
740 void WebPageProxy::getTextStyleStateForSelection()
742 process()->send(Messages::WebPage::GetTextStyleStateForSelection(), m_pageID, 0);
745 void WebPageProxy::didGetTextStyleStateForSelection(int underlineState, int italicState, int boldState)
747 static_cast<PageClientImpl*>(m_pageClient)->didGetTextStyleStateForSelection(underlineState, italicState, boldState);
751 #endif // #if OS(TIZEN)
753 } // namespace WebKit