1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
|
/*
Copyright (C) 2010 Robert Hogan <robert@roberthogan.net>
Copyright (C) 2008,2009,2010 Nokia Corporation and/or its subsidiary(-ies)
Copyright (C) 2007 Staikos Computing Services Inc.
Copyright (C) 2007, 2012 Apple Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "DumpRenderTreeSupportQt.h"
#include "APICast.h"
#include "ApplicationCacheStorage.h"
#include "ChromeClientQt.h"
#include "ContainerNode.h"
#include "ContextMenu.h"
#include "ContextMenuClientQt.h"
#include "ContextMenuController.h"
#include "DeviceOrientationClientMock.h"
#include "DeviceOrientationController.h"
#include "DeviceOrientationData.h"
#include "DocumentLoader.h"
#include "Editor.h"
#include "EditorClientQt.h"
#include "Element.h"
#include "FocusController.h"
#include "Font.h"
#include "Frame.h"
#include "FrameLoadRequest.h"
#include "FrameLoaderClientQt.h"
#include "FrameView.h"
#include "GCController.h"
#include "GeolocationClient.h"
#include "GeolocationClientMock.h"
#include "GeolocationController.h"
#include "GeolocationError.h"
#include "GeolocationPosition.h"
#include "HTMLFormElement.h"
#include "HTMLInputElement.h"
#include "HistoryItem.h"
#include "InspectorController.h"
#include "JSNode.h"
#include "NodeList.h"
#include "NotificationPresenterClientQt.h"
#include "Page.h"
#include "PageGroup.h"
#include "PluginDatabase.h"
#include "PluginView.h"
#include "PositionError.h"
#include "PrintContext.h"
#include "QWebFrameAdapter.h"
#include "QWebPageAdapter.h"
#include "RenderListItem.h"
#include "RenderTreeAsText.h"
#include "RuntimeEnabledFeatures.h"
#include "SchemeRegistry.h"
#include "ScriptController.h"
#include "ScriptSourceCode.h"
#include "ScriptValue.h"
#include "SecurityOrigin.h"
#include "SecurityPolicy.h"
#include "Settings.h"
#include "TextIterator.h"
#include "ThirdPartyCookiesQt.h"
#include "WebCoreTestSupport.h"
#include "qt_runtime.h"
#include "qwebelement.h"
#include "qwebhistory.h"
#include "qwebhistory_p.h"
#include "qwebscriptworld.h"
#if ENABLE(VIDEO) && USE(QT_MULTIMEDIA)
#include "HTMLVideoElement.h"
#include "MediaPlayerPrivateQt.h"
#endif
#include <QPainter>
#include <wtf/CurrentTime.h>
using namespace WebCore;
QMap<int, QWebScriptWorld*> m_worldMap;
#if ENABLE(GEOLOCATION)
GeolocationClientMock* toGeolocationClientMock(GeolocationClient* client)
{
ASSERT(QWebPageAdapter::drtRun);
return static_cast<GeolocationClientMock*>(client);
}
#endif
#if ENABLE(DEVICE_ORIENTATION)
DeviceOrientationClientMock* toDeviceOrientationClientMock(DeviceOrientationClient* client)
{
ASSERT(QWebPageAdapter::drtRun);
return static_cast<DeviceOrientationClientMock*>(client);
}
#endif
QDRTNode::QDRTNode()
: m_node(0)
{
}
QDRTNode::QDRTNode(WebCore::Node* node)
: m_node(0)
{
if (node) {
m_node = node;
m_node->ref();
}
}
QDRTNode::~QDRTNode()
{
if (m_node)
m_node->deref();
}
QDRTNode::QDRTNode(const QDRTNode& other)
:m_node(other.m_node)
{
if (m_node)
m_node->ref();
}
QDRTNode& QDRTNode::operator=(const QDRTNode& other)
{
if (this != &other) {
Node* otherNode = other.m_node;
if (otherNode)
otherNode->ref();
if (m_node)
m_node->deref();
m_node = otherNode;
}
return *this;
}
QDRTNode QtDRTNodeRuntime::create(WebCore::Node* node)
{
return QDRTNode(node);
}
WebCore::Node* QtDRTNodeRuntime::get(const QDRTNode& node)
{
return node.m_node;
}
static QVariant convertJSValueToNodeVariant(JSC::JSObject* object, int *distance, HashSet<JSObjectRef>*)
{
if (!object || !object->inherits(&JSNode::s_info))
return QVariant();
return QVariant::fromValue<QDRTNode>(QtDRTNodeRuntime::create((static_cast<JSNode*>(object))->impl()));
}
static JSC::JSValue convertNodeVariantToJSValue(JSC::ExecState* exec, WebCore::JSDOMGlobalObject* globalObject, const QVariant& variant)
{
return toJS(exec, globalObject, QtDRTNodeRuntime::get(variant.value<QDRTNode>()));
}
void QtDRTNodeRuntime::initialize()
{
static bool initialized = false;
if (initialized)
return;
initialized = true;
int id = qRegisterMetaType<QDRTNode>();
JSC::Bindings::registerCustomType(id, convertJSValueToNodeVariant, convertNodeVariantToJSValue);
}
DumpRenderTreeSupportQt::DumpRenderTreeSupportQt()
{
}
DumpRenderTreeSupportQt::~DumpRenderTreeSupportQt()
{
}
void DumpRenderTreeSupportQt::initialize()
{
QtDRTNodeRuntime::initialize();
}
void DumpRenderTreeSupportQt::overwritePluginDirectories()
{
PluginDatabase* db = PluginDatabase::installedPlugins(/* populate */ false);
Vector<String> paths;
String qtPath(qgetenv("QTWEBKIT_PLUGIN_PATH").data());
qtPath.split(UChar(':'), /* allowEmptyEntries */ false, paths);
db->setPluginDirectories(paths);
db->refresh();
}
void DumpRenderTreeSupportQt::setDumpRenderTreeModeEnabled(bool b)
{
QWebPageAdapter::drtRun = b;
#if ENABLE(NETSCAPE_PLUGIN_API) && defined(XP_UNIX)
// PluginViewQt (X11) needs a few workarounds when running under DRT
PluginView::setIsRunningUnderDRT(b);
#endif
}
void DumpRenderTreeSupportQt::setFrameFlatteningEnabled(QWebPageAdapter* adapter, bool enabled)
{
adapter->page->settings()->setFrameFlatteningEnabled(enabled);
}
void DumpRenderTreeSupportQt::webPageSetGroupName(QWebPageAdapter *adapter, const QString& groupName)
{
adapter->page->setGroupName(groupName);
}
QString DumpRenderTreeSupportQt::webPageGroupName(QWebPageAdapter* adapter)
{
return adapter->page->groupName();
}
void DumpRenderTreeSupportQt::webInspectorExecuteScript(QWebPageAdapter* adapter, long callId, const QString& script)
{
#if ENABLE(INSPECTOR)
if (!adapter->page->inspectorController())
return;
adapter->page->inspectorController()->evaluateForTestInFrontend(callId, script);
#endif
}
void DumpRenderTreeSupportQt::webInspectorShow(QWebPageAdapter* adapter)
{
#if ENABLE(INSPECTOR)
if (!adapter->page->inspectorController())
return;
adapter->page->inspectorController()->show();
#endif
}
void DumpRenderTreeSupportQt::webInspectorClose(QWebPageAdapter* adapter)
{
#if ENABLE(INSPECTOR)
if (!adapter->page->inspectorController())
return;
adapter->page->inspectorController()->close();
#endif
}
bool DumpRenderTreeSupportQt::hasDocumentElement(QWebFrameAdapter *adapter)
{
return adapter->frame->document()->documentElement();
}
void DumpRenderTreeSupportQt::setValueForUser(const QWebElement& element, const QString& value)
{
WebCore::Element* webElement = element.m_element;
if (!webElement)
return;
HTMLInputElement* inputElement = webElement->toInputElement();
if (!inputElement)
return;
inputElement->setValueForUser(value);
}
void DumpRenderTreeSupportQt::clearFrameName(QWebFrameAdapter *adapter)
{
Frame* coreFrame = adapter->frame;
coreFrame->tree()->clearName();
}
int DumpRenderTreeSupportQt::javaScriptObjectsCount()
{
return JSDOMWindowBase::commonVM()->heap.globalObjectCount();
}
void DumpRenderTreeSupportQt::garbageCollectorCollect()
{
gcController().garbageCollectNow();
}
void DumpRenderTreeSupportQt::garbageCollectorCollectOnAlternateThread(bool waitUntilDone)
{
gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
}
void DumpRenderTreeSupportQt::whiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains)
{
SecurityPolicy::addOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
}
void DumpRenderTreeSupportQt::removeWhiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains)
{
SecurityPolicy::removeOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
}
void DumpRenderTreeSupportQt::resetOriginAccessWhiteLists()
{
SecurityPolicy::resetOriginAccessWhitelists();
}
void DumpRenderTreeSupportQt::setDomainRelaxationForbiddenForURLScheme(bool forbidden, const QString& scheme)
{
SchemeRegistry::setDomainRelaxationForbiddenForURLScheme(forbidden, scheme);
}
void DumpRenderTreeSupportQt::setCaretBrowsingEnabled(QWebPageAdapter* adapter, bool value)
{
adapter->page->settings()->setCaretBrowsingEnabled(value);
}
void DumpRenderTreeSupportQt::setAuthorAndUserStylesEnabled(QWebPageAdapter* adapter, bool value)
{
adapter->page->settings()->setAuthorAndUserStylesEnabled(value);
}
void DumpRenderTreeSupportQt::executeCoreCommandByName(QWebPageAdapter* adapter, const QString& name, const QString& value)
{
adapter->page->focusController()->focusedOrMainFrame()->editor().command(name).execute(value);
}
bool DumpRenderTreeSupportQt::isCommandEnabled(QWebPageAdapter *adapter, const QString& name)
{
return adapter->page->focusController()->focusedOrMainFrame()->editor().command(name).isEnabled();
}
QVariantList DumpRenderTreeSupportQt::selectedRange(QWebPageAdapter *adapter)
{
WebCore::Frame* frame = adapter->page->focusController()->focusedOrMainFrame();
QVariantList selectedRange;
RefPtr<Range> range = frame->selection()->toNormalizedRange().get();
Element* selectionRoot = frame->selection()->rootEditableElement();
Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement();
RefPtr<Range> testRange = Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset());
ASSERT(testRange->startContainer() == scope);
int startPosition = TextIterator::rangeLength(testRange.get());
ExceptionCode ec;
testRange->setEnd(range->endContainer(), range->endOffset(), ec);
ASSERT(testRange->startContainer() == scope);
int endPosition = TextIterator::rangeLength(testRange.get());
selectedRange << startPosition << (endPosition - startPosition);
return selectedRange;
}
QVariantList DumpRenderTreeSupportQt::firstRectForCharacterRange(QWebPageAdapter *adapter, int location, int length)
{
WebCore::Frame* frame = adapter->page->focusController()->focusedOrMainFrame();
QVariantList rect;
if ((location + length < location) && (location + length))
length = 0;
RefPtr<Range> range = TextIterator::rangeFromLocationAndLength(frame->selection()->rootEditableElementOrDocumentElement(), location, length);
if (!range)
return QVariantList();
QRect resultRect = frame->editor().firstRectForRange(range.get());
rect << resultRect.x() << resultRect.y() << resultRect.width() << resultRect.height();
return rect;
}
void DumpRenderTreeSupportQt::setWindowsBehaviorAsEditingBehavior(QWebPageAdapter* adapter)
{
Page* corePage = adapter->page;
if (!corePage)
return;
corePage->settings()->setEditingBehaviorType(EditingWindowsBehavior);
}
void DumpRenderTreeSupportQt::clearAllApplicationCaches()
{
WebCore::cacheStorage().empty();
WebCore::cacheStorage().vacuumDatabaseFile();
}
void DumpRenderTreeSupportQt::dumpFrameLoader(bool b)
{
FrameLoaderClientQt::dumpFrameLoaderCallbacks = b;
}
void DumpRenderTreeSupportQt::dumpProgressFinishedCallback(bool b)
{
FrameLoaderClientQt::dumpProgressFinishedCallback = b;
}
void DumpRenderTreeSupportQt::dumpUserGestureInFrameLoader(bool b)
{
FrameLoaderClientQt::dumpUserGestureInFrameLoaderCallbacks = b;
}
void DumpRenderTreeSupportQt::dumpResourceLoadCallbacks(bool b)
{
FrameLoaderClientQt::dumpResourceLoadCallbacks = b;
}
void DumpRenderTreeSupportQt::dumpResourceLoadCallbacksPath(const QString& path)
{
FrameLoaderClientQt::dumpResourceLoadCallbacksPath = path;
}
void DumpRenderTreeSupportQt::dumpResourceResponseMIMETypes(bool b)
{
FrameLoaderClientQt::dumpResourceResponseMIMETypes = b;
}
void DumpRenderTreeSupportQt::dumpWillCacheResponseCallbacks(bool b)
{
FrameLoaderClientQt::dumpWillCacheResponseCallbacks = b;
}
void DumpRenderTreeSupportQt::setWillSendRequestReturnsNullOnRedirect(bool b)
{
FrameLoaderClientQt::sendRequestReturnsNullOnRedirect = b;
}
void DumpRenderTreeSupportQt::setWillSendRequestReturnsNull(bool b)
{
FrameLoaderClientQt::sendRequestReturnsNull = b;
}
void DumpRenderTreeSupportQt::setWillSendRequestClearHeaders(const QStringList& headers)
{
FrameLoaderClientQt::sendRequestClearHeaders = headers;
}
void DumpRenderTreeSupportQt::setDeferMainResourceDataLoad(bool b)
{
FrameLoaderClientQt::deferMainResourceDataLoad = b;
}
void DumpRenderTreeSupportQt::setCustomPolicyDelegate(bool enabled, bool permissive)
{
FrameLoaderClientQt::policyDelegateEnabled = enabled;
FrameLoaderClientQt::policyDelegatePermissive = permissive;
}
void DumpRenderTreeSupportQt::dumpHistoryCallbacks(bool b)
{
FrameLoaderClientQt::dumpHistoryCallbacks = b;
}
void DumpRenderTreeSupportQt::dumpVisitedLinksCallbacks(bool b)
{
ChromeClientQt::dumpVisitedLinksCallbacks = b;
}
void DumpRenderTreeSupportQt::dumpEditingCallbacks(bool b)
{
EditorClientQt::dumpEditingCallbacks = b;
}
void DumpRenderTreeSupportQt::dumpSetAcceptsEditing(bool b)
{
EditorClientQt::acceptsEditing = b;
}
void DumpRenderTreeSupportQt::dumpNotification(bool b)
{
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
NotificationPresenterClientQt::dumpNotification = b;
#endif
}
QString DumpRenderTreeSupportQt::viewportAsText(QWebPageAdapter* adapter, int deviceDPI, const QSize& deviceSize, const QSize& availableSize)
{
WebCore::ViewportArguments args = adapter->viewportArguments();
float devicePixelRatio = deviceDPI / WebCore::ViewportArguments::deprecatedTargetDPI;
WebCore::ViewportAttributes conf = WebCore::computeViewportAttributes(args,
/* desktop-width */980,
/* device-width */deviceSize.width(),
/* device-height */deviceSize.height(),
devicePixelRatio,
availableSize);
WebCore::restrictMinimumScaleFactorToViewportSize(conf, availableSize, devicePixelRatio);
WebCore::restrictScaleFactorToInitialScaleIfNotUserScalable(conf);
QString res;
res = res.sprintf("viewport size %dx%d scale %f with limits [%f, %f] and userScalable %f\n",
static_cast<int>(conf.layoutSize.width()),
static_cast<int>(conf.layoutSize.height()),
conf.initialScale,
conf.minimumScale,
conf.maximumScale,
conf.userScalable);
return res;
}
void DumpRenderTreeSupportQt::scalePageBy(QWebFrameAdapter* adapter, float scalefactor, const QPoint& origin)
{
WebCore::Frame* coreFrame = adapter->frame;
if (Page* page = coreFrame->page())
page->setPageScaleFactor(scalefactor, origin);
}
void DumpRenderTreeSupportQt::setMockDeviceOrientation(QWebPageAdapter* adapter, bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma)
{
#if ENABLE(DEVICE_ORIENTATION)
Page* corePage = adapter->page;
DeviceOrientationClientMock* mockClient = toDeviceOrientationClientMock(DeviceOrientationController::from(corePage)->deviceOrientationClient());
mockClient->setOrientation(DeviceOrientationData::create(canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma));
#endif
}
void DumpRenderTreeSupportQt::resetGeolocationMock(QWebPageAdapter* adapter)
{
#if ENABLE(GEOLOCATION)
Page* corePage = adapter->page;
GeolocationClientMock* mockClient = toGeolocationClientMock(GeolocationController::from(corePage)->client());
mockClient->reset();
#endif
}
void DumpRenderTreeSupportQt::setMockGeolocationPermission(QWebPageAdapter* adapter, bool allowed)
{
#if ENABLE(GEOLOCATION)
Page* corePage = adapter->page;
GeolocationClientMock* mockClient = toGeolocationClientMock(GeolocationController::from(corePage)->client());
mockClient->setPermission(allowed);
#endif
}
void DumpRenderTreeSupportQt::setMockGeolocationPosition(QWebPageAdapter* adapter, double latitude, double longitude, double accuracy)
{
#if ENABLE(GEOLOCATION)
Page* corePage = adapter->page;
GeolocationClientMock* mockClient = toGeolocationClientMock(GeolocationController::from(corePage)->client());
mockClient->setPosition(GeolocationPosition::create(currentTime(), latitude, longitude, accuracy));
#endif
}
void DumpRenderTreeSupportQt::setMockGeolocationPositionUnavailableError(QWebPageAdapter* adapter, const QString& message)
{
#if ENABLE(GEOLOCATION)
Page* corePage = adapter->page;
GeolocationClientMock* mockClient = static_cast<GeolocationClientMock*>(GeolocationController::from(corePage)->client());
mockClient->setPositionUnavailableError(message);
#endif
}
int DumpRenderTreeSupportQt::numberOfPendingGeolocationPermissionRequests(QWebPageAdapter* adapter)
{
#if ENABLE(GEOLOCATION)
Page* corePage = adapter->page;
GeolocationClientMock* mockClient = toGeolocationClientMock(GeolocationController::from(corePage)->client());
return mockClient->numberOfPendingPermissionRequests();
#else
return -1;
#endif
}
bool DumpRenderTreeSupportQt::isTargetItem(const QWebHistoryItem& historyItem)
{
QWebHistoryItem it = historyItem;
if (QWebHistoryItemPrivate::core(&it)->isTargetItem())
return true;
return false;
}
QString DumpRenderTreeSupportQt::historyItemTarget(const QWebHistoryItem& historyItem)
{
QWebHistoryItem it = historyItem;
return (QWebHistoryItemPrivate::core(&it)->target());
}
QMap<QString, QWebHistoryItem> DumpRenderTreeSupportQt::getChildHistoryItems(const QWebHistoryItem& historyItem)
{
QWebHistoryItem it = historyItem;
HistoryItem* item = QWebHistoryItemPrivate::core(&it);
const WebCore::HistoryItemVector& children = item->children();
unsigned size = children.size();
QMap<QString, QWebHistoryItem> kids;
for (unsigned i = 0; i < size; ++i) {
QWebHistoryItem kid(new QWebHistoryItemPrivate(children[i].get()));
kids.insert(DumpRenderTreeSupportQt::historyItemTarget(kid), kid);
}
return kids;
}
bool DumpRenderTreeSupportQt::shouldClose(QWebFrameAdapter *adapter)
{
WebCore::Frame* coreFrame = adapter->frame;
return coreFrame->loader()->shouldClose();
}
void DumpRenderTreeSupportQt::clearScriptWorlds()
{
m_worldMap.clear();
}
void DumpRenderTreeSupportQt::evaluateScriptInIsolatedWorld(QWebFrameAdapter *adapter, int worldID, const QString& script)
{
QWebScriptWorld* scriptWorld;
if (!worldID) {
scriptWorld = new QWebScriptWorld();
} else if (!m_worldMap.contains(worldID)) {
scriptWorld = new QWebScriptWorld();
m_worldMap.insert(worldID, scriptWorld);
} else
scriptWorld = m_worldMap.value(worldID);
WebCore::Frame* coreFrame = adapter->frame;
ScriptController* proxy = coreFrame->script();
if (!proxy)
return;
proxy->executeScriptInWorld(scriptWorld->world(), script, true);
}
void DumpRenderTreeSupportQt::addUserStyleSheet(QWebPageAdapter* adapter, const QString& sourceCode)
{
adapter->page->group().addUserStyleSheetToWorld(mainThreadNormalWorld(), sourceCode, QUrl(), Vector<String>(), Vector<String>(), WebCore::InjectInAllFrames);
}
void DumpRenderTreeSupportQt::removeUserStyleSheets(QWebPageAdapter* adapter)
{
adapter->page->group().removeUserStyleSheetsFromWorld(mainThreadNormalWorld());
}
void DumpRenderTreeSupportQt::simulateDesktopNotificationClick(const QString& title)
{
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
NotificationPresenterClientQt::notificationPresenter()->notificationClicked(title);
#endif
}
void DumpRenderTreeSupportQt::setDefersLoading(QWebPageAdapter* adapter, bool flag)
{
Page* corePage = adapter->page;
if (corePage)
corePage->setDefersLoading(flag);
}
void DumpRenderTreeSupportQt::goBack(QWebPageAdapter* adapter)
{
Page* corePage = adapter->page;
if (corePage)
corePage->goBack();
}
// API Candidate?
QString DumpRenderTreeSupportQt::responseMimeType(QWebFrameAdapter* adapter)
{
WebCore::Frame* coreFrame = adapter->frame;
WebCore::DocumentLoader* docLoader = coreFrame->loader()->documentLoader();
return docLoader->responseMIMEType();
}
void DumpRenderTreeSupportQt::clearOpener(QWebFrameAdapter* adapter)
{
WebCore::Frame* coreFrame = adapter->frame;
coreFrame->loader()->setOpener(0);
}
void DumpRenderTreeSupportQt::addURLToRedirect(const QString& origin, const QString& destination)
{
FrameLoaderClientQt::URLsToRedirect[origin] = destination;
}
void DumpRenderTreeSupportQt::setInteractiveFormValidationEnabled(QWebPageAdapter* adapter, bool enable)
{
Page* corePage = adapter->page;
if (corePage)
corePage->settings()->setInteractiveFormValidationEnabled(enable);
}
QStringList DumpRenderTreeSupportQt::contextMenu(QWebPageAdapter* page)
{
return page->menuActionsAsText();
}
bool DumpRenderTreeSupportQt::thirdPartyCookiePolicyAllows(QWebPageAdapter *adapter, const QUrl& url, const QUrl& firstPartyUrl)
{
Page* corePage = adapter->page;
return thirdPartyCookiePolicyPermits(corePage->mainFrame()->loader()->networkingContext(), url, firstPartyUrl);
}
void DumpRenderTreeSupportQt::enableMockScrollbars()
{
Settings::setMockScrollbarsEnabled(true);
}
QUrl DumpRenderTreeSupportQt::mediaContentUrlByElementId(QWebFrameAdapter* adapter, const QString& elementId)
{
QUrl res;
#if ENABLE(VIDEO) && USE(QT_MULTIMEDIA)
Frame* coreFrame = adapter->frame;
if (!coreFrame)
return res;
Document* doc = coreFrame->document();
if (!doc)
return res;
Node* coreNode = doc->getElementById(elementId);
if (!coreNode)
return res;
HTMLVideoElement* videoElement = toHTMLVideoElement(coreNode);
PlatformMedia platformMedia = videoElement->platformMedia();
if (platformMedia.type != PlatformMedia::QtMediaPlayerType)
return res;
MediaPlayerPrivateQt* mediaPlayerQt = static_cast<MediaPlayerPrivateQt*>(platformMedia.media.qtMediaPlayer);
if (mediaPlayerQt && mediaPlayerQt->mediaPlayer())
res = mediaPlayerQt->mediaPlayer()->media().canonicalUrl();
#endif
return res;
}
// API Candidate?
void DumpRenderTreeSupportQt::setAlternateHtml(QWebFrameAdapter* adapter, const QString& html, const QUrl& baseUrl, const QUrl& failingUrl)
{
KURL kurl(baseUrl);
WebCore::Frame* coreFrame = adapter->frame;
WebCore::ResourceRequest request(kurl);
const QByteArray utf8 = html.toUtf8();
WTF::RefPtr<WebCore::SharedBuffer> data = WebCore::SharedBuffer::create(utf8.constData(), utf8.length());
WebCore::SubstituteData substituteData(data, WTF::String("text/html"), WTF::String("utf-8"), failingUrl);
coreFrame->loader()->load(WebCore::FrameLoadRequest(coreFrame, request, substituteData));
}
void DumpRenderTreeSupportQt::confirmComposition(QWebPageAdapter *adapter, const char* text)
{
Frame* frame = adapter->page->focusController()->focusedOrMainFrame();
if (!frame)
return;
Editor& editor = frame->editor();
if (!editor.hasComposition() && !text)
return;
if (editor.hasComposition()) {
if (text)
editor.confirmComposition(String::fromUTF8(text));
else
editor.confirmComposition();
} else
editor.insertText(String::fromUTF8(text), 0);
}
void DumpRenderTreeSupportQt::injectInternalsObject(QWebFrameAdapter* adapter)
{
WebCore::Frame* coreFrame = adapter->frame;
JSDOMWindow* window = toJSDOMWindow(coreFrame, mainThreadNormalWorld());
Q_ASSERT(window);
JSC::ExecState* exec = window->globalExec();
Q_ASSERT(exec);
JSC::JSLockHolder lock(exec);
JSContextRef context = toRef(exec);
WebCoreTestSupport::injectInternalsObject(context);
}
void DumpRenderTreeSupportQt::injectInternalsObject(JSContextRef context)
{
WebCoreTestSupport::injectInternalsObject(context);
}
void DumpRenderTreeSupportQt::resetInternalsObject(QWebFrameAdapter* adapter)
{
WebCore::Frame* coreFrame = adapter->frame;
JSDOMWindow* window = toJSDOMWindow(coreFrame, mainThreadNormalWorld());
Q_ASSERT(window);
JSC::ExecState* exec = window->globalExec();
Q_ASSERT(exec);
JSC::JSLockHolder lock(exec);
JSContextRef context = toRef(exec);
WebCoreTestSupport::resetInternalsObject(context);
}
void DumpRenderTreeSupportQt::resetInternalsObject(JSContextRef context)
{
WebCoreTestSupport::resetInternalsObject(context);
}
QImage DumpRenderTreeSupportQt::paintPagesWithBoundaries(QWebFrameAdapter* adapter)
{
Frame* frame = adapter->frame;
PrintContext printContext(frame);
QRect rect = frame->view()->frameRect();
IntRect pageRect(0, 0, rect.width(), rect.height());
printContext.begin(pageRect.width(), pageRect.height());
float pageHeight = 0;
printContext.computePageRects(pageRect, /* headerHeight */ 0, /* footerHeight */ 0, /* userScaleFactor */ 1.0, pageHeight);
QPainter painter;
int pageCount = printContext.pageCount();
// pages * pageHeight and 1px line between each page
int totalHeight = pageCount * (pageRect.height() + 1) - 1;
QImage image(pageRect.width(), totalHeight, QImage::Format_ARGB32);
image.fill(Qt::white);
painter.begin(&image);
GraphicsContext ctx(&painter);
for (int i = 0; i < printContext.pageCount(); ++i) {
printContext.spoolPage(ctx, i, pageRect.width());
// translate to next page coordinates
ctx.translate(0, pageRect.height() + 1);
// if there is a next page, draw a blue line between these two
if (i + 1 < printContext.pageCount()) {
ctx.save();
ctx.setStrokeColor(Color(0, 0, 255), ColorSpaceDeviceRGB);
ctx.setFillColor(Color(0, 0, 255), ColorSpaceDeviceRGB);
ctx.drawLine(IntPoint(0, -1), IntPoint(pageRect.width(), -1));
ctx.restore();
}
}
painter.end();
printContext.end();
return image;
}
void DumpRenderTreeSupportQt::setTrackRepaintRects(QWebFrameAdapter* adapter, bool enable)
{
adapter->frame->view()->setTracksRepaints(enable);
}
bool DumpRenderTreeSupportQt::trackRepaintRects(QWebFrameAdapter* adapter)
{
return adapter->frame->view()->isTrackingRepaints();
}
void DumpRenderTreeSupportQt::getTrackedRepaintRects(QWebFrameAdapter* adapter, QVector<QRect>& result)
{
Frame* coreFrame = adapter->frame;
const Vector<IntRect>& rects = coreFrame->view()->trackedRepaintRects();
result.resize(rects.size());
for (size_t i = 0; i < rects.size(); ++i)
result.append(rects[i]);
}
void DumpRenderTreeSupportQt::setSeamlessIFramesEnabled(bool enabled)
{
#if ENABLE(IFRAME_SEAMLESS)
WebCore::RuntimeEnabledFeatures::setSeamlessIFramesEnabled(enabled);
#else
UNUSED_PARAM(enabled);
#endif
}
void DumpRenderTreeSupportQt::setShouldUseFontSmoothing(bool enabled)
{
WebCore::Font::setShouldUseSmoothing(enabled);
}
QString DumpRenderTreeSupportQt::frameRenderTreeDump(QWebFrameAdapter* adapter)
{
if (adapter->frame->view() && adapter->frame->view()->layoutPending())
adapter->frame->view()->layout();
return externalRepresentation(adapter->frame);
}
void DumpRenderTreeSupportQt::clearNotificationPermissions()
{
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
WebCore::NotificationPresenterClientQt::notificationPresenter()->clearCachedPermissions();
#endif
}
void DumpRenderTreeSupportQt::disableDefaultTypesettingFeatures()
{
WebCore::Font::setDefaultTypesettingFeatures(0);
}
void DumpRenderTreeSupportQt::resetPageVisibility(QWebPageAdapter* adapter)
{
#if ENABLE(PAGE_VISIBILITY_API)
// Set visibility without emitting an event.
adapter->page->setVisibilityState(PageVisibilityStateVisible, true);
#else
UNUSED_PARAM(adapter);
#endif
}
void DumpRenderTreeSupportQt::getJSWindowObject(QWebFrameAdapter* adapter, JSContextRef* context, JSObjectRef* object)
{
JSDOMWindow* window = toJSDOMWindow(adapter->frame, mainThreadNormalWorld());
*object = toRef(window);
*context = toRef(window->globalExec());
}
|