2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Apple Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "Internals.h"
31 #include "InternalProfilers.h"
32 #include "InternalRuntimeFlags.h"
33 #include "InternalSettings.h"
34 #include "LayerRect.h"
35 #include "LayerRectList.h"
36 #include "MallocStatistics.h"
37 #include "MockPagePopupDriver.h"
38 #include "RuntimeEnabledFeatures.h"
39 #include "TypeConversions.h"
40 #include "bindings/v8/ExceptionMessages.h"
41 #include "bindings/v8/ExceptionState.h"
42 #include "bindings/v8/ScriptFunction.h"
43 #include "bindings/v8/ScriptPromise.h"
44 #include "bindings/v8/ScriptPromiseResolver.h"
45 #include "bindings/v8/SerializedScriptValue.h"
46 #include "bindings/v8/V8ThrowException.h"
47 #include "core/animation/DocumentTimeline.h"
48 #include "core/css/StyleSheetContents.h"
49 #include "core/css/resolver/StyleResolver.h"
50 #include "core/css/resolver/StyleResolverStats.h"
51 #include "core/css/resolver/ViewportStyleResolver.h"
52 #include "core/dom/ClientRect.h"
53 #include "core/dom/ClientRectList.h"
54 #include "core/dom/DOMStringList.h"
55 #include "core/dom/Document.h"
56 #include "core/dom/DocumentMarker.h"
57 #include "core/dom/DocumentMarkerController.h"
58 #include "core/dom/Element.h"
59 #include "core/dom/ExceptionCode.h"
60 #include "core/dom/FullscreenElementStack.h"
61 #include "core/dom/NodeRenderStyle.h"
62 #include "core/dom/PseudoElement.h"
63 #include "core/dom/Range.h"
64 #include "core/dom/StaticNodeList.h"
65 #include "core/dom/TreeScope.h"
66 #include "core/dom/ViewportDescription.h"
67 #include "core/dom/WheelController.h"
68 #include "core/dom/shadow/ComposedTreeWalker.h"
69 #include "core/dom/shadow/ElementShadow.h"
70 #include "core/dom/shadow/SelectRuleFeatureSet.h"
71 #include "core/dom/shadow/ShadowRoot.h"
72 #include "core/editing/Editor.h"
73 #include "core/editing/PlainTextRange.h"
74 #include "core/editing/SpellCheckRequester.h"
75 #include "core/editing/SpellChecker.h"
76 #include "core/editing/SurroundingText.h"
77 #include "core/editing/TextIterator.h"
78 #include "core/fetch/MemoryCache.h"
79 #include "core/fetch/ResourceFetcher.h"
80 #include "core/frame/DOMPoint.h"
81 #include "core/frame/DOMWindow.h"
82 #include "core/frame/EventHandlerRegistry.h"
83 #include "core/frame/FrameView.h"
84 #include "core/frame/LocalFrame.h"
85 #include "core/frame/Settings.h"
86 #include "core/html/HTMLContentElement.h"
87 #include "core/html/HTMLIFrameElement.h"
88 #include "core/html/HTMLInputElement.h"
89 #include "core/html/HTMLMediaElement.h"
90 #include "core/html/HTMLSelectElement.h"
91 #include "core/html/HTMLTextAreaElement.h"
92 #include "core/html/forms/FormController.h"
93 #include "core/html/shadow/ShadowElementNames.h"
94 #include "core/html/shadow/TextControlInnerElements.h"
95 #include "core/inspector/InspectorClient.h"
96 #include "core/inspector/InspectorConsoleAgent.h"
97 #include "core/inspector/InspectorController.h"
98 #include "core/inspector/InspectorCounters.h"
99 #include "core/inspector/InspectorFrontendChannel.h"
100 #include "core/inspector/InspectorInstrumentation.h"
101 #include "core/inspector/InspectorOverlay.h"
102 #include "core/inspector/InstrumentingAgents.h"
103 #include "core/loader/FrameLoader.h"
104 #include "core/loader/HistoryItem.h"
105 #include "core/page/Chrome.h"
106 #include "core/page/ChromeClient.h"
107 #include "core/page/EventHandler.h"
108 #include "core/page/Page.h"
109 #include "core/page/PagePopupController.h"
110 #include "core/page/PrintContext.h"
111 #include "core/rendering/RenderLayer.h"
112 #include "core/rendering/RenderMenuList.h"
113 #include "core/rendering/RenderObject.h"
114 #include "core/rendering/RenderTreeAsText.h"
115 #include "core/rendering/RenderView.h"
116 #include "core/rendering/compositing/CompositedLayerMapping.h"
117 #include "core/rendering/compositing/RenderLayerCompositor.h"
118 #include "core/testing/GCObservation.h"
119 #include "core/workers/WorkerThread.h"
120 #include "platform/ColorChooser.h"
121 #include "platform/Cursor.h"
122 #include "platform/Language.h"
123 #include "platform/TraceEvent.h"
124 #include "platform/geometry/IntRect.h"
125 #include "platform/geometry/LayoutRect.h"
126 #include "platform/graphics/GraphicsLayer.h"
127 #include "platform/graphics/filters/FilterOperation.h"
128 #include "platform/graphics/filters/FilterOperations.h"
129 #include "platform/weborigin/SchemeRegistry.h"
130 #include "public/platform/Platform.h"
131 #include "public/platform/WebGraphicsContext3D.h"
132 #include "public/platform/WebGraphicsContext3DProvider.h"
133 #include "public/platform/WebLayer.h"
134 #include "wtf/InstanceCounter.h"
135 #include "wtf/PassOwnPtr.h"
136 #include "wtf/dtoa.h"
137 #include "wtf/text/StringBuffer.h"
141 // FIXME: oilpan: These will be removed soon.
142 static MockPagePopupDriver* s_pagePopupDriver = 0;
144 using namespace HTMLNames;
146 static bool markerTypesFrom(const String& markerType, DocumentMarker::MarkerTypes& result)
148 if (markerType.isEmpty() || equalIgnoringCase(markerType, "all"))
149 result = DocumentMarker::AllMarkers();
150 else if (equalIgnoringCase(markerType, "Spelling"))
151 result = DocumentMarker::Spelling;
152 else if (equalIgnoringCase(markerType, "Grammar"))
153 result = DocumentMarker::Grammar;
154 else if (equalIgnoringCase(markerType, "TextMatch"))
155 result = DocumentMarker::TextMatch;
162 static SpellCheckRequester* spellCheckRequester(Document* document)
164 if (!document || !document->frame())
166 return &document->frame()->spellChecker().spellCheckRequester();
169 const char* Internals::internalsId = "internals";
171 PassRefPtrWillBeRawPtr<Internals> Internals::create(Document* document)
173 return adoptRefWillBeNoop(new Internals(document));
176 Internals::~Internals()
180 void Internals::resetToConsistentState(Page* page)
184 page->setDeviceScaleFactor(1);
185 page->setIsCursorVisible(true);
186 page->setPageScaleFactor(1, IntPoint(0, 0));
187 TextRun::setAllowsRoundingHacks(false);
188 WebCore::overrideUserPreferredLanguages(Vector<AtomicString>());
189 delete s_pagePopupDriver;
190 s_pagePopupDriver = 0;
191 page->chrome().client().resetPagePopupDriver();
192 if (!page->mainFrame()->spellChecker().isContinuousSpellCheckingEnabled())
193 page->mainFrame()->spellChecker().toggleContinuousSpellChecking();
194 if (page->mainFrame()->editor().isOverwriteModeEnabled())
195 page->mainFrame()->editor().toggleOverwriteModeEnabled();
197 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
198 scrollingCoordinator->reset();
200 page->mainFrame()->view()->clear();
203 Internals::Internals(Document* document)
204 : ContextLifecycleObserver(document)
205 , m_runtimeFlags(InternalRuntimeFlags::create())
209 Document* Internals::contextDocument() const
211 return toDocument(executionContext());
214 LocalFrame* Internals::frame() const
216 if (!contextDocument())
218 return contextDocument()->frame();
221 InternalSettings* Internals::settings() const
223 Document* document = contextDocument();
226 Page* page = document->page();
229 return InternalSettings::from(*page);
232 InternalRuntimeFlags* Internals::runtimeFlags() const
234 return m_runtimeFlags.get();
237 InternalProfilers* Internals::profilers()
240 m_profilers = InternalProfilers::create();
241 return m_profilers.get();
244 unsigned Internals::workerThreadCount() const
246 return WorkerThread::workerThreadCount();
249 String Internals::address(Node* node)
252 sprintf(buf, "%p", node);
257 PassRefPtrWillBeRawPtr<GCObservation> Internals::observeGC(ScriptValue scriptValue)
259 v8::Handle<v8::Value> observedValue = scriptValue.v8Value();
260 ASSERT(!observedValue.IsEmpty());
261 if (observedValue->IsNull() || observedValue->IsUndefined()) {
262 V8ThrowException::throwTypeError("value to observe is null or undefined", v8::Isolate::GetCurrent());
266 return GCObservation::create(observedValue);
269 unsigned Internals::updateStyleAndReturnAffectedElementCount(ExceptionState& exceptionState) const
271 Document* document = contextDocument();
273 exceptionState.throwDOMException(InvalidAccessError, "No context document is available.");
277 unsigned beforeCount = document->styleEngine()->resolverAccessCount();
278 document->updateRenderTreeIfNeeded();
279 return document->styleEngine()->resolverAccessCount() - beforeCount;
282 unsigned Internals::needsLayoutCount(ExceptionState& exceptionState) const
284 LocalFrame* contextFrame = frame();
286 exceptionState.throwDOMException(InvalidAccessError, "No context frame is available.");
291 unsigned needsLayoutObjects;
292 unsigned totalObjects;
293 contextFrame->countObjectsNeedingLayout(needsLayoutObjects, totalObjects, isPartial);
294 return needsLayoutObjects;
297 bool Internals::isPreloaded(const String& url)
299 Document* document = contextDocument();
300 return document->fetcher()->isPreloaded(url);
303 bool Internals::isLoadingFromMemoryCache(const String& url)
305 if (!contextDocument())
307 Resource* resource = memoryCache()->resourceForURL(contextDocument()->completeURL(url));
308 return resource && resource->status() == Resource::Cached;
311 void Internals::crash()
316 void Internals::setStyleResolverStatsEnabled(bool enabled)
318 Document* document = contextDocument();
320 document->ensureStyleResolver().enableStats(StyleResolver::ReportSlowStats);
322 document->ensureStyleResolver().disableStats();
325 String Internals::styleResolverStatsReport(ExceptionState& exceptionState) const
327 Document* document = contextDocument();
328 if (!document->ensureStyleResolver().stats()) {
329 exceptionState.throwDOMException(InvalidStateError, "Style resolver stats not enabled");
332 return document->ensureStyleResolver().stats()->report();
335 String Internals::styleResolverStatsTotalsReport(ExceptionState& exceptionState) const
337 Document* document = contextDocument();
338 if (!document->ensureStyleResolver().statsTotals()) {
339 exceptionState.throwDOMException(InvalidStateError, "Style resolver stats not enabled");
342 return document->ensureStyleResolver().statsTotals()->report();
345 bool Internals::isSharingStyle(Element* element1, Element* element2, ExceptionState& exceptionState) const
347 if (!element1 || !element2) {
348 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(element1 ? 2 : 1, "Element"));
351 return element1->renderStyle() == element2->renderStyle();
354 bool Internals::isValidContentSelect(Element* insertionPoint, ExceptionState& exceptionState)
356 if (!insertionPoint || !insertionPoint->isInsertionPoint()) {
357 exceptionState.throwDOMException(InvalidAccessError, "The insertion point provided is invalid.");
361 return isHTMLContentElement(*insertionPoint) && toHTMLContentElement(*insertionPoint).isSelectValid();
364 Node* Internals::treeScopeRootNode(Node* node, ExceptionState& exceptionState)
367 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
371 return &node->treeScope().rootNode();
374 Node* Internals::parentTreeScope(Node* node, ExceptionState& exceptionState)
377 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
380 const TreeScope* parentTreeScope = node->treeScope().parentTreeScope();
381 return parentTreeScope ? &parentTreeScope->rootNode() : 0;
384 bool Internals::hasSelectorForIdInShadow(Element* host, const AtomicString& idValue, ExceptionState& exceptionState)
386 if (!host || !host->shadow()) {
387 exceptionState.throwDOMException(InvalidAccessError, "The host element provided is invalid, or does not have a shadow.");
391 return host->shadow()->ensureSelectFeatureSet().hasSelectorForId(idValue);
394 bool Internals::hasSelectorForClassInShadow(Element* host, const AtomicString& className, ExceptionState& exceptionState)
396 if (!host || !host->shadow()) {
397 exceptionState.throwDOMException(InvalidAccessError, "The host element provided is invalid, or does not have a shadow.");
401 return host->shadow()->ensureSelectFeatureSet().hasSelectorForClass(className);
404 bool Internals::hasSelectorForAttributeInShadow(Element* host, const AtomicString& attributeName, ExceptionState& exceptionState)
406 if (!host || !host->shadow()) {
407 exceptionState.throwDOMException(InvalidAccessError, "The host element provided is invalid, or does not have a shadow.");
411 return host->shadow()->ensureSelectFeatureSet().hasSelectorForAttribute(attributeName);
414 bool Internals::hasSelectorForPseudoClassInShadow(Element* host, const String& pseudoClass, ExceptionState& exceptionState)
416 if (!host || !host->shadow()) {
417 exceptionState.throwDOMException(InvalidAccessError, "The host element provided is invalid, or does not have a shadow.");
421 const SelectRuleFeatureSet& featureSet = host->shadow()->ensureSelectFeatureSet();
422 if (pseudoClass == "checked")
423 return featureSet.hasSelectorForChecked();
424 if (pseudoClass == "enabled")
425 return featureSet.hasSelectorForEnabled();
426 if (pseudoClass == "disabled")
427 return featureSet.hasSelectorForDisabled();
428 if (pseudoClass == "indeterminate")
429 return featureSet.hasSelectorForIndeterminate();
430 if (pseudoClass == "link")
431 return featureSet.hasSelectorForLink();
432 if (pseudoClass == "target")
433 return featureSet.hasSelectorForTarget();
434 if (pseudoClass == "visited")
435 return featureSet.hasSelectorForVisited();
437 ASSERT_NOT_REACHED();
441 unsigned short Internals::compareTreeScopePosition(const Node* node1, const Node* node2, ExceptionState& exceptionState) const
443 if (!node1 || !node2) {
444 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(node1 ? 2 : 1, "Node"));
447 const TreeScope* treeScope1 = node1->isDocumentNode() ? static_cast<const TreeScope*>(toDocument(node1)) :
448 node1->isShadowRoot() ? static_cast<const TreeScope*>(toShadowRoot(node1)) : 0;
449 const TreeScope* treeScope2 = node2->isDocumentNode() ? static_cast<const TreeScope*>(toDocument(node2)) :
450 node2->isShadowRoot() ? static_cast<const TreeScope*>(toShadowRoot(node2)) : 0;
451 if (!treeScope1 || !treeScope2) {
452 exceptionState.throwDOMException(InvalidAccessError, String::format("The %s node is neither a document node, nor a shadow root.", treeScope1 ? "second" : "first"));
455 return treeScope1->comparePosition(*treeScope2);
458 unsigned Internals::numberOfActiveAnimations() const
460 LocalFrame* contextFrame = frame();
461 Document* document = contextFrame->document();
462 return document->timeline().numberOfActiveAnimationsForTesting() + document->transitionTimeline().numberOfActiveAnimationsForTesting();
465 void Internals::pauseAnimations(double pauseTime, ExceptionState& exceptionState)
468 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::indexExceedsMinimumBound("pauseTime", pauseTime, 0.0));
472 frame()->view()->updateLayoutAndStyleForPainting();
473 frame()->document()->timeline().pauseAnimationsForTesting(pauseTime);
474 frame()->document()->transitionTimeline().pauseAnimationsForTesting(pauseTime);
477 bool Internals::hasShadowInsertionPoint(const Node* root, ExceptionState& exceptionState) const
479 if (root && root->isShadowRoot())
480 return toShadowRoot(root)->containsShadowElements();
482 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
486 bool Internals::hasContentElement(const Node* root, ExceptionState& exceptionState) const
488 if (root && root->isShadowRoot())
489 return toShadowRoot(root)->containsContentElements();
491 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
495 size_t Internals::countElementShadow(const Node* root, ExceptionState& exceptionState) const
497 if (!root || !root->isShadowRoot()) {
498 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
501 return toShadowRoot(root)->childShadowRootCount();
504 Node* Internals::nextSiblingByWalker(Node* node, ExceptionState& exceptionState)
507 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
510 ComposedTreeWalker walker(node);
511 walker.nextSibling();
515 Node* Internals::firstChildByWalker(Node* node, ExceptionState& exceptionState)
518 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
521 ComposedTreeWalker walker(node);
526 Node* Internals::lastChildByWalker(Node* node, ExceptionState& exceptionState)
529 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
532 ComposedTreeWalker walker(node);
537 Node* Internals::nextNodeByWalker(Node* node, ExceptionState& exceptionState)
540 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
543 ComposedTreeWalker walker(node);
548 Node* Internals::previousNodeByWalker(Node* node, ExceptionState& exceptionState)
551 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
554 ComposedTreeWalker walker(node);
559 String Internals::elementRenderTreeAsText(Element* element, ExceptionState& exceptionState)
562 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
566 String representation = externalRepresentation(element);
567 if (representation.isEmpty()) {
568 exceptionState.throwDOMException(InvalidAccessError, "The element provided has no external representation.");
572 return representation;
575 size_t Internals::numberOfScopedHTMLStyleChildren(const Node* scope, ExceptionState& exceptionState) const
577 if (scope && (scope->isElementNode() || scope->isShadowRoot()))
578 return scope->numberOfScopedHTMLStyleChildren();
580 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
584 PassRefPtrWillBeRawPtr<CSSComputedStyleDeclaration> Internals::computedStyleIncludingVisitedInfo(Node* node, ExceptionState& exceptionState) const
587 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
591 bool allowVisitedStyle = true;
592 return CSSComputedStyleDeclaration::create(node, allowVisitedStyle);
595 ShadowRoot* Internals::shadowRoot(Element* host, ExceptionState& exceptionState)
597 // FIXME: Internals::shadowRoot() in tests should be converted to youngestShadowRoot() or oldestShadowRoot().
598 // https://bugs.webkit.org/show_bug.cgi?id=78465
599 return youngestShadowRoot(host, exceptionState);
602 ShadowRoot* Internals::youngestShadowRoot(Element* host, ExceptionState& exceptionState)
605 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
609 if (ElementShadow* shadow = host->shadow())
610 return shadow->youngestShadowRoot();
614 ShadowRoot* Internals::oldestShadowRoot(Element* host, ExceptionState& exceptionState)
617 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
621 if (ElementShadow* shadow = host->shadow())
622 return shadow->oldestShadowRoot();
626 ShadowRoot* Internals::youngerShadowRoot(Node* shadow, ExceptionState& exceptionState)
628 if (!shadow || !shadow->isShadowRoot()) {
629 exceptionState.throwDOMException(InvalidAccessError, "The node provided is not a valid shadow root.");
633 return toShadowRoot(shadow)->youngerShadowRoot();
636 String Internals::shadowRootType(const Node* root, ExceptionState& exceptionState) const
638 if (!root || !root->isShadowRoot()) {
639 exceptionState.throwDOMException(InvalidAccessError, "The node provided is not a valid shadow root.");
643 switch (toShadowRoot(root)->type()) {
644 case ShadowRoot::UserAgentShadowRoot:
645 return String("UserAgentShadowRoot");
646 case ShadowRoot::AuthorShadowRoot:
647 return String("AuthorShadowRoot");
649 ASSERT_NOT_REACHED();
650 return String("Unknown");
654 const AtomicString& Internals::shadowPseudoId(Element* element, ExceptionState& exceptionState)
657 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
661 return element->shadowPseudoId();
664 void Internals::setShadowPseudoId(Element* element, const AtomicString& id, ExceptionState& exceptionState)
667 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
671 return element->setShadowPseudoId(id);
674 String Internals::visiblePlaceholder(Element* element)
676 if (element && isHTMLTextFormControlElement(*element)) {
677 if (toHTMLTextFormControlElement(element)->placeholderShouldBeVisible())
678 return toHTMLTextFormControlElement(element)->placeholderElement()->textContent();
684 void Internals::selectColorInColorChooser(Element* element, const String& colorValue)
687 if (!isHTMLInputElement(*element))
690 if (!color.setFromString(colorValue))
692 toHTMLInputElement(*element).selectColorInColorChooser(color);
695 bool Internals::hasAutofocusRequest(Document* document)
698 document = contextDocument();
699 return document->autofocusElement();
702 bool Internals::hasAutofocusRequest()
704 return hasAutofocusRequest(0);
707 Vector<String> Internals::formControlStateOfHistoryItem(ExceptionState& exceptionState)
709 HistoryItem* mainItem = frame()->loader().currentItem();
711 exceptionState.throwDOMException(InvalidAccessError, "No history item is available.");
712 return Vector<String>();
714 return mainItem->documentState();
717 void Internals::setFormControlStateOfHistoryItem(const Vector<String>& state, ExceptionState& exceptionState)
719 HistoryItem* mainItem = frame()->loader().currentItem();
721 exceptionState.throwDOMException(InvalidAccessError, "No history item is available.");
724 mainItem->clearDocumentState();
725 mainItem->setDocumentState(state);
728 void Internals::setEnableMockPagePopup(bool enabled, ExceptionState& exceptionState)
730 Document* document = contextDocument();
731 if (!document || !document->page())
733 Page* page = document->page();
735 page->chrome().client().resetPagePopupDriver();
738 if (!s_pagePopupDriver)
739 s_pagePopupDriver = MockPagePopupDriver::create(page->mainFrame()).leakPtr();
740 page->chrome().client().setPagePopupDriver(s_pagePopupDriver);
743 PassRefPtrWillBeRawPtr<PagePopupController> Internals::pagePopupController()
745 return s_pagePopupDriver ? s_pagePopupDriver->pagePopupController() : 0;
748 PassRefPtrWillBeRawPtr<ClientRect> Internals::unscaledViewportRect(ExceptionState& exceptionState)
750 Document* document = contextDocument();
751 if (!document || !document->view()) {
752 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's viewport cannot be retrieved." : "No context document can be obtained.");
753 return ClientRect::create();
756 return ClientRect::create(document->view()->visibleContentRect());
759 PassRefPtrWillBeRawPtr<ClientRect> Internals::absoluteCaretBounds(ExceptionState& exceptionState)
761 Document* document = contextDocument();
762 if (!document || !document->frame()) {
763 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "No context document can be obtained.");
764 return ClientRect::create();
767 return ClientRect::create(document->frame()->selection().absoluteCaretBounds());
770 PassRefPtrWillBeRawPtr<ClientRect> Internals::boundingBox(Element* element, ExceptionState& exceptionState)
773 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
774 return ClientRect::create();
777 element->document().updateLayoutIgnorePendingStylesheets();
778 RenderObject* renderer = element->renderer();
780 return ClientRect::create();
781 return ClientRect::create(renderer->absoluteBoundingBoxRectIgnoringTransforms());
784 unsigned Internals::markerCountForNode(Node* node, const String& markerType, ExceptionState& exceptionState)
787 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
791 DocumentMarker::MarkerTypes markerTypes = 0;
792 if (!markerTypesFrom(markerType, markerTypes)) {
793 exceptionState.throwDOMException(SyntaxError, "The marker type provided ('" + markerType + "') is invalid.");
797 return node->document().markers().markersFor(node, markerTypes).size();
800 unsigned Internals::activeMarkerCountForNode(Node* node, ExceptionState& exceptionState)
803 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
807 // Only TextMatch markers can be active.
808 DocumentMarker::MarkerType markerType = DocumentMarker::TextMatch;
809 Vector<DocumentMarker*> markers = node->document().markers().markersFor(node, markerType);
811 unsigned activeMarkerCount = 0;
812 for (Vector<DocumentMarker*>::iterator iter = markers.begin(); iter != markers.end(); ++iter) {
813 if ((*iter)->activeMatch())
817 return activeMarkerCount;
820 DocumentMarker* Internals::markerAt(Node* node, const String& markerType, unsigned index, ExceptionState& exceptionState)
823 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
827 DocumentMarker::MarkerTypes markerTypes = 0;
828 if (!markerTypesFrom(markerType, markerTypes)) {
829 exceptionState.throwDOMException(SyntaxError, "The marker type provided ('" + markerType + "') is invalid.");
833 Vector<DocumentMarker*> markers = node->document().markers().markersFor(node, markerTypes);
834 if (markers.size() <= index)
836 return markers[index];
839 PassRefPtrWillBeRawPtr<Range> Internals::markerRangeForNode(Node* node, const String& markerType, unsigned index, ExceptionState& exceptionState)
841 DocumentMarker* marker = markerAt(node, markerType, index, exceptionState);
844 return Range::create(node->document(), node, marker->startOffset(), node, marker->endOffset());
847 String Internals::markerDescriptionForNode(Node* node, const String& markerType, unsigned index, ExceptionState& exceptionState)
849 DocumentMarker* marker = markerAt(node, markerType, index, exceptionState);
852 return marker->description();
855 void Internals::addTextMatchMarker(const Range* range, bool isActive)
857 range->ownerDocument().updateLayoutIgnorePendingStylesheets();
858 range->ownerDocument().markers().addTextMatchMarker(range, isActive);
861 void Internals::setMarkersActive(Node* node, unsigned startOffset, unsigned endOffset, bool active, ExceptionState& exceptionState)
864 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
868 node->document().markers().setMarkersActive(node, startOffset, endOffset, active);
871 void Internals::setMarkedTextMatchesAreHighlighted(Document* document, bool highlight, ExceptionState&)
873 if (!document || !document->frame())
876 document->frame()->editor().setMarkedTextMatchesAreHighlighted(highlight);
879 void Internals::setScrollViewPosition(Document* document, long x, long y, ExceptionState& exceptionState)
881 if (!document || !document->view()) {
882 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's view cannot be retrieved." : "The document provided is invalid.");
886 FrameView* frameView = document->view();
887 bool constrainsScrollingToContentEdgeOldValue = frameView->constrainsScrollingToContentEdge();
888 bool scrollbarsSuppressedOldValue = frameView->scrollbarsSuppressed();
890 frameView->setConstrainsScrollingToContentEdge(false);
891 frameView->setScrollbarsSuppressed(false);
892 frameView->setScrollOffsetFromInternals(IntPoint(x, y));
893 frameView->setScrollbarsSuppressed(scrollbarsSuppressedOldValue);
894 frameView->setConstrainsScrollingToContentEdge(constrainsScrollingToContentEdgeOldValue);
897 String Internals::viewportAsText(Document* document, float, int availableWidth, int availableHeight, ExceptionState& exceptionState)
899 if (!document || !document->page()) {
900 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's page cannot be retrieved." : "The document provided is invalid.");
904 document->updateLayoutIgnorePendingStylesheets();
906 Page* page = document->page();
908 // Update initial viewport size.
909 IntSize initialViewportSize(availableWidth, availableHeight);
910 document->page()->mainFrame()->view()->setFrameRect(IntRect(IntPoint::zero(), initialViewportSize));
912 ViewportDescription description = page->viewportDescription();
913 PageScaleConstraints constraints = description.resolve(initialViewportSize, Length());
915 constraints.fitToContentsWidth(constraints.layoutSize.width(), availableWidth);
917 StringBuilder builder;
919 builder.appendLiteral("viewport size ");
920 builder.append(String::number(constraints.layoutSize.width()));
922 builder.append(String::number(constraints.layoutSize.height()));
924 builder.appendLiteral(" scale ");
925 builder.append(String::number(constraints.initialScale));
926 builder.appendLiteral(" with limits [");
927 builder.append(String::number(constraints.minimumScale));
928 builder.appendLiteral(", ");
929 builder.append(String::number(constraints.maximumScale));
931 builder.appendLiteral("] and userScalable ");
932 builder.append(description.userZoom ? "true" : "false");
934 return builder.toString();
937 bool Internals::wasLastChangeUserEdit(Element* textField, ExceptionState& exceptionState)
940 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
944 if (isHTMLInputElement(*textField))
945 return toHTMLInputElement(*textField).lastChangeWasUserEdit();
947 if (isHTMLTextAreaElement(*textField))
948 return toHTMLTextAreaElement(*textField).lastChangeWasUserEdit();
950 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a TEXTAREA.");
954 bool Internals::elementShouldAutoComplete(Element* element, ExceptionState& exceptionState)
957 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
961 if (isHTMLInputElement(*element))
962 return toHTMLInputElement(*element).shouldAutocomplete();
964 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not an INPUT.");
968 String Internals::suggestedValue(Element* element, ExceptionState& exceptionState)
971 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
975 if (!element->isFormControlElement()) {
976 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a form control element.");
980 String suggestedValue;
981 if (isHTMLInputElement(*element))
982 suggestedValue = toHTMLInputElement(*element).suggestedValue();
984 if (isHTMLTextAreaElement(*element))
985 suggestedValue = toHTMLTextAreaElement(*element).suggestedValue();
987 if (isHTMLSelectElement(*element))
988 suggestedValue = toHTMLSelectElement(*element).suggestedValue();
990 return suggestedValue;
993 void Internals::setSuggestedValue(Element* element, const String& value, ExceptionState& exceptionState)
996 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
1000 if (!element->isFormControlElement()) {
1001 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a form control element.");
1005 if (isHTMLInputElement(*element))
1006 toHTMLInputElement(*element).setSuggestedValue(value);
1008 if (isHTMLTextAreaElement(*element))
1009 toHTMLTextAreaElement(*element).setSuggestedValue(value);
1011 if (isHTMLSelectElement(*element))
1012 toHTMLSelectElement(*element).setSuggestedValue(value);
1015 void Internals::setEditingValue(Element* element, const String& value, ExceptionState& exceptionState)
1018 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
1022 if (!isHTMLInputElement(*element)) {
1023 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not an INPUT.");
1027 toHTMLInputElement(*element).setEditingValue(value);
1030 void Internals::setAutofilled(Element* element, bool enabled, ExceptionState& exceptionState)
1032 if (!element->isFormControlElement()) {
1033 exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a form control element.");
1036 toHTMLFormControlElement(element)->setAutofilled(enabled);
1039 void Internals::scrollElementToRect(Element* element, long x, long y, long w, long h, ExceptionState& exceptionState)
1041 if (!element || !element->document().view()) {
1042 exceptionState.throwDOMException(InvalidNodeTypeError, element ? "No view can be obtained from the provided element's document." : ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
1045 FrameView* frameView = element->document().view();
1046 frameView->scrollElementToRect(element, IntRect(x, y, w, h));
1049 PassRefPtrWillBeRawPtr<Range> Internals::rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionState& exceptionState)
1052 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
1056 // TextIterator depends on Layout information, make sure layout it up to date.
1057 scope->document().updateLayoutIgnorePendingStylesheets();
1059 return PlainTextRange(rangeLocation, rangeLocation + rangeLength).createRange(*scope);
1062 unsigned Internals::locationFromRange(Element* scope, const Range* range, ExceptionState& exceptionState)
1064 if (!scope || !range) {
1065 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(scope ? 2 : 1, scope ? "Range" : "Element"));
1069 // PlainTextRange depends on Layout information, make sure layout it up to date.
1070 scope->document().updateLayoutIgnorePendingStylesheets();
1072 return PlainTextRange::create(*scope, *range).start();
1075 unsigned Internals::lengthFromRange(Element* scope, const Range* range, ExceptionState& exceptionState)
1077 if (!scope || !range) {
1078 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(scope ? 2 : 1, scope ? "Range" : "Element"));
1082 // PlainTextRange depends on Layout information, make sure layout it up to date.
1083 scope->document().updateLayoutIgnorePendingStylesheets();
1085 return PlainTextRange::create(*scope, *range).length();
1088 String Internals::rangeAsText(const Range* range, ExceptionState& exceptionState)
1091 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Range"));
1095 return range->text();
1098 PassRefPtrWillBeRawPtr<DOMPoint> Internals::touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1100 if (!document || !document->frame()) {
1101 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1105 document->updateLayout();
1107 IntSize radius(width / 2, height / 2);
1108 IntPoint point(x + radius.width(), y + radius.height());
1111 IntPoint adjustedPoint;
1113 bool foundNode = document->frame()->eventHandler().bestClickableNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1115 return DOMPoint::create(adjustedPoint.x(), adjustedPoint.y());
1120 Node* Internals::touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1122 if (!document || !document->frame()) {
1123 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1127 document->updateLayout();
1129 IntSize radius(width / 2, height / 2);
1130 IntPoint point(x + radius.width(), y + radius.height());
1133 IntPoint adjustedPoint;
1134 document->frame()->eventHandler().bestClickableNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1138 PassRefPtrWillBeRawPtr<DOMPoint> Internals::touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1140 if (!document || !document->frame()) {
1141 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1145 document->updateLayout();
1147 IntSize radius(width / 2, height / 2);
1148 IntPoint point(x + radius.width(), y + radius.height());
1150 Node* targetNode = 0;
1151 IntPoint adjustedPoint;
1153 bool foundNode = document->frame()->eventHandler().bestContextMenuNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1155 return DOMPoint::create(adjustedPoint.x(), adjustedPoint.y());
1157 return DOMPoint::create(x, y);
1160 Node* Internals::touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1162 if (!document || !document->frame()) {
1163 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1167 document->updateLayout();
1169 IntSize radius(width / 2, height / 2);
1170 IntPoint point(x + radius.width(), y + radius.height());
1172 Node* targetNode = 0;
1173 IntPoint adjustedPoint;
1174 document->frame()->eventHandler().bestContextMenuNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1178 PassRefPtrWillBeRawPtr<ClientRect> Internals::bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document* document, ExceptionState& exceptionState)
1180 if (!document || !document->frame()) {
1181 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1185 document->updateLayout();
1187 IntSize radius(width / 2, height / 2);
1188 IntPoint point(x + radius.width(), y + radius.height());
1191 IntRect zoomableArea;
1192 bool foundNode = document->frame()->eventHandler().bestZoomableAreaForTouchPoint(point, radius, zoomableArea, targetNode);
1194 return ClientRect::create(zoomableArea);
1200 int Internals::lastSpellCheckRequestSequence(Document* document, ExceptionState& exceptionState)
1202 SpellCheckRequester* requester = spellCheckRequester(document);
1205 exceptionState.throwDOMException(InvalidAccessError, "No spell check requestor can be obtained for the provided document.");
1209 return requester->lastRequestSequence();
1212 int Internals::lastSpellCheckProcessedSequence(Document* document, ExceptionState& exceptionState)
1214 SpellCheckRequester* requester = spellCheckRequester(document);
1217 exceptionState.throwDOMException(InvalidAccessError, "No spell check requestor can be obtained for the provided document.");
1221 return requester->lastProcessedSequence();
1224 Vector<AtomicString> Internals::userPreferredLanguages() const
1226 return WebCore::userPreferredLanguages();
1229 // Optimally, the bindings generator would pass a Vector<AtomicString> here but
1230 // this is not supported yet.
1231 void Internals::setUserPreferredLanguages(const Vector<String>& languages)
1233 Vector<AtomicString> atomicLanguages;
1234 for (size_t i = 0; i < languages.size(); ++i)
1235 atomicLanguages.append(AtomicString(languages[i]));
1236 WebCore::overrideUserPreferredLanguages(atomicLanguages);
1239 unsigned Internals::activeDOMObjectCount(Document* document, ExceptionState& exceptionState)
1242 exceptionState.throwDOMException(InvalidAccessError, "No context document is available.");
1246 return document->activeDOMObjectCount();
1249 static unsigned eventHandlerCount(Document& document, EventHandlerRegistry::EventHandlerClass handlerClass)
1251 if (!document.frameHost())
1253 EventHandlerRegistry* registry = &document.frameHost()->eventHandlerRegistry();
1255 const EventTargetSet* targets = registry->eventHandlerTargets(handlerClass);
1257 for (EventTargetSet::const_iterator iter = targets->begin(); iter != targets->end(); ++iter)
1258 count += iter->value;
1263 unsigned Internals::wheelEventHandlerCount(Document* document, ExceptionState& exceptionState)
1266 exceptionState.throwDOMException(InvalidAccessError, "No context document is available.");
1270 return WheelController::from(*document)->wheelEventHandlerCount();
1273 unsigned Internals::scrollEventHandlerCount(Document* document, ExceptionState& exceptionState)
1276 exceptionState.throwDOMException(InvalidAccessError, "No context document is available.");
1280 return eventHandlerCount(*document, EventHandlerRegistry::ScrollEvent);
1283 unsigned Internals::touchEventHandlerCount(Document* document, ExceptionState& exceptionState)
1286 exceptionState.throwDOMException(InvalidAccessError, "No context document is available.");
1290 const TouchEventTargetSet* touchHandlers = document->touchEventTargets();
1295 for (TouchEventTargetSet::const_iterator iter = touchHandlers->begin(); iter != touchHandlers->end(); ++iter)
1296 count += iter->value;
1300 static RenderLayer* findRenderLayerForGraphicsLayer(RenderLayer* searchRoot, GraphicsLayer* graphicsLayer, IntSize* layerOffset, String* layerType)
1302 *layerOffset = IntSize();
1303 if (searchRoot->hasCompositedLayerMapping() && graphicsLayer == searchRoot->compositedLayerMapping()->mainGraphicsLayer()) {
1304 CompositedLayerMappingPtr compositedLayerMapping = searchRoot->compositedLayerMapping();
1305 LayoutSize offset = compositedLayerMapping->contentOffsetInCompositingLayer();
1306 *layerOffset = IntSize(offset.width(), offset.height());
1310 GraphicsLayer* layerForScrolling = searchRoot->scrollableArea() ? searchRoot->scrollableArea()->layerForScrolling() : 0;
1311 if (graphicsLayer == layerForScrolling) {
1312 *layerType = "scrolling";
1316 if (searchRoot->compositingState() == PaintsIntoGroupedBacking) {
1317 GraphicsLayer* squashingLayer = searchRoot->groupedMapping()->squashingLayer();
1318 if (graphicsLayer == squashingLayer) {
1319 *layerType ="squashing";
1320 *layerOffset = -searchRoot->offsetFromSquashingLayerOrigin();
1325 GraphicsLayer* layerForHorizontalScrollbar = searchRoot->scrollableArea() ? searchRoot->scrollableArea()->layerForHorizontalScrollbar() : 0;
1326 if (graphicsLayer == layerForHorizontalScrollbar) {
1327 *layerType = "horizontalScrollbar";
1331 GraphicsLayer* layerForVerticalScrollbar = searchRoot->scrollableArea() ? searchRoot->scrollableArea()->layerForVerticalScrollbar() : 0;
1332 if (graphicsLayer == layerForVerticalScrollbar) {
1333 *layerType = "verticalScrollbar";
1337 GraphicsLayer* layerForScrollCorner = searchRoot->scrollableArea() ? searchRoot->scrollableArea()->layerForScrollCorner() : 0;
1338 if (graphicsLayer == layerForScrollCorner) {
1339 *layerType = "scrollCorner";
1343 // Search right to left to increase the chances that we'll choose the top-most layers in a
1344 // grouped mapping for squashing.
1345 for (RenderLayer* child = searchRoot->lastChild(); child; child = child->previousSibling()) {
1346 RenderLayer* foundLayer = findRenderLayerForGraphicsLayer(child, graphicsLayer, layerOffset, layerType);
1354 // Given a vector of rects, merge those that are adjacent, leaving empty rects
1355 // in the place of no longer used slots. This is intended to simplify the list
1356 // of rects returned by an SkRegion (which have been split apart for sorting
1357 // purposes). No attempt is made to do this efficiently (eg. by relying on the
1358 // sort criteria of SkRegion).
1359 static void mergeRects(blink::WebVector<blink::WebRect>& rects)
1361 for (size_t i = 0; i < rects.size(); ++i) {
1362 if (rects[i].isEmpty())
1367 for (size_t j = i+1; j < rects.size(); ++j) {
1368 if (rects[j].isEmpty())
1370 // Try to merge rects[j] into rects[i] along the 4 possible edges.
1371 if (rects[i].y == rects[j].y && rects[i].height == rects[j].height) {
1372 if (rects[i].x + rects[i].width == rects[j].x) {
1373 rects[i].width += rects[j].width;
1374 rects[j] = blink::WebRect();
1376 } else if (rects[i].x == rects[j].x + rects[j].width) {
1377 rects[i].x = rects[j].x;
1378 rects[i].width += rects[j].width;
1379 rects[j] = blink::WebRect();
1382 } else if (rects[i].x == rects[j].x && rects[i].width == rects[j].width) {
1383 if (rects[i].y + rects[i].height == rects[j].y) {
1384 rects[i].height += rects[j].height;
1385 rects[j] = blink::WebRect();
1387 } else if (rects[i].y == rects[j].y + rects[j].height) {
1388 rects[i].y = rects[j].y;
1389 rects[i].height += rects[j].height;
1390 rects[j] = blink::WebRect();
1399 static void accumulateLayerRectList(RenderLayerCompositor* compositor, GraphicsLayer* graphicsLayer, LayerRectList* rects)
1401 blink::WebVector<blink::WebRect> layerRects = graphicsLayer->platformLayer()->touchEventHandlerRegion();
1402 if (!layerRects.isEmpty()) {
1403 mergeRects(layerRects);
1405 IntSize layerOffset;
1406 RenderLayer* renderLayer = findRenderLayerForGraphicsLayer(compositor->rootRenderLayer(), graphicsLayer, &layerOffset, &layerType);
1407 Node* node = renderLayer ? renderLayer->renderer()->node() : 0;
1408 for (size_t i = 0; i < layerRects.size(); ++i) {
1409 if (!layerRects[i].isEmpty()) {
1410 rects->append(node, layerType, layerOffset.width(), layerOffset.height(), ClientRect::create(layerRects[i]));
1415 size_t numChildren = graphicsLayer->children().size();
1416 for (size_t i = 0; i < numChildren; ++i)
1417 accumulateLayerRectList(compositor, graphicsLayer->children()[i], rects);
1420 PassRefPtrWillBeRawPtr<LayerRectList> Internals::touchEventTargetLayerRects(Document* document, ExceptionState& exceptionState)
1422 if (!document || !document->view() || !document->page() || document != contextDocument()) {
1423 exceptionState.throwDOMException(InvalidAccessError, "The document provided is invalid.");
1427 // Do any pending layout and compositing update (which may call touchEventTargetRectsChange) to ensure this
1428 // really takes any previous changes into account.
1429 forceCompositingUpdate(document, exceptionState);
1430 if (exceptionState.hadException())
1433 if (RenderView* view = document->renderView()) {
1434 if (RenderLayerCompositor* compositor = view->compositor()) {
1435 if (GraphicsLayer* rootLayer = compositor->rootGraphicsLayer()) {
1436 RefPtrWillBeRawPtr<LayerRectList> rects = LayerRectList::create();
1437 accumulateLayerRectList(compositor, rootLayer, rects.get());
1446 PassRefPtr<NodeList> Internals::nodesFromRect(Document* document, int centerX, int centerY, unsigned topPadding, unsigned rightPadding,
1447 unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent, ExceptionState& exceptionState) const
1449 if (!document || !document->frame() || !document->frame()->view()) {
1450 exceptionState.throwDOMException(InvalidAccessError, "No view can be obtained from the provided document.");
1454 LocalFrame* frame = document->frame();
1455 FrameView* frameView = document->view();
1456 RenderView* renderView = document->renderView();
1461 float zoomFactor = frame->pageZoomFactor();
1462 LayoutPoint point = roundedLayoutPoint(FloatPoint(centerX * zoomFactor + frameView->scrollX(), centerY * zoomFactor + frameView->scrollY()));
1464 HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly | HitTestRequest::Active;
1466 hitType |= HitTestRequest::IgnoreClipping;
1467 if (!allowShadowContent)
1468 hitType |= HitTestRequest::ConfusingAndOftenMisusedDisallowShadowContent;
1469 if (allowChildFrameContent)
1470 hitType |= HitTestRequest::AllowChildFrameContent;
1472 HitTestRequest request(hitType);
1474 // When ignoreClipping is false, this method returns null for coordinates outside of the viewport.
1475 if (!request.ignoreClipping() && !frameView->visibleContentRect().intersects(HitTestLocation::rectForPoint(point, topPadding, rightPadding, bottomPadding, leftPadding)))
1478 Vector<RefPtr<Node> > matches;
1480 // Need padding to trigger a rect based hit test, but we want to return a NodeList
1481 // so we special case this.
1482 if (!topPadding && !rightPadding && !bottomPadding && !leftPadding) {
1483 HitTestResult result(point);
1484 renderView->hitTest(request, result);
1485 if (result.innerNode())
1486 matches.append(result.innerNode()->deprecatedShadowAncestorNode());
1488 HitTestResult result(point, topPadding, rightPadding, bottomPadding, leftPadding);
1489 renderView->hitTest(request, result);
1490 copyToVector(result.rectBasedTestResult(), matches);
1493 return StaticNodeList::adopt(matches);
1496 void Internals::emitInspectorDidBeginFrame(int frameId)
1498 contextDocument()->page()->inspectorController().didBeginFrame(frameId);
1501 void Internals::emitInspectorDidCancelFrame()
1503 contextDocument()->page()->inspectorController().didCancelFrame();
1506 bool Internals::hasSpellingMarker(Document* document, int from, int length, ExceptionState&)
1508 if (!document || !document->frame())
1511 return document->frame()->spellChecker().selectionStartHasMarkerFor(DocumentMarker::Spelling, from, length);
1514 void Internals::setContinuousSpellCheckingEnabled(bool enabled, ExceptionState&)
1516 if (!contextDocument() || !contextDocument()->frame())
1519 if (enabled != contextDocument()->frame()->spellChecker().isContinuousSpellCheckingEnabled())
1520 contextDocument()->frame()->spellChecker().toggleContinuousSpellChecking();
1523 bool Internals::isOverwriteModeEnabled(Document* document, ExceptionState&)
1525 if (!document || !document->frame())
1528 return document->frame()->editor().isOverwriteModeEnabled();
1531 void Internals::toggleOverwriteModeEnabled(Document* document, ExceptionState&)
1533 if (!document || !document->frame())
1536 document->frame()->editor().toggleOverwriteModeEnabled();
1539 unsigned Internals::numberOfLiveNodes() const
1541 return InspectorCounters::counterValue(InspectorCounters::NodeCounter);
1544 unsigned Internals::numberOfLiveDocuments() const
1546 return InspectorCounters::counterValue(InspectorCounters::DocumentCounter);
1549 String Internals::dumpRefCountedInstanceCounts() const
1551 return WTF::dumpRefCountedInstanceCounts();
1554 Vector<String> Internals::consoleMessageArgumentCounts(Document* document) const
1556 InstrumentingAgents* instrumentingAgents = instrumentationForPage(document->page());
1557 if (!instrumentingAgents)
1558 return Vector<String>();
1559 InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent();
1561 return Vector<String>();
1562 Vector<unsigned> counts = consoleAgent->consoleMessageArgumentCounts();
1563 Vector<String> result(counts.size());
1564 for (size_t i = 0; i < counts.size(); i++)
1565 result[i] = String::number(counts[i]);
1569 Vector<unsigned long> Internals::setMemoryCacheCapacities(unsigned long minDeadBytes, unsigned long maxDeadBytes, unsigned long totalBytes)
1571 Vector<unsigned long> result;
1572 result.append(memoryCache()->minDeadCapacity());
1573 result.append(memoryCache()->maxDeadCapacity());
1574 result.append(memoryCache()->capacity());
1575 memoryCache()->setCapacities(minDeadBytes, maxDeadBytes, totalBytes);
1579 void Internals::setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionState& exceptionState)
1581 Page* page = contextDocument()->frame()->page();
1583 exceptionState.throwDOMException(InvalidAccessError, "No page can be obtained from the current context document.");
1586 page->inspectorController().setResourcesDataSizeLimitsFromInternals(maximumResourcesContentSize, maximumSingleResourceContentSize);
1589 bool Internals::hasGrammarMarker(Document* document, int from, int length, ExceptionState&)
1591 if (!document || !document->frame())
1594 return document->frame()->spellChecker().selectionStartHasMarkerFor(DocumentMarker::Grammar, from, length);
1597 unsigned Internals::numberOfScrollableAreas(Document* document, ExceptionState&)
1600 LocalFrame* frame = document->frame();
1601 if (frame->view()->scrollableAreas())
1602 count += frame->view()->scrollableAreas()->size();
1604 for (LocalFrame* child = frame->tree().firstChild(); child; child = child->tree().nextSibling()) {
1605 if (child->view() && child->view()->scrollableAreas())
1606 count += child->view()->scrollableAreas()->size();
1612 bool Internals::isPageBoxVisible(Document* document, int pageNumber, ExceptionState& exceptionState)
1615 exceptionState.throwDOMException(InvalidAccessError, "No context document is available.");
1619 return document->isPageBoxVisible(pageNumber);
1622 String Internals::layerTreeAsText(Document* document, ExceptionState& exceptionState) const
1624 return layerTreeAsText(document, 0, exceptionState);
1627 String Internals::elementLayerTreeAsText(Element* element, ExceptionState& exceptionState) const
1630 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
1634 FrameView* frameView = element->document().view();
1635 frameView->updateLayoutAndStyleForPainting();
1637 return elementLayerTreeAsText(element, 0, exceptionState);
1640 bool Internals::scrollsWithRespectTo(Element* element1, Element* element2, ExceptionState& exceptionState)
1642 if (!element1 || !element2) {
1643 exceptionState.throwDOMException(InvalidAccessError, String::format("The %s element provided is invalid.", element1 ? "second" : "first"));
1647 element1->document().updateLayout();
1649 RenderObject* renderer1 = element1->renderer();
1650 RenderObject* renderer2 = element2->renderer();
1651 if (!renderer1 || !renderer1->isBox()) {
1652 exceptionState.throwDOMException(InvalidAccessError, renderer1 ? "The first provided element's renderer is not a box." : "The first provided element has no renderer.");
1655 if (!renderer2 || !renderer2->isBox()) {
1656 exceptionState.throwDOMException(InvalidAccessError, renderer2 ? "The second provided element's renderer is not a box." : "The second provided element has no renderer.");
1660 RenderLayer* layer1 = toRenderBox(renderer1)->layer();
1661 RenderLayer* layer2 = toRenderBox(renderer2)->layer();
1662 if (!layer1 || !layer2) {
1663 exceptionState.throwDOMException(InvalidAccessError, String::format("No render layer can be obtained from the %s provided element.", layer1 ? "second" : "first"));
1667 return layer1->scrollsWithRespectTo(layer2);
1670 bool Internals::isUnclippedDescendant(Element* element, ExceptionState& exceptionState)
1673 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
1677 element->document().view()->updateLayoutAndStyleForPainting();
1679 RenderObject* renderer = element->renderer();
1680 if (!renderer || !renderer->isBox()) {
1681 exceptionState.throwDOMException(InvalidAccessError, renderer ? "The provided element's renderer is not a box." : "The provided element has no renderer.");
1685 RenderLayer* layer = toRenderBox(renderer)->layer();
1687 exceptionState.throwDOMException(InvalidAccessError, "No render layer can be obtained from the provided element.");
1691 return layer->isUnclippedDescendant();
1694 String Internals::layerTreeAsText(Document* document, unsigned flags, ExceptionState& exceptionState) const
1696 if (!document || !document->frame()) {
1697 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1701 document->view()->updateLayoutAndStyleForPainting();
1703 return document->frame()->layerTreeAsText(flags);
1706 String Internals::elementLayerTreeAsText(Element* element, unsigned flags, ExceptionState& exceptionState) const
1709 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
1713 element->document().updateLayout();
1715 RenderObject* renderer = element->renderer();
1716 if (!renderer || !renderer->isBox()) {
1717 exceptionState.throwDOMException(InvalidAccessError, renderer ? "The provided element's renderer is not a box." : "The provided element has no renderer.");
1721 RenderLayer* layer = toRenderBox(renderer)->layer();
1723 || !layer->hasCompositedLayerMapping()
1724 || !layer->compositedLayerMapping()->mainGraphicsLayer()) {
1725 // Don't raise exception in these cases which may be normally used in tests.
1729 return layer->compositedLayerMapping()->mainGraphicsLayer()->layerTreeAsText(flags);
1732 static RenderLayer* getRenderLayerForElement(Element* element, ExceptionState& exceptionState)
1735 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
1739 RenderObject* renderer = element->renderer();
1740 if (!renderer || !renderer->isBox()) {
1741 exceptionState.throwDOMException(InvalidAccessError, renderer ? "The provided element's renderer is not a box." : "The provided element has no renderer.");
1745 RenderLayer* layer = toRenderBox(renderer)->layer();
1747 exceptionState.throwDOMException(InvalidAccessError, "No render layer can be obtained from the provided element.");
1754 void Internals::setNeedsCompositedScrolling(Element* element, unsigned needsCompositedScrolling, ExceptionState& exceptionState)
1757 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
1761 element->document().updateLayout();
1763 if (RenderLayer* layer = getRenderLayerForElement(element, exceptionState))
1764 layer->scrollableArea()->setForceNeedsCompositedScrolling(static_cast<ForceNeedsCompositedScrollingMode>(needsCompositedScrolling));
1767 String Internals::repaintRectsAsText(Document* document, ExceptionState& exceptionState) const
1769 if (!document || !document->frame()) {
1770 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1774 return document->frame()->trackedRepaintRectsAsText();
1777 PassRefPtrWillBeRawPtr<ClientRectList> Internals::repaintRects(Element* element, ExceptionState& exceptionState) const
1780 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
1784 element->document().frame()->view()->updateLayoutAndStyleForPainting();
1786 if (RenderLayer* layer = getRenderLayerForElement(element, exceptionState)) {
1787 if (layer->compositingState() == PaintsIntoOwnBacking) {
1788 OwnPtr<Vector<FloatRect> > rects = layer->collectTrackedRepaintRects();
1789 ASSERT(rects.get());
1790 Vector<FloatQuad> quads(rects->size());
1791 for (size_t i = 0; i < rects->size(); ++i)
1792 quads[i] = FloatRect(rects->at(i));
1793 return ClientRectList::create(quads);
1797 exceptionState.throwDOMException(InvalidAccessError, "The provided element is not composited.");
1801 String Internals::scrollingStateTreeAsText(Document* document, ExceptionState& exceptionState) const
1806 String Internals::mainThreadScrollingReasons(Document* document, ExceptionState& exceptionState) const
1808 if (!document || !document->frame()) {
1809 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1813 document->frame()->view()->updateLayoutAndStyleForPainting();
1815 Page* page = document->page();
1819 return page->mainThreadScrollingReasonsAsText();
1822 PassRefPtrWillBeRawPtr<ClientRectList> Internals::nonFastScrollableRects(Document* document, ExceptionState& exceptionState) const
1824 if (!document || !document->frame()) {
1825 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
1829 Page* page = document->page();
1833 return page->nonFastScrollableRects(document->frame());
1836 void Internals::garbageCollectDocumentResources(Document* document, ExceptionState& exceptionState) const
1839 exceptionState.throwDOMException(InvalidAccessError, "No context document is available.");
1842 ResourceFetcher* fetcher = document->fetcher();
1845 fetcher->garbageCollectDocumentResources();
1848 void Internals::evictAllResources() const
1850 memoryCache()->evictResources();
1853 void Internals::allowRoundingHacks() const
1855 TextRun::setAllowsRoundingHacks(true);
1858 String Internals::counterValue(Element* element)
1863 return counterValueForElement(element);
1866 int Internals::pageNumber(Element* element, float pageWidth, float pageHeight)
1871 return PrintContext::pageNumberForElement(element, FloatSize(pageWidth, pageHeight));
1874 Vector<String> Internals::iconURLs(Document* document, int iconTypesMask) const
1876 Vector<IconURL> iconURLs = document->iconURLs(iconTypesMask);
1877 Vector<String> array;
1879 Vector<IconURL>::const_iterator iter(iconURLs.begin());
1880 for (; iter != iconURLs.end(); ++iter)
1881 array.append(iter->m_iconURL.string());
1886 Vector<String> Internals::shortcutIconURLs(Document* document) const
1888 return iconURLs(document, Favicon);
1891 Vector<String> Internals::allIconURLs(Document* document) const
1893 return iconURLs(document, Favicon | TouchIcon | TouchPrecomposedIcon);
1896 int Internals::numberOfPages(float pageWidth, float pageHeight)
1901 return PrintContext::numberOfPages(frame(), FloatSize(pageWidth, pageHeight));
1904 String Internals::pageProperty(String propertyName, int pageNumber, ExceptionState& exceptionState) const
1907 exceptionState.throwDOMException(InvalidAccessError, "No frame is available.");
1911 return PrintContext::pageProperty(frame(), propertyName.utf8().data(), pageNumber);
1914 String Internals::pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft, ExceptionState& exceptionState) const
1917 exceptionState.throwDOMException(InvalidAccessError, "No frame is available.");
1921 return PrintContext::pageSizeAndMarginsInPixels(frame(), pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft);
1924 void Internals::setDeviceScaleFactor(float scaleFactor, ExceptionState& exceptionState)
1926 Document* document = contextDocument();
1927 if (!document || !document->page()) {
1928 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's page cannot be retrieved." : "No context document can be obtained.");
1931 Page* page = document->page();
1932 page->setDeviceScaleFactor(scaleFactor);
1935 void Internals::setIsCursorVisible(Document* document, bool isVisible, ExceptionState& exceptionState)
1937 if (!document || !document->page()) {
1938 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's page cannot be retrieved." : "No context document can be obtained.");
1941 document->page()->setIsCursorVisible(isVisible);
1944 void Internals::webkitWillEnterFullScreenForElement(Document* document, Element* element)
1948 FullscreenElementStack::from(*document).webkitWillEnterFullScreenForElement(element);
1951 void Internals::webkitDidEnterFullScreenForElement(Document* document, Element* element)
1955 FullscreenElementStack::from(*document).webkitDidEnterFullScreenForElement(element);
1958 void Internals::webkitWillExitFullScreenForElement(Document* document, Element* element)
1962 FullscreenElementStack::from(*document).webkitWillExitFullScreenForElement(element);
1965 void Internals::webkitDidExitFullScreenForElement(Document* document, Element* element)
1969 FullscreenElementStack::from(*document).webkitDidExitFullScreenForElement(element);
1972 void Internals::mediaPlayerRequestFullscreen(HTMLMediaElement* mediaElement)
1974 mediaElement->mediaPlayerRequestFullscreen();
1977 void Internals::registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme)
1979 SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy(scheme);
1982 void Internals::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme)
1984 SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(scheme);
1987 PassRefPtrWillBeRawPtr<MallocStatistics> Internals::mallocStatistics() const
1989 return MallocStatistics::create();
1992 PassRefPtrWillBeRawPtr<TypeConversions> Internals::typeConversions() const
1994 return TypeConversions::create();
1997 Vector<String> Internals::getReferencedFilePaths() const
1999 return frame()->loader().currentItem()->getReferencedFilePaths();
2002 void Internals::startTrackingRepaints(Document* document, ExceptionState& exceptionState)
2004 if (!document || !document->view()) {
2005 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's view cannot be retrieved." : "The document provided is invalid.");
2009 FrameView* frameView = document->view();
2010 frameView->updateLayoutAndStyleForPainting();
2011 frameView->setTracksRepaints(true);
2014 void Internals::stopTrackingRepaints(Document* document, ExceptionState& exceptionState)
2016 if (!document || !document->view()) {
2017 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's view cannot be retrieved." : "The document provided is invalid.");
2021 FrameView* frameView = document->view();
2022 frameView->updateLayoutAndStyleForPainting();
2023 frameView->setTracksRepaints(false);
2026 void Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionState& exceptionState)
2028 updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(0, exceptionState);
2031 void Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node* node, ExceptionState& exceptionState)
2035 document = contextDocument();
2036 } else if (node->isDocumentNode()) {
2037 document = toDocument(node);
2038 } else if (isHTMLIFrameElement(*node)) {
2039 document = toHTMLIFrameElement(*node).contentDocument();
2041 exceptionState.throwTypeError("The node provided is neither a document nor an IFrame.");
2044 document->updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasksSynchronously);
2047 PassRefPtrWillBeRawPtr<ClientRectList> Internals::draggableRegions(Document* document, ExceptionState& exceptionState)
2049 return annotatedRegions(document, true, exceptionState);
2052 PassRefPtrWillBeRawPtr<ClientRectList> Internals::nonDraggableRegions(Document* document, ExceptionState& exceptionState)
2054 return annotatedRegions(document, false, exceptionState);
2057 PassRefPtrWillBeRawPtr<ClientRectList> Internals::annotatedRegions(Document* document, bool draggable, ExceptionState& exceptionState)
2059 if (!document || !document->view()) {
2060 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's view cannot be retrieved." : "The document provided is invalid.");
2061 return ClientRectList::create();
2064 document->updateLayout();
2065 document->view()->updateAnnotatedRegions();
2066 Vector<AnnotatedRegionValue> regions = document->annotatedRegions();
2068 Vector<FloatQuad> quads;
2069 for (size_t i = 0; i < regions.size(); ++i) {
2070 if (regions[i].draggable == draggable)
2071 quads.append(FloatQuad(regions[i].bounds));
2073 return ClientRectList::create(quads);
2076 static const char* cursorTypeToString(Cursor::Type cursorType)
2078 switch (cursorType) {
2079 case Cursor::Pointer: return "Pointer";
2080 case Cursor::Cross: return "Cross";
2081 case Cursor::Hand: return "Hand";
2082 case Cursor::IBeam: return "IBeam";
2083 case Cursor::Wait: return "Wait";
2084 case Cursor::Help: return "Help";
2085 case Cursor::EastResize: return "EastResize";
2086 case Cursor::NorthResize: return "NorthResize";
2087 case Cursor::NorthEastResize: return "NorthEastResize";
2088 case Cursor::NorthWestResize: return "NorthWestResize";
2089 case Cursor::SouthResize: return "SouthResize";
2090 case Cursor::SouthEastResize: return "SouthEastResize";
2091 case Cursor::SouthWestResize: return "SouthWestResize";
2092 case Cursor::WestResize: return "WestResize";
2093 case Cursor::NorthSouthResize: return "NorthSouthResize";
2094 case Cursor::EastWestResize: return "EastWestResize";
2095 case Cursor::NorthEastSouthWestResize: return "NorthEastSouthWestResize";
2096 case Cursor::NorthWestSouthEastResize: return "NorthWestSouthEastResize";
2097 case Cursor::ColumnResize: return "ColumnResize";
2098 case Cursor::RowResize: return "RowResize";
2099 case Cursor::MiddlePanning: return "MiddlePanning";
2100 case Cursor::EastPanning: return "EastPanning";
2101 case Cursor::NorthPanning: return "NorthPanning";
2102 case Cursor::NorthEastPanning: return "NorthEastPanning";
2103 case Cursor::NorthWestPanning: return "NorthWestPanning";
2104 case Cursor::SouthPanning: return "SouthPanning";
2105 case Cursor::SouthEastPanning: return "SouthEastPanning";
2106 case Cursor::SouthWestPanning: return "SouthWestPanning";
2107 case Cursor::WestPanning: return "WestPanning";
2108 case Cursor::Move: return "Move";
2109 case Cursor::VerticalText: return "VerticalText";
2110 case Cursor::Cell: return "Cell";
2111 case Cursor::ContextMenu: return "ContextMenu";
2112 case Cursor::Alias: return "Alias";
2113 case Cursor::Progress: return "Progress";
2114 case Cursor::NoDrop: return "NoDrop";
2115 case Cursor::Copy: return "Copy";
2116 case Cursor::None: return "None";
2117 case Cursor::NotAllowed: return "NotAllowed";
2118 case Cursor::ZoomIn: return "ZoomIn";
2119 case Cursor::ZoomOut: return "ZoomOut";
2120 case Cursor::Grab: return "Grab";
2121 case Cursor::Grabbing: return "Grabbing";
2122 case Cursor::Custom: return "Custom";
2125 ASSERT_NOT_REACHED();
2129 String Internals::getCurrentCursorInfo(Document* document, ExceptionState& exceptionState)
2131 if (!document || !document->frame()) {
2132 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "The document provided is invalid.");
2136 Cursor cursor = document->frame()->eventHandler().currentMouseCursor();
2138 StringBuilder result;
2139 result.append("type=");
2140 result.append(cursorTypeToString(cursor.type()));
2141 result.append(" hotSpot=");
2142 result.appendNumber(cursor.hotSpot().x());
2144 result.appendNumber(cursor.hotSpot().y());
2145 if (cursor.image()) {
2146 IntSize size = cursor.image()->size();
2147 result.append(" image=");
2148 result.appendNumber(size.width());
2150 result.appendNumber(size.height());
2152 if (cursor.imageScaleFactor() != 1) {
2153 result.append(" scale=");
2154 NumberToStringBuffer buffer;
2155 result.append(numberToFixedPrecisionString(cursor.imageScaleFactor(), 8, buffer, true));
2158 return result.toString();
2161 PassRefPtr<ArrayBuffer> Internals::serializeObject(PassRefPtr<SerializedScriptValue> value) const
2163 String stringValue = value->toWireString();
2164 RefPtr<ArrayBuffer> buffer = ArrayBuffer::createUninitialized(stringValue.length(), sizeof(UChar));
2165 stringValue.copyTo(static_cast<UChar*>(buffer->data()), 0, stringValue.length());
2166 return buffer.release();
2169 PassRefPtr<SerializedScriptValue> Internals::deserializeBuffer(PassRefPtr<ArrayBuffer> buffer) const
2171 String value(static_cast<const UChar*>(buffer->data()), buffer->byteLength() / sizeof(UChar));
2172 return SerializedScriptValue::createFromWire(value);
2175 void Internals::forceReload(bool endToEnd)
2177 frame()->loader().reload(endToEnd ? EndToEndReload : NormalReload);
2180 PassRefPtrWillBeRawPtr<ClientRect> Internals::selectionBounds(ExceptionState& exceptionState)
2182 Document* document = contextDocument();
2183 if (!document || !document->frame()) {
2184 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's frame cannot be retrieved." : "No context document can be obtained.");
2188 return ClientRect::create(document->frame()->selection().bounds());
2191 String Internals::markerTextForListItem(Element* element, ExceptionState& exceptionState)
2194 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
2197 return WebCore::markerTextForListItem(element);
2200 String Internals::getImageSourceURL(Element* element, ExceptionState& exceptionState)
2203 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
2206 return element->imageSourceURL();
2209 String Internals::baseURL(Document* document, ExceptionState& exceptionState)
2212 exceptionState.throwDOMException(InvalidAccessError, "No context document is available.");
2216 return document->baseURL().string();
2219 bool Internals::isSelectPopupVisible(Node* node)
2222 if (!isHTMLSelectElement(*node))
2225 HTMLSelectElement& select = toHTMLSelectElement(*node);
2227 RenderObject* renderer = select.renderer();
2228 if (!renderer->isMenuList())
2231 RenderMenuList* menuList = toRenderMenuList(renderer);
2232 return menuList->popupIsVisible();
2235 bool Internals::loseSharedGraphicsContext3D()
2237 OwnPtr<blink::WebGraphicsContext3DProvider> sharedProvider = adoptPtr(blink::Platform::current()->createSharedOffscreenGraphicsContext3DProvider());
2238 if (!sharedProvider)
2240 blink::WebGraphicsContext3D* sharedContext = sharedProvider->context3d();
2241 sharedContext->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_EXT, GL_INNOCENT_CONTEXT_RESET_EXT);
2242 // To prevent tests that call loseSharedGraphicsContext3D from being
2243 // flaky, we call finish so that the context is guaranteed to be lost
2244 // synchronously (i.e. before returning).
2245 sharedContext->finish();
2249 void Internals::forceCompositingUpdate(Document* document, ExceptionState& exceptionState)
2251 // Hit when running content_shell with --expose-internals-for-testing.
2252 DisableCompositingQueryAsserts disabler;
2254 if (!document || !document->renderView()) {
2255 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's render view cannot be retrieved." : "The document provided is invalid.");
2259 document->frame()->view()->updateLayoutAndStyleForPainting();
2262 bool Internals::isCompositorFramePending(Document* document, ExceptionState& exceptionState)
2264 if (!document || !document->renderView()) {
2265 exceptionState.throwDOMException(InvalidAccessError, document ? "The document's render view cannot be retrieved." : "The document provided is invalid.");
2269 return document->page()->chrome().client().isCompositorFramePending();
2272 void Internals::setZoomFactor(float factor)
2274 frame()->setPageZoomFactor(factor);
2277 void Internals::setShouldRevealPassword(Element* element, bool reveal, ExceptionState& exceptionState)
2279 if (!isHTMLInputElement(element)) {
2280 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "Element"));
2284 return toHTMLInputElement(*element).setShouldRevealPassword(reveal);
2289 class AddOneFunction : public ScriptFunction {
2291 static PassOwnPtr<ScriptFunction> create(ExecutionContext* context)
2293 return adoptPtr(new AddOneFunction(toIsolate(context)));
2297 AddOneFunction(v8::Isolate* isolate)
2298 : ScriptFunction(isolate)
2302 virtual ScriptValue call(ScriptValue value) OVERRIDE
2304 v8::Local<v8::Value> v8Value = value.v8Value();
2305 v8::Isolate* isolate = value.isolate();
2306 ASSERT(v8Value->IsNumber());
2307 int intValue = v8Value.As<v8::Integer>()->Value();
2308 ScriptValue result = ScriptValue(v8::Integer::New(isolate, intValue + 1), isolate);
2315 ScriptPromise Internals::createPromise(ScriptState* scriptState)
2317 return ScriptPromiseResolver::create(scriptState)->promise();
2320 ScriptPromise Internals::createResolvedPromise(ScriptState* scriptState, ScriptValue value)
2322 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
2323 ScriptPromise promise = resolver->promise();
2324 resolver->resolve(value);
2328 ScriptPromise Internals::createRejectedPromise(ScriptState* scriptState, ScriptValue value)
2330 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
2331 ScriptPromise promise = resolver->promise();
2332 resolver->reject(value);
2336 ScriptPromise Internals::addOneToPromise(ExecutionContext* context, ScriptPromise promise)
2338 return promise.then(AddOneFunction::create(context));
2341 void Internals::trace(Visitor* visitor)
2343 visitor->trace(m_runtimeFlags);
2344 visitor->trace(m_profilers);
2347 void Internals::setValueForUser(Element* element, const String& value)
2349 toHTMLInputElement(element)->setValueForUser(value);
2352 String Internals::textSurroundingNode(Node* node, int x, int y, unsigned long maxLength)
2356 blink::WebPoint point(x, y);
2357 SurroundingText surroundingText(VisiblePosition(node->renderer()->positionForPoint(static_cast<IntPoint>(point))), maxLength);
2358 return surroundingText.content();