2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Intel Corporation. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
30 #include "Arguments.h"
31 #include "DataReference.h"
32 #include "DecoderAdapter.h"
33 #include "DrawingArea.h"
34 #include "InjectedBundle.h"
35 #include "InjectedBundleBackForwardList.h"
36 #include "LayerTreeHost.h"
37 #include "MessageID.h"
38 #include "NetscapePlugin.h"
39 #include "NotificationPermissionRequestManager.h"
40 #include "PageOverlay.h"
41 #include "PluginProxy.h"
42 #include "PluginView.h"
43 #include "PrintInfo.h"
44 #include "SessionState.h"
45 #include "ShareableBitmap.h"
46 #include "WebAlternativeTextClient.h"
47 #include "WebBackForwardList.h"
48 #include "WebBackForwardListItem.h"
49 #include "WebBackForwardListProxy.h"
50 #include "WebChromeClient.h"
51 #include "WebColorChooser.h"
52 #include "WebContextMenu.h"
53 #include "WebContextMenuClient.h"
54 #include "WebContextMessages.h"
55 #include "WebCoreArgumentCoders.h"
56 #include "WebDragClient.h"
57 #include "WebEditorClient.h"
59 #include "WebEventConversion.h"
61 #include "WebFullScreenManager.h"
62 #include "WebGeolocationClient.h"
63 #include "WebGeometry.h"
65 #include "WebInspector.h"
66 #include "WebInspectorClient.h"
67 #include "WebNotificationClient.h"
68 #include "WebOpenPanelResultListener.h"
69 #include "WebPageCreationParameters.h"
70 #include "WebPageGroupProxy.h"
71 #include "WebPageProxyMessages.h"
72 #include "WebPopupMenu.h"
73 #include "WebPreferencesStore.h"
74 #include "WebProcess.h"
75 #include "WebProcessProxyMessages.h"
76 #include <JavaScriptCore/APICast.h>
77 #include <WebCore/AbstractDatabase.h>
78 #include <WebCore/ArchiveResource.h>
79 #include <WebCore/Chrome.h>
80 #include <WebCore/ContextMenuController.h>
81 #include <WebCore/DocumentFragment.h>
82 #include <WebCore/DocumentLoader.h>
83 #include <WebCore/DocumentMarkerController.h>
84 #include <WebCore/DragController.h>
85 #include <WebCore/DragData.h>
86 #include <WebCore/DragSession.h>
87 #include <WebCore/EventHandler.h>
88 #include <WebCore/FocusController.h>
89 #include <WebCore/FormState.h>
90 #include <WebCore/Frame.h>
91 #include <WebCore/FrameLoadRequest.h>
92 #include <WebCore/FrameLoaderTypes.h>
93 #include <WebCore/FrameView.h>
94 #include <WebCore/HTMLFormElement.h>
95 #include <WebCore/HTMLInputElement.h>
96 #include <WebCore/HTMLPlugInElement.h>
97 #include <WebCore/HistoryItem.h>
98 #include <WebCore/KeyboardEvent.h>
99 #include <WebCore/MouseEvent.h>
100 #include <WebCore/Page.h>
101 #include <WebCore/PlatformKeyboardEvent.h>
102 #include <WebCore/PluginDocument.h>
103 #include <WebCore/PrintContext.h>
104 #include <WebCore/RenderLayer.h>
105 #include <WebCore/RenderTreeAsText.h>
106 #include <WebCore/RenderView.h>
107 #include <WebCore/ResourceRequest.h>
108 #include <WebCore/RunLoop.h>
109 #include <WebCore/SchemeRegistry.h>
110 #include <WebCore/ScriptValue.h>
111 #include <WebCore/SerializedScriptValue.h>
112 #include <WebCore/Settings.h>
113 #include <WebCore/SharedBuffer.h>
114 #include <WebCore/SubstituteData.h>
115 #include <WebCore/TextIterator.h>
116 #include <WebCore/markup.h>
117 #include <runtime/JSLock.h>
118 #include <runtime/JSValue.h>
120 #include <WebCore/Range.h>
121 #include <WebCore/VisiblePosition.h>
124 #include <WebCore/MHTMLArchive.h>
127 #if ENABLE(PLUGIN_PROCESS)
129 #include "MachPort.h"
133 #if ENABLE(BATTERY_STATUS)
134 #include "WebBatteryClient.h"
137 #if ENABLE(NETWORK_INFO)
138 #include "WebNetworkInfoClient.h"
141 #if ENABLE(WEB_INTENTS)
142 #include "IntentData.h"
145 #if ENABLE(VIBRATION)
146 #include "WebVibrationClient.h"
149 #if ENABLE(TIZEN_REGISTER_PROTOCOL_HANDLER) || ENABLE(TIZEN_CUSTOM_SCHEME_HANDLER)
150 #include "WebRegisterProtocolHandlerClient.h"
153 #if ENABLE(TIZEN_REGISTER_CONTENT_HANDLER)
154 #include "WebRegisterContentHandlerClient.h"
158 #include "BuiltInPDFView.h"
162 #if ENABLE(DEVICE_ORIENTATION)
163 #include "DeviceMotionClientQt.h"
164 #include "DeviceOrientationClientQt.h"
166 #include "HitTestResult.h"
172 #include "DataObjectGtk.h"
173 #include "WebPrintOperationGtk.h"
176 #if ENABLE(TIZEN_MEDIA_STREAM)
177 #include "WebUserMediaClient.h"
178 #include "UserMediaPermissionRequestManager.h"
181 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
182 #include <WebCore/NodeList.h>
183 #include "HTMLLinkElement.h"
184 #include "HTMLMetaElement.h"
187 #if ENABLE(TIZEN_GEOLOCATION)
188 #include <WebCore/GeolocationClientMock.h>
189 #include <WebCore/GeolocationController.h>
193 #include <wtf/RefCountedLeakCounter.h>
196 #if ENABLE(TIZEN_INDEXED_DATABASE)
197 #include <WebCore/PageGroup.h>
198 #include <WebCore/GroupSettings.h>
201 #if ENABLE(TIZEN_ISF_PORT)
202 #include "NativeWebKeyboardEvent.h"
205 #if ENABLE(TIZEN_NATIVE_MEMORY_SNAPSHOT)
206 #include "AboutDataTizen.h"
209 #if ENABLE(TIZEN_DRAG_SUPPORT)
210 #include "DataObjectTizen.h"
213 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
214 #include "HTMLImageElement.h"
218 using namespace WebCore;
223 class SendStopResponsivenessTimer {
225 SendStopResponsivenessTimer(WebPage* page)
230 ~SendStopResponsivenessTimer()
232 m_page->send(Messages::WebPageProxy::StopResponsivenessTimer());
239 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, webPageCounter, ("WebPage"));
241 PassRefPtr<WebPage> WebPage::create(uint64_t pageID, const WebPageCreationParameters& parameters)
243 RefPtr<WebPage> page = adoptRef(new WebPage(pageID, parameters));
245 if (page->pageGroup()->isVisibleToInjectedBundle() && WebProcess::shared().injectedBundle())
246 WebProcess::shared().injectedBundle()->didCreatePage(page.get());
248 return page.release();
251 WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
252 : m_viewSize(parameters.viewSize)
253 , m_useFixedLayout(false)
254 , m_drawsBackground(true)
255 , m_drawsTransparentBackground(false)
258 , m_tabToLinks(false)
260 , m_windowIsVisible(false)
261 , m_isSmartInsertDeleteEnabled(parameters.isSmartInsertDeleteEnabled)
262 , m_layerHostingMode(parameters.layerHostingMode)
263 , m_keyboardEventBeingInterpreted(0)
265 , m_nativeWindow(parameters.nativeWindow)
267 , m_accessibilityObject(0)
269 , m_setCanStartMediaTimer(WebProcess::shared().runLoop(), this, &WebPage::setCanStartMediaTimerFired)
270 , m_findController(this)
271 #if ENABLE(TOUCH_EVENTS)
273 , m_tapHighlightController(this)
276 #if ENABLE(INPUT_TYPE_COLOR)
277 , m_activeColorChooser(0)
279 #if ENABLE(GEOLOCATION)
280 , m_geolocationPermissionRequestManager(this)
283 , m_canRunBeforeUnloadConfirmPanel(parameters.canRunBeforeUnloadConfirmPanel)
284 , m_canRunModal(parameters.canRunModal)
285 , m_isRunningModal(false)
286 , m_cachedMainFrameIsPinnedToLeftSide(false)
287 , m_cachedMainFrameIsPinnedToRightSide(false)
288 , m_canShortCircuitHorizontalWheelEvents(false)
289 , m_numWheelEventHandlers(0)
290 , m_cachedPageCount(0)
291 #if ENABLE(CONTEXT_MENUS)
292 , m_isShowingContextMenu(false)
294 , m_willGoToBackForwardItemCallbackEnabled(true)
296 , m_gestureReachedScrollingLimit(false)
298 #if ENABLE(PAGE_VISIBILITY_API)
299 , m_visibilityState(WebCore::PageVisibilityStateVisible)
301 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
302 , m_recordingSurfaceSetEnable(false)
303 , m_recordingSurfaceSetLoadStart(false)
304 , m_recordingSurfaceSetLoadFinished(false)
305 , m_recordingSurfaceSetSettings(false)
307 #if ENABLE(TIZEN_SYNC_REQUEST_ANIMATION_FRAME)
308 , m_suspendedAnimationController(false)
310 , m_inspectorClient(0)
313 // FIXME: This is a non-ideal location for this Setting and
314 // 4ms should be adopted project-wide now, https://bugs.webkit.org/show_bug.cgi?id=61214
315 #if ENABLE(TIZEN_DOM_TIMER_MIN_INTERVAL_SET)
316 Settings::setDefaultMinDOMTimerInterval(0.001);
318 Settings::setDefaultMinDOMTimerInterval(0.004);
321 Page::PageClients pageClients;
322 pageClients.chromeClient = new WebChromeClient(this);
323 #if ENABLE(CONTEXT_MENUS)
324 pageClients.contextMenuClient = new WebContextMenuClient(this);
326 pageClients.editorClient = new WebEditorClient(this);
327 #if ENABLE(DRAG_SUPPORT)
328 pageClients.dragClient = new WebDragClient(this);
330 pageClients.backForwardClient = WebBackForwardListProxy::create(this);
331 #if ENABLE(INSPECTOR)
332 m_inspectorClient = new WebInspectorClient(this);
333 pageClients.inspectorClient = m_inspectorClient;
335 #if USE(AUTOCORRECTION_PANEL)
336 pageClients.alternativeTextClient = new WebAlternativeTextClient(this);
339 m_page = adoptPtr(new Page(pageClients));
341 #if ENABLE(BATTERY_STATUS)
342 WebCore::provideBatteryTo(m_page.get(), new WebBatteryClient(this));
344 #if ENABLE(GEOLOCATION)
345 #if ENABLE(TIZEN_GEOLOCATION) && ENABLE(TIZEN_WEBKIT2_EFL_WTR)
346 if (WebProcess::shared().injectedBundle() && WebProcess::shared().injectedBundle()->testRunnerModeEnabled()) {
347 GeolocationClientMock* mock = new GeolocationClientMock();
348 WebCore::provideGeolocationTo(m_page.get(), mock);
349 mock->setController(WebCore::GeolocationController::from(m_page.get()));
351 #endif // ENABLE(TIZEN_GEOLOCATION) && ENABLE(TIZEN_WEBKIT2_EFL_WTR)
352 WebCore::provideGeolocationTo(m_page.get(), new WebGeolocationClient(this));
354 #if ENABLE(DEVICE_ORIENTATION) && PLATFORM(QT)
355 WebCore::provideDeviceMotionTo(m_page.get(), new DeviceMotionClientQt);
356 WebCore::provideDeviceOrientationTo(m_page.get(), new DeviceOrientationClientQt);
358 #if ENABLE(NETWORK_INFO)
359 WebCore::provideNetworkInfoTo(m_page.get(), new WebNetworkInfoClient(this));
361 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
362 WebCore::provideNotification(m_page.get(), new WebNotificationClient(this));
364 #if ENABLE(VIBRATION)
365 WebCore::provideVibrationTo(m_page.get(), new WebVibrationClient(this));
368 #if ENABLE(VIBRATION)
369 WebCore::provideVibrationTo(m_page.get(), new WebVibrationClient(this));
372 #if ENABLE(TIZEN_MEDIA_STREAM)
373 WebCore::provideUserMediaTo(m_page.get(), new WebUserMediaClient(this));
376 #if ENABLE(TIZEN_REGISTER_PROTOCOL_HANDLER) || ENABLE(TIZEN_CUSTOM_SCHEME_HANDLER)
377 WebCore::provideRegisterProtocolHandlerTo(m_page.get(), new WebRegisterProtocolHandlerClient(this));
380 #if ENABLE(TIZEN_REGISTER_CONTENT_HANDLER)
381 WebCore::provideRegisterContentHandlerTo(m_page.get(), new WebRegisterContentHandlerClient(this));
384 // Qt does not yet call setIsInWindow. Until it does, just leave
385 // this line out so plug-ins and video will work. Eventually all platforms
386 // should call setIsInWindow and this comment and #if should be removed,
387 // leaving behind the setCanStartMedia call.
389 m_page->setCanStartMedia(false);
392 updatePreferences(parameters.store);
394 m_pageGroup = WebProcess::shared().webPageGroup(parameters.pageGroupData);
395 m_page->setGroupName(m_pageGroup->identifier());
396 m_page->setDeviceScaleFactor(parameters.deviceScaleFactor);
398 platformInitialize();
400 m_drawingArea = DrawingArea::create(this, parameters);
401 m_drawingArea->setPaintingEnabled(false);
403 m_mainFrame = WebFrame::createMainFrame(this);
405 setUseFixedLayout(parameters.useFixedLayout);
407 setDrawsBackground(parameters.drawsBackground);
408 setDrawsTransparentBackground(parameters.drawsTransparentBackground);
410 setPaginationMode(parameters.paginationMode);
411 setPaginationBehavesLikeColumns(parameters.paginationBehavesLikeColumns);
412 setPageLength(parameters.pageLength);
413 setGapBetweenPages(parameters.gapBetweenPages);
415 setMemoryCacheMessagesEnabled(parameters.areMemoryCacheClientCallsEnabled);
417 setActive(parameters.isActive);
418 setFocused(parameters.isFocused);
419 setIsInWindow(parameters.isInWindow);
421 m_userAgent = parameters.userAgent;
423 WebBackForwardListProxy::setHighestItemIDFromUIProcess(parameters.highestUsedBackForwardItemID);
425 if (!parameters.sessionState.isEmpty())
426 restoreSession(parameters.sessionState);
428 m_drawingArea->setPaintingEnabled(true);
430 setMediaVolume(parameters.mediaVolume);
433 webPageCounter.increment();
439 if (m_backForwardList)
440 m_backForwardList->detach();
444 m_sandboxExtensionTracker.invalidate();
446 for (HashSet<PluginView*>::const_iterator it = m_pluginViews.begin(), end = m_pluginViews.end(); it != end; ++it)
447 (*it)->webPageDestroyed();
450 webPageCounter.decrement();
454 void WebPage::dummy(bool&)
458 CoreIPC::Connection* WebPage::connection() const
460 return WebProcess::shared().connection();
463 #if ENABLE(CONTEXT_MENUS)
464 void WebPage::initializeInjectedBundleContextMenuClient(WKBundlePageContextMenuClient* client)
466 m_contextMenuClient.initialize(client);
470 void WebPage::initializeInjectedBundleEditorClient(WKBundlePageEditorClient* client)
472 m_editorClient.initialize(client);
475 void WebPage::initializeInjectedBundleFormClient(WKBundlePageFormClient* client)
477 m_formClient.initialize(client);
480 void WebPage::initializeInjectedBundleLoaderClient(WKBundlePageLoaderClient* client)
482 m_loaderClient.initialize(client);
485 void WebPage::initializeInjectedBundlePolicyClient(WKBundlePagePolicyClient* client)
487 m_policyClient.initialize(client);
490 void WebPage::initializeInjectedBundleResourceLoadClient(WKBundlePageResourceLoadClient* client)
492 m_resourceLoadClient.initialize(client);
495 void WebPage::initializeInjectedBundleUIClient(WKBundlePageUIClient* client)
497 m_uiClient.initialize(client);
500 #if ENABLE(FULLSCREEN_API)
501 void WebPage::initializeInjectedBundleFullScreenClient(WKBundlePageFullScreenClient* client)
503 m_fullScreenClient.initialize(client);
507 void WebPage::initializeInjectedBundleDiagnosticLoggingClient(WKBundlePageDiagnosticLoggingClient* client)
509 m_logDiagnosticMessageClient.initialize(client);
512 PassRefPtr<Plugin> WebPage::createPlugin(WebFrame* frame, HTMLPlugInElement* pluginElement, const Plugin::Parameters& parameters)
515 bool blocked = false;
517 if (!WebProcess::shared().connection()->sendSync(
518 Messages::WebContext::GetPluginPath(parameters.mimeType, parameters.url.string()),
519 Messages::WebContext::GetPluginPath::Reply(pluginPath, blocked), 0)) {
524 if (pluginElement->renderer()->isEmbeddedObject())
525 toRenderEmbeddedObject(pluginElement->renderer())->setPluginUnavailabilityReason(RenderEmbeddedObject::InsecurePluginVersion);
527 send(Messages::WebPageProxy::DidBlockInsecurePluginVersion(parameters.mimeType, parameters.url.string()));
531 if (pluginPath.isNull()) {
533 if (parameters.mimeType == "application/pdf"
534 || (parameters.mimeType.isEmpty() && parameters.url.path().lower().endsWith(".pdf")))
535 return BuiltInPDFView::create(frame);
542 #if ENABLE(PLUGIN_PROCESS)
543 return PluginProxy::create(pluginPath);
544 #elif ENABLE(NETSCAPE_PLUGIN_API)
545 NetscapePlugin::setSetExceptionFunction(NPRuntimeObjectMap::setGlobalException);
546 return NetscapePlugin::create(NetscapePluginModule::getOrCreate(pluginPath));
552 EditorState WebPage::editorState() const
554 Frame* frame = m_page->focusController()->focusedOrMainFrame();
558 result.selectionIsNone = frame->selection()->isNone();
559 result.selectionIsRange = frame->selection()->isRange();
560 result.isContentEditable = frame->selection()->isContentEditable();
561 result.isContentRichlyEditable = frame->selection()->isContentRichlyEditable();
562 result.isInPasswordField = frame->selection()->isInPasswordField();
563 result.hasComposition = frame->editor()->hasComposition();
564 result.shouldIgnoreCompositionSelectionChange = frame->editor()->ignoreCompositionSelectionChange();
566 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
567 Element* selectionRoot = frame->selection()->rootEditableElement();
569 result.editorRect = frame->view()->contentsToWindow(selectionRoot->getPixelSnappedRect());
576 Element* selectionRoot = frame->selection()->rootEditableElement();
577 Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement();
582 if (scope->hasTagName(HTMLNames::inputTag)) {
583 HTMLInputElement* input = static_cast<HTMLInputElement*>(scope);
584 if (input->isTelephoneField())
585 result.inputMethodHints |= Qt::ImhDialableCharactersOnly;
586 else if (input->isNumberField())
587 result.inputMethodHints |= Qt::ImhDigitsOnly;
588 else if (input->isEmailField()) {
589 result.inputMethodHints |= Qt::ImhEmailCharactersOnly;
590 result.inputMethodHints |= Qt::ImhNoAutoUppercase;
591 } else if (input->isURLField()) {
592 result.inputMethodHints |= Qt::ImhUrlCharactersOnly;
593 result.inputMethodHints |= Qt::ImhNoAutoUppercase;
594 } else if (input->isPasswordField()) {
595 // Set ImhHiddenText flag for password fields. The Qt platform
596 // is responsible for determining which widget will receive input
597 // method events for password fields.
598 result.inputMethodHints |= Qt::ImhHiddenText;
599 result.inputMethodHints |= Qt::ImhNoAutoUppercase;
600 result.inputMethodHints |= Qt::ImhNoPredictiveText;
601 result.inputMethodHints |= Qt::ImhSensitiveData;
606 result.editorRect = frame->view()->contentsToWindow(selectionRoot->getPixelSnappedRect());
609 if (result.hasComposition && (range = frame->editor()->compositionRange())) {
610 frame->editor()->getCompositionSelection(result.anchorPosition, result.cursorPosition);
612 result.compositionRect = frame->view()->contentsToWindow(range->boundingBox());
615 if (!result.hasComposition && !result.selectionIsNone && (range = frame->selection()->selection().firstRange())) {
616 TextIterator::getLocationAndLengthFromRange(scope, range.get(), location, length);
617 bool baseIsFirst = frame->selection()->selection().isBaseFirst();
619 result.cursorPosition = (baseIsFirst) ? location + length : location;
620 result.anchorPosition = (baseIsFirst) ? location : location + length;
621 result.selectedText = range->text();
625 result.cursorRect = frame->view()->contentsToWindow(frame->editor()->firstRectForRange(range.get()));
627 // FIXME: We should only transfer innerText when it changes and do this on the UI side.
628 if (result.isContentEditable && !result.isInPasswordField) {
629 result.surroundingText = scope->innerText();
630 if (result.hasComposition) {
631 // The anchor is always the left position when they represent a composition.
632 result.surroundingText.remove(result.anchorPosition, result.cursorPosition - result.anchorPosition);
640 String WebPage::renderTreeExternalRepresentation() const
642 return externalRepresentation(m_mainFrame->coreFrame(), RenderAsTextBehaviorNormal);
645 uint64_t WebPage::renderTreeSize() const
649 return m_page->renderTreeSize().treeSize;
652 void WebPage::setPaintedObjectsCounterThreshold(uint64_t threshold)
656 m_page->setRelevantRepaintedObjectsCounterThreshold(threshold);
659 void WebPage::setTracksRepaints(bool trackRepaints)
661 if (FrameView* view = mainFrameView())
662 view->setTracksRepaints(trackRepaints);
665 bool WebPage::isTrackingRepaints() const
667 if (FrameView* view = mainFrameView())
668 return view->isTrackingRepaints();
673 void WebPage::resetTrackedRepaints()
675 if (FrameView* view = mainFrameView())
676 view->resetTrackedRepaints();
679 PassRefPtr<ImmutableArray> WebPage::trackedRepaintRects()
681 FrameView* view = mainFrameView();
683 return ImmutableArray::create();
685 const Vector<IntRect>& rects = view->trackedRepaintRects();
686 size_t size = rects.size();
688 return ImmutableArray::create();
690 Vector<RefPtr<APIObject> > vector;
691 vector.reserveInitialCapacity(size);
693 for (size_t i = 0; i < size; ++i)
694 vector.uncheckedAppend(WebRect::create(toAPI(rects[i])));
696 return ImmutableArray::adopt(vector);
699 void WebPage::executeEditingCommand(const String& commandName, const String& argument)
701 Frame* frame = m_page->focusController()->focusedOrMainFrame();
704 frame->editor()->command(commandName).execute(argument);
707 bool WebPage::isEditingCommandEnabled(const String& commandName)
709 Frame* frame = m_page->focusController()->focusedOrMainFrame();
713 Editor::Command command = frame->editor()->command(commandName);
714 return command.isSupported() && command.isEnabled();
717 void WebPage::clearMainFrameName()
719 if (Frame* frame = mainFrame())
720 frame->tree()->clearName();
723 #if USE(ACCELERATED_COMPOSITING)
724 void WebPage::enterAcceleratedCompositingMode(GraphicsLayer* layer)
726 m_drawingArea->setRootCompositingLayer(layer);
729 void WebPage::exitAcceleratedCompositingMode()
731 m_drawingArea->setRootCompositingLayer(0);
735 void WebPage::close()
742 if (pageGroup()->isVisibleToInjectedBundle() && WebProcess::shared().injectedBundle())
743 WebProcess::shared().injectedBundle()->willDestroyPage(this);
745 #if ENABLE(INSPECTOR)
748 #if ENABLE(FULLSCREEN_API)
749 m_fullScreenManager = 0;
752 if (m_activePopupMenu) {
753 m_activePopupMenu->disconnectFromPage();
754 m_activePopupMenu = 0;
757 if (m_activeOpenPanelResultListener) {
758 m_activeOpenPanelResultListener->disconnectFromPage();
759 m_activeOpenPanelResultListener = 0;
762 #if ENABLE(INPUT_TYPE_COLOR)
763 if (m_activeColorChooser) {
764 m_activeColorChooser->disconnectFromPage();
765 m_activeColorChooser = 0;
769 m_sandboxExtensionTracker.invalidate();
771 m_underlayPage = nullptr;
772 m_printContext = nullptr;
773 m_mainFrame->coreFrame()->loader()->detachFromParent();
775 m_drawingArea = nullptr;
777 bool isRunningModal = m_isRunningModal;
778 m_isRunningModal = false;
780 // The WebPage can be destroyed by this call.
781 WebProcess::shared().removeWebPage(m_pageID);
784 WebProcess::shared().runLoop()->stop();
787 void WebPage::tryClose()
789 SendStopResponsivenessTimer stopper(this);
791 if (!m_mainFrame->coreFrame()->loader()->shouldClose()) {
792 send(Messages::WebPageProxy::StopResponsivenessTimer());
796 send(Messages::WebPageProxy::ClosePage(true));
799 void WebPage::sendClose()
801 send(Messages::WebPageProxy::ClosePage(false));
804 void WebPage::loadURL(const String& url, const SandboxExtension::Handle& sandboxExtensionHandle)
806 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
807 recordingSurfaceSetEnableURL(url);
809 loadURLRequest(ResourceRequest(KURL(KURL(), url)), sandboxExtensionHandle);
812 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
813 void WebPage::recordingSurfaceSetEnableURL(const String& url)
815 if (m_recordingSurfaceSetSettings && strstr(url.utf8().data(), "bubblemark.com")) {
816 m_recordingSurfaceSetEnable = true;
817 m_page->m_recordingSurfaceSetEnable = true;
819 m_recordingSurfaceSetEnable = false;
820 m_page->m_recordingSurfaceSetEnable = false;
825 void WebPage::loadURLRequest(const ResourceRequest& request, const SandboxExtension::Handle& sandboxExtensionHandle)
827 SendStopResponsivenessTimer stopper(this);
829 m_sandboxExtensionTracker.beginLoad(m_mainFrame.get(), sandboxExtensionHandle);
830 m_mainFrame->coreFrame()->loader()->load(request, false);
833 void WebPage::loadData(PassRefPtr<SharedBuffer> sharedBuffer, const String& MIMEType, const String& encodingName, const KURL& baseURL, const KURL& unreachableURL)
835 SendStopResponsivenessTimer stopper(this);
837 ResourceRequest request(baseURL);
838 SubstituteData substituteData(sharedBuffer, MIMEType, encodingName, unreachableURL);
839 m_mainFrame->coreFrame()->loader()->load(request, substituteData, false);
842 void WebPage::loadHTMLString(const String& htmlString, const String& baseURLString)
844 #if ENABLE(TIZEN_LOAD_HTML_STRING_AS_UTF8)
845 CString html = htmlString.utf8();
846 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<const char*>(html.data()), html.length());
847 KURL baseURL = baseURLString.isEmpty() ? blankURL() : KURL(KURL(), baseURLString);
848 loadData(sharedBuffer, "text/html", "utf-8", baseURL, KURL());
850 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<const char*>(htmlString.characters()), htmlString.length() * sizeof(UChar));
851 KURL baseURL = baseURLString.isEmpty() ? blankURL() : KURL(KURL(), baseURLString);
852 loadData(sharedBuffer, "text/html", "utf-16", baseURL, KURL());
856 void WebPage::loadAlternateHTMLString(const String& htmlString, const String& baseURLString, const String& unreachableURLString)
858 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<const char*>(htmlString.characters()), htmlString.length() * sizeof(UChar));
859 KURL baseURL = baseURLString.isEmpty() ? blankURL() : KURL(KURL(), baseURLString);
860 KURL unreachableURL = unreachableURLString.isEmpty() ? KURL() : KURL(KURL(), unreachableURLString);
861 loadData(sharedBuffer, "text/html", "utf-16", baseURL, unreachableURL);
864 void WebPage::loadPlainTextString(const String& string)
866 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<const char*>(string.characters()), string.length() * sizeof(UChar));
867 loadData(sharedBuffer, "text/plain", "utf-16", blankURL(), KURL());
870 void WebPage::loadWebArchiveData(const CoreIPC::DataReference& webArchiveData)
872 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<const char*>(webArchiveData.data()), webArchiveData.size() * sizeof(uint8_t));
873 loadData(sharedBuffer, "application/x-webarchive", "utf-16", blankURL(), KURL());
877 void WebPage::loadContentsbyMimeType(const CoreIPC::DataReference& contents, const String& mimeType, const String& encoding, const String& baseURL)
879 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<const char*>(contents.data()), contents.size() * sizeof(uint8_t));
880 KURL baseKURL(WebCore::KURL(), baseURL);
881 loadData(sharedBuffer, mimeType, encoding, baseKURL, KURL());
885 void WebPage::linkClicked(const String& url, const WebMouseEvent& event)
887 Frame* frame = m_page->mainFrame();
891 RefPtr<Event> coreEvent;
892 if (event.type() != WebEvent::NoType)
893 coreEvent = MouseEvent::create(eventNames().clickEvent, frame->document()->defaultView(), platform(event), 0, 0);
895 frame->loader()->loadFrameRequest(FrameLoadRequest(frame->document()->securityOrigin(), ResourceRequest(url)),
896 false, false, coreEvent.get(), 0, MaybeSendReferrer);
899 void WebPage::stopLoadingFrame(uint64_t frameID)
901 WebFrame* frame = WebProcess::shared().webFrame(frameID);
905 frame->coreFrame()->loader()->stopForUserCancel();
908 void WebPage::stopLoading()
910 SendStopResponsivenessTimer stopper(this);
912 m_mainFrame->coreFrame()->loader()->stopForUserCancel();
915 void WebPage::setDefersLoading(bool defersLoading)
917 m_page->setDefersLoading(defersLoading);
920 void WebPage::reload(bool reloadFromOrigin, const SandboxExtension::Handle& sandboxExtensionHandle)
922 SendStopResponsivenessTimer stopper(this);
924 m_sandboxExtensionTracker.beginLoad(m_mainFrame.get(), sandboxExtensionHandle);
925 m_mainFrame->coreFrame()->loader()->reload(reloadFromOrigin);
928 void WebPage::goForward(uint64_t backForwardItemID)
930 SendStopResponsivenessTimer stopper(this);
932 HistoryItem* item = WebBackForwardListProxy::itemForID(backForwardItemID);
937 m_page->goToItem(item, FrameLoadTypeForward);
940 void WebPage::goBack(uint64_t backForwardItemID)
942 SendStopResponsivenessTimer stopper(this);
944 HistoryItem* item = WebBackForwardListProxy::itemForID(backForwardItemID);
949 m_page->goToItem(item, FrameLoadTypeBack);
952 void WebPage::goToBackForwardItem(uint64_t backForwardItemID)
954 SendStopResponsivenessTimer stopper(this);
956 HistoryItem* item = WebBackForwardListProxy::itemForID(backForwardItemID);
961 m_page->goToItem(item, FrameLoadTypeIndexedBackForward);
964 void WebPage::tryRestoreScrollPosition()
966 m_page->mainFrame()->loader()->history()->restoreScrollPositionAndViewState();
969 void WebPage::layoutIfNeeded()
971 if (m_mainFrame->coreFrame()->view())
972 m_mainFrame->coreFrame()->view()->updateLayoutAndStyleIfNeededRecursive();
974 if (m_underlayPage) {
975 if (FrameView *frameView = m_underlayPage->mainFrameView())
976 frameView->updateLayoutAndStyleIfNeededRecursive();
980 void WebPage::setSize(const WebCore::IntSize& viewSize)
982 FrameView* view = m_page->mainFrame()->view();
984 #if USE(TILED_BACKING_STORE)
985 // If we are resizing to content ignore external attempts.
986 if (view->useFixedLayout())
990 if (m_viewSize == viewSize)
993 view->resize(viewSize);
994 view->setNeedsLayout();
995 m_drawingArea->setNeedsDisplay(IntRect(IntPoint(0, 0), viewSize));
997 m_viewSize = viewSize;
1000 #if USE(TILED_BACKING_STORE)
1001 void WebPage::setFixedVisibleContentRect(const IntRect& rect)
1003 ASSERT(m_useFixedLayout);
1005 m_page->mainFrame()->view()->setFixedVisibleContentRect(rect);
1008 void WebPage::setResizesToContentsUsingLayoutSize(const IntSize& targetLayoutSize)
1010 ASSERT(m_useFixedLayout);
1011 ASSERT(!targetLayoutSize.isEmpty());
1013 FrameView* view = m_page->mainFrame()->view();
1015 view->setDelegatesScrolling(true);
1016 view->setUseFixedLayout(true);
1017 view->setPaintsEntireContents(true);
1019 if (view->fixedLayoutSize() == targetLayoutSize)
1022 m_page->settings()->setAcceleratedCompositingForFixedPositionEnabled(true);
1023 m_page->settings()->setFixedElementsLayoutRelativeToFrame(true);
1024 m_page->settings()->setFixedPositionCreatesStackingContext(true);
1026 // Always reset even when empty. This also takes care of the relayout.
1027 setFixedLayoutSize(targetLayoutSize);
1030 void WebPage::resizeToContentsIfNeeded()
1032 ASSERT(m_useFixedLayout);
1034 FrameView* view = m_page->mainFrame()->view();
1036 if (!view->useFixedLayout())
1039 IntSize newSize = view->contentsSize().expandedTo(view->fixedLayoutSize());
1041 if (newSize == m_viewSize)
1044 m_viewSize = newSize;
1045 view->resize(newSize);
1046 view->setNeedsLayout();
1049 void WebPage::sendViewportAttributesChanged()
1051 ASSERT(m_useFixedLayout);
1053 // Viewport properties have no impact on zero sized fixed viewports.
1054 if (m_viewportSize.isEmpty())
1057 // Recalculate the recommended layout size, when the available size (device pixel) changes.
1058 Settings* settings = m_page->settings();
1061 // As android and iphone does, we set layout width to 980 for desktop content
1062 int minimumLayoutFallbackWidth = settings->layoutFallbackWidth();
1064 int minimumLayoutFallbackWidth = std::max(settings->layoutFallbackWidth(), m_viewportSize.width());
1067 // If unset we use the viewport dimensions. This fits with the behavior of desktop browsers.
1068 int deviceWidth = (settings->deviceWidth() > 0) ? settings->deviceWidth() : m_viewportSize.width();
1069 int deviceHeight = (settings->deviceHeight() > 0) ? settings->deviceHeight() : m_viewportSize.height();
1071 ViewportAttributes attr = computeViewportAttributes(m_page->viewportArguments(), minimumLayoutFallbackWidth, deviceWidth, deviceHeight, m_page->deviceScaleFactor(), m_viewportSize);
1072 WebCore::restrictMinimumScaleFactorToViewportSize(attr, m_viewportSize);
1073 WebCore::restrictScaleFactorToInitialScaleIfNotUserScalable(attr);
1075 #if ENABLE(TIZEN_VIEWPORT_META_TAG)
1076 // On WebProcess, JS runs before visible content rect is updated by UIProcess
1077 // In this case, JS returns incorrect inner size value because scale factor is not updated yet
1078 // So, we update fixed visible content rect at here.
1079 // FIXME: scale factor needs to be calculated and set fixed visible content rect
1081 // if constrainsScrollingToContentEdge is true, scroll position will be adjusted with contents size.
1082 // disable this to avoid adjust scroll position on setFixedVisibleContentRect() because contents size is not fixed yet.
1083 bool constrainsScrollingToContentEdge = mainFrameView()->constrainsScrollingToContentEdge();
1084 mainFrameView()->setConstrainsScrollingToContentEdge(false);
1086 FloatSize contentFixedSize = m_viewportSize;
1087 contentFixedSize.scale(1 / (attr.initialScale * attr.devicePixelRatio));
1088 mainFrameView()->setFixedVisibleContentRect(IntRect(mainFrameView()->scrollPosition(), roundedIntSize(contentFixedSize)));
1090 // If viewport meta tag is not defined or initial scale factor is not defined,
1091 // initial scale factor can be defined by "Default View" setting of UIProcess.
1092 // Therefore we set initialScale as ValueAuto as WebKit opensource does, to handle it with setting on UIProcess.
1093 // You can find this implementation on WebKit bug.
1094 // https://bugs.webkit.org/show_bug.cgi?id=102392
1095 if (m_page->viewportArguments().type == ViewportArguments::Implicit
1096 || m_page->viewportArguments().initialScale == ViewportArguments::ValueAuto)
1097 attr.initialScale = ViewportArguments::ValueAuto;
1100 setResizesToContentsUsingLayoutSize(IntSize(static_cast<int>(attr.layoutSize.width()), static_cast<int>(attr.layoutSize.height())));
1102 #if ENABLE(TIZEN_VIEWPORT_META_TAG)
1103 // recover constrainsScrollingToContentEdge
1104 mainFrameView()->setConstrainsScrollingToContentEdge(constrainsScrollingToContentEdge);
1107 send(Messages::WebPageProxy::DidChangeViewportProperties(attr));
1110 void WebPage::setViewportSize(const IntSize& size)
1112 ASSERT(m_useFixedLayout);
1114 if (m_viewportSize == size)
1117 m_viewportSize = size;
1119 sendViewportAttributesChanged();
1124 void WebPage::scrollMainFrameIfNotAtMaxScrollPosition(const IntSize& scrollOffset)
1126 Frame* frame = m_page->mainFrame();
1128 IntPoint scrollPosition = frame->view()->scrollPosition();
1129 IntPoint maximumScrollPosition = frame->view()->maximumScrollPosition();
1131 // If the current scroll position in a direction is the max scroll position
1132 // we don't want to scroll at all.
1133 IntSize newScrollOffset;
1134 if (scrollPosition.x() < maximumScrollPosition.x())
1135 newScrollOffset.setWidth(scrollOffset.width());
1136 if (scrollPosition.y() < maximumScrollPosition.y())
1137 newScrollOffset.setHeight(scrollOffset.height());
1139 if (newScrollOffset.isZero())
1142 frame->view()->setScrollPosition(frame->view()->scrollPosition() + newScrollOffset);
1145 void WebPage::drawRect(GraphicsContext& graphicsContext, const IntRect& rect)
1147 GraphicsContextStateSaver stateSaver(graphicsContext);
1148 graphicsContext.clip(rect);
1150 if (m_underlayPage) {
1151 m_underlayPage->drawRect(graphicsContext, rect);
1153 graphicsContext.beginTransparencyLayer(1);
1154 m_mainFrame->coreFrame()->view()->paint(&graphicsContext, rect);
1155 graphicsContext.endTransparencyLayer();
1159 m_mainFrame->coreFrame()->view()->paint(&graphicsContext, rect);
1162 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
1163 void WebPage::selectLink(WebCore::IntPoint positionForSelection, bool& result)
1166 Frame* frame = m_page->focusController()->focusedOrMainFrame();
1170 FrameView* frameView = frame->view();
1174 HitTestResult hitTestResult = frame->eventHandler()->hitTestResultAtPoint(frameView->windowToContents(positionForSelection), false);
1176 RefPtr<Range> range;
1177 Element* URLElement = hitTestResult.URLElement();
1179 for (Node* childNode = URLElement->firstChild(); childNode; childNode = childNode->traverseNextNode(URLElement)) {
1180 RenderObject* r = childNode->renderer();
1181 if (r && (r->isText() || r->isImage())) {
1183 range = VisibleSelection::selectionFromContentsOfNode(childNode).toNormalizedRange();
1184 else if (!hitTestResult.image()) {
1185 RefPtr<Range> extendedRange = VisibleSelection::selectionFromContentsOfNode(childNode).toNormalizedRange();
1186 range->setEnd(childNode, extendedRange->endOffset());
1191 range = VisibleSelection::selectionFromContentsOfNode(URLElement).toNormalizedRange();
1193 range = VisibleSelection::selectionFromContentsOfNode(hitTestResult.innerNonSharedNode()).toNormalizedRange();
1195 WebCore::FrameSelection* frameSelection = frame->selection();
1196 if (!frameSelection)
1199 EAffinity affinity = frameSelection->affinity();
1200 frameSelection->setSelectedRange(range.get(), affinity, true);
1202 if (frameSelection->isRange())
1209 #if ENABLE(TIZEN_ORIENTATION_EVENTS)
1210 void WebPage::sendOrientationChangeEvent(int newOrientation)
1212 Frame* frame = m_mainFrame->coreFrame();
1213 if (!frame || frame->orientation() == newOrientation)
1216 frame->sendOrientationChangeEvent(newOrientation);
1217 for (WebCore::Frame* child = frame->tree()->firstChild(); child; child = child->tree()->nextSibling())
1218 child->sendOrientationChangeEvent(newOrientation);
1222 void WebPage::drawPageOverlay(GraphicsContext& graphicsContext, const IntRect& rect)
1224 ASSERT(m_pageOverlay);
1226 GraphicsContextStateSaver stateSaver(graphicsContext);
1227 graphicsContext.clip(rect);
1228 m_pageOverlay->drawRect(graphicsContext, rect);
1231 double WebPage::textZoomFactor() const
1233 Frame* frame = m_mainFrame->coreFrame();
1236 return frame->textZoomFactor();
1239 void WebPage::setTextZoomFactor(double zoomFactor)
1241 Frame* frame = m_mainFrame->coreFrame();
1244 frame->setTextZoomFactor(static_cast<float>(zoomFactor));
1247 double WebPage::pageZoomFactor() const
1249 Frame* frame = m_mainFrame->coreFrame();
1252 return frame->pageZoomFactor();
1255 void WebPage::setPageZoomFactor(double zoomFactor)
1257 Frame* frame = m_mainFrame->coreFrame();
1260 frame->setPageZoomFactor(static_cast<float>(zoomFactor));
1263 void WebPage::setPageAndTextZoomFactors(double pageZoomFactor, double textZoomFactor)
1265 Frame* frame = m_mainFrame->coreFrame();
1268 return frame->setPageAndTextZoomFactors(static_cast<float>(pageZoomFactor), static_cast<float>(textZoomFactor));
1271 void WebPage::windowScreenDidChange(uint64_t displayID)
1273 m_page->windowScreenDidChange(static_cast<PlatformDisplayID>(displayID));
1276 void WebPage::setViewMode(Page::ViewMode mode)
1278 m_page->setViewMode(mode);
1281 void WebPage::scalePage(double scale, const IntPoint& origin)
1283 m_page->setPageScaleFactor(scale, origin);
1285 for (HashSet<PluginView*>::const_iterator it = m_pluginViews.begin(), end = m_pluginViews.end(); it != end; ++it)
1286 (*it)->pageScaleFactorDidChange();
1288 send(Messages::WebPageProxy::PageScaleFactorDidChange(scale));
1291 double WebPage::pageScaleFactor() const
1293 return m_page->pageScaleFactor();
1296 void WebPage::setDeviceScaleFactor(float scaleFactor)
1298 if (scaleFactor == m_page->deviceScaleFactor())
1301 m_page->setDeviceScaleFactor(scaleFactor);
1303 // Tell all our plug-in views that the device scale factor changed.
1305 for (HashSet<PluginView*>::const_iterator it = m_pluginViews.begin(), end = m_pluginViews.end(); it != end; ++it)
1306 (*it)->setDeviceScaleFactor(scaleFactor);
1309 if (m_findController.isShowingOverlay()) {
1310 // We must have updated layout to get the selection rects right.
1312 m_findController.deviceScaleFactorDidChange();
1316 float WebPage::deviceScaleFactor() const
1318 return m_page->deviceScaleFactor();
1321 void WebPage::setUseFixedLayout(bool fixed)
1323 m_useFixedLayout = fixed;
1325 FrameView* view = mainFrameView();
1329 view->setUseFixedLayout(fixed);
1331 setFixedLayoutSize(IntSize());
1334 void WebPage::setFixedLayoutSize(const IntSize& size)
1336 FrameView* view = mainFrameView();
1337 if (!view || view->fixedLayoutSize() == size)
1340 view->setFixedLayoutSize(size);
1341 // Do not force it until the first layout, this would then become our first layout prematurely.
1342 if (view->didFirstLayout())
1343 view->forceLayout();
1346 void WebPage::setPaginationMode(uint32_t mode)
1348 Page::Pagination pagination = m_page->pagination();
1349 pagination.mode = static_cast<Page::Pagination::Mode>(mode);
1350 m_page->setPagination(pagination);
1353 void WebPage::setPaginationBehavesLikeColumns(bool behavesLikeColumns)
1355 Page::Pagination pagination = m_page->pagination();
1356 pagination.behavesLikeColumns = behavesLikeColumns;
1357 m_page->setPagination(pagination);
1360 void WebPage::setPageLength(double pageLength)
1362 Page::Pagination pagination = m_page->pagination();
1363 pagination.pageLength = pageLength;
1364 m_page->setPagination(pagination);
1367 void WebPage::setGapBetweenPages(double gap)
1369 Page::Pagination pagination = m_page->pagination();
1370 pagination.gap = gap;
1371 m_page->setPagination(pagination);
1374 void WebPage::installPageOverlay(PassRefPtr<PageOverlay> pageOverlay)
1376 bool shouldFadeIn = true;
1378 if (m_pageOverlay) {
1379 m_pageOverlay->setPage(0);
1382 // We're installing a page overlay when a page overlay is already active.
1383 // In this case we don't want to fade in the new overlay.
1384 shouldFadeIn = false;
1388 m_pageOverlay = pageOverlay;
1389 m_pageOverlay->setPage(this);
1392 m_pageOverlay->startFadeInAnimation();
1394 m_drawingArea->didInstallPageOverlay();
1396 send(Messages::WebPageProxy::DidInstallOrUninstallPageOverlay(true));
1399 m_pageOverlay->setNeedsDisplay();
1402 void WebPage::uninstallPageOverlay(PageOverlay* pageOverlay, bool fadeOut)
1404 if (pageOverlay != m_pageOverlay)
1408 m_pageOverlay->startFadeOutAnimation();
1412 m_pageOverlay->setPage(0);
1413 m_pageOverlay = nullptr;
1415 m_drawingArea->didUninstallPageOverlay();
1417 send(Messages::WebPageProxy::DidInstallOrUninstallPageOverlay(false));
1421 #if PLATFORM(EFL) && OS(TIZEN)
1422 PassRefPtr<WebImage> WebPage::scaledSnapshotInViewCoordinates(const IntRect& rect, double scaleFactor, ImageOptions options)
1424 FrameView* frameView = m_mainFrame->coreFrame()->view();
1428 IntSize size(ceil(rect.width() * scaleFactor), ceil(rect.height() * scaleFactor));
1429 RefPtr<WebImage> snapshot = WebImage::create(size, options);
1430 if (!snapshot->bitmap())
1433 OwnPtr<WebCore::GraphicsContext> graphicsContext = snapshot->bitmap()->createGraphicsContext();
1434 graphicsContext->scale(FloatSize(scaleFactor, scaleFactor));
1435 graphicsContext->translate(-rect.x(), -rect.y());
1437 frameView->updateLayoutAndStyleIfNeededRecursive();
1439 PaintBehavior oldBehavior = frameView->paintBehavior();
1440 frameView->setPaintBehavior(oldBehavior | PaintBehaviorFlattenCompositingLayers);
1441 frameView->paint(graphicsContext.get(), rect);
1442 frameView->setPaintBehavior(oldBehavior);
1444 return snapshot.release();
1447 PassRefPtr<WebImage> WebPage::snapshotInViewCoordinates(const IntRect& rect, ImageOptions options)
1449 return scaledSnapshotInViewCoordinates(rect, 1, options);
1452 PassRefPtr<WebImage> WebPage::snapshotInViewCoordinates(const IntRect& rect, ImageOptions options)
1454 FrameView* frameView = m_mainFrame->coreFrame()->view();
1458 IntSize bitmapSize = rect.size();
1459 float deviceScaleFactor = corePage()->deviceScaleFactor();
1460 bitmapSize.scale(deviceScaleFactor);
1462 RefPtr<WebImage> snapshot = WebImage::create(bitmapSize, options);
1463 if (!snapshot->bitmap())
1466 OwnPtr<WebCore::GraphicsContext> graphicsContext = snapshot->bitmap()->createGraphicsContext();
1467 graphicsContext->applyDeviceScaleFactor(deviceScaleFactor);
1468 graphicsContext->translate(-rect.x(), -rect.y());
1470 frameView->updateLayoutAndStyleIfNeededRecursive();
1472 PaintBehavior oldBehavior = frameView->paintBehavior();
1473 frameView->setPaintBehavior(oldBehavior | PaintBehaviorFlattenCompositingLayers);
1474 frameView->paint(graphicsContext.get(), rect);
1475 frameView->setPaintBehavior(oldBehavior);
1477 return snapshot.release();
1481 PassRefPtr<WebImage> WebPage::scaledSnapshotInDocumentCoordinates(const IntRect& rect, double scaleFactor, ImageOptions options)
1483 FrameView* frameView = m_mainFrame->coreFrame()->view();
1487 float combinedScaleFactor = scaleFactor * corePage()->deviceScaleFactor();
1488 IntSize size(ceil(rect.width() * combinedScaleFactor), ceil(rect.height() * combinedScaleFactor));
1489 RefPtr<WebImage> snapshot = WebImage::create(size, options);
1490 if (!snapshot->bitmap())
1493 OwnPtr<WebCore::GraphicsContext> graphicsContext = snapshot->bitmap()->createGraphicsContext();
1494 graphicsContext->applyDeviceScaleFactor(combinedScaleFactor);
1495 graphicsContext->translate(-rect.x(), -rect.y());
1497 frameView->updateLayoutAndStyleIfNeededRecursive();
1499 PaintBehavior oldBehavior = frameView->paintBehavior();
1500 frameView->setPaintBehavior(oldBehavior | PaintBehaviorFlattenCompositingLayers);
1501 frameView->paintContents(graphicsContext.get(), rect);
1502 frameView->setPaintBehavior(oldBehavior);
1504 return snapshot.release();
1507 PassRefPtr<WebImage> WebPage::snapshotInDocumentCoordinates(const IntRect& rect, ImageOptions options)
1509 return scaledSnapshotInDocumentCoordinates(rect, 1, options);
1512 void WebPage::pageDidScroll()
1514 m_uiClient.pageDidScroll(this);
1516 send(Messages::WebPageProxy::PageDidScroll());
1519 #if USE(TILED_BACKING_STORE)
1520 void WebPage::pageDidRequestScroll(const IntPoint& point)
1522 send(Messages::WebPageProxy::PageDidRequestScroll(point));
1526 #if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
1527 void WebPage::pageDidRequestRestoreVisibleContentRect(const IntPoint& point, float scale)
1529 send(Messages::WebPageProxy::pageDidRequestRestoreVisibleContentRect(point, scale));
1533 #if ENABLE(CONTEXT_MENUS)
1534 WebContextMenu* WebPage::contextMenu()
1537 m_contextMenu = WebContextMenu::create(this);
1538 return m_contextMenu.get();
1544 static const WebEvent* g_currentEvent = 0;
1546 // FIXME: WebPage::currentEvent is used by the plug-in code to avoid having to convert from DOM events back to
1547 // WebEvents. When we get the event handling sorted out, this should go away and the Widgets should get the correct
1548 // platform events passed to the event handler code.
1549 const WebEvent* WebPage::currentEvent()
1551 return g_currentEvent;
1554 class CurrentEvent {
1556 explicit CurrentEvent(const WebEvent& event)
1557 : m_previousCurrentEvent(g_currentEvent)
1559 g_currentEvent = &event;
1564 g_currentEvent = m_previousCurrentEvent;
1568 const WebEvent* m_previousCurrentEvent;
1571 #if ENABLE(CONTEXT_MENUS)
1572 static bool isContextClick(const PlatformMouseEvent& event)
1574 if (event.button() == WebCore::RightButton)
1578 // FIXME: this really should be about OSX-style UI, not about the Mac port
1579 if (event.button() == WebCore::LeftButton && event.ctrlKey())
1586 static bool handleContextMenuEvent(const PlatformMouseEvent& platformMouseEvent, WebPage* page)
1588 IntPoint point = page->corePage()->mainFrame()->view()->windowToContents(platformMouseEvent.position());
1589 HitTestResult result = page->corePage()->mainFrame()->eventHandler()->hitTestResultAtPoint(point, false);
1591 Frame* frame = page->corePage()->mainFrame();
1592 #if !ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
1593 if (result.innerNonSharedNode())
1594 frame = result.innerNonSharedNode()->document()->frame();
1597 bool handled = frame->eventHandler()->sendContextMenuEvent(platformMouseEvent);
1599 page->contextMenu()->show();
1601 #if ENABLE(TIZEN_DRAG_SUPPORT)
1602 if(result.isDragSupport()) {
1603 if (result.innerNonSharedNode())
1604 frame = result.innerNonSharedNode()->document()->frame();
1606 PlatformMouseEvent event(frame->view()->windowToContents(platformMouseEvent.position()), platformMouseEvent.globalPosition(), LeftButton, PlatformEvent::MousePressed, 1, false, false, false, false, currentTime());
1607 frame->page()->dragController()->setPosition(event);
1615 static bool handleMouseEvent(const WebMouseEvent& mouseEvent, WebPage* page, bool onlyUpdateScrollbars)
1617 Frame* frame = page->corePage()->mainFrame();
1621 PlatformMouseEvent platformMouseEvent = platform(mouseEvent);
1623 switch (platformMouseEvent.type()) {
1624 case PlatformEvent::MousePressed: {
1625 #if ENABLE(CONTEXT_MENUS)
1626 if (isContextClick(platformMouseEvent))
1627 page->corePage()->contextMenuController()->clearContextMenu();
1630 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
1632 if (!isContextClick(platformMouseEvent))
1633 handled = frame->eventHandler()->handleMousePressEvent(platformMouseEvent);
1635 bool handled = frame->eventHandler()->handleMousePressEvent(platformMouseEvent);
1637 #if ENABLE(CONTEXT_MENUS)
1638 if (isContextClick(platformMouseEvent))
1639 handled = handleContextMenuEvent(platformMouseEvent, page);
1642 bool gtkMouseButtonPressHandled = page->handleMousePressedEvent(platformMouseEvent);
1643 handled = handled || gtkMouseButtonPressHandled;
1648 case PlatformEvent::MouseReleased:
1649 return frame->eventHandler()->handleMouseReleaseEvent(platformMouseEvent);
1650 case PlatformEvent::MouseMoved:
1651 if (onlyUpdateScrollbars)
1652 return frame->eventHandler()->passMouseMovedEventToScrollbars(platformMouseEvent);
1653 return frame->eventHandler()->mouseMoved(platformMouseEvent);
1655 ASSERT_NOT_REACHED();
1660 void WebPage::mouseEvent(const WebMouseEvent& mouseEvent)
1662 #if ENABLE(CONTEXT_MENUS)
1663 // Don't try to handle any pending mouse events if a context menu is showing.
1664 if (m_isShowingContextMenu) {
1665 send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(mouseEvent.type()), false));
1670 bool handled = false;
1672 if (m_pageOverlay) {
1673 // Let the page overlay handle the event.
1674 handled = m_pageOverlay->mouseEvent(mouseEvent);
1678 CurrentEvent currentEvent(mouseEvent);
1680 // We need to do a full, normal hit test during this mouse event if the page is active or if a mouse
1681 // button is currently pressed. It is possible that neither of those things will be true since on
1682 // Lion when legacy scrollbars are enabled, WebKit receives mouse events all the time. If it is one
1683 // of those cases where the page is not active and the mouse is not pressed, then we can fire a more
1684 // efficient scrollbars-only version of the event.
1685 bool onlyUpdateScrollbars = !(m_page->focusController()->isActive() || (mouseEvent.button() != WebMouseEvent::NoButton));
1686 handled = handleMouseEvent(mouseEvent, this, onlyUpdateScrollbars);
1689 send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(mouseEvent.type()), handled));
1692 void WebPage::mouseEventSyncForTesting(const WebMouseEvent& mouseEvent, bool& handled)
1694 handled = m_pageOverlay && m_pageOverlay->mouseEvent(mouseEvent);
1697 CurrentEvent currentEvent(mouseEvent);
1699 // We need to do a full, normal hit test during this mouse event if the page is active or if a mouse
1700 // button is currently pressed. It is possible that neither of those things will be true since on
1701 // Lion when legacy scrollbars are enabled, WebKit receives mouse events all the time. If it is one
1702 // of those cases where the page is not active and the mouse is not pressed, then we can fire a more
1703 // efficient scrollbars-only version of the event.
1704 bool onlyUpdateScrollbars = !(m_page->focusController()->isActive() || (mouseEvent.button() != WebMouseEvent::NoButton));
1705 handled = handleMouseEvent(mouseEvent, this, onlyUpdateScrollbars);
1709 static bool handleWheelEvent(const WebWheelEvent& wheelEvent, Page* page)
1711 Frame* frame = page->mainFrame();
1715 PlatformWheelEvent platformWheelEvent = platform(wheelEvent);
1716 return frame->eventHandler()->handleWheelEvent(platformWheelEvent);
1719 void WebPage::wheelEvent(const WebWheelEvent& wheelEvent)
1721 CurrentEvent currentEvent(wheelEvent);
1723 bool handled = handleWheelEvent(wheelEvent, m_page.get());
1724 send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(wheelEvent.type()), handled));
1727 void WebPage::wheelEventSyncForTesting(const WebWheelEvent& wheelEvent, bool& handled)
1729 CurrentEvent currentEvent(wheelEvent);
1731 handled = handleWheelEvent(wheelEvent, m_page.get());
1734 static bool handleKeyEvent(const WebKeyboardEvent& keyboardEvent, Page* page)
1736 if (!page->mainFrame()->view())
1739 if (keyboardEvent.type() == WebEvent::Char && keyboardEvent.isSystemKey())
1740 return page->focusController()->focusedOrMainFrame()->eventHandler()->handleAccessKey(platform(keyboardEvent));
1741 return page->focusController()->focusedOrMainFrame()->eventHandler()->keyEvent(platform(keyboardEvent));
1744 #if ENABLE(TIZEN_ISF_PORT)
1745 void WebPage::keyEvent(const NativeWebKeyboardEvent& keyboardEvent)
1747 void WebPage::keyEvent(const WebKeyboardEvent& keyboardEvent)
1750 CurrentEvent currentEvent(keyboardEvent);
1752 bool handled = handleKeyEvent(keyboardEvent, m_page.get());
1753 // FIXME: Platform default behaviors should be performed during normal DOM event dispatch (in most cases, in default keydown event handler).
1755 handled = performDefaultBehaviorForKeyEvent(keyboardEvent);
1757 send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(keyboardEvent.type()), handled));
1760 void WebPage::keyEventSyncForTesting(const WebKeyboardEvent& keyboardEvent, bool& handled)
1762 CurrentEvent currentEvent(keyboardEvent);
1764 handled = handleKeyEvent(keyboardEvent, m_page.get());
1766 handled = performDefaultBehaviorForKeyEvent(keyboardEvent);
1769 #if ENABLE(GESTURE_EVENTS)
1770 static bool handleGestureEvent(const WebGestureEvent& gestureEvent, Page* page)
1772 Frame* frame = page->mainFrame();
1776 PlatformGestureEvent platformGestureEvent = platform(gestureEvent);
1777 return frame->eventHandler()->handleGestureEvent(platformGestureEvent);
1780 void WebPage::gestureEvent(const WebGestureEvent& gestureEvent)
1782 CurrentEvent currentEvent(gestureEvent);
1784 bool handled = handleGestureEvent(gestureEvent, m_page.get());
1785 send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(gestureEvent.type()), handled));
1789 void WebPage::validateCommand(const String& commandName, uint64_t callbackID)
1791 bool isEnabled = false;
1793 Frame* frame = m_page->focusController()->focusedOrMainFrame();
1795 Editor::Command command = frame->editor()->command(commandName);
1796 state = command.state();
1797 isEnabled = command.isSupported() && command.isEnabled();
1800 send(Messages::WebPageProxy::ValidateCommandCallback(commandName, isEnabled, state, callbackID));
1803 void WebPage::executeEditCommand(const String& commandName)
1805 executeEditingCommand(commandName, String());
1808 uint64_t WebPage::restoreSession(const SessionState& sessionState)
1810 const BackForwardListItemVector& list = sessionState.list();
1811 size_t size = list.size();
1812 uint64_t currentItemID = 0;
1813 for (size_t i = 0; i < size; ++i) {
1814 WebBackForwardListItem* webItem = list[i].get();
1815 DecoderAdapter decoder(webItem->backForwardData().data(), webItem->backForwardData().size());
1817 RefPtr<HistoryItem> item = HistoryItem::decodeBackForwardTree(webItem->url(), webItem->title(), webItem->originalURL(), decoder);
1819 LOG_ERROR("Failed to decode a HistoryItem from session state data.");
1823 if (i == sessionState.currentIndex())
1824 currentItemID = webItem->itemID();
1826 WebBackForwardListProxy::addItemFromUIProcess(list[i]->itemID(), item.release());
1828 ASSERT(currentItemID);
1829 return currentItemID;
1832 void WebPage::restoreSessionAndNavigateToCurrentItem(const SessionState& sessionState)
1834 if (uint64_t currentItemID = restoreSession(sessionState))
1835 goToBackForwardItem(currentItemID);
1838 #if ENABLE(TOUCH_EVENTS)
1840 void WebPage::highlightPotentialActivation(const IntPoint& point, const IntSize& area)
1842 if (point == IntPoint::zero()) {
1843 // An empty point deactivates the highlighting.
1844 tapHighlightController().hideHighlight();
1846 Frame* mainframe = m_page->mainFrame();
1847 Node* activationNode = 0;
1848 Node* adjustedNode = 0;
1849 IntPoint adjustedPoint;
1851 #if ENABLE(TOUCH_ADJUSTMENT)
1852 if (!mainframe->eventHandler()->bestClickableNodeForTouchPoint(point, IntSize(area.width() / 2, area.height() / 2), adjustedPoint, adjustedNode))
1856 HitTestResult result = mainframe->eventHandler()->hitTestResultAtPoint(mainframe->view()->windowToContents(point), /*allowShadowContent*/ false, /*ignoreClipping*/ true);
1857 adjustedNode = result.innerNode();
1859 // Find the node to highlight. This is not the same as the node responding the tap gesture, because many
1860 // pages has a global click handler and we do not want to highlight the body.
1861 // Instead find the enclosing link or focusable element, or the last enclosing inline element.
1862 for (Node* node = adjustedNode; node; node = node->parentOrHostNode()) {
1863 if (node->isMouseFocusable() || node->isLink()) {
1864 activationNode = node;
1867 if (node->renderer() && node->renderer()->isInline())
1868 activationNode = node;
1869 else if (activationNode)
1874 tapHighlightController().highlight(activationNode);
1879 static bool handleTouchEvent(const WebTouchEvent& touchEvent, Page* page)
1881 Frame* frame = page->mainFrame();
1885 return frame->eventHandler()->handleTouchEvent(platform(touchEvent));
1888 void WebPage::touchEvent(const WebTouchEvent& touchEvent)
1890 CurrentEvent currentEvent(touchEvent);
1892 bool handled = handleTouchEvent(touchEvent, m_page.get());
1894 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
1895 static bool checkOverflow = false;
1896 if (touchEvent.type() == WebEvent::TouchStart && touchEvent.touchPoints().size() == 1) {
1897 checkOverflow = true;
1898 } else if (checkOverflow && touchEvent.type() == WebEvent::TouchMove && touchEvent.touchPoints().size() == 1) {
1899 bool pressed = false;
1901 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
1902 setPressedNodeAtPoint(touchEvent.touchPoints()[0].position(), true, pressed, id);
1904 setPressedNodeAtPoint(touchEvent.touchPoints()[0].position(), false, pressed, id);
1906 send(Messages::WebPageProxy::SetOverflowResult(pressed, id));
1907 checkOverflow = false;
1910 send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(touchEvent.type()), handled));
1913 void WebPage::touchEventSyncForTesting(const WebTouchEvent& touchEvent, bool& handled)
1915 CurrentEvent currentEvent(touchEvent);
1916 handled = handleTouchEvent(touchEvent, m_page.get());
1920 void WebPage::scroll(Page* page, ScrollDirection direction, ScrollGranularity granularity)
1922 page->focusController()->focusedOrMainFrame()->eventHandler()->scrollRecursively(direction, granularity);
1925 void WebPage::logicalScroll(Page* page, ScrollLogicalDirection direction, ScrollGranularity granularity)
1927 page->focusController()->focusedOrMainFrame()->eventHandler()->logicalScrollRecursively(direction, granularity);
1930 void WebPage::scrollBy(uint32_t scrollDirection, uint32_t scrollGranularity)
1932 scroll(m_page.get(), static_cast<ScrollDirection>(scrollDirection), static_cast<ScrollGranularity>(scrollGranularity));
1935 void WebPage::centerSelectionInVisibleArea()
1937 Frame* frame = m_page->focusController()->focusedOrMainFrame();
1941 frame->selection()->revealSelection(ScrollAlignment::alignCenterAlways);
1942 m_findController.showFindIndicatorInSelection();
1945 void WebPage::setActive(bool isActive)
1947 m_page->focusController()->setActive(isActive);
1950 // Tell all our plug-in views that the window focus changed.
1951 for (HashSet<PluginView*>::const_iterator it = m_pluginViews.begin(), end = m_pluginViews.end(); it != end; ++it)
1952 (*it)->setWindowIsFocused(isActive);
1956 void WebPage::setDrawsBackground(bool drawsBackground)
1958 if (m_drawsBackground == drawsBackground)
1961 m_drawsBackground = drawsBackground;
1963 for (Frame* coreFrame = m_mainFrame->coreFrame(); coreFrame; coreFrame = coreFrame->tree()->traverseNext()) {
1964 if (FrameView* view = coreFrame->view())
1965 view->setTransparent(!drawsBackground);
1968 m_drawingArea->pageBackgroundTransparencyChanged();
1969 m_drawingArea->setNeedsDisplay(IntRect(IntPoint(0, 0), m_viewSize));
1972 void WebPage::setDrawsTransparentBackground(bool drawsTransparentBackground)
1974 if (m_drawsTransparentBackground == drawsTransparentBackground)
1977 m_drawsTransparentBackground = drawsTransparentBackground;
1979 Color backgroundColor = drawsTransparentBackground ? Color::transparent : Color::white;
1980 for (Frame* coreFrame = m_mainFrame->coreFrame(); coreFrame; coreFrame = coreFrame->tree()->traverseNext()) {
1981 if (FrameView* view = coreFrame->view())
1982 view->setBaseBackgroundColor(backgroundColor);
1985 m_drawingArea->pageBackgroundTransparencyChanged();
1986 m_drawingArea->setNeedsDisplay(IntRect(IntPoint(0, 0), m_viewSize));
1989 void WebPage::viewWillStartLiveResize()
1994 // FIXME: This should propagate to all ScrollableAreas.
1995 if (Frame* frame = m_page->focusController()->focusedOrMainFrame()) {
1996 if (FrameView* view = frame->view())
1997 view->willStartLiveResize();
2001 void WebPage::viewWillEndLiveResize()
2006 // FIXME: This should propagate to all ScrollableAreas.
2007 if (Frame* frame = m_page->focusController()->focusedOrMainFrame()) {
2008 if (FrameView* view = frame->view())
2009 view->willEndLiveResize();
2013 void WebPage::setFocused(bool isFocused)
2015 m_page->focusController()->setFocused(isFocused);
2018 void WebPage::setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent& event)
2020 if (!m_page || !m_page->focusController())
2023 Frame* frame = m_page->focusController()->focusedOrMainFrame();
2024 frame->document()->setFocusedNode(0);
2026 if (isKeyboardEventValid && event.type() == WebEvent::KeyDown) {
2027 PlatformKeyboardEvent platformEvent(platform(event));
2028 platformEvent.disambiguateKeyDownEvent(PlatformEvent::RawKeyDown);
2029 m_page->focusController()->setInitialFocus(forward ? FocusDirectionForward : FocusDirectionBackward, KeyboardEvent::create(platformEvent, frame->document()->defaultView()).get());
2033 m_page->focusController()->setInitialFocus(forward ? FocusDirectionForward : FocusDirectionBackward, 0);
2036 void WebPage::setWindowResizerSize(const IntSize& windowResizerSize)
2038 if (m_windowResizerSize == windowResizerSize)
2041 m_windowResizerSize = windowResizerSize;
2043 for (Frame* coreFrame = m_mainFrame->coreFrame(); coreFrame; coreFrame = coreFrame->tree()->traverseNext()) {
2044 FrameView* view = coreFrame->view();
2046 view->windowResizerRectChanged();
2050 void WebPage::setCanStartMediaTimerFired()
2053 m_page->setCanStartMedia(true);
2056 void WebPage::setIsInWindow(bool isInWindow)
2059 m_setCanStartMediaTimer.stop();
2060 m_page->setCanStartMedia(false);
2061 m_page->willMoveOffscreen();
2063 // Defer the call to Page::setCanStartMedia() since it ends up sending a syncrhonous messages to the UI process
2064 // in order to get plug-in connections, and the UI process will be waiting for the Web process to update the backing
2065 // store after moving the view into a window, until it times out and paints white. See <rdar://problem/9242771>.
2066 m_setCanStartMediaTimer.startOneShot(0);
2067 m_page->didMoveOnscreen();
2071 void WebPage::didReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, uint32_t policyAction, uint64_t downloadID)
2073 WebFrame* frame = WebProcess::shared().webFrame(frameID);
2076 frame->didReceivePolicyDecision(listenerID, static_cast<PolicyAction>(policyAction), downloadID);
2079 void WebPage::show()
2081 send(Messages::WebPageProxy::ShowPage());
2084 void WebPage::setUserAgent(const String& userAgent)
2086 m_userAgent = userAgent;
2088 #if ENABLE(TIZEN_CUSTOM_HEADERS)
2089 void WebPage::addCustomHeader(const String& name, const String& value)
2091 m_customHeaders.add(name, value);
2094 void WebPage::removeCustomHeader(const String& name)
2096 m_customHeaders.remove(name);
2099 void WebPage::clearCustomHeaders()
2101 m_customHeaders.clear();
2104 WebCore::HTTPHeaderMap WebPage::customHeaders()
2106 return m_customHeaders;
2110 void WebPage::suspendActiveDOMObjectsAndAnimations()
2112 m_page->suspendActiveDOMObjectsAndAnimations();
2115 void WebPage::resumeActiveDOMObjectsAndAnimations()
2117 m_page->resumeActiveDOMObjectsAndAnimations();
2119 // We need to repaint on resume to kickstart animated painting again.
2120 m_drawingArea->setNeedsDisplay(IntRect(IntPoint(0, 0), m_viewSize));
2123 IntPoint WebPage::screenToWindow(const IntPoint& point)
2125 IntPoint windowPoint;
2126 sendSync(Messages::WebPageProxy::ScreenToWindow(point), Messages::WebPageProxy::ScreenToWindow::Reply(windowPoint));
2130 IntRect WebPage::windowToScreen(const IntRect& rect)
2133 sendSync(Messages::WebPageProxy::WindowToScreen(rect), Messages::WebPageProxy::WindowToScreen::Reply(screenRect));
2137 IntRect WebPage::windowResizerRect() const
2139 if (m_windowResizerSize.isEmpty())
2142 IntSize frameViewSize;
2143 if (Frame* coreFrame = m_mainFrame->coreFrame()) {
2144 if (FrameView* view = coreFrame->view())
2145 frameViewSize = view->size();
2148 return IntRect(frameViewSize.width() - m_windowResizerSize.width(), frameViewSize.height() - m_windowResizerSize.height(),
2149 m_windowResizerSize.width(), m_windowResizerSize.height());
2152 KeyboardUIMode WebPage::keyboardUIMode()
2154 bool fullKeyboardAccessEnabled = WebProcess::shared().fullKeyboardAccessEnabled();
2155 return static_cast<KeyboardUIMode>((fullKeyboardAccessEnabled ? KeyboardAccessFull : KeyboardAccessDefault) | (m_tabToLinks ? KeyboardAccessTabsToLinks : 0));
2158 void WebPage::runJavaScriptInMainFrame(const String& script, uint64_t callbackID)
2160 // NOTE: We need to be careful when running scripts that the objects we depend on don't
2161 // disappear during script execution.
2163 // Retain the SerializedScriptValue at this level so it (and the internal data) lives
2164 // long enough for the DataReference to be encoded by the sent message.
2165 RefPtr<SerializedScriptValue> serializedResultValue;
2166 CoreIPC::DataReference dataReference;
2168 JSLockHolder lock(JSDOMWindow::commonJSGlobalData());
2169 if (JSValue resultValue = m_mainFrame->coreFrame()->script()->executeScript(script, true).jsValue()) {
2170 if ((serializedResultValue = SerializedScriptValue::create(m_mainFrame->jsContext(), toRef(m_mainFrame->coreFrame()->script()->globalObject(mainThreadNormalWorld())->globalExec(), resultValue), 0)))
2171 dataReference = serializedResultValue->data();
2174 send(Messages::WebPageProxy::ScriptValueCallback(dataReference, callbackID));
2177 void WebPage::getContentsAsString(uint64_t callbackID)
2179 String resultString = m_mainFrame->contentsAsString();
2180 send(Messages::WebPageProxy::StringCallback(resultString, callbackID));
2184 void WebPage::getContentsAsMHTMLData(uint64_t callbackID, bool useBinaryEncoding)
2186 CoreIPC::DataReference dataReference;
2188 RefPtr<SharedBuffer> buffer = useBinaryEncoding
2189 ? MHTMLArchive::generateMHTMLDataUsingBinaryEncoding(m_page.get())
2190 : MHTMLArchive::generateMHTMLData(m_page.get());
2193 dataReference = CoreIPC::DataReference(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
2195 send(Messages::WebPageProxy::DataCallback(dataReference, callbackID));
2199 void WebPage::getRenderTreeExternalRepresentation(uint64_t callbackID)
2201 String resultString = renderTreeExternalRepresentation();
2202 send(Messages::WebPageProxy::StringCallback(resultString, callbackID));
2205 void WebPage::getSelectionOrContentsAsString(uint64_t callbackID)
2207 String resultString = m_mainFrame->selectionAsString();
2208 if (resultString.isEmpty())
2209 resultString = m_mainFrame->contentsAsString();
2210 send(Messages::WebPageProxy::StringCallback(resultString, callbackID));
2213 void WebPage::getSourceForFrame(uint64_t frameID, uint64_t callbackID)
2215 String resultString;
2216 if (WebFrame* frame = WebProcess::shared().webFrame(frameID))
2217 resultString = frame->source();
2219 send(Messages::WebPageProxy::StringCallback(resultString, callbackID));
2222 void WebPage::getMainResourceDataOfFrame(uint64_t frameID, uint64_t callbackID)
2224 CoreIPC::DataReference dataReference;
2226 RefPtr<SharedBuffer> buffer;
2227 if (WebFrame* frame = WebProcess::shared().webFrame(frameID)) {
2228 if (DocumentLoader* loader = frame->coreFrame()->loader()->documentLoader()) {
2229 if ((buffer = loader->mainResourceData()))
2230 dataReference = CoreIPC::DataReference(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
2234 send(Messages::WebPageProxy::DataCallback(dataReference, callbackID));
2237 static PassRefPtr<SharedBuffer> resourceDataForFrame(Frame* frame, const KURL& resourceURL)
2239 DocumentLoader* loader = frame->loader()->documentLoader();
2243 RefPtr<ArchiveResource> subresource = loader->subresource(resourceURL);
2247 return subresource->data();
2250 void WebPage::getResourceDataFromFrame(uint64_t frameID, const String& resourceURLString, uint64_t callbackID)
2252 CoreIPC::DataReference dataReference;
2253 KURL resourceURL(KURL(), resourceURLString);
2255 RefPtr<SharedBuffer> buffer;
2256 if (WebFrame* frame = WebProcess::shared().webFrame(frameID)) {
2257 buffer = resourceDataForFrame(frame->coreFrame(), resourceURL);
2259 // Try to get the resource data from the cache.
2260 buffer = cachedResponseDataForURL(resourceURL);
2264 dataReference = CoreIPC::DataReference(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
2267 send(Messages::WebPageProxy::DataCallback(dataReference, callbackID));
2270 void WebPage::getWebArchiveOfFrame(uint64_t frameID, uint64_t callbackID)
2272 CoreIPC::DataReference dataReference;
2274 #if PLATFORM(MAC) || PLATFORM(WIN)
2275 RetainPtr<CFDataRef> data;
2276 if (WebFrame* frame = WebProcess::shared().webFrame(frameID)) {
2277 if ((data = frame->webArchiveData(0, 0)))
2278 dataReference = CoreIPC::DataReference(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get()));
2282 send(Messages::WebPageProxy::DataCallback(dataReference, callbackID));
2285 void WebPage::forceRepaintWithoutCallback()
2287 m_drawingArea->forceRepaint();
2290 void WebPage::forceRepaint(uint64_t callbackID)
2292 if (m_drawingArea->forceRepaintAsync(callbackID))
2295 forceRepaintWithoutCallback();
2296 send(Messages::WebPageProxy::VoidCallback(callbackID));
2299 #if ENABLE(WEB_INTENTS)
2300 void WebPage::deliverIntentToFrame(uint64_t frameID, const IntentData& intentData)
2302 WebFrame* frame = WebProcess::shared().webFrame(frameID);
2306 frame->deliverIntent(intentData);
2310 void WebPage::preferencesDidChange(const WebPreferencesStore& store)
2312 WebPreferencesStore::removeTestRunnerOverrides();
2313 updatePreferences(store);
2316 void WebPage::updatePreferences(const WebPreferencesStore& store)
2318 Settings* settings = m_page->settings();
2320 m_tabToLinks = store.getBoolValueForKey(WebPreferencesKey::tabsToLinksKey());
2322 // FIXME: This should be generated from macro expansion for all preferences,
2323 // but we currently don't match the naming of WebCore exactly so we are
2324 // handrolling the boolean and integer preferences until that is fixed.
2326 #define INITIALIZE_SETTINGS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) settings->set##KeyUpper(store.get##TypeName##ValueForKey(WebPreferencesKey::KeyLower##Key()));
2328 FOR_EACH_WEBKIT_STRING_PREFERENCE(INITIALIZE_SETTINGS)
2330 #undef INITIALIZE_SETTINGS
2332 settings->setScriptEnabled(store.getBoolValueForKey(WebPreferencesKey::javaScriptEnabledKey()));
2333 settings->setLoadsImagesAutomatically(store.getBoolValueForKey(WebPreferencesKey::loadsImagesAutomaticallyKey()));
2334 settings->setLoadsSiteIconsIgnoringImageLoadingSetting(store.getBoolValueForKey(WebPreferencesKey::loadsSiteIconsIgnoringImageLoadingPreferenceKey()));
2335 settings->setPluginsEnabled(store.getBoolValueForKey(WebPreferencesKey::pluginsEnabledKey()));
2336 settings->setJavaEnabled(store.getBoolValueForKey(WebPreferencesKey::javaEnabledKey()));
2337 settings->setJavaEnabledForLocalFiles(store.getBoolValueForKey(WebPreferencesKey::javaEnabledForLocalFilesKey()));
2338 settings->setOfflineWebApplicationCacheEnabled(store.getBoolValueForKey(WebPreferencesKey::offlineWebApplicationCacheEnabledKey()));
2339 settings->setLocalStorageEnabled(store.getBoolValueForKey(WebPreferencesKey::localStorageEnabledKey()));
2340 settings->setXSSAuditorEnabled(store.getBoolValueForKey(WebPreferencesKey::xssAuditorEnabledKey()));
2341 settings->setFrameFlatteningEnabled(store.getBoolValueForKey(WebPreferencesKey::frameFlatteningEnabledKey()));
2342 settings->setPrivateBrowsingEnabled(store.getBoolValueForKey(WebPreferencesKey::privateBrowsingEnabledKey()));
2343 settings->setDeveloperExtrasEnabled(store.getBoolValueForKey(WebPreferencesKey::developerExtrasEnabledKey()));
2344 settings->setJavaScriptExperimentsEnabled(store.getBoolValueForKey(WebPreferencesKey::javaScriptExperimentsEnabledKey()));
2345 settings->setTextAreasAreResizable(store.getBoolValueForKey(WebPreferencesKey::textAreasAreResizableKey()));
2346 settings->setNeedsSiteSpecificQuirks(store.getBoolValueForKey(WebPreferencesKey::needsSiteSpecificQuirksKey()));
2347 settings->setJavaScriptCanOpenWindowsAutomatically(store.getBoolValueForKey(WebPreferencesKey::javaScriptCanOpenWindowsAutomaticallyKey()));
2348 settings->setForceFTPDirectoryListings(store.getBoolValueForKey(WebPreferencesKey::forceFTPDirectoryListingsKey()));
2349 settings->setDNSPrefetchingEnabled(store.getBoolValueForKey(WebPreferencesKey::dnsPrefetchingEnabledKey()));
2350 #if ENABLE(WEB_ARCHIVE)
2351 settings->setWebArchiveDebugModeEnabled(store.getBoolValueForKey(WebPreferencesKey::webArchiveDebugModeEnabledKey()));
2353 settings->setLocalFileContentSniffingEnabled(store.getBoolValueForKey(WebPreferencesKey::localFileContentSniffingEnabledKey()));
2354 settings->setUsesPageCache(store.getBoolValueForKey(WebPreferencesKey::usesPageCacheKey()));
2355 settings->setPageCacheSupportsPlugins(store.getBoolValueForKey(WebPreferencesKey::pageCacheSupportsPluginsKey()));
2356 settings->setAuthorAndUserStylesEnabled(store.getBoolValueForKey(WebPreferencesKey::authorAndUserStylesEnabledKey()));
2357 settings->setPaginateDuringLayoutEnabled(store.getBoolValueForKey(WebPreferencesKey::paginateDuringLayoutEnabledKey()));
2358 settings->setDOMPasteAllowed(store.getBoolValueForKey(WebPreferencesKey::domPasteAllowedKey()));
2359 settings->setJavaScriptCanAccessClipboard(store.getBoolValueForKey(WebPreferencesKey::javaScriptCanAccessClipboardKey()));
2360 settings->setShouldPrintBackgrounds(store.getBoolValueForKey(WebPreferencesKey::shouldPrintBackgroundsKey()));
2361 settings->setWebSecurityEnabled(store.getBoolValueForKey(WebPreferencesKey::webSecurityEnabledKey()));
2362 settings->setAllowUniversalAccessFromFileURLs(store.getBoolValueForKey(WebPreferencesKey::allowUniversalAccessFromFileURLsKey()));
2363 settings->setAllowFileAccessFromFileURLs(store.getBoolValueForKey(WebPreferencesKey::allowFileAccessFromFileURLsKey()));
2365 settings->setMinimumFontSize(store.getUInt32ValueForKey(WebPreferencesKey::minimumFontSizeKey()));
2366 settings->setMinimumLogicalFontSize(store.getUInt32ValueForKey(WebPreferencesKey::minimumLogicalFontSizeKey()));
2367 settings->setDefaultFontSize(store.getUInt32ValueForKey(WebPreferencesKey::defaultFontSizeKey()));
2368 settings->setDefaultFixedFontSize(store.getUInt32ValueForKey(WebPreferencesKey::defaultFixedFontSizeKey()));
2369 settings->setLayoutFallbackWidth(store.getUInt32ValueForKey(WebPreferencesKey::layoutFallbackWidthKey()));
2370 settings->setDeviceWidth(store.getUInt32ValueForKey(WebPreferencesKey::deviceWidthKey()));
2371 settings->setDeviceHeight(store.getUInt32ValueForKey(WebPreferencesKey::deviceHeightKey()));
2372 settings->setEditableLinkBehavior(static_cast<WebCore::EditableLinkBehavior>(store.getUInt32ValueForKey(WebPreferencesKey::editableLinkBehaviorKey())));
2373 settings->setShowsToolTipOverTruncatedText(store.getBoolValueForKey(WebPreferencesKey::showsToolTipOverTruncatedTextKey()));
2375 settings->setAcceleratedCompositingEnabled(store.getBoolValueForKey(WebPreferencesKey::acceleratedCompositingEnabledKey()) && LayerTreeHost::supportsAcceleratedCompositing());
2376 settings->setAcceleratedDrawingEnabled(store.getBoolValueForKey(WebPreferencesKey::acceleratedDrawingEnabledKey()) && LayerTreeHost::supportsAcceleratedCompositing());
2377 settings->setCanvasUsesAcceleratedDrawing(store.getBoolValueForKey(WebPreferencesKey::canvasUsesAcceleratedDrawingKey()) && LayerTreeHost::supportsAcceleratedCompositing());
2378 settings->setShowDebugBorders(store.getBoolValueForKey(WebPreferencesKey::compositingBordersVisibleKey()));
2379 settings->setShowRepaintCounter(store.getBoolValueForKey(WebPreferencesKey::compositingRepaintCountersVisibleKey()));
2380 settings->setCSSCustomFilterEnabled(store.getBoolValueForKey(WebPreferencesKey::cssCustomFilterEnabledKey()));
2381 settings->setCSSRegionsEnabled(store.getBoolValueForKey(WebPreferencesKey::cssRegionsEnabledKey()));
2382 settings->setCSSGridLayoutEnabled(store.getBoolValueForKey(WebPreferencesKey::cssGridLayoutEnabledKey()));
2383 settings->setRegionBasedColumnsEnabled(store.getBoolValueForKey(WebPreferencesKey::regionBasedColumnsEnabledKey()));
2384 settings->setWebGLEnabled(store.getBoolValueForKey(WebPreferencesKey::webGLEnabledKey()));
2385 settings->setMediaPlaybackRequiresUserGesture(store.getBoolValueForKey(WebPreferencesKey::mediaPlaybackRequiresUserGestureKey()));
2386 settings->setMediaPlaybackAllowsInline(store.getBoolValueForKey(WebPreferencesKey::mediaPlaybackAllowsInlineKey()));
2387 settings->setMockScrollbarsEnabled(store.getBoolValueForKey(WebPreferencesKey::mockScrollbarsEnabledKey()));
2388 settings->setHyperlinkAuditingEnabled(store.getBoolValueForKey(WebPreferencesKey::hyperlinkAuditingEnabledKey()));
2389 settings->setRequestAnimationFrameEnabled(store.getBoolValueForKey(WebPreferencesKey::requestAnimationFrameEnabledKey()));
2391 // <rdar://problem/10697417>: It is necessary to force compositing when accelerate drawing
2392 // is enabled on Mac so that scrollbars are always in their own layers.
2394 if (settings->acceleratedDrawingEnabled())
2395 settings->setForceCompositingMode(LayerTreeHost::supportsAcceleratedCompositing());
2398 settings->setForceCompositingMode(store.getBoolValueForKey(WebPreferencesKey::forceCompositingModeKey()) && LayerTreeHost::supportsAcceleratedCompositing());
2400 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
2401 if (!settings->acceleratedCompositingEnabled()) {
2402 settings->setAcceleratedCompositingFor3DTransformsEnabled(false);
2403 settings->setAcceleratedCompositingForVideoEnabled(false);
2404 settings->setAcceleratedCompositingForPluginsEnabled(false);
2405 settings->setAcceleratedCompositingForCanvasEnabled(false);
2406 settings->setAcceleratedCompositingForAnimationEnabled(false);
2409 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
2410 settings->setMemorySavingMode(WebProcess::shared().memorySavingModeEnabled());
2413 #if ENABLE(SQL_DATABASE)
2414 AbstractDatabase::setIsAvailable(store.getBoolValueForKey(WebPreferencesKey::databasesEnabledKey()));
2417 #if ENABLE(FULLSCREEN_API)
2418 settings->setFullScreenEnabled(store.getBoolValueForKey(WebPreferencesKey::fullScreenEnabledKey()));
2421 #if ENABLE(TIZEN_WEBKIT2_ASYNCHRONOUS_SPELLCHECKING)
2422 settings->setAsynchronousSpellCheckingEnabled(store.getBoolValueForKey(WebPreferencesKey::asynchronousSpellCheckingEnabledKey()));
2424 settings->setLocalStorageDatabasePath(WebProcess::shared().localStorageDirectory());
2426 #if USE(AVFOUNDATION)
2427 settings->setAVFoundationEnabled(store.getBoolValueForKey(WebPreferencesKey::isAVFoundationEnabledKey()));
2430 #if ENABLE(WEB_AUDIO)
2431 settings->setWebAudioEnabled(store.getBoolValueForKey(WebPreferencesKey::webAudioEnabledKey()));
2434 settings->setApplicationChromeMode(store.getBoolValueForKey(WebPreferencesKey::applicationChromeModeKey()));
2435 settings->setSuppressesIncrementalRendering(store.getBoolValueForKey(WebPreferencesKey::suppressesIncrementalRenderingKey()));
2436 settings->setBackspaceKeyNavigationEnabled(store.getBoolValueForKey(WebPreferencesKey::backspaceKeyNavigationEnabledKey()));
2437 settings->setWantsBalancedSetDefersLoadingBehavior(store.getBoolValueForKey(WebPreferencesKey::wantsBalancedSetDefersLoadingBehaviorKey()));
2438 settings->setCaretBrowsingEnabled(store.getBoolValueForKey(WebPreferencesKey::caretBrowsingEnabledKey()));
2440 #if ENABLE(VIDEO_TRACK)
2441 settings->setShouldDisplaySubtitles(store.getBoolValueForKey(WebPreferencesKey::shouldDisplaySubtitlesKey()));
2442 settings->setShouldDisplayCaptions(store.getBoolValueForKey(WebPreferencesKey::shouldDisplayCaptionsKey()));
2443 settings->setShouldDisplayTextDescriptions(store.getBoolValueForKey(WebPreferencesKey::shouldDisplayTextDescriptionsKey()));
2446 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
2447 settings->setNotificationsEnabled(store.getBoolValueForKey(WebPreferencesKey::notificationsEnabledKey()));
2450 settings->setShouldRespectImageOrientation(store.getBoolValueForKey(WebPreferencesKey::shouldRespectImageOrientationKey()));
2452 #if ENABLE(TIZEN_INDEXED_DATABASE)
2453 m_page->group().groupSettings()->setIndexedDBDatabasePath(WebProcess::shared().indexedDatabaseDirectory());
2456 settings->setDiagnosticLoggingEnabled(store.getBoolValueForKey(WebPreferencesKey::diagnosticLoggingEnabledKey()));
2458 #if ENABLE(TEXT_AUTOSIZING)
2459 settings->setTextAutosizingEnabled(store.getBoolValueForKey(WebPreferencesKey::textAutosizingEnabledKey()));
2462 platformPreferencesDidChange(store);
2465 m_drawingArea->updatePreferences();
2468 #if ENABLE(INSPECTOR)
2469 WebInspector* WebPage::inspector()
2474 m_inspector = WebInspector::create(this, m_inspectorClient);
2475 return m_inspector.get();
2479 #if ENABLE(FULLSCREEN_API)
2480 WebFullScreenManager* WebPage::fullScreenManager()
2482 if (!m_fullScreenManager)
2483 m_fullScreenManager = WebFullScreenManager::create(this);
2484 return m_fullScreenManager.get();
2488 NotificationPermissionRequestManager* WebPage::notificationPermissionRequestManager()
2490 if (m_notificationPermissionRequestManager)
2491 return m_notificationPermissionRequestManager.get();
2493 m_notificationPermissionRequestManager = NotificationPermissionRequestManager::create(this);
2494 return m_notificationPermissionRequestManager.get();
2497 #if ENABLE(TIZEN_MEDIA_STREAM)
2498 UserMediaPermissionRequestManager* WebPage::userMediaPermissionRequestManager()
2500 if (m_userMediaPermissionRequestManager)
2501 return m_userMediaPermissionRequestManager.get();
2503 m_userMediaPermissionRequestManager = UserMediaPermissionRequestManager::create(this);
2504 return m_userMediaPermissionRequestManager.get();
2508 #if !PLATFORM(GTK) && !PLATFORM(MAC)
2509 bool WebPage::handleEditingKeyboardEvent(KeyboardEvent* evt)
2511 Node* node = evt->target()->toNode();
2513 Frame* frame = node->document()->frame();
2516 const PlatformKeyboardEvent* keyEvent = evt->keyEvent();
2520 Editor::Command command = frame->editor()->command(interpretKeyEvent(evt));
2522 if (keyEvent->type() == PlatformEvent::RawKeyDown) {
2523 // WebKit doesn't have enough information about mode to decide how commands that just insert text if executed via Editor should be treated,
2524 // so we leave it upon WebCore to either handle them immediately (e.g. Tab that changes focus) or let a keypress event be generated
2525 // (e.g. Tab that inserts a Tab character, or Enter).
2526 return !command.isTextInsertion() && command.execute(evt);
2529 if (command.execute(evt))
2532 // Don't allow text insertion for nodes that cannot edit.
2533 if (!frame->editor()->canEdit())
2536 // Don't insert null or control characters as they can result in unexpected behaviour
2537 if (evt->charCode() < ' ')
2540 return frame->editor()->insertText(evt->keyEvent()->text(), evt);
2544 #if ENABLE(DRAG_SUPPORT)
2547 void WebPage::performDragControllerAction(uint64_t action, WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t draggingSourceOperationMask, const WebCore::DragDataMap& dataMap, uint32_t flags)
2550 send(Messages::WebPageProxy::DidPerformDragControllerAction(WebCore::DragSession()));
2554 DragData dragData(dataMap, clientPosition, globalPosition, static_cast<DragOperation>(draggingSourceOperationMask), static_cast<DragApplicationFlags>(flags));
2556 case DragControllerActionEntered:
2557 send(Messages::WebPageProxy::DidPerformDragControllerAction(m_page->dragController()->dragEntered(&dragData)));
2560 case DragControllerActionUpdated:
2561 send(Messages::WebPageProxy::DidPerformDragControllerAction(m_page->dragController()->dragUpdated(&dragData)));
2564 case DragControllerActionExited:
2565 m_page->dragController()->dragExited(&dragData);
2568 case DragControllerActionPerformDrag:
2569 m_page->dragController()->performDrag(&dragData);
2573 ASSERT_NOT_REACHED();
2577 #elif PLATFORM(QT) || PLATFORM(GTK) || ENABLE(TIZEN_DRAG_SUPPORT)
2578 void WebPage::performDragControllerAction(uint64_t action, WebCore::DragData dragData)
2581 send(Messages::WebPageProxy::DidPerformDragControllerAction(WebCore::DragSession()));
2583 QMimeData* data = const_cast<QMimeData*>(dragData.platformData());
2586 DataObjectGtk* data = const_cast<DataObjectGtk*>(dragData.platformData());
2589 #if ENABLE(TIZEN_DRAG_SUPPORT)
2590 DataObjectTizen* data = const_cast<DataObjectTizen*>(dragData.platformData());
2597 case DragControllerActionEntered:
2598 send(Messages::WebPageProxy::DidPerformDragControllerAction(m_page->dragController()->dragEntered(&dragData)));
2601 case DragControllerActionUpdated:
2602 send(Messages::WebPageProxy::DidPerformDragControllerAction(m_page->dragController()->dragUpdated(&dragData)));
2605 case DragControllerActionExited:
2606 m_page->dragController()->dragExited(&dragData);
2609 case DragControllerActionPerformDrag: {
2610 m_page->dragController()->performDrag(&dragData);
2615 ASSERT_NOT_REACHED();
2617 // DragData does not delete its platformData so we need to do that here.
2619 QMimeData* data = const_cast<QMimeData*>(dragData.platformData());
2622 DataObjectGtk* data = const_cast<DataObjectGtk*>(dragData.platformData());
2625 #if ENABLE(TIZEN_DRAG_SUPPORT)
2626 DataObjectTizen* data = const_cast<DataObjectTizen*>(dragData.platformData());
2632 void WebPage::performDragControllerAction(uint64_t action, WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t draggingSourceOperationMask, const String& dragStorageName, uint32_t flags, const SandboxExtension::Handle& sandboxExtensionHandle, const SandboxExtension::HandleArray& sandboxExtensionsHandleArray)
2635 send(Messages::WebPageProxy::DidPerformDragControllerAction(WebCore::DragSession()));
2639 DragData dragData(dragStorageName, clientPosition, globalPosition, static_cast<DragOperation>(draggingSourceOperationMask), static_cast<DragApplicationFlags>(flags));
2641 case DragControllerActionEntered:
2642 send(Messages::WebPageProxy::DidPerformDragControllerAction(m_page->dragController()->dragEntered(&dragData)));
2645 case DragControllerActionUpdated:
2646 send(Messages::WebPageProxy::DidPerformDragControllerAction(m_page->dragController()->dragUpdated(&dragData)));
2649 case DragControllerActionExited:
2650 m_page->dragController()->dragExited(&dragData);
2653 case DragControllerActionPerformDrag: {
2654 ASSERT(!m_pendingDropSandboxExtension);
2656 m_pendingDropSandboxExtension = SandboxExtension::create(sandboxExtensionHandle);
2657 for (size_t i = 0; i < sandboxExtensionsHandleArray.size(); i++) {
2658 if (RefPtr<SandboxExtension> extension = SandboxExtension::create(sandboxExtensionsHandleArray[i]))
2659 m_pendingDropExtensionsForFileUpload.append(extension);
2662 m_page->dragController()->performDrag(&dragData);
2664 // If we started loading a local file, the sandbox extension tracker would have adopted this
2665 // pending drop sandbox extension. If not, we'll play it safe and invalidate it.
2666 if (m_pendingDropSandboxExtension) {
2667 m_pendingDropSandboxExtension->invalidate();
2668 m_pendingDropSandboxExtension = nullptr;
2670 for (size_t i = 0; i < m_pendingDropExtensionsForFileUpload.size(); i++)
2671 m_pendingDropExtensionsForFileUpload[i]->invalidate();
2673 m_pendingDropExtensionsForFileUpload.clear();
2678 ASSERT_NOT_REACHED();
2683 void WebPage::dragEnded(WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t operation)
2685 IntPoint adjustedClientPosition(clientPosition.x() + m_page->dragController()->dragOffset().x(), clientPosition.y() + m_page->dragController()->dragOffset().y());
2686 IntPoint adjustedGlobalPosition(globalPosition.x() + m_page->dragController()->dragOffset().x(), globalPosition.y() + m_page->dragController()->dragOffset().y());
2688 m_page->dragController()->dragEnded();
2689 FrameView* view = m_page->mainFrame()->view();
2692 // FIXME: These are fake modifier keys here, but they should be real ones instead.
2693 PlatformMouseEvent event(adjustedClientPosition, adjustedGlobalPosition, LeftButton, PlatformEvent::MouseMoved, 0, false, false, false, false, currentTime());
2694 m_page->mainFrame()->eventHandler()->dragSourceEndedAt(event, (DragOperation)operation);
2697 void WebPage::willPerformLoadDragDestinationAction()
2699 m_sandboxExtensionTracker.willPerformLoadDragDestinationAction(m_pendingDropSandboxExtension.release());
2702 void WebPage::mayPerformUploadDragDestinationAction()
2704 for (size_t i = 0; i < m_pendingDropExtensionsForFileUpload.size(); i++)
2705 m_pendingDropExtensionsForFileUpload[i]->consumePermanently();
2706 m_pendingDropExtensionsForFileUpload.clear();
2709 #endif // ENABLE(DRAG_SUPPORT)
2711 WebUndoStep* WebPage::webUndoStep(uint64_t stepID)
2713 return m_undoStepMap.get(stepID).get();
2716 void WebPage::addWebUndoStep(uint64_t stepID, WebUndoStep* entry)
2718 m_undoStepMap.set(stepID, entry);
2721 void WebPage::removeWebEditCommand(uint64_t stepID)
2723 m_undoStepMap.remove(stepID);
2726 void WebPage::unapplyEditCommand(uint64_t stepID)
2728 WebUndoStep* step = webUndoStep(stepID);
2732 step->step()->unapply();
2735 void WebPage::reapplyEditCommand(uint64_t stepID)
2737 WebUndoStep* step = webUndoStep(stepID);
2742 step->step()->reapply();
2746 void WebPage::didRemoveEditCommand(uint64_t commandID)
2748 removeWebEditCommand(commandID);
2751 void WebPage::setActivePopupMenu(WebPopupMenu* menu)
2753 m_activePopupMenu = menu;
2756 #if ENABLE(INPUT_TYPE_COLOR)
2757 void WebPage::setActiveColorChooser(WebColorChooser* colorChooser)
2759 m_activeColorChooser = colorChooser;
2762 void WebPage::didEndColorChooser()
2764 m_activeColorChooser->didEndChooser();
2767 void WebPage::didChooseColor(const WebCore::Color& color)
2769 m_activeColorChooser->didChooseColor(color);
2773 void WebPage::setActiveOpenPanelResultListener(PassRefPtr<WebOpenPanelResultListener> openPanelResultListener)
2775 m_activeOpenPanelResultListener = openPanelResultListener;
2778 bool WebPage::findStringFromInjectedBundle(const String& target, FindOptions options)
2780 return m_page->findString(target, options);
2783 void WebPage::findString(const String& string, uint32_t options, uint32_t maxMatchCount)
2785 m_findController.findString(string, static_cast<FindOptions>(options), maxMatchCount);
2788 void WebPage::findStringMatches(const String& string, uint32_t options, uint32_t maxMatchCount)
2790 m_findController.findStringMatches(string, static_cast<FindOptions>(options), maxMatchCount);
2793 void WebPage::getImageForFindMatch(uint32_t matchIndex)
2795 m_findController.getImageForFindMatch(matchIndex);
2798 void WebPage::selectFindMatch(uint32_t matchIndex)
2800 m_findController.selectFindMatch(matchIndex);
2803 void WebPage::hideFindUI()
2805 m_findController.hideFindUI();
2808 void WebPage::countStringMatches(const String& string, uint32_t options, uint32_t maxMatchCount)
2810 m_findController.countStringMatches(string, static_cast<FindOptions>(options), maxMatchCount);
2813 void WebPage::didChangeSelectedIndexForActivePopupMenu(int32_t newIndex)
2815 changeSelectedIndex(newIndex);
2817 // Since applictions on tizen may provide a way to select item more than one time,
2818 // we need to keep the active popup menu to allow repetitive selection.
2820 m_activePopupMenu = 0;
2824 void WebPage::changeSelectedIndex(int32_t index)
2826 if (!m_activePopupMenu)
2829 m_activePopupMenu->didChangeSelectedIndex(index);
2832 void WebPage::didChooseFilesForOpenPanel(const Vector<String>& files)
2834 if (!m_activeOpenPanelResultListener)
2837 m_activeOpenPanelResultListener->didChooseFiles(files);
2838 m_activeOpenPanelResultListener = 0;
2841 void WebPage::didCancelForOpenPanel()
2843 m_activeOpenPanelResultListener = 0;
2846 #if ENABLE(WEB_PROCESS_SANDBOX)
2847 void WebPage::extendSandboxForFileFromOpenPanel(const SandboxExtension::Handle& handle)
2849 SandboxExtension::create(handle)->consumePermanently();
2853 #if ENABLE(GEOLOCATION)
2854 void WebPage::didReceiveGeolocationPermissionDecision(uint64_t geolocationID, bool allowed)
2856 m_geolocationPermissionRequestManager.didReceiveGeolocationPermissionDecision(geolocationID, allowed);
2860 void WebPage::didReceiveNotificationPermissionDecision(uint64_t notificationID, bool allowed)
2862 notificationPermissionRequestManager()->didReceiveNotificationPermissionDecision(notificationID, allowed);
2865 #if ENABLE(TIZEN_MEDIA_STREAM)
2866 void WebPage::didReceiveUserMediaPermissionDecision(uint64_t userMediaID, bool allowed)
2868 userMediaPermissionRequestManager()->didReceiveUserMediaPermissionDecision(userMediaID, allowed);
2872 void WebPage::advanceToNextMisspelling(bool startBeforeSelection)
2874 Frame* frame = m_page->focusController()->focusedOrMainFrame();
2875 frame->editor()->advanceToNextMisspelling(startBeforeSelection);
2878 void WebPage::changeSpellingToWord(const String& word)
2880 replaceSelectionWithText(m_page->focusController()->focusedOrMainFrame(), word);
2883 void WebPage::unmarkAllMisspellings()
2885 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
2886 if (Document* document = frame->document())
2887 document->markers()->removeMarkers(DocumentMarker::Spelling);
2891 void WebPage::unmarkAllBadGrammar()
2893 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
2894 if (Document* document = frame->document())
2895 document->markers()->removeMarkers(DocumentMarker::Grammar);
2900 void WebPage::uppercaseWord()
2902 m_page->focusController()->focusedOrMainFrame()->editor()->uppercaseWord();
2905 void WebPage::lowercaseWord()
2907 m_page->focusController()->focusedOrMainFrame()->editor()->lowercaseWord();
2910 void WebPage::capitalizeWord()
2912 m_page->focusController()->focusedOrMainFrame()->editor()->capitalizeWord();
2916 void WebPage::setTextForActivePopupMenu(int32_t index)
2918 if (!m_activePopupMenu)
2921 m_activePopupMenu->setTextForIndex(index);
2925 void WebPage::failedToShowPopupMenu()
2927 if (!m_activePopupMenu)
2930 m_activePopupMenu->client()->popupDidHide();
2934 #if ENABLE(CONTEXT_MENUS)
2935 void WebPage::didSelectItemFromActiveContextMenu(const WebContextMenuItemData& item)
2940 m_contextMenu->itemSelected(item);
2945 void WebPage::replaceSelectionWithText(Frame* frame, const String& text)
2947 bool selectReplacement = true;
2948 bool smartReplace = false;
2949 return frame->editor()->replaceSelectionWithText(text, selectReplacement, smartReplace);
2952 void WebPage::clearSelection()
2954 m_page->focusController()->focusedOrMainFrame()->selection()->clear();
2957 bool WebPage::mainFrameHasCustomRepresentation() const
2959 if (Frame* frame = mainFrame())
2960 return static_cast<WebFrameLoaderClient*>(frame->loader()->client())->frameHasCustomRepresentation();
2965 void WebPage::didChangeScrollOffsetForMainFrame()
2967 Frame* frame = m_page->mainFrame();
2968 IntPoint scrollPosition = frame->view()->scrollPosition();
2969 IntPoint maximumScrollPosition = frame->view()->maximumScrollPosition();
2970 IntPoint minimumScrollPosition = frame->view()->minimumScrollPosition();
2972 #if PLATFORM(EFL) && OS(TIZEN)
2973 send(Messages::WebPageProxy::DidChangeScrollPositionForMainFrame(scrollPosition));
2976 bool isPinnedToLeftSide = (scrollPosition.x() <= minimumScrollPosition.x());
2977 bool isPinnedToRightSide = (scrollPosition.x() >= maximumScrollPosition.x());
2979 if (isPinnedToLeftSide != m_cachedMainFrameIsPinnedToLeftSide || isPinnedToRightSide != m_cachedMainFrameIsPinnedToRightSide) {
2980 send(Messages::WebPageProxy::DidChangeScrollOffsetPinningForMainFrame(isPinnedToLeftSide, isPinnedToRightSide));
2982 m_cachedMainFrameIsPinnedToLeftSide = isPinnedToLeftSide;
2983 m_cachedMainFrameIsPinnedToRightSide = isPinnedToRightSide;
2987 void WebPage::mainFrameDidLayout()
2989 unsigned pageCount = m_page->pageCount();
2990 if (pageCount != m_cachedPageCount) {
2991 send(Messages::WebPageProxy::DidChangePageCount(pageCount));
2992 m_cachedPageCount = pageCount;
2995 double red, green, blue, alpha;
2996 m_mainFrame->getDocumentBackgroundColor(&red, &green, &blue, &alpha);
2997 send(Messages::WebPageProxy::SetBackgroundColor(red, green, blue, alpha));
3000 void WebPage::addPluginView(PluginView* pluginView)
3002 ASSERT(!m_pluginViews.contains(pluginView));
3004 m_pluginViews.add(pluginView);
3007 void WebPage::removePluginView(PluginView* pluginView)
3009 ASSERT(m_pluginViews.contains(pluginView));
3011 m_pluginViews.remove(pluginView);
3015 void WebPage::setWindowIsVisible(bool windowIsVisible)
3017 m_windowIsVisible = windowIsVisible;
3019 corePage()->focusController()->setContainingWindowIsVisible(windowIsVisible);
3021 // Tell all our plug-in views that the window visibility changed.
3022 for (HashSet<PluginView*>::const_iterator it = m_pluginViews.begin(), end = m_pluginViews.end(); it != end; ++it)
3023 (*it)->setWindowIsVisible(windowIsVisible);
3026 void WebPage::windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates, const WebCore::IntPoint& accessibilityViewCoordinates)
3028 m_windowFrameInScreenCoordinates = windowFrameInScreenCoordinates;
3029 m_viewFrameInWindowCoordinates = viewFrameInWindowCoordinates;
3030 m_accessibilityPosition = accessibilityViewCoordinates;
3032 // Tell all our plug-in views that the window and view frames have changed.
3033 for (HashSet<PluginView*>::const_iterator it = m_pluginViews.begin(), end = m_pluginViews.end(); it != end; ++it)
3034 (*it)->windowAndViewFramesChanged(windowFrameInScreenCoordinates, viewFrameInWindowCoordinates);
3038 bool WebPage::windowIsFocused() const
3040 return m_page->focusController()->isActive();
3043 bool WebPage::windowAndWebPageAreFocused() const
3046 if (!m_windowIsVisible)
3049 return m_page->focusController()->isFocused() && m_page->focusController()->isActive();
3052 void WebPage::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
3054 if (messageID.is<CoreIPC::MessageClassDrawingArea>()) {
3056 m_drawingArea->didReceiveDrawingAreaMessage(connection, messageID, arguments);
3060 #if USE(TILED_BACKING_STORE) && USE(ACCELERATED_COMPOSITING)
3061 if (messageID.is<CoreIPC::MessageClassLayerTreeCoordinator>()) {
3063 m_drawingArea->didReceiveLayerTreeCoordinatorMessage(connection, messageID, arguments);
3068 #if ENABLE(INSPECTOR)
3069 if (messageID.is<CoreIPC::MessageClassWebInspector>()) {
3070 if (WebInspector* inspector = this->inspector())
3071 inspector->didReceiveWebInspectorMessage(connection, messageID, arguments);
3076 #if ENABLE(FULLSCREEN_API)
3077 if (messageID.is<CoreIPC::MessageClassWebFullScreenManager>()) {
3078 fullScreenManager()->didReceiveMessage(connection, messageID, arguments);
3083 didReceiveWebPageMessage(connection, messageID, arguments);
3086 void WebPage::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, OwnPtr<CoreIPC::ArgumentEncoder>& reply)
3088 didReceiveSyncWebPageMessage(connection, messageID, arguments, reply);
3091 InjectedBundleBackForwardList* WebPage::backForwardList()
3093 if (!m_backForwardList)
3094 m_backForwardList = InjectedBundleBackForwardList::create(this);
3095 return m_backForwardList.get();
3098 #if PLATFORM(QT) || OS(TIZEN)
3099 #if ENABLE(TOUCH_ADJUSTMENT)
3100 void WebPage::findZoomableAreaForPoint(const WebCore::IntPoint& point, const WebCore::IntSize& area)
3103 IntRect zoomableArea;
3104 bool foundAreaForTouchPoint = m_mainFrame->coreFrame()->eventHandler()->bestZoomableAreaForTouchPoint(point, IntSize(area.width() / 2, area.height() / 2), zoomableArea, node);
3107 if (!foundAreaForTouchPoint)
3110 send(Messages::WebPageProxy::DidFindZoomableArea(point, zoomableArea));
3114 void WebPage::findZoomableAreaForPoint(const WebCore::IntPoint& point, const WebCore::IntSize& area)
3117 Frame* mainframe = m_mainFrame->coreFrame();
3118 HitTestResult result = mainframe->eventHandler()->hitTestResultAtPoint(mainframe->view()->windowToContents(point), /*allowShadowContent*/ false, /*ignoreClipping*/ true);
3120 Node* node = result.innerNode();
3125 #if OS(TIZEN) // FIXME: This is to fix wrong codes of open source.
3126 IntRect zoomableArea = enclosingIntRect(node->getRect());
3128 IntRect zoomableArea = node->getRect();
3132 bool found = !node->isTextNode() && !node->isShadowRoot();
3134 // No candidate found, bail out.
3135 if (!found && !node->parentNode())
3138 // Candidate found, and it is a better candidate than its parent.
3139 // NB: A parent is considered a better candidate iff the node is
3140 // contained by it and it is the only child.
3141 if (found && (!node->parentNode() || node->parentNode()->childNodeCount() != 1))
3144 node = node->parentNode();
3145 #if OS(TIZEN) // FIXME: This is to fix wrong codes of open source.
3146 zoomableArea.unite(enclosingIntRect(node->getRect()));
3148 zoomableArea.unite(node->getRect());
3152 if (node->document() && node->document()->frame() && node->document()->frame()->view()) {
3153 const ScrollView* view = node->document()->frame()->view();
3154 zoomableArea = view->contentsToWindow(zoomableArea);
3157 send(Messages::WebPageProxy::DidFindZoomableArea(point, zoomableArea));
3162 WebPage::SandboxExtensionTracker::~SandboxExtensionTracker()
3167 void WebPage::SandboxExtensionTracker::invalidate()
3169 if (m_pendingProvisionalSandboxExtension) {
3170 m_pendingProvisionalSandboxExtension->invalidate();
3171 m_pendingProvisionalSandboxExtension = 0;
3174 if (m_provisionalSandboxExtension) {
3175 m_provisionalSandboxExtension->invalidate();
3176 m_provisionalSandboxExtension = 0;
3179 if (m_committedSandboxExtension) {
3180 m_committedSandboxExtension->invalidate();
3181 m_committedSandboxExtension = 0;
3185 void WebPage::SandboxExtensionTracker::willPerformLoadDragDestinationAction(PassRefPtr<SandboxExtension> pendingDropSandboxExtension)
3187 setPendingProvisionalSandboxExtension(pendingDropSandboxExtension);
3190 void WebPage::SandboxExtensionTracker::beginLoad(WebFrame* frame, const SandboxExtension::Handle& handle)
3192 ASSERT(frame->isMainFrame());
3194 setPendingProvisionalSandboxExtension(SandboxExtension::create(handle));
3197 void WebPage::SandboxExtensionTracker::setPendingProvisionalSandboxExtension(PassRefPtr<SandboxExtension> pendingProvisionalSandboxExtension)
3199 // If we get two beginLoad calls in succession, without a provisional load starting, then
3200 // m_pendingProvisionalSandboxExtension will be non-null. Invalidate and null out the extension if that is the case.
3201 if (m_pendingProvisionalSandboxExtension) {
3202 m_pendingProvisionalSandboxExtension->invalidate();
3203 m_pendingProvisionalSandboxExtension = nullptr;
3206 m_pendingProvisionalSandboxExtension = pendingProvisionalSandboxExtension;
3209 static bool shouldReuseCommittedSandboxExtension(WebFrame* frame)
3211 ASSERT(frame->isMainFrame());
3213 FrameLoader* frameLoader = frame->coreFrame()->loader();
3214 FrameLoadType frameLoadType = frameLoader->loadType();
3216 // If the page is being reloaded, it should reuse whatever extension is committed.
3217 if (frameLoadType == FrameLoadTypeReload || frameLoadType == FrameLoadTypeReloadFromOrigin)
3220 DocumentLoader* documentLoader = frameLoader->documentLoader();
3221 DocumentLoader* provisionalDocumentLoader = frameLoader->provisionalDocumentLoader();
3222 if (!documentLoader || !provisionalDocumentLoader)
3225 if (documentLoader->url().isLocalFile() && provisionalDocumentLoader->url().isLocalFile())
3231 void WebPage::SandboxExtensionTracker::didStartProvisionalLoad(WebFrame* frame)
3233 if (!frame->isMainFrame())
3236 // We should only reuse the commited sandbox extension if it is not null. It can be
3237 // null if the last load was for an error page.
3238 if (m_committedSandboxExtension && shouldReuseCommittedSandboxExtension(frame)) {
3239 m_pendingProvisionalSandboxExtension = m_committedSandboxExtension.release();
3240 ASSERT(!m_committedSandboxExtension);
3243 ASSERT(!m_provisionalSandboxExtension);
3245 m_provisionalSandboxExtension = m_pendingProvisionalSandboxExtension.release();
3246 if (!m_provisionalSandboxExtension)
3249 m_provisionalSandboxExtension->consume();
3252 void WebPage::SandboxExtensionTracker::didCommitProvisionalLoad(WebFrame* frame)
3254 if (!frame->isMainFrame())
3257 // Generally, there should be no pending extension at this stage, but we can have one if UI process
3258 // has an out of date idea of WebProcess state, and initiates a load or reload without stopping an existing one.
3259 if (m_pendingProvisionalSandboxExtension) {
3260 m_pendingProvisionalSandboxExtension->invalidate();
3261 m_pendingProvisionalSandboxExtension = nullptr;
3264 // The provisional load has been committed. Invalidate the currently committed sandbox
3265 // extension and make the provisional sandbox extension the committed sandbox extension.
3266 if (m_committedSandboxExtension)
3267 m_committedSandboxExtension->invalidate();
3269 m_committedSandboxExtension = m_provisionalSandboxExtension.release();
3272 void WebPage::SandboxExtensionTracker::didFailProvisionalLoad(WebFrame* frame)
3274 if (!frame->isMainFrame())
3277 // Generally, there should be no pending extension at this stage, but we can have one if UI process
3278 // has an out of date idea of WebProcess state, and initiates a load or reload without stopping an existing one.
3279 if (m_pendingProvisionalSandboxExtension) {
3280 m_pendingProvisionalSandboxExtension->invalidate();
3281 m_pendingProvisionalSandboxExtension = nullptr;
3284 if (!m_provisionalSandboxExtension)
3287 m_provisionalSandboxExtension->invalidate();
3288 m_provisionalSandboxExtension = nullptr;
3291 bool WebPage::hasLocalDataForURL(const KURL& url)
3293 if (url.isLocalFile())
3296 FrameLoader* frameLoader = m_page->mainFrame()->loader();
3297 DocumentLoader* documentLoader = frameLoader ? frameLoader->documentLoader() : 0;
3298 if (documentLoader && documentLoader->subresource(url))
3301 return platformHasLocalDataForURL(url);
3304 void WebPage::setCustomTextEncodingName(const String& encoding)
3306 m_page->mainFrame()->loader()->reloadWithOverrideEncoding(encoding);
3309 void WebPage::didRemoveBackForwardItem(uint64_t itemID)
3311 WebBackForwardListProxy::removeItem(itemID);
3316 bool WebPage::isSpeaking()
3319 return sendSync(Messages::WebPageProxy::GetIsSpeaking(), Messages::WebPageProxy::GetIsSpeaking::Reply(result)) && result;
3322 void WebPage::speak(const String& string)
3324 send(Messages::WebPageProxy::Speak(string));
3327 void WebPage::stopSpeaking()
3329 send(Messages::WebPageProxy::StopSpeaking());
3335 RetainPtr<PDFDocument> WebPage::pdfDocumentForPrintingFrame(Frame* coreFrame)
3337 Document* document = coreFrame->document();
3341 if (!document->isPluginDocument())
3344 PluginView* pluginView = static_cast<PluginView*>(toPluginDocument(document)->pluginWidget());
3348 return pluginView->pdfDocumentForPrinting();
3350 #endif // PLATFORM(MAC)
3352 void WebPage::beginPrinting(uint64_t frameID, const PrintInfo& printInfo)
3354 WebFrame* frame = WebProcess::shared().webFrame(frameID);
3358 Frame* coreFrame = frame->coreFrame();
3363 if (pdfDocumentForPrintingFrame(coreFrame))
3365 #endif // PLATFORM(MAC)
3367 if (!m_printContext)
3368 m_printContext = adoptPtr(new PrintContext(coreFrame));
3370 drawingArea()->setLayerTreeStateIsFrozen(true);
3371 m_printContext->begin(printInfo.availablePaperWidth, printInfo.availablePaperHeight);
3373 float fullPageHeight;
3374 m_printContext->computePageRects(FloatRect(0, 0, printInfo.availablePaperWidth, printInfo.availablePaperHeight), 0, 0, printInfo.pageSetupScaleFactor, fullPageHeight, true);
3377 if (!m_printOperation)
3378 m_printOperation = WebPrintOperationGtk::create(this, printInfo);
3382 void WebPage::endPrinting()
3384 drawingArea()->setLayerTreeStateIsFrozen(false);
3386 m_printOperation = 0;
3388 m_printContext = nullptr;
3391 void WebPage::computePagesForPrinting(uint64_t frameID, const PrintInfo& printInfo, uint64_t callbackID)
3393 Vector<IntRect> resultPageRects;
3394 double resultTotalScaleFactorForPrinting = 1;
3396 beginPrinting(frameID, printInfo);
3398 if (m_printContext) {
3399 resultPageRects = m_printContext->pageRects();
3400 resultTotalScaleFactorForPrinting = m_printContext->computeAutomaticScaleFactor(FloatSize(printInfo.availablePaperWidth, printInfo.availablePaperHeight)) * printInfo.pageSetupScaleFactor;
3404 computePagesForPrintingPDFDocument(frameID, printInfo, resultPageRects);
3405 #endif // PLATFORM(MAC)
3407 // If we're asked to print, we should actually print at least a blank page.
3408 if (resultPageRects.isEmpty())
3409 resultPageRects.append(IntRect(0, 0, 1, 1));
3411 send(Messages::WebPageProxy::ComputedPagesCallback(resultPageRects, resultTotalScaleFactorForPrinting, callbackID));
3414 #if PLATFORM(MAC) || PLATFORM(WIN)
3415 void WebPage::drawRectToPDF(uint64_t frameID, const PrintInfo& printInfo, const WebCore::IntRect& rect, uint64_t callbackID)
3417 WebFrame* frame = WebProcess::shared().webFrame(frameID);
3418 Frame* coreFrame = frame ? frame->coreFrame() : 0;
3420 RetainPtr<CFMutableDataRef> pdfPageData(AdoptCF, CFDataCreateMutable(0, 0));
3425 ASSERT(coreFrame->document()->printing() || pdfDocumentForPrintingFrame(coreFrame));
3427 ASSERT(coreFrame->document()->printing());
3430 // FIXME: Use CGDataConsumerCreate with callbacks to avoid copying the data.
3431 RetainPtr<CGDataConsumerRef> pdfDataConsumer(AdoptCF, CGDataConsumerCreateWithCFData(pdfPageData.get()));
3433 CGRect mediaBox = CGRectMake(0, 0, rect.width(), rect.height());
3434 RetainPtr<CGContextRef> context(AdoptCF, CGPDFContextCreate(pdfDataConsumer.get(), &mediaBox, 0));
3435 RetainPtr<CFDictionaryRef> pageInfo(AdoptCF, CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
3436 CGPDFContextBeginPage(context.get(), pageInfo.get());
3439 if (RetainPtr<PDFDocument> pdfDocument = pdfDocumentForPrintingFrame(coreFrame)) {
3440 ASSERT(!m_printContext);
3441 drawRectToPDFFromPDFDocument(context.get(), pdfDocument.get(), printInfo, rect);
3445 GraphicsContext ctx(context.get());
3446 ctx.scale(FloatSize(1, -1));
3447 ctx.translate(0, -rect.height());
3448 m_printContext->spoolRect(ctx, rect);
3451 CGPDFContextEndPage(context.get());
3452 CGPDFContextClose(context.get());
3456 send(Messages::WebPageProxy::DataCallback(CoreIPC::DataReference(CFDataGetBytePtr(pdfPageData.get()), CFDataGetLength(pdfPageData.get())), callbackID));
3459 void WebPage::drawPagesToPDF(uint64_t frameID, const PrintInfo& printInfo, uint32_t first, uint32_t count, uint64_t callbackID)
3461 WebFrame* frame = WebProcess::shared().webFrame(frameID);
3462 Frame* coreFrame = frame ? frame->coreFrame() : 0;
3464 RetainPtr<CFMutableDataRef> pdfPageData(AdoptCF, CFDataCreateMutable(0, 0));
3470 ASSERT(coreFrame->document()->printing() || pdfDocumentForPrintingFrame(coreFrame));
3472 ASSERT(coreFrame->document()->printing());
3475 // FIXME: Use CGDataConsumerCreate with callbacks to avoid copying the data.
3476 RetainPtr<CGDataConsumerRef> pdfDataConsumer(AdoptCF, CGDataConsumerCreateWithCFData(pdfPageData.get()));
3478 CGRect mediaBox = (m_printContext && m_printContext->pageCount()) ? m_printContext->pageRect(0) : CGRectMake(0, 0, printInfo.availablePaperWidth, printInfo.availablePaperHeight);
3479 RetainPtr<CGContextRef> context(AdoptCF, CGPDFContextCreate(pdfDataConsumer.get(), &mediaBox, 0));
3482 if (RetainPtr<PDFDocument> pdfDocument = pdfDocumentForPrintingFrame(coreFrame)) {
3483 ASSERT(!m_printContext);
3484 drawPagesToPDFFromPDFDocument(context.get(), pdfDocument.get(), printInfo, first, count);
3488 size_t pageCount = m_printContext->pageCount();
3489 for (uint32_t page = first; page < first + count; ++page) {
3490 if (page >= pageCount)
3493 RetainPtr<CFDictionaryRef> pageInfo(AdoptCF, CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
3494 CGPDFContextBeginPage(context.get(), pageInfo.get());
3496 GraphicsContext ctx(context.get());
3497 ctx.scale(FloatSize(1, -1));
3498 ctx.translate(0, -m_printContext->pageRect(page).height());
3499 m_printContext->spoolPage(ctx, page, m_printContext->pageRect(page).width());
3501 CGPDFContextEndPage(context.get());
3504 CGPDFContextClose(context.get());
3508 send(Messages::WebPageProxy::DataCallback(CoreIPC::DataReference(CFDataGetBytePtr(pdfPageData.get()), CFDataGetLength(pdfPageData.get())), callbackID));
3513 void WebPage::drawPagesForPrinting(uint64_t frameID, const PrintInfo& printInfo, uint64_t callbackID)
3515 beginPrinting(frameID, printInfo);
3516 if (m_printContext && m_printOperation) {
3517 m_printOperation->startPrint(m_printContext.get(), callbackID);
3521 send(Messages::WebPageProxy::VoidCallback(callbackID));
3525 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
3526 void WebPage::getWebAppCapable(uint64_t callbackID)
3528 RefPtr<WebCore::NodeList> nodeList = mainFrame()->document()->getElementsByTagName("meta");
3529 bool capable = false;
3531 for (unsigned i = 0; i < nodeList->length(); i++) {
3532 WebCore::HTMLMetaElement* metaElement = static_cast<WebCore::HTMLMetaElement*>(nodeList->item(i));
3533 if (metaElement->name() == "apple-mobile-web-app-capable") {
3534 capable = metaElement->content() == "yes" ? true : false;
3539 send(Messages::WebPageProxy::DidGetWebAppCapable(capable, callbackID));
3542 void WebPage::getWebAppIconURL(uint64_t callbackID)
3544 RefPtr<WebCore::NodeList> nodeList = mainFrame()->document()->getElementsByTagName("link");
3547 for (unsigned i = 0; i < nodeList->length(); i++) {
3548 WebCore::HTMLLinkElement* linkElement = static_cast<WebCore::HTMLLinkElement*>(nodeList->item(i));
3549 if (linkElement->rel() == "apple-touch-icon" || linkElement->rel() == "apple-touch-icon-precomposed")
3550 iconURL = linkElement->href().string();
3553 send(Messages::WebPageProxy::DidGetWebAppIconURL(iconURL, callbackID));
3556 void WebPage::getWebAppIconURLs(uint64_t callbackID)
3558 RefPtr<WebCore::NodeList> nodeList = mainFrame()->document()->getElementsByTagName("link");
3559 Vector<std::pair<String, String> > iconURLs;
3561 for (unsigned i = 0; i < nodeList->length(); i++) {
3562 WebCore::HTMLLinkElement* linkElement = static_cast<WebCore::HTMLLinkElement*>(nodeList->item(i));
3563 if (linkElement->rel() == "apple-touch-icon" || linkElement->rel() == "apple-touch-icon-precomposed")
3564 iconURLs.append(pair<String, String>(linkElement->href().string(), linkElement->iconSizes()));
3567 send(Messages::WebPageProxy::DidGetWebAppIconURLs(iconURLs, callbackID));
3571 void WebPage::setMediaVolume(float volume)
3573 m_page->setMediaVolume(volume);
3576 void WebPage::runModal()
3580 if (m_isRunningModal)
3583 m_isRunningModal = true;
3584 send(Messages::WebPageProxy::RunModal());
3586 ASSERT(!m_isRunningModal);
3589 void WebPage::setMemoryCacheMessagesEnabled(bool memoryCacheMessagesEnabled)
3591 m_page->setMemoryCacheClientCallsEnabled(memoryCacheMessagesEnabled);
3594 bool WebPage::canHandleRequest(const WebCore::ResourceRequest& request)
3596 if (SchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(request.url().protocol()))
3598 return platformCanHandleRequest(request);
3601 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
3602 void WebPage::handleAlternativeTextUIResult(const String& result)
3604 Frame* frame = m_page->focusController()->focusedOrMainFrame();
3607 frame->editor()->handleAlternativeTextUIResult(result);
3611 void WebPage::simulateMouseDown(int button, WebCore::IntPoint position, int clickCount, WKEventModifiers modifiers, double time)
3613 mouseEvent(WebMouseEvent(WebMouseEvent::MouseDown, static_cast<WebMouseEvent::Button>(button), position, position, 0, 0, 0, clickCount, static_cast<WebMouseEvent::Modifiers>(modifiers), time));
3616 void WebPage::simulateMouseUp(int button, WebCore::IntPoint position, int clickCount, WKEventModifiers modifiers, double time)
3618 mouseEvent(WebMouseEvent(WebMouseEvent::MouseUp, static_cast<WebMouseEvent::Button>(button), position, position, 0, 0, 0, clickCount, static_cast<WebMouseEvent::Modifiers>(modifiers), time));
3621 void WebPage::simulateMouseMotion(WebCore::IntPoint position, double time)
3623 mouseEvent(WebMouseEvent(WebMouseEvent::MouseMove, WebMouseEvent::NoButton, position, position, 0, 0, 0, 0, WebMouseEvent::Modifiers(), time));
3626 void WebPage::setCompositionForTesting(const String& compositionString, uint64_t from, uint64_t length)
3628 Frame* frame = m_page->focusController()->focusedOrMainFrame();
3629 if (!frame || !frame->editor()->canEdit())
3632 Vector<CompositionUnderline> underlines;
3633 underlines.append(CompositionUnderline(0, compositionString.length(), Color(Color::black), false));
3634 frame->editor()->setComposition(compositionString, underlines, from, from + length);
3637 bool WebPage::hasCompositionForTesting()
3639 Frame* frame = m_page->focusController()->focusedOrMainFrame();
3640 return frame && frame->editor()->hasComposition();
3643 void WebPage::confirmCompositionForTesting(const String& compositionString)
3645 Frame* frame = m_page->focusController()->focusedOrMainFrame();
3646 if (!frame || !frame->editor()->canEdit())
3649 if (compositionString.isNull())
3650 frame->editor()->confirmComposition();
3651 frame->editor()->confirmComposition(compositionString);
3654 void WebPage::numWheelEventHandlersChanged(unsigned numWheelEventHandlers)
3656 if (m_numWheelEventHandlers == numWheelEventHandlers)
3659 m_numWheelEventHandlers = numWheelEventHandlers;
3660 recomputeShortCircuitHorizontalWheelEventsState();
3663 static bool hasEnabledHorizontalScrollbar(ScrollableArea* scrollableArea)
3665 if (Scrollbar* scrollbar = scrollableArea->horizontalScrollbar())
3666 return scrollbar->enabled();
3671 static bool pageContainsAnyHorizontalScrollbars(Frame* mainFrame)
3673 if (FrameView* frameView = mainFrame->view()) {
3674 if (hasEnabledHorizontalScrollbar(frameView))
3678 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext()) {
3679 FrameView* frameView = frame->view();
3683 const HashSet<ScrollableArea*>* scrollableAreas = frameView->scrollableAreas();
3684 if (!scrollableAreas)
3687 for (HashSet<ScrollableArea*>::const_iterator it = scrollableAreas->begin(), end = scrollableAreas->end(); it != end; ++it) {
3688 ScrollableArea* scrollableArea = *it;
3689 if (!scrollableArea->isOnActivePage())
3692 if (hasEnabledHorizontalScrollbar(scrollableArea))
3700 void WebPage::recomputeShortCircuitHorizontalWheelEventsState()
3702 bool canShortCircuitHorizontalWheelEvents = !m_numWheelEventHandlers;
3704 if (canShortCircuitHorizontalWheelEvents) {
3705 // Check if we have any horizontal scroll bars on the page.
3706 if (pageContainsAnyHorizontalScrollbars(mainFrame()))
3707 canShortCircuitHorizontalWheelEvents = false;
3710 if (m_canShortCircuitHorizontalWheelEvents == canShortCircuitHorizontalWheelEvents)
3713 m_canShortCircuitHorizontalWheelEvents = canShortCircuitHorizontalWheelEvents;
3714 send(Messages::WebPageProxy::SetCanShortCircuitHorizontalWheelEvents(m_canShortCircuitHorizontalWheelEvents));
3717 Frame* WebPage::mainFrame() const
3719 return m_page ? m_page->mainFrame() : 0;
3722 FrameView* WebPage::mainFrameView() const
3724 if (Frame* frame = mainFrame())
3725 return frame->view();
3730 #if ENABLE(PAGE_VISIBILITY_API)
3731 void WebPage::setVisibilityState(int visibilityState, bool isInitialState)
3736 WebCore::PageVisibilityState state = static_cast<WebCore::PageVisibilityState>(visibilityState);
3738 if (m_visibilityState == state)
3741 FrameView* view = m_page->mainFrame() ? m_page->mainFrame()->view() : 0;
3743 if (state == WebCore::PageVisibilityStateVisible) {
3744 m_page->didMoveOnscreen();
3749 m_page->setVisibilityState(state, isInitialState);
3750 m_visibilityState = state;
3752 if (state == WebCore::PageVisibilityStateHidden) {
3753 m_page->willMoveOffscreen();
3760 #if ENABLE(TIZEN_NATIVE_MEMORY_SNAPSHOT)
3761 const char* dumpFileName = "/tmp/webkit_memory";
3764 void dumpMemorySnapshotForUrl(char* url)
3766 PrintFormat format = PRINT_FORMAT_JSON;
3768 fp = fopen(dumpFileName, "a");
3770 if (format == PRINT_FORMAT_JSON)
3773 fprintf(fp, "URL:%s\n", url);
3774 fprintf(fp, "%s", memoryPage(format).utf8().data());
3775 if (format == PRINT_FORMAT_JSON)
3776 fprintf(fp, "\"URL\":\"%s\"}\n", url);
3782 void dumpMemorySnapshot()
3784 dumpMemorySnapshotForUrl(lastUrl);
3787 void WebPage::dumpMemorySnapshot()
3789 char* url = strdup(mainWebFrame()->url().utf8().data());
3796 } // namespace WebKit