2 Copyright (C) 2010 Robert Hogan <robert@roberthogan.net>
3 Copyright (C) 2008,2009,2010 Nokia Corporation and/or its subsidiary(-ies)
4 Copyright (C) 2007 Staikos Computing Services Inc.
5 Copyright (C) 2007 Apple Inc.
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
24 #include "DumpRenderTreeSupportQt.h"
26 #include "ApplicationCacheStorage.h"
27 #include "CSSComputedStyleDeclaration.h"
28 #include "ChromeClientQt.h"
29 #include "ContainerNode.h"
30 #include "ContextMenu.h"
31 #include "ContextMenuClientQt.h"
32 #include "ContextMenuController.h"
33 #include "DeviceOrientation.h"
34 #include "DeviceOrientationClientMockQt.h"
35 #include "DocumentLoader.h"
37 #include "EditorClientQt.h"
39 #include "FocusController.h"
41 #include "FrameLoaderClientQt.h"
42 #include "FrameView.h"
44 #include "GCController.h"
46 #include "V8GCController.h"
49 #include "GeolocationClient.h"
50 #include "GeolocationClientMock.h"
51 #include "GeolocationController.h"
52 #include "GeolocationError.h"
53 #include "GeolocationPosition.h"
54 #include "HistoryItem.h"
55 #include "HTMLInputElement.h"
56 #include "InspectorController.h"
58 #include "NotificationPresenterClientQt.h"
60 #include "PageGroup.h"
61 #include "PluginDatabase.h"
62 #include "PositionError.h"
63 #include "PrintContext.h"
64 #include "RenderListItem.h"
65 #include "RenderTreeAsText.h"
66 #include "ScriptController.h"
67 #include "SecurityOrigin.h"
70 #include "SVGDocumentExtensions.h"
71 #include "SVGSMILElement.h"
73 #include "TextIterator.h"
74 #include "WorkerThread.h"
75 #include <wtf/CurrentTime.h>
77 #include "qwebelement.h"
78 #include "qwebframe.h"
79 #include "qwebframe_p.h"
80 #include "qwebhistory.h"
81 #include "qwebhistory_p.h"
83 #include "qwebpage_p.h"
84 #include "qwebscriptworld.h"
86 #if ENABLE(VIDEO) && USE(QT_MULTIMEDIA)
87 #include "HTMLVideoElement.h"
88 #include "MediaPlayerPrivateQt.h"
91 using namespace WebCore;
93 QMap<int, QWebScriptWorld*> m_worldMap;
95 #if ENABLE(CLIENT_BASED_GEOLOCATION)
96 GeolocationClientMock* toGeolocationClientMock(GeolocationClient* client)
98 ASSERT(QWebPagePrivate::drtRun);
99 return static_cast<GeolocationClientMock*>(client);
108 QDRTNode::QDRTNode(WebCore::Node* node)
117 QDRTNode::~QDRTNode()
123 QDRTNode::QDRTNode(const QDRTNode& other)
124 :m_node(other.m_node)
130 QDRTNode& QDRTNode::operator=(const QDRTNode& other)
132 if (this != &other) {
133 Node* otherNode = other.m_node;
144 DumpRenderTreeSupportQt::DumpRenderTreeSupportQt()
148 DumpRenderTreeSupportQt::~DumpRenderTreeSupportQt()
152 void DumpRenderTreeSupportQt::overwritePluginDirectories()
154 PluginDatabase* db = PluginDatabase::installedPlugins(/* populate */ false);
156 Vector<String> paths;
157 String qtPath(qgetenv("QTWEBKIT_PLUGIN_PATH").data());
158 qtPath.split(UChar(':'), /* allowEmptyEntries */ false, paths);
160 db->setPluginDirectories(paths);
164 int DumpRenderTreeSupportQt::workerThreadCount()
167 return WebCore::WorkerThread::workerThreadCount();
173 void DumpRenderTreeSupportQt::setDumpRenderTreeModeEnabled(bool b)
175 QWebPagePrivate::drtRun = b;
178 void DumpRenderTreeSupportQt::setFrameFlatteningEnabled(QWebPage* page, bool enabled)
180 QWebPagePrivate::core(page)->settings()->setFrameFlatteningEnabled(enabled);
183 void DumpRenderTreeSupportQt::webPageSetGroupName(QWebPage* page, const QString& groupName)
185 page->handle()->page->setGroupName(groupName);
188 QString DumpRenderTreeSupportQt::webPageGroupName(QWebPage* page)
190 return page->handle()->page->groupName();
193 void DumpRenderTreeSupportQt::webInspectorExecuteScript(QWebPage* page, long callId, const QString& script)
195 #if ENABLE(INSPECTOR)
196 if (!page->handle()->page->inspectorController())
198 page->handle()->page->inspectorController()->evaluateForTestInFrontend(callId, script);
202 void DumpRenderTreeSupportQt::webInspectorClose(QWebPage* page)
204 #if ENABLE(INSPECTOR)
205 if (!page->handle()->page->inspectorController())
207 page->handle()->page->inspectorController()->close();
211 void DumpRenderTreeSupportQt::webInspectorShow(QWebPage* page)
213 #if ENABLE(INSPECTOR)
214 if (!page->handle()->page->inspectorController())
216 page->handle()->page->inspectorController()->show();
220 void DumpRenderTreeSupportQt::setTimelineProfilingEnabled(QWebPage* page, bool enabled)
222 #if ENABLE(INSPECTOR)
223 InspectorController* controller = page->handle()->page->inspectorController();
227 controller->startTimelineProfiler();
229 controller->stopTimelineProfiler();
233 bool DumpRenderTreeSupportQt::hasDocumentElement(QWebFrame* frame)
235 return QWebFramePrivate::core(frame)->document()->documentElement();
238 void DumpRenderTreeSupportQt::setJavaScriptProfilingEnabled(QWebFrame* frame, bool enabled)
240 #if ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
241 Frame* coreFrame = QWebFramePrivate::core(frame);
242 InspectorController* controller = coreFrame->page()->inspectorController();
246 controller->enableProfiler();
248 controller->disableProfiler();
252 // Pause a given CSS animation or transition on the target node at a specific time.
253 // If the animation or transition is already paused, it will update its pause time.
254 // This method is only intended to be used for testing the CSS animation and transition system.
255 bool DumpRenderTreeSupportQt::pauseAnimation(QWebFrame *frame, const QString &animationName, double time, const QString &elementId)
257 Frame* coreFrame = QWebFramePrivate::core(frame);
261 AnimationController* controller = coreFrame->animation();
265 Document* doc = coreFrame->document();
268 Node* coreNode = doc->getElementById(elementId);
269 if (!coreNode || !coreNode->renderer())
272 return controller->pauseAnimationAtTime(coreNode->renderer(), animationName, time);
275 bool DumpRenderTreeSupportQt::pauseTransitionOfProperty(QWebFrame *frame, const QString &propertyName, double time, const QString &elementId)
277 Frame* coreFrame = QWebFramePrivate::core(frame);
281 AnimationController* controller = coreFrame->animation();
285 Document* doc = coreFrame->document();
288 Node* coreNode = doc->getElementById(elementId);
289 if (!coreNode || !coreNode->renderer())
292 return controller->pauseTransitionAtTime(coreNode->renderer(), propertyName, time);
295 // Pause a given SVG animation on the target node at a specific time.
296 // This method is only intended to be used for testing the SVG animation system.
297 bool DumpRenderTreeSupportQt::pauseSVGAnimation(QWebFrame *frame, const QString &animationId, double time, const QString &elementId)
302 Frame* coreFrame = QWebFramePrivate::core(frame);
306 Document* doc = coreFrame->document();
309 if (!doc->svgExtensions())
312 Node* coreNode = doc->getElementById(animationId);
313 if (!coreNode || !SVGSMILElement::isSMILElement(coreNode))
316 return doc->accessSVGExtensions()->sampleAnimationAtTime(elementId, static_cast<SVGSMILElement*>(coreNode), time);
320 // Returns the total number of currently running animations (includes both CSS transitions and CSS animations).
321 int DumpRenderTreeSupportQt::numberOfActiveAnimations(QWebFrame *frame)
323 Frame* coreFrame = QWebFramePrivate::core(frame);
327 AnimationController* controller = coreFrame->animation();
331 return controller->numberOfActiveAnimations();
334 void DumpRenderTreeSupportQt::suspendAnimations(QWebFrame *frame)
336 Frame* coreFrame = QWebFramePrivate::core(frame);
340 AnimationController* controller = coreFrame->animation();
344 controller->suspendAnimations();
347 void DumpRenderTreeSupportQt::resumeAnimations(QWebFrame *frame)
349 Frame* coreFrame = QWebFramePrivate::core(frame);
353 AnimationController* controller = coreFrame->animation();
357 controller->resumeAnimations();
360 void DumpRenderTreeSupportQt::clearFrameName(QWebFrame* frame)
362 Frame* coreFrame = QWebFramePrivate::core(frame);
363 coreFrame->tree()->clearName();
366 int DumpRenderTreeSupportQt::javaScriptObjectsCount()
369 return JSDOMWindowBase::commonJSGlobalData()->heap.globalObjectCount();
371 // FIXME: Find a way to do this using V8.
376 void DumpRenderTreeSupportQt::garbageCollectorCollect()
379 gcController().garbageCollectNow();
381 v8::V8::LowMemoryNotification();
385 void DumpRenderTreeSupportQt::garbageCollectorCollectOnAlternateThread(bool waitUntilDone)
388 gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
390 // FIXME: Find a way to do this using V8.
391 garbageCollectorCollect();
395 // Returns the value of counter in the element specified by \a id.
396 QString DumpRenderTreeSupportQt::counterValueForElementById(QWebFrame* frame, const QString& id)
398 Frame* coreFrame = QWebFramePrivate::core(frame);
399 if (Document* document = coreFrame->document()) {
400 if (Element* element = document->getElementById(id))
401 return WebCore::counterValueForElement(element);
406 int DumpRenderTreeSupportQt::pageNumberForElementById(QWebFrame* frame, const QString& id, float width, float height)
408 Frame* coreFrame = QWebFramePrivate::core(frame);
412 Element* element = coreFrame->document()->getElementById(AtomicString(id));
416 return PrintContext::pageNumberForElement(element, FloatSize(width, height));
419 int DumpRenderTreeSupportQt::numberOfPages(QWebFrame* frame, float width, float height)
421 Frame* coreFrame = QWebFramePrivate::core(frame);
425 return PrintContext::numberOfPages(coreFrame, FloatSize(width, height));
428 // Suspend active DOM objects in this frame.
429 void DumpRenderTreeSupportQt::suspendActiveDOMObjects(QWebFrame* frame)
431 Frame* coreFrame = QWebFramePrivate::core(frame);
432 if (coreFrame->document())
433 // FIXME: This function should be changed take a ReasonForSuspension parameter
434 // https://bugs.webkit.org/show_bug.cgi?id=45732
435 coreFrame->document()->suspendActiveDOMObjects(ActiveDOMObject::JavaScriptDebuggerPaused);
438 // Resume active DOM objects in this frame.
439 void DumpRenderTreeSupportQt::resumeActiveDOMObjects(QWebFrame* frame)
441 Frame* coreFrame = QWebFramePrivate::core(frame);
442 if (coreFrame->document())
443 coreFrame->document()->resumeActiveDOMObjects();
446 void DumpRenderTreeSupportQt::whiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains)
448 SecurityOrigin::addOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
451 void DumpRenderTreeSupportQt::removeWhiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains)
453 SecurityOrigin::removeOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
456 void DumpRenderTreeSupportQt::resetOriginAccessWhiteLists()
458 SecurityOrigin::resetOriginAccessWhitelists();
461 void DumpRenderTreeSupportQt::setDomainRelaxationForbiddenForURLScheme(bool forbidden, const QString& scheme)
463 SecurityOrigin::setDomainRelaxationForbiddenForURLScheme(forbidden, scheme);
466 void DumpRenderTreeSupportQt::setCaretBrowsingEnabled(QWebPage* page, bool value)
468 page->handle()->page->settings()->setCaretBrowsingEnabled(value);
471 void DumpRenderTreeSupportQt::setMediaType(QWebFrame* frame, const QString& type)
473 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
474 WebCore::FrameView* view = coreFrame->view();
475 view->setMediaType(type);
476 coreFrame->document()->styleSelectorChanged(RecalcStyleImmediately);
480 void DumpRenderTreeSupportQt::setSmartInsertDeleteEnabled(QWebPage* page, bool enabled)
482 page->d->smartInsertDeleteEnabled = enabled;
486 void DumpRenderTreeSupportQt::setSelectTrailingWhitespaceEnabled(QWebPage* page, bool enabled)
488 page->d->selectTrailingWhitespaceEnabled = enabled;
492 void DumpRenderTreeSupportQt::executeCoreCommandByName(QWebPage* page, const QString& name, const QString& value)
494 page->handle()->page->focusController()->focusedOrMainFrame()->editor()->command(name).execute(value);
497 bool DumpRenderTreeSupportQt::isCommandEnabled(QWebPage* page, const QString& name)
499 return page->handle()->page->focusController()->focusedOrMainFrame()->editor()->command(name).isEnabled();
502 bool DumpRenderTreeSupportQt::findString(QWebPage* page, const QString& string, const QStringList& optionArray)
504 // 1. Parse the options from the array
505 WebCore::FindOptions options = 0;
506 const int optionCount = optionArray.size();
507 for (int i = 0; i < optionCount; ++i) {
508 const QString& option = optionArray.at(i);
509 if (option == QLatin1String("CaseInsensitive"))
510 options |= WebCore::CaseInsensitive;
511 else if (option == QLatin1String("AtWordStarts"))
512 options |= WebCore::AtWordStarts;
513 else if (option == QLatin1String("TreatMedialCapitalAsWordStart"))
514 options |= WebCore::TreatMedialCapitalAsWordStart;
515 else if (option == QLatin1String("Backwards"))
516 options |= WebCore::Backwards;
517 else if (option == QLatin1String("WrapAround"))
518 options |= WebCore::WrapAround;
519 else if (option == QLatin1String("StartInSelection"))
520 options |= WebCore::StartInSelection;
523 // 2. find the string
524 WebCore::Frame* frame = page->handle()->page->focusController()->focusedOrMainFrame();
525 return frame && frame->editor()->findString(string, options);
528 QString DumpRenderTreeSupportQt::markerTextForListItem(const QWebElement& listItem)
530 return WebCore::markerTextForListItem(listItem.m_element);
533 static QString convertToPropertyName(const QString& name)
535 QStringList parts = name.split(QLatin1Char('-'));
536 QString camelCaseName;
537 for (int j = 0; j < parts.count(); ++j) {
538 QString part = parts.at(j);
540 camelCaseName.append(part.replace(0, 1, part.left(1).toUpper()));
542 camelCaseName.append(part);
544 return camelCaseName;
547 QVariantMap DumpRenderTreeSupportQt::computedStyleIncludingVisitedInfo(const QWebElement& element)
551 WebCore::Element* webElement = element.m_element;
555 RefPtr<WebCore::CSSComputedStyleDeclaration> style = computedStyle(webElement, true);
556 for (int i = 0; i < style->length(); i++) {
557 QString name = style->item(i);
558 QString value = (static_cast<WebCore::CSSStyleDeclaration*>(style.get()))->getPropertyValue(name);
559 res[convertToPropertyName(name)] = QVariant(value);
564 QVariantList DumpRenderTreeSupportQt::selectedRange(QWebPage* page)
566 WebCore::Frame* frame = page->handle()->page->focusController()->focusedOrMainFrame();
567 QVariantList selectedRange;
568 RefPtr<Range> range = frame->selection()->toNormalizedRange().get();
570 Element* selectionRoot = frame->selection()->rootEditableElement();
571 Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement();
573 RefPtr<Range> testRange = Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset());
574 ASSERT(testRange->startContainer() == scope);
575 int startPosition = TextIterator::rangeLength(testRange.get());
578 testRange->setEnd(range->endContainer(), range->endOffset(), ec);
579 ASSERT(testRange->startContainer() == scope);
580 int endPosition = TextIterator::rangeLength(testRange.get());
582 selectedRange << startPosition << (endPosition - startPosition);
584 return selectedRange;
588 QVariantList DumpRenderTreeSupportQt::firstRectForCharacterRange(QWebPage* page, int location, int length)
590 WebCore::Frame* frame = page->handle()->page->focusController()->focusedOrMainFrame();
593 if ((location + length < location) && (location + length))
596 Element* selectionRoot = frame->selection()->rootEditableElement();
597 Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement();
598 RefPtr<Range> range = TextIterator::rangeFromLocationAndLength(scope, location, length);
601 return QVariantList();
603 QRect resultRect = frame->editor()->firstRectForRange(range.get());
604 rect << resultRect.x() << resultRect.y() << resultRect.width() << resultRect.height();
608 bool DumpRenderTreeSupportQt::elementDoesAutoCompleteForElementWithId(QWebFrame* frame, const QString& elementId)
610 Frame* coreFrame = QWebFramePrivate::core(frame);
614 Document* doc = coreFrame->document();
617 Node* coreNode = doc->getElementById(elementId);
618 if (!coreNode || !coreNode->renderer())
621 HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(coreNode);
623 return inputElement->isTextField() && !inputElement->isPasswordField() && inputElement->autoComplete();
626 void DumpRenderTreeSupportQt::setEditingBehavior(QWebPage* page, const QString& editingBehavior)
628 WebCore::EditingBehaviorType coreEditingBehavior;
630 if (editingBehavior == QLatin1String("win"))
631 coreEditingBehavior = EditingWindowsBehavior;
632 else if (editingBehavior == QLatin1String("mac"))
633 coreEditingBehavior = EditingMacBehavior;
634 else if (editingBehavior == QLatin1String("unix"))
635 coreEditingBehavior = EditingUnixBehavior;
637 ASSERT_NOT_REACHED();
641 Page* corePage = QWebPagePrivate::core(page);
645 corePage->settings()->setEditingBehaviorType(coreEditingBehavior);
648 void DumpRenderTreeSupportQt::clearAllApplicationCaches()
650 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
651 WebCore::cacheStorage().empty();
652 WebCore::cacheStorage().vacuumDatabaseFile();
656 void DumpRenderTreeSupportQt::dumpFrameLoader(bool b)
658 FrameLoaderClientQt::dumpFrameLoaderCallbacks = b;
661 void DumpRenderTreeSupportQt::dumpUserGestureInFrameLoader(bool b)
663 FrameLoaderClientQt::dumpUserGestureInFrameLoaderCallbacks = b;
666 void DumpRenderTreeSupportQt::dumpResourceLoadCallbacks(bool b)
668 FrameLoaderClientQt::dumpResourceLoadCallbacks = b;
671 void DumpRenderTreeSupportQt::dumpResourceLoadCallbacksPath(const QString& path)
673 FrameLoaderClientQt::dumpResourceLoadCallbacksPath = path;
676 void DumpRenderTreeSupportQt::dumpResourceResponseMIMETypes(bool b)
678 FrameLoaderClientQt::dumpResourceResponseMIMETypes = b;
681 void DumpRenderTreeSupportQt::setWillSendRequestReturnsNullOnRedirect(bool b)
683 FrameLoaderClientQt::sendRequestReturnsNullOnRedirect = b;
686 void DumpRenderTreeSupportQt::setWillSendRequestReturnsNull(bool b)
688 FrameLoaderClientQt::sendRequestReturnsNull = b;
691 void DumpRenderTreeSupportQt::setWillSendRequestClearHeaders(const QStringList& headers)
693 FrameLoaderClientQt::sendRequestClearHeaders = headers;
696 void DumpRenderTreeSupportQt::setDeferMainResourceDataLoad(bool b)
698 FrameLoaderClientQt::deferMainResourceDataLoad = b;
701 void DumpRenderTreeSupportQt::setCustomPolicyDelegate(bool enabled, bool permissive)
703 FrameLoaderClientQt::policyDelegateEnabled = enabled;
704 FrameLoaderClientQt::policyDelegatePermissive = permissive;
707 void DumpRenderTreeSupportQt::dumpHistoryCallbacks(bool b)
709 FrameLoaderClientQt::dumpHistoryCallbacks = b;
712 void DumpRenderTreeSupportQt::dumpVisitedLinksCallbacks(bool b)
714 ChromeClientQt::dumpVisitedLinksCallbacks = b;
717 void DumpRenderTreeSupportQt::dumpEditingCallbacks(bool b)
719 EditorClientQt::dumpEditingCallbacks = b;
722 void DumpRenderTreeSupportQt::dumpSetAcceptsEditing(bool b)
724 EditorClientQt::acceptsEditing = b;
727 void DumpRenderTreeSupportQt::dumpNotification(bool b)
729 #if ENABLE(NOTIFICATIONS)
730 NotificationPresenterClientQt::dumpNotification = b;
734 QString DumpRenderTreeSupportQt::viewportAsText(QWebPage* page, int deviceDPI, const QSize& deviceSize, const QSize& availableSize)
736 WebCore::ViewportArguments args = page->d->viewportArguments();
738 WebCore::ViewportAttributes conf = WebCore::computeViewportAttributes(args,
739 /* desktop-width */ 980,
740 /* device-width */ deviceSize.width(),
741 /* device-height */ deviceSize.height(),
742 /* device-dpi */ deviceDPI,
746 res = res.sprintf("viewport size %dx%d scale %f with limits [%f, %f] and userScalable %f\n",
747 conf.layoutSize.width(),
748 conf.layoutSize.height(),
757 void DumpRenderTreeSupportQt::activeMockDeviceOrientationClient(bool b)
759 #if ENABLE(DEVICE_ORIENTATION)
760 DeviceOrientationClientMockQt::mockIsActive = b;
764 void DumpRenderTreeSupportQt::removeMockDeviceOrientation()
766 #if ENABLE(DEVICE_ORIENTATION)
767 DeviceOrientationClientMockQt* client = DeviceOrientationClientMockQt::client();
772 void DumpRenderTreeSupportQt::setMockDeviceOrientation(bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma)
774 #if ENABLE(DEVICE_ORIENTATION)
775 DeviceOrientationClientMockQt::client()->setOrientation(canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma);
779 void DumpRenderTreeSupportQt::resetGeolocationMock(QWebPage* page)
781 #if ENABLE(CLIENT_BASED_GEOLOCATION)
782 Page* corePage = QWebPagePrivate::core(page);
783 GeolocationClientMock* mockClient = toGeolocationClientMock(corePage->geolocationController()->client());
788 void DumpRenderTreeSupportQt::setMockGeolocationPermission(QWebPage* page, bool allowed)
790 #if ENABLE(CLIENT_BASED_GEOLOCATION)
791 Page* corePage = QWebPagePrivate::core(page);
792 GeolocationClientMock* mockClient = toGeolocationClientMock(corePage->geolocationController()->client());
793 mockClient->setPermission(allowed);
797 void DumpRenderTreeSupportQt::setMockGeolocationPosition(QWebPage* page, double latitude, double longitude, double accuracy)
799 #if ENABLE(CLIENT_BASED_GEOLOCATION)
800 Page* corePage = QWebPagePrivate::core(page);
801 GeolocationClientMock* mockClient = toGeolocationClientMock(corePage->geolocationController()->client());
802 mockClient->setPosition(GeolocationPosition::create(currentTime(), latitude, longitude, accuracy));
806 void DumpRenderTreeSupportQt::setMockGeolocationError(QWebPage* page, int errorCode, const QString& message)
808 #if ENABLE(CLIENT_BASED_GEOLOCATION)
809 Page* corePage = QWebPagePrivate::core(page);
811 GeolocationError::ErrorCode code = GeolocationError::PositionUnavailable;
813 case PositionError::PERMISSION_DENIED:
814 code = GeolocationError::PermissionDenied;
816 case PositionError::POSITION_UNAVAILABLE:
817 code = GeolocationError::PositionUnavailable;
821 GeolocationClientMock* mockClient = static_cast<GeolocationClientMock*>(corePage->geolocationController()->client());
822 mockClient->setError(GeolocationError::create(code, message));
826 int DumpRenderTreeSupportQt::numberOfPendingGeolocationPermissionRequests(QWebPage* page)
828 #if ENABLE(CLIENT_BASED_GEOLOCATION)
829 Page* corePage = QWebPagePrivate::core(page);
830 GeolocationClientMock* mockClient = toGeolocationClientMock(corePage->geolocationController()->client());
831 return mockClient->numberOfPendingPermissionRequests();
837 bool DumpRenderTreeSupportQt::isTargetItem(const QWebHistoryItem& historyItem)
839 QWebHistoryItem it = historyItem;
840 if (QWebHistoryItemPrivate::core(&it)->isTargetItem())
845 QString DumpRenderTreeSupportQt::historyItemTarget(const QWebHistoryItem& historyItem)
847 QWebHistoryItem it = historyItem;
848 return (QWebHistoryItemPrivate::core(&it)->target());
851 QMap<QString, QWebHistoryItem> DumpRenderTreeSupportQt::getChildHistoryItems(const QWebHistoryItem& historyItem)
853 QWebHistoryItem it = historyItem;
854 HistoryItem* item = QWebHistoryItemPrivate::core(&it);
855 const WebCore::HistoryItemVector& children = item->children();
857 unsigned size = children.size();
858 QMap<QString, QWebHistoryItem> kids;
859 for (unsigned i = 0; i < size; ++i) {
860 QWebHistoryItem kid(new QWebHistoryItemPrivate(children[i].get()));
861 kids.insert(DumpRenderTreeSupportQt::historyItemTarget(kid), kid);
866 bool DumpRenderTreeSupportQt::shouldClose(QWebFrame* frame)
868 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
869 return coreFrame->loader()->shouldClose();
872 void DumpRenderTreeSupportQt::clearScriptWorlds()
877 void DumpRenderTreeSupportQt::evaluateScriptInIsolatedWorld(QWebFrame* frame, int worldID, const QString& script)
879 QWebScriptWorld* scriptWorld;
881 scriptWorld = new QWebScriptWorld();
882 } else if (!m_worldMap.contains(worldID)) {
883 scriptWorld = new QWebScriptWorld();
884 m_worldMap.insert(worldID, scriptWorld);
886 scriptWorld = m_worldMap.value(worldID);
888 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
890 ScriptController* proxy = coreFrame->script();
895 proxy->executeScriptInWorld(scriptWorld->world(), script, true);
897 ScriptSourceCode source(script);
898 Vector<ScriptSourceCode> sources;
899 sources.append(source);
900 proxy->evaluateInIsolatedWorld(0, sources, true);
904 bool DumpRenderTreeSupportQt::isPageBoxVisible(QWebFrame* frame, int pageIndex)
906 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
907 return coreFrame->document()->isPageBoxVisible(pageIndex);
910 QString DumpRenderTreeSupportQt::pageSizeAndMarginsInPixels(QWebFrame* frame, int pageIndex, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft)
912 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
913 return PrintContext::pageSizeAndMarginsInPixels(coreFrame, pageIndex, width, height,
914 marginTop, marginRight, marginBottom, marginLeft);
917 QString DumpRenderTreeSupportQt::pageProperty(QWebFrame* frame, const QString& propertyName, int pageNumber)
919 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
920 return PrintContext::pageProperty(coreFrame, propertyName.toUtf8().constData(), pageNumber);
923 void DumpRenderTreeSupportQt::addUserStyleSheet(QWebPage* page, const QString& sourceCode)
925 page->handle()->page->group().addUserStyleSheetToWorld(mainThreadNormalWorld(), sourceCode, QUrl(), 0, 0, WebCore::InjectInAllFrames);
928 void DumpRenderTreeSupportQt::simulateDesktopNotificationClick(const QString& title)
930 #if ENABLE(NOTIFICATIONS)
931 NotificationPresenterClientQt::notificationPresenter()->notificationClicked(title);
935 QString DumpRenderTreeSupportQt::plainText(const QVariant& range)
937 QMap<QString, QVariant> map = range.toMap();
938 QVariant startContainer = map.value(QLatin1String("startContainer"));
939 map = startContainer.toMap();
941 return map.value(QLatin1String("innerText")).toString();
944 QVariantList DumpRenderTreeSupportQt::nodesFromRect(const QWebElement& document, int x, int y, unsigned top, unsigned right, unsigned bottom, unsigned left, bool ignoreClipping)
947 WebCore::Element* webElement = document.m_element;
951 Document* doc = webElement->document();
954 RefPtr<NodeList> nodes = doc->nodesFromRect(x, y, top, right, bottom, left, ignoreClipping);
955 for (int i = 0; i < nodes->length(); i++) {
956 // QWebElement will be null if the Node is not an HTML Element
957 if (nodes->item(i)->isHTMLElement())
958 res << QVariant::fromValue(QWebElement(nodes->item(i)));
960 res << QVariant::fromValue(QDRTNode(nodes->item(i)));
966 QString DumpRenderTreeSupportQt::responseMimeType(QWebFrame* frame)
968 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
969 WebCore::DocumentLoader* docLoader = coreFrame->loader()->documentLoader();
970 return docLoader->responseMIMEType();
973 void DumpRenderTreeSupportQt::clearOpener(QWebFrame* frame)
975 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
976 coreFrame->loader()->setOpener(0);
979 void DumpRenderTreeSupportQt::addURLToRedirect(const QString& origin, const QString& destination)
981 FrameLoaderClientQt::URLsToRedirect[origin] = destination;
984 static QStringList iterateContextMenu(QMenu* menu)
987 return QStringList();
990 QList<QAction *> actions = menu->actions();
991 for (int i = 0; i < actions.count(); ++i) {
992 if (actions.at(i)->isSeparator())
993 items << QLatin1String("<separator>");
995 items << actions.at(i)->text();
996 if (actions.at(i)->menu())
997 items << iterateContextMenu(actions.at(i)->menu());
1002 QStringList DumpRenderTreeSupportQt::contextMenu(QWebPage* page)
1004 #ifndef QT_NO_CONTEXTMENU
1005 return iterateContextMenu(page->d->currentContextMenu);
1007 return QStringList();
1011 double DumpRenderTreeSupportQt::defaultMinimumTimerInterval()
1013 return Settings::defaultMinDOMTimerInterval();
1016 void DumpRenderTreeSupportQt::setMinimumTimerInterval(QWebPage* page, double interval)
1018 Page* corePage = QWebPagePrivate::core(page);
1022 corePage->settings()->setMinDOMTimerInterval(interval);
1025 QUrl DumpRenderTreeSupportQt::mediaContentUrlByElementId(QWebFrame* frame, const QString& elementId)
1029 #if ENABLE(VIDEO) && USE(QT_MULTIMEDIA)
1030 Frame* coreFrame = QWebFramePrivate::core(frame);
1034 Document* doc = coreFrame->document();
1038 Node* coreNode = doc->getElementById(elementId);
1042 HTMLVideoElement* videoElement = static_cast<HTMLVideoElement*>(coreNode);
1043 PlatformMedia platformMedia = videoElement->platformMedia();
1044 if (platformMedia.type != PlatformMedia::QtMediaPlayerType)
1047 MediaPlayerPrivateQt* mediaPlayerQt = static_cast<MediaPlayerPrivateQt*>(platformMedia.media.qtMediaPlayer);
1048 if (mediaPlayerQt && mediaPlayerQt->mediaPlayer())
1049 res = mediaPlayerQt->mediaPlayer()->media().canonicalUrl();
1056 void DumpRenderTreeSupportQt::setAlternateHtml(QWebFrame* frame, const QString& html, const QUrl& baseUrl, const QUrl& failingUrl)
1059 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
1060 WebCore::ResourceRequest request(kurl);
1061 const QByteArray utf8 = html.toUtf8();
1062 WTF::RefPtr<WebCore::SharedBuffer> data = WebCore::SharedBuffer::create(utf8.constData(), utf8.length());
1063 WebCore::SubstituteData substituteData(data, WTF::String("text/html"), WTF::String("utf-8"), failingUrl);
1064 coreFrame->loader()->load(request, substituteData, false);
1067 QVariant DumpRenderTreeSupportQt::shadowRoot(const QWebElement& element)
1069 WebCore::Element* webElement = element.m_element;
1073 ContainerNode* webShadowRoot = webElement->shadowRoot();
1077 return QVariant::fromValue(QDRTNode(webShadowRoot));
1080 // Provide a backward compatibility with previously exported private symbols as of QtWebKit 4.6 release
1082 void QWEBKIT_EXPORT qt_resumeActiveDOMObjects(QWebFrame* frame)
1084 DumpRenderTreeSupportQt::resumeActiveDOMObjects(frame);
1087 void QWEBKIT_EXPORT qt_suspendActiveDOMObjects(QWebFrame* frame)
1089 DumpRenderTreeSupportQt::suspendActiveDOMObjects(frame);
1092 void QWEBKIT_EXPORT qt_drt_clearFrameName(QWebFrame* frame)
1094 DumpRenderTreeSupportQt::clearFrameName(frame);
1097 void QWEBKIT_EXPORT qt_drt_garbageCollector_collect()
1099 DumpRenderTreeSupportQt::garbageCollectorCollect();
1102 void QWEBKIT_EXPORT qt_drt_garbageCollector_collectOnAlternateThread(bool waitUntilDone)
1104 DumpRenderTreeSupportQt::garbageCollectorCollectOnAlternateThread(waitUntilDone);
1107 int QWEBKIT_EXPORT qt_drt_javaScriptObjectsCount()
1109 return DumpRenderTreeSupportQt::javaScriptObjectsCount();
1112 int QWEBKIT_EXPORT qt_drt_numberOfActiveAnimations(QWebFrame* frame)
1114 return DumpRenderTreeSupportQt::numberOfActiveAnimations(frame);
1117 void QWEBKIT_EXPORT qt_drt_overwritePluginDirectories()
1119 DumpRenderTreeSupportQt::overwritePluginDirectories();
1122 bool QWEBKIT_EXPORT qt_drt_pauseAnimation(QWebFrame* frame, const QString& animationName, double time, const QString& elementId)
1124 return DumpRenderTreeSupportQt::pauseAnimation(frame, animationName, time, elementId);
1127 bool QWEBKIT_EXPORT qt_drt_pauseTransitionOfProperty(QWebFrame* frame, const QString& propertyName, double time, const QString &elementId)
1129 return DumpRenderTreeSupportQt::pauseTransitionOfProperty(frame, propertyName, time, elementId);
1132 void QWEBKIT_EXPORT qt_drt_resetOriginAccessWhiteLists()
1134 DumpRenderTreeSupportQt::resetOriginAccessWhiteLists();
1137 void QWEBKIT_EXPORT qt_drt_run(bool b)
1139 DumpRenderTreeSupportQt::setDumpRenderTreeModeEnabled(b);
1142 void QWEBKIT_EXPORT qt_drt_setJavaScriptProfilingEnabled(QWebFrame* frame, bool enabled)
1144 DumpRenderTreeSupportQt::setJavaScriptProfilingEnabled(frame, enabled);
1147 void QWEBKIT_EXPORT qt_drt_whiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains)
1149 DumpRenderTreeSupportQt::whiteListAccessFromOrigin(sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains);
1152 QString QWEBKIT_EXPORT qt_webpage_groupName(QWebPage* page)
1154 return DumpRenderTreeSupportQt::webPageGroupName(page);
1157 void QWEBKIT_EXPORT qt_webpage_setGroupName(QWebPage* page, const QString& groupName)
1159 DumpRenderTreeSupportQt::webPageSetGroupName(page, groupName);
1162 void QWEBKIT_EXPORT qt_dump_frame_loader(bool b)
1164 DumpRenderTreeSupportQt::dumpFrameLoader(b);
1167 void QWEBKIT_EXPORT qt_dump_resource_load_callbacks(bool b)
1169 DumpRenderTreeSupportQt::dumpResourceLoadCallbacks(b);
1172 void QWEBKIT_EXPORT qt_dump_editing_callbacks(bool b)
1174 DumpRenderTreeSupportQt::dumpEditingCallbacks(b);
1177 void QWEBKIT_EXPORT qt_dump_set_accepts_editing(bool b)
1179 DumpRenderTreeSupportQt::dumpSetAcceptsEditing(b);