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 ShadowRoot* Internals::shadowRoot(Element* host)
574 // FIXME: Internals::shadowRoot() in tests should be converted to youngestShadowRoot() or oldestShadowRoot().
575 // https://bugs.webkit.org/show_bug.cgi?id=78465
576 return youngestShadowRoot(host);
579 ShadowRoot* Internals::youngestShadowRoot(Element* host)
582 if (ElementShadow* shadow = host->shadow())
583 return shadow->youngestShadowRoot();
587 ShadowRoot* Internals::oldestShadowRoot(Element* host)
590 if (ElementShadow* shadow = host->shadow())
591 return shadow->oldestShadowRoot();
595 ShadowRoot* Internals::youngerShadowRoot(Node* shadow, ExceptionState& exceptionState)
598 if (!shadow->isShadowRoot()) {
599 exceptionState.throwDOMException(InvalidAccessError, "The node provided is not a shadow root.");
603 return toShadowRoot(shadow)->youngerShadowRoot();
606 String Internals::shadowRootType(const Node* root, ExceptionState& exceptionState) const
609 if (!root->isShadowRoot()) {
610 exceptionState.throwDOMException(InvalidAccessError, "The node provided is not a shadow root.");
614 switch (toShadowRoot(root)->type()) {
615 case ShadowRoot::UserAgentShadowRoot:
616 return String("UserAgentShadowRoot");
617 case ShadowRoot::AuthorShadowRoot:
618 return String("AuthorShadowRoot");
620 ASSERT_NOT_REACHED();
621 return String("Unknown");
625 const AtomicString& Internals::shadowPseudoId(Element* element)
628 return element->shadowPseudoId();
631 void Internals::setShadowPseudoId(Element* element, const AtomicString& id)
634 return element->setShadowPseudoId(id);
637 String Internals::visiblePlaceholder(Element* element)
639 if (element && isHTMLTextFormControlElement(*element)) {
640 if (toHTMLTextFormControlElement(element)->placeholderShouldBeVisible())
641 return toHTMLTextFormControlElement(element)->placeholderElement()->textContent();
647 void Internals::selectColorInColorChooser(Element* element, const String& colorValue)
650 if (!isHTMLInputElement(*element))
653 if (!color.setFromString(colorValue))
655 toHTMLInputElement(*element).selectColorInColorChooser(color);
658 bool Internals::hasAutofocusRequest(Document* document)
661 document = contextDocument();
662 return document->autofocusElement();
665 bool Internals::hasAutofocusRequest()
667 return hasAutofocusRequest(0);
670 Vector<String> Internals::formControlStateOfHistoryItem(ExceptionState& exceptionState)
672 HistoryItem* mainItem = frame()->loader().currentItem();
674 exceptionState.throwDOMException(InvalidAccessError, "No history item is available.");
675 return Vector<String>();
677 return mainItem->documentState();
680 void Internals::setFormControlStateOfHistoryItem(const Vector<String>& state, ExceptionState& exceptionState)
682 HistoryItem* mainItem = frame()->loader().currentItem();
684 exceptionState.throwDOMException(InvalidAccessError, "No history item is available.");
687 mainItem->clearDocumentState();
688 mainItem->setDocumentState(state);
691 void Internals::setEnableMockPagePopup(bool enabled, ExceptionState& exceptionState)
693 Document* document = contextDocument();
694 if (!document || !document->page())
696 Page* page = document->page();
698 page->chrome().client().resetPagePopupDriver();
701 if (!s_pagePopupDriver)
702 s_pagePopupDriver = MockPagePopupDriver::create(page->deprecatedLocalMainFrame()).leakPtr();
703 page->chrome().client().setPagePopupDriver(s_pagePopupDriver);
706 PassRefPtrWillBeRawPtr<PagePopupController> Internals::pagePopupController()
708 return s_pagePopupDriver ? s_pagePopupDriver->pagePopupController() : 0;
711 PassRefPtrWillBeRawPtr<ClientRect> Internals::unscaledViewportRect(ExceptionState& exceptionState)
713 Document* document = contextDocument();
714 if (!document || !document->view()) {
715 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's viewport cannot be retrieved." : "No context document can be obtained.");
716 return ClientRect::create();
719 return ClientRect::create(document->view()->visibleContentRect());
722 PassRefPtrWillBeRawPtr<ClientRect> Internals::absoluteCaretBounds(ExceptionState& exceptionState)
724 Document* document = contextDocument();
725 if (!document || !document->frame()) {
726 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "No context document can be obtained.");
727 return ClientRect::create();
730 return ClientRect::create(document->frame()->selection().absoluteCaretBounds());
733 PassRefPtrWillBeRawPtr<ClientRect> Internals::boundingBox(Element* element)
737 element->document().updateLayoutIgnorePendingStylesheets();
738 RenderObject* renderer = element->renderer();
740 return ClientRect::create();
741 return ClientRect::create(renderer->absoluteBoundingBoxRectIgnoringTransforms());
744 unsigned Internals::markerCountForNode(Node* node, const String& markerType, ExceptionState& exceptionState)
747 DocumentMarker::MarkerTypes markerTypes = 0;
748 if (!markerTypesFrom(markerType, markerTypes)) {
749 exceptionState.throwDOMException(SyntaxError, "The marker type provided ('" + markerType + "') is invalid.");
753 return node->document().markers().markersFor(node, markerTypes).size();
756 unsigned Internals::activeMarkerCountForNode(Node* node)
760 // Only TextMatch markers can be active.
761 DocumentMarker::MarkerType markerType = DocumentMarker::TextMatch;
762 DocumentMarkerVector markers = node->document().markers().markersFor(node, markerType);
764 unsigned activeMarkerCount = 0;
765 for (DocumentMarkerVector::iterator iter = markers.begin(); iter != markers.end(); ++iter) {
766 if ((*iter)->activeMatch())
770 return activeMarkerCount;
773 DocumentMarker* Internals::markerAt(Node* node, const String& markerType, unsigned index, ExceptionState& exceptionState)
776 DocumentMarker::MarkerTypes markerTypes = 0;
777 if (!markerTypesFrom(markerType, markerTypes)) {
778 exceptionState.throwDOMException(SyntaxError, "The marker type provided ('" + markerType + "') is invalid.");
782 DocumentMarkerVector markers = node->document().markers().markersFor(node, markerTypes);
783 if (markers.size() <= index)
785 return markers[index];
788 PassRefPtrWillBeRawPtr<Range> Internals::markerRangeForNode(Node* node, const String& markerType, unsigned index, ExceptionState& exceptionState)
791 DocumentMarker* marker = markerAt(node, markerType, index, exceptionState);
794 return Range::create(node->document(), node, marker->startOffset(), node, marker->endOffset());
797 String Internals::markerDescriptionForNode(Node* node, const String& markerType, unsigned index, ExceptionState& exceptionState)
799 DocumentMarker* marker = markerAt(node, markerType, index, exceptionState);
802 return marker->description();
805 void Internals::addTextMatchMarker(const Range* range, bool isActive)
808 range->ownerDocument().updateLayoutIgnorePendingStylesheets();
809 range->ownerDocument().markers().addTextMatchMarker(range, isActive);
812 void Internals::setMarkersActive(Node* node, unsigned startOffset, unsigned endOffset, bool active)
815 node->document().markers().setMarkersActive(node, startOffset, endOffset, active);
818 void Internals::setMarkedTextMatchesAreHighlighted(Document* document, bool highlight)
820 if (!document || !document->frame())
823 document->frame()->editor().setMarkedTextMatchesAreHighlighted(highlight);
826 void Internals::setScrollViewPosition(Document* document, long x, long y, ExceptionState& exceptionState)
829 if (!document->view()) {
830 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
834 FrameView* frameView = document->view();
835 bool constrainsScrollingToContentEdgeOldValue = frameView->constrainsScrollingToContentEdge();
836 bool scrollbarsSuppressedOldValue = frameView->scrollbarsSuppressed();
838 frameView->setConstrainsScrollingToContentEdge(false);
839 frameView->setScrollbarsSuppressed(false);
840 frameView->setScrollOffsetFromInternals(IntPoint(x, y));
841 frameView->setScrollbarsSuppressed(scrollbarsSuppressedOldValue);
842 frameView->setConstrainsScrollingToContentEdge(constrainsScrollingToContentEdgeOldValue);
845 String Internals::viewportAsText(Document* document, float, int availableWidth, int availableHeight, ExceptionState& exceptionState)
848 if (!document->page()) {
849 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
853 document->updateLayoutIgnorePendingStylesheets();
855 Page* page = document->page();
857 // Update initial viewport size.
858 IntSize initialViewportSize(availableWidth, availableHeight);
859 document->page()->deprecatedLocalMainFrame()->view()->setFrameRect(IntRect(IntPoint::zero(), initialViewportSize));
861 ViewportDescription description = page->viewportDescription();
862 PageScaleConstraints constraints = description.resolve(initialViewportSize, Length());
864 constraints.fitToContentsWidth(constraints.layoutSize.width(), availableWidth);
866 StringBuilder builder;
868 builder.appendLiteral("viewport size ");
869 builder.append(String::number(constraints.layoutSize.width()));
871 builder.append(String::number(constraints.layoutSize.height()));
873 builder.appendLiteral(" scale ");
874 builder.append(String::number(constraints.initialScale));
875 builder.appendLiteral(" with limits [");
876 builder.append(String::number(constraints.minimumScale));
877 builder.appendLiteral(", ");
878 builder.append(String::number(constraints.maximumScale));
880 builder.appendLiteral("] and userScalable ");
881 builder.append(description.userZoom ? "true" : "false");
883 return builder.toString();
886 bool Internals::wasLastChangeUserEdit(Element* textField, ExceptionState& exceptionState)
889 if (isHTMLInputElement(*textField))
890 return toHTMLInputElement(*textField).lastChangeWasUserEdit();
892 if (isHTMLTextAreaElement(*textField))
893 return toHTMLTextAreaElement(*textField).lastChangeWasUserEdit();
895 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a TEXTAREA.");
899 bool Internals::elementShouldAutoComplete(Element* element, ExceptionState& exceptionState)
902 if (isHTMLInputElement(*element))
903 return toHTMLInputElement(*element).shouldAutocomplete();
905 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not an INPUT.");
909 String Internals::suggestedValue(Element* element, ExceptionState& exceptionState)
912 if (!element->isFormControlElement()) {
913 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a form control element.");
917 String suggestedValue;
918 if (isHTMLInputElement(*element))
919 suggestedValue = toHTMLInputElement(*element).suggestedValue();
921 if (isHTMLTextAreaElement(*element))
922 suggestedValue = toHTMLTextAreaElement(*element).suggestedValue();
924 if (isHTMLSelectElement(*element))
925 suggestedValue = toHTMLSelectElement(*element).suggestedValue();
927 return suggestedValue;
930 void Internals::setSuggestedValue(Element* element, const String& value, ExceptionState& exceptionState)
933 if (!element->isFormControlElement()) {
934 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a form control element.");
938 if (isHTMLInputElement(*element))
939 toHTMLInputElement(*element).setSuggestedValue(value);
941 if (isHTMLTextAreaElement(*element))
942 toHTMLTextAreaElement(*element).setSuggestedValue(value);
944 if (isHTMLSelectElement(*element))
945 toHTMLSelectElement(*element).setSuggestedValue(value);
948 void Internals::setEditingValue(Element* element, const String& value, ExceptionState& exceptionState)
951 if (!isHTMLInputElement(*element)) {
952 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not an INPUT.");
956 toHTMLInputElement(*element).setEditingValue(value);
959 void Internals::setAutofilled(Element* element, bool enabled, ExceptionState& exceptionState)
962 if (!element->isFormControlElement()) {
963 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a form control element.");
966 toHTMLFormControlElement(element)->setAutofilled(enabled);
969 void Internals::scrollElementToRect(Element* element, long x, long y, long w, long h, ExceptionState& exceptionState)
972 if (!element->document().view()) {
973 exceptionState.throwDOMException(InvalidNodeTypeError, element ? "No view can be obtained from the provided element's document." : ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
976 FrameView* frameView = element->document().view();
977 frameView->scrollElementToRect(element, IntRect(x, y, w, h));
980 PassRefPtrWillBeRawPtr<Range> Internals::rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength)
984 // TextIterator depends on Layout information, make sure layout it up to date.
985 scope->document().updateLayoutIgnorePendingStylesheets();
987 return PlainTextRange(rangeLocation, rangeLocation + rangeLength).createRange(*scope);
990 unsigned Internals::locationFromRange(Element* scope, const Range* range)
992 ASSERT(scope && range);
993 // PlainTextRange depends on Layout information, make sure layout it up to date.
994 scope->document().updateLayoutIgnorePendingStylesheets();
996 return PlainTextRange::create(*scope, *range).start();
999 unsigned Internals::lengthFromRange(Element* scope, const Range* range)
1001 ASSERT(scope && range);
1002 // PlainTextRange depends on Layout information, make sure layout it up to date.
1003 scope->document().updateLayoutIgnorePendingStylesheets();
1005 return PlainTextRange::create(*scope, *range).length();
1008 String Internals::rangeAsText(const Range* range)
1011 return range->text();
1014 // FIXME: The next four functions are very similar - combine them once
1015 // bestClickableNode/bestContextMenuNode have been combined..
1017 PassRefPtrWillBeRawPtr<WebKitPoint> Internals::touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1020 if (!document->frame()) {
1021 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1025 document->updateLayout();
1027 IntSize radius(width / 2, height / 2);
1028 IntPoint point(x + radius.width(), y + radius.height());
1030 EventHandler& eventHandler = document->frame()->eventHandler();
1031 IntPoint hitTestPoint = document->frame()->view()->windowToContents(point);
1032 HitTestResult result = eventHandler.hitTestResultAtPoint(hitTestPoint, HitTestRequest::ReadOnly | HitTestRequest::Active, radius);
1035 IntPoint adjustedPoint;
1037 bool foundNode = eventHandler.bestClickableNodeForHitTestResult(result, adjustedPoint, targetNode);
1039 return WebKitPoint::create(adjustedPoint.x(), adjustedPoint.y());
1044 Node* Internals::touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1047 if (!document->frame()) {
1048 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1052 document->updateLayout();
1054 IntSize radius(width / 2, height / 2);
1055 IntPoint point(x + radius.width(), y + radius.height());
1057 EventHandler& eventHandler = document->frame()->eventHandler();
1058 IntPoint hitTestPoint = document->frame()->view()->windowToContents(point);
1059 HitTestResult result = eventHandler.hitTestResultAtPoint(hitTestPoint, HitTestRequest::ReadOnly | HitTestRequest::Active, radius);
1062 IntPoint adjustedPoint;
1063 document->frame()->eventHandler().bestClickableNodeForHitTestResult(result, adjustedPoint, targetNode);
1067 PassRefPtrWillBeRawPtr<WebKitPoint> Internals::touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1070 if (!document->frame()) {
1071 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1075 document->updateLayout();
1077 IntSize radius(width / 2, height / 2);
1078 IntPoint point(x + radius.width(), y + radius.height());
1080 EventHandler& eventHandler = document->frame()->eventHandler();
1081 IntPoint hitTestPoint = document->frame()->view()->windowToContents(point);
1082 HitTestResult result = eventHandler.hitTestResultAtPoint(hitTestPoint, HitTestRequest::ReadOnly | HitTestRequest::Active, radius);
1084 Node* targetNode = 0;
1085 IntPoint adjustedPoint;
1087 bool foundNode = eventHandler.bestContextMenuNodeForHitTestResult(result, adjustedPoint, targetNode);
1089 return WebKitPoint::create(adjustedPoint.x(), adjustedPoint.y());
1091 return WebKitPoint::create(x, y);
1094 Node* Internals::touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1097 if (!document->frame()) {
1098 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1102 document->updateLayout();
1104 IntSize radius(width / 2, height / 2);
1105 IntPoint point(x + radius.width(), y + radius.height());
1107 EventHandler& eventHandler = document->frame()->eventHandler();
1108 IntPoint hitTestPoint = document->frame()->view()->windowToContents(point);
1109 HitTestResult result = eventHandler.hitTestResultAtPoint(hitTestPoint, HitTestRequest::ReadOnly | HitTestRequest::Active, radius);
1111 Node* targetNode = 0;
1112 IntPoint adjustedPoint;
1113 eventHandler.bestContextMenuNodeForHitTestResult(result, adjustedPoint, targetNode);
1117 PassRefPtrWillBeRawPtr<ClientRect> Internals::bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1120 if (!document->frame()) {
1121 exceptionState.throwDOMException(InvalidAccessError, "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 IntRect zoomableArea;
1132 bool foundNode = document->frame()->eventHandler().bestZoomableAreaForTouchPoint(point, radius, zoomableArea, targetNode);
1134 return ClientRect::create(zoomableArea);
1140 int Internals::lastSpellCheckRequestSequence(Document* document, ExceptionState& exceptionState)
1142 SpellCheckRequester* requester = spellCheckRequester(document);
1145 exceptionState.throwDOMException(InvalidAccessError, "No spell check requestor can be obtained for the provided document.");
1149 return requester->lastRequestSequence();
1152 int Internals::lastSpellCheckProcessedSequence(Document* document, ExceptionState& exceptionState)
1154 SpellCheckRequester* requester = spellCheckRequester(document);
1157 exceptionState.throwDOMException(InvalidAccessError, "No spell check requestor can be obtained for the provided document.");
1161 return requester->lastProcessedSequence();
1164 Vector<AtomicString> Internals::userPreferredLanguages() const
1166 return blink::userPreferredLanguages();
1169 // Optimally, the bindings generator would pass a Vector<AtomicString> here but
1170 // this is not supported yet.
1171 void Internals::setUserPreferredLanguages(const Vector<String>& languages)
1173 Vector<AtomicString> atomicLanguages;
1174 for (size_t i = 0; i < languages.size(); ++i)
1175 atomicLanguages.append(AtomicString(languages[i]));
1176 blink::overrideUserPreferredLanguages(atomicLanguages);
1179 unsigned Internals::activeDOMObjectCount(Document* document)
1182 return document->activeDOMObjectCount();
1185 static unsigned eventHandlerCount(Document& document, EventHandlerRegistry::EventHandlerClass handlerClass)
1187 if (!document.frameHost())
1189 EventHandlerRegistry* registry = &document.frameHost()->eventHandlerRegistry();
1191 const EventTargetSet* targets = registry->eventHandlerTargets(handlerClass);
1193 for (EventTargetSet::const_iterator iter = targets->begin(); iter != targets->end(); ++iter)
1194 count += iter->value;
1199 unsigned Internals::wheelEventHandlerCount(Document* document)
1202 return eventHandlerCount(*document, EventHandlerRegistry::WheelEvent);
1205 unsigned Internals::scrollEventHandlerCount(Document* document)
1208 return eventHandlerCount(*document, EventHandlerRegistry::ScrollEvent);
1211 unsigned Internals::touchEventHandlerCount(Document* document)
1214 return eventHandlerCount(*document, EventHandlerRegistry::TouchEvent);
1217 static RenderLayer* findRenderLayerForGraphicsLayer(RenderLayer* searchRoot, GraphicsLayer* graphicsLayer, IntSize* layerOffset, String* layerType)
1219 *layerOffset = IntSize();
1220 if (searchRoot->hasCompositedLayerMapping() && graphicsLayer == searchRoot->compositedLayerMapping()->mainGraphicsLayer()) {
1222 RenderLayer::mapRectToPaintBackingCoordinates(searchRoot->renderer(), rect);
1223 *layerOffset = IntSize(rect.x(), rect.y());
1227 GraphicsLayer* layerForScrolling = searchRoot->scrollableArea() ? searchRoot->scrollableArea()->layerForScrolling() : 0;
1228 if (graphicsLayer == layerForScrolling) {
1229 *layerType = "scrolling";
1233 if (searchRoot->compositingState() == PaintsIntoGroupedBacking) {
1234 GraphicsLayer* squashingLayer = searchRoot->groupedMapping()->squashingLayer();
1235 if (graphicsLayer == squashingLayer) {
1236 *layerType ="squashing";
1238 RenderLayer::mapRectToPaintBackingCoordinates(searchRoot->renderer(), rect);
1239 *layerOffset = IntSize(rect.x(), rect.y());
1244 GraphicsLayer* layerForHorizontalScrollbar = searchRoot->scrollableArea() ? searchRoot->scrollableArea()->layerForHorizontalScrollbar() : 0;
1245 if (graphicsLayer == layerForHorizontalScrollbar) {
1246 *layerType = "horizontalScrollbar";
1250 GraphicsLayer* layerForVerticalScrollbar = searchRoot->scrollableArea() ? searchRoot->scrollableArea()->layerForVerticalScrollbar() : 0;
1251 if (graphicsLayer == layerForVerticalScrollbar) {
1252 *layerType = "verticalScrollbar";
1256 GraphicsLayer* layerForScrollCorner = searchRoot->scrollableArea() ? searchRoot->scrollableArea()->layerForScrollCorner() : 0;
1257 if (graphicsLayer == layerForScrollCorner) {
1258 *layerType = "scrollCorner";
1262 // Search right to left to increase the chances that we'll choose the top-most layers in a
1263 // grouped mapping for squashing.
1264 for (RenderLayer* child = searchRoot->lastChild(); child; child = child->previousSibling()) {
1265 RenderLayer* foundLayer = findRenderLayerForGraphicsLayer(child, graphicsLayer, layerOffset, layerType);
1273 // Given a vector of rects, merge those that are adjacent, leaving empty rects
1274 // in the place of no longer used slots. This is intended to simplify the list
1275 // of rects returned by an SkRegion (which have been split apart for sorting
1276 // purposes). No attempt is made to do this efficiently (eg. by relying on the
1277 // sort criteria of SkRegion).
1278 static void mergeRects(blink::WebVector<blink::WebRect>& rects)
1280 for (size_t i = 0; i < rects.size(); ++i) {
1281 if (rects[i].isEmpty())
1286 for (size_t j = i+1; j < rects.size(); ++j) {
1287 if (rects[j].isEmpty())
1289 // Try to merge rects[j] into rects[i] along the 4 possible edges.
1290 if (rects[i].y == rects[j].y && rects[i].height == rects[j].height) {
1291 if (rects[i].x + rects[i].width == rects[j].x) {
1292 rects[i].width += rects[j].width;
1293 rects[j] = blink::WebRect();
1295 } else if (rects[i].x == rects[j].x + rects[j].width) {
1296 rects[i].x = rects[j].x;
1297 rects[i].width += rects[j].width;
1298 rects[j] = blink::WebRect();
1301 } else if (rects[i].x == rects[j].x && rects[i].width == rects[j].width) {
1302 if (rects[i].y + rects[i].height == rects[j].y) {
1303 rects[i].height += rects[j].height;
1304 rects[j] = blink::WebRect();
1306 } else if (rects[i].y == rects[j].y + rects[j].height) {
1307 rects[i].y = rects[j].y;
1308 rects[i].height += rects[j].height;
1309 rects[j] = blink::WebRect();
1318 static void accumulateLayerRectList(RenderLayerCompositor* compositor, GraphicsLayer* graphicsLayer, LayerRectList* rects)
1320 blink::WebVector<blink::WebRect> layerRects = graphicsLayer->platformLayer()->touchEventHandlerRegion();
1321 if (!layerRects.isEmpty()) {
1322 mergeRects(layerRects);
1324 IntSize layerOffset;
1325 RenderLayer* renderLayer = findRenderLayerForGraphicsLayer(compositor->rootRenderLayer(), graphicsLayer, &layerOffset, &layerType);
1326 Node* node = renderLayer ? renderLayer->renderer()->node() : 0;
1327 for (size_t i = 0; i < layerRects.size(); ++i) {
1328 if (!layerRects[i].isEmpty()) {
1329 rects->append(node, layerType, layerOffset.width(), layerOffset.height(), ClientRect::create(layerRects[i]));
1334 size_t numChildren = graphicsLayer->children().size();
1335 for (size_t i = 0; i < numChildren; ++i)
1336 accumulateLayerRectList(compositor, graphicsLayer->children()[i], rects);
1339 PassRefPtrWillBeRawPtr<LayerRectList> Internals::touchEventTargetLayerRects(Document* document, ExceptionState& exceptionState)
1342 if (!document->view() || !document->page() || document != contextDocument()) {
1343 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1347 // Do any pending layout and compositing update (which may call touchEventTargetRectsChange) to ensure this
1348 // really takes any previous changes into account.
1349 forceCompositingUpdate(document, exceptionState);
1350 if (exceptionState.hadException())
1353 if (RenderView* view = document->renderView()) {
1354 if (RenderLayerCompositor* compositor = view->compositor()) {
1355 if (GraphicsLayer* rootLayer = compositor->rootGraphicsLayer()) {
1356 RefPtrWillBeRawPtr<LayerRectList> rects = LayerRectList::create();
1357 accumulateLayerRectList(compositor, rootLayer, rects.get());
1366 PassRefPtrWillBeRawPtr<StaticNodeList> Internals::nodesFromRect(Document* document, int centerX, int centerY, unsigned topPadding, unsigned rightPadding,
1367 unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowChildFrameContent, ExceptionState& exceptionState) const
1370 if (!document->frame() || !document->frame()->view()) {
1371 exceptionState.throwDOMException(InvalidAccessError, "No view can be obtained from the provided document.");
1375 LocalFrame* frame = document->frame();
1376 FrameView* frameView = document->view();
1377 RenderView* renderView = document->renderView();
1382 float zoomFactor = frame->pageZoomFactor();
1383 LayoutPoint point = roundedLayoutPoint(FloatPoint(centerX * zoomFactor + frameView->scrollX(), centerY * zoomFactor + frameView->scrollY()));
1385 HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly | HitTestRequest::Active;
1387 hitType |= HitTestRequest::IgnoreClipping;
1388 if (allowChildFrameContent)
1389 hitType |= HitTestRequest::AllowChildFrameContent;
1391 HitTestRequest request(hitType);
1393 // When ignoreClipping is false, this method returns null for coordinates outside of the viewport.
1394 if (!request.ignoreClipping() && !frameView->visibleContentRect().intersects(HitTestLocation::rectForPoint(point, topPadding, rightPadding, bottomPadding, leftPadding)))
1397 WillBeHeapVector<RefPtrWillBeMember<Node> > matches;
1399 // Need padding to trigger a rect based hit test, but we want to return a NodeList
1400 // so we special case this.
1401 if (!topPadding && !rightPadding && !bottomPadding && !leftPadding) {
1402 HitTestResult result(point);
1403 renderView->hitTest(request, result);
1405 if (Node* innerNode = result.innerNode()) {
1406 if (innerNode->isInShadowTree())
1407 innerNode = innerNode->shadowHost();
1408 matches.append(innerNode);
1411 HitTestResult result(point, topPadding, rightPadding, bottomPadding, leftPadding);
1412 renderView->hitTest(request, result);
1413 copyToVector(result.rectBasedTestResult(), matches);
1416 return StaticNodeList::adopt(matches);
1419 void Internals::emitInspectorDidBeginFrame(int frameId)
1421 contextDocument()->page()->inspectorController().didBeginFrame(frameId);
1424 void Internals::emitInspectorDidCancelFrame()
1426 contextDocument()->page()->inspectorController().didCancelFrame();
1429 bool Internals::hasSpellingMarker(Document* document, int from, int length)
1432 if (!document->frame())
1435 return document->frame()->spellChecker().selectionStartHasMarkerFor(DocumentMarker::Spelling, from, length);
1438 void Internals::setContinuousSpellCheckingEnabled(bool enabled)
1440 if (!contextDocument() || !contextDocument()->frame())
1443 if (enabled != contextDocument()->frame()->spellChecker().isContinuousSpellCheckingEnabled())
1444 contextDocument()->frame()->spellChecker().toggleContinuousSpellChecking();
1447 bool Internals::isOverwriteModeEnabled(Document* document)
1450 if (!document->frame())
1453 return document->frame()->editor().isOverwriteModeEnabled();
1456 void Internals::toggleOverwriteModeEnabled(Document* document)
1459 if (!document->frame())
1462 document->frame()->editor().toggleOverwriteModeEnabled();
1465 unsigned Internals::numberOfLiveNodes() const
1467 return InspectorCounters::counterValue(InspectorCounters::NodeCounter);
1470 unsigned Internals::numberOfLiveDocuments() const
1472 return InspectorCounters::counterValue(InspectorCounters::DocumentCounter);
1475 String Internals::dumpRefCountedInstanceCounts() const
1477 return WTF::dumpRefCountedInstanceCounts();
1480 Vector<String> Internals::consoleMessageArgumentCounts(Document* document) const
1482 InstrumentingAgents* instrumentingAgents = instrumentationForPage(document->page());
1483 if (!instrumentingAgents)
1484 return Vector<String>();
1485 InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent();
1487 return Vector<String>();
1488 Vector<unsigned> counts = consoleAgent->consoleMessageArgumentCounts();
1489 Vector<String> result(counts.size());
1490 for (size_t i = 0; i < counts.size(); i++)
1491 result[i] = String::number(counts[i]);
1495 Vector<unsigned long> Internals::setMemoryCacheCapacities(unsigned long minDeadBytes, unsigned long maxDeadBytes, unsigned long totalBytes)
1497 Vector<unsigned long> result;
1498 result.append(memoryCache()->minDeadCapacity());
1499 result.append(memoryCache()->maxDeadCapacity());
1500 result.append(memoryCache()->capacity());
1501 memoryCache()->setCapacities(minDeadBytes, maxDeadBytes, totalBytes);
1505 void Internals::setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionState& exceptionState)
1507 Page* page = contextDocument()->frame()->page();
1509 exceptionState.throwDOMException(InvalidAccessError, "No page can be obtained from the current context document.");
1512 page->inspectorController().setResourcesDataSizeLimitsFromInternals(maximumResourcesContentSize, maximumSingleResourceContentSize);
1515 bool Internals::hasGrammarMarker(Document* document, int from, int length)
1518 if (!document->frame())
1521 return document->frame()->spellChecker().selectionStartHasMarkerFor(DocumentMarker::Grammar, from, length);
1524 unsigned Internals::numberOfScrollableAreas(Document* document)
1527 if (!document->frame())
1531 LocalFrame* frame = document->frame();
1532 if (frame->view()->scrollableAreas())
1533 count += frame->view()->scrollableAreas()->size();
1535 for (Frame* child = frame->tree().firstChild(); child; child = child->tree().nextSibling()) {
1536 if (child->isLocalFrame() && toLocalFrame(child)->view() && toLocalFrame(child)->view()->scrollableAreas())
1537 count += toLocalFrame(child)->view()->scrollableAreas()->size();
1543 bool Internals::isPageBoxVisible(Document* document, int pageNumber)
1546 return document->isPageBoxVisible(pageNumber);
1549 String Internals::layerTreeAsText(Document* document, ExceptionState& exceptionState) const
1551 return layerTreeAsText(document, 0, exceptionState);
1554 String Internals::elementLayerTreeAsText(Element* element, ExceptionState& exceptionState) const
1557 FrameView* frameView = element->document().view();
1558 frameView->updateLayoutAndStyleForPainting();
1560 return elementLayerTreeAsText(element, 0, exceptionState);
1563 bool Internals::scrollsWithRespectTo(Element* element1, Element* element2, ExceptionState& exceptionState)
1565 ASSERT(element1 && element2);
1566 element1->document().view()->updateLayoutAndStyleForPainting();
1568 RenderObject* renderer1 = element1->renderer();
1569 RenderObject* renderer2 = element2->renderer();
1570 if (!renderer1 || !renderer1->isBox()) {
1571 exceptionState.throwDOMException(InvalidAccessError, renderer1 ? "The first provided element's renderer is not a box." : "The first provided element has no renderer.");
1574 if (!renderer2 || !renderer2->isBox()) {
1575 exceptionState.throwDOMException(InvalidAccessError, renderer2 ? "The second provided element's renderer is not a box." : "The second provided element has no renderer.");
1579 RenderLayer* layer1 = toRenderBox(renderer1)->layer();
1580 RenderLayer* layer2 = toRenderBox(renderer2)->layer();
1581 if (!layer1 || !layer2) {
1582 exceptionState.throwDOMException(InvalidAccessError, String::format("No render layer can be obtained from the %s provided element.", layer1 ? "second" : "first"));
1586 return layer1->scrollsWithRespectTo(layer2);
1589 bool Internals::isUnclippedDescendant(Element* element, ExceptionState& exceptionState)
1592 element->document().view()->updateLayoutAndStyleForPainting();
1594 RenderObject* renderer = element->renderer();
1595 if (!renderer || !renderer->isBox()) {
1596 exceptionState.throwDOMException(InvalidAccessError, renderer ? "The provided element's renderer is not a box." : "The provided element has no renderer.");
1600 RenderLayer* layer = toRenderBox(renderer)->layer();
1602 exceptionState.throwDOMException(InvalidAccessError, "No render layer can be obtained from the provided element.");
1606 // We used to compute isUnclippedDescendant only when acceleratedCompositingForOverflowScrollEnabled,
1607 // but now we compute it all the time.
1608 // FIXME: Remove this if statement and rebaseline the tests that make this assumption.
1609 if (!layer->compositor()->acceleratedCompositingForOverflowScrollEnabled())
1612 return layer->isUnclippedDescendant();
1615 String Internals::layerTreeAsText(Document* document, unsigned flags, ExceptionState& exceptionState) const
1618 if (!document->frame()) {
1619 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1623 document->view()->updateLayoutAndStyleForPainting();
1625 return document->frame()->layerTreeAsText(flags);
1628 String Internals::elementLayerTreeAsText(Element* element, unsigned flags, ExceptionState& exceptionState) const
1631 element->document().updateLayout();
1633 RenderObject* renderer = element->renderer();
1634 if (!renderer || !renderer->isBox()) {
1635 exceptionState.throwDOMException(InvalidAccessError, renderer ? "The provided element's renderer is not a box." : "The provided element has no renderer.");
1639 RenderLayer* layer = toRenderBox(renderer)->layer();
1641 || !layer->hasCompositedLayerMapping()
1642 || !layer->compositedLayerMapping()->mainGraphicsLayer()) {
1643 // Don't raise exception in these cases which may be normally used in tests.
1647 return layer->compositedLayerMapping()->mainGraphicsLayer()->layerTreeAsText(flags);
1650 String Internals::scrollingStateTreeAsText(Document*) const
1655 String Internals::mainThreadScrollingReasons(Document* document, ExceptionState& exceptionState) const
1658 if (!document->frame()) {
1659 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1663 document->frame()->view()->updateLayoutAndStyleForPainting();
1665 Page* page = document->page();
1669 return page->mainThreadScrollingReasonsAsText();
1672 PassRefPtrWillBeRawPtr<ClientRectList> Internals::nonFastScrollableRects(Document* document, ExceptionState& exceptionState) const
1675 if (!document->frame()) {
1676 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1680 Page* page = document->page();
1684 return page->nonFastScrollableRects(document->frame());
1687 void Internals::garbageCollectDocumentResources(Document* document) const
1690 ResourceFetcher* fetcher = document->fetcher();
1693 fetcher->garbageCollectDocumentResources();
1696 void Internals::evictAllResources() const
1698 memoryCache()->evictResources();
1701 String Internals::counterValue(Element* element)
1706 return counterValueForElement(element);
1709 int Internals::pageNumber(Element* element, float pageWidth, float pageHeight)
1714 return PrintContext::pageNumberForElement(element, FloatSize(pageWidth, pageHeight));
1717 Vector<String> Internals::iconURLs(Document* document, int iconTypesMask) const
1719 Vector<IconURL> iconURLs = document->iconURLs(iconTypesMask);
1720 Vector<String> array;
1722 Vector<IconURL>::const_iterator iter(iconURLs.begin());
1723 for (; iter != iconURLs.end(); ++iter)
1724 array.append(iter->m_iconURL.string());
1729 Vector<String> Internals::shortcutIconURLs(Document* document) const
1731 return iconURLs(document, Favicon);
1734 Vector<String> Internals::allIconURLs(Document* document) const
1736 return iconURLs(document, Favicon | TouchIcon | TouchPrecomposedIcon);
1739 int Internals::numberOfPages(float pageWidth, float pageHeight)
1744 return PrintContext::numberOfPages(frame(), FloatSize(pageWidth, pageHeight));
1747 String Internals::pageProperty(String propertyName, int pageNumber, ExceptionState& exceptionState) const
1750 exceptionState.throwDOMException(InvalidAccessError, "No frame is available.");
1754 return PrintContext::pageProperty(frame(), propertyName.utf8().data(), pageNumber);
1757 String Internals::pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft, ExceptionState& exceptionState) const
1760 exceptionState.throwDOMException(InvalidAccessError, "No frame is available.");
1764 return PrintContext::pageSizeAndMarginsInPixels(frame(), pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft);
1767 void Internals::setDeviceScaleFactor(float scaleFactor, ExceptionState& exceptionState)
1769 Document* document = contextDocument();
1770 if (!document || !document->page()) {
1771 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's page cannot be retrieved." : "No context document can be obtained.");
1774 Page* page = document->page();
1775 page->setDeviceScaleFactor(scaleFactor);
1778 void Internals::setIsCursorVisible(Document* document, bool isVisible, ExceptionState& exceptionState)
1781 if (!document->page()) {
1782 exceptionState.throwDOMException(InvalidAccessError, "No context document can be obtained.");
1785 document->page()->setIsCursorVisible(isVisible);
1788 void Internals::mediaPlayerRequestFullscreen(HTMLMediaElement* mediaElement)
1790 mediaElement->mediaPlayerRequestFullscreen();
1793 double Internals::effectiveMediaVolume(HTMLMediaElement* mediaElement)
1795 return mediaElement->effectiveMediaVolume();
1798 void Internals::registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme)
1800 SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy(scheme);
1803 void Internals::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme)
1805 SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(scheme);
1808 PassRefPtrWillBeRawPtr<TypeConversions> Internals::typeConversions() const
1810 return TypeConversions::create();
1813 PrivateScriptTest* Internals::privateScriptTest() const
1815 return PrivateScriptTest::create(frame());
1818 Vector<String> Internals::getReferencedFilePaths() const
1820 return frame()->loader().currentItem()->getReferencedFilePaths();
1823 void Internals::startTrackingRepaints(Document* document, ExceptionState& exceptionState)
1826 if (!document->view()) {
1827 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1831 FrameView* frameView = document->view();
1832 frameView->updateLayoutAndStyleForPainting();
1833 frameView->setTracksPaintInvalidations(true);
1836 void Internals::stopTrackingRepaints(Document* document, ExceptionState& exceptionState)
1839 if (!document->view()) {
1840 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1844 FrameView* frameView = document->view();
1845 frameView->updateLayoutAndStyleForPainting();
1846 frameView->setTracksPaintInvalidations(false);
1849 void Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionState& exceptionState)
1851 updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(0, exceptionState);
1854 void Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node* node, ExceptionState& exceptionState)
1858 document = contextDocument();
1859 } else if (node->isDocumentNode()) {
1860 document = toDocument(node);
1861 } else if (isHTMLIFrameElement(*node)) {
1862 document = toHTMLIFrameElement(*node).contentDocument();
1864 exceptionState.throwTypeError("The node provided is neither a document nor an IFrame.");
1867 document->updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasksSynchronously);
1870 void Internals::forceFullRepaint(Document* document, ExceptionState& exceptionState)
1873 if (!document->view()) {
1874 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1878 if (RenderView *renderView = document->renderView())
1879 renderView->invalidatePaintForViewAndCompositedLayers();
1882 PassRefPtrWillBeRawPtr<ClientRectList> Internals::draggableRegions(Document* document, ExceptionState& exceptionState)
1884 return annotatedRegions(document, true, exceptionState);
1887 PassRefPtrWillBeRawPtr<ClientRectList> Internals::nonDraggableRegions(Document* document, ExceptionState& exceptionState)
1889 return annotatedRegions(document, false, exceptionState);
1892 PassRefPtrWillBeRawPtr<ClientRectList> Internals::annotatedRegions(Document* document, bool draggable, ExceptionState& exceptionState)
1895 if (!document->view()) {
1896 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1897 return ClientRectList::create();
1900 document->updateLayout();
1901 document->view()->updateAnnotatedRegions();
1902 Vector<AnnotatedRegionValue> regions = document->annotatedRegions();
1904 Vector<FloatQuad> quads;
1905 for (size_t i = 0; i < regions.size(); ++i) {
1906 if (regions[i].draggable == draggable)
1907 quads.append(FloatQuad(regions[i].bounds));
1909 return ClientRectList::create(quads);
1912 static const char* cursorTypeToString(Cursor::Type cursorType)
1914 switch (cursorType) {
1915 case Cursor::Pointer: return "Pointer";
1916 case Cursor::Cross: return "Cross";
1917 case Cursor::Hand: return "Hand";
1918 case Cursor::IBeam: return "IBeam";
1919 case Cursor::Wait: return "Wait";
1920 case Cursor::Help: return "Help";
1921 case Cursor::EastResize: return "EastResize";
1922 case Cursor::NorthResize: return "NorthResize";
1923 case Cursor::NorthEastResize: return "NorthEastResize";
1924 case Cursor::NorthWestResize: return "NorthWestResize";
1925 case Cursor::SouthResize: return "SouthResize";
1926 case Cursor::SouthEastResize: return "SouthEastResize";
1927 case Cursor::SouthWestResize: return "SouthWestResize";
1928 case Cursor::WestResize: return "WestResize";
1929 case Cursor::NorthSouthResize: return "NorthSouthResize";
1930 case Cursor::EastWestResize: return "EastWestResize";
1931 case Cursor::NorthEastSouthWestResize: return "NorthEastSouthWestResize";
1932 case Cursor::NorthWestSouthEastResize: return "NorthWestSouthEastResize";
1933 case Cursor::ColumnResize: return "ColumnResize";
1934 case Cursor::RowResize: return "RowResize";
1935 case Cursor::MiddlePanning: return "MiddlePanning";
1936 case Cursor::EastPanning: return "EastPanning";
1937 case Cursor::NorthPanning: return "NorthPanning";
1938 case Cursor::NorthEastPanning: return "NorthEastPanning";
1939 case Cursor::NorthWestPanning: return "NorthWestPanning";
1940 case Cursor::SouthPanning: return "SouthPanning";
1941 case Cursor::SouthEastPanning: return "SouthEastPanning";
1942 case Cursor::SouthWestPanning: return "SouthWestPanning";
1943 case Cursor::WestPanning: return "WestPanning";
1944 case Cursor::Move: return "Move";
1945 case Cursor::VerticalText: return "VerticalText";
1946 case Cursor::Cell: return "Cell";
1947 case Cursor::ContextMenu: return "ContextMenu";
1948 case Cursor::Alias: return "Alias";
1949 case Cursor::Progress: return "Progress";
1950 case Cursor::NoDrop: return "NoDrop";
1951 case Cursor::Copy: return "Copy";
1952 case Cursor::None: return "None";
1953 case Cursor::NotAllowed: return "NotAllowed";
1954 case Cursor::ZoomIn: return "ZoomIn";
1955 case Cursor::ZoomOut: return "ZoomOut";
1956 case Cursor::Grab: return "Grab";
1957 case Cursor::Grabbing: return "Grabbing";
1958 case Cursor::Custom: return "Custom";
1961 ASSERT_NOT_REACHED();
1965 String Internals::getCurrentCursorInfo(Document* document, ExceptionState& exceptionState)
1968 if (!document->frame()) {
1969 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1973 Cursor cursor = document->frame()->eventHandler().currentMouseCursor();
1975 StringBuilder result;
1976 result.append("type=");
1977 result.append(cursorTypeToString(cursor.type()));
1978 result.append(" hotSpot=");
1979 result.appendNumber(cursor.hotSpot().x());
1981 result.appendNumber(cursor.hotSpot().y());
1982 if (cursor.image()) {
1983 IntSize size = cursor.image()->size();
1984 result.append(" image=");
1985 result.appendNumber(size.width());
1987 result.appendNumber(size.height());
1989 if (cursor.imageScaleFactor() != 1) {
1990 result.append(" scale=");
1991 NumberToStringBuffer buffer;
1992 result.append(numberToFixedPrecisionString(cursor.imageScaleFactor(), 8, buffer, true));
1995 return result.toString();
1998 PassRefPtr<ArrayBuffer> Internals::serializeObject(PassRefPtr<SerializedScriptValue> value) const
2000 String stringValue = value->toWireString();
2001 RefPtr<ArrayBuffer> buffer = ArrayBuffer::createUninitialized(stringValue.length(), sizeof(UChar));
2002 stringValue.copyTo(static_cast<UChar*>(buffer->data()), 0, stringValue.length());
2003 return buffer.release();
2006 PassRefPtr<SerializedScriptValue> Internals::deserializeBuffer(PassRefPtr<ArrayBuffer> buffer) const
2008 String value(static_cast<const UChar*>(buffer->data()), buffer->byteLength() / sizeof(UChar));
2009 return SerializedScriptValue::createFromWire(value);
2012 void Internals::forceReload(bool endToEnd)
2014 frame()->loader().reload(endToEnd ? EndToEndReload : NormalReload);
2017 PassRefPtrWillBeRawPtr<ClientRect> Internals::selectionBounds(ExceptionState& exceptionState)
2019 Document* document = contextDocument();
2020 if (!document || !document->frame()) {
2021 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "No context document can be obtained.");
2025 return ClientRect::create(document->frame()->selection().bounds());
2028 String Internals::markerTextForListItem(Element* element)
2031 return blink::markerTextForListItem(element);
2034 String Internals::getImageSourceURL(Element* element)
2037 return element->imageSourceURL();
2040 String Internals::baseURL(Document* document)
2043 return document->baseURL().string();
2046 bool Internals::isSelectPopupVisible(Node* node)
2049 if (!isHTMLSelectElement(*node))
2052 HTMLSelectElement& select = toHTMLSelectElement(*node);
2054 RenderObject* renderer = select.renderer();
2055 if (!renderer || !renderer->isMenuList())
2058 RenderMenuList* menuList = toRenderMenuList(renderer);
2059 return menuList->popupIsVisible();
2062 bool Internals::selectPopupItemStyleIsRtl(Node* node, int itemIndex)
2064 if (!node || !isHTMLSelectElement(*node))
2067 HTMLSelectElement& select = toHTMLSelectElement(*node);
2069 RenderObject* renderer = select.renderer();
2070 if (!renderer || !renderer->isMenuList())
2073 RenderMenuList& menuList = toRenderMenuList(*renderer);
2074 PopupMenuStyle itemStyle = menuList.itemStyle(itemIndex);
2075 return itemStyle.textDirection() == RTL;
2078 int Internals::selectPopupItemStyleFontHeight(Node* node, int itemIndex)
2080 if (!node || !isHTMLSelectElement(*node))
2083 HTMLSelectElement& select = toHTMLSelectElement(*node);
2085 RenderObject* renderer = select.renderer();
2086 if (!renderer || !renderer->isMenuList())
2089 RenderMenuList& menuList = toRenderMenuList(*renderer);
2090 PopupMenuStyle itemStyle = menuList.itemStyle(itemIndex);
2091 return itemStyle.font().fontMetrics().height();
2094 bool Internals::loseSharedGraphicsContext3D()
2096 OwnPtr<blink::WebGraphicsContext3DProvider> sharedProvider = adoptPtr(blink::Platform::current()->createSharedOffscreenGraphicsContext3DProvider());
2097 if (!sharedProvider)
2099 blink::WebGraphicsContext3D* sharedContext = sharedProvider->context3d();
2100 sharedContext->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_EXT, GL_INNOCENT_CONTEXT_RESET_EXT);
2101 // To prevent tests that call loseSharedGraphicsContext3D from being
2102 // flaky, we call finish so that the context is guaranteed to be lost
2103 // synchronously (i.e. before returning).
2104 sharedContext->finish();
2108 void Internals::forceCompositingUpdate(Document* document, ExceptionState& exceptionState)
2111 if (!document->renderView()) {
2112 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
2116 document->frame()->view()->updateLayoutAndStyleForPainting();
2119 void Internals::setZoomFactor(float factor)
2121 frame()->setPageZoomFactor(factor);
2124 void Internals::setShouldRevealPassword(Element* element, bool reveal, ExceptionState& exceptionState)
2127 if (!isHTMLInputElement(element)) {
2128 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not an INPUT.");
2132 return toHTMLInputElement(*element).setShouldRevealPassword(reveal);
2137 class AddOneFunction : public ScriptFunction {
2139 static PassOwnPtr<ScriptFunction> create(ExecutionContext* context)
2141 return adoptPtr(new AddOneFunction(toIsolate(context)));
2145 AddOneFunction(v8::Isolate* isolate)
2146 : ScriptFunction(isolate)
2150 virtual ScriptValue call(ScriptValue value) OVERRIDE
2152 v8::Local<v8::Value> v8Value = value.v8Value();
2153 ASSERT(v8Value->IsNumber());
2154 int intValue = v8Value.As<v8::Integer>()->Value();
2155 ScriptValue result = ScriptValue(ScriptState::current(isolate()), v8::Integer::New(isolate(), intValue + 1));
2162 ScriptPromise Internals::createResolvedPromise(ScriptState* scriptState, ScriptValue value)
2164 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
2165 ScriptPromise promise = resolver->promise();
2166 resolver->resolve(value);
2170 ScriptPromise Internals::createRejectedPromise(ScriptState* scriptState, ScriptValue value)
2172 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
2173 ScriptPromise promise = resolver->promise();
2174 resolver->reject(value);
2178 ScriptPromise Internals::addOneToPromise(ScriptState* scriptState, ScriptPromise promise)
2180 return promise.then(AddOneFunction::create(scriptState->executionContext()));
2183 ScriptPromise Internals::promiseCheck(ScriptState* scriptState, long arg1, bool arg2, const Dictionary& arg3, const String& arg4, const Vector<String>& arg5, ExceptionState& exceptionState)
2186 return ScriptPromise::cast(scriptState, v8String(scriptState->isolate(), "done"));
2187 exceptionState.throwDOMException(InvalidStateError, "Thrown from the native implementation.");
2188 return ScriptPromise();
2191 ScriptPromise Internals::promiseCheckWithoutExceptionState(ScriptState* scriptState, const Dictionary& arg1, const String& arg2, const Vector<String>& arg3)
2193 return ScriptPromise::cast(scriptState, v8String(scriptState->isolate(), "done"));
2196 ScriptPromise Internals::promiseCheckRange(ScriptState* scriptState, long arg1)
2198 return ScriptPromise::cast(scriptState, v8String(scriptState->isolate(), "done"));
2201 void Internals::trace(Visitor* visitor)
2203 visitor->trace(m_runtimeFlags);
2204 visitor->trace(m_profilers);
2207 void Internals::setValueForUser(Element* element, const String& value)
2209 toHTMLInputElement(element)->setValueForUser(value);
2212 String Internals::textSurroundingNode(Node* node, int x, int y, unsigned long maxLength)
2216 blink::WebPoint point(x, y);
2217 SurroundingText surroundingText(VisiblePosition(node->renderer()->positionForPoint(static_cast<IntPoint>(point))).deepEquivalent().parentAnchoredEquivalent(), maxLength);
2218 return surroundingText.content();
2221 void Internals::setFocused(bool focused)
2223 frame()->page()->focusController().setFocused(focused);
2226 bool Internals::ignoreLayoutWithPendingStylesheets(Document* document)
2229 return document->ignoreLayoutWithPendingStylesheets();
2232 void Internals::setNetworkStateNotifierTestOnly(bool testOnly)
2234 networkStateNotifier().setTestUpdatesOnly(testOnly);
2237 void Internals::setNetworkConnectionInfo(const String& type, ExceptionState& exceptionState)
2239 blink::WebConnectionType webtype;
2240 if (type == "cellular") {
2241 webtype = blink::ConnectionTypeCellular;
2242 } else if (type == "bluetooth") {
2243 webtype = blink::ConnectionTypeBluetooth;
2244 } else if (type == "ethernet") {
2245 webtype = blink::ConnectionTypeEthernet;
2246 } else if (type == "wifi") {
2247 webtype = blink::ConnectionTypeWifi;
2248 } else if (type == "other") {
2249 webtype = blink::ConnectionTypeOther;
2250 } else if (type == "none") {
2251 webtype = blink::ConnectionTypeNone;
2252 } else if (type == "unknown") {
2253 webtype = blink::ConnectionTypeUnknown;
2255 exceptionState.throwDOMException(NotFoundError, ExceptionMessages::failedToEnumerate("connection type", type));
2258 networkStateNotifier().setWebConnectionTypeForTest(webtype);
2261 unsigned Internals::countHitRegions(CanvasRenderingContext2D* context)
2263 return context->hitRegionsCount();
2266 String Internals::serializeNavigationMarkup()
2268 Vector<Document::TransitionElementData> elementData;
2269 frame()->document()->getTransitionElementData(elementData);
2271 StringBuilder markup;
2272 Vector<Document::TransitionElementData>::iterator iter = elementData.begin();
2273 for (; iter != elementData.end(); ++iter)
2274 markup.append(iter->markup);
2276 return markup.toString();
2279 void Internals::hideAllTransitionElements()
2281 Vector<Document::TransitionElementData> elementData;
2282 frame()->document()->getTransitionElementData(elementData);
2284 Vector<Document::TransitionElementData>::iterator iter = elementData.begin();
2285 for (; iter != elementData.end(); ++iter)
2286 frame()->document()->hideTransitionElements(AtomicString(iter->selector));
2289 } // namespace blink