1 /*
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.
6 
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.
11 
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.
16 
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.
21 */
22 
23 #include "config.h"
24 #include "DumpRenderTreeSupportQt.h"
25 
26 #if USE(JSC)
27 #include "APICast.h"
28 #endif
29 #include "ApplicationCacheStorage.h"
30 #include "CSSComputedStyleDeclaration.h"
31 #include "ChromeClientQt.h"
32 #include "ContainerNode.h"
33 #include "ContextMenu.h"
34 #include "ContextMenuClientQt.h"
35 #include "ContextMenuController.h"
36 #include "DeviceOrientation.h"
37 #include "DeviceOrientationClientMockQt.h"
38 #include "DocumentLoader.h"
39 #include "Editor.h"
40 #include "EditorClientQt.h"
41 #include "Element.h"
42 #include "FocusController.h"
43 #include "Frame.h"
44 #include "FrameLoaderClientQt.h"
45 #include "FrameView.h"
46 #if USE(JSC)
47 #include "GCController.h"
48 #elif USE(V8)
49 #include "V8GCController.h"
50 #include "V8Proxy.h"
51 #endif
52 #include "GeolocationClient.h"
53 #include "GeolocationClientMock.h"
54 #include "GeolocationController.h"
55 #include "GeolocationError.h"
56 #include "GeolocationPosition.h"
57 #include "HistoryItem.h"
58 #include "HTMLInputElement.h"
59 #include "InputElement.h"
60 #include "InspectorController.h"
61 #include "NodeList.h"
62 #include "NotificationPresenterClientQt.h"
63 #include "Page.h"
64 #include "PageGroup.h"
65 #include "PluginDatabase.h"
66 #include "PositionError.h"
67 #include "PrintContext.h"
68 #include "RenderListItem.h"
69 #include "RenderTreeAsText.h"
70 #include "ShadowRoot.h"
71 #include "ScriptController.h"
72 #include "ScriptValue.h"
73 #include "SecurityOrigin.h"
74 #include "Settings.h"
75 #if ENABLE(SVG)
76 #include "SVGDocumentExtensions.h"
77 #include "SVGSMILElement.h"
78 #endif
79 #include "TextIterator.h"
80 #include "WebCoreTestSupport.h"
81 #include "WorkerThread.h"
82 #include <wtf/CurrentTime.h>
83 
84 #include "qwebelement.h"
85 #include "qwebframe.h"
86 #include "qwebframe_p.h"
87 #include "qwebhistory.h"
88 #include "qwebhistory_p.h"
89 #include "qwebpage.h"
90 #include "qwebpage_p.h"
91 #include "qwebscriptworld.h"
92 
93 #if ENABLE(VIDEO) && USE(QT_MULTIMEDIA)
94 #include "HTMLVideoElement.h"
95 #include "MediaPlayerPrivateQt.h"
96 #endif
97 
98 using namespace WebCore;
99 
100 QMap<int, QWebScriptWorld*> m_worldMap;
101 
102 #if ENABLE(CLIENT_BASED_GEOLOCATION)
toGeolocationClientMock(GeolocationClient * client)103 GeolocationClientMock* toGeolocationClientMock(GeolocationClient* client)
104 {
105      ASSERT(QWebPagePrivate::drtRun);
106      return static_cast<GeolocationClientMock*>(client);
107 }
108 #endif
109 
QDRTNode()110 QDRTNode::QDRTNode()
111     : m_node(0)
112 {
113 }
114 
QDRTNode(WebCore::Node * node)115 QDRTNode::QDRTNode(WebCore::Node* node)
116     : m_node(0)
117 {
118     if (node) {
119         m_node = node;
120         m_node->ref();
121     }
122 }
123 
~QDRTNode()124 QDRTNode::~QDRTNode()
125 {
126     if (m_node)
127         m_node->deref();
128 }
129 
QDRTNode(const QDRTNode & other)130 QDRTNode::QDRTNode(const QDRTNode& other)
131     :m_node(other.m_node)
132 {
133     if (m_node)
134         m_node->ref();
135 }
136 
operator =(const QDRTNode & other)137 QDRTNode& QDRTNode::operator=(const QDRTNode& other)
138 {
139     if (this != &other) {
140         Node* otherNode = other.m_node;
141         if (otherNode)
142             otherNode->ref();
143         if (m_node)
144             m_node->deref();
145         m_node = otherNode;
146     }
147     return *this;
148 }
149 
150 
DumpRenderTreeSupportQt()151 DumpRenderTreeSupportQt::DumpRenderTreeSupportQt()
152 {
153 }
154 
~DumpRenderTreeSupportQt()155 DumpRenderTreeSupportQt::~DumpRenderTreeSupportQt()
156 {
157 }
158 
overwritePluginDirectories()159 void DumpRenderTreeSupportQt::overwritePluginDirectories()
160 {
161     PluginDatabase* db = PluginDatabase::installedPlugins(/* populate */ false);
162 
163     Vector<String> paths;
164     String qtPath(qgetenv("QTWEBKIT_PLUGIN_PATH").data());
165     qtPath.split(UChar(':'), /* allowEmptyEntries */ false, paths);
166 
167     db->setPluginDirectories(paths);
168     db->refresh();
169 }
170 
workerThreadCount()171 int DumpRenderTreeSupportQt::workerThreadCount()
172 {
173 #if ENABLE(WORKERS)
174     return WebCore::WorkerThread::workerThreadCount();
175 #else
176     return 0;
177 #endif
178 }
179 
setDumpRenderTreeModeEnabled(bool b)180 void DumpRenderTreeSupportQt::setDumpRenderTreeModeEnabled(bool b)
181 {
182     QWebPagePrivate::drtRun = b;
183 }
184 
setFrameFlatteningEnabled(QWebPage * page,bool enabled)185 void DumpRenderTreeSupportQt::setFrameFlatteningEnabled(QWebPage* page, bool enabled)
186 {
187     QWebPagePrivate::core(page)->settings()->setFrameFlatteningEnabled(enabled);
188 }
189 
webPageSetGroupName(QWebPage * page,const QString & groupName)190 void DumpRenderTreeSupportQt::webPageSetGroupName(QWebPage* page, const QString& groupName)
191 {
192     page->handle()->page->setGroupName(groupName);
193 }
194 
webPageGroupName(QWebPage * page)195 QString DumpRenderTreeSupportQt::webPageGroupName(QWebPage* page)
196 {
197     return page->handle()->page->groupName();
198 }
199 
webInspectorExecuteScript(QWebPage * page,long callId,const QString & script)200 void DumpRenderTreeSupportQt::webInspectorExecuteScript(QWebPage* page, long callId, const QString& script)
201 {
202 #if ENABLE(INSPECTOR)
203     if (!page->handle()->page->inspectorController())
204         return;
205     page->handle()->page->inspectorController()->evaluateForTestInFrontend(callId, script);
206 #endif
207 }
208 
webInspectorClose(QWebPage * page)209 void DumpRenderTreeSupportQt::webInspectorClose(QWebPage* page)
210 {
211 #if ENABLE(INSPECTOR)
212     if (!page->handle()->page->inspectorController())
213         return;
214     page->handle()->page->inspectorController()->close();
215 #endif
216 }
217 
webInspectorShow(QWebPage * page)218 void DumpRenderTreeSupportQt::webInspectorShow(QWebPage* page)
219 {
220 #if ENABLE(INSPECTOR)
221     if (!page->handle()->page->inspectorController())
222         return;
223     page->handle()->page->inspectorController()->show();
224 #endif
225 }
226 
setTimelineProfilingEnabled(QWebPage * page,bool enabled)227 void DumpRenderTreeSupportQt::setTimelineProfilingEnabled(QWebPage* page, bool enabled)
228 {
229 #if ENABLE(INSPECTOR)
230     InspectorController* controller = page->handle()->page->inspectorController();
231     if (!controller)
232         return;
233     if (enabled)
234         controller->startTimelineProfiler();
235     else
236         controller->stopTimelineProfiler();
237 #endif
238 }
239 
hasDocumentElement(QWebFrame * frame)240 bool DumpRenderTreeSupportQt::hasDocumentElement(QWebFrame* frame)
241 {
242     return QWebFramePrivate::core(frame)->document()->documentElement();
243 }
244 
setAutofilled(const QWebElement & element,bool isAutofilled)245 void DumpRenderTreeSupportQt::setAutofilled(const QWebElement& element, bool isAutofilled)
246 {
247     WebCore::Element* webElement = element.m_element;
248     if (!webElement)
249         return;
250     InputElement* inputElement = webElement->toInputElement();
251     if (!inputElement)
252         return;
253 
254     static_cast<HTMLInputElement*>(inputElement)->setAutofilled(isAutofilled);
255 }
256 
setJavaScriptProfilingEnabled(QWebFrame * frame,bool enabled)257 void DumpRenderTreeSupportQt::setJavaScriptProfilingEnabled(QWebFrame* frame, bool enabled)
258 {
259 #if ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
260     Frame* coreFrame = QWebFramePrivate::core(frame);
261     InspectorController* controller = coreFrame->page()->inspectorController();
262     if (!controller)
263         return;
264     if (enabled)
265         controller->enableProfiler();
266     else
267         controller->disableProfiler();
268 #endif
269 }
270 
271 // Pause a given CSS animation or transition on the target node at a specific time.
272 // If the animation or transition is already paused, it will update its pause time.
273 // This method is only intended to be used for testing the CSS animation and transition system.
pauseAnimation(QWebFrame * frame,const QString & animationName,double time,const QString & elementId)274 bool DumpRenderTreeSupportQt::pauseAnimation(QWebFrame *frame, const QString &animationName, double time, const QString &elementId)
275 {
276     Frame* coreFrame = QWebFramePrivate::core(frame);
277     if (!coreFrame)
278         return false;
279 
280     AnimationController* controller = coreFrame->animation();
281     if (!controller)
282         return false;
283 
284     Document* doc = coreFrame->document();
285     Q_ASSERT(doc);
286 
287     Node* coreNode = doc->getElementById(elementId);
288     if (!coreNode || !coreNode->renderer())
289         return false;
290 
291     return controller->pauseAnimationAtTime(coreNode->renderer(), animationName, time);
292 }
293 
pauseTransitionOfProperty(QWebFrame * frame,const QString & propertyName,double time,const QString & elementId)294 bool DumpRenderTreeSupportQt::pauseTransitionOfProperty(QWebFrame *frame, const QString &propertyName, double time, const QString &elementId)
295 {
296     Frame* coreFrame = QWebFramePrivate::core(frame);
297     if (!coreFrame)
298         return false;
299 
300     AnimationController* controller = coreFrame->animation();
301     if (!controller)
302         return false;
303 
304     Document* doc = coreFrame->document();
305     Q_ASSERT(doc);
306 
307     Node* coreNode = doc->getElementById(elementId);
308     if (!coreNode || !coreNode->renderer())
309         return false;
310 
311     return controller->pauseTransitionAtTime(coreNode->renderer(), propertyName, time);
312 }
313 
314 // Pause a given SVG animation on the target node at a specific time.
315 // This method is only intended to be used for testing the SVG animation system.
pauseSVGAnimation(QWebFrame * frame,const QString & animationId,double time,const QString & elementId)316 bool DumpRenderTreeSupportQt::pauseSVGAnimation(QWebFrame *frame, const QString &animationId, double time, const QString &elementId)
317 {
318 #if !ENABLE(SVG)
319     return false;
320 #else
321     Frame* coreFrame = QWebFramePrivate::core(frame);
322     if (!coreFrame)
323         return false;
324 
325     Document* doc = coreFrame->document();
326     Q_ASSERT(doc);
327 
328     if (!doc->svgExtensions())
329         return false;
330 
331     Node* coreNode = doc->getElementById(animationId);
332     if (!coreNode || !SVGSMILElement::isSMILElement(coreNode))
333         return false;
334 
335     return doc->accessSVGExtensions()->sampleAnimationAtTime(elementId, static_cast<SVGSMILElement*>(coreNode), time);
336 #endif
337 }
338 
339 // Returns the total number of currently running animations (includes both CSS transitions and CSS animations).
numberOfActiveAnimations(QWebFrame * frame)340 int DumpRenderTreeSupportQt::numberOfActiveAnimations(QWebFrame *frame)
341 {
342     Frame* coreFrame = QWebFramePrivate::core(frame);
343     if (!coreFrame)
344         return false;
345 
346     AnimationController* controller = coreFrame->animation();
347     if (!controller)
348         return false;
349 
350     return controller->numberOfActiveAnimations();
351 }
352 
suspendAnimations(QWebFrame * frame)353 void DumpRenderTreeSupportQt::suspendAnimations(QWebFrame *frame)
354 {
355     Frame* coreFrame = QWebFramePrivate::core(frame);
356     if (!coreFrame)
357         return;
358 
359     AnimationController* controller = coreFrame->animation();
360     if (!controller)
361         return;
362 
363     controller->suspendAnimations();
364 }
365 
resumeAnimations(QWebFrame * frame)366 void DumpRenderTreeSupportQt::resumeAnimations(QWebFrame *frame)
367 {
368     Frame* coreFrame = QWebFramePrivate::core(frame);
369     if (!coreFrame)
370         return;
371 
372     AnimationController* controller = coreFrame->animation();
373     if (!controller)
374         return;
375 
376     controller->resumeAnimations();
377 }
378 
clearFrameName(QWebFrame * frame)379 void DumpRenderTreeSupportQt::clearFrameName(QWebFrame* frame)
380 {
381     Frame* coreFrame = QWebFramePrivate::core(frame);
382     coreFrame->tree()->clearName();
383 }
384 
javaScriptObjectsCount()385 int DumpRenderTreeSupportQt::javaScriptObjectsCount()
386 {
387 #if USE(JSC)
388     return JSDOMWindowBase::commonJSGlobalData()->heap.globalObjectCount();
389 #elif USE(V8)
390     // FIXME: Find a way to do this using V8.
391     return 1;
392 #endif
393 }
394 
garbageCollectorCollect()395 void DumpRenderTreeSupportQt::garbageCollectorCollect()
396 {
397 #if USE(JSC)
398     gcController().garbageCollectNow();
399 #elif USE(V8)
400     v8::V8::LowMemoryNotification();
401 #endif
402 }
403 
garbageCollectorCollectOnAlternateThread(bool waitUntilDone)404 void DumpRenderTreeSupportQt::garbageCollectorCollectOnAlternateThread(bool waitUntilDone)
405 {
406 #if USE(JSC)
407     gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
408 #elif USE(V8)
409     // FIXME: Find a way to do this using V8.
410     garbageCollectorCollect();
411 #endif
412 }
413 
414 // Returns the value of counter in the element specified by \a id.
counterValueForElementById(QWebFrame * frame,const QString & id)415 QString DumpRenderTreeSupportQt::counterValueForElementById(QWebFrame* frame, const QString& id)
416 {
417     Frame* coreFrame = QWebFramePrivate::core(frame);
418     if (Document* document = coreFrame->document()) {
419         if (Element* element = document->getElementById(id))
420             return WebCore::counterValueForElement(element);
421     }
422     return QString();
423 }
424 
pageNumberForElementById(QWebFrame * frame,const QString & id,float width,float height)425 int DumpRenderTreeSupportQt::pageNumberForElementById(QWebFrame* frame, const QString& id, float width, float height)
426 {
427     Frame* coreFrame = QWebFramePrivate::core(frame);
428     if (!coreFrame)
429         return -1;
430 
431     Element* element = coreFrame->document()->getElementById(AtomicString(id));
432     if (!element)
433         return -1;
434 
435     return PrintContext::pageNumberForElement(element, FloatSize(width, height));
436 }
437 
numberOfPages(QWebFrame * frame,float width,float height)438 int DumpRenderTreeSupportQt::numberOfPages(QWebFrame* frame, float width, float height)
439 {
440     Frame* coreFrame = QWebFramePrivate::core(frame);
441     if (!coreFrame)
442         return -1;
443 
444     return PrintContext::numberOfPages(coreFrame, FloatSize(width, height));
445 }
446 
447 // Suspend active DOM objects in this frame.
suspendActiveDOMObjects(QWebFrame * frame)448 void DumpRenderTreeSupportQt::suspendActiveDOMObjects(QWebFrame* frame)
449 {
450     Frame* coreFrame = QWebFramePrivate::core(frame);
451     if (coreFrame->document())
452         // FIXME: This function should be changed take a ReasonForSuspension parameter
453         // https://bugs.webkit.org/show_bug.cgi?id=45732
454         coreFrame->document()->suspendActiveDOMObjects(ActiveDOMObject::JavaScriptDebuggerPaused);
455 }
456 
457 // Resume active DOM objects in this frame.
resumeActiveDOMObjects(QWebFrame * frame)458 void DumpRenderTreeSupportQt::resumeActiveDOMObjects(QWebFrame* frame)
459 {
460     Frame* coreFrame = QWebFramePrivate::core(frame);
461     if (coreFrame->document())
462         coreFrame->document()->resumeActiveDOMObjects();
463 }
464 
whiteListAccessFromOrigin(const QString & sourceOrigin,const QString & destinationProtocol,const QString & destinationHost,bool allowDestinationSubdomains)465 void DumpRenderTreeSupportQt::whiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains)
466 {
467     SecurityOrigin::addOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
468 }
469 
removeWhiteListAccessFromOrigin(const QString & sourceOrigin,const QString & destinationProtocol,const QString & destinationHost,bool allowDestinationSubdomains)470 void DumpRenderTreeSupportQt::removeWhiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains)
471 {
472     SecurityOrigin::removeOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
473 }
474 
resetOriginAccessWhiteLists()475 void DumpRenderTreeSupportQt::resetOriginAccessWhiteLists()
476 {
477     SecurityOrigin::resetOriginAccessWhitelists();
478 }
479 
setDomainRelaxationForbiddenForURLScheme(bool forbidden,const QString & scheme)480 void DumpRenderTreeSupportQt::setDomainRelaxationForbiddenForURLScheme(bool forbidden, const QString& scheme)
481 {
482     SecurityOrigin::setDomainRelaxationForbiddenForURLScheme(forbidden, scheme);
483 }
484 
setCaretBrowsingEnabled(QWebPage * page,bool value)485 void DumpRenderTreeSupportQt::setCaretBrowsingEnabled(QWebPage* page, bool value)
486 {
487     page->handle()->page->settings()->setCaretBrowsingEnabled(value);
488 }
489 
setMediaType(QWebFrame * frame,const QString & type)490 void DumpRenderTreeSupportQt::setMediaType(QWebFrame* frame, const QString& type)
491 {
492     WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
493     WebCore::FrameView* view = coreFrame->view();
494     view->setMediaType(type);
495     coreFrame->document()->styleSelectorChanged(RecalcStyleImmediately);
496     view->layout();
497 }
498 
setSmartInsertDeleteEnabled(QWebPage * page,bool enabled)499 void DumpRenderTreeSupportQt::setSmartInsertDeleteEnabled(QWebPage* page, bool enabled)
500 {
501     page->d->smartInsertDeleteEnabled = enabled;
502 }
503 
504 
setSelectTrailingWhitespaceEnabled(QWebPage * page,bool enabled)505 void DumpRenderTreeSupportQt::setSelectTrailingWhitespaceEnabled(QWebPage* page, bool enabled)
506 {
507     page->d->selectTrailingWhitespaceEnabled = enabled;
508 }
509 
510 
executeCoreCommandByName(QWebPage * page,const QString & name,const QString & value)511 void DumpRenderTreeSupportQt::executeCoreCommandByName(QWebPage* page, const QString& name, const QString& value)
512 {
513     page->handle()->page->focusController()->focusedOrMainFrame()->editor()->command(name).execute(value);
514 }
515 
isCommandEnabled(QWebPage * page,const QString & name)516 bool DumpRenderTreeSupportQt::isCommandEnabled(QWebPage* page, const QString& name)
517 {
518     return page->handle()->page->focusController()->focusedOrMainFrame()->editor()->command(name).isEnabled();
519 }
520 
findString(QWebPage * page,const QString & string,const QStringList & optionArray)521 bool DumpRenderTreeSupportQt::findString(QWebPage* page, const QString& string, const QStringList& optionArray)
522 {
523     // 1. Parse the options from the array
524     WebCore::FindOptions options = 0;
525     const int optionCount = optionArray.size();
526     for (int i = 0; i < optionCount; ++i) {
527         const QString& option = optionArray.at(i);
528         if (option == QLatin1String("CaseInsensitive"))
529             options |= WebCore::CaseInsensitive;
530         else if (option == QLatin1String("AtWordStarts"))
531             options |= WebCore::AtWordStarts;
532         else if (option == QLatin1String("TreatMedialCapitalAsWordStart"))
533             options |= WebCore::TreatMedialCapitalAsWordStart;
534         else if (option == QLatin1String("Backwards"))
535             options |= WebCore::Backwards;
536         else if (option == QLatin1String("WrapAround"))
537             options |= WebCore::WrapAround;
538         else if (option == QLatin1String("StartInSelection"))
539             options |= WebCore::StartInSelection;
540     }
541 
542     // 2. find the string
543     WebCore::Frame* frame = page->handle()->page->focusController()->focusedOrMainFrame();
544     return frame && frame->editor()->findString(string, options);
545 }
546 
markerTextForListItem(const QWebElement & listItem)547 QString DumpRenderTreeSupportQt::markerTextForListItem(const QWebElement& listItem)
548 {
549     return WebCore::markerTextForListItem(listItem.m_element);
550 }
551 
convertToPropertyName(const QString & name)552 static QString convertToPropertyName(const QString& name)
553 {
554     QStringList parts = name.split(QLatin1Char('-'));
555     QString camelCaseName;
556     for (int j = 0; j < parts.count(); ++j) {
557         QString part = parts.at(j);
558         if (j)
559             camelCaseName.append(part.replace(0, 1, part.left(1).toUpper()));
560         else
561             camelCaseName.append(part);
562     }
563     return camelCaseName;
564 }
565 
computedStyleIncludingVisitedInfo(const QWebElement & element)566 QVariantMap DumpRenderTreeSupportQt::computedStyleIncludingVisitedInfo(const QWebElement& element)
567 {
568     QVariantMap res;
569 
570     WebCore::Element* webElement = element.m_element;
571     if (!webElement)
572         return res;
573 
574     RefPtr<WebCore::CSSComputedStyleDeclaration> style = computedStyle(webElement, true);
575     for (unsigned i = 0; i < style->length(); i++) {
576         QString name = style->item(i);
577         QString value = (static_cast<WebCore::CSSStyleDeclaration*>(style.get()))->getPropertyValue(name);
578         res[convertToPropertyName(name)] = QVariant(value);
579     }
580     return res;
581 }
582 
selectedRange(QWebPage * page)583 QVariantList DumpRenderTreeSupportQt::selectedRange(QWebPage* page)
584 {
585     WebCore::Frame* frame = page->handle()->page->focusController()->focusedOrMainFrame();
586     QVariantList selectedRange;
587     RefPtr<Range> range = frame->selection()->toNormalizedRange().get();
588 
589     Element* selectionRoot = frame->selection()->rootEditableElement();
590     Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement();
591 
592     RefPtr<Range> testRange = Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset());
593     ASSERT(testRange->startContainer() == scope);
594     int startPosition = TextIterator::rangeLength(testRange.get());
595 
596     ExceptionCode ec;
597     testRange->setEnd(range->endContainer(), range->endOffset(), ec);
598     ASSERT(testRange->startContainer() == scope);
599     int endPosition = TextIterator::rangeLength(testRange.get());
600 
601     selectedRange << startPosition << (endPosition - startPosition);
602 
603     return selectedRange;
604 
605 }
606 
firstRectForCharacterRange(QWebPage * page,int location,int length)607 QVariantList DumpRenderTreeSupportQt::firstRectForCharacterRange(QWebPage* page, int location, int length)
608 {
609     WebCore::Frame* frame = page->handle()->page->focusController()->focusedOrMainFrame();
610     QVariantList rect;
611 
612     if ((location + length < location) && (location + length))
613         length = 0;
614 
615     Element* selectionRoot = frame->selection()->rootEditableElement();
616     Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement();
617     RefPtr<Range> range = TextIterator::rangeFromLocationAndLength(scope, location, length);
618 
619     if (!range)
620         return QVariantList();
621 
622     QRect resultRect = frame->editor()->firstRectForRange(range.get());
623     rect << resultRect.x() << resultRect.y() << resultRect.width() << resultRect.height();
624     return rect;
625 }
626 
elementDoesAutoCompleteForElementWithId(QWebFrame * frame,const QString & elementId)627 bool DumpRenderTreeSupportQt::elementDoesAutoCompleteForElementWithId(QWebFrame* frame, const QString& elementId)
628 {
629     Frame* coreFrame = QWebFramePrivate::core(frame);
630     if (!coreFrame)
631         return false;
632 
633     Document* doc = coreFrame->document();
634     Q_ASSERT(doc);
635 
636     Node* coreNode = doc->getElementById(elementId);
637     if (!coreNode || !coreNode->renderer())
638         return false;
639 
640     HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(coreNode);
641 
642     return inputElement->isTextField() && !inputElement->isPasswordField() && inputElement->autoComplete();
643 }
644 
setEditingBehavior(QWebPage * page,const QString & editingBehavior)645 void DumpRenderTreeSupportQt::setEditingBehavior(QWebPage* page, const QString& editingBehavior)
646 {
647     WebCore::EditingBehaviorType coreEditingBehavior;
648 
649     if (editingBehavior == QLatin1String("win"))
650         coreEditingBehavior = EditingWindowsBehavior;
651     else if (editingBehavior == QLatin1String("mac"))
652         coreEditingBehavior = EditingMacBehavior;
653     else if (editingBehavior == QLatin1String("unix"))
654         coreEditingBehavior = EditingUnixBehavior;
655     else {
656         ASSERT_NOT_REACHED();
657         return;
658     }
659 
660     Page* corePage = QWebPagePrivate::core(page);
661     if (!corePage)
662         return;
663 
664     corePage->settings()->setEditingBehaviorType(coreEditingBehavior);
665 }
666 
clearAllApplicationCaches()667 void DumpRenderTreeSupportQt::clearAllApplicationCaches()
668 {
669 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
670     WebCore::cacheStorage().empty();
671     WebCore::cacheStorage().vacuumDatabaseFile();
672 #endif
673 }
674 
dumpFrameLoader(bool b)675 void DumpRenderTreeSupportQt::dumpFrameLoader(bool b)
676 {
677     FrameLoaderClientQt::dumpFrameLoaderCallbacks = b;
678 }
679 
dumpProgressFinishedCallback(bool b)680 void DumpRenderTreeSupportQt::dumpProgressFinishedCallback(bool b)
681 {
682     FrameLoaderClientQt::dumpProgressFinishedCallback = b;
683 }
684 
dumpUserGestureInFrameLoader(bool b)685 void DumpRenderTreeSupportQt::dumpUserGestureInFrameLoader(bool b)
686 {
687     FrameLoaderClientQt::dumpUserGestureInFrameLoaderCallbacks = b;
688 }
689 
dumpResourceLoadCallbacks(bool b)690 void DumpRenderTreeSupportQt::dumpResourceLoadCallbacks(bool b)
691 {
692     FrameLoaderClientQt::dumpResourceLoadCallbacks = b;
693 }
694 
dumpResourceLoadCallbacksPath(const QString & path)695 void DumpRenderTreeSupportQt::dumpResourceLoadCallbacksPath(const QString& path)
696 {
697     FrameLoaderClientQt::dumpResourceLoadCallbacksPath = path;
698 }
699 
dumpResourceResponseMIMETypes(bool b)700 void DumpRenderTreeSupportQt::dumpResourceResponseMIMETypes(bool b)
701 {
702     FrameLoaderClientQt::dumpResourceResponseMIMETypes = b;
703 }
704 
setWillSendRequestReturnsNullOnRedirect(bool b)705 void DumpRenderTreeSupportQt::setWillSendRequestReturnsNullOnRedirect(bool b)
706 {
707     FrameLoaderClientQt::sendRequestReturnsNullOnRedirect = b;
708 }
709 
setWillSendRequestReturnsNull(bool b)710 void DumpRenderTreeSupportQt::setWillSendRequestReturnsNull(bool b)
711 {
712     FrameLoaderClientQt::sendRequestReturnsNull = b;
713 }
714 
setWillSendRequestClearHeaders(const QStringList & headers)715 void DumpRenderTreeSupportQt::setWillSendRequestClearHeaders(const QStringList& headers)
716 {
717     FrameLoaderClientQt::sendRequestClearHeaders = headers;
718 }
719 
setDeferMainResourceDataLoad(bool b)720 void DumpRenderTreeSupportQt::setDeferMainResourceDataLoad(bool b)
721 {
722     FrameLoaderClientQt::deferMainResourceDataLoad = b;
723 }
724 
setCustomPolicyDelegate(bool enabled,bool permissive)725 void DumpRenderTreeSupportQt::setCustomPolicyDelegate(bool enabled, bool permissive)
726 {
727     FrameLoaderClientQt::policyDelegateEnabled = enabled;
728     FrameLoaderClientQt::policyDelegatePermissive = permissive;
729 }
730 
dumpHistoryCallbacks(bool b)731 void DumpRenderTreeSupportQt::dumpHistoryCallbacks(bool b)
732 {
733     FrameLoaderClientQt::dumpHistoryCallbacks = b;
734 }
735 
dumpVisitedLinksCallbacks(bool b)736 void DumpRenderTreeSupportQt::dumpVisitedLinksCallbacks(bool b)
737 {
738     ChromeClientQt::dumpVisitedLinksCallbacks = b;
739 }
740 
dumpEditingCallbacks(bool b)741 void DumpRenderTreeSupportQt::dumpEditingCallbacks(bool b)
742 {
743     EditorClientQt::dumpEditingCallbacks = b;
744 }
745 
dumpSetAcceptsEditing(bool b)746 void DumpRenderTreeSupportQt::dumpSetAcceptsEditing(bool b)
747 {
748     EditorClientQt::acceptsEditing = b;
749 }
750 
dumpNotification(bool b)751 void DumpRenderTreeSupportQt::dumpNotification(bool b)
752 {
753 #if ENABLE(NOTIFICATIONS)
754     NotificationPresenterClientQt::dumpNotification = b;
755 #endif
756 }
757 
viewportAsText(QWebPage * page,int deviceDPI,const QSize & deviceSize,const QSize & availableSize)758 QString DumpRenderTreeSupportQt::viewportAsText(QWebPage* page, int deviceDPI, const QSize& deviceSize, const QSize& availableSize)
759 {
760     WebCore::ViewportArguments args = page->d->viewportArguments();
761 
762     WebCore::ViewportAttributes conf = WebCore::computeViewportAttributes(args,
763         /* desktop-width */ 980,
764         /* device-width  */ deviceSize.width(),
765         /* device-height */ deviceSize.height(),
766         /* device-dpi    */ deviceDPI,
767         availableSize);
768 
769     QString res;
770     res = res.sprintf("viewport size %dx%d scale %f with limits [%f, %f] and userScalable %f\n",
771             conf.layoutSize.width(),
772             conf.layoutSize.height(),
773             conf.initialScale,
774             conf.minimumScale,
775             conf.maximumScale,
776             conf.userScalable);
777 
778     return res;
779 }
780 
activeMockDeviceOrientationClient(bool b)781 void DumpRenderTreeSupportQt::activeMockDeviceOrientationClient(bool b)
782 {
783 #if ENABLE(DEVICE_ORIENTATION)
784     DeviceOrientationClientMockQt::mockIsActive = b;
785 #endif
786 }
787 
removeMockDeviceOrientation()788 void DumpRenderTreeSupportQt::removeMockDeviceOrientation()
789 {
790 #if ENABLE(DEVICE_ORIENTATION)
791     DeviceOrientationClientMockQt* client = DeviceOrientationClientMockQt::client();
792     delete client;
793 #endif
794 }
795 
setMockDeviceOrientation(bool canProvideAlpha,double alpha,bool canProvideBeta,double beta,bool canProvideGamma,double gamma)796 void DumpRenderTreeSupportQt::setMockDeviceOrientation(bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma)
797 {
798 #if ENABLE(DEVICE_ORIENTATION)
799     DeviceOrientationClientMockQt::client()->setOrientation(canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma);
800 #endif
801 }
802 
resetGeolocationMock(QWebPage * page)803 void DumpRenderTreeSupportQt::resetGeolocationMock(QWebPage* page)
804 {
805 #if ENABLE(CLIENT_BASED_GEOLOCATION)
806     Page* corePage = QWebPagePrivate::core(page);
807     GeolocationClientMock* mockClient = toGeolocationClientMock(corePage->geolocationController()->client());
808     mockClient->reset();
809 #endif
810 }
811 
setMockGeolocationPermission(QWebPage * page,bool allowed)812 void DumpRenderTreeSupportQt::setMockGeolocationPermission(QWebPage* page, bool allowed)
813 {
814 #if ENABLE(CLIENT_BASED_GEOLOCATION)
815     Page* corePage = QWebPagePrivate::core(page);
816     GeolocationClientMock* mockClient = toGeolocationClientMock(corePage->geolocationController()->client());
817     mockClient->setPermission(allowed);
818 #endif
819 }
820 
setMockGeolocationPosition(QWebPage * page,double latitude,double longitude,double accuracy)821 void DumpRenderTreeSupportQt::setMockGeolocationPosition(QWebPage* page, double latitude, double longitude, double accuracy)
822 {
823 #if ENABLE(CLIENT_BASED_GEOLOCATION)
824     Page* corePage = QWebPagePrivate::core(page);
825     GeolocationClientMock* mockClient = toGeolocationClientMock(corePage->geolocationController()->client());
826     mockClient->setPosition(GeolocationPosition::create(currentTime(), latitude, longitude, accuracy));
827 #endif
828 }
829 
setMockGeolocationError(QWebPage * page,int errorCode,const QString & message)830 void DumpRenderTreeSupportQt::setMockGeolocationError(QWebPage* page, int errorCode, const QString& message)
831 {
832 #if ENABLE(CLIENT_BASED_GEOLOCATION)
833     Page* corePage = QWebPagePrivate::core(page);
834 
835     GeolocationError::ErrorCode code = GeolocationError::PositionUnavailable;
836     switch (errorCode) {
837     case PositionError::PERMISSION_DENIED:
838         code = GeolocationError::PermissionDenied;
839         break;
840     case PositionError::POSITION_UNAVAILABLE:
841         code = GeolocationError::PositionUnavailable;
842         break;
843     }
844 
845     GeolocationClientMock* mockClient = static_cast<GeolocationClientMock*>(corePage->geolocationController()->client());
846     mockClient->setError(GeolocationError::create(code, message));
847 #endif
848 }
849 
numberOfPendingGeolocationPermissionRequests(QWebPage * page)850 int DumpRenderTreeSupportQt::numberOfPendingGeolocationPermissionRequests(QWebPage* page)
851 {
852 #if ENABLE(CLIENT_BASED_GEOLOCATION)
853     Page* corePage = QWebPagePrivate::core(page);
854     GeolocationClientMock* mockClient = toGeolocationClientMock(corePage->geolocationController()->client());
855     return mockClient->numberOfPendingPermissionRequests();
856 #else
857     return -1;
858 #endif
859 }
860 
isTargetItem(const QWebHistoryItem & historyItem)861 bool DumpRenderTreeSupportQt::isTargetItem(const QWebHistoryItem& historyItem)
862 {
863     QWebHistoryItem it = historyItem;
864     if (QWebHistoryItemPrivate::core(&it)->isTargetItem())
865         return true;
866     return false;
867 }
868 
historyItemTarget(const QWebHistoryItem & historyItem)869 QString DumpRenderTreeSupportQt::historyItemTarget(const QWebHistoryItem& historyItem)
870 {
871     QWebHistoryItem it = historyItem;
872     return (QWebHistoryItemPrivate::core(&it)->target());
873 }
874 
getChildHistoryItems(const QWebHistoryItem & historyItem)875 QMap<QString, QWebHistoryItem> DumpRenderTreeSupportQt::getChildHistoryItems(const QWebHistoryItem& historyItem)
876 {
877     QWebHistoryItem it = historyItem;
878     HistoryItem* item = QWebHistoryItemPrivate::core(&it);
879     const WebCore::HistoryItemVector& children = item->children();
880 
881     unsigned size = children.size();
882     QMap<QString, QWebHistoryItem> kids;
883     for (unsigned i = 0; i < size; ++i) {
884         QWebHistoryItem kid(new QWebHistoryItemPrivate(children[i].get()));
885         kids.insert(DumpRenderTreeSupportQt::historyItemTarget(kid), kid);
886     }
887     return kids;
888 }
889 
shouldClose(QWebFrame * frame)890 bool DumpRenderTreeSupportQt::shouldClose(QWebFrame* frame)
891 {
892     WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
893     return coreFrame->loader()->shouldClose();
894 }
895 
clearScriptWorlds()896 void DumpRenderTreeSupportQt::clearScriptWorlds()
897 {
898     m_worldMap.clear();
899 }
900 
evaluateScriptInIsolatedWorld(QWebFrame * frame,int worldID,const QString & script)901 void DumpRenderTreeSupportQt::evaluateScriptInIsolatedWorld(QWebFrame* frame, int worldID, const QString& script)
902 {
903     QWebScriptWorld* scriptWorld;
904     if (!worldID) {
905         scriptWorld = new QWebScriptWorld();
906     } else if (!m_worldMap.contains(worldID)) {
907         scriptWorld = new QWebScriptWorld();
908         m_worldMap.insert(worldID, scriptWorld);
909     } else
910         scriptWorld = m_worldMap.value(worldID);
911 
912     WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
913 
914     ScriptController* proxy = coreFrame->script();
915 
916     if (!proxy)
917         return;
918 #if USE(JSC)
919     proxy->executeScriptInWorld(scriptWorld->world(), script, true);
920 #elif USE(V8)
921     ScriptSourceCode source(script);
922     Vector<ScriptSourceCode> sources;
923     sources.append(source);
924     proxy->evaluateInIsolatedWorld(0, sources, true);
925 #endif
926 }
927 
isPageBoxVisible(QWebFrame * frame,int pageIndex)928 bool DumpRenderTreeSupportQt::isPageBoxVisible(QWebFrame* frame, int pageIndex)
929 {
930     WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
931     return coreFrame->document()->isPageBoxVisible(pageIndex);
932 }
933 
pageSizeAndMarginsInPixels(QWebFrame * frame,int pageIndex,int width,int height,int marginTop,int marginRight,int marginBottom,int marginLeft)934 QString DumpRenderTreeSupportQt::pageSizeAndMarginsInPixels(QWebFrame* frame, int pageIndex, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft)
935 {
936     WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
937     return PrintContext::pageSizeAndMarginsInPixels(coreFrame, pageIndex, width, height,
938                                                     marginTop, marginRight, marginBottom, marginLeft);
939 }
940 
pageProperty(QWebFrame * frame,const QString & propertyName,int pageNumber)941 QString DumpRenderTreeSupportQt::pageProperty(QWebFrame* frame, const QString& propertyName, int pageNumber)
942 {
943     WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
944     return PrintContext::pageProperty(coreFrame, propertyName.toUtf8().constData(), pageNumber);
945 }
946 
addUserStyleSheet(QWebPage * page,const QString & sourceCode)947 void DumpRenderTreeSupportQt::addUserStyleSheet(QWebPage* page, const QString& sourceCode)
948 {
949     page->handle()->page->group().addUserStyleSheetToWorld(mainThreadNormalWorld(), sourceCode, QUrl(), nullptr, nullptr, WebCore::InjectInAllFrames);
950 }
951 
simulateDesktopNotificationClick(const QString & title)952 void DumpRenderTreeSupportQt::simulateDesktopNotificationClick(const QString& title)
953 {
954 #if ENABLE(NOTIFICATIONS)
955     NotificationPresenterClientQt::notificationPresenter()->notificationClicked(title);
956 #endif
957 }
958 
plainText(const QVariant & range)959 QString DumpRenderTreeSupportQt::plainText(const QVariant& range)
960 {
961     QMap<QString, QVariant> map = range.toMap();
962     QVariant startContainer  = map.value(QLatin1String("startContainer"));
963     map = startContainer.toMap();
964 
965     return map.value(QLatin1String("innerText")).toString();
966 }
967 
nodesFromRect(const QWebElement & document,int x,int y,unsigned top,unsigned right,unsigned bottom,unsigned left,bool ignoreClipping)968 QVariantList DumpRenderTreeSupportQt::nodesFromRect(const QWebElement& document, int x, int y, unsigned top, unsigned right, unsigned bottom, unsigned left, bool ignoreClipping)
969 {
970     QVariantList res;
971     WebCore::Element* webElement = document.m_element;
972     if (!webElement)
973         return res;
974 
975     Document* doc = webElement->document();
976     if (!doc)
977         return res;
978     RefPtr<NodeList> nodes = doc->nodesFromRect(x, y, top, right, bottom, left, ignoreClipping);
979     for (unsigned i = 0; i < nodes->length(); i++) {
980         // QWebElement will be null if the Node is not an HTML Element
981         if (nodes->item(i)->isHTMLElement())
982             res << QVariant::fromValue(QWebElement(nodes->item(i)));
983         else
984             res << QVariant::fromValue(QDRTNode(nodes->item(i)));
985     }
986     return res;
987 }
988 
989 // API Candidate?
responseMimeType(QWebFrame * frame)990 QString DumpRenderTreeSupportQt::responseMimeType(QWebFrame* frame)
991 {
992     WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
993     WebCore::DocumentLoader* docLoader = coreFrame->loader()->documentLoader();
994     return docLoader->responseMIMEType();
995 }
996 
clearOpener(QWebFrame * frame)997 void DumpRenderTreeSupportQt::clearOpener(QWebFrame* frame)
998 {
999     WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
1000     coreFrame->loader()->setOpener(0);
1001 }
1002 
addURLToRedirect(const QString & origin,const QString & destination)1003 void DumpRenderTreeSupportQt::addURLToRedirect(const QString& origin, const QString& destination)
1004 {
1005     FrameLoaderClientQt::URLsToRedirect[origin] = destination;
1006 }
1007 
iterateContextMenu(QMenu * menu)1008 static QStringList iterateContextMenu(QMenu* menu)
1009 {
1010     if (!menu)
1011         return QStringList();
1012 
1013     QStringList items;
1014     QList<QAction *> actions = menu->actions();
1015     for (int i = 0; i < actions.count(); ++i) {
1016         if (actions.at(i)->isSeparator())
1017             items << QLatin1String("<separator>");
1018         else
1019             items << actions.at(i)->text();
1020         if (actions.at(i)->menu())
1021             items << iterateContextMenu(actions.at(i)->menu());
1022     }
1023     return items;
1024 }
1025 
contextMenu(QWebPage * page)1026 QStringList DumpRenderTreeSupportQt::contextMenu(QWebPage* page)
1027 {
1028 #ifndef QT_NO_CONTEXTMENU
1029     return iterateContextMenu(page->d->currentContextMenu);
1030 #else
1031     return QStringList();
1032 #endif
1033 }
1034 
defaultMinimumTimerInterval()1035 double DumpRenderTreeSupportQt::defaultMinimumTimerInterval()
1036 {
1037     return Settings::defaultMinDOMTimerInterval();
1038 }
1039 
setMinimumTimerInterval(QWebPage * page,double interval)1040 void DumpRenderTreeSupportQt::setMinimumTimerInterval(QWebPage* page, double interval)
1041 {
1042     Page* corePage = QWebPagePrivate::core(page);
1043     if (!corePage)
1044         return;
1045 
1046     corePage->settings()->setMinDOMTimerInterval(interval);
1047 }
1048 
mediaContentUrlByElementId(QWebFrame * frame,const QString & elementId)1049 QUrl DumpRenderTreeSupportQt::mediaContentUrlByElementId(QWebFrame* frame, const QString& elementId)
1050 {
1051     QUrl res;
1052 
1053 #if ENABLE(VIDEO) && USE(QT_MULTIMEDIA)
1054     Frame* coreFrame = QWebFramePrivate::core(frame);
1055     if (!coreFrame)
1056         return res;
1057 
1058     Document* doc = coreFrame->document();
1059     if (!doc)
1060         return res;
1061 
1062     Node* coreNode = doc->getElementById(elementId);
1063     if (!coreNode)
1064         return res;
1065 
1066     HTMLVideoElement* videoElement = static_cast<HTMLVideoElement*>(coreNode);
1067     PlatformMedia platformMedia = videoElement->platformMedia();
1068     if (platformMedia.type != PlatformMedia::QtMediaPlayerType)
1069         return res;
1070 
1071     MediaPlayerPrivateQt* mediaPlayerQt = static_cast<MediaPlayerPrivateQt*>(platformMedia.media.qtMediaPlayer);
1072     if (mediaPlayerQt && mediaPlayerQt->mediaPlayer())
1073         res = mediaPlayerQt->mediaPlayer()->media().canonicalUrl();
1074 #endif
1075 
1076     return res;
1077 }
1078 
1079 // API Candidate?
setAlternateHtml(QWebFrame * frame,const QString & html,const QUrl & baseUrl,const QUrl & failingUrl)1080 void DumpRenderTreeSupportQt::setAlternateHtml(QWebFrame* frame, const QString& html, const QUrl& baseUrl, const QUrl& failingUrl)
1081 {
1082     KURL kurl(baseUrl);
1083     WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
1084     WebCore::ResourceRequest request(kurl);
1085     const QByteArray utf8 = html.toUtf8();
1086     WTF::RefPtr<WebCore::SharedBuffer> data = WebCore::SharedBuffer::create(utf8.constData(), utf8.length());
1087     WebCore::SubstituteData substituteData(data, WTF::String("text/html"), WTF::String("utf-8"), failingUrl);
1088     coreFrame->loader()->load(request, substituteData, false);
1089 }
1090 
shadowRoot(const QWebElement & element)1091 QVariant DumpRenderTreeSupportQt::shadowRoot(const QWebElement& element)
1092 {
1093     WebCore::Element* webElement = element.m_element;
1094     if (!webElement)
1095         return QVariant();
1096 
1097     ShadowRoot* webShadowRoot = webElement->shadowRoot();
1098     if (!webShadowRoot)
1099         return QVariant();
1100 
1101     return QVariant::fromValue(QDRTNode(webShadowRoot));
1102 }
1103 
ensureShadowRoot(const QWebElement & element)1104 QVariant DumpRenderTreeSupportQt::ensureShadowRoot(const QWebElement& element)
1105 {
1106     WebCore::Element* webElement = element.m_element;
1107     if (!webElement)
1108         return QVariant();
1109 
1110     return QVariant::fromValue(QDRTNode(webElement->ensureShadowRoot()));
1111 }
1112 
removeShadowRoot(const QWebElement & element)1113 void DumpRenderTreeSupportQt::removeShadowRoot(const QWebElement& element)
1114 {
1115     WebCore::Element* webElement = element.m_element;
1116     if (!webElement)
1117         return;
1118     webElement->removeShadowRoot();
1119 }
1120 
injectInternalsObject(QWebFrame * frame)1121 void DumpRenderTreeSupportQt::injectInternalsObject(QWebFrame* frame)
1122 {
1123     WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
1124 #if USE(JSC)
1125     JSC::JSLock lock(JSC::SilenceAssertionsOnly);
1126 
1127     JSDOMWindow* window = toJSDOMWindow(coreFrame, mainThreadNormalWorld());
1128     Q_ASSERT(window);
1129 
1130     JSC::ExecState* exec = window->globalExec();
1131     Q_ASSERT(exec);
1132 
1133     JSContextRef context = toRef(exec);
1134     WebCoreTestSupport::injectInternalsObject(context);
1135 #elif USE(V8)
1136     WebCoreTestSupport::injectInternalsObject(V8Proxy::mainWorldContext(coreFrame));
1137 #endif
1138 }
1139 
resetInternalsObject(QWebFrame * frame)1140 void DumpRenderTreeSupportQt::resetInternalsObject(QWebFrame* frame)
1141 {
1142     WebCore::Frame* coreFrame = QWebFramePrivate::core(frame);
1143 #if USE(JSC)
1144     JSC::JSLock lock(JSC::SilenceAssertionsOnly);
1145 
1146     JSDOMWindow* window = toJSDOMWindow(coreFrame, mainThreadNormalWorld());
1147     Q_ASSERT(window);
1148 
1149     JSC::ExecState* exec = window->globalExec();
1150     Q_ASSERT(exec);
1151 
1152     JSContextRef context = toRef(exec);
1153     WebCoreTestSupport::resetInternalsObject(context);
1154 #elif USE(V8)
1155     WebCoreTestSupport::resetInternalsObject(V8Proxy::mainWorldContext(coreFrame));
1156 #endif
1157 }
1158 
1159 // Provide a backward compatibility with previously exported private symbols as of QtWebKit 4.6 release
1160 
qt_resumeActiveDOMObjects(QWebFrame * frame)1161 void QWEBKIT_EXPORT qt_resumeActiveDOMObjects(QWebFrame* frame)
1162 {
1163     DumpRenderTreeSupportQt::resumeActiveDOMObjects(frame);
1164 }
1165 
qt_suspendActiveDOMObjects(QWebFrame * frame)1166 void QWEBKIT_EXPORT qt_suspendActiveDOMObjects(QWebFrame* frame)
1167 {
1168     DumpRenderTreeSupportQt::suspendActiveDOMObjects(frame);
1169 }
1170 
qt_drt_clearFrameName(QWebFrame * frame)1171 void QWEBKIT_EXPORT qt_drt_clearFrameName(QWebFrame* frame)
1172 {
1173     DumpRenderTreeSupportQt::clearFrameName(frame);
1174 }
1175 
qt_drt_garbageCollector_collect()1176 void QWEBKIT_EXPORT qt_drt_garbageCollector_collect()
1177 {
1178     DumpRenderTreeSupportQt::garbageCollectorCollect();
1179 }
1180 
qt_drt_garbageCollector_collectOnAlternateThread(bool waitUntilDone)1181 void QWEBKIT_EXPORT qt_drt_garbageCollector_collectOnAlternateThread(bool waitUntilDone)
1182 {
1183     DumpRenderTreeSupportQt::garbageCollectorCollectOnAlternateThread(waitUntilDone);
1184 }
1185 
qt_drt_javaScriptObjectsCount()1186 int QWEBKIT_EXPORT qt_drt_javaScriptObjectsCount()
1187 {
1188     return DumpRenderTreeSupportQt::javaScriptObjectsCount();
1189 }
1190 
qt_drt_numberOfActiveAnimations(QWebFrame * frame)1191 int QWEBKIT_EXPORT qt_drt_numberOfActiveAnimations(QWebFrame* frame)
1192 {
1193     return DumpRenderTreeSupportQt::numberOfActiveAnimations(frame);
1194 }
1195 
qt_drt_overwritePluginDirectories()1196 void QWEBKIT_EXPORT qt_drt_overwritePluginDirectories()
1197 {
1198     DumpRenderTreeSupportQt::overwritePluginDirectories();
1199 }
1200 
qt_drt_pauseAnimation(QWebFrame * frame,const QString & animationName,double time,const QString & elementId)1201 bool QWEBKIT_EXPORT qt_drt_pauseAnimation(QWebFrame* frame, const QString& animationName, double time, const QString& elementId)
1202 {
1203     return DumpRenderTreeSupportQt::pauseAnimation(frame, animationName, time, elementId);
1204 }
1205 
qt_drt_pauseTransitionOfProperty(QWebFrame * frame,const QString & propertyName,double time,const QString & elementId)1206 bool QWEBKIT_EXPORT qt_drt_pauseTransitionOfProperty(QWebFrame* frame, const QString& propertyName, double time, const QString &elementId)
1207 {
1208     return DumpRenderTreeSupportQt::pauseTransitionOfProperty(frame, propertyName, time, elementId);
1209 }
1210 
qt_drt_resetOriginAccessWhiteLists()1211 void QWEBKIT_EXPORT qt_drt_resetOriginAccessWhiteLists()
1212 {
1213     DumpRenderTreeSupportQt::resetOriginAccessWhiteLists();
1214 }
1215 
qt_drt_run(bool b)1216 void QWEBKIT_EXPORT qt_drt_run(bool b)
1217 {
1218     DumpRenderTreeSupportQt::setDumpRenderTreeModeEnabled(b);
1219 }
1220 
qt_drt_setJavaScriptProfilingEnabled(QWebFrame * frame,bool enabled)1221 void QWEBKIT_EXPORT qt_drt_setJavaScriptProfilingEnabled(QWebFrame* frame, bool enabled)
1222 {
1223     DumpRenderTreeSupportQt::setJavaScriptProfilingEnabled(frame, enabled);
1224 }
1225 
qt_drt_whiteListAccessFromOrigin(const QString & sourceOrigin,const QString & destinationProtocol,const QString & destinationHost,bool allowDestinationSubdomains)1226 void QWEBKIT_EXPORT qt_drt_whiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains)
1227 {
1228     DumpRenderTreeSupportQt::whiteListAccessFromOrigin(sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains);
1229 }
1230 
qt_webpage_groupName(QWebPage * page)1231 QString QWEBKIT_EXPORT qt_webpage_groupName(QWebPage* page)
1232 {
1233     return DumpRenderTreeSupportQt::webPageGroupName(page);
1234 }
1235 
qt_webpage_setGroupName(QWebPage * page,const QString & groupName)1236 void QWEBKIT_EXPORT qt_webpage_setGroupName(QWebPage* page, const QString& groupName)
1237 {
1238     DumpRenderTreeSupportQt::webPageSetGroupName(page, groupName);
1239 }
1240 
qt_dump_frame_loader(bool b)1241 void QWEBKIT_EXPORT qt_dump_frame_loader(bool b)
1242 {
1243     DumpRenderTreeSupportQt::dumpFrameLoader(b);
1244 }
1245 
qt_dump_resource_load_callbacks(bool b)1246 void QWEBKIT_EXPORT qt_dump_resource_load_callbacks(bool b)
1247 {
1248     DumpRenderTreeSupportQt::dumpResourceLoadCallbacks(b);
1249 }
1250 
qt_dump_editing_callbacks(bool b)1251 void QWEBKIT_EXPORT qt_dump_editing_callbacks(bool b)
1252 {
1253     DumpRenderTreeSupportQt::dumpEditingCallbacks(b);
1254 }
1255 
qt_dump_set_accepts_editing(bool b)1256 void QWEBKIT_EXPORT qt_dump_set_accepts_editing(bool b)
1257 {
1258     DumpRenderTreeSupportQt::dumpSetAcceptsEditing(b);
1259 }
1260 
1261