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 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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"
30 #include "AnimationController.h"
31 #include "BackForwardController.h"
32 #include "CachedResourceLoader.h"
34 #include "ChromeClient.h"
35 #include "ClientRect.h"
36 #include "ClientRectList.h"
37 #include "ComposedShadowTreeWalker.h"
38 #include "ContentDistributor.h"
40 #include "DOMStringList.h"
41 #include "DOMWindow.h"
43 #include "DocumentMarker.h"
44 #include "DocumentMarkerController.h"
47 #include "ElementShadow.h"
48 #include "EventHandler.h"
49 #include "ExceptionCode.h"
50 #include "FormController.h"
52 #include "FrameLoader.h"
53 #include "FrameView.h"
54 #include "HTMLContentElement.h"
55 #include "HTMLInputElement.h"
56 #include "HTMLNames.h"
57 #include "HTMLSelectElement.h"
58 #include "HTMLTextAreaElement.h"
59 #include "HistoryController.h"
60 #include "HistoryItem.h"
61 #include "InspectorClient.h"
62 #include "InspectorConsoleAgent.h"
63 #include "InspectorController.h"
64 #include "InspectorCounters.h"
65 #include "InspectorFrontendChannel.h"
66 #include "InspectorFrontendClientLocal.h"
67 #include "InspectorInstrumentation.h"
68 #include "InspectorOverlay.h"
69 #include "InstrumentingAgents.h"
70 #include "InternalSettings.h"
73 #include "MallocStatistics.h"
74 #include "MemoryCache.h"
75 #include "MockPagePopupDriver.h"
76 #include "NodeRenderingContext.h"
78 #include "PrintContext.h"
79 #include "PseudoElement.h"
81 #include "RenderMenuList.h"
82 #include "RenderObject.h"
83 #include "RenderTreeAsText.h"
84 #include "RenderView.h"
85 #include "RuntimeEnabledFeatures.h"
86 #include "SchemeRegistry.h"
87 #include "ScrollingCoordinator.h"
88 #include "SerializedScriptValue.h"
90 #include "ShadowRoot.h"
91 #include "SpellChecker.h"
92 #include "StaticNodeList.h"
93 #include "StyleSheetContents.h"
94 #include "TextIterator.h"
95 #include "TreeScope.h"
96 #include "TypeConversions.h"
97 #include "ViewportArguments.h"
98 #include "WorkerThread.h"
99 #include <wtf/text/CString.h>
100 #include <wtf/text/StringBuffer.h>
102 #if ENABLE(INPUT_TYPE_COLOR)
103 #include "ColorChooser.h"
106 #if ENABLE(BATTERY_STATUS)
107 #include "BatteryController.h"
110 #if ENABLE(NETWORK_INFO)
111 #include "NetworkInfo.h"
112 #include "NetworkInfoController.h"
115 #if ENABLE(PROXIMITY_EVENTS)
116 #include "DeviceProximityController.h"
119 #if ENABLE(PAGE_POPUP)
120 #include "PagePopupController.h"
123 #if ENABLE(TOUCH_ADJUSTMENT)
124 #include "WebKitPoint.h"
127 #if ENABLE(MOUSE_CURSOR_SCALE)
128 #include <wtf/dtoa.h>
131 #if ENABLE(ENCRYPTED_MEDIA_V2)
136 #if ENABLE(VIDEO_TRACK)
137 #include "CaptionUserPreferences.h"
138 #include "PageGroup.h"
142 #include "HTMLMediaElement.h"
143 #include "TimeRanges.h"
146 #if ENABLE(SPEECH_SYNTHESIS)
147 #include "DOMWindowSpeechSynthesis.h"
148 #include "PlatformSpeechSynthesizerMock.h"
149 #include "SpeechSynthesis.h"
154 #if ENABLE(PAGE_POPUP)
155 static MockPagePopupDriver* s_pagePopupDriver = 0;
158 using namespace HTMLNames;
160 #if ENABLE(INSPECTOR)
161 class InspectorFrontendClientDummy : public InspectorFrontendClientLocal {
163 InspectorFrontendClientDummy(InspectorController*, Page*);
164 virtual ~InspectorFrontendClientDummy() { }
165 virtual void attachWindow(DockSide) OVERRIDE { }
166 virtual void detachWindow() OVERRIDE { }
168 virtual String localizedStringsURL() OVERRIDE { return String(); }
170 virtual void bringToFront() OVERRIDE { }
171 virtual void closeWindow() OVERRIDE { }
173 virtual void inspectedURLChanged(const String&) OVERRIDE { }
176 virtual void setAttachedWindowHeight(unsigned) OVERRIDE { }
177 virtual void setAttachedWindowWidth(unsigned) OVERRIDE { }
178 virtual void setToolbarHeight(unsigned) OVERRIDE { }
181 InspectorFrontendClientDummy::InspectorFrontendClientDummy(InspectorController* controller, Page* page)
182 : InspectorFrontendClientLocal(controller, page, adoptPtr(new InspectorFrontendClientLocal::Settings()))
186 class InspectorFrontendChannelDummy : public InspectorFrontendChannel {
188 explicit InspectorFrontendChannelDummy(Page*);
189 virtual ~InspectorFrontendChannelDummy() { }
190 virtual bool sendMessageToFrontend(const String& message) OVERRIDE;
193 Page* m_frontendPage;
196 InspectorFrontendChannelDummy::InspectorFrontendChannelDummy(Page* page)
197 : m_frontendPage(page)
201 bool InspectorFrontendChannelDummy::sendMessageToFrontend(const String& message)
203 return InspectorClient::doDispatchMessageOnFrontendPage(m_frontendPage, message);
205 #endif // ENABLE(INSPECTOR)
207 static bool markerTypesFrom(const String& markerType, DocumentMarker::MarkerTypes& result)
209 if (markerType.isEmpty() || equalIgnoringCase(markerType, "all"))
210 result = DocumentMarker::AllMarkers();
211 else if (equalIgnoringCase(markerType, "Spelling"))
212 result = DocumentMarker::Spelling;
213 else if (equalIgnoringCase(markerType, "Grammar"))
214 result = DocumentMarker::Grammar;
215 else if (equalIgnoringCase(markerType, "TextMatch"))
216 result = DocumentMarker::TextMatch;
217 else if (equalIgnoringCase(markerType, "Replacement"))
218 result = DocumentMarker::Replacement;
219 else if (equalIgnoringCase(markerType, "CorrectionIndicator"))
220 result = DocumentMarker::CorrectionIndicator;
221 else if (equalIgnoringCase(markerType, "RejectedCorrection"))
222 result = DocumentMarker::RejectedCorrection;
223 else if (equalIgnoringCase(markerType, "Autocorrected"))
224 result = DocumentMarker::Autocorrected;
225 else if (equalIgnoringCase(markerType, "SpellCheckingExemption"))
226 result = DocumentMarker::SpellCheckingExemption;
227 else if (equalIgnoringCase(markerType, "DeletedAutocorrection"))
228 result = DocumentMarker::DeletedAutocorrection;
229 else if (equalIgnoringCase(markerType, "DictationAlternatives"))
230 result = DocumentMarker::DictationAlternatives;
237 static SpellChecker* spellchecker(Document* document)
239 if (!document || !document->frame())
242 return document->frame()->editor().spellChecker();
245 const char* Internals::internalsId = "internals";
247 PassRefPtr<Internals> Internals::create(Document* document)
249 return adoptRef(new Internals(document));
252 Internals::~Internals()
256 void Internals::resetToConsistentState(Page* page)
260 page->setPageScaleFactor(1, IntPoint(0, 0));
261 page->setPagination(Pagination());
263 #if USE(ACCELERATED_COMPOSITING)
264 FrameView* mainFrameView = page->mainFrame()->view();
266 mainFrameView->setHeaderHeight(0);
267 mainFrameView->setFooterHeight(0);
270 TextRun::setAllowsRoundingHacks(false);
271 WebCore::overrideUserPreferredLanguages(Vector<String>());
272 WebCore::Settings::setUsesOverlayScrollbars(false);
273 #if ENABLE(PAGE_POPUP)
274 delete s_pagePopupDriver;
275 s_pagePopupDriver = 0;
276 page->chrome().client()->resetPagePopupDriver();
278 #if ENABLE(INSPECTOR) && ENABLE(JAVASCRIPT_DEBUGGER)
279 if (page->inspectorController())
280 page->inspectorController()->setProfilerEnabled(false);
282 #if ENABLE(VIDEO_TRACK) && !PLATFORM(WIN)
283 page->group().captionPreferences()->setCaptionsStyleSheetOverride(emptyString());
284 page->group().captionPreferences()->setTestingMode(false);
286 if (!page->mainFrame()->editor().isContinuousSpellCheckingEnabled())
287 page->mainFrame()->editor().toggleContinuousSpellChecking();
289 #if USE(AUTOMATIC_TEXT_REPLACEMENT)
290 if (page->mainFrame()->editor().isAutomaticQuoteSubstitutionEnabled())
291 page->mainFrame()->editor().toggleAutomaticQuoteSubstitution();
292 if (page->mainFrame()->editor().isAutomaticLinkDetectionEnabled())
293 page->mainFrame()->editor().toggleAutomaticLinkDetection();
294 if (page->mainFrame()->editor().isAutomaticDashSubstitutionEnabled())
295 page->mainFrame()->editor().toggleAutomaticDashSubstitution();
296 if (page->mainFrame()->editor().isAutomaticTextReplacementEnabled())
297 page->mainFrame()->editor().toggleAutomaticTextReplacement();
298 if (!page->mainFrame()->editor().isAutomaticSpellingCorrectionEnabled())
299 page->mainFrame()->editor().toggleAutomaticSpellingCorrection();
302 if (page->mainFrame()->editor().isOverwriteModeEnabled())
303 page->mainFrame()->editor().toggleOverwriteModeEnabled();
306 Internals::Internals(Document* document)
307 : ContextDestructionObserver(document)
309 #if ENABLE(VIDEO_TRACK) && !PLATFORM(WIN)
310 if (document && document->page())
311 document->page()->group().captionPreferences()->setTestingMode(true);
315 Document* Internals::contextDocument() const
317 return toDocument(scriptExecutionContext());
320 Frame* Internals::frame() const
322 if (!contextDocument())
324 return contextDocument()->frame();
327 InternalSettings* Internals::settings() const
329 Document* document = contextDocument();
332 Page* page = document->page();
335 return InternalSettings::from(page);
338 unsigned Internals::workerThreadCount() const
341 return WorkerThread::workerThreadCount();
347 String Internals::address(Node* node)
350 sprintf(buf, "%p", node);
355 bool Internals::isPreloaded(const String& url)
357 Document* document = contextDocument();
358 return document->cachedResourceLoader()->isPreloaded(url);
361 bool Internals::isLoadingFromMemoryCache(const String& url)
363 if (!contextDocument())
365 CachedResource* resource = memoryCache()->resourceForURL(contextDocument()->completeURL(url));
366 return resource && resource->status() == CachedResource::Cached;
369 PassRefPtr<Element> Internals::createContentElement(ExceptionCode& ec)
371 Document* document = contextDocument();
373 ec = INVALID_ACCESS_ERR;
377 #if ENABLE(SHADOW_DOM)
378 return HTMLContentElement::create(document);
384 bool Internals::isValidContentSelect(Element* insertionPoint, ExceptionCode& ec)
386 if (!insertionPoint || !insertionPoint->isInsertionPoint()) {
387 ec = INVALID_ACCESS_ERR;
391 #if ENABLE(SHADOW_DOM)
392 return isHTMLContentElement(insertionPoint) && toHTMLContentElement(insertionPoint)->isSelectValid();
398 Node* Internals::treeScopeRootNode(Node* node, ExceptionCode& ec)
401 ec = INVALID_ACCESS_ERR;
405 return node->treeScope()->rootNode();
408 Node* Internals::parentTreeScope(Node* node, ExceptionCode& ec)
411 ec = INVALID_ACCESS_ERR;
414 const TreeScope* parentTreeScope = node->treeScope()->parentTreeScope();
415 return parentTreeScope ? parentTreeScope->rootNode() : 0;
418 unsigned Internals::numberOfActiveAnimations() const
420 Frame* contextFrame = frame();
421 if (AnimationController* controller = contextFrame->animation())
422 return controller->numberOfActiveAnimations(contextFrame->document());
426 bool Internals::animationsAreSuspended(Document* document, ExceptionCode& ec) const
428 if (!document || !document->frame()) {
429 ec = INVALID_ACCESS_ERR;
433 AnimationController* controller = document->frame()->animation();
437 return controller->isSuspended();
440 void Internals::suspendAnimations(Document* document, ExceptionCode& ec) const
442 if (!document || !document->frame()) {
443 ec = INVALID_ACCESS_ERR;
447 AnimationController* controller = document->frame()->animation();
451 controller->suspendAnimations();
454 void Internals::resumeAnimations(Document* document, ExceptionCode& ec) const
456 if (!document || !document->frame()) {
457 ec = INVALID_ACCESS_ERR;
461 AnimationController* controller = document->frame()->animation();
465 controller->resumeAnimations();
468 bool Internals::pauseAnimationAtTimeOnElement(const String& animationName, double pauseTime, Element* element, ExceptionCode& ec)
470 if (!element || pauseTime < 0) {
471 ec = INVALID_ACCESS_ERR;
474 AnimationController* controller = frame()->animation();
475 return controller->pauseAnimationAtTime(element->renderer(), AtomicString(animationName), pauseTime);
478 bool Internals::pauseAnimationAtTimeOnPseudoElement(const String& animationName, double pauseTime, Element* element, const String& pseudoId, ExceptionCode& ec)
480 if (!element || pauseTime < 0) {
481 ec = INVALID_ACCESS_ERR;
485 if (pseudoId != "before" && pseudoId != "after") {
486 ec = INVALID_ACCESS_ERR;
490 PseudoElement* pseudoElement = element->pseudoElement(pseudoId == "before" ? BEFORE : AFTER);
491 if (!pseudoElement) {
492 ec = INVALID_ACCESS_ERR;
496 return frame()->animation()->pauseAnimationAtTime(pseudoElement->renderer(), AtomicString(animationName), pauseTime);
499 bool Internals::pauseTransitionAtTimeOnElement(const String& propertyName, double pauseTime, Element* element, ExceptionCode& ec)
501 if (!element || pauseTime < 0) {
502 ec = INVALID_ACCESS_ERR;
505 AnimationController* controller = frame()->animation();
506 return controller->pauseTransitionAtTime(element->renderer(), propertyName, pauseTime);
509 bool Internals::pauseTransitionAtTimeOnPseudoElement(const String& property, double pauseTime, Element* element, const String& pseudoId, ExceptionCode& ec)
511 if (!element || pauseTime < 0) {
512 ec = INVALID_ACCESS_ERR;
516 if (pseudoId != "before" && pseudoId != "after") {
517 ec = INVALID_ACCESS_ERR;
521 PseudoElement* pseudoElement = element->pseudoElement(pseudoId == "before" ? BEFORE : AFTER);
522 if (!pseudoElement) {
523 ec = INVALID_ACCESS_ERR;
527 return frame()->animation()->pauseTransitionAtTime(pseudoElement->renderer(), property, pauseTime);
530 bool Internals::attached(Node* node, ExceptionCode& ec)
533 ec = INVALID_ACCESS_ERR;
537 return node->attached();
540 Node* Internals::nextSiblingByWalker(Node* node, ExceptionCode& ec)
543 ec = INVALID_ACCESS_ERR;
546 ComposedShadowTreeWalker walker(node);
547 walker.nextSibling();
551 Node* Internals::firstChildByWalker(Node* node, ExceptionCode& ec)
554 ec = INVALID_ACCESS_ERR;
557 ComposedShadowTreeWalker walker(node);
562 Node* Internals::lastChildByWalker(Node* node, ExceptionCode& ec)
565 ec = INVALID_ACCESS_ERR;
568 ComposedShadowTreeWalker walker(node);
573 Node* Internals::nextNodeByWalker(Node* node, ExceptionCode& ec)
576 ec = INVALID_ACCESS_ERR;
579 ComposedShadowTreeWalker walker(node);
584 Node* Internals::previousNodeByWalker(Node* node, ExceptionCode& ec)
587 ec = INVALID_ACCESS_ERR;
590 ComposedShadowTreeWalker walker(node);
595 String Internals::elementRenderTreeAsText(Element* element, ExceptionCode& ec)
598 ec = INVALID_ACCESS_ERR;
602 String representation = externalRepresentation(element);
603 if (representation.isEmpty()) {
604 ec = INVALID_ACCESS_ERR;
608 return representation;
611 size_t Internals::numberOfScopedHTMLStyleChildren(const Node* scope, ExceptionCode& ec) const
613 if (scope && (scope->isElementNode() || scope->isShadowRoot()))
614 #if ENABLE(STYLE_SCOPED)
615 return scope->numberOfScopedHTMLStyleChildren();
620 ec = INVALID_ACCESS_ERR;
624 PassRefPtr<CSSComputedStyleDeclaration> Internals::computedStyleIncludingVisitedInfo(Node* node, ExceptionCode& ec) const
627 ec = INVALID_ACCESS_ERR;
631 bool allowVisitedStyle = true;
632 return CSSComputedStyleDeclaration::create(node, allowVisitedStyle);
635 Internals::ShadowRootIfShadowDOMEnabledOrNode* Internals::ensureShadowRoot(Element* host, ExceptionCode& ec)
638 ec = INVALID_ACCESS_ERR;
642 if (ElementShadow* shadow = host->shadow())
643 return shadow->shadowRoot();
645 return host->createShadowRoot(ec).get();
648 Internals::ShadowRootIfShadowDOMEnabledOrNode* Internals::createShadowRoot(Element* host, ExceptionCode& ec)
651 ec = INVALID_ACCESS_ERR;
654 return host->createShadowRoot(ec).get();
657 Internals::ShadowRootIfShadowDOMEnabledOrNode* Internals::shadowRoot(Element* host, ExceptionCode& ec)
660 ec = INVALID_ACCESS_ERR;
663 if (ElementShadow* shadow = host->shadow())
664 return shadow->shadowRoot();
668 String Internals::shadowRootType(const Node* root, ExceptionCode& ec) const
670 if (!root || !root->isShadowRoot()) {
671 ec = INVALID_ACCESS_ERR;
675 switch (toShadowRoot(root)->type()) {
676 case ShadowRoot::UserAgentShadowRoot:
677 return String("UserAgentShadowRoot");
678 case ShadowRoot::AuthorShadowRoot:
679 return String("AuthorShadowRoot");
681 ASSERT_NOT_REACHED();
682 return String("Unknown");
686 Element* Internals::includerFor(Node* node, ExceptionCode& ec)
689 ec = INVALID_ACCESS_ERR;
693 return NodeRenderingContext(node).insertionPoint();
696 String Internals::shadowPseudoId(Element* element, ExceptionCode& ec)
699 ec = INVALID_ACCESS_ERR;
703 return element->shadowPseudoId().string();
706 void Internals::setShadowPseudoId(Element* element, const String& id, ExceptionCode& ec)
709 ec = INVALID_ACCESS_ERR;
713 return element->setPseudo(id);
716 String Internals::visiblePlaceholder(Element* element)
718 if (element && isHTMLTextFormControlElement(element)) {
719 if (toHTMLTextFormControlElement(element)->placeholderShouldBeVisible())
720 return toHTMLTextFormControlElement(element)->placeholderElement()->textContent();
726 #if ENABLE(INPUT_TYPE_COLOR)
727 void Internals::selectColorInColorChooser(Element* element, const String& colorValue)
729 if (!element->hasTagName(inputTag))
731 HTMLInputElement* inputElement = element->toInputElement();
734 inputElement->selectColorInColorChooser(Color(colorValue));
738 Vector<String> Internals::formControlStateOfPreviousHistoryItem(ExceptionCode& ec)
740 HistoryItem* mainItem = frame()->loader()->history()->previousItem();
742 ec = INVALID_ACCESS_ERR;
743 return Vector<String>();
745 String uniqueName = frame()->tree()->uniqueName();
746 if (mainItem->target() != uniqueName && !mainItem->childItemWithTarget(uniqueName)) {
747 ec = INVALID_ACCESS_ERR;
748 return Vector<String>();
750 return mainItem->target() == uniqueName ? mainItem->documentState() : mainItem->childItemWithTarget(uniqueName)->documentState();
753 void Internals::setFormControlStateOfPreviousHistoryItem(const Vector<String>& state, ExceptionCode& ec)
755 HistoryItem* mainItem = frame()->loader()->history()->previousItem();
757 ec = INVALID_ACCESS_ERR;
760 String uniqueName = frame()->tree()->uniqueName();
761 if (mainItem->target() == uniqueName)
762 mainItem->setDocumentState(state);
763 else if (HistoryItem* subItem = mainItem->childItemWithTarget(uniqueName))
764 subItem->setDocumentState(state);
766 ec = INVALID_ACCESS_ERR;
769 #if ENABLE(SPEECH_SYNTHESIS)
770 void Internals::enableMockSpeechSynthesizer()
772 Document* document = contextDocument();
773 if (!document || !document->domWindow())
775 SpeechSynthesis* synthesis = DOMWindowSpeechSynthesis::speechSynthesis(document->domWindow());
779 synthesis->setPlatformSynthesizer(PlatformSpeechSynthesizerMock::create(synthesis));
783 void Internals::setEnableMockPagePopup(bool enabled, ExceptionCode& ec)
785 #if ENABLE(PAGE_POPUP)
786 Document* document = contextDocument();
787 if (!document || !document->page())
789 Page* page = document->page();
791 page->chrome().client()->resetPagePopupDriver();
794 if (!s_pagePopupDriver)
795 s_pagePopupDriver = MockPagePopupDriver::create(page->mainFrame()).leakPtr();
796 page->chrome().client()->setPagePopupDriver(s_pagePopupDriver);
798 UNUSED_PARAM(enabled);
803 #if ENABLE(PAGE_POPUP)
804 PassRefPtr<PagePopupController> Internals::pagePopupController()
806 return s_pagePopupDriver ? s_pagePopupDriver->pagePopupController() : 0;
810 PassRefPtr<ClientRect> Internals::absoluteCaretBounds(ExceptionCode& ec)
812 Document* document = contextDocument();
813 if (!document || !document->frame() || !document->frame()->selection()) {
814 ec = INVALID_ACCESS_ERR;
815 return ClientRect::create();
818 return ClientRect::create(document->frame()->selection()->absoluteCaretBounds());
821 PassRefPtr<ClientRect> Internals::boundingBox(Element* element, ExceptionCode& ec)
824 ec = INVALID_ACCESS_ERR;
825 return ClientRect::create();
828 element->document()->updateLayoutIgnorePendingStylesheets();
829 RenderObject* renderer = element->renderer();
831 return ClientRect::create();
832 return ClientRect::create(renderer->absoluteBoundingBoxRectIgnoringTransforms());
835 PassRefPtr<ClientRectList> Internals::inspectorHighlightRects(Document* document, ExceptionCode& ec)
837 #if ENABLE(INSPECTOR)
838 if (!document || !document->page() || !document->page()->inspectorController()) {
839 ec = INVALID_ACCESS_ERR;
840 return ClientRectList::create();
844 document->page()->inspectorController()->getHighlight(&highlight);
845 return ClientRectList::create(highlight.quads);
847 UNUSED_PARAM(document);
849 return ClientRectList::create();
853 unsigned Internals::markerCountForNode(Node* node, const String& markerType, ExceptionCode& ec)
856 ec = INVALID_ACCESS_ERR;
860 DocumentMarker::MarkerTypes markerTypes = 0;
861 if (!markerTypesFrom(markerType, markerTypes)) {
866 return node->document()->markers()->markersFor(node, markerTypes).size();
869 DocumentMarker* Internals::markerAt(Node* node, const String& markerType, unsigned index, ExceptionCode& ec)
872 ec = INVALID_ACCESS_ERR;
876 DocumentMarker::MarkerTypes markerTypes = 0;
877 if (!markerTypesFrom(markerType, markerTypes)) {
882 Vector<DocumentMarker*> markers = node->document()->markers()->markersFor(node, markerTypes);
883 if (markers.size() <= index)
885 return markers[index];
888 PassRefPtr<Range> Internals::markerRangeForNode(Node* node, const String& markerType, unsigned index, ExceptionCode& ec)
890 DocumentMarker* marker = markerAt(node, markerType, index, ec);
893 return Range::create(node->document(), node, marker->startOffset(), node, marker->endOffset());
896 String Internals::markerDescriptionForNode(Node* node, const String& markerType, unsigned index, ExceptionCode& ec)
898 DocumentMarker* marker = markerAt(node, markerType, index, ec);
901 return marker->description();
904 void Internals::addTextMatchMarker(const Range* range, bool isActive)
906 range->ownerDocument()->updateLayoutIgnorePendingStylesheets();
907 range->ownerDocument()->markers()->addTextMatchMarker(range, isActive);
910 void Internals::setScrollViewPosition(Document* document, long x, long y, ExceptionCode& ec)
912 if (!document || !document->view()) {
913 ec = INVALID_ACCESS_ERR;
917 FrameView* frameView = document->view();
918 bool constrainsScrollingToContentEdgeOldValue = frameView->constrainsScrollingToContentEdge();
919 bool scrollbarsSuppressedOldValue = frameView->scrollbarsSuppressed();
921 frameView->setConstrainsScrollingToContentEdge(false);
922 frameView->setScrollbarsSuppressed(false);
923 frameView->setScrollOffsetFromInternals(IntPoint(x, y));
924 frameView->setScrollbarsSuppressed(scrollbarsSuppressedOldValue);
925 frameView->setConstrainsScrollingToContentEdge(constrainsScrollingToContentEdgeOldValue);
928 void Internals::setPagination(Document* document, const String& mode, int gap, int pageLength, ExceptionCode& ec)
930 if (!document || !document->page()) {
931 ec = INVALID_ACCESS_ERR;
934 Page* page = document->page();
936 Pagination pagination;
937 if (mode == "Unpaginated")
938 pagination.mode = Pagination::Unpaginated;
939 else if (mode == "LeftToRightPaginated")
940 pagination.mode = Pagination::LeftToRightPaginated;
941 else if (mode == "RightToLeftPaginated")
942 pagination.mode = Pagination::RightToLeftPaginated;
943 else if (mode == "TopToBottomPaginated")
944 pagination.mode = Pagination::TopToBottomPaginated;
945 else if (mode == "BottomToTopPaginated")
946 pagination.mode = Pagination::BottomToTopPaginated;
952 pagination.gap = gap;
953 pagination.pageLength = pageLength;
954 page->setPagination(pagination);
957 String Internals::configurationForViewport(Document* document, float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight, ExceptionCode& ec)
959 if (!document || !document->page()) {
960 ec = INVALID_ACCESS_ERR;
963 Page* page = document->page();
965 const int defaultLayoutWidthForNonMobilePages = 980;
967 ViewportArguments arguments = page->viewportArguments();
968 ViewportAttributes attributes = computeViewportAttributes(arguments, defaultLayoutWidthForNonMobilePages, deviceWidth, deviceHeight, devicePixelRatio, IntSize(availableWidth, availableHeight));
969 restrictMinimumScaleFactorToViewportSize(attributes, IntSize(availableWidth, availableHeight), devicePixelRatio);
970 restrictScaleFactorToInitialScaleIfNotUserScalable(attributes);
972 return "viewport size " + String::number(attributes.layoutSize.width()) + "x" + String::number(attributes.layoutSize.height()) + " scale " + String::number(attributes.initialScale) + " with limits [" + String::number(attributes.minimumScale) + ", " + String::number(attributes.maximumScale) + "] and userScalable " + (attributes.userScalable ? "true" : "false");
975 bool Internals::wasLastChangeUserEdit(Element* textField, ExceptionCode& ec)
978 ec = INVALID_ACCESS_ERR;
982 if (HTMLInputElement* inputElement = textField->toInputElement())
983 return inputElement->lastChangeWasUserEdit();
985 // FIXME: We should be using hasTagName instead but Windows port doesn't link QualifiedNames properly.
986 if (textField->tagName() == "TEXTAREA")
987 return static_cast<HTMLTextAreaElement*>(textField)->lastChangeWasUserEdit();
989 ec = INVALID_NODE_TYPE_ERR;
993 bool Internals::elementShouldAutoComplete(Element* element, ExceptionCode& ec)
996 ec = INVALID_ACCESS_ERR;
1000 if (HTMLInputElement* inputElement = element->toInputElement())
1001 return inputElement->shouldAutocomplete();
1003 ec = INVALID_NODE_TYPE_ERR;
1007 String Internals::suggestedValue(Element* element, ExceptionCode& ec)
1010 ec = INVALID_ACCESS_ERR;
1014 HTMLInputElement* inputElement = element->toInputElement();
1015 if (!inputElement) {
1016 ec = INVALID_NODE_TYPE_ERR;
1020 return inputElement->suggestedValue();
1023 void Internals::setSuggestedValue(Element* element, const String& value, ExceptionCode& ec)
1026 ec = INVALID_ACCESS_ERR;
1030 HTMLInputElement* inputElement = element->toInputElement();
1031 if (!inputElement) {
1032 ec = INVALID_NODE_TYPE_ERR;
1036 inputElement->setSuggestedValue(value);
1039 void Internals::setEditingValue(Element* element, const String& value, ExceptionCode& ec)
1042 ec = INVALID_ACCESS_ERR;
1046 HTMLInputElement* inputElement = element->toInputElement();
1047 if (!inputElement) {
1048 ec = INVALID_NODE_TYPE_ERR;
1052 inputElement->setEditingValue(value);
1055 void Internals::setAutofilled(Element* element, bool enabled, ExceptionCode& ec)
1057 HTMLInputElement* inputElement = element->toInputElement();
1058 if (!inputElement) {
1059 ec = INVALID_ACCESS_ERR;
1062 inputElement->setAutofilled(enabled);
1065 void Internals::scrollElementToRect(Element* element, long x, long y, long w, long h, ExceptionCode& ec)
1067 if (!element || !element->document() || !element->document()->view()) {
1068 ec = INVALID_ACCESS_ERR;
1071 FrameView* frameView = element->document()->view();
1072 frameView->scrollElementToRect(element, IntRect(x, y, w, h));
1075 void Internals::paintControlTints(Document* document, ExceptionCode& ec)
1077 if (!document || !document->view()) {
1078 ec = INVALID_ACCESS_ERR;
1082 FrameView* frameView = document->view();
1083 frameView->paintControlTints();
1086 PassRefPtr<Range> Internals::rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionCode& ec)
1089 ec = INVALID_ACCESS_ERR;
1093 return TextIterator::rangeFromLocationAndLength(scope, rangeLocation, rangeLength);
1096 unsigned Internals::locationFromRange(Element* scope, const Range* range, ExceptionCode& ec)
1098 if (!scope || !range) {
1099 ec = INVALID_ACCESS_ERR;
1103 size_t location = 0;
1104 size_t unusedLength = 0;
1105 TextIterator::getLocationAndLengthFromRange(scope, range, location, unusedLength);
1109 unsigned Internals::lengthFromRange(Element* scope, const Range* range, ExceptionCode& ec)
1111 if (!scope || !range) {
1112 ec = INVALID_ACCESS_ERR;
1116 size_t unusedLocation = 0;
1118 TextIterator::getLocationAndLengthFromRange(scope, range, unusedLocation, length);
1122 String Internals::rangeAsText(const Range* range, ExceptionCode& ec)
1125 ec = INVALID_ACCESS_ERR;
1129 return range->text();
1132 void Internals::setDelegatesScrolling(bool enabled, Document* document, ExceptionCode& ec)
1134 // Delegate scrolling is valid only on mainframe's view.
1135 if (!document || !document->view() || !document->page() || document->page()->mainFrame() != document->frame()) {
1136 ec = INVALID_ACCESS_ERR;
1140 document->view()->setDelegatesScrolling(enabled);
1143 #if ENABLE(TOUCH_ADJUSTMENT)
1144 PassRefPtr<WebKitPoint> Internals::touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
1146 if (!document || !document->frame()) {
1147 ec = INVALID_ACCESS_ERR;
1151 IntSize radius(width / 2, height / 2);
1152 IntPoint point(x + radius.width(), y + radius.height());
1155 IntPoint adjustedPoint;
1157 bool foundNode = document->frame()->eventHandler()->bestClickableNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1159 return WebKitPoint::create(adjustedPoint.x(), adjustedPoint.y());
1164 Node* Internals::touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
1166 if (!document || !document->frame()) {
1167 ec = INVALID_ACCESS_ERR;
1171 IntSize radius(width / 2, height / 2);
1172 IntPoint point(x + radius.width(), y + radius.height());
1175 IntPoint adjustedPoint;
1176 document->frame()->eventHandler()->bestClickableNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1180 PassRefPtr<WebKitPoint> Internals::touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
1182 if (!document || !document->frame()) {
1183 ec = INVALID_ACCESS_ERR;
1187 IntSize radius(width / 2, height / 2);
1188 IntPoint point(x + radius.width(), y + radius.height());
1190 Node* targetNode = 0;
1191 IntPoint adjustedPoint;
1193 bool foundNode = document->frame()->eventHandler()->bestContextMenuNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1195 return WebKitPoint::create(adjustedPoint.x(), adjustedPoint.y());
1197 return WebKitPoint::create(x, y);
1200 Node* Internals::touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
1202 if (!document || !document->frame()) {
1203 ec = INVALID_ACCESS_ERR;
1207 IntSize radius(width / 2, height / 2);
1208 IntPoint point(x + radius.width(), y + radius.height());
1210 Node* targetNode = 0;
1211 IntPoint adjustedPoint;
1212 document->frame()->eventHandler()->bestContextMenuNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1216 PassRefPtr<ClientRect> Internals::bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
1218 if (!document || !document->frame()) {
1219 ec = INVALID_ACCESS_ERR;
1223 IntSize radius(width / 2, height / 2);
1224 IntPoint point(x + radius.width(), y + radius.height());
1227 IntRect zoomableArea;
1228 bool foundNode = document->frame()->eventHandler()->bestZoomableAreaForTouchPoint(point, radius, zoomableArea, targetNode);
1230 return ClientRect::create(zoomableArea);
1237 int Internals::lastSpellCheckRequestSequence(Document* document, ExceptionCode& ec)
1239 SpellChecker* checker = spellchecker(document);
1242 ec = INVALID_ACCESS_ERR;
1246 return checker->lastRequestSequence();
1249 int Internals::lastSpellCheckProcessedSequence(Document* document, ExceptionCode& ec)
1251 SpellChecker* checker = spellchecker(document);
1254 ec = INVALID_ACCESS_ERR;
1258 return checker->lastProcessedSequence();
1261 Vector<String> Internals::userPreferredLanguages() const
1263 return WebCore::userPreferredLanguages();
1266 void Internals::setUserPreferredLanguages(const Vector<String>& languages)
1268 WebCore::overrideUserPreferredLanguages(languages);
1271 unsigned Internals::wheelEventHandlerCount(Document* document, ExceptionCode& ec)
1274 ec = INVALID_ACCESS_ERR;
1278 return document->wheelEventHandlerCount();
1281 unsigned Internals::touchEventHandlerCount(Document* document, ExceptionCode& ec)
1284 ec = INVALID_ACCESS_ERR;
1288 const TouchEventTargetSet* touchHandlers = document->touchEventTargets();
1293 for (TouchEventTargetSet::const_iterator iter = touchHandlers->begin(); iter != touchHandlers->end(); ++iter)
1294 count += iter->value;
1298 #if ENABLE(TOUCH_EVENT_TRACKING)
1299 PassRefPtr<ClientRectList> Internals::touchEventTargetClientRects(Document* document, ExceptionCode& ec)
1301 if (!document || !document->view() || !document->page()) {
1302 ec = INVALID_ACCESS_ERR;
1305 if (!document->page()->scrollingCoordinator())
1306 return ClientRectList::create();
1308 document->updateLayoutIgnorePendingStylesheets();
1310 Vector<IntRect> absoluteRects;
1311 document->page()->scrollingCoordinator()->computeAbsoluteTouchEventTargetRects(document, absoluteRects);
1312 Vector<FloatQuad> absoluteQuads(absoluteRects.size());
1314 for (size_t i = 0; i < absoluteRects.size(); ++i)
1315 absoluteQuads[i] = FloatQuad(absoluteRects[i]);
1317 return ClientRectList::create(absoluteQuads);
1321 PassRefPtr<NodeList> Internals::nodesFromRect(Document* document, int centerX, int centerY, unsigned topPadding, unsigned rightPadding,
1322 unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent, ExceptionCode& ec) const
1324 if (!document || !document->frame() || !document->frame()->view()) {
1325 ec = INVALID_ACCESS_ERR;
1329 Frame* frame = document->frame();
1330 FrameView* frameView = document->view();
1331 RenderView* renderView = document->renderView();
1335 float zoomFactor = frame->pageZoomFactor();
1336 LayoutPoint point = roundedLayoutPoint(FloatPoint(centerX * zoomFactor + frameView->scrollX(), centerY * zoomFactor + frameView->scrollY()));
1338 HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly | HitTestRequest::Active;
1340 hitType |= HitTestRequest::IgnoreClipping;
1341 if (!allowShadowContent)
1342 hitType |= HitTestRequest::DisallowShadowContent;
1343 if (allowChildFrameContent)
1344 hitType |= HitTestRequest::AllowChildFrameContent;
1346 HitTestRequest request(hitType);
1348 // When ignoreClipping is false, this method returns null for coordinates outside of the viewport.
1349 if (!request.ignoreClipping() && !frameView->visibleContentRect().intersects(HitTestLocation::rectForPoint(point, topPadding, rightPadding, bottomPadding, leftPadding)))
1352 Vector<RefPtr<Node> > matches;
1354 // Need padding to trigger a rect based hit test, but we want to return a NodeList
1355 // so we special case this.
1356 if (!topPadding && !rightPadding && !bottomPadding && !leftPadding) {
1357 HitTestResult result(point);
1358 renderView->hitTest(request, result);
1359 if (result.innerNode())
1360 matches.append(result.innerNode()->deprecatedShadowAncestorNode());
1362 HitTestResult result(point, topPadding, rightPadding, bottomPadding, leftPadding);
1363 renderView->hitTest(request, result);
1364 copyToVector(result.rectBasedTestResult(), matches);
1367 return StaticNodeList::adopt(matches);
1370 void Internals::emitInspectorDidBeginFrame()
1372 #if ENABLE(INSPECTOR)
1373 InspectorController* inspectorController = contextDocument()->frame()->page()->inspectorController();
1374 inspectorController->didBeginFrame();
1378 void Internals::emitInspectorDidCancelFrame()
1380 #if ENABLE(INSPECTOR)
1381 InspectorController* inspectorController = contextDocument()->frame()->page()->inspectorController();
1382 inspectorController->didCancelFrame();
1386 void Internals::setBatteryStatus(Document* document, const String& eventType, bool charging, double chargingTime, double dischargingTime, double level, ExceptionCode& ec)
1388 if (!document || !document->page()) {
1389 ec = INVALID_ACCESS_ERR;
1393 #if ENABLE(BATTERY_STATUS)
1394 BatteryController::from(document->page())->didChangeBatteryStatus(eventType, BatteryStatus::create(charging, chargingTime, dischargingTime, level));
1396 UNUSED_PARAM(eventType);
1397 UNUSED_PARAM(charging);
1398 UNUSED_PARAM(chargingTime);
1399 UNUSED_PARAM(dischargingTime);
1400 UNUSED_PARAM(level);
1404 void Internals::setNetworkInformation(Document* document, const String& eventType, double bandwidth, bool metered, ExceptionCode& ec)
1406 if (!document || !document->page()) {
1407 ec = INVALID_ACCESS_ERR;
1411 #if ENABLE(NETWORK_INFO)
1412 NetworkInfoController::from(document->page())->didChangeNetworkInformation(eventType, NetworkInfo::create(bandwidth, metered));
1414 UNUSED_PARAM(eventType);
1415 UNUSED_PARAM(bandwidth);
1416 UNUSED_PARAM(metered);
1420 void Internals::setDeviceProximity(Document* document, const String& eventType, double value, double min, double max, ExceptionCode& ec)
1422 if (!document || !document->page()) {
1423 ec = INVALID_ACCESS_ERR;
1427 #if ENABLE(PROXIMITY_EVENTS)
1428 DeviceProximityController::from(document->page())->didChangeDeviceProximity(value, min, max);
1430 UNUSED_PARAM(eventType);
1431 UNUSED_PARAM(value);
1437 bool Internals::hasSpellingMarker(Document* document, int from, int length, ExceptionCode&)
1439 if (!document || !document->frame())
1442 return document->frame()->editor().selectionStartHasMarkerFor(DocumentMarker::Spelling, from, length);
1445 bool Internals::hasAutocorrectedMarker(Document* document, int from, int length, ExceptionCode&)
1447 if (!document || !document->frame())
1450 return document->frame()->editor().selectionStartHasMarkerFor(DocumentMarker::Autocorrected, from, length);
1453 void Internals::setContinuousSpellCheckingEnabled(bool enabled, ExceptionCode&)
1455 if (!contextDocument() || !contextDocument()->frame())
1458 if (enabled != contextDocument()->frame()->editor().isContinuousSpellCheckingEnabled())
1459 contextDocument()->frame()->editor().toggleContinuousSpellChecking();
1462 void Internals::setAutomaticQuoteSubstitutionEnabled(bool enabled, ExceptionCode&)
1464 if (!contextDocument() || !contextDocument()->frame())
1467 #if USE(AUTOMATIC_TEXT_REPLACEMENT)
1468 if (enabled != contextDocument()->frame()->editor().isAutomaticQuoteSubstitutionEnabled())
1469 contextDocument()->frame()->editor().toggleAutomaticQuoteSubstitution();
1471 UNUSED_PARAM(enabled);
1475 void Internals::setAutomaticLinkDetectionEnabled(bool enabled, ExceptionCode&)
1477 if (!contextDocument() || !contextDocument()->frame())
1480 #if USE(AUTOMATIC_TEXT_REPLACEMENT)
1481 if (enabled != contextDocument()->frame()->editor().isAutomaticLinkDetectionEnabled())
1482 contextDocument()->frame()->editor().toggleAutomaticLinkDetection();
1484 UNUSED_PARAM(enabled);
1488 void Internals::setAutomaticDashSubstitutionEnabled(bool enabled, ExceptionCode&)
1490 if (!contextDocument() || !contextDocument()->frame())
1493 #if USE(AUTOMATIC_TEXT_REPLACEMENT)
1494 if (enabled != contextDocument()->frame()->editor().isAutomaticDashSubstitutionEnabled())
1495 contextDocument()->frame()->editor().toggleAutomaticDashSubstitution();
1497 UNUSED_PARAM(enabled);
1501 void Internals::setAutomaticTextReplacementEnabled(bool enabled, ExceptionCode&)
1503 if (!contextDocument() || !contextDocument()->frame())
1506 #if USE(AUTOMATIC_TEXT_REPLACEMENT)
1507 if (enabled != contextDocument()->frame()->editor().isAutomaticTextReplacementEnabled())
1508 contextDocument()->frame()->editor().toggleAutomaticTextReplacement();
1510 UNUSED_PARAM(enabled);
1514 void Internals::setAutomaticSpellingCorrectionEnabled(bool enabled, ExceptionCode&)
1516 if (!contextDocument() || !contextDocument()->frame())
1519 #if USE(AUTOMATIC_TEXT_REPLACEMENT)
1520 if (enabled != contextDocument()->frame()->editor().isAutomaticSpellingCorrectionEnabled())
1521 contextDocument()->frame()->editor().toggleAutomaticSpellingCorrection();
1523 UNUSED_PARAM(enabled);
1527 bool Internals::isOverwriteModeEnabled(Document* document, ExceptionCode&)
1529 if (!document || !document->frame())
1532 return document->frame()->editor().isOverwriteModeEnabled();
1535 void Internals::toggleOverwriteModeEnabled(Document* document, ExceptionCode&)
1537 if (!document || !document->frame())
1540 document->frame()->editor().toggleOverwriteModeEnabled();
1543 #if ENABLE(INSPECTOR)
1544 unsigned Internals::numberOfLiveNodes() const
1546 return InspectorCounters::counterValue(InspectorCounters::NodeCounter);
1549 unsigned Internals::numberOfLiveDocuments() const
1551 return InspectorCounters::counterValue(InspectorCounters::DocumentCounter);
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 PassRefPtr<DOMWindow> Internals::openDummyInspectorFrontend(const String& url)
1571 Page* page = contextDocument()->frame()->page();
1574 DOMWindow* window = page->mainFrame()->document()->domWindow();
1577 m_frontendWindow = window->open(url, "", "", window, window);
1578 ASSERT(m_frontendWindow);
1580 Page* frontendPage = m_frontendWindow->document()->page();
1581 ASSERT(frontendPage);
1583 OwnPtr<InspectorFrontendClientDummy> frontendClient = adoptPtr(new InspectorFrontendClientDummy(page->inspectorController(), frontendPage));
1585 frontendPage->inspectorController()->setInspectorFrontendClient(frontendClient.release());
1587 m_frontendChannel = adoptPtr(new InspectorFrontendChannelDummy(frontendPage));
1589 page->inspectorController()->connectFrontend(m_frontendChannel.get());
1591 return m_frontendWindow;
1594 void Internals::closeDummyInspectorFrontend()
1596 Page* page = contextDocument()->frame()->page();
1598 ASSERT(m_frontendWindow);
1600 page->inspectorController()->disconnectFrontend();
1602 m_frontendChannel.release();
1604 m_frontendWindow->close(m_frontendWindow->scriptExecutionContext());
1605 m_frontendWindow.release();
1608 void Internals::setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionCode& ec)
1610 Page* page = contextDocument()->frame()->page();
1611 if (!page || !page->inspectorController()) {
1612 ec = INVALID_ACCESS_ERR;
1615 page->inspectorController()->setResourcesDataSizeLimitsFromInternals(maximumResourcesContentSize, maximumSingleResourceContentSize);
1618 void Internals::setJavaScriptProfilingEnabled(bool enabled, ExceptionCode& ec)
1620 Page* page = contextDocument()->frame()->page();
1621 if (!page || !page->inspectorController()) {
1622 ec = INVALID_ACCESS_ERR;
1626 page->inspectorController()->setProfilerEnabled(enabled);
1628 #endif // ENABLE(INSPECTOR)
1630 bool Internals::hasGrammarMarker(Document* document, int from, int length, ExceptionCode&)
1632 if (!document || !document->frame())
1635 return document->frame()->editor().selectionStartHasMarkerFor(DocumentMarker::Grammar, from, length);
1638 unsigned Internals::numberOfScrollableAreas(Document* document, ExceptionCode&)
1641 Frame* frame = document->frame();
1642 if (frame->view()->scrollableAreas())
1643 count += frame->view()->scrollableAreas()->size();
1645 for (Frame* child = frame->tree()->firstChild(); child; child = child->tree()->nextSibling()) {
1646 if (child->view() && child->view()->scrollableAreas())
1647 count += child->view()->scrollableAreas()->size();
1653 bool Internals::isPageBoxVisible(Document* document, int pageNumber, ExceptionCode& ec)
1656 ec = INVALID_ACCESS_ERR;
1660 return document->isPageBoxVisible(pageNumber);
1663 String Internals::layerTreeAsText(Document* document, ExceptionCode& ec) const
1665 return layerTreeAsText(document, 0, ec);
1668 String Internals::layerTreeAsText(Document* document, unsigned flags, ExceptionCode& ec) const
1670 if (!document || !document->frame()) {
1671 ec = INVALID_ACCESS_ERR;
1675 LayerTreeFlags layerTreeFlags = 0;
1676 if (flags & LAYER_TREE_INCLUDES_VISIBLE_RECTS)
1677 layerTreeFlags |= LayerTreeFlagsIncludeVisibleRects;
1678 if (flags & LAYER_TREE_INCLUDES_TILE_CACHES)
1679 layerTreeFlags |= LayerTreeFlagsIncludeTileCaches;
1680 if (flags & LAYER_TREE_INCLUDES_REPAINT_RECTS)
1681 layerTreeFlags |= LayerTreeFlagsIncludeRepaintRects;
1682 if (flags & LAYER_TREE_INCLUDES_PAINTING_PHASES)
1683 layerTreeFlags |= LayerTreeFlagsIncludePaintingPhases;
1685 return document->frame()->layerTreeAsText(layerTreeFlags);
1688 String Internals::repaintRectsAsText(Document* document, ExceptionCode& ec) const
1690 if (!document || !document->frame()) {
1691 ec = INVALID_ACCESS_ERR;
1695 return document->frame()->trackedRepaintRectsAsText();
1698 String Internals::scrollingStateTreeAsText(Document* document, ExceptionCode& ec) const
1700 if (!document || !document->frame()) {
1701 ec = INVALID_ACCESS_ERR;
1705 Page* page = document->page();
1709 return page->scrollingStateTreeAsText();
1712 String Internals::mainThreadScrollingReasons(Document* document, ExceptionCode& ec) const
1714 if (!document || !document->frame()) {
1715 ec = INVALID_ACCESS_ERR;
1719 Page* page = document->page();
1723 return page->mainThreadScrollingReasonsAsText();
1726 PassRefPtr<ClientRectList> Internals::nonFastScrollableRects(Document* document, ExceptionCode& ec) const
1728 if (!document || !document->frame()) {
1729 ec = INVALID_ACCESS_ERR;
1733 Page* page = document->page();
1737 return page->nonFastScrollableRects(document->frame());
1740 void Internals::garbageCollectDocumentResources(Document* document, ExceptionCode& ec) const
1743 ec = INVALID_ACCESS_ERR;
1747 CachedResourceLoader* cachedResourceLoader = document->cachedResourceLoader();
1748 if (!cachedResourceLoader)
1750 cachedResourceLoader->garbageCollectDocumentResources();
1753 void Internals::allowRoundingHacks() const
1755 TextRun::setAllowsRoundingHacks(true);
1758 void Internals::insertAuthorCSS(Document* document, const String& css) const
1760 RefPtr<StyleSheetContents> parsedSheet = StyleSheetContents::create(document);
1761 parsedSheet->setIsUserStyleSheet(false);
1762 parsedSheet->parseString(css);
1763 document->styleSheetCollection()->addAuthorSheet(parsedSheet);
1766 void Internals::insertUserCSS(Document* document, const String& css) const
1768 RefPtr<StyleSheetContents> parsedSheet = StyleSheetContents::create(document);
1769 parsedSheet->setIsUserStyleSheet(true);
1770 parsedSheet->parseString(css);
1771 document->styleSheetCollection()->addUserSheet(parsedSheet);
1774 String Internals::counterValue(Element* element)
1779 return counterValueForElement(element);
1782 int Internals::pageNumber(Element* element, float pageWidth, float pageHeight)
1787 return PrintContext::pageNumberForElement(element, FloatSize(pageWidth, pageHeight));
1790 Vector<String> Internals::iconURLs(Document* document, int iconTypesMask) const
1792 Vector<IconURL> iconURLs = document->iconURLs(iconTypesMask);
1793 Vector<String> array;
1795 Vector<IconURL>::const_iterator iter(iconURLs.begin());
1796 for (; iter != iconURLs.end(); ++iter)
1797 array.append(iter->m_iconURL.string());
1802 Vector<String> Internals::shortcutIconURLs(Document* document) const
1804 return iconURLs(document, Favicon);
1807 Vector<String> Internals::allIconURLs(Document* document) const
1809 return iconURLs(document, Favicon | TouchIcon | TouchPrecomposedIcon);
1812 int Internals::numberOfPages(float pageWidth, float pageHeight)
1817 return PrintContext::numberOfPages(frame(), FloatSize(pageWidth, pageHeight));
1820 String Internals::pageProperty(String propertyName, int pageNumber, ExceptionCode& ec) const
1823 ec = INVALID_ACCESS_ERR;
1827 return PrintContext::pageProperty(frame(), propertyName.utf8().data(), pageNumber);
1830 String Internals::pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft, ExceptionCode& ec) const
1833 ec = INVALID_ACCESS_ERR;
1837 return PrintContext::pageSizeAndMarginsInPixels(frame(), pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft);
1840 void Internals::setPageScaleFactor(float scaleFactor, int x, int y, ExceptionCode& ec)
1842 Document* document = contextDocument();
1843 if (!document || !document->page()) {
1844 ec = INVALID_ACCESS_ERR;
1847 Page* page = document->page();
1848 page->setPageScaleFactor(scaleFactor, IntPoint(x, y));
1851 void Internals::setHeaderHeight(Document* document, float height)
1853 if (!document || !document->view())
1855 #if USE(ACCELERATED_COMPOSITING)
1856 FrameView* frameView = document->view();
1857 frameView->setHeaderHeight(height);
1861 void Internals::setFooterHeight(Document* document, float height)
1863 if (!document || !document->view())
1865 #if USE(ACCELERATED_COMPOSITING)
1866 FrameView* frameView = document->view();
1867 frameView->setFooterHeight(height);
1871 #if ENABLE(FULLSCREEN_API)
1872 void Internals::webkitWillEnterFullScreenForElement(Document* document, Element* element)
1876 document->webkitWillEnterFullScreenForElement(element);
1879 void Internals::webkitDidEnterFullScreenForElement(Document* document, Element* element)
1883 document->webkitDidEnterFullScreenForElement(element);
1886 void Internals::webkitWillExitFullScreenForElement(Document* document, Element* element)
1890 document->webkitWillExitFullScreenForElement(element);
1893 void Internals::webkitDidExitFullScreenForElement(Document* document, Element* element)
1897 document->webkitDidExitFullScreenForElement(element);
1901 void Internals::registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme)
1903 SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy(scheme);
1906 void Internals::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme)
1908 SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(scheme);
1911 PassRefPtr<MallocStatistics> Internals::mallocStatistics() const
1913 return MallocStatistics::create();
1916 PassRefPtr<TypeConversions> Internals::typeConversions() const
1918 return TypeConversions::create();
1921 Vector<String> Internals::getReferencedFilePaths() const
1923 frame()->loader()->history()->saveDocumentAndScrollState();
1924 return FormController::getReferencedFilePaths(frame()->loader()->history()->currentItem()->documentState());
1927 void Internals::startTrackingRepaints(Document* document, ExceptionCode& ec)
1929 if (!document || !document->view()) {
1930 ec = INVALID_ACCESS_ERR;
1934 FrameView* frameView = document->view();
1935 frameView->setTracksRepaints(true);
1938 void Internals::stopTrackingRepaints(Document* document, ExceptionCode& ec)
1940 if (!document || !document->view()) {
1941 ec = INVALID_ACCESS_ERR;
1945 FrameView* frameView = document->view();
1946 frameView->setTracksRepaints(false);
1949 #if USE(LAZY_NATIVE_CURSOR)
1950 static const char* cursorTypeToString(Cursor::Type cursorType)
1952 switch (cursorType) {
1953 case Cursor::Pointer: return "Pointer";
1954 case Cursor::Cross: return "Cross";
1955 case Cursor::Hand: return "Hand";
1956 case Cursor::IBeam: return "IBeam";
1957 case Cursor::Wait: return "Wait";
1958 case Cursor::Help: return "Help";
1959 case Cursor::EastResize: return "EastResize";
1960 case Cursor::NorthResize: return "NorthResize";
1961 case Cursor::NorthEastResize: return "NorthEastResize";
1962 case Cursor::NorthWestResize: return "NorthWestResize";
1963 case Cursor::SouthResize: return "SouthResize";
1964 case Cursor::SouthEastResize: return "SouthEastResize";
1965 case Cursor::SouthWestResize: return "SouthWestResize";
1966 case Cursor::WestResize: return "WestResize";
1967 case Cursor::NorthSouthResize: return "NorthSouthResize";
1968 case Cursor::EastWestResize: return "EastWestResize";
1969 case Cursor::NorthEastSouthWestResize: return "NorthEastSouthWestResize";
1970 case Cursor::NorthWestSouthEastResize: return "NorthWestSouthEastResize";
1971 case Cursor::ColumnResize: return "ColumnResize";
1972 case Cursor::RowResize: return "RowResize";
1973 case Cursor::MiddlePanning: return "MiddlePanning";
1974 case Cursor::EastPanning: return "EastPanning";
1975 case Cursor::NorthPanning: return "NorthPanning";
1976 case Cursor::NorthEastPanning: return "NorthEastPanning";
1977 case Cursor::NorthWestPanning: return "NorthWestPanning";
1978 case Cursor::SouthPanning: return "SouthPanning";
1979 case Cursor::SouthEastPanning: return "SouthEastPanning";
1980 case Cursor::SouthWestPanning: return "SouthWestPanning";
1981 case Cursor::WestPanning: return "WestPanning";
1982 case Cursor::Move: return "Move";
1983 case Cursor::VerticalText: return "VerticalText";
1984 case Cursor::Cell: return "Cell";
1985 case Cursor::ContextMenu: return "ContextMenu";
1986 case Cursor::Alias: return "Alias";
1987 case Cursor::Progress: return "Progress";
1988 case Cursor::NoDrop: return "NoDrop";
1989 case Cursor::Copy: return "Copy";
1990 case Cursor::None: return "None";
1991 case Cursor::NotAllowed: return "NotAllowed";
1992 case Cursor::ZoomIn: return "ZoomIn";
1993 case Cursor::ZoomOut: return "ZoomOut";
1994 case Cursor::Grab: return "Grab";
1995 case Cursor::Grabbing: return "Grabbing";
1996 case Cursor::Custom: return "Custom";
1999 ASSERT_NOT_REACHED();
2004 String Internals::getCurrentCursorInfo(Document* document, ExceptionCode& ec)
2006 if (!document || !document->frame()) {
2007 ec = INVALID_ACCESS_ERR;
2011 Cursor cursor = document->frame()->eventHandler()->currentMouseCursor();
2013 #if USE(LAZY_NATIVE_CURSOR)
2014 StringBuilder result;
2015 result.append("type=");
2016 result.append(cursorTypeToString(cursor.type()));
2017 result.append(" hotSpot=");
2018 result.appendNumber(cursor.hotSpot().x());
2020 result.appendNumber(cursor.hotSpot().y());
2021 if (cursor.image()) {
2022 IntSize size = cursor.image()->size();
2023 result.append(" image=");
2024 result.appendNumber(size.width());
2026 result.appendNumber(size.height());
2028 #if ENABLE(MOUSE_CURSOR_SCALE)
2029 if (cursor.imageScaleFactor() != 1) {
2030 result.append(" scale=");
2031 NumberToStringBuffer buffer;
2032 result.append(numberToFixedPrecisionString(cursor.imageScaleFactor(), 8, buffer, true));
2035 return result.toString();
2037 return "FAIL: Cursor details not available on this platform.";
2041 PassRefPtr<ArrayBuffer> Internals::serializeObject(PassRefPtr<SerializedScriptValue> value) const
2043 Vector<uint8_t> bytes = value->data();
2044 return ArrayBuffer::create(bytes.data(), bytes.size());
2047 PassRefPtr<SerializedScriptValue> Internals::deserializeBuffer(PassRefPtr<ArrayBuffer> buffer) const
2049 Vector<uint8_t> bytes;
2050 bytes.append(static_cast<const uint8_t*>(buffer->data()), buffer->byteLength());
2051 return SerializedScriptValue::adopt(bytes);
2054 void Internals::setUsesOverlayScrollbars(bool enabled)
2056 WebCore::Settings::setUsesOverlayScrollbars(enabled);
2059 void Internals::forceReload(bool endToEnd)
2061 frame()->loader()->reload(endToEnd);
2064 #if ENABLE(ENCRYPTED_MEDIA_V2)
2065 void Internals::initializeMockCDM()
2067 CDM::registerCDMFactory(MockCDM::create, MockCDM::supportsKeySytem);
2071 String Internals::markerTextForListItem(Element* element, ExceptionCode& ec)
2074 ec = INVALID_ACCESS_ERR;
2077 return WebCore::markerTextForListItem(element);
2080 String Internals::getImageSourceURL(Element* element, ExceptionCode& ec)
2083 ec = INVALID_ACCESS_ERR;
2086 return element->imageSourceURL();
2090 void Internals::simulateAudioInterruption(Node* node)
2093 HTMLMediaElement* element = toMediaElement(node);
2094 element->player()->simulateAudioInterruption();
2101 bool Internals::isSelectPopupVisible(Node* node)
2103 if (!isHTMLSelectElement(node))
2106 HTMLSelectElement* select = toHTMLSelectElement(node);
2108 RenderObject* renderer = select->renderer();
2109 if (!renderer->isMenuList())
2112 RenderMenuList* menuList = toRenderMenuList(renderer);
2113 return menuList->popupIsVisible();
2116 String Internals::captionsStyleSheetOverride(ExceptionCode& ec)
2118 Document* document = contextDocument();
2119 if (!document || !document->page()) {
2120 ec = INVALID_ACCESS_ERR;
2121 return emptyString();
2124 #if ENABLE(VIDEO_TRACK) && !PLATFORM(WIN)
2125 return document->page()->group().captionPreferences()->captionsStyleSheetOverride();
2127 return emptyString();
2131 void Internals::setCaptionsStyleSheetOverride(const String& override, ExceptionCode& ec)
2133 Document* document = contextDocument();
2134 if (!document || !document->page()) {
2135 ec = INVALID_ACCESS_ERR;
2139 #if ENABLE(VIDEO_TRACK) && !PLATFORM(WIN)
2140 document->page()->group().captionPreferences()->setCaptionsStyleSheetOverride(override);
2144 void Internals::setPrimaryAudioTrackLanguageOverride(const String& language, ExceptionCode& ec)
2146 Document* document = contextDocument();
2147 if (!document || !document->page()) {
2148 ec = INVALID_ACCESS_ERR;
2152 #if ENABLE(VIDEO_TRACK) && !PLATFORM(WIN)
2153 document->page()->group().captionPreferences()->setPrimaryAudioTrackLanguageOverride(language);
2155 UNUSED_PARAM(language);
2159 void Internals::setCaptionDisplayMode(const String& mode, ExceptionCode& ec)
2161 Document* document = contextDocument();
2162 if (!document || !document->page()) {
2163 ec = INVALID_ACCESS_ERR;
2167 #if ENABLE(VIDEO_TRACK) && !PLATFORM(WIN)
2168 CaptionUserPreferences* captionPreferences = document->page()->group().captionPreferences();
2170 if (equalIgnoringCase(mode, "Automatic"))
2171 captionPreferences->setCaptionDisplayMode(CaptionUserPreferences::Automatic);
2172 else if (equalIgnoringCase(mode, "ForcedOnly"))
2173 captionPreferences->setCaptionDisplayMode(CaptionUserPreferences::ForcedOnly);
2174 else if (equalIgnoringCase(mode, "AlwaysOn"))
2175 captionPreferences->setCaptionDisplayMode(CaptionUserPreferences::AlwaysOn);
2184 PassRefPtr<TimeRanges> Internals::createTimeRanges(Float32Array* startTimes, Float32Array* endTimes)
2186 ASSERT(startTimes && endTimes);
2187 ASSERT(startTimes->length() == endTimes->length());
2188 RefPtr<TimeRanges> ranges = TimeRanges::create();
2190 unsigned count = std::min(startTimes->length(), endTimes->length());
2191 for (unsigned i = 0; i < count; ++i)
2192 ranges->add(startTimes->item(i), endTimes->item(i));
2196 double Internals::closestTimeToTimeRanges(double time, TimeRanges* ranges)
2198 return ranges->nearest(time);
2202 PassRefPtr<ClientRect> Internals::selectionBounds(ExceptionCode& ec)
2204 Document* document = contextDocument();
2205 if (!document || !document->frame() || !document->frame()->selection()) {
2206 ec = INVALID_ACCESS_ERR;
2207 return ClientRect::create();
2210 return ClientRect::create(document->frame()->selection()->bounds());