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 "core/testing/Internals.h"
30 #include "bindings/core/v8/ExceptionMessages.h"
31 #include "bindings/core/v8/ExceptionState.h"
32 #include "bindings/core/v8/ScriptFunction.h"
33 #include "bindings/core/v8/ScriptPromise.h"
34 #include "bindings/core/v8/ScriptPromiseResolver.h"
35 #include "bindings/core/v8/SerializedScriptValue.h"
36 #include "bindings/core/v8/V8ThrowException.h"
37 #include "core/InternalRuntimeFlags.h"
38 #include "core/animation/AnimationTimeline.h"
39 #include "core/css/StyleSheetContents.h"
40 #include "core/css/resolver/StyleResolver.h"
41 #include "core/css/resolver/StyleResolverStats.h"
42 #include "core/css/resolver/ViewportStyleResolver.h"
43 #include "core/dom/ClientRect.h"
44 #include "core/dom/ClientRectList.h"
45 #include "core/dom/DOMStringList.h"
46 #include "core/dom/Document.h"
47 #include "core/dom/DocumentMarker.h"
48 #include "core/dom/DocumentMarkerController.h"
49 #include "core/dom/Element.h"
50 #include "core/dom/ExceptionCode.h"
51 #include "core/dom/FullscreenElementStack.h"
52 #include "core/dom/NodeRenderStyle.h"
53 #include "core/dom/PseudoElement.h"
54 #include "core/dom/Range.h"
55 #include "core/dom/StaticNodeList.h"
56 #include "core/dom/StyleEngine.h"
57 #include "core/dom/TreeScope.h"
58 #include "core/dom/ViewportDescription.h"
59 #include "core/dom/shadow/ComposedTreeWalker.h"
60 #include "core/dom/shadow/ElementShadow.h"
61 #include "core/dom/shadow/SelectRuleFeatureSet.h"
62 #include "core/dom/shadow/ShadowRoot.h"
63 #include "core/editing/Editor.h"
64 #include "core/editing/PlainTextRange.h"
65 #include "core/editing/SpellCheckRequester.h"
66 #include "core/editing/SpellChecker.h"
67 #include "core/editing/SurroundingText.h"
68 #include "core/editing/TextIterator.h"
69 #include "core/fetch/MemoryCache.h"
70 #include "core/fetch/ResourceFetcher.h"
71 #include "core/frame/LocalDOMWindow.h"
72 #include "core/frame/EventHandlerRegistry.h"
73 #include "core/frame/FrameView.h"
74 #include "core/frame/LocalFrame.h"
75 #include "core/frame/Settings.h"
76 #include "core/frame/WebKitPoint.h"
77 #include "core/html/HTMLContentElement.h"
78 #include "core/html/HTMLIFrameElement.h"
79 #include "core/html/HTMLInputElement.h"
80 #include "core/html/HTMLMediaElement.h"
81 #include "core/html/HTMLSelectElement.h"
82 #include "core/html/HTMLTextAreaElement.h"
83 #include "core/html/canvas/CanvasRenderingContext2D.h"
84 #include "core/html/forms/FormController.h"
85 #include "core/html/shadow/ShadowElementNames.h"
86 #include "core/html/shadow/TextControlInnerElements.h"
87 #include "core/inspector/InspectorClient.h"
88 #include "core/inspector/InspectorConsoleAgent.h"
89 #include "core/inspector/InspectorController.h"
90 #include "core/inspector/InspectorCounters.h"
91 #include "core/inspector/InspectorFrontendChannel.h"
92 #include "core/inspector/InspectorInstrumentation.h"
93 #include "core/inspector/InspectorOverlay.h"
94 #include "core/inspector/InstrumentingAgents.h"
95 #include "core/loader/FrameLoader.h"
96 #include "core/loader/HistoryItem.h"
97 #include "core/page/Chrome.h"
98 #include "core/page/ChromeClient.h"
99 #include "core/page/EventHandler.h"
100 #include "core/page/FocusController.h"
101 #include "core/page/NetworkStateNotifier.h"
102 #include "core/page/Page.h"
103 #include "core/page/PagePopupController.h"
104 #include "core/page/PrintContext.h"
105 #include "core/rendering/RenderLayer.h"
106 #include "core/rendering/RenderMenuList.h"
107 #include "core/rendering/RenderObject.h"
108 #include "core/rendering/RenderTreeAsText.h"
109 #include "core/rendering/RenderView.h"
110 #include "core/rendering/compositing/CompositedLayerMapping.h"
111 #include "core/rendering/compositing/RenderLayerCompositor.h"
112 #include "core/testing/GCObservation.h"
113 #include "core/testing/InternalProfilers.h"
114 #include "core/testing/InternalSettings.h"
115 #include "core/testing/LayerRect.h"
116 #include "core/testing/LayerRectList.h"
117 #include "core/testing/MockPagePopupDriver.h"
118 #include "core/testing/PrivateScriptTest.h"
119 #include "core/testing/TypeConversions.h"
120 #include "core/workers/WorkerThread.h"
121 #include "platform/Cursor.h"
122 #include "platform/Language.h"
123 #include "platform/RuntimeEnabledFeatures.h"
124 #include "platform/TraceEvent.h"
125 #include "platform/geometry/IntRect.h"
126 #include "platform/geometry/LayoutRect.h"
127 #include "platform/graphics/GraphicsLayer.h"
128 #include "platform/graphics/filters/FilterOperation.h"
129 #include "platform/graphics/filters/FilterOperations.h"
130 #include "platform/weborigin/SchemeRegistry.h"
131 #include "public/platform/Platform.h"
132 #include "public/platform/WebConnectionType.h"
133 #include "public/platform/WebGraphicsContext3D.h"
134 #include "public/platform/WebGraphicsContext3DProvider.h"
135 #include "public/platform/WebLayer.h"
136 #include "wtf/InstanceCounter.h"
137 #include "wtf/PassOwnPtr.h"
138 #include "wtf/dtoa.h"
139 #include "wtf/text/StringBuffer.h"
144 // FIXME: oilpan: These will be removed soon.
145 static MockPagePopupDriver* s_pagePopupDriver = 0;
147 using namespace HTMLNames;
149 static bool markerTypesFrom(const String& markerType, DocumentMarker::MarkerTypes& result)
151 if (markerType.isEmpty() || equalIgnoringCase(markerType, "all"))
152 result = DocumentMarker::AllMarkers();
153 else if (equalIgnoringCase(markerType, "Spelling"))
154 result = DocumentMarker::Spelling;
155 else if (equalIgnoringCase(markerType, "Grammar"))
156 result = DocumentMarker::Grammar;
157 else if (equalIgnoringCase(markerType, "TextMatch"))
158 result = DocumentMarker::TextMatch;
165 static SpellCheckRequester* spellCheckRequester(Document* document)
167 if (!document || !document->frame())
169 return &document->frame()->spellChecker().spellCheckRequester();
172 const char* Internals::internalsId = "internals";
174 PassRefPtrWillBeRawPtr<Internals> Internals::create(Document* document)
176 return adoptRefWillBeNoop(new Internals(document));
179 Internals::~Internals()
183 void Internals::resetToConsistentState(Page* page)
187 page->setDeviceScaleFactor(1);
188 page->setIsCursorVisible(true);
189 page->setPageScaleFactor(1, IntPoint(0, 0));
190 blink::overrideUserPreferredLanguages(Vector<AtomicString>());
191 delete s_pagePopupDriver;
192 s_pagePopupDriver = 0;
193 page->chrome().client().resetPagePopupDriver();
194 if (!page->deprecatedLocalMainFrame()->spellChecker().isContinuousSpellCheckingEnabled())
195 page->deprecatedLocalMainFrame()->spellChecker().toggleContinuousSpellChecking();
196 if (page->deprecatedLocalMainFrame()->editor().isOverwriteModeEnabled())
197 page->deprecatedLocalMainFrame()->editor().toggleOverwriteModeEnabled();
199 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
200 scrollingCoordinator->reset();
202 page->deprecatedLocalMainFrame()->view()->clear();
205 Internals::Internals(Document* document)
206 : ContextLifecycleObserver(document)
207 , m_runtimeFlags(InternalRuntimeFlags::create())
209 ScriptWrappable::init(this);
212 Document* Internals::contextDocument() const
214 return toDocument(executionContext());
217 LocalFrame* Internals::frame() const
219 if (!contextDocument())
221 return contextDocument()->frame();
224 InternalSettings* Internals::settings() const
226 Document* document = contextDocument();
229 Page* page = document->page();
232 return InternalSettings::from(*page);
235 InternalRuntimeFlags* Internals::runtimeFlags() const
237 return m_runtimeFlags.get();
240 InternalProfilers* Internals::profilers()
243 m_profilers = InternalProfilers::create();
244 return m_profilers.get();
247 unsigned Internals::workerThreadCount() const
249 return WorkerThread::workerThreadCount();
252 String Internals::address(Node* node)
255 sprintf(buf, "%p", node);
260 PassRefPtrWillBeRawPtr<GCObservation> Internals::observeGC(ScriptValue scriptValue)
262 v8::Handle<v8::Value> observedValue = scriptValue.v8Value();
263 ASSERT(!observedValue.IsEmpty());
264 if (observedValue->IsNull() || observedValue->IsUndefined()) {
265 V8ThrowException::throwTypeError("value to observe is null or undefined", v8::Isolate::GetCurrent());
269 return GCObservation::create(observedValue);
272 unsigned Internals::updateStyleAndReturnAffectedElementCount(ExceptionState& exceptionState) const
274 Document* document = contextDocument();
276 exceptionState.throwDOMException(InvalidAccessError, "No context document is available.");
280 unsigned beforeCount = document->styleEngine()->resolverAccessCount();
281 document->updateRenderTreeIfNeeded();
282 return document->styleEngine()->resolverAccessCount() - beforeCount;
285 unsigned Internals::needsLayoutCount(ExceptionState& exceptionState) const
287 LocalFrame* contextFrame = frame();
289 exceptionState.throwDOMException(InvalidAccessError, "No context frame is available.");
294 unsigned needsLayoutObjects;
295 unsigned totalObjects;
296 contextFrame->countObjectsNeedingLayout(needsLayoutObjects, totalObjects, isPartial);
297 return needsLayoutObjects;
300 unsigned Internals::hitTestCount(Document* doc, ExceptionState& exceptionState) const
303 exceptionState.throwDOMException(InvalidAccessError, "Must supply document to check");
307 return doc->renderView()->hitTestCount();
311 bool Internals::isPreloaded(const String& url)
313 Document* document = contextDocument();
314 return document->fetcher()->isPreloaded(url);
317 bool Internals::isLoadingFromMemoryCache(const String& url)
319 if (!contextDocument())
321 Resource* resource = memoryCache()->resourceForURL(contextDocument()->completeURL(url));
322 return resource && resource->status() == Resource::Cached;
325 void Internals::crash()
330 void Internals::setStyleResolverStatsEnabled(bool enabled)
332 Document* document = contextDocument();
334 document->ensureStyleResolver().enableStats(StyleResolver::ReportSlowStats);
336 document->ensureStyleResolver().disableStats();
339 String Internals::styleResolverStatsReport(ExceptionState& exceptionState) const
341 Document* document = contextDocument();
343 exceptionState.throwDOMException(InvalidAccessError, "No context document is available.");
346 if (!document->ensureStyleResolver().stats()) {
347 exceptionState.throwDOMException(InvalidStateError, "Style resolver stats not enabled");
350 return document->ensureStyleResolver().stats()->report();
353 String Internals::styleResolverStatsTotalsReport(ExceptionState& exceptionState) const
355 Document* document = contextDocument();
357 exceptionState.throwDOMException(InvalidAccessError, "No context document is available.");
360 if (!document->ensureStyleResolver().statsTotals()) {
361 exceptionState.throwDOMException(InvalidStateError, "Style resolver stats not enabled");
364 return document->ensureStyleResolver().statsTotals()->report();
367 bool Internals::isSharingStyle(Element* element1, Element* element2) const
369 ASSERT(element1 && element2);
370 return element1->renderStyle() == element2->renderStyle();
373 bool Internals::isValidContentSelect(Element* insertionPoint, ExceptionState& exceptionState)
375 ASSERT(insertionPoint);
376 if (!insertionPoint->isInsertionPoint()) {
377 exceptionState.throwDOMException(InvalidAccessError, "The element is not an insertion point.");
381 return isHTMLContentElement(*insertionPoint) && toHTMLContentElement(*insertionPoint).isSelectValid();
384 Node* Internals::treeScopeRootNode(Node* node)
387 return &node->treeScope().rootNode();
390 Node* Internals::parentTreeScope(Node* node)
393 const TreeScope* parentTreeScope = node->treeScope().parentTreeScope();
394 return parentTreeScope ? &parentTreeScope->rootNode() : 0;
397 bool Internals::hasSelectorForIdInShadow(Element* host, const AtomicString& idValue, ExceptionState& exceptionState)
400 if (!host->shadow()) {
401 exceptionState.throwDOMException(InvalidAccessError, "The host element does not have a shadow.");
405 return host->shadow()->ensureSelectFeatureSet().hasSelectorForId(idValue);
408 bool Internals::hasSelectorForClassInShadow(Element* host, const AtomicString& className, ExceptionState& exceptionState)
411 if (!host->shadow()) {
412 exceptionState.throwDOMException(InvalidAccessError, "The host element does not have a shadow.");
416 return host->shadow()->ensureSelectFeatureSet().hasSelectorForClass(className);
419 bool Internals::hasSelectorForAttributeInShadow(Element* host, const AtomicString& attributeName, ExceptionState& exceptionState)
422 if (!host->shadow()) {
423 exceptionState.throwDOMException(InvalidAccessError, "The host element does not have a shadow.");
427 return host->shadow()->ensureSelectFeatureSet().hasSelectorForAttribute(attributeName);
430 bool Internals::hasSelectorForPseudoClassInShadow(Element* host, const String& pseudoClass, ExceptionState& exceptionState)
433 if (!host->shadow()) {
434 exceptionState.throwDOMException(InvalidAccessError, "The host element does not have a shadow.");
438 const SelectRuleFeatureSet& featureSet = host->shadow()->ensureSelectFeatureSet();
439 if (pseudoClass == "checked")
440 return featureSet.hasSelectorForChecked();
441 if (pseudoClass == "enabled")
442 return featureSet.hasSelectorForEnabled();
443 if (pseudoClass == "disabled")
444 return featureSet.hasSelectorForDisabled();
445 if (pseudoClass == "indeterminate")
446 return featureSet.hasSelectorForIndeterminate();
447 if (pseudoClass == "link")
448 return featureSet.hasSelectorForLink();
449 if (pseudoClass == "target")
450 return featureSet.hasSelectorForTarget();
451 if (pseudoClass == "visited")
452 return featureSet.hasSelectorForVisited();
454 ASSERT_NOT_REACHED();
458 unsigned short Internals::compareTreeScopePosition(const Node* node1, const Node* node2, ExceptionState& exceptionState) const
460 ASSERT(node1 && node2);
461 const TreeScope* treeScope1 = node1->isDocumentNode() ? static_cast<const TreeScope*>(toDocument(node1)) :
462 node1->isShadowRoot() ? static_cast<const TreeScope*>(toShadowRoot(node1)) : 0;
463 const TreeScope* treeScope2 = node2->isDocumentNode() ? static_cast<const TreeScope*>(toDocument(node2)) :
464 node2->isShadowRoot() ? static_cast<const TreeScope*>(toShadowRoot(node2)) : 0;
465 if (!treeScope1 || !treeScope2) {
466 exceptionState.throwDOMException(InvalidAccessError, String::format("The %s node is neither a document node, nor a shadow root.", treeScope1 ? "second" : "first"));
469 return treeScope1->comparePosition(*treeScope2);
472 void Internals::pauseAnimations(double pauseTime, ExceptionState& exceptionState)
475 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::indexExceedsMinimumBound("pauseTime", pauseTime, 0.0));
479 frame()->view()->updateLayoutAndStyleForPainting();
480 frame()->document()->timeline().pauseAnimationsForTesting(pauseTime);
483 bool Internals::hasShadowInsertionPoint(const Node* root, ExceptionState& exceptionState) const
486 if (!root->isShadowRoot()) {
487 exceptionState.throwDOMException(InvalidAccessError, "The node argument is not a shadow root.");
490 return toShadowRoot(root)->containsShadowElements();
493 bool Internals::hasContentElement(const Node* root, ExceptionState& exceptionState) const
496 if (!root->isShadowRoot()) {
497 exceptionState.throwDOMException(InvalidAccessError, "The node argument is not a shadow root.");
500 return toShadowRoot(root)->containsContentElements();
503 size_t Internals::countElementShadow(const Node* root, ExceptionState& exceptionState) const
506 if (!root->isShadowRoot()) {
507 exceptionState.throwDOMException(InvalidAccessError, "The node argument is not a shadow root.");
510 return toShadowRoot(root)->childShadowRootCount();
513 Node* Internals::nextSiblingByWalker(Node* node)
516 ComposedTreeWalker walker(node);
517 walker.nextSibling();
521 Node* Internals::firstChildByWalker(Node* node)
524 ComposedTreeWalker walker(node);
529 Node* Internals::lastChildByWalker(Node* node)
532 ComposedTreeWalker walker(node);
537 Node* Internals::nextNodeByWalker(Node* node)
540 ComposedTreeWalker walker(node);
545 Node* Internals::previousNodeByWalker(Node* node)
548 ComposedTreeWalker walker(node);
553 String Internals::elementRenderTreeAsText(Element* element, ExceptionState& exceptionState)
556 String representation = externalRepresentation(element);
557 if (representation.isEmpty()) {
558 exceptionState.throwDOMException(InvalidAccessError, "The element provided has no external representation.");
562 return representation;
565 PassRefPtrWillBeRawPtr<CSSStyleDeclaration> Internals::computedStyleIncludingVisitedInfo(Node* node) const
568 bool allowVisitedStyle = true;
569 return CSSComputedStyleDeclaration::create(node, allowVisitedStyle);
572 PassRefPtrWillBeRawPtr<ShadowRoot> Internals::createUserAgentShadowRoot(Element* host)
575 return PassRefPtrWillBeRawPtr<ShadowRoot>(host->ensureUserAgentShadowRoot());
578 ShadowRoot* Internals::shadowRoot(Element* host)
580 // FIXME: Internals::shadowRoot() in tests should be converted to youngestShadowRoot() or oldestShadowRoot().
581 // https://bugs.webkit.org/show_bug.cgi?id=78465
582 return youngestShadowRoot(host);
585 ShadowRoot* Internals::youngestShadowRoot(Element* host)
588 if (ElementShadow* shadow = host->shadow())
589 return shadow->youngestShadowRoot();
593 ShadowRoot* Internals::oldestShadowRoot(Element* host)
596 if (ElementShadow* shadow = host->shadow())
597 return shadow->oldestShadowRoot();
601 ShadowRoot* Internals::youngerShadowRoot(Node* shadow, ExceptionState& exceptionState)
604 if (!shadow->isShadowRoot()) {
605 exceptionState.throwDOMException(InvalidAccessError, "The node provided is not a shadow root.");
609 return toShadowRoot(shadow)->youngerShadowRoot();
612 String Internals::shadowRootType(const Node* root, ExceptionState& exceptionState) const
615 if (!root->isShadowRoot()) {
616 exceptionState.throwDOMException(InvalidAccessError, "The node provided is not a shadow root.");
620 switch (toShadowRoot(root)->type()) {
621 case ShadowRoot::UserAgentShadowRoot:
622 return String("UserAgentShadowRoot");
623 case ShadowRoot::AuthorShadowRoot:
624 return String("AuthorShadowRoot");
626 ASSERT_NOT_REACHED();
627 return String("Unknown");
631 const AtomicString& Internals::shadowPseudoId(Element* element)
634 return element->shadowPseudoId();
637 void Internals::setShadowPseudoId(Element* element, const AtomicString& id)
640 return element->setShadowPseudoId(id);
643 String Internals::visiblePlaceholder(Element* element)
645 if (element && isHTMLTextFormControlElement(*element)) {
646 if (toHTMLTextFormControlElement(element)->placeholderShouldBeVisible())
647 return toHTMLTextFormControlElement(element)->placeholderElement()->textContent();
653 void Internals::selectColorInColorChooser(Element* element, const String& colorValue)
656 if (!isHTMLInputElement(*element))
659 if (!color.setFromString(colorValue))
661 toHTMLInputElement(*element).selectColorInColorChooser(color);
664 bool Internals::hasAutofocusRequest(Document* document)
667 document = contextDocument();
668 return document->autofocusElement();
671 bool Internals::hasAutofocusRequest()
673 return hasAutofocusRequest(0);
676 Vector<String> Internals::formControlStateOfHistoryItem(ExceptionState& exceptionState)
678 HistoryItem* mainItem = frame()->loader().currentItem();
680 exceptionState.throwDOMException(InvalidAccessError, "No history item is available.");
681 return Vector<String>();
683 return mainItem->documentState();
686 void Internals::setFormControlStateOfHistoryItem(const Vector<String>& state, ExceptionState& exceptionState)
688 HistoryItem* mainItem = frame()->loader().currentItem();
690 exceptionState.throwDOMException(InvalidAccessError, "No history item is available.");
693 mainItem->clearDocumentState();
694 mainItem->setDocumentState(state);
697 void Internals::setEnableMockPagePopup(bool enabled, ExceptionState& exceptionState)
699 Document* document = contextDocument();
700 if (!document || !document->page())
702 Page* page = document->page();
704 page->chrome().client().resetPagePopupDriver();
707 if (!s_pagePopupDriver)
708 s_pagePopupDriver = MockPagePopupDriver::create(page->deprecatedLocalMainFrame()).leakPtr();
709 page->chrome().client().setPagePopupDriver(s_pagePopupDriver);
712 PassRefPtrWillBeRawPtr<PagePopupController> Internals::pagePopupController()
714 return s_pagePopupDriver ? s_pagePopupDriver->pagePopupController() : 0;
717 PassRefPtrWillBeRawPtr<ClientRect> Internals::unscaledViewportRect(ExceptionState& exceptionState)
719 Document* document = contextDocument();
720 if (!document || !document->view()) {
721 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's viewport cannot be retrieved." : "No context document can be obtained.");
722 return ClientRect::create();
725 return ClientRect::create(document->view()->visibleContentRect());
728 PassRefPtrWillBeRawPtr<ClientRect> Internals::absoluteCaretBounds(ExceptionState& exceptionState)
730 Document* document = contextDocument();
731 if (!document || !document->frame()) {
732 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "No context document can be obtained.");
733 return ClientRect::create();
736 return ClientRect::create(document->frame()->selection().absoluteCaretBounds());
739 PassRefPtrWillBeRawPtr<ClientRect> Internals::boundingBox(Element* element)
743 element->document().updateLayoutIgnorePendingStylesheets();
744 RenderObject* renderer = element->renderer();
746 return ClientRect::create();
747 return ClientRect::create(renderer->absoluteBoundingBoxRectIgnoringTransforms());
750 unsigned Internals::markerCountForNode(Node* node, const String& markerType, ExceptionState& exceptionState)
753 DocumentMarker::MarkerTypes markerTypes = 0;
754 if (!markerTypesFrom(markerType, markerTypes)) {
755 exceptionState.throwDOMException(SyntaxError, "The marker type provided ('" + markerType + "') is invalid.");
759 return node->document().markers().markersFor(node, markerTypes).size();
762 unsigned Internals::activeMarkerCountForNode(Node* node)
766 // Only TextMatch markers can be active.
767 DocumentMarker::MarkerType markerType = DocumentMarker::TextMatch;
768 DocumentMarkerVector markers = node->document().markers().markersFor(node, markerType);
770 unsigned activeMarkerCount = 0;
771 for (DocumentMarkerVector::iterator iter = markers.begin(); iter != markers.end(); ++iter) {
772 if ((*iter)->activeMatch())
776 return activeMarkerCount;
779 DocumentMarker* Internals::markerAt(Node* node, const String& markerType, unsigned index, ExceptionState& exceptionState)
782 DocumentMarker::MarkerTypes markerTypes = 0;
783 if (!markerTypesFrom(markerType, markerTypes)) {
784 exceptionState.throwDOMException(SyntaxError, "The marker type provided ('" + markerType + "') is invalid.");
788 DocumentMarkerVector markers = node->document().markers().markersFor(node, markerTypes);
789 if (markers.size() <= index)
791 return markers[index];
794 PassRefPtrWillBeRawPtr<Range> Internals::markerRangeForNode(Node* node, const String& markerType, unsigned index, ExceptionState& exceptionState)
797 DocumentMarker* marker = markerAt(node, markerType, index, exceptionState);
800 return Range::create(node->document(), node, marker->startOffset(), node, marker->endOffset());
803 String Internals::markerDescriptionForNode(Node* node, const String& markerType, unsigned index, ExceptionState& exceptionState)
805 DocumentMarker* marker = markerAt(node, markerType, index, exceptionState);
808 return marker->description();
811 void Internals::addTextMatchMarker(const Range* range, bool isActive)
814 range->ownerDocument().updateLayoutIgnorePendingStylesheets();
815 range->ownerDocument().markers().addTextMatchMarker(range, isActive);
818 void Internals::setMarkersActive(Node* node, unsigned startOffset, unsigned endOffset, bool active)
821 node->document().markers().setMarkersActive(node, startOffset, endOffset, active);
824 void Internals::setMarkedTextMatchesAreHighlighted(Document* document, bool highlight)
826 if (!document || !document->frame())
829 document->frame()->editor().setMarkedTextMatchesAreHighlighted(highlight);
832 void Internals::setScrollViewPosition(Document* document, long x, long y, ExceptionState& exceptionState)
835 if (!document->view()) {
836 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
840 FrameView* frameView = document->view();
841 bool constrainsScrollingToContentEdgeOldValue = frameView->constrainsScrollingToContentEdge();
842 bool scrollbarsSuppressedOldValue = frameView->scrollbarsSuppressed();
844 frameView->setConstrainsScrollingToContentEdge(false);
845 frameView->setScrollbarsSuppressed(false);
846 frameView->setScrollOffsetFromInternals(IntPoint(x, y));
847 frameView->setScrollbarsSuppressed(scrollbarsSuppressedOldValue);
848 frameView->setConstrainsScrollingToContentEdge(constrainsScrollingToContentEdgeOldValue);
851 String Internals::viewportAsText(Document* document, float, int availableWidth, int availableHeight, ExceptionState& exceptionState)
854 if (!document->page()) {
855 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
859 document->updateLayoutIgnorePendingStylesheets();
861 Page* page = document->page();
863 // Update initial viewport size.
864 IntSize initialViewportSize(availableWidth, availableHeight);
865 document->page()->deprecatedLocalMainFrame()->view()->setFrameRect(IntRect(IntPoint::zero(), initialViewportSize));
867 ViewportDescription description = page->viewportDescription();
868 PageScaleConstraints constraints = description.resolve(initialViewportSize, Length());
870 constraints.fitToContentsWidth(constraints.layoutSize.width(), availableWidth);
872 StringBuilder builder;
874 builder.appendLiteral("viewport size ");
875 builder.append(String::number(constraints.layoutSize.width()));
877 builder.append(String::number(constraints.layoutSize.height()));
879 builder.appendLiteral(" scale ");
880 builder.append(String::number(constraints.initialScale));
881 builder.appendLiteral(" with limits [");
882 builder.append(String::number(constraints.minimumScale));
883 builder.appendLiteral(", ");
884 builder.append(String::number(constraints.maximumScale));
886 builder.appendLiteral("] and userScalable ");
887 builder.append(description.userZoom ? "true" : "false");
889 return builder.toString();
892 bool Internals::wasLastChangeUserEdit(Element* textField, ExceptionState& exceptionState)
895 if (isHTMLInputElement(*textField))
896 return toHTMLInputElement(*textField).lastChangeWasUserEdit();
898 if (isHTMLTextAreaElement(*textField))
899 return toHTMLTextAreaElement(*textField).lastChangeWasUserEdit();
901 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a TEXTAREA.");
905 bool Internals::elementShouldAutoComplete(Element* element, ExceptionState& exceptionState)
908 if (isHTMLInputElement(*element))
909 return toHTMLInputElement(*element).shouldAutocomplete();
911 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not an INPUT.");
915 String Internals::suggestedValue(Element* element, ExceptionState& exceptionState)
918 if (!element->isFormControlElement()) {
919 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a form control element.");
923 String suggestedValue;
924 if (isHTMLInputElement(*element))
925 suggestedValue = toHTMLInputElement(*element).suggestedValue();
927 if (isHTMLTextAreaElement(*element))
928 suggestedValue = toHTMLTextAreaElement(*element).suggestedValue();
930 if (isHTMLSelectElement(*element))
931 suggestedValue = toHTMLSelectElement(*element).suggestedValue();
933 return suggestedValue;
936 void Internals::setSuggestedValue(Element* element, const String& value, ExceptionState& exceptionState)
939 if (!element->isFormControlElement()) {
940 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a form control element.");
944 if (isHTMLInputElement(*element))
945 toHTMLInputElement(*element).setSuggestedValue(value);
947 if (isHTMLTextAreaElement(*element))
948 toHTMLTextAreaElement(*element).setSuggestedValue(value);
950 if (isHTMLSelectElement(*element))
951 toHTMLSelectElement(*element).setSuggestedValue(value);
954 void Internals::setEditingValue(Element* element, const String& value, ExceptionState& exceptionState)
957 if (!isHTMLInputElement(*element)) {
958 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not an INPUT.");
962 toHTMLInputElement(*element).setEditingValue(value);
965 void Internals::setAutofilled(Element* element, bool enabled, ExceptionState& exceptionState)
968 if (!element->isFormControlElement()) {
969 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a form control element.");
972 toHTMLFormControlElement(element)->setAutofilled(enabled);
975 void Internals::scrollElementToRect(Element* element, long x, long y, long w, long h, ExceptionState& exceptionState)
978 if (!element->document().view()) {
979 exceptionState.throwDOMException(InvalidNodeTypeError, element ? "No view can be obtained from the provided element's document." : ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
982 FrameView* frameView = element->document().view();
983 frameView->scrollElementToRect(element, IntRect(x, y, w, h));
986 PassRefPtrWillBeRawPtr<Range> Internals::rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength)
990 // TextIterator depends on Layout information, make sure layout it up to date.
991 scope->document().updateLayoutIgnorePendingStylesheets();
993 return PlainTextRange(rangeLocation, rangeLocation + rangeLength).createRange(*scope);
996 unsigned Internals::locationFromRange(Element* scope, const Range* range)
998 ASSERT(scope && range);
999 // PlainTextRange depends on Layout information, make sure layout it up to date.
1000 scope->document().updateLayoutIgnorePendingStylesheets();
1002 return PlainTextRange::create(*scope, *range).start();
1005 unsigned Internals::lengthFromRange(Element* scope, const Range* range)
1007 ASSERT(scope && range);
1008 // PlainTextRange depends on Layout information, make sure layout it up to date.
1009 scope->document().updateLayoutIgnorePendingStylesheets();
1011 return PlainTextRange::create(*scope, *range).length();
1014 String Internals::rangeAsText(const Range* range)
1017 return range->text();
1020 // FIXME: The next four functions are very similar - combine them once
1021 // bestClickableNode/bestContextMenuNode have been combined..
1023 PassRefPtrWillBeRawPtr<WebKitPoint> Internals::touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1026 if (!document->frame()) {
1027 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1031 document->updateLayout();
1033 IntSize radius(width / 2, height / 2);
1034 IntPoint point(x + radius.width(), y + radius.height());
1036 EventHandler& eventHandler = document->frame()->eventHandler();
1037 IntPoint hitTestPoint = document->frame()->view()->windowToContents(point);
1038 HitTestResult result = eventHandler.hitTestResultAtPoint(hitTestPoint, HitTestRequest::ReadOnly | HitTestRequest::Active, radius);
1041 IntPoint adjustedPoint;
1043 bool foundNode = eventHandler.bestClickableNodeForHitTestResult(result, adjustedPoint, targetNode);
1045 return WebKitPoint::create(adjustedPoint.x(), adjustedPoint.y());
1050 Node* Internals::touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1053 if (!document->frame()) {
1054 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1058 document->updateLayout();
1060 IntSize radius(width / 2, height / 2);
1061 IntPoint point(x + radius.width(), y + radius.height());
1063 EventHandler& eventHandler = document->frame()->eventHandler();
1064 IntPoint hitTestPoint = document->frame()->view()->windowToContents(point);
1065 HitTestResult result = eventHandler.hitTestResultAtPoint(hitTestPoint, HitTestRequest::ReadOnly | HitTestRequest::Active, radius);
1068 IntPoint adjustedPoint;
1069 document->frame()->eventHandler().bestClickableNodeForHitTestResult(result, adjustedPoint, targetNode);
1073 PassRefPtrWillBeRawPtr<WebKitPoint> Internals::touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1076 if (!document->frame()) {
1077 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1081 document->updateLayout();
1083 IntSize radius(width / 2, height / 2);
1084 IntPoint point(x + radius.width(), y + radius.height());
1086 EventHandler& eventHandler = document->frame()->eventHandler();
1087 IntPoint hitTestPoint = document->frame()->view()->windowToContents(point);
1088 HitTestResult result = eventHandler.hitTestResultAtPoint(hitTestPoint, HitTestRequest::ReadOnly | HitTestRequest::Active, radius);
1090 Node* targetNode = 0;
1091 IntPoint adjustedPoint;
1093 bool foundNode = eventHandler.bestContextMenuNodeForHitTestResult(result, adjustedPoint, targetNode);
1095 return WebKitPoint::create(adjustedPoint.x(), adjustedPoint.y());
1097 return WebKitPoint::create(x, y);
1100 Node* Internals::touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1103 if (!document->frame()) {
1104 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1108 document->updateLayout();
1110 IntSize radius(width / 2, height / 2);
1111 IntPoint point(x + radius.width(), y + radius.height());
1113 EventHandler& eventHandler = document->frame()->eventHandler();
1114 IntPoint hitTestPoint = document->frame()->view()->windowToContents(point);
1115 HitTestResult result = eventHandler.hitTestResultAtPoint(hitTestPoint, HitTestRequest::ReadOnly | HitTestRequest::Active, radius);
1117 Node* targetNode = 0;
1118 IntPoint adjustedPoint;
1119 eventHandler.bestContextMenuNodeForHitTestResult(result, adjustedPoint, targetNode);
1123 PassRefPtrWillBeRawPtr<ClientRect> Internals::bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1126 if (!document->frame()) {
1127 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1131 document->updateLayout();
1133 IntSize radius(width / 2, height / 2);
1134 IntPoint point(x + radius.width(), y + radius.height());
1137 IntRect zoomableArea;
1138 bool foundNode = document->frame()->eventHandler().bestZoomableAreaForTouchPoint(point, radius, zoomableArea, targetNode);
1140 return ClientRect::create(zoomableArea);
1146 int Internals::lastSpellCheckRequestSequence(Document* document, ExceptionState& exceptionState)
1148 SpellCheckRequester* requester = spellCheckRequester(document);
1151 exceptionState.throwDOMException(InvalidAccessError, "No spell check requestor can be obtained for the provided document.");
1155 return requester->lastRequestSequence();
1158 int Internals::lastSpellCheckProcessedSequence(Document* document, ExceptionState& exceptionState)
1160 SpellCheckRequester* requester = spellCheckRequester(document);
1163 exceptionState.throwDOMException(InvalidAccessError, "No spell check requestor can be obtained for the provided document.");
1167 return requester->lastProcessedSequence();
1170 Vector<AtomicString> Internals::userPreferredLanguages() const
1172 return blink::userPreferredLanguages();
1175 // Optimally, the bindings generator would pass a Vector<AtomicString> here but
1176 // this is not supported yet.
1177 void Internals::setUserPreferredLanguages(const Vector<String>& languages)
1179 Vector<AtomicString> atomicLanguages;
1180 for (size_t i = 0; i < languages.size(); ++i)
1181 atomicLanguages.append(AtomicString(languages[i]));
1182 blink::overrideUserPreferredLanguages(atomicLanguages);
1185 unsigned Internals::activeDOMObjectCount(Document* document)
1188 return document->activeDOMObjectCount();
1191 static unsigned eventHandlerCount(Document& document, EventHandlerRegistry::EventHandlerClass handlerClass)
1193 if (!document.frameHost())
1195 EventHandlerRegistry* registry = &document.frameHost()->eventHandlerRegistry();
1197 const EventTargetSet* targets = registry->eventHandlerTargets(handlerClass);
1199 for (EventTargetSet::const_iterator iter = targets->begin(); iter != targets->end(); ++iter)
1200 count += iter->value;
1205 unsigned Internals::wheelEventHandlerCount(Document* document)
1208 return eventHandlerCount(*document, EventHandlerRegistry::WheelEvent);
1211 unsigned Internals::scrollEventHandlerCount(Document* document)
1214 return eventHandlerCount(*document, EventHandlerRegistry::ScrollEvent);
1217 unsigned Internals::touchEventHandlerCount(Document* document)
1220 return eventHandlerCount(*document, EventHandlerRegistry::TouchEvent);
1223 static RenderLayer* findRenderLayerForGraphicsLayer(RenderLayer* searchRoot, GraphicsLayer* graphicsLayer, IntSize* layerOffset, String* layerType)
1225 *layerOffset = IntSize();
1226 if (searchRoot->hasCompositedLayerMapping() && graphicsLayer == searchRoot->compositedLayerMapping()->mainGraphicsLayer()) {
1228 RenderLayer::mapRectToPaintBackingCoordinates(searchRoot->renderer(), rect);
1229 *layerOffset = IntSize(rect.x(), rect.y());
1233 GraphicsLayer* layerForScrolling = searchRoot->scrollableArea() ? searchRoot->scrollableArea()->layerForScrolling() : 0;
1234 if (graphicsLayer == layerForScrolling) {
1235 *layerType = "scrolling";
1239 if (searchRoot->compositingState() == PaintsIntoGroupedBacking) {
1240 GraphicsLayer* squashingLayer = searchRoot->groupedMapping()->squashingLayer();
1241 if (graphicsLayer == squashingLayer) {
1242 *layerType ="squashing";
1244 RenderLayer::mapRectToPaintBackingCoordinates(searchRoot->renderer(), rect);
1245 *layerOffset = IntSize(rect.x(), rect.y());
1250 GraphicsLayer* layerForHorizontalScrollbar = searchRoot->scrollableArea() ? searchRoot->scrollableArea()->layerForHorizontalScrollbar() : 0;
1251 if (graphicsLayer == layerForHorizontalScrollbar) {
1252 *layerType = "horizontalScrollbar";
1256 GraphicsLayer* layerForVerticalScrollbar = searchRoot->scrollableArea() ? searchRoot->scrollableArea()->layerForVerticalScrollbar() : 0;
1257 if (graphicsLayer == layerForVerticalScrollbar) {
1258 *layerType = "verticalScrollbar";
1262 GraphicsLayer* layerForScrollCorner = searchRoot->scrollableArea() ? searchRoot->scrollableArea()->layerForScrollCorner() : 0;
1263 if (graphicsLayer == layerForScrollCorner) {
1264 *layerType = "scrollCorner";
1268 // Search right to left to increase the chances that we'll choose the top-most layers in a
1269 // grouped mapping for squashing.
1270 for (RenderLayer* child = searchRoot->lastChild(); child; child = child->previousSibling()) {
1271 RenderLayer* foundLayer = findRenderLayerForGraphicsLayer(child, graphicsLayer, layerOffset, layerType);
1279 // Given a vector of rects, merge those that are adjacent, leaving empty rects
1280 // in the place of no longer used slots. This is intended to simplify the list
1281 // of rects returned by an SkRegion (which have been split apart for sorting
1282 // purposes). No attempt is made to do this efficiently (eg. by relying on the
1283 // sort criteria of SkRegion).
1284 static void mergeRects(blink::WebVector<blink::WebRect>& rects)
1286 for (size_t i = 0; i < rects.size(); ++i) {
1287 if (rects[i].isEmpty())
1292 for (size_t j = i+1; j < rects.size(); ++j) {
1293 if (rects[j].isEmpty())
1295 // Try to merge rects[j] into rects[i] along the 4 possible edges.
1296 if (rects[i].y == rects[j].y && rects[i].height == rects[j].height) {
1297 if (rects[i].x + rects[i].width == rects[j].x) {
1298 rects[i].width += rects[j].width;
1299 rects[j] = blink::WebRect();
1301 } else if (rects[i].x == rects[j].x + rects[j].width) {
1302 rects[i].x = rects[j].x;
1303 rects[i].width += rects[j].width;
1304 rects[j] = blink::WebRect();
1307 } else if (rects[i].x == rects[j].x && rects[i].width == rects[j].width) {
1308 if (rects[i].y + rects[i].height == rects[j].y) {
1309 rects[i].height += rects[j].height;
1310 rects[j] = blink::WebRect();
1312 } else if (rects[i].y == rects[j].y + rects[j].height) {
1313 rects[i].y = rects[j].y;
1314 rects[i].height += rects[j].height;
1315 rects[j] = blink::WebRect();
1324 static void accumulateLayerRectList(RenderLayerCompositor* compositor, GraphicsLayer* graphicsLayer, LayerRectList* rects)
1326 blink::WebVector<blink::WebRect> layerRects = graphicsLayer->platformLayer()->touchEventHandlerRegion();
1327 if (!layerRects.isEmpty()) {
1328 mergeRects(layerRects);
1330 IntSize layerOffset;
1331 RenderLayer* renderLayer = findRenderLayerForGraphicsLayer(compositor->rootRenderLayer(), graphicsLayer, &layerOffset, &layerType);
1332 Node* node = renderLayer ? renderLayer->renderer()->node() : 0;
1333 for (size_t i = 0; i < layerRects.size(); ++i) {
1334 if (!layerRects[i].isEmpty()) {
1335 rects->append(node, layerType, layerOffset.width(), layerOffset.height(), ClientRect::create(layerRects[i]));
1340 size_t numChildren = graphicsLayer->children().size();
1341 for (size_t i = 0; i < numChildren; ++i)
1342 accumulateLayerRectList(compositor, graphicsLayer->children()[i], rects);
1345 PassRefPtrWillBeRawPtr<LayerRectList> Internals::touchEventTargetLayerRects(Document* document, ExceptionState& exceptionState)
1348 if (!document->view() || !document->page() || document != contextDocument()) {
1349 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1353 // Do any pending layout and compositing update (which may call touchEventTargetRectsChange) to ensure this
1354 // really takes any previous changes into account.
1355 forceCompositingUpdate(document, exceptionState);
1356 if (exceptionState.hadException())
1359 if (RenderView* view = document->renderView()) {
1360 if (RenderLayerCompositor* compositor = view->compositor()) {
1361 if (GraphicsLayer* rootLayer = compositor->rootGraphicsLayer()) {
1362 RefPtrWillBeRawPtr<LayerRectList> rects = LayerRectList::create();
1363 accumulateLayerRectList(compositor, rootLayer, rects.get());
1372 PassRefPtrWillBeRawPtr<StaticNodeList> Internals::nodesFromRect(Document* document, int centerX, int centerY, unsigned topPadding, unsigned rightPadding,
1373 unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowChildFrameContent, ExceptionState& exceptionState) const
1376 if (!document->frame() || !document->frame()->view()) {
1377 exceptionState.throwDOMException(InvalidAccessError, "No view can be obtained from the provided document.");
1381 LocalFrame* frame = document->frame();
1382 FrameView* frameView = document->view();
1383 RenderView* renderView = document->renderView();
1388 float zoomFactor = frame->pageZoomFactor();
1389 LayoutPoint point = roundedLayoutPoint(FloatPoint(centerX * zoomFactor + frameView->scrollX(), centerY * zoomFactor + frameView->scrollY()));
1391 HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly | HitTestRequest::Active;
1393 hitType |= HitTestRequest::IgnoreClipping;
1394 if (allowChildFrameContent)
1395 hitType |= HitTestRequest::AllowChildFrameContent;
1397 HitTestRequest request(hitType);
1399 // When ignoreClipping is false, this method returns null for coordinates outside of the viewport.
1400 if (!request.ignoreClipping() && !frameView->visibleContentRect().intersects(HitTestLocation::rectForPoint(point, topPadding, rightPadding, bottomPadding, leftPadding)))
1403 WillBeHeapVector<RefPtrWillBeMember<Node> > matches;
1405 // Need padding to trigger a rect based hit test, but we want to return a NodeList
1406 // so we special case this.
1407 if (!topPadding && !rightPadding && !bottomPadding && !leftPadding) {
1408 HitTestResult result(point);
1409 renderView->hitTest(request, result);
1411 if (Node* innerNode = result.innerNode()) {
1412 if (innerNode->isInShadowTree())
1413 innerNode = innerNode->shadowHost();
1414 matches.append(innerNode);
1417 HitTestResult result(point, topPadding, rightPadding, bottomPadding, leftPadding);
1418 renderView->hitTest(request, result);
1419 copyToVector(result.rectBasedTestResult(), matches);
1422 return StaticNodeList::adopt(matches);
1425 void Internals::emitInspectorDidBeginFrame(int frameId)
1427 contextDocument()->page()->inspectorController().didBeginFrame(frameId);
1430 void Internals::emitInspectorDidCancelFrame()
1432 contextDocument()->page()->inspectorController().didCancelFrame();
1435 bool Internals::hasSpellingMarker(Document* document, int from, int length)
1438 if (!document->frame())
1441 return document->frame()->spellChecker().selectionStartHasMarkerFor(DocumentMarker::Spelling, from, length);
1444 void Internals::setContinuousSpellCheckingEnabled(bool enabled)
1446 if (!contextDocument() || !contextDocument()->frame())
1449 if (enabled != contextDocument()->frame()->spellChecker().isContinuousSpellCheckingEnabled())
1450 contextDocument()->frame()->spellChecker().toggleContinuousSpellChecking();
1453 bool Internals::isOverwriteModeEnabled(Document* document)
1456 if (!document->frame())
1459 return document->frame()->editor().isOverwriteModeEnabled();
1462 void Internals::toggleOverwriteModeEnabled(Document* document)
1465 if (!document->frame())
1468 document->frame()->editor().toggleOverwriteModeEnabled();
1471 unsigned Internals::numberOfLiveNodes() const
1473 return InspectorCounters::counterValue(InspectorCounters::NodeCounter);
1476 unsigned Internals::numberOfLiveDocuments() const
1478 return InspectorCounters::counterValue(InspectorCounters::DocumentCounter);
1481 String Internals::dumpRefCountedInstanceCounts() const
1483 return WTF::dumpRefCountedInstanceCounts();
1486 Vector<String> Internals::consoleMessageArgumentCounts(Document* document) const
1488 InstrumentingAgents* instrumentingAgents = instrumentationForPage(document->page());
1489 if (!instrumentingAgents)
1490 return Vector<String>();
1491 InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent();
1493 return Vector<String>();
1494 Vector<unsigned> counts = consoleAgent->consoleMessageArgumentCounts();
1495 Vector<String> result(counts.size());
1496 for (size_t i = 0; i < counts.size(); i++)
1497 result[i] = String::number(counts[i]);
1501 Vector<unsigned long> Internals::setMemoryCacheCapacities(unsigned long minDeadBytes, unsigned long maxDeadBytes, unsigned long totalBytes)
1503 Vector<unsigned long> result;
1504 result.append(memoryCache()->minDeadCapacity());
1505 result.append(memoryCache()->maxDeadCapacity());
1506 result.append(memoryCache()->capacity());
1507 memoryCache()->setCapacities(minDeadBytes, maxDeadBytes, totalBytes);
1511 void Internals::setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionState& exceptionState)
1513 Page* page = contextDocument()->frame()->page();
1515 exceptionState.throwDOMException(InvalidAccessError, "No page can be obtained from the current context document.");
1518 page->inspectorController().setResourcesDataSizeLimitsFromInternals(maximumResourcesContentSize, maximumSingleResourceContentSize);
1521 bool Internals::hasGrammarMarker(Document* document, int from, int length)
1524 if (!document->frame())
1527 return document->frame()->spellChecker().selectionStartHasMarkerFor(DocumentMarker::Grammar, from, length);
1530 unsigned Internals::numberOfScrollableAreas(Document* document)
1533 if (!document->frame())
1537 LocalFrame* frame = document->frame();
1538 if (frame->view()->scrollableAreas())
1539 count += frame->view()->scrollableAreas()->size();
1541 for (Frame* child = frame->tree().firstChild(); child; child = child->tree().nextSibling()) {
1542 if (child->isLocalFrame() && toLocalFrame(child)->view() && toLocalFrame(child)->view()->scrollableAreas())
1543 count += toLocalFrame(child)->view()->scrollableAreas()->size();
1549 bool Internals::isPageBoxVisible(Document* document, int pageNumber)
1552 return document->isPageBoxVisible(pageNumber);
1555 String Internals::layerTreeAsText(Document* document, ExceptionState& exceptionState) const
1557 return layerTreeAsText(document, 0, exceptionState);
1560 String Internals::elementLayerTreeAsText(Element* element, ExceptionState& exceptionState) const
1563 FrameView* frameView = element->document().view();
1564 frameView->updateLayoutAndStyleForPainting();
1566 return elementLayerTreeAsText(element, 0, exceptionState);
1569 bool Internals::scrollsWithRespectTo(Element* element1, Element* element2, ExceptionState& exceptionState)
1571 ASSERT(element1 && element2);
1572 element1->document().view()->updateLayoutAndStyleForPainting();
1574 RenderObject* renderer1 = element1->renderer();
1575 RenderObject* renderer2 = element2->renderer();
1576 if (!renderer1 || !renderer1->isBox()) {
1577 exceptionState.throwDOMException(InvalidAccessError, renderer1 ? "The first provided element's renderer is not a box." : "The first provided element has no renderer.");
1580 if (!renderer2 || !renderer2->isBox()) {
1581 exceptionState.throwDOMException(InvalidAccessError, renderer2 ? "The second provided element's renderer is not a box." : "The second provided element has no renderer.");
1585 RenderLayer* layer1 = toRenderBox(renderer1)->layer();
1586 RenderLayer* layer2 = toRenderBox(renderer2)->layer();
1587 if (!layer1 || !layer2) {
1588 exceptionState.throwDOMException(InvalidAccessError, String::format("No render layer can be obtained from the %s provided element.", layer1 ? "second" : "first"));
1592 return layer1->scrollsWithRespectTo(layer2);
1595 bool Internals::isUnclippedDescendant(Element* element, ExceptionState& exceptionState)
1598 element->document().view()->updateLayoutAndStyleForPainting();
1600 RenderObject* renderer = element->renderer();
1601 if (!renderer || !renderer->isBox()) {
1602 exceptionState.throwDOMException(InvalidAccessError, renderer ? "The provided element's renderer is not a box." : "The provided element has no renderer.");
1606 RenderLayer* layer = toRenderBox(renderer)->layer();
1608 exceptionState.throwDOMException(InvalidAccessError, "No render layer can be obtained from the provided element.");
1612 // We used to compute isUnclippedDescendant only when acceleratedCompositingForOverflowScrollEnabled,
1613 // but now we compute it all the time.
1614 // FIXME: Remove this if statement and rebaseline the tests that make this assumption.
1615 if (!layer->compositor()->acceleratedCompositingForOverflowScrollEnabled())
1618 return layer->isUnclippedDescendant();
1621 String Internals::layerTreeAsText(Document* document, unsigned flags, ExceptionState& exceptionState) const
1624 if (!document->frame()) {
1625 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1629 document->view()->updateLayoutAndStyleForPainting();
1631 return document->frame()->layerTreeAsText(flags);
1634 String Internals::elementLayerTreeAsText(Element* element, unsigned flags, ExceptionState& exceptionState) const
1637 element->document().updateLayout();
1639 RenderObject* renderer = element->renderer();
1640 if (!renderer || !renderer->isBox()) {
1641 exceptionState.throwDOMException(InvalidAccessError, renderer ? "The provided element's renderer is not a box." : "The provided element has no renderer.");
1645 RenderLayer* layer = toRenderBox(renderer)->layer();
1647 || !layer->hasCompositedLayerMapping()
1648 || !layer->compositedLayerMapping()->mainGraphicsLayer()) {
1649 // Don't raise exception in these cases which may be normally used in tests.
1653 return layer->compositedLayerMapping()->mainGraphicsLayer()->layerTreeAsText(flags);
1656 String Internals::scrollingStateTreeAsText(Document*) const
1661 String Internals::mainThreadScrollingReasons(Document* document, ExceptionState& exceptionState) const
1664 if (!document->frame()) {
1665 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1669 document->frame()->view()->updateLayoutAndStyleForPainting();
1671 Page* page = document->page();
1675 return page->mainThreadScrollingReasonsAsText();
1678 PassRefPtrWillBeRawPtr<ClientRectList> Internals::nonFastScrollableRects(Document* document, ExceptionState& exceptionState) const
1681 if (!document->frame()) {
1682 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1686 Page* page = document->page();
1690 return page->nonFastScrollableRects(document->frame());
1693 void Internals::garbageCollectDocumentResources(Document* document) const
1696 ResourceFetcher* fetcher = document->fetcher();
1699 fetcher->garbageCollectDocumentResources();
1702 void Internals::evictAllResources() const
1704 memoryCache()->evictResources();
1707 String Internals::counterValue(Element* element)
1712 return counterValueForElement(element);
1715 int Internals::pageNumber(Element* element, float pageWidth, float pageHeight)
1720 return PrintContext::pageNumberForElement(element, FloatSize(pageWidth, pageHeight));
1723 Vector<String> Internals::iconURLs(Document* document, int iconTypesMask) const
1725 Vector<IconURL> iconURLs = document->iconURLs(iconTypesMask);
1726 Vector<String> array;
1728 Vector<IconURL>::const_iterator iter(iconURLs.begin());
1729 for (; iter != iconURLs.end(); ++iter)
1730 array.append(iter->m_iconURL.string());
1735 Vector<String> Internals::shortcutIconURLs(Document* document) const
1737 return iconURLs(document, Favicon);
1740 Vector<String> Internals::allIconURLs(Document* document) const
1742 return iconURLs(document, Favicon | TouchIcon | TouchPrecomposedIcon);
1745 int Internals::numberOfPages(float pageWidth, float pageHeight)
1750 return PrintContext::numberOfPages(frame(), FloatSize(pageWidth, pageHeight));
1753 String Internals::pageProperty(String propertyName, int pageNumber, ExceptionState& exceptionState) const
1756 exceptionState.throwDOMException(InvalidAccessError, "No frame is available.");
1760 return PrintContext::pageProperty(frame(), propertyName.utf8().data(), pageNumber);
1763 String Internals::pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft, ExceptionState& exceptionState) const
1766 exceptionState.throwDOMException(InvalidAccessError, "No frame is available.");
1770 return PrintContext::pageSizeAndMarginsInPixels(frame(), pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft);
1773 void Internals::setDeviceScaleFactor(float scaleFactor, ExceptionState& exceptionState)
1775 Document* document = contextDocument();
1776 if (!document || !document->page()) {
1777 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's page cannot be retrieved." : "No context document can be obtained.");
1780 Page* page = document->page();
1781 page->setDeviceScaleFactor(scaleFactor);
1784 void Internals::setIsCursorVisible(Document* document, bool isVisible, ExceptionState& exceptionState)
1787 if (!document->page()) {
1788 exceptionState.throwDOMException(InvalidAccessError, "No context document can be obtained.");
1791 document->page()->setIsCursorVisible(isVisible);
1794 void Internals::mediaPlayerRequestFullscreen(HTMLMediaElement* mediaElement)
1796 mediaElement->mediaPlayerRequestFullscreen();
1799 double Internals::effectiveMediaVolume(HTMLMediaElement* mediaElement)
1801 return mediaElement->effectiveMediaVolume();
1804 void Internals::registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme)
1806 SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy(scheme);
1809 void Internals::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme)
1811 SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(scheme);
1814 PassRefPtrWillBeRawPtr<TypeConversions> Internals::typeConversions() const
1816 return TypeConversions::create();
1819 PrivateScriptTest* Internals::privateScriptTest() const
1821 return PrivateScriptTest::create(frame());
1824 Vector<String> Internals::getReferencedFilePaths() const
1826 return frame()->loader().currentItem()->getReferencedFilePaths();
1829 void Internals::startTrackingRepaints(Document* document, ExceptionState& exceptionState)
1832 if (!document->view()) {
1833 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1837 FrameView* frameView = document->view();
1838 frameView->updateLayoutAndStyleForPainting();
1839 frameView->setTracksPaintInvalidations(true);
1842 void Internals::stopTrackingRepaints(Document* document, ExceptionState& exceptionState)
1845 if (!document->view()) {
1846 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1850 FrameView* frameView = document->view();
1851 frameView->updateLayoutAndStyleForPainting();
1852 frameView->setTracksPaintInvalidations(false);
1855 void Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionState& exceptionState)
1857 updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(0, exceptionState);
1860 void Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node* node, ExceptionState& exceptionState)
1864 document = contextDocument();
1865 } else if (node->isDocumentNode()) {
1866 document = toDocument(node);
1867 } else if (isHTMLIFrameElement(*node)) {
1868 document = toHTMLIFrameElement(*node).contentDocument();
1870 exceptionState.throwTypeError("The node provided is neither a document nor an IFrame.");
1873 document->updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasksSynchronously);
1876 void Internals::forceFullRepaint(Document* document, ExceptionState& exceptionState)
1879 if (!document->view()) {
1880 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1884 if (RenderView *renderView = document->renderView())
1885 renderView->invalidatePaintForViewAndCompositedLayers();
1888 PassRefPtrWillBeRawPtr<ClientRectList> Internals::draggableRegions(Document* document, ExceptionState& exceptionState)
1890 return annotatedRegions(document, true, exceptionState);
1893 PassRefPtrWillBeRawPtr<ClientRectList> Internals::nonDraggableRegions(Document* document, ExceptionState& exceptionState)
1895 return annotatedRegions(document, false, exceptionState);
1898 PassRefPtrWillBeRawPtr<ClientRectList> Internals::annotatedRegions(Document* document, bool draggable, ExceptionState& exceptionState)
1901 if (!document->view()) {
1902 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1903 return ClientRectList::create();
1906 document->updateLayout();
1907 document->view()->updateAnnotatedRegions();
1908 Vector<AnnotatedRegionValue> regions = document->annotatedRegions();
1910 Vector<FloatQuad> quads;
1911 for (size_t i = 0; i < regions.size(); ++i) {
1912 if (regions[i].draggable == draggable)
1913 quads.append(FloatQuad(regions[i].bounds));
1915 return ClientRectList::create(quads);
1918 static const char* cursorTypeToString(Cursor::Type cursorType)
1920 switch (cursorType) {
1921 case Cursor::Pointer: return "Pointer";
1922 case Cursor::Cross: return "Cross";
1923 case Cursor::Hand: return "Hand";
1924 case Cursor::IBeam: return "IBeam";
1925 case Cursor::Wait: return "Wait";
1926 case Cursor::Help: return "Help";
1927 case Cursor::EastResize: return "EastResize";
1928 case Cursor::NorthResize: return "NorthResize";
1929 case Cursor::NorthEastResize: return "NorthEastResize";
1930 case Cursor::NorthWestResize: return "NorthWestResize";
1931 case Cursor::SouthResize: return "SouthResize";
1932 case Cursor::SouthEastResize: return "SouthEastResize";
1933 case Cursor::SouthWestResize: return "SouthWestResize";
1934 case Cursor::WestResize: return "WestResize";
1935 case Cursor::NorthSouthResize: return "NorthSouthResize";
1936 case Cursor::EastWestResize: return "EastWestResize";
1937 case Cursor::NorthEastSouthWestResize: return "NorthEastSouthWestResize";
1938 case Cursor::NorthWestSouthEastResize: return "NorthWestSouthEastResize";
1939 case Cursor::ColumnResize: return "ColumnResize";
1940 case Cursor::RowResize: return "RowResize";
1941 case Cursor::MiddlePanning: return "MiddlePanning";
1942 case Cursor::EastPanning: return "EastPanning";
1943 case Cursor::NorthPanning: return "NorthPanning";
1944 case Cursor::NorthEastPanning: return "NorthEastPanning";
1945 case Cursor::NorthWestPanning: return "NorthWestPanning";
1946 case Cursor::SouthPanning: return "SouthPanning";
1947 case Cursor::SouthEastPanning: return "SouthEastPanning";
1948 case Cursor::SouthWestPanning: return "SouthWestPanning";
1949 case Cursor::WestPanning: return "WestPanning";
1950 case Cursor::Move: return "Move";
1951 case Cursor::VerticalText: return "VerticalText";
1952 case Cursor::Cell: return "Cell";
1953 case Cursor::ContextMenu: return "ContextMenu";
1954 case Cursor::Alias: return "Alias";
1955 case Cursor::Progress: return "Progress";
1956 case Cursor::NoDrop: return "NoDrop";
1957 case Cursor::Copy: return "Copy";
1958 case Cursor::None: return "None";
1959 case Cursor::NotAllowed: return "NotAllowed";
1960 case Cursor::ZoomIn: return "ZoomIn";
1961 case Cursor::ZoomOut: return "ZoomOut";
1962 case Cursor::Grab: return "Grab";
1963 case Cursor::Grabbing: return "Grabbing";
1964 case Cursor::Custom: return "Custom";
1967 ASSERT_NOT_REACHED();
1971 String Internals::getCurrentCursorInfo(Document* document, ExceptionState& exceptionState)
1974 if (!document->frame()) {
1975 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1979 Cursor cursor = document->frame()->eventHandler().currentMouseCursor();
1981 StringBuilder result;
1982 result.append("type=");
1983 result.append(cursorTypeToString(cursor.type()));
1984 result.append(" hotSpot=");
1985 result.appendNumber(cursor.hotSpot().x());
1987 result.appendNumber(cursor.hotSpot().y());
1988 if (cursor.image()) {
1989 IntSize size = cursor.image()->size();
1990 result.append(" image=");
1991 result.appendNumber(size.width());
1993 result.appendNumber(size.height());
1995 if (cursor.imageScaleFactor() != 1) {
1996 result.append(" scale=");
1997 NumberToStringBuffer buffer;
1998 result.append(numberToFixedPrecisionString(cursor.imageScaleFactor(), 8, buffer, true));
2001 return result.toString();
2004 PassRefPtr<ArrayBuffer> Internals::serializeObject(PassRefPtr<SerializedScriptValue> value) const
2006 String stringValue = value->toWireString();
2007 RefPtr<ArrayBuffer> buffer = ArrayBuffer::createUninitialized(stringValue.length(), sizeof(UChar));
2008 stringValue.copyTo(static_cast<UChar*>(buffer->data()), 0, stringValue.length());
2009 return buffer.release();
2012 PassRefPtr<SerializedScriptValue> Internals::deserializeBuffer(PassRefPtr<ArrayBuffer> buffer) const
2014 String value(static_cast<const UChar*>(buffer->data()), buffer->byteLength() / sizeof(UChar));
2015 return SerializedScriptValue::createFromWire(value);
2018 void Internals::forceReload(bool endToEnd)
2020 frame()->loader().reload(endToEnd ? EndToEndReload : NormalReload);
2023 PassRefPtrWillBeRawPtr<ClientRect> Internals::selectionBounds(ExceptionState& exceptionState)
2025 Document* document = contextDocument();
2026 if (!document || !document->frame()) {
2027 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "No context document can be obtained.");
2031 return ClientRect::create(document->frame()->selection().bounds());
2034 String Internals::markerTextForListItem(Element* element)
2037 return blink::markerTextForListItem(element);
2040 String Internals::getImageSourceURL(Element* element)
2043 return element->imageSourceURL();
2046 String Internals::baseURL(Document* document)
2049 return document->baseURL().string();
2052 bool Internals::isSelectPopupVisible(Node* node)
2055 if (!isHTMLSelectElement(*node))
2058 HTMLSelectElement& select = toHTMLSelectElement(*node);
2060 RenderObject* renderer = select.renderer();
2061 if (!renderer || !renderer->isMenuList())
2064 RenderMenuList* menuList = toRenderMenuList(renderer);
2065 return menuList->popupIsVisible();
2068 bool Internals::selectPopupItemStyleIsRtl(Node* node, int itemIndex)
2070 if (!node || !isHTMLSelectElement(*node))
2073 HTMLSelectElement& select = toHTMLSelectElement(*node);
2075 RenderObject* renderer = select.renderer();
2076 if (!renderer || !renderer->isMenuList())
2079 RenderMenuList& menuList = toRenderMenuList(*renderer);
2080 PopupMenuStyle itemStyle = menuList.itemStyle(itemIndex);
2081 return itemStyle.textDirection() == RTL;
2084 int Internals::selectPopupItemStyleFontHeight(Node* node, int itemIndex)
2086 if (!node || !isHTMLSelectElement(*node))
2089 HTMLSelectElement& select = toHTMLSelectElement(*node);
2091 RenderObject* renderer = select.renderer();
2092 if (!renderer || !renderer->isMenuList())
2095 RenderMenuList& menuList = toRenderMenuList(*renderer);
2096 PopupMenuStyle itemStyle = menuList.itemStyle(itemIndex);
2097 return itemStyle.font().fontMetrics().height();
2100 bool Internals::loseSharedGraphicsContext3D()
2102 OwnPtr<blink::WebGraphicsContext3DProvider> sharedProvider = adoptPtr(blink::Platform::current()->createSharedOffscreenGraphicsContext3DProvider());
2103 if (!sharedProvider)
2105 blink::WebGraphicsContext3D* sharedContext = sharedProvider->context3d();
2106 sharedContext->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_EXT, GL_INNOCENT_CONTEXT_RESET_EXT);
2107 // To prevent tests that call loseSharedGraphicsContext3D from being
2108 // flaky, we call finish so that the context is guaranteed to be lost
2109 // synchronously (i.e. before returning).
2110 sharedContext->finish();
2114 void Internals::forceCompositingUpdate(Document* document, ExceptionState& exceptionState)
2117 if (!document->renderView()) {
2118 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
2122 document->frame()->view()->updateLayoutAndStyleForPainting();
2125 void Internals::setZoomFactor(float factor)
2127 frame()->setPageZoomFactor(factor);
2130 void Internals::setShouldRevealPassword(Element* element, bool reveal, ExceptionState& exceptionState)
2133 if (!isHTMLInputElement(element)) {
2134 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not an INPUT.");
2138 return toHTMLInputElement(*element).setShouldRevealPassword(reveal);
2143 class AddOneFunction : public ScriptFunction {
2145 static PassOwnPtr<ScriptFunction> create(ExecutionContext* context)
2147 return adoptPtr(new AddOneFunction(toIsolate(context)));
2151 AddOneFunction(v8::Isolate* isolate)
2152 : ScriptFunction(isolate)
2156 virtual ScriptValue call(ScriptValue value) OVERRIDE
2158 v8::Local<v8::Value> v8Value = value.v8Value();
2159 ASSERT(v8Value->IsNumber());
2160 int intValue = v8Value.As<v8::Integer>()->Value();
2161 ScriptValue result = ScriptValue(ScriptState::current(isolate()), v8::Integer::New(isolate(), intValue + 1));
2168 ScriptPromise Internals::createResolvedPromise(ScriptState* scriptState, ScriptValue value)
2170 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
2171 ScriptPromise promise = resolver->promise();
2172 resolver->resolve(value);
2176 ScriptPromise Internals::createRejectedPromise(ScriptState* scriptState, ScriptValue value)
2178 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
2179 ScriptPromise promise = resolver->promise();
2180 resolver->reject(value);
2184 ScriptPromise Internals::addOneToPromise(ScriptState* scriptState, ScriptPromise promise)
2186 return promise.then(AddOneFunction::create(scriptState->executionContext()));
2189 ScriptPromise Internals::promiseCheck(ScriptState* scriptState, long arg1, bool arg2, const Dictionary& arg3, const String& arg4, const Vector<String>& arg5, ExceptionState& exceptionState)
2192 return ScriptPromise::cast(scriptState, v8String(scriptState->isolate(), "done"));
2193 exceptionState.throwDOMException(InvalidStateError, "Thrown from the native implementation.");
2194 return ScriptPromise();
2197 ScriptPromise Internals::promiseCheckWithoutExceptionState(ScriptState* scriptState, const Dictionary& arg1, const String& arg2, const Vector<String>& arg3)
2199 return ScriptPromise::cast(scriptState, v8String(scriptState->isolate(), "done"));
2202 ScriptPromise Internals::promiseCheckRange(ScriptState* scriptState, long arg1)
2204 return ScriptPromise::cast(scriptState, v8String(scriptState->isolate(), "done"));
2207 void Internals::trace(Visitor* visitor)
2209 visitor->trace(m_runtimeFlags);
2210 visitor->trace(m_profilers);
2213 void Internals::setValueForUser(Element* element, const String& value)
2215 toHTMLInputElement(element)->setValueForUser(value);
2218 String Internals::textSurroundingNode(Node* node, int x, int y, unsigned long maxLength)
2222 blink::WebPoint point(x, y);
2223 SurroundingText surroundingText(VisiblePosition(node->renderer()->positionForPoint(static_cast<IntPoint>(point))).deepEquivalent().parentAnchoredEquivalent(), maxLength);
2224 return surroundingText.content();
2227 void Internals::setFocused(bool focused)
2229 frame()->page()->focusController().setFocused(focused);
2232 bool Internals::ignoreLayoutWithPendingStylesheets(Document* document)
2235 return document->ignoreLayoutWithPendingStylesheets();
2238 void Internals::setNetworkStateNotifierTestOnly(bool testOnly)
2240 networkStateNotifier().setTestUpdatesOnly(testOnly);
2243 void Internals::setNetworkConnectionInfo(const String& type, ExceptionState& exceptionState)
2245 blink::WebConnectionType webtype;
2246 if (type == "cellular") {
2247 webtype = blink::ConnectionTypeCellular;
2248 } else if (type == "bluetooth") {
2249 webtype = blink::ConnectionTypeBluetooth;
2250 } else if (type == "ethernet") {
2251 webtype = blink::ConnectionTypeEthernet;
2252 } else if (type == "wifi") {
2253 webtype = blink::ConnectionTypeWifi;
2254 } else if (type == "other") {
2255 webtype = blink::ConnectionTypeOther;
2256 } else if (type == "none") {
2257 webtype = blink::ConnectionTypeNone;
2258 } else if (type == "unknown") {
2259 webtype = blink::ConnectionTypeUnknown;
2261 exceptionState.throwDOMException(NotFoundError, ExceptionMessages::failedToEnumerate("connection type", type));
2264 networkStateNotifier().setWebConnectionTypeForTest(webtype);
2267 unsigned Internals::countHitRegions(CanvasRenderingContext2D* context)
2269 return context->hitRegionsCount();
2272 String Internals::serializeNavigationMarkup()
2274 Vector<Document::TransitionElementData> elementData;
2275 frame()->document()->getTransitionElementData(elementData);
2277 StringBuilder markup;
2278 Vector<Document::TransitionElementData>::iterator iter = elementData.begin();
2279 for (; iter != elementData.end(); ++iter)
2280 markup.append(iter->markup);
2282 return markup.toString();
2285 void Internals::hideAllTransitionElements()
2287 Vector<Document::TransitionElementData> elementData;
2288 frame()->document()->getTransitionElementData(elementData);
2290 Vector<Document::TransitionElementData>::iterator iter = elementData.begin();
2291 for (; iter != elementData.end(); ++iter)
2292 frame()->document()->hideTransitionElements(AtomicString(iter->selector));
2295 } // namespace blink