2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Apple Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "Internals.h"
31 #include "HTMLNames.h"
32 #include "InspectorFrontendClientLocal.h"
33 #include "InternalProfilers.h"
34 #include "InternalRuntimeFlags.h"
35 #include "InternalSettings.h"
36 #include "LayerRect.h"
37 #include "LayerRectList.h"
38 #include "MallocStatistics.h"
39 #include "MockPagePopupDriver.h"
40 #include "RuntimeEnabledFeatures.h"
41 #include "TypeConversions.h"
42 #include "bindings/v8/ExceptionState.h"
43 #include "bindings/v8/ScriptFunction.h"
44 #include "bindings/v8/ScriptPromise.h"
45 #include "bindings/v8/SerializedScriptValue.h"
46 #include "bindings/v8/V8ThrowException.h"
47 #include "core/animation/DocumentTimeline.h"
48 #include "core/css/StyleSheetContents.h"
49 #include "core/css/resolver/StyleResolver.h"
50 #include "core/css/resolver/StyleResolverStats.h"
51 #include "core/css/resolver/ViewportStyleResolver.h"
52 #include "core/dom/ClientRect.h"
53 #include "core/dom/ClientRectList.h"
54 #include "core/dom/DOMStringList.h"
55 #include "core/dom/Document.h"
56 #include "core/dom/DocumentMarker.h"
57 #include "core/dom/DocumentMarkerController.h"
58 #include "core/dom/Element.h"
59 #include "core/dom/ExceptionCode.h"
60 #include "core/dom/FullscreenElementStack.h"
61 #include "core/dom/NodeRenderStyle.h"
62 #include "core/dom/PseudoElement.h"
63 #include "core/dom/Range.h"
64 #include "core/dom/StaticNodeList.h"
65 #include "core/dom/TreeScope.h"
66 #include "core/dom/ViewportDescription.h"
67 #include "core/dom/WheelController.h"
68 #include "core/dom/shadow/ComposedTreeWalker.h"
69 #include "core/dom/shadow/ElementShadow.h"
70 #include "core/dom/shadow/SelectRuleFeatureSet.h"
71 #include "core/dom/shadow/ShadowRoot.h"
72 #include "core/editing/Editor.h"
73 #include "core/editing/PlainTextRange.h"
74 #include "core/editing/SpellCheckRequester.h"
75 #include "core/editing/SpellChecker.h"
76 #include "core/editing/TextIterator.h"
77 #include "core/fetch/MemoryCache.h"
78 #include "core/fetch/ResourceFetcher.h"
79 #include "core/frame/DOMPoint.h"
80 #include "core/frame/Frame.h"
81 #include "core/html/HTMLIFrameElement.h"
82 #include "core/html/HTMLInputElement.h"
83 #include "core/html/HTMLMediaElement.h"
84 #include "core/html/HTMLSelectElement.h"
85 #include "core/html/HTMLTextAreaElement.h"
86 #include "core/html/forms/FormController.h"
87 #include "core/html/shadow/HTMLContentElement.h"
88 #include "core/inspector/InspectorClient.h"
89 #include "core/inspector/InspectorConsoleAgent.h"
90 #include "core/inspector/InspectorController.h"
91 #include "core/inspector/InspectorCounters.h"
92 #include "core/inspector/InspectorFrontendChannel.h"
93 #include "core/inspector/InspectorInstrumentation.h"
94 #include "core/inspector/InspectorOverlay.h"
95 #include "core/inspector/InstrumentingAgents.h"
96 #include "core/loader/FrameLoader.h"
97 #include "core/loader/HistoryItem.h"
98 #include "core/page/Chrome.h"
99 #include "core/page/ChromeClient.h"
100 #include "core/frame/DOMWindow.h"
101 #include "core/page/EventHandler.h"
102 #include "core/frame/FrameView.h"
103 #include "core/page/Page.h"
104 #include "core/page/PagePopupController.h"
105 #include "core/page/PrintContext.h"
106 #include "core/frame/Settings.h"
107 #include "core/rendering/CompositedLayerMapping.h"
108 #include "core/rendering/RenderLayer.h"
109 #include "core/rendering/RenderLayerCompositor.h"
110 #include "core/rendering/RenderMenuList.h"
111 #include "core/rendering/RenderObject.h"
112 #include "core/rendering/RenderTreeAsText.h"
113 #include "core/rendering/RenderView.h"
114 #include "core/testing/GCObservation.h"
115 #include "core/workers/WorkerThread.h"
116 #include "platform/ColorChooser.h"
117 #include "platform/Cursor.h"
118 #include "platform/Language.h"
119 #include "platform/TraceEvent.h"
120 #include "platform/geometry/IntRect.h"
121 #include "platform/geometry/LayoutRect.h"
122 #include "platform/graphics/GraphicsLayer.h"
123 #include "platform/graphics/filters/FilterOperation.h"
124 #include "platform/graphics/filters/FilterOperations.h"
125 #include "platform/weborigin/SchemeRegistry.h"
126 #include "public/platform/Platform.h"
127 #include "public/platform/WebGraphicsContext3D.h"
128 #include "public/platform/WebGraphicsContext3DProvider.h"
129 #include "public/platform/WebLayer.h"
130 #include "wtf/InstanceCounter.h"
131 #include "wtf/PassOwnPtr.h"
132 #include "wtf/dtoa.h"
133 #include "wtf/text/StringBuffer.h"
137 static MockPagePopupDriver* s_pagePopupDriver = 0;
139 using namespace HTMLNames;
141 class InspectorFrontendChannelDummy : public InspectorFrontendChannel {
143 explicit InspectorFrontendChannelDummy(Page*);
144 virtual ~InspectorFrontendChannelDummy() { }
145 virtual bool sendMessageToFrontend(const String& message) OVERRIDE;
148 Page* m_frontendPage;
151 InspectorFrontendChannelDummy::InspectorFrontendChannelDummy(Page* page)
152 : m_frontendPage(page)
156 bool InspectorFrontendChannelDummy::sendMessageToFrontend(const String& message)
158 return InspectorClient::doDispatchMessageOnFrontendPage(m_frontendPage, message);
161 static bool markerTypesFrom(const String& markerType, DocumentMarker::MarkerTypes& result)
163 if (markerType.isEmpty() || equalIgnoringCase(markerType, "all"))
164 result = DocumentMarker::AllMarkers();
165 else if (equalIgnoringCase(markerType, "Spelling"))
166 result = DocumentMarker::Spelling;
167 else if (equalIgnoringCase(markerType, "Grammar"))
168 result = DocumentMarker::Grammar;
169 else if (equalIgnoringCase(markerType, "TextMatch"))
170 result = DocumentMarker::TextMatch;
177 static SpellCheckRequester* spellCheckRequester(Document* document)
179 if (!document || !document->frame())
181 return &document->frame()->spellChecker().spellCheckRequester();
184 const char* Internals::internalsId = "internals";
186 PassRefPtr<Internals> Internals::create(Document* document)
188 return adoptRef(new Internals(document));
191 Internals::~Internals()
195 void Internals::resetToConsistentState(Page* page)
199 page->setDeviceScaleFactor(1);
200 page->setIsCursorVisible(true);
201 page->setPageScaleFactor(1, IntPoint(0, 0));
202 TextRun::setAllowsRoundingHacks(false);
203 WebCore::overrideUserPreferredLanguages(Vector<AtomicString>());
204 delete s_pagePopupDriver;
205 s_pagePopupDriver = 0;
206 page->chrome().client().resetPagePopupDriver();
207 if (!page->mainFrame()->spellChecker().isContinuousSpellCheckingEnabled())
208 page->mainFrame()->spellChecker().toggleContinuousSpellChecking();
209 if (page->mainFrame()->editor().isOverwriteModeEnabled())
210 page->mainFrame()->editor().toggleOverwriteModeEnabled();
212 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
213 scrollingCoordinator->reset();
215 page->mainFrame()->view()->clear();
218 Internals::Internals(Document* document)
219 : ContextLifecycleObserver(document)
220 , m_runtimeFlags(InternalRuntimeFlags::create())
224 Document* Internals::contextDocument() const
226 return toDocument(executionContext());
229 Frame* Internals::frame() const
231 if (!contextDocument())
233 return contextDocument()->frame();
236 InternalSettings* Internals::settings() const
238 Document* document = contextDocument();
241 Page* page = document->page();
244 return InternalSettings::from(page);
247 InternalRuntimeFlags* Internals::runtimeFlags() const
249 return m_runtimeFlags.get();
252 InternalProfilers* Internals::profilers()
255 m_profilers = InternalProfilers::create();
256 return m_profilers.get();
259 unsigned Internals::workerThreadCount() const
261 return WorkerThread::workerThreadCount();
264 String Internals::address(Node* node)
267 sprintf(buf, "%p", node);
272 PassRefPtr<GCObservation> Internals::observeGC(ScriptValue scriptValue)
274 v8::Handle<v8::Value> observedValue = scriptValue.v8Value();
275 ASSERT(!observedValue.IsEmpty());
276 if (observedValue->IsNull() || observedValue->IsUndefined()) {
277 V8ThrowException::throwTypeError("value to observe is null or undefined", v8::Isolate::GetCurrent());
281 return GCObservation::create(observedValue);
284 unsigned Internals::updateStyleAndReturnAffectedElementCount(ExceptionState& exceptionState) const
286 Document* document = contextDocument();
288 exceptionState.throwDOMException(InvalidAccessError, "No context document is available.");
292 unsigned beforeCount = document->styleEngine()->resolverAccessCount();
293 document->updateStyleIfNeeded();
294 return document->styleEngine()->resolverAccessCount() - beforeCount;
297 unsigned Internals::needsLayoutCount(ExceptionState& exceptionState) const
299 Frame* contextFrame = frame();
301 exceptionState.throwDOMException(InvalidAccessError, "No context frame is available.");
306 unsigned needsLayoutObjects;
307 unsigned totalObjects;
308 contextFrame->countObjectsNeedingLayout(needsLayoutObjects, totalObjects, isPartial);
309 return needsLayoutObjects;
312 bool Internals::isPreloaded(const String& url)
314 Document* document = contextDocument();
315 return document->fetcher()->isPreloaded(url);
318 bool Internals::isLoadingFromMemoryCache(const String& url)
320 if (!contextDocument())
322 Resource* resource = memoryCache()->resourceForURL(contextDocument()->completeURL(url));
323 return resource && resource->status() == Resource::Cached;
326 void Internals::crash()
331 void Internals::setStyleResolverStatsEnabled(bool enabled)
333 Document* document = contextDocument();
335 document->ensureStyleResolver().enableStats(StyleResolver::ReportSlowStats);
337 document->ensureStyleResolver().disableStats();
340 String Internals::styleResolverStatsReport(ExceptionState& exceptionState) const
342 Document* document = contextDocument();
343 if (!document->ensureStyleResolver().stats()) {
344 exceptionState.throwDOMException(InvalidStateError, "Style resolver stats not enabled");
347 return document->ensureStyleResolver().stats()->report();
350 String Internals::styleResolverStatsTotalsReport(ExceptionState& exceptionState) const
352 Document* document = contextDocument();
353 if (!document->ensureStyleResolver().statsTotals()) {
354 exceptionState.throwDOMException(InvalidStateError, "Style resolver stats not enabled");
357 return document->ensureStyleResolver().statsTotals()->report();
360 bool Internals::isSharingStyle(Element* element1, Element* element2, ExceptionState& exceptionState) const
362 if (!element1 || !element2) {
363 exceptionState.throwDOMException(InvalidAccessError, String::format("The %s element provided is invalid.", element1 ? "second" : "first"));
366 return element1->renderStyle() == element2->renderStyle();
369 bool Internals::isValidContentSelect(Element* insertionPoint, ExceptionState& exceptionState)
371 if (!insertionPoint || !insertionPoint->isInsertionPoint()) {
372 exceptionState.throwDOMException(InvalidAccessError, "The insertion point provided is invalid.");
376 return insertionPoint->hasTagName(contentTag) && toHTMLContentElement(insertionPoint)->isSelectValid();
379 Node* Internals::treeScopeRootNode(Node* node, ExceptionState& exceptionState)
382 exceptionState.throwDOMException(InvalidAccessError, "The node provided is invalid.");
386 return &node->treeScope().rootNode();
389 Node* Internals::parentTreeScope(Node* node, ExceptionState& exceptionState)
392 exceptionState.throwDOMException(InvalidAccessError, "The node provided is invalid.");
395 const TreeScope* parentTreeScope = node->treeScope().parentTreeScope();
396 return parentTreeScope ? &parentTreeScope->rootNode() : 0;
399 bool Internals::hasSelectorForIdInShadow(Element* host, const AtomicString& idValue, ExceptionState& exceptionState)
401 if (!host || !host->shadow()) {
402 exceptionState.throwDOMException(InvalidAccessError, "The host element provided is invalid, or does not have a shadow.");
406 return host->shadow()->ensureSelectFeatureSet().hasSelectorForId(idValue);
409 bool Internals::hasSelectorForClassInShadow(Element* host, const AtomicString& className, ExceptionState& exceptionState)
411 if (!host || !host->shadow()) {
412 exceptionState.throwDOMException(InvalidAccessError, "The host element provided is invalid, or does not have a shadow.");
416 return host->shadow()->ensureSelectFeatureSet().hasSelectorForClass(className);
419 bool Internals::hasSelectorForAttributeInShadow(Element* host, const AtomicString& attributeName, ExceptionState& exceptionState)
421 if (!host || !host->shadow()) {
422 exceptionState.throwDOMException(InvalidAccessError, "The host element provided is invalid, or does not have a shadow.");
426 return host->shadow()->ensureSelectFeatureSet().hasSelectorForAttribute(attributeName);
429 bool Internals::hasSelectorForPseudoClassInShadow(Element* host, const String& pseudoClass, ExceptionState& exceptionState)
431 if (!host || !host->shadow()) {
432 exceptionState.throwDOMException(InvalidAccessError, "The host element provided is invalid, or does not have a shadow.");
436 const SelectRuleFeatureSet& featureSet = host->shadow()->ensureSelectFeatureSet();
437 if (pseudoClass == "checked")
438 return featureSet.hasSelectorForChecked();
439 if (pseudoClass == "enabled")
440 return featureSet.hasSelectorForEnabled();
441 if (pseudoClass == "disabled")
442 return featureSet.hasSelectorForDisabled();
443 if (pseudoClass == "indeterminate")
444 return featureSet.hasSelectorForIndeterminate();
445 if (pseudoClass == "link")
446 return featureSet.hasSelectorForLink();
447 if (pseudoClass == "target")
448 return featureSet.hasSelectorForTarget();
449 if (pseudoClass == "visited")
450 return featureSet.hasSelectorForVisited();
452 ASSERT_NOT_REACHED();
456 unsigned short Internals::compareTreeScopePosition(const Node* node1, const Node* node2, ExceptionState& exceptionState) const
458 if (!node1 || !node2) {
459 exceptionState.throwDOMException(InvalidAccessError, String::format("The %s node provided is invalid.", node1 ? "second" : "first"));
462 const TreeScope* treeScope1 = node1->isDocumentNode() ? static_cast<const TreeScope*>(toDocument(node1)) :
463 node1->isShadowRoot() ? static_cast<const TreeScope*>(toShadowRoot(node1)) : 0;
464 const TreeScope* treeScope2 = node2->isDocumentNode() ? static_cast<const TreeScope*>(toDocument(node2)) :
465 node2->isShadowRoot() ? static_cast<const TreeScope*>(toShadowRoot(node2)) : 0;
466 if (!treeScope1 || !treeScope2) {
467 exceptionState.throwDOMException(InvalidAccessError, String::format("The %s node is neither a document node, nor a shadow root.", treeScope1 ? "second" : "first"));
470 return treeScope1->comparePosition(*treeScope2);
473 unsigned Internals::numberOfActiveAnimations() const
475 Frame* contextFrame = frame();
476 Document* document = contextFrame->document();
477 return document->timeline()->numberOfActiveAnimationsForTesting() + document->transitionTimeline()->numberOfActiveAnimationsForTesting();
480 void Internals::pauseAnimations(double pauseTime, ExceptionState& exceptionState)
483 exceptionState.throwDOMException(InvalidAccessError, "The pauseTime provided is negative.");
487 // https://code.google.com/p/chromium/issues/detail?id=343760
488 DisableCompositingQueryAsserts disabler;
490 frame()->document()->timeline()->pauseAnimationsForTesting(pauseTime);
491 frame()->document()->transitionTimeline()->pauseAnimationsForTesting(pauseTime);
494 bool Internals::hasShadowInsertionPoint(const Node* root, ExceptionState& exceptionState) const
496 if (root && root->isShadowRoot())
497 return toShadowRoot(root)->containsShadowElements();
499 exceptionState.throwDOMException(InvalidAccessError, "The root node provided is invalid.");
503 bool Internals::hasContentElement(const Node* root, ExceptionState& exceptionState) const
505 if (root && root->isShadowRoot())
506 return toShadowRoot(root)->containsContentElements();
508 exceptionState.throwDOMException(InvalidAccessError, "The root node provided is invalid.");
512 size_t Internals::countElementShadow(const Node* root, ExceptionState& exceptionState) const
514 if (!root || !root->isShadowRoot()) {
515 exceptionState.throwDOMException(InvalidAccessError, "The root node provided is invalid.");
518 return toShadowRoot(root)->childShadowRootCount();
521 Node* Internals::nextSiblingByWalker(Node* node, ExceptionState& exceptionState)
524 exceptionState.throwDOMException(InvalidAccessError, "The node provided is invalid.");
527 ComposedTreeWalker walker(node);
528 walker.nextSibling();
532 Node* Internals::firstChildByWalker(Node* node, ExceptionState& exceptionState)
535 exceptionState.throwDOMException(InvalidAccessError, "The node provided is invalid.");
538 ComposedTreeWalker walker(node);
543 Node* Internals::lastChildByWalker(Node* node, ExceptionState& exceptionState)
546 exceptionState.throwDOMException(InvalidAccessError, "The node provided is invalid.");
549 ComposedTreeWalker walker(node);
554 Node* Internals::nextNodeByWalker(Node* node, ExceptionState& exceptionState)
557 exceptionState.throwDOMException(InvalidAccessError, "The node provided is invalid.");
560 ComposedTreeWalker walker(node);
565 Node* Internals::previousNodeByWalker(Node* node, ExceptionState& exceptionState)
568 exceptionState.throwDOMException(InvalidAccessError, "The node provided is invalid.");
571 ComposedTreeWalker walker(node);
576 String Internals::elementRenderTreeAsText(Element* element, ExceptionState& exceptionState)
579 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
583 String representation = externalRepresentation(element);
584 if (representation.isEmpty()) {
585 exceptionState.throwDOMException(InvalidAccessError, "The element provided has no external representation.");
589 return representation;
592 size_t Internals::numberOfScopedHTMLStyleChildren(const Node* scope, ExceptionState& exceptionState) const
594 if (scope && (scope->isElementNode() || scope->isShadowRoot()))
595 return scope->numberOfScopedHTMLStyleChildren();
597 exceptionState.throwDOMException(InvalidAccessError, "The scope provided is invalid.");
601 PassRefPtr<CSSComputedStyleDeclaration> Internals::computedStyleIncludingVisitedInfo(Node* node, ExceptionState& exceptionState) const
604 exceptionState.throwDOMException(InvalidAccessError, "The node provided is invalid.");
608 bool allowVisitedStyle = true;
609 return CSSComputedStyleDeclaration::create(node, allowVisitedStyle);
612 ShadowRoot* Internals::shadowRoot(Element* host, ExceptionState& exceptionState)
614 // FIXME: Internals::shadowRoot() in tests should be converted to youngestShadowRoot() or oldestShadowRoot().
615 // https://bugs.webkit.org/show_bug.cgi?id=78465
616 return youngestShadowRoot(host, exceptionState);
619 ShadowRoot* Internals::youngestShadowRoot(Element* host, ExceptionState& exceptionState)
622 exceptionState.throwDOMException(InvalidAccessError, "The host element provided is invalid.");
626 if (ElementShadow* shadow = host->shadow())
627 return shadow->youngestShadowRoot();
631 ShadowRoot* Internals::oldestShadowRoot(Element* host, ExceptionState& exceptionState)
634 exceptionState.throwDOMException(InvalidAccessError, "The host element provided is invalid.");
638 if (ElementShadow* shadow = host->shadow())
639 return shadow->oldestShadowRoot();
643 ShadowRoot* Internals::youngerShadowRoot(Node* shadow, ExceptionState& exceptionState)
645 if (!shadow || !shadow->isShadowRoot()) {
646 exceptionState.throwDOMException(InvalidAccessError, "The node provided is not a valid shadow root.");
650 return toShadowRoot(shadow)->youngerShadowRoot();
653 String Internals::shadowRootType(const Node* root, ExceptionState& exceptionState) const
655 if (!root || !root->isShadowRoot()) {
656 exceptionState.throwDOMException(InvalidAccessError, "The node provided is not a valid shadow root.");
660 switch (toShadowRoot(root)->type()) {
661 case ShadowRoot::UserAgentShadowRoot:
662 return String("UserAgentShadowRoot");
663 case ShadowRoot::AuthorShadowRoot:
664 return String("AuthorShadowRoot");
666 ASSERT_NOT_REACHED();
667 return String("Unknown");
671 const AtomicString& Internals::shadowPseudoId(Element* element, ExceptionState& exceptionState)
674 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
678 return element->shadowPseudoId();
681 void Internals::setShadowPseudoId(Element* element, const AtomicString& id, ExceptionState& exceptionState)
684 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
688 return element->setShadowPseudoId(id);
691 String Internals::visiblePlaceholder(Element* element)
693 if (element && isHTMLTextFormControlElement(*element)) {
694 if (toHTMLTextFormControlElement(element)->placeholderShouldBeVisible())
695 return toHTMLTextFormControlElement(element)->placeholderElement()->textContent();
701 void Internals::selectColorInColorChooser(Element* element, const String& colorValue)
703 if (!element->hasTagName(inputTag))
706 if (!color.setFromString(colorValue))
708 toHTMLInputElement(element)->selectColorInColorChooser(color);
711 bool Internals::hasAutofocusRequest(Document* document)
714 document = contextDocument();
715 return document->autofocusElement();
718 bool Internals::hasAutofocusRequest()
720 return hasAutofocusRequest(0);
723 Vector<String> Internals::formControlStateOfHistoryItem(ExceptionState& exceptionState)
725 HistoryItem* mainItem = frame()->loader().currentItem();
727 exceptionState.throwDOMException(InvalidAccessError, "No history item is available.");
728 return Vector<String>();
730 return mainItem->documentState();
733 void Internals::setFormControlStateOfHistoryItem(const Vector<String>& state, ExceptionState& exceptionState)
735 HistoryItem* mainItem = frame()->loader().currentItem();
737 exceptionState.throwDOMException(InvalidAccessError, "No history item is available.");
740 mainItem->setDocumentState(state);
743 void Internals::setEnableMockPagePopup(bool enabled, ExceptionState& exceptionState)
745 Document* document = contextDocument();
746 if (!document || !document->page())
748 Page* page = document->page();
750 page->chrome().client().resetPagePopupDriver();
753 if (!s_pagePopupDriver)
754 s_pagePopupDriver = MockPagePopupDriver::create(page->mainFrame()).leakPtr();
755 page->chrome().client().setPagePopupDriver(s_pagePopupDriver);
758 PassRefPtr<PagePopupController> Internals::pagePopupController()
760 return s_pagePopupDriver ? s_pagePopupDriver->pagePopupController() : 0;
763 PassRefPtr<ClientRect> Internals::unscaledViewportRect(ExceptionState& exceptionState)
765 Document* document = contextDocument();
766 if (!document || !document->view()) {
767 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's viewport cannot be retrieved." : "No context document can be obtained.");
768 return ClientRect::create();
771 return ClientRect::create(document->view()->visibleContentRect());
774 PassRefPtr<ClientRect> Internals::absoluteCaretBounds(ExceptionState& exceptionState)
776 Document* document = contextDocument();
777 if (!document || !document->frame()) {
778 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "No context document can be obtained.");
779 return ClientRect::create();
782 return ClientRect::create(document->frame()->selection().absoluteCaretBounds());
785 PassRefPtr<ClientRect> Internals::boundingBox(Element* element, ExceptionState& exceptionState)
788 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
789 return ClientRect::create();
792 element->document().updateLayoutIgnorePendingStylesheets();
793 RenderObject* renderer = element->renderer();
795 return ClientRect::create();
796 return ClientRect::create(renderer->absoluteBoundingBoxRectIgnoringTransforms());
799 PassRefPtr<ClientRectList> Internals::inspectorHighlightRects(Document* document, ExceptionState& exceptionState)
801 if (!document || !document->page()) {
802 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's Page cannot be retrieved." : "No context document can be obtained.");
803 return ClientRectList::create();
807 document->page()->inspectorController().getHighlight(&highlight);
808 return ClientRectList::create(highlight.quads);
811 unsigned Internals::markerCountForNode(Node* node, const String& markerType, ExceptionState& exceptionState)
814 exceptionState.throwDOMException(InvalidAccessError, "The node provided is invalid.");
818 DocumentMarker::MarkerTypes markerTypes = 0;
819 if (!markerTypesFrom(markerType, markerTypes)) {
820 exceptionState.throwDOMException(SyntaxError, "The marker type provided ('" + markerType + "') is invalid.");
824 return node->document().markers()->markersFor(node, markerTypes).size();
827 unsigned Internals::activeMarkerCountForNode(Node* node, ExceptionState& exceptionState)
830 exceptionState.throwDOMException(InvalidAccessError, "The node provided is invalid.");
834 // Only TextMatch markers can be active.
835 DocumentMarker::MarkerType markerType = DocumentMarker::TextMatch;
836 Vector<DocumentMarker*> markers = node->document().markers()->markersFor(node, markerType);
838 unsigned activeMarkerCount = 0;
839 for (Vector<DocumentMarker*>::iterator iter = markers.begin(); iter != markers.end(); ++iter) {
840 if ((*iter)->activeMatch())
844 return activeMarkerCount;
847 DocumentMarker* Internals::markerAt(Node* node, const String& markerType, unsigned index, ExceptionState& exceptionState)
850 exceptionState.throwDOMException(InvalidAccessError, "The node provided is invalid.");
854 DocumentMarker::MarkerTypes markerTypes = 0;
855 if (!markerTypesFrom(markerType, markerTypes)) {
856 exceptionState.throwDOMException(SyntaxError, "The marker type provided ('" + markerType + "') is invalid.");
860 Vector<DocumentMarker*> markers = node->document().markers()->markersFor(node, markerTypes);
861 if (markers.size() <= index)
863 return markers[index];
866 PassRefPtr<Range> Internals::markerRangeForNode(Node* node, const String& markerType, unsigned index, ExceptionState& exceptionState)
868 DocumentMarker* marker = markerAt(node, markerType, index, exceptionState);
871 return Range::create(node->document(), node, marker->startOffset(), node, marker->endOffset());
874 String Internals::markerDescriptionForNode(Node* node, const String& markerType, unsigned index, ExceptionState& exceptionState)
876 DocumentMarker* marker = markerAt(node, markerType, index, exceptionState);
879 return marker->description();
882 void Internals::addTextMatchMarker(const Range* range, bool isActive)
884 range->ownerDocument().updateLayoutIgnorePendingStylesheets();
885 range->ownerDocument().markers()->addTextMatchMarker(range, isActive);
888 void Internals::setMarkersActive(Node* node, unsigned startOffset, unsigned endOffset, bool active, ExceptionState& exceptionState)
891 exceptionState.throwDOMException(InvalidAccessError, "The node provided is invalid.");
895 node->document().markers()->setMarkersActive(node, startOffset, endOffset, active);
898 void Internals::setMarkedTextMatchesAreHighlighted(Document* document, bool highlight, ExceptionState&)
900 if (!document || !document->frame())
903 document->frame()->editor().setMarkedTextMatchesAreHighlighted(highlight);
906 void Internals::setScrollViewPosition(Document* document, long x, long y, ExceptionState& exceptionState)
908 if (!document || !document->view()) {
909 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's view cannot be retrieved." : "The document provided is invalid.");
913 FrameView* frameView = document->view();
914 bool constrainsScrollingToContentEdgeOldValue = frameView->constrainsScrollingToContentEdge();
915 bool scrollbarsSuppressedOldValue = frameView->scrollbarsSuppressed();
917 frameView->setConstrainsScrollingToContentEdge(false);
918 frameView->setScrollbarsSuppressed(false);
919 frameView->setScrollOffsetFromInternals(IntPoint(x, y));
920 frameView->setScrollbarsSuppressed(scrollbarsSuppressedOldValue);
921 frameView->setConstrainsScrollingToContentEdge(constrainsScrollingToContentEdgeOldValue);
924 String Internals::viewportAsText(Document* document, float, int availableWidth, int availableHeight, ExceptionState& exceptionState)
926 if (!document || !document->page()) {
927 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's page cannot be retrieved." : "The document provided is invalid.");
931 document->updateLayoutIgnorePendingStylesheets();
933 Page* page = document->page();
935 // Update initial viewport size.
936 IntSize initialViewportSize(availableWidth, availableHeight);
937 document->page()->mainFrame()->view()->setFrameRect(IntRect(IntPoint::zero(), initialViewportSize));
939 ViewportDescription description = page->viewportDescription();
940 PageScaleConstraints constraints = description.resolve(initialViewportSize);
942 constraints.fitToContentsWidth(constraints.layoutSize.width(), availableWidth);
944 StringBuilder builder;
946 builder.appendLiteral("viewport size ");
947 builder.append(String::number(constraints.layoutSize.width()));
949 builder.append(String::number(constraints.layoutSize.height()));
951 builder.appendLiteral(" scale ");
952 builder.append(String::number(constraints.initialScale));
953 builder.appendLiteral(" with limits [");
954 builder.append(String::number(constraints.minimumScale));
955 builder.appendLiteral(", ");
956 builder.append(String::number(constraints.maximumScale));
958 builder.appendLiteral("] and userScalable ");
959 builder.append(description.userZoom ? "true" : "false");
961 return builder.toString();
964 bool Internals::wasLastChangeUserEdit(Element* textField, ExceptionState& exceptionState)
967 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
971 if (textField->hasTagName(inputTag))
972 return toHTMLInputElement(textField)->lastChangeWasUserEdit();
974 if (textField->hasTagName(textareaTag))
975 return toHTMLTextAreaElement(textField)->lastChangeWasUserEdit();
977 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a TEXTAREA.");
981 bool Internals::elementShouldAutoComplete(Element* element, ExceptionState& exceptionState)
984 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
988 if (element->hasTagName(inputTag))
989 return toHTMLInputElement(element)->shouldAutocomplete();
991 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not an INPUT.");
995 String Internals::suggestedValue(Element* element, ExceptionState& exceptionState)
998 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
1002 if (!element->isFormControlElement()) {
1003 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a form control element.");
1007 String suggestedValue;
1008 if (element->hasTagName(inputTag))
1009 suggestedValue = toHTMLInputElement(element)->suggestedValue();
1011 if (element->hasTagName(textareaTag))
1012 suggestedValue = toHTMLTextAreaElement(element)->suggestedValue();
1013 return suggestedValue;
1016 void Internals::setSuggestedValue(Element* element, const String& value, ExceptionState& exceptionState)
1019 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
1023 if (!element->isFormControlElement()) {
1024 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a form control element.");
1028 if (element->hasTagName(inputTag))
1029 toHTMLInputElement(element)->setSuggestedValue(value);
1031 if (element->hasTagName(textareaTag))
1032 toHTMLTextAreaElement(element)->setSuggestedValue(value);
1035 void Internals::setEditingValue(Element* element, const String& value, ExceptionState& exceptionState)
1038 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
1042 if (!element->hasTagName(inputTag)) {
1043 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not an INPUT.");
1047 toHTMLInputElement(element)->setEditingValue(value);
1050 void Internals::setAutofilled(Element* element, bool enabled, ExceptionState& exceptionState)
1052 if (!element->isFormControlElement()) {
1053 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a form control element.");
1056 toHTMLFormControlElement(element)->setAutofilled(enabled);
1059 void Internals::scrollElementToRect(Element* element, long x, long y, long w, long h, ExceptionState& exceptionState)
1061 if (!element || !element->document().view()) {
1062 exceptionState.throwDOMException(InvalidNodeTypeError, element ? "No view can be obtained from the provided element's document." : "The element provided is invalid.");
1065 FrameView* frameView = element->document().view();
1066 frameView->scrollElementToRect(element, IntRect(x, y, w, h));
1069 PassRefPtr<Range> Internals::rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionState& exceptionState)
1072 exceptionState.throwDOMException(InvalidAccessError, "The scope element provided is invalid.");
1076 // TextIterator depends on Layout information, make sure layout it up to date.
1077 scope->document().updateLayoutIgnorePendingStylesheets();
1079 return PlainTextRange(rangeLocation, rangeLocation + rangeLength).createRange(*scope);
1082 unsigned Internals::locationFromRange(Element* scope, const Range* range, ExceptionState& exceptionState)
1084 if (!scope || !range) {
1085 exceptionState.throwDOMException(InvalidAccessError, scope ? "The Range provided is invalid." : "The scope element provided is invalid.");
1089 // PlainTextRange depends on Layout information, make sure layout it up to date.
1090 scope->document().updateLayoutIgnorePendingStylesheets();
1092 return PlainTextRange::create(*scope, *range).start();
1095 unsigned Internals::lengthFromRange(Element* scope, const Range* range, ExceptionState& exceptionState)
1097 if (!scope || !range) {
1098 exceptionState.throwDOMException(InvalidAccessError, scope ? "The Range provided is invalid." : "The scope element provided is invalid.");
1102 // PlainTextRange depends on Layout information, make sure layout it up to date.
1103 scope->document().updateLayoutIgnorePendingStylesheets();
1105 return PlainTextRange::create(*scope, *range).length();
1108 String Internals::rangeAsText(const Range* range, ExceptionState& exceptionState)
1111 exceptionState.throwDOMException(InvalidAccessError, "The Range provided is invalid.");
1115 return range->text();
1118 PassRefPtr<DOMPoint> Internals::touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1120 if (!document || !document->frame()) {
1121 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1125 document->updateLayout();
1127 IntSize radius(width / 2, height / 2);
1128 IntPoint point(x + radius.width(), y + radius.height());
1131 IntPoint adjustedPoint;
1133 bool foundNode = document->frame()->eventHandler().bestClickableNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1135 return DOMPoint::create(adjustedPoint.x(), adjustedPoint.y());
1140 Node* Internals::touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1142 if (!document || !document->frame()) {
1143 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1147 document->updateLayout();
1149 IntSize radius(width / 2, height / 2);
1150 IntPoint point(x + radius.width(), y + radius.height());
1153 IntPoint adjustedPoint;
1154 document->frame()->eventHandler().bestClickableNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1158 PassRefPtr<DOMPoint> Internals::touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1160 if (!document || !document->frame()) {
1161 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1165 document->updateLayout();
1167 IntSize radius(width / 2, height / 2);
1168 IntPoint point(x + radius.width(), y + radius.height());
1170 Node* targetNode = 0;
1171 IntPoint adjustedPoint;
1173 bool foundNode = document->frame()->eventHandler().bestContextMenuNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1175 return DOMPoint::create(adjustedPoint.x(), adjustedPoint.y());
1177 return DOMPoint::create(x, y);
1180 Node* Internals::touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1182 if (!document || !document->frame()) {
1183 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1187 document->updateLayout();
1189 IntSize radius(width / 2, height / 2);
1190 IntPoint point(x + radius.width(), y + radius.height());
1192 Node* targetNode = 0;
1193 IntPoint adjustedPoint;
1194 document->frame()->eventHandler().bestContextMenuNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1198 PassRefPtr<ClientRect> Internals::bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1200 if (!document || !document->frame()) {
1201 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1205 document->updateLayout();
1207 IntSize radius(width / 2, height / 2);
1208 IntPoint point(x + radius.width(), y + radius.height());
1211 IntRect zoomableArea;
1212 bool foundNode = document->frame()->eventHandler().bestZoomableAreaForTouchPoint(point, radius, zoomableArea, targetNode);
1214 return ClientRect::create(zoomableArea);
1220 int Internals::lastSpellCheckRequestSequence(Document* document, ExceptionState& exceptionState)
1222 SpellCheckRequester* requester = spellCheckRequester(document);
1225 exceptionState.throwDOMException(InvalidAccessError, "No spell check requestor can be obtained for the provided document.");
1229 return requester->lastRequestSequence();
1232 int Internals::lastSpellCheckProcessedSequence(Document* document, ExceptionState& exceptionState)
1234 SpellCheckRequester* requester = spellCheckRequester(document);
1237 exceptionState.throwDOMException(InvalidAccessError, "No spell check requestor can be obtained for the provided document.");
1241 return requester->lastProcessedSequence();
1244 Vector<AtomicString> Internals::userPreferredLanguages() const
1246 return WebCore::userPreferredLanguages();
1249 // Optimally, the bindings generator would pass a Vector<AtomicString> here but
1250 // this is not supported yet.
1251 void Internals::setUserPreferredLanguages(const Vector<String>& languages)
1253 Vector<AtomicString> atomicLanguages;
1254 for (size_t i = 0; i < languages.size(); ++i)
1255 atomicLanguages.append(AtomicString(languages[i]));
1256 WebCore::overrideUserPreferredLanguages(atomicLanguages);
1259 unsigned Internals::wheelEventHandlerCount(Document* document, ExceptionState& exceptionState)
1262 exceptionState.throwDOMException(InvalidAccessError, "No context document is available.");
1266 return WheelController::from(document)->wheelEventHandlerCount();
1269 unsigned Internals::touchEventHandlerCount(Document* document, ExceptionState& exceptionState)
1272 exceptionState.throwDOMException(InvalidAccessError, "No context document is available.");
1276 const TouchEventTargetSet* touchHandlers = document->touchEventTargets();
1281 for (TouchEventTargetSet::const_iterator iter = touchHandlers->begin(); iter != touchHandlers->end(); ++iter)
1282 count += iter->value;
1286 static RenderLayer* findRenderLayerForGraphicsLayer(RenderLayer* searchRoot, GraphicsLayer* graphicsLayer, String* layerType)
1288 if (searchRoot->hasCompositedLayerMapping() && graphicsLayer == searchRoot->compositedLayerMapping()->mainGraphicsLayer())
1291 GraphicsLayer* layerForScrolling = searchRoot->scrollableArea() ? searchRoot->scrollableArea()->layerForScrolling() : 0;
1292 if (graphicsLayer == layerForScrolling) {
1293 *layerType = "scrolling";
1297 GraphicsLayer* layerForHorizontalScrollbar = searchRoot->scrollableArea() ? searchRoot->scrollableArea()->layerForHorizontalScrollbar() : 0;
1298 if (graphicsLayer == layerForHorizontalScrollbar) {
1299 *layerType = "horizontalScrollbar";
1303 GraphicsLayer* layerForVerticalScrollbar = searchRoot->scrollableArea() ? searchRoot->scrollableArea()->layerForVerticalScrollbar() : 0;
1304 if (graphicsLayer == layerForVerticalScrollbar) {
1305 *layerType = "verticalScrollbar";
1309 GraphicsLayer* layerForScrollCorner = searchRoot->scrollableArea() ? searchRoot->scrollableArea()->layerForScrollCorner() : 0;
1310 if (graphicsLayer == layerForScrollCorner) {
1311 *layerType = "scrollCorner";
1315 for (RenderLayer* child = searchRoot->firstChild(); child; child = child->nextSibling()) {
1316 RenderLayer* foundLayer = findRenderLayerForGraphicsLayer(child, graphicsLayer, layerType);
1324 // Given a vector of rects, merge those that are adjacent, leaving empty rects
1325 // in the place of no longer used slots. This is intended to simplify the list
1326 // of rects returned by an SkRegion (which have been split apart for sorting
1327 // purposes). No attempt is made to do this efficiently (eg. by relying on the
1328 // sort criteria of SkRegion).
1329 static void mergeRects(blink::WebVector<blink::WebRect>& rects)
1331 for (size_t i = 0; i < rects.size(); ++i) {
1332 if (rects[i].isEmpty())
1337 for (size_t j = i+1; j < rects.size(); ++j) {
1338 if (rects[j].isEmpty())
1340 // Try to merge rects[j] into rects[i] along the 4 possible edges.
1341 if (rects[i].y == rects[j].y && rects[i].height == rects[j].height) {
1342 if (rects[i].x + rects[i].width == rects[j].x) {
1343 rects[i].width += rects[j].width;
1344 rects[j] = blink::WebRect();
1346 } else if (rects[i].x == rects[j].x + rects[j].width) {
1347 rects[i].x = rects[j].x;
1348 rects[i].width += rects[j].width;
1349 rects[j] = blink::WebRect();
1352 } else if (rects[i].x == rects[j].x && rects[i].width == rects[j].width) {
1353 if (rects[i].y + rects[i].height == rects[j].y) {
1354 rects[i].height += rects[j].height;
1355 rects[j] = blink::WebRect();
1357 } else if (rects[i].y == rects[j].y + rects[j].height) {
1358 rects[i].y = rects[j].y;
1359 rects[i].height += rects[j].height;
1360 rects[j] = blink::WebRect();
1369 static void accumulateLayerRectList(RenderLayerCompositor* compositor, GraphicsLayer* graphicsLayer, LayerRectList* rects)
1371 blink::WebVector<blink::WebRect> layerRects = graphicsLayer->platformLayer()->touchEventHandlerRegion();
1372 if (!layerRects.isEmpty()) {
1373 mergeRects(layerRects);
1375 RenderLayer* renderLayer = findRenderLayerForGraphicsLayer(compositor->rootRenderLayer(), graphicsLayer, &layerType);
1376 Node* node = renderLayer ? renderLayer->renderer()->node() : 0;
1377 for (size_t i = 0; i < layerRects.size(); ++i) {
1378 if (!layerRects[i].isEmpty())
1379 rects->append(node, layerType, ClientRect::create(layerRects[i]));
1383 size_t numChildren = graphicsLayer->children().size();
1384 for (size_t i = 0; i < numChildren; ++i)
1385 accumulateLayerRectList(compositor, graphicsLayer->children()[i], rects);
1388 PassRefPtr<LayerRectList> Internals::touchEventTargetLayerRects(Document* document, ExceptionState& exceptionState)
1390 if (!document || !document->view() || !document->page() || document != contextDocument()) {
1391 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1395 // Do any pending layout and compositing update (which may call touchEventTargetRectsChange) to ensure this
1396 // really takes any previous changes into account.
1397 forceCompositingUpdate(document, exceptionState);
1398 if (exceptionState.hadException())
1401 if (RenderView* view = document->renderView()) {
1402 if (RenderLayerCompositor* compositor = view->compositor()) {
1403 if (GraphicsLayer* rootLayer = compositor->rootGraphicsLayer()) {
1404 RefPtr<LayerRectList> rects = LayerRectList::create();
1405 accumulateLayerRectList(compositor, rootLayer, rects.get());
1414 PassRefPtr<NodeList> Internals::nodesFromRect(Document* document, int centerX, int centerY, unsigned topPadding, unsigned rightPadding,
1415 unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent, ExceptionState& exceptionState) const
1417 if (!document || !document->frame() || !document->frame()->view()) {
1418 exceptionState.throwDOMException(InvalidAccessError, "No view can be obtained from the provided document.");
1422 Frame* frame = document->frame();
1423 FrameView* frameView = document->view();
1424 RenderView* renderView = document->renderView();
1429 float zoomFactor = frame->pageZoomFactor();
1430 LayoutPoint point = roundedLayoutPoint(FloatPoint(centerX * zoomFactor + frameView->scrollX(), centerY * zoomFactor + frameView->scrollY()));
1432 HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly | HitTestRequest::Active;
1434 hitType |= HitTestRequest::IgnoreClipping;
1435 if (!allowShadowContent)
1436 hitType |= HitTestRequest::ConfusingAndOftenMisusedDisallowShadowContent;
1437 if (allowChildFrameContent)
1438 hitType |= HitTestRequest::AllowChildFrameContent;
1440 HitTestRequest request(hitType);
1442 // When ignoreClipping is false, this method returns null for coordinates outside of the viewport.
1443 if (!request.ignoreClipping() && !frameView->visibleContentRect().intersects(HitTestLocation::rectForPoint(point, topPadding, rightPadding, bottomPadding, leftPadding)))
1446 Vector<RefPtr<Node> > matches;
1448 // Need padding to trigger a rect based hit test, but we want to return a NodeList
1449 // so we special case this.
1450 if (!topPadding && !rightPadding && !bottomPadding && !leftPadding) {
1451 HitTestResult result(point);
1452 renderView->hitTest(request, result);
1453 if (result.innerNode())
1454 matches.append(result.innerNode()->deprecatedShadowAncestorNode());
1456 HitTestResult result(point, topPadding, rightPadding, bottomPadding, leftPadding);
1457 renderView->hitTest(request, result);
1458 copyToVector(result.rectBasedTestResult(), matches);
1461 return StaticNodeList::adopt(matches);
1464 void Internals::emitInspectorDidBeginFrame(int frameId)
1466 contextDocument()->page()->inspectorController().didBeginFrame(frameId);
1469 void Internals::emitInspectorDidCancelFrame()
1471 contextDocument()->page()->inspectorController().didCancelFrame();
1474 bool Internals::hasSpellingMarker(Document* document, int from, int length, ExceptionState&)
1476 if (!document || !document->frame())
1479 return document->frame()->spellChecker().selectionStartHasMarkerFor(DocumentMarker::Spelling, from, length);
1482 void Internals::setContinuousSpellCheckingEnabled(bool enabled, ExceptionState&)
1484 if (!contextDocument() || !contextDocument()->frame())
1487 if (enabled != contextDocument()->frame()->spellChecker().isContinuousSpellCheckingEnabled())
1488 contextDocument()->frame()->spellChecker().toggleContinuousSpellChecking();
1491 bool Internals::isOverwriteModeEnabled(Document* document, ExceptionState&)
1493 if (!document || !document->frame())
1496 return document->frame()->editor().isOverwriteModeEnabled();
1499 void Internals::toggleOverwriteModeEnabled(Document* document, ExceptionState&)
1501 if (!document || !document->frame())
1504 document->frame()->editor().toggleOverwriteModeEnabled();
1507 unsigned Internals::numberOfLiveNodes() const
1509 return InspectorCounters::counterValue(InspectorCounters::NodeCounter);
1512 unsigned Internals::numberOfLiveDocuments() const
1514 return InspectorCounters::counterValue(InspectorCounters::DocumentCounter);
1517 String Internals::dumpRefCountedInstanceCounts() const
1519 return WTF::dumpRefCountedInstanceCounts();
1522 Vector<String> Internals::consoleMessageArgumentCounts(Document* document) const
1524 InstrumentingAgents* instrumentingAgents = instrumentationForPage(document->page());
1525 if (!instrumentingAgents)
1526 return Vector<String>();
1527 InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent();
1529 return Vector<String>();
1530 Vector<unsigned> counts = consoleAgent->consoleMessageArgumentCounts();
1531 Vector<String> result(counts.size());
1532 for (size_t i = 0; i < counts.size(); i++)
1533 result[i] = String::number(counts[i]);
1537 PassRefPtr<DOMWindow> Internals::openDummyInspectorFrontend(const String& url)
1539 Page* page = contextDocument()->frame()->page();
1542 DOMWindow* window = page->mainFrame()->domWindow();
1545 m_frontendWindow = window->open(url, "", "", window, window);
1546 ASSERT(m_frontendWindow);
1548 Page* frontendPage = m_frontendWindow->document()->page();
1549 ASSERT(frontendPage);
1551 OwnPtr<InspectorFrontendClientLocal> frontendClient = adoptPtr(new InspectorFrontendClientLocal(page->inspectorController(), frontendPage));
1553 frontendPage->inspectorController().setInspectorFrontendClient(frontendClient.release());
1555 m_frontendChannel = adoptPtr(new InspectorFrontendChannelDummy(frontendPage));
1557 page->inspectorController().connectFrontend(m_frontendChannel.get());
1559 return m_frontendWindow;
1562 void Internals::closeDummyInspectorFrontend()
1564 Page* page = contextDocument()->frame()->page();
1566 ASSERT(m_frontendWindow);
1568 page->inspectorController().disconnectFrontend();
1570 m_frontendChannel.release();
1572 m_frontendWindow->close(m_frontendWindow->executionContext());
1573 m_frontendWindow.release();
1576 Vector<unsigned long> Internals::setMemoryCacheCapacities(unsigned long minDeadBytes, unsigned long maxDeadBytes, unsigned long totalBytes)
1578 Vector<unsigned long> result;
1579 result.append(memoryCache()->minDeadCapacity());
1580 result.append(memoryCache()->maxDeadCapacity());
1581 result.append(memoryCache()->capacity());
1582 memoryCache()->setCapacities(minDeadBytes, maxDeadBytes, totalBytes);
1586 void Internals::setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionState& exceptionState)
1588 Page* page = contextDocument()->frame()->page();
1590 exceptionState.throwDOMException(InvalidAccessError, "No page can be obtained from the current context document.");
1593 page->inspectorController().setResourcesDataSizeLimitsFromInternals(maximumResourcesContentSize, maximumSingleResourceContentSize);
1596 bool Internals::hasGrammarMarker(Document* document, int from, int length, ExceptionState&)
1598 if (!document || !document->frame())
1601 return document->frame()->spellChecker().selectionStartHasMarkerFor(DocumentMarker::Grammar, from, length);
1604 unsigned Internals::numberOfScrollableAreas(Document* document, ExceptionState&)
1607 Frame* frame = document->frame();
1608 if (frame->view()->scrollableAreas())
1609 count += frame->view()->scrollableAreas()->size();
1611 for (Frame* child = frame->tree().firstChild(); child; child = child->tree().nextSibling()) {
1612 if (child->view() && child->view()->scrollableAreas())
1613 count += child->view()->scrollableAreas()->size();
1619 bool Internals::isPageBoxVisible(Document* document, int pageNumber, ExceptionState& exceptionState)
1622 exceptionState.throwDOMException(InvalidAccessError, "No context document is available.");
1626 return document->isPageBoxVisible(pageNumber);
1629 String Internals::layerTreeAsText(Document* document, ExceptionState& exceptionState) const
1631 return layerTreeAsText(document, 0, exceptionState);
1634 String Internals::elementLayerTreeAsText(Element* element, ExceptionState& exceptionState) const
1636 return elementLayerTreeAsText(element, 0, exceptionState);
1639 static PassRefPtr<NodeList> paintOrderList(Element* element, ExceptionState& exceptionState, RenderLayerStackingNode::PaintOrderListType type)
1642 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
1646 element->document().updateLayout();
1648 RenderObject* renderer = element->renderer();
1649 if (!renderer || !renderer->isBox()) {
1650 exceptionState.throwDOMException(InvalidAccessError, renderer ? "The provided element's renderer is not a box." : "The provided element has no renderer.");
1654 RenderLayer* layer = toRenderBox(renderer)->layer();
1656 exceptionState.throwDOMException(InvalidAccessError, "No render layer can be obtained from the provided element.");
1660 Vector<RefPtr<Node> > nodes;
1661 layer->stackingNode()->computePaintOrderList(type, nodes);
1662 return StaticNodeList::adopt(nodes);
1665 PassRefPtr<NodeList> Internals::paintOrderListBeforePromote(Element* element, ExceptionState& exceptionState)
1667 return paintOrderList(element, exceptionState, RenderLayerStackingNode::BeforePromote);
1670 PassRefPtr<NodeList> Internals::paintOrderListAfterPromote(Element* element, ExceptionState& exceptionState)
1672 return paintOrderList(element, exceptionState, RenderLayerStackingNode::AfterPromote);
1675 bool Internals::scrollsWithRespectTo(Element* element1, Element* element2, ExceptionState& exceptionState)
1677 if (!element1 || !element2) {
1678 exceptionState.throwDOMException(InvalidAccessError, String::format("The %s element provided is invalid.", element1 ? "second" : "first"));
1682 element1->document().updateLayout();
1684 RenderObject* renderer1 = element1->renderer();
1685 RenderObject* renderer2 = element2->renderer();
1686 if (!renderer1 || !renderer1->isBox()) {
1687 exceptionState.throwDOMException(InvalidAccessError, renderer1 ? "The first provided element's renderer is not a box." : "The first provided element has no renderer.");
1690 if (!renderer2 || !renderer2->isBox()) {
1691 exceptionState.throwDOMException(InvalidAccessError, renderer2 ? "The second provided element's renderer is not a box." : "The second provided element has no renderer.");
1695 RenderLayer* layer1 = toRenderBox(renderer1)->layer();
1696 RenderLayer* layer2 = toRenderBox(renderer2)->layer();
1697 if (!layer1 || !layer2) {
1698 exceptionState.throwDOMException(InvalidAccessError, String::format("No render layer can be obtained from the %s provided element.", layer1 ? "second" : "first"));
1702 return layer1->scrollsWithRespectTo(layer2);
1705 bool Internals::isUnclippedDescendant(Element* element, ExceptionState& exceptionState)
1708 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
1712 element->document().updateLayout();
1714 RenderObject* renderer = element->renderer();
1715 if (!renderer || !renderer->isBox()) {
1716 exceptionState.throwDOMException(InvalidAccessError, renderer ? "The provided element's renderer is not a box." : "The provided element has no renderer.");
1720 RenderLayer* layer = toRenderBox(renderer)->layer();
1722 exceptionState.throwDOMException(InvalidAccessError, "No render layer can be obtained from the provided element.");
1726 return layer->isUnclippedDescendant();
1729 bool Internals::needsCompositedScrolling(Element* element, ExceptionState& exceptionState)
1732 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
1736 element->document().updateLayout();
1738 RenderObject* renderer = element->renderer();
1739 if (!renderer || !renderer->isBox()) {
1740 exceptionState.throwDOMException(InvalidAccessError, renderer ? "The provided element's renderer is not a box." : "The provided element has no renderer.");
1744 RenderLayer* layer = toRenderBox(renderer)->layer();
1746 exceptionState.throwDOMException(InvalidAccessError, "No render layer can be obtained from the provided element.");
1750 return layer->needsCompositedScrolling();
1753 String Internals::layerTreeAsText(Document* document, unsigned flags, ExceptionState& exceptionState) const
1755 if (!document || !document->frame()) {
1756 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1760 return document->frame()->layerTreeAsText(flags);
1763 String Internals::elementLayerTreeAsText(Element* element, unsigned flags, ExceptionState& exceptionState) const
1766 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
1770 element->document().updateLayout();
1772 RenderObject* renderer = element->renderer();
1773 if (!renderer || !renderer->isBox()) {
1774 exceptionState.throwDOMException(InvalidAccessError, renderer ? "The provided element's renderer is not a box." : "The provided element has no renderer.");
1778 RenderLayer* layer = toRenderBox(renderer)->layer();
1780 || !layer->hasCompositedLayerMapping()
1781 || !layer->compositedLayerMapping()->mainGraphicsLayer()) {
1782 // Don't raise exception in these cases which may be normally used in tests.
1786 return layer->compositedLayerMapping()->mainGraphicsLayer()->layerTreeAsText(flags);
1789 static RenderLayer* getRenderLayerForElement(Element* element, ExceptionState& exceptionState)
1792 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
1796 RenderObject* renderer = element->renderer();
1797 if (!renderer || !renderer->isBox()) {
1798 exceptionState.throwDOMException(InvalidAccessError, renderer ? "The provided element's renderer is not a box." : "The provided element has no renderer.");
1802 RenderLayer* layer = toRenderBox(renderer)->layer();
1804 exceptionState.throwDOMException(InvalidAccessError, "No render layer can be obtained from the provided element.");
1811 void Internals::setNeedsCompositedScrolling(Element* element, unsigned needsCompositedScrolling, ExceptionState& exceptionState)
1814 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
1818 element->document().updateLayout();
1820 if (RenderLayer* layer = getRenderLayerForElement(element, exceptionState))
1821 layer->scrollableArea()->setForceNeedsCompositedScrolling(static_cast<ForceNeedsCompositedScrollingMode>(needsCompositedScrolling));
1824 String Internals::repaintRectsAsText(Document* document, ExceptionState& exceptionState) const
1826 if (!document || !document->frame()) {
1827 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1831 return document->frame()->trackedRepaintRectsAsText();
1834 PassRefPtr<ClientRectList> Internals::repaintRects(Element* element, ExceptionState& exceptionState) const
1837 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
1841 if (RenderLayer* layer = getRenderLayerForElement(element, exceptionState)) {
1842 if (layer->compositingState() == PaintsIntoOwnBacking) {
1843 OwnPtr<Vector<FloatRect> > rects = layer->collectTrackedRepaintRects();
1844 ASSERT(rects.get());
1845 Vector<FloatQuad> quads(rects->size());
1846 for (size_t i = 0; i < rects->size(); ++i)
1847 quads[i] = FloatRect(rects->at(i));
1848 return ClientRectList::create(quads);
1852 exceptionState.throwDOMException(InvalidAccessError, "The provided element is not composited.");
1856 String Internals::scrollingStateTreeAsText(Document* document, ExceptionState& exceptionState) const
1861 String Internals::mainThreadScrollingReasons(Document* document, ExceptionState& exceptionState) const
1863 if (!document || !document->frame()) {
1864 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1868 // Force a re-layout and a compositing update.
1869 document->updateLayout();
1870 RenderView* view = document->renderView();
1871 if (view->compositor())
1872 view->compositor()->updateCompositingLayers();
1874 Page* page = document->page();
1878 return page->mainThreadScrollingReasonsAsText();
1881 PassRefPtr<ClientRectList> Internals::nonFastScrollableRects(Document* document, ExceptionState& exceptionState) const
1883 if (!document || !document->frame()) {
1884 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1888 Page* page = document->page();
1892 return page->nonFastScrollableRects(document->frame());
1895 void Internals::garbageCollectDocumentResources(Document* document, ExceptionState& exceptionState) const
1898 exceptionState.throwDOMException(InvalidAccessError, "No context document is available.");
1901 ResourceFetcher* fetcher = document->fetcher();
1904 fetcher->garbageCollectDocumentResources();
1907 void Internals::evictAllResources() const
1909 memoryCache()->evictResources();
1912 void Internals::allowRoundingHacks() const
1914 TextRun::setAllowsRoundingHacks(true);
1917 String Internals::counterValue(Element* element)
1922 return counterValueForElement(element);
1925 int Internals::pageNumber(Element* element, float pageWidth, float pageHeight)
1930 return PrintContext::pageNumberForElement(element, FloatSize(pageWidth, pageHeight));
1933 Vector<String> Internals::iconURLs(Document* document, int iconTypesMask) const
1935 Vector<IconURL> iconURLs = document->iconURLs(iconTypesMask);
1936 Vector<String> array;
1938 Vector<IconURL>::const_iterator iter(iconURLs.begin());
1939 for (; iter != iconURLs.end(); ++iter)
1940 array.append(iter->m_iconURL.string());
1945 Vector<String> Internals::shortcutIconURLs(Document* document) const
1947 return iconURLs(document, Favicon);
1950 Vector<String> Internals::allIconURLs(Document* document) const
1952 return iconURLs(document, Favicon | TouchIcon | TouchPrecomposedIcon);
1955 int Internals::numberOfPages(float pageWidth, float pageHeight)
1960 return PrintContext::numberOfPages(frame(), FloatSize(pageWidth, pageHeight));
1963 String Internals::pageProperty(String propertyName, int pageNumber, ExceptionState& exceptionState) const
1966 exceptionState.throwDOMException(InvalidAccessError, "No frame is available.");
1970 return PrintContext::pageProperty(frame(), propertyName.utf8().data(), pageNumber);
1973 String Internals::pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft, ExceptionState& exceptionState) const
1976 exceptionState.throwDOMException(InvalidAccessError, "No frame is available.");
1980 return PrintContext::pageSizeAndMarginsInPixels(frame(), pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft);
1983 void Internals::setDeviceScaleFactor(float scaleFactor, ExceptionState& exceptionState)
1985 Document* document = contextDocument();
1986 if (!document || !document->page()) {
1987 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's page cannot be retrieved." : "No context document can be obtained.");
1990 Page* page = document->page();
1991 page->setDeviceScaleFactor(scaleFactor);
1994 void Internals::setIsCursorVisible(Document* document, bool isVisible, ExceptionState& exceptionState)
1996 if (!document || !document->page()) {
1997 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's page cannot be retrieved." : "No context document can be obtained.");
2000 document->page()->setIsCursorVisible(isVisible);
2003 void Internals::webkitWillEnterFullScreenForElement(Document* document, Element* element)
2007 FullscreenElementStack::from(document)->webkitWillEnterFullScreenForElement(element);
2010 void Internals::webkitDidEnterFullScreenForElement(Document* document, Element* element)
2014 FullscreenElementStack::from(document)->webkitDidEnterFullScreenForElement(element);
2017 void Internals::webkitWillExitFullScreenForElement(Document* document, Element* element)
2021 FullscreenElementStack::from(document)->webkitWillExitFullScreenForElement(element);
2024 void Internals::webkitDidExitFullScreenForElement(Document* document, Element* element)
2028 FullscreenElementStack::from(document)->webkitDidExitFullScreenForElement(element);
2031 void Internals::registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme)
2033 SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy(scheme);
2036 void Internals::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme)
2038 SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(scheme);
2041 PassRefPtr<MallocStatistics> Internals::mallocStatistics() const
2043 return MallocStatistics::create();
2046 PassRefPtr<TypeConversions> Internals::typeConversions() const
2048 return TypeConversions::create();
2051 Vector<String> Internals::getReferencedFilePaths() const
2053 frame()->loader().saveDocumentAndScrollState();
2054 return FormController::getReferencedFilePaths(frame()->loader().currentItem()->documentState());
2057 void Internals::startTrackingRepaints(Document* document, ExceptionState& exceptionState)
2059 if (!document || !document->view()) {
2060 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's view cannot be retrieved." : "The document provided is invalid.");
2064 FrameView* frameView = document->view();
2065 frameView->setTracksRepaints(true);
2068 void Internals::stopTrackingRepaints(Document* document, ExceptionState& exceptionState)
2070 if (!document || !document->view()) {
2071 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's view cannot be retrieved." : "The document provided is invalid.");
2075 FrameView* frameView = document->view();
2076 frameView->setTracksRepaints(false);
2079 void Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionState& exceptionState)
2081 updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(0, exceptionState);
2084 void Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node* node, ExceptionState& exceptionState)
2088 document = contextDocument();
2089 } else if (node->isDocumentNode()) {
2090 document = toDocument(node);
2091 } else if (node->hasTagName(HTMLNames::iframeTag)) {
2092 document = toHTMLIFrameElement(node)->contentDocument();
2094 exceptionState.throwDOMException(TypeError, "The node provided is neither a document nor an IFrame.");
2097 document->updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasksSynchronously);
2100 PassRefPtr<ClientRectList> Internals::draggableRegions(Document* document, ExceptionState& exceptionState)
2102 return annotatedRegions(document, true, exceptionState);
2105 PassRefPtr<ClientRectList> Internals::nonDraggableRegions(Document* document, ExceptionState& exceptionState)
2107 return annotatedRegions(document, false, exceptionState);
2110 PassRefPtr<ClientRectList> Internals::annotatedRegions(Document* document, bool draggable, ExceptionState& exceptionState)
2112 if (!document || !document->view()) {
2113 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's view cannot be retrieved." : "The document provided is invalid.");
2114 return ClientRectList::create();
2117 document->updateLayout();
2118 document->view()->updateAnnotatedRegions();
2119 Vector<AnnotatedRegionValue> regions = document->annotatedRegions();
2121 Vector<FloatQuad> quads;
2122 for (size_t i = 0; i < regions.size(); ++i) {
2123 if (regions[i].draggable == draggable)
2124 quads.append(FloatQuad(regions[i].bounds));
2126 return ClientRectList::create(quads);
2129 static const char* cursorTypeToString(Cursor::Type cursorType)
2131 switch (cursorType) {
2132 case Cursor::Pointer: return "Pointer";
2133 case Cursor::Cross: return "Cross";
2134 case Cursor::Hand: return "Hand";
2135 case Cursor::IBeam: return "IBeam";
2136 case Cursor::Wait: return "Wait";
2137 case Cursor::Help: return "Help";
2138 case Cursor::EastResize: return "EastResize";
2139 case Cursor::NorthResize: return "NorthResize";
2140 case Cursor::NorthEastResize: return "NorthEastResize";
2141 case Cursor::NorthWestResize: return "NorthWestResize";
2142 case Cursor::SouthResize: return "SouthResize";
2143 case Cursor::SouthEastResize: return "SouthEastResize";
2144 case Cursor::SouthWestResize: return "SouthWestResize";
2145 case Cursor::WestResize: return "WestResize";
2146 case Cursor::NorthSouthResize: return "NorthSouthResize";
2147 case Cursor::EastWestResize: return "EastWestResize";
2148 case Cursor::NorthEastSouthWestResize: return "NorthEastSouthWestResize";
2149 case Cursor::NorthWestSouthEastResize: return "NorthWestSouthEastResize";
2150 case Cursor::ColumnResize: return "ColumnResize";
2151 case Cursor::RowResize: return "RowResize";
2152 case Cursor::MiddlePanning: return "MiddlePanning";
2153 case Cursor::EastPanning: return "EastPanning";
2154 case Cursor::NorthPanning: return "NorthPanning";
2155 case Cursor::NorthEastPanning: return "NorthEastPanning";
2156 case Cursor::NorthWestPanning: return "NorthWestPanning";
2157 case Cursor::SouthPanning: return "SouthPanning";
2158 case Cursor::SouthEastPanning: return "SouthEastPanning";
2159 case Cursor::SouthWestPanning: return "SouthWestPanning";
2160 case Cursor::WestPanning: return "WestPanning";
2161 case Cursor::Move: return "Move";
2162 case Cursor::VerticalText: return "VerticalText";
2163 case Cursor::Cell: return "Cell";
2164 case Cursor::ContextMenu: return "ContextMenu";
2165 case Cursor::Alias: return "Alias";
2166 case Cursor::Progress: return "Progress";
2167 case Cursor::NoDrop: return "NoDrop";
2168 case Cursor::Copy: return "Copy";
2169 case Cursor::None: return "None";
2170 case Cursor::NotAllowed: return "NotAllowed";
2171 case Cursor::ZoomIn: return "ZoomIn";
2172 case Cursor::ZoomOut: return "ZoomOut";
2173 case Cursor::Grab: return "Grab";
2174 case Cursor::Grabbing: return "Grabbing";
2175 case Cursor::Custom: return "Custom";
2178 ASSERT_NOT_REACHED();
2182 String Internals::getCurrentCursorInfo(Document* document, ExceptionState& exceptionState)
2184 if (!document || !document->frame()) {
2185 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
2189 Cursor cursor = document->frame()->eventHandler().currentMouseCursor();
2191 StringBuilder result;
2192 result.append("type=");
2193 result.append(cursorTypeToString(cursor.type()));
2194 result.append(" hotSpot=");
2195 result.appendNumber(cursor.hotSpot().x());
2197 result.appendNumber(cursor.hotSpot().y());
2198 if (cursor.image()) {
2199 IntSize size = cursor.image()->size();
2200 result.append(" image=");
2201 result.appendNumber(size.width());
2203 result.appendNumber(size.height());
2205 if (cursor.imageScaleFactor() != 1) {
2206 result.append(" scale=");
2207 NumberToStringBuffer buffer;
2208 result.append(numberToFixedPrecisionString(cursor.imageScaleFactor(), 8, buffer, true));
2211 return result.toString();
2214 PassRefPtr<ArrayBuffer> Internals::serializeObject(PassRefPtr<SerializedScriptValue> value) const
2216 String stringValue = value->toWireString();
2217 RefPtr<ArrayBuffer> buffer = ArrayBuffer::createUninitialized(stringValue.length(), sizeof(UChar));
2218 stringValue.copyTo(static_cast<UChar*>(buffer->data()), 0, stringValue.length());
2219 return buffer.release();
2222 PassRefPtr<SerializedScriptValue> Internals::deserializeBuffer(PassRefPtr<ArrayBuffer> buffer) const
2224 String value(static_cast<const UChar*>(buffer->data()), buffer->byteLength() / sizeof(UChar));
2225 return SerializedScriptValue::createFromWire(value);
2228 void Internals::forceReload(bool endToEnd)
2230 frame()->loader().reload(endToEnd ? EndToEndReload : NormalReload);
2233 PassRefPtr<ClientRect> Internals::selectionBounds(ExceptionState& exceptionState)
2235 Document* document = contextDocument();
2236 if (!document || !document->frame()) {
2237 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "No context document can be obtained.");
2241 return ClientRect::create(document->frame()->selection().bounds());
2244 String Internals::markerTextForListItem(Element* element, ExceptionState& exceptionState)
2247 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
2250 return WebCore::markerTextForListItem(element);
2253 String Internals::getImageSourceURL(Element* element, ExceptionState& exceptionState)
2256 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
2259 return element->imageSourceURL();
2262 String Internals::baseURL(Document* document, ExceptionState& exceptionState)
2265 exceptionState.throwDOMException(InvalidAccessError, "No context document is available.");
2269 return document->baseURL().string();
2272 bool Internals::isSelectPopupVisible(Node* node)
2274 if (!node->hasTagName(HTMLNames::selectTag))
2277 HTMLSelectElement* select = toHTMLSelectElement(node);
2279 RenderObject* renderer = select->renderer();
2280 if (!renderer->isMenuList())
2283 RenderMenuList* menuList = toRenderMenuList(renderer);
2284 return menuList->popupIsVisible();
2287 bool Internals::loseSharedGraphicsContext3D()
2289 OwnPtr<blink::WebGraphicsContext3DProvider> sharedProvider = adoptPtr(blink::Platform::current()->createSharedOffscreenGraphicsContext3DProvider());
2290 if (!sharedProvider)
2292 blink::WebGraphicsContext3D* sharedContext = sharedProvider->context3d();
2293 sharedContext->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_EXT, GL_INNOCENT_CONTEXT_RESET_EXT);
2294 // To prevent tests that call loseSharedGraphicsContext3D from being
2295 // flaky, we call finish so that the context is guaranteed to be lost
2296 // synchronously (i.e. before returning).
2297 sharedContext->finish();
2301 void Internals::forceCompositingUpdate(Document* document, ExceptionState& exceptionState)
2303 if (!document || !document->renderView()) {
2304 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's render view cannot be retrieved." : "The document provided is invalid.");
2308 document->updateLayout();
2310 RenderView* view = document->renderView();
2311 if (view->compositor())
2312 view->compositor()->updateCompositingLayers();
2315 bool Internals::isCompositorFramePending(Document* document, ExceptionState& exceptionState)
2317 if (!document || !document->renderView()) {
2318 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's render view cannot be retrieved." : "The document provided is invalid.");
2322 return document->page()->chrome().client().isCompositorFramePending();
2325 void Internals::setZoomFactor(float factor)
2327 frame()->setPageZoomFactor(factor);
2330 void Internals::setShouldRevealPassword(Element* element, bool reveal, ExceptionState& exceptionState)
2332 if (!element || !element->hasTagName(inputTag)) {
2333 exceptionState.throwDOMException(InvalidAccessError, "The element provided is invalid.");
2337 return toHTMLInputElement(element)->setShouldRevealPassword(reveal);
2342 class AddOneFunction : public ScriptFunction {
2344 static PassOwnPtr<ScriptFunction> create(ExecutionContext* context)
2346 return adoptPtr(new AddOneFunction(toIsolate(context)));
2350 AddOneFunction(v8::Isolate* isolate)
2351 : ScriptFunction(isolate)
2355 virtual ScriptValue call(ScriptValue value) OVERRIDE
2357 v8::Local<v8::Value> v8Value = value.v8Value();
2358 v8::Isolate* isolate = value.isolate();
2359 ASSERT(v8Value->IsNumber());
2360 int intValue = v8Value.As<v8::Integer>()->Value();
2361 ScriptValue result = ScriptValue(v8::Integer::New(isolate, intValue + 1), isolate);
2368 ScriptPromise Internals::addOneToPromise(ExecutionContext* context, ScriptPromise promise)
2370 return promise.then(AddOneFunction::create(context));