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 "ContextMenu.h"
30 #include "ContextMenuClientQt.h"
31 #include "ContextMenuController.h"
32 #include "DeviceOrientation.h"
33 #include "DeviceOrientationClientMockQt.h"
34 #include "DocumentLoader.h"
36 #include "EditorClientQt.h"
38 #include "FocusController.h"
40 #include "FrameLoaderClientQt.h"
41 #include "FrameView.h"
43 #include "GCController.h"
45 #include "V8GCController.h"
48 #include "GeolocationClient.h"
49 #include "GeolocationClientMock.h"
50 #include "GeolocationController.h"
51 #include "GeolocationError.h"
52 #include "GeolocationPosition.h"
53 #include "HistoryItem.h"
54 #include "HTMLInputElement.h"
55 #include "InspectorController.h"
57 #include "NotificationPresenterClientQt.h"
59 #include "PageGroup.h"
60 #include "PluginDatabase.h"
61 #include "PositionError.h"
62 #include "PrintContext.h"
63 #include "RenderListItem.h"
64 #include "RenderTreeAsText.h"
65 #include "ScriptController.h"
66 #include "SecurityOrigin.h"
69 #include "SVGDocumentExtensions.h"
70 #include "SVGSMILElement.h"
72 #include "TextIterator.h"
73 #include "WorkerThread.h"
74 #include <wtf/CurrentTime.h>
76 #include "qwebelement.h"
77 #include "qwebframe.h"
78 #include "qwebframe_p.h"
79 #include "qwebhistory.h"
80 #include "qwebhistory_p.h"
82 #include "qwebpage_p.h"
83 #include "qwebscriptworld.h"
85 #if ENABLE(VIDEO) && ENABLE(QT_MULTIMEDIA)
86 #include "HTMLVideoElement.h"
87 #include "MediaPlayerPrivateQt.h"
90 using namespace WebCore;
92 QMap<int, QWebScriptWorld*> m_worldMap;
94 #if ENABLE(CLIENT_BASED_GEOLOCATION)
95 GeolocationClientMock* toGeolocationClientMock(GeolocationClient* client)
97 ASSERT(QWebPagePrivate::drtRun);
98 return static_cast<GeolocationClientMock*>(client);
107 QDRTNode::QDRTNode(WebCore::Node* node)
116 QDRTNode::~QDRTNode()
122 QDRTNode::QDRTNode(const QDRTNode& other)
123 :m_node(other.m_node)
129 QDRTNode& QDRTNode::operator=(const QDRTNode& other)
131 if (this != &other) {
132 Node* otherNode = other.m_node;
143 DumpRenderTreeSupportQt::DumpRenderTreeSupportQt()
147 DumpRenderTreeSupportQt::~DumpRenderTreeSupportQt()
151 void DumpRenderTreeSupportQt::overwritePluginDirectories()
153 PluginDatabase* db = PluginDatabase::installedPlugins(/* populate */ false);
155 Vector<String> paths;
156 String qtPath(qgetenv("QTWEBKIT_PLUGIN_PATH").data());
157 qtPath.split(UChar(':'), /* allowEmptyEntries */ false, paths);
159 db->setPluginDirectories(paths);
163 int DumpRenderTreeSupportQt::workerThreadCount()
166 return WebCore::WorkerThread::workerThreadCount();
172 void DumpRenderTreeSupportQt::setDumpRenderTreeModeEnabled(bool b)
174 QWebPagePrivate::drtRun = b;
177 void DumpRenderTreeSupportQt::setFrameFlatteningEnabled(QWebPage* page, bool enabled)
179 QWebPagePrivate::core(page)->settings()->setFrameFlatteningEnabled(enabled);
182 void DumpRenderTreeSupportQt::webPageSetGroupName(QWebPage* page, const QString& groupName)
184 page->handle()->page->setGroupName(groupName);
187 QString DumpRenderTreeSupportQt::webPageGroupName(QWebPage* page)
189 return page->handle()->page->groupName();
192 void DumpRenderTreeSupportQt::webInspectorExecuteScript(QWebPage* page, long callId, const QString& script)
194 #if ENABLE(INSPECTOR)
195 if (!page->handle()->page->inspectorController())
197 page->handle()->page->inspectorController()->evaluateForTestInFrontend(callId, script);
201 void DumpRenderTreeSupportQt::webInspectorClose(QWebPage* page)
203 #if ENABLE(INSPECTOR)
204 if (!page->handle()->page->inspectorController())
206 page->handle()->page->inspectorController()->close();
210 void DumpRenderTreeSupportQt::webInspectorShow(QWebPage* page)
212 #if ENABLE(INSPECTOR)
213 if (!page->handle()->page->inspectorController())
215 page->handle()->page->inspectorController()->show();
219 void DumpRenderTreeSupportQt::setTimelineProfilingEnabled(QWebPage* page, bool enabled)
221 #if ENABLE(INSPECTOR)
222 InspectorController* controller = page->handle()->page->inspectorController();
226 controller->startTimelineProfiler();
228 controller->stopTimelineProfiler();
232 bool DumpRenderTreeSupportQt::hasDocumentElement(QWebFrame* frame)
234 return QWebFramePrivate::core(frame)->document()->documentElement();
237 void DumpRenderTreeSupportQt::setJavaScriptProfilingEnabled(QWebFrame* frame, bool enabled)
239 #if ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
240 Frame* coreFrame = QWebFramePrivate::core(frame);
241 InspectorController* controller = coreFrame->page()->inspectorController();
245 controller->enableProfiler();
247 controller->disableProfiler();
251 // Pause a given CSS animation or transition on the target node at a specific time.
252 // If the animation or transition is already paused, it will update its pause time.
253 // This method is only intended to be used for testing the CSS animation and transition system.
254 bool DumpRenderTreeSupportQt::pauseAnimation(QWebFrame *frame, const QString &animationName, double time, const QString &elementId)
256 Frame* coreFrame = QWebFramePrivate::core(frame);
260 AnimationController* controller = coreFrame->animation();
264 Document* doc = coreFrame->document();
267 Node* coreNode = doc->getElementById(elementId);
268 if (!coreNode || !coreNode->renderer())
271 return controller->pauseAnimationAtTime(coreNode->renderer(), animationName, time);
274 bool DumpRenderTreeSupportQt::pauseTransitionOfProperty(QWebFrame *frame, const QString &propertyName, double time, const QString &elementId)
276 Frame* coreFrame = QWebFramePrivate::core(frame);
280 AnimationController* controller = coreFrame->animation();
284 Document* doc = coreFrame->document();
287 Node* coreNode = doc->getElementById(elementId);
288 if (!coreNode || !coreNode->renderer())
291 return controller->pauseTransitionAtTime(coreNode->renderer(), propertyName, time);
294 // Pause a given SVG animation on the target node at a specific time.
295 // This method is only intended to be used for testing the SVG animation system.
296 bool DumpRenderTreeSupportQt::pauseSVGAnimation(QWebFrame *frame, const QString &animationId, double time, const QString &elementId)
301 Frame* coreFrame = QWebFramePrivate::core(frame);
305 Document* doc = coreFrame->document();
308 if (!doc->svgExtensions())
311 Node* coreNode = doc->getElementById(animationId);
312 if (!coreNode || !SVGSMILElement::isSMILElement(coreNode))
315 return doc->accessSVGExtensions()->sampleAnimationAtTime(elementId, static_cast<SVGSMILElement*>(coreNode), time);
319 // Returns the total number of currently running animations (includes both CSS transitions and CSS animations).
320 int DumpRenderTreeSupportQt::numberOfActiveAnimations(QWebFrame *frame)
322 Frame* coreFrame = QWebFramePrivate::core(frame);
326 AnimationController* controller = coreFrame->animation();
330 return controller->numberOfActiveAnimations();
333 void DumpRenderTreeSupportQt::suspendAnimations(QWebFrame *frame)
335 Frame* coreFrame = QWebFramePrivate::core(frame);
339 AnimationController* controller = coreFrame->animation();
343 controller->suspendAnimations();
346 void DumpRenderTreeSupportQt::resumeAnimations(QWebFrame *frame)
348 Frame* coreFrame = QWebFramePrivate::core(frame);
352 AnimationController* controller = coreFrame->animation();
356 controller->resumeAnimations();
359 void DumpRenderTreeSupportQt::clearFrameName(QWebFrame* frame)
361 Frame* coreFrame = QWebFramePrivate::core(frame);
362 coreFrame->tree()->clearName();
365 int DumpRenderTreeSupportQt::javaScriptObjectsCount()
368 return JSDOMWindowBase::commonJSGlobalData()->heap.globalObjectCount();
370 // FIXME: Find a way to do this using V8.
375 void DumpRenderTreeSupportQt::garbageCollectorCollect()
378 gcController().garbageCollectNow();
380 v8::V8::LowMemoryNotification();
384 void DumpRenderTreeSupportQt::garbageCollectorCollectOnAlternateThread(bool waitUntilDone)
387 gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
389 // FIXME: Find a way to do this using V8.
390 garbageCollectorCollect();
394 // Returns the value of counter in the element specified by \a id.
395 QString DumpRenderTreeSupportQt::counterValueForElementById(QWebFrame* frame, const QString& id)
397 Frame* coreFrame = QWebFramePrivate::core(frame);
398 if (Document* document = coreFrame->document()) {
399 if (Element* element = document->getElementById(id))
400 return WebCore::counterValueForElement(element);
405 int DumpRenderTreeSupportQt::pageNumberForElementById(QWebFrame* frame, const QString& id, float width, float height)
407 Frame* coreFrame = QWebFramePrivate::core(frame);
411 Element* element = coreFrame->document()->getElementById(AtomicString(id));
415 return PrintContext::pageNumberForElement(element, FloatSize(width, height));
418 int DumpRenderTreeSupportQt::numberOfPages(QWebFrame* frame, float width, float height)
420 Frame* coreFrame = QWebFramePrivate::core(frame);
424 return PrintContext::numberOfPages(coreFrame, FloatSize(width, height));
427 // Suspend active DOM objects in this frame.
428 void DumpRenderTreeSupportQt::suspendActiveDOMObjects(QWebFrame* frame)
430 Frame* coreFrame = QWebFramePrivate::core(frame);
431 if (coreFrame->document())
432 // FIXME: This function should be changed take a ReasonForSuspension parameter
433 // https://bugs.webkit.org/show_bug.cgi?id=45732
434 coreFrame->document()->suspendActiveDOMObjects(ActiveDOMObject::JavaScriptDebuggerPaused);
437 // Resume active DOM objects in this frame.
438 void DumpRenderTreeSupportQt::resumeActiveDOMObjects(QWebFrame* frame)
440 Frame* coreFrame = QWebFramePrivate::core(frame);
441 if (coreFrame->document())
442 coreFrame->document()->resumeActiveDOMObjects();
445 void DumpRenderTreeSupportQt::whiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains)
447 SecurityOrigin::addOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
450 void DumpRenderTreeSupportQt::removeWhiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains)
452 SecurityOrigin::removeOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
455 void DumpRenderTreeSupportQt::resetOriginAccessWhiteLists()
457 SecurityOrigin::resetOriginAccessWhitelists();
460 void DumpRenderTreeSupportQt::setDomainRelaxationForbiddenForURLScheme(bool forbidden, const QString& scheme)
462 SecurityOrigin::setDomainRelaxationForbiddenForURLScheme(forbidden, scheme);
465 void DumpRenderTreeSupportQt::setCaretBrowsingEnabled(QWebPage* page, bool value)
467 page->handle()->page->settings()->setCaretBrowsingEnabled(value);
470 void DumpRenderTreeSupportQt::setMediaType(QWebFrame* frame, const QString& type)
472 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
473 WebCore::FrameView* view = coreFrame->view();
474 view->setMediaType(type);
475 coreFrame->document()->styleSelectorChanged(RecalcStyleImmediately);
479 void DumpRenderTreeSupportQt::setSmartInsertDeleteEnabled(QWebPage* page, bool enabled)
481 page->d->smartInsertDeleteEnabled = enabled;
485 void DumpRenderTreeSupportQt::setSelectTrailingWhitespaceEnabled(QWebPage* page, bool enabled)
487 page->d->selectTrailingWhitespaceEnabled = enabled;
491 void DumpRenderTreeSupportQt::executeCoreCommandByName(QWebPage* page, const QString& name, const QString& value)
493 page->handle()->page->focusController()->focusedOrMainFrame()->editor()->command(name).execute(value);
496 bool DumpRenderTreeSupportQt::isCommandEnabled(QWebPage* page, const QString& name)
498 return page->handle()->page->focusController()->focusedOrMainFrame()->editor()->command(name).isEnabled();
501 bool DumpRenderTreeSupportQt::findString(QWebPage* page, const QString& string, const QStringList& optionArray)
503 // 1. Parse the options from the array
504 WebCore::FindOptions options = 0;
505 const int optionCount = optionArray.size();
506 for (int i = 0; i < optionCount; ++i) {
507 const QString& option = optionArray.at(i);
508 if (option == QLatin1String("CaseInsensitive"))
509 options |= WebCore::CaseInsensitive;
510 else if (option == QLatin1String("AtWordStarts"))
511 options |= WebCore::AtWordStarts;
512 else if (option == QLatin1String("TreatMedialCapitalAsWordStart"))
513 options |= WebCore::TreatMedialCapitalAsWordStart;
514 else if (option == QLatin1String("Backwards"))
515 options |= WebCore::Backwards;
516 else if (option == QLatin1String("WrapAround"))
517 options |= WebCore::WrapAround;
518 else if (option == QLatin1String("StartInSelection"))
519 options |= WebCore::StartInSelection;
522 // 2. find the string
523 WebCore::Frame* frame = page->handle()->page->focusController()->focusedOrMainFrame();
524 return frame && frame->editor()->findString(string, options);
527 QString DumpRenderTreeSupportQt::markerTextForListItem(const QWebElement& listItem)
529 return WebCore::markerTextForListItem(listItem.m_element);
532 static QString convertToPropertyName(const QString& name)
534 QStringList parts = name.split(QLatin1Char('-'));
535 QString camelCaseName;
536 for (int j = 0; j < parts.count(); ++j) {
537 QString part = parts.at(j);
539 camelCaseName.append(part.replace(0, 1, part.left(1).toUpper()));
541 camelCaseName.append(part);
543 return camelCaseName;
546 QVariantMap DumpRenderTreeSupportQt::computedStyleIncludingVisitedInfo(const QWebElement& element)
550 WebCore::Element* webElement = element.m_element;
554 RefPtr<WebCore::CSSComputedStyleDeclaration> style = computedStyle(webElement, true);
555 for (int i = 0; i < style->length(); i++) {
556 QString name = style->item(i);
557 QString value = (static_cast<WebCore::CSSStyleDeclaration*>(style.get()))->getPropertyValue(name);
558 res[convertToPropertyName(name)] = QVariant(value);
563 QVariantList DumpRenderTreeSupportQt::selectedRange(QWebPage* page)
565 WebCore::Frame* frame = page->handle()->page->focusController()->focusedOrMainFrame();
566 QVariantList selectedRange;
567 RefPtr<Range> range = frame->selection()->toNormalizedRange().get();
569 Element* selectionRoot = frame->selection()->rootEditableElement();
570 Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement();
572 RefPtr<Range> testRange = Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset());
573 ASSERT(testRange->startContainer() == scope);
574 int startPosition = TextIterator::rangeLength(testRange.get());
577 testRange->setEnd(range->endContainer(), range->endOffset(), ec);
578 ASSERT(testRange->startContainer() == scope);
579 int endPosition = TextIterator::rangeLength(testRange.get());
581 selectedRange << startPosition << (endPosition - startPosition);
583 return selectedRange;
587 QVariantList DumpRenderTreeSupportQt::firstRectForCharacterRange(QWebPage* page, int location, int length)
589 WebCore::Frame* frame = page->handle()->page->focusController()->focusedOrMainFrame();
592 if ((location + length < location) && (location + length))
595 Element* selectionRoot = frame->selection()->rootEditableElement();
596 Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement();
597 RefPtr<Range> range = TextIterator::rangeFromLocationAndLength(scope, location, length);
600 return QVariantList();
602 QRect resultRect = frame->editor()->firstRectForRange(range.get());
603 rect << resultRect.x() << resultRect.y() << resultRect.width() << resultRect.height();
607 bool DumpRenderTreeSupportQt::elementDoesAutoCompleteForElementWithId(QWebFrame* frame, const QString& elementId)
609 Frame* coreFrame = QWebFramePrivate::core(frame);
613 Document* doc = coreFrame->document();
616 Node* coreNode = doc->getElementById(elementId);
617 if (!coreNode || !coreNode->renderer())
620 HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(coreNode);
622 return inputElement->isTextField() && !inputElement->isPasswordField() && inputElement->autoComplete();
625 void DumpRenderTreeSupportQt::setEditingBehavior(QWebPage* page, const QString& editingBehavior)
627 WebCore::EditingBehaviorType coreEditingBehavior;
629 if (editingBehavior == QLatin1String("win"))
630 coreEditingBehavior = EditingWindowsBehavior;
631 else if (editingBehavior == QLatin1String("mac"))
632 coreEditingBehavior = EditingMacBehavior;
633 else if (editingBehavior == QLatin1String("unix"))
634 coreEditingBehavior = EditingUnixBehavior;
636 ASSERT_NOT_REACHED();
640 Page* corePage = QWebPagePrivate::core(page);
644 corePage->settings()->setEditingBehaviorType(coreEditingBehavior);
647 void DumpRenderTreeSupportQt::clearAllApplicationCaches()
649 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
650 WebCore::cacheStorage().empty();
651 WebCore::cacheStorage().vacuumDatabaseFile();
655 void DumpRenderTreeSupportQt::dumpFrameLoader(bool b)
657 FrameLoaderClientQt::dumpFrameLoaderCallbacks = b;
660 void DumpRenderTreeSupportQt::dumpUserGestureInFrameLoader(bool b)
662 FrameLoaderClientQt::dumpUserGestureInFrameLoaderCallbacks = b;
665 void DumpRenderTreeSupportQt::dumpResourceLoadCallbacks(bool b)
667 FrameLoaderClientQt::dumpResourceLoadCallbacks = b;
670 void DumpRenderTreeSupportQt::dumpResourceLoadCallbacksPath(const QString& path)
672 FrameLoaderClientQt::dumpResourceLoadCallbacksPath = path;
675 void DumpRenderTreeSupportQt::dumpResourceResponseMIMETypes(bool b)
677 FrameLoaderClientQt::dumpResourceResponseMIMETypes = b;
680 void DumpRenderTreeSupportQt::setWillSendRequestReturnsNullOnRedirect(bool b)
682 FrameLoaderClientQt::sendRequestReturnsNullOnRedirect = b;
685 void DumpRenderTreeSupportQt::setWillSendRequestReturnsNull(bool b)
687 FrameLoaderClientQt::sendRequestReturnsNull = b;
690 void DumpRenderTreeSupportQt::setWillSendRequestClearHeaders(const QStringList& headers)
692 FrameLoaderClientQt::sendRequestClearHeaders = headers;
695 void DumpRenderTreeSupportQt::setDeferMainResourceDataLoad(bool b)
697 FrameLoaderClientQt::deferMainResourceDataLoad = b;
700 void DumpRenderTreeSupportQt::setCustomPolicyDelegate(bool enabled, bool permissive)
702 FrameLoaderClientQt::policyDelegateEnabled = enabled;
703 FrameLoaderClientQt::policyDelegatePermissive = permissive;
706 void DumpRenderTreeSupportQt::dumpHistoryCallbacks(bool b)
708 FrameLoaderClientQt::dumpHistoryCallbacks = b;
711 void DumpRenderTreeSupportQt::dumpVisitedLinksCallbacks(bool b)
713 ChromeClientQt::dumpVisitedLinksCallbacks = b;
716 void DumpRenderTreeSupportQt::dumpEditingCallbacks(bool b)
718 EditorClientQt::dumpEditingCallbacks = b;
721 void DumpRenderTreeSupportQt::dumpSetAcceptsEditing(bool b)
723 EditorClientQt::acceptsEditing = b;
726 void DumpRenderTreeSupportQt::dumpNotification(bool b)
728 #if ENABLE(NOTIFICATIONS)
729 NotificationPresenterClientQt::dumpNotification = b;
733 QString DumpRenderTreeSupportQt::viewportAsText(QWebPage* page, int deviceDPI, const QSize& deviceSize, const QSize& availableSize)
735 WebCore::ViewportArguments args = page->d->viewportArguments();
737 WebCore::ViewportAttributes conf = WebCore::computeViewportAttributes(args,
738 /* desktop-width */ 980,
739 /* device-width */ deviceSize.width(),
740 /* device-height */ deviceSize.height(),
741 /* device-dpi */ deviceDPI,
745 res = res.sprintf("viewport size %dx%d scale %f with limits [%f, %f] and userScalable %f\n",
746 conf.layoutSize.width(),
747 conf.layoutSize.height(),
756 void DumpRenderTreeSupportQt::activeMockDeviceOrientationClient(bool b)
758 #if ENABLE(DEVICE_ORIENTATION)
759 DeviceOrientationClientMockQt::mockIsActive = b;
763 void DumpRenderTreeSupportQt::removeMockDeviceOrientation()
765 #if ENABLE(DEVICE_ORIENTATION)
766 DeviceOrientationClientMockQt* client = DeviceOrientationClientMockQt::client();
771 void DumpRenderTreeSupportQt::setMockDeviceOrientation(bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma)
773 #if ENABLE(DEVICE_ORIENTATION)
774 DeviceOrientationClientMockQt::client()->setOrientation(canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma);
778 void DumpRenderTreeSupportQt::resetGeolocationMock(QWebPage* page)
780 #if ENABLE(CLIENT_BASED_GEOLOCATION)
781 Page* corePage = QWebPagePrivate::core(page);
782 GeolocationClientMock* mockClient = toGeolocationClientMock(corePage->geolocationController()->client());
787 void DumpRenderTreeSupportQt::setMockGeolocationPermission(QWebPage* page, bool allowed)
789 #if ENABLE(CLIENT_BASED_GEOLOCATION)
790 Page* corePage = QWebPagePrivate::core(page);
791 GeolocationClientMock* mockClient = toGeolocationClientMock(corePage->geolocationController()->client());
792 mockClient->setPermission(allowed);
796 void DumpRenderTreeSupportQt::setMockGeolocationPosition(QWebPage* page, double latitude, double longitude, double accuracy)
798 #if ENABLE(CLIENT_BASED_GEOLOCATION)
799 Page* corePage = QWebPagePrivate::core(page);
800 GeolocationClientMock* mockClient = toGeolocationClientMock(corePage->geolocationController()->client());
801 mockClient->setPosition(GeolocationPosition::create(currentTime(), latitude, longitude, accuracy));
805 void DumpRenderTreeSupportQt::setMockGeolocationError(QWebPage* page, int errorCode, const QString& message)
807 #if ENABLE(CLIENT_BASED_GEOLOCATION)
808 Page* corePage = QWebPagePrivate::core(page);
810 GeolocationError::ErrorCode code = GeolocationError::PositionUnavailable;
812 case PositionError::PERMISSION_DENIED:
813 code = GeolocationError::PermissionDenied;
815 case PositionError::POSITION_UNAVAILABLE:
816 code = GeolocationError::PositionUnavailable;
820 GeolocationClientMock* mockClient = static_cast<GeolocationClientMock*>(corePage->geolocationController()->client());
821 mockClient->setError(GeolocationError::create(code, message));
825 bool DumpRenderTreeSupportQt::isTargetItem(const QWebHistoryItem& historyItem)
827 QWebHistoryItem it = historyItem;
828 if (QWebHistoryItemPrivate::core(&it)->isTargetItem())
833 QString DumpRenderTreeSupportQt::historyItemTarget(const QWebHistoryItem& historyItem)
835 QWebHistoryItem it = historyItem;
836 return (QWebHistoryItemPrivate::core(&it)->target());
839 QMap<QString, QWebHistoryItem> DumpRenderTreeSupportQt::getChildHistoryItems(const QWebHistoryItem& historyItem)
841 QWebHistoryItem it = historyItem;
842 HistoryItem* item = QWebHistoryItemPrivate::core(&it);
843 const WebCore::HistoryItemVector& children = item->children();
845 unsigned size = children.size();
846 QMap<QString, QWebHistoryItem> kids;
847 for (unsigned i = 0; i < size; ++i) {
848 QWebHistoryItem kid(new QWebHistoryItemPrivate(children[i].get()));
849 kids.insert(DumpRenderTreeSupportQt::historyItemTarget(kid), kid);
854 bool DumpRenderTreeSupportQt::shouldClose(QWebFrame* frame)
856 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
857 return coreFrame->loader()->shouldClose();
860 void DumpRenderTreeSupportQt::clearScriptWorlds()
865 void DumpRenderTreeSupportQt::evaluateScriptInIsolatedWorld(QWebFrame* frame, int worldID, const QString& script)
867 QWebScriptWorld* scriptWorld;
869 scriptWorld = new QWebScriptWorld();
870 } else if (!m_worldMap.contains(worldID)) {
871 scriptWorld = new QWebScriptWorld();
872 m_worldMap.insert(worldID, scriptWorld);
874 scriptWorld = m_worldMap.value(worldID);
876 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
878 ScriptController* proxy = coreFrame->script();
883 proxy->executeScriptInWorld(scriptWorld->world(), script, true);
885 ScriptSourceCode source(script);
886 Vector<ScriptSourceCode> sources;
887 sources.append(source);
888 proxy->evaluateInIsolatedWorld(0, sources, true);
892 bool DumpRenderTreeSupportQt::isPageBoxVisible(QWebFrame* frame, int pageIndex)
894 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
895 return coreFrame->document()->isPageBoxVisible(pageIndex);
898 QString DumpRenderTreeSupportQt::pageSizeAndMarginsInPixels(QWebFrame* frame, int pageIndex, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft)
900 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
901 return PrintContext::pageSizeAndMarginsInPixels(coreFrame, pageIndex, width, height,
902 marginTop, marginRight, marginBottom, marginLeft);
905 QString DumpRenderTreeSupportQt::pageProperty(QWebFrame* frame, const QString& propertyName, int pageNumber)
907 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
908 return PrintContext::pageProperty(coreFrame, propertyName.toUtf8().constData(), pageNumber);
911 void DumpRenderTreeSupportQt::addUserStyleSheet(QWebPage* page, const QString& sourceCode)
913 page->handle()->page->group().addUserStyleSheetToWorld(mainThreadNormalWorld(), sourceCode, QUrl(), 0, 0, WebCore::InjectInAllFrames);
916 void DumpRenderTreeSupportQt::simulateDesktopNotificationClick(const QString& title)
918 #if ENABLE(NOTIFICATIONS)
919 NotificationPresenterClientQt::notificationPresenter()->notificationClicked(title);
923 QString DumpRenderTreeSupportQt::plainText(const QVariant& range)
925 QMap<QString, QVariant> map = range.toMap();
926 QVariant startContainer = map.value(QLatin1String("startContainer"));
927 map = startContainer.toMap();
929 return map.value(QLatin1String("innerText")).toString();
932 QVariantList DumpRenderTreeSupportQt::nodesFromRect(const QWebElement& document, int x, int y, unsigned top, unsigned right, unsigned bottom, unsigned left, bool ignoreClipping)
935 WebCore::Element* webElement = document.m_element;
939 Document* doc = webElement->document();
942 RefPtr<NodeList> nodes = doc->nodesFromRect(x, y, top, right, bottom, left, ignoreClipping);
943 for (int i = 0; i < nodes->length(); i++) {
944 // QWebElement will be null if the Node is not an HTML Element
945 if (nodes->item(i)->isHTMLElement())
946 res << QVariant::fromValue(QWebElement(nodes->item(i)));
948 res << QVariant::fromValue(QDRTNode(nodes->item(i)));
954 QString DumpRenderTreeSupportQt::responseMimeType(QWebFrame* frame)
956 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
957 WebCore::DocumentLoader* docLoader = coreFrame->loader()->documentLoader();
958 return docLoader->responseMIMEType();
961 void DumpRenderTreeSupportQt::clearOpener(QWebFrame* frame)
963 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
964 coreFrame->loader()->setOpener(0);
967 void DumpRenderTreeSupportQt::addURLToRedirect(const QString& origin, const QString& destination)
969 FrameLoaderClientQt::URLsToRedirect[origin] = destination;
972 static QStringList iterateContextMenu(QMenu* menu)
975 return QStringList();
978 QList<QAction *> actions = menu->actions();
979 for (int i = 0; i < actions.count(); ++i) {
980 if (actions.at(i)->isSeparator())
981 items << QLatin1String("<separator>");
983 items << actions.at(i)->text();
984 if (actions.at(i)->menu())
985 items << iterateContextMenu(actions.at(i)->menu());
990 QStringList DumpRenderTreeSupportQt::contextMenu(QWebPage* page)
992 #ifndef QT_NO_CONTEXTMENU
993 return iterateContextMenu(page->d->currentContextMenu);
995 return QStringList();
999 double DumpRenderTreeSupportQt::defaultMinimumTimerInterval()
1001 return Settings::defaultMinDOMTimerInterval();
1004 void DumpRenderTreeSupportQt::setMinimumTimerInterval(QWebPage* page, double interval)
1006 Page* corePage = QWebPagePrivate::core(page);
1010 corePage->settings()->setMinDOMTimerInterval(interval);
1013 QUrl DumpRenderTreeSupportQt::mediaContentUrlByElementId(QWebFrame* frame, const QString& elementId)
1017 #if ENABLE(VIDEO) && ENABLE(QT_MULTIMEDIA)
1018 Frame* coreFrame = QWebFramePrivate::core(frame);
1022 Document* doc = coreFrame->document();
1026 Node* coreNode = doc->getElementById(elementId);
1030 HTMLVideoElement* videoElement = static_cast<HTMLVideoElement*>(coreNode);
1031 PlatformMedia platformMedia = videoElement->platformMedia();
1032 if (platformMedia.type != PlatformMedia::QtMediaPlayerType)
1035 MediaPlayerPrivateQt* mediaPlayerQt = static_cast<MediaPlayerPrivateQt*>(platformMedia.media.qtMediaPlayer);
1036 if (mediaPlayerQt && mediaPlayerQt->mediaPlayer())
1037 res = mediaPlayerQt->mediaPlayer()->media().canonicalUrl();
1044 void DumpRenderTreeSupportQt::setAlternateHtml(QWebFrame* frame, const QString& html, const QUrl& baseUrl, const QUrl& failingUrl)
1047 WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
1048 WebCore::ResourceRequest request(kurl);
1049 const QByteArray utf8 = html.toUtf8();
1050 WTF::RefPtr<WebCore::SharedBuffer> data = WebCore::SharedBuffer::create(utf8.constData(), utf8.length());
1051 WebCore::SubstituteData substituteData(data, WTF::String("text/html"), WTF::String("utf-8"), failingUrl);
1052 coreFrame->loader()->load(request, substituteData, false);
1055 // Provide a backward compatibility with previously exported private symbols as of QtWebKit 4.6 release
1057 void QWEBKIT_EXPORT qt_resumeActiveDOMObjects(QWebFrame* frame)
1059 DumpRenderTreeSupportQt::resumeActiveDOMObjects(frame);
1062 void QWEBKIT_EXPORT qt_suspendActiveDOMObjects(QWebFrame* frame)
1064 DumpRenderTreeSupportQt::suspendActiveDOMObjects(frame);
1067 void QWEBKIT_EXPORT qt_drt_clearFrameName(QWebFrame* frame)
1069 DumpRenderTreeSupportQt::clearFrameName(frame);
1072 void QWEBKIT_EXPORT qt_drt_garbageCollector_collect()
1074 DumpRenderTreeSupportQt::garbageCollectorCollect();
1077 void QWEBKIT_EXPORT qt_drt_garbageCollector_collectOnAlternateThread(bool waitUntilDone)
1079 DumpRenderTreeSupportQt::garbageCollectorCollectOnAlternateThread(waitUntilDone);
1082 int QWEBKIT_EXPORT qt_drt_javaScriptObjectsCount()
1084 return DumpRenderTreeSupportQt::javaScriptObjectsCount();
1087 int QWEBKIT_EXPORT qt_drt_numberOfActiveAnimations(QWebFrame* frame)
1089 return DumpRenderTreeSupportQt::numberOfActiveAnimations(frame);
1092 void QWEBKIT_EXPORT qt_drt_overwritePluginDirectories()
1094 DumpRenderTreeSupportQt::overwritePluginDirectories();
1097 bool QWEBKIT_EXPORT qt_drt_pauseAnimation(QWebFrame* frame, const QString& animationName, double time, const QString& elementId)
1099 return DumpRenderTreeSupportQt::pauseAnimation(frame, animationName, time, elementId);
1102 bool QWEBKIT_EXPORT qt_drt_pauseTransitionOfProperty(QWebFrame* frame, const QString& propertyName, double time, const QString &elementId)
1104 return DumpRenderTreeSupportQt::pauseTransitionOfProperty(frame, propertyName, time, elementId);
1107 void QWEBKIT_EXPORT qt_drt_resetOriginAccessWhiteLists()
1109 DumpRenderTreeSupportQt::resetOriginAccessWhiteLists();
1112 void QWEBKIT_EXPORT qt_drt_run(bool b)
1114 DumpRenderTreeSupportQt::setDumpRenderTreeModeEnabled(b);
1117 void QWEBKIT_EXPORT qt_drt_setJavaScriptProfilingEnabled(QWebFrame* frame, bool enabled)
1119 DumpRenderTreeSupportQt::setJavaScriptProfilingEnabled(frame, enabled);
1122 void QWEBKIT_EXPORT qt_drt_whiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains)
1124 DumpRenderTreeSupportQt::whiteListAccessFromOrigin(sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains);
1127 QString QWEBKIT_EXPORT qt_webpage_groupName(QWebPage* page)
1129 return DumpRenderTreeSupportQt::webPageGroupName(page);
1132 void QWEBKIT_EXPORT qt_webpage_setGroupName(QWebPage* page, const QString& groupName)
1134 DumpRenderTreeSupportQt::webPageSetGroupName(page, groupName);
1137 void QWEBKIT_EXPORT qt_dump_frame_loader(bool b)
1139 DumpRenderTreeSupportQt::dumpFrameLoader(b);
1142 void QWEBKIT_EXPORT qt_dump_resource_load_callbacks(bool b)
1144 DumpRenderTreeSupportQt::dumpResourceLoadCallbacks(b);
1147 void QWEBKIT_EXPORT qt_dump_editing_callbacks(bool b)
1149 DumpRenderTreeSupportQt::dumpEditingCallbacks(b);
1152 void QWEBKIT_EXPORT qt_dump_set_accepts_editing(bool b)
1154 DumpRenderTreeSupportQt::dumpSetAcceptsEditing(b);