2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "Internals.h"
29 #include "BackForwardController.h"
30 #include "CachedResourceLoader.h"
31 #include "ClientRect.h"
32 #include "ClientRectList.h"
33 #include "ComposedShadowTreeWalker.h"
34 #include "DOMStringList.h"
36 #include "DocumentMarker.h"
37 #include "DocumentMarkerController.h"
39 #include "ElementShadow.h"
40 #include "ExceptionCode.h"
41 #include "FormController.h"
43 #include "FrameView.h"
44 #include "HTMLContentElement.h"
45 #include "HTMLInputElement.h"
46 #include "HTMLNames.h"
47 #include "HTMLTextAreaElement.h"
48 #include "HistoryItem.h"
49 #include "InspectorConsoleAgent.h"
50 #include "InspectorController.h"
51 #include "InspectorCounters.h"
52 #include "InspectorInstrumentation.h"
53 #include "InspectorOverlay.h"
54 #include "InstrumentingAgents.h"
55 #include "InternalSettings.h"
58 #include "MallocStatistics.h"
59 #include "NodeRenderingContext.h"
61 #include "PrintContext.h"
63 #include "RenderObject.h"
64 #include "RenderTreeAsText.h"
65 #include "RuntimeEnabledFeatures.h"
66 #include "SchemeRegistry.h"
68 #include "ShadowRoot.h"
69 #include "SpellChecker.h"
70 #include "TextIterator.h"
71 #include "TreeScope.h"
72 #include "ViewportArguments.h"
74 #if ENABLE(INPUT_TYPE_COLOR)
75 #include "ColorChooser.h"
78 #if ENABLE(BATTERY_STATUS)
79 #include "BatteryController.h"
82 #if ENABLE(NETWORK_INFO)
83 #include "NetworkInfo.h"
84 #include "NetworkInfoController.h"
87 #if ENABLE(PAGE_POPUP)
88 #include "PagePopupController.h"
91 #if ENABLE(TOUCH_ADJUSTMENT)
92 #include "EventHandler.h"
93 #include "WebKitPoint.h"
96 #if PLATFORM(CHROMIUM)
97 #include "FilterOperation.h"
98 #include "FilterOperations.h"
99 #include "GraphicsLayer.h"
100 #include "GraphicsLayerChromium.h"
101 #include "RenderLayerBacking.h"
106 using namespace HTMLNames;
108 static bool markerTypesFrom(const String& markerType, DocumentMarker::MarkerTypes& result)
110 if (markerType.isEmpty() || equalIgnoringCase(markerType, "all"))
111 result = DocumentMarker::AllMarkers();
112 else if (equalIgnoringCase(markerType, "Spelling"))
113 result = DocumentMarker::Spelling;
114 else if (equalIgnoringCase(markerType, "Grammar"))
115 result = DocumentMarker::Grammar;
116 else if (equalIgnoringCase(markerType, "TextMatch"))
117 result = DocumentMarker::TextMatch;
118 else if (equalIgnoringCase(markerType, "Replacement"))
119 result = DocumentMarker::Replacement;
120 else if (equalIgnoringCase(markerType, "CorrectionIndicator"))
121 result = DocumentMarker::CorrectionIndicator;
122 else if (equalIgnoringCase(markerType, "RejectedCorrection"))
123 result = DocumentMarker::RejectedCorrection;
124 else if (equalIgnoringCase(markerType, "Autocorrected"))
125 result = DocumentMarker::Autocorrected;
126 else if (equalIgnoringCase(markerType, "SpellCheckingExemption"))
127 result = DocumentMarker::SpellCheckingExemption;
128 else if (equalIgnoringCase(markerType, "DeletedAutocorrection"))
129 result = DocumentMarker::DeletedAutocorrection;
130 else if (equalIgnoringCase(markerType, "DictationAlternatives"))
131 result = DocumentMarker::DictationAlternatives;
138 static SpellChecker* spellchecker(Document* document)
140 if (!document || !document->frame() || !document->frame()->editor())
143 return document->frame()->editor()->spellChecker();
146 const char* Internals::internalsId = "internals";
148 PassRefPtr<Internals> Internals::create(Document* document)
150 return adoptRef(new Internals(document));
153 Internals::~Internals()
157 Internals::Internals(Document* document)
158 : ContextDestructionObserver(document)
162 Document* Internals::contextDocument() const
164 return static_cast<Document*>(scriptExecutionContext());
167 Frame* Internals::frame() const
169 if (!contextDocument())
171 return contextDocument()->frame();
174 InternalSettings* Internals::settings() const
176 Document* document = contextDocument();
179 Page* page = document->page();
182 return InternalSettings::from(page);
185 String Internals::address(Node* node)
188 sprintf(buf, "%p", node);
193 bool Internals::isPreloaded(Document* document, const String& url)
198 return document->cachedResourceLoader()->isPreloaded(url);
201 PassRefPtr<Element> Internals::createContentElement(Document* document, ExceptionCode& ec)
204 ec = INVALID_ACCESS_ERR;
208 return HTMLContentElement::create(document);
211 Element* Internals::getElementByIdInShadowRoot(Node* shadowRoot, const String& id, ExceptionCode& ec)
213 if (!shadowRoot || !shadowRoot->isShadowRoot()) {
214 ec = INVALID_ACCESS_ERR;
217 return toShadowRoot(shadowRoot)->getElementById(id);
220 bool Internals::isValidContentSelect(Element* insertionPoint, ExceptionCode& ec)
222 if (!insertionPoint || !isInsertionPoint(insertionPoint)) {
223 ec = INVALID_ACCESS_ERR;
227 return toInsertionPoint(insertionPoint)->isSelectValid();
230 Node* Internals::treeScopeRootNode(Node* node, ExceptionCode& ec)
233 ec = INVALID_ACCESS_ERR;
237 return node->treeScope()->rootNode();
240 Node* Internals::parentTreeScope(Node* node, ExceptionCode& ec)
243 ec = INVALID_ACCESS_ERR;
246 const TreeScope* parentTreeScope = node->treeScope()->parentTreeScope();
247 return parentTreeScope ? parentTreeScope->rootNode() : 0;
250 bool Internals::attached(Node* node, ExceptionCode& ec)
253 ec = INVALID_ACCESS_ERR;
257 return node->attached();
260 Node* Internals::nextSiblingByWalker(Node* node, ExceptionCode& ec)
263 ec = INVALID_ACCESS_ERR;
266 ComposedShadowTreeWalker walker(node);
267 walker.nextSibling();
271 Node* Internals::firstChildByWalker(Node* node, ExceptionCode& ec)
274 ec = INVALID_ACCESS_ERR;
277 ComposedShadowTreeWalker walker(node);
282 Node* Internals::lastChildByWalker(Node* node, ExceptionCode& ec)
285 ec = INVALID_ACCESS_ERR;
288 ComposedShadowTreeWalker walker(node);
293 Node* Internals::nextNodeByWalker(Node* node, ExceptionCode& ec)
296 ec = INVALID_ACCESS_ERR;
299 ComposedShadowTreeWalker walker(node);
304 Node* Internals::previousNodeByWalker(Node* node, ExceptionCode& ec)
307 ec = INVALID_ACCESS_ERR;
310 ComposedShadowTreeWalker walker(node);
315 String Internals::elementRenderTreeAsText(Element* element, ExceptionCode& ec)
318 ec = INVALID_ACCESS_ERR;
322 String representation = externalRepresentation(element);
323 if (representation.isEmpty()) {
324 ec = INVALID_ACCESS_ERR;
328 return representation;
331 size_t Internals::numberOfScopedHTMLStyleChildren(const Node* scope, ExceptionCode& ec) const
333 if (scope && (scope->isElementNode() || scope->isShadowRoot()))
334 #if ENABLE(STYLE_SCOPED)
335 return scope->numberOfScopedHTMLStyleChildren();
340 ec = INVALID_ACCESS_ERR;
344 Internals::ShadowRootIfShadowDOMEnabledOrNode* Internals::ensureShadowRoot(Element* host, ExceptionCode& ec)
347 ec = INVALID_ACCESS_ERR;
351 if (ElementShadow* shadow = host->shadow())
352 return shadow->youngestShadowRoot();
354 return ShadowRoot::create(host, ec).get();
357 Internals::ShadowRootIfShadowDOMEnabledOrNode* Internals::shadowRoot(Element* host, ExceptionCode& ec)
359 // FIXME: Internals::shadowRoot() in tests should be converted to youngestShadowRoot() or oldestShadowRoot().
360 // https://bugs.webkit.org/show_bug.cgi?id=78465
361 return youngestShadowRoot(host, ec);
364 Internals::ShadowRootIfShadowDOMEnabledOrNode* Internals::youngestShadowRoot(Element* host, ExceptionCode& ec)
367 ec = INVALID_ACCESS_ERR;
371 if (ElementShadow* shadow = host->shadow())
372 return shadow->youngestShadowRoot();
376 Internals::ShadowRootIfShadowDOMEnabledOrNode* Internals::oldestShadowRoot(Element* host, ExceptionCode& ec)
379 ec = INVALID_ACCESS_ERR;
383 if (ElementShadow* shadow = host->shadow())
384 return shadow->oldestShadowRoot();
388 Internals::ShadowRootIfShadowDOMEnabledOrNode* Internals::youngerShadowRoot(Node* shadow, ExceptionCode& ec)
390 if (!shadow || !shadow->isShadowRoot()) {
391 ec = INVALID_ACCESS_ERR;
395 return toShadowRoot(shadow)->youngerShadowRoot();
398 Internals::ShadowRootIfShadowDOMEnabledOrNode* Internals::olderShadowRoot(Node* shadow, ExceptionCode& ec)
400 if (!shadow || !shadow->isShadowRoot()) {
401 ec = INVALID_ACCESS_ERR;
405 return toShadowRoot(shadow)->olderShadowRoot();
408 Element* Internals::includerFor(Node* node, ExceptionCode& ec)
411 ec = INVALID_ACCESS_ERR;
415 return NodeRenderingContext(node).insertionPoint();
418 String Internals::shadowPseudoId(Element* element, ExceptionCode& ec)
421 ec = INVALID_ACCESS_ERR;
425 return element->shadowPseudoId().string();
428 void Internals::setShadowPseudoId(Element* element, const String& id, ExceptionCode& ec)
431 ec = INVALID_ACCESS_ERR;
435 return element->setShadowPseudoId(id, ec);
438 String Internals::visiblePlaceholder(Element* element)
440 HTMLTextFormControlElement* textControl = toTextFormControl(element);
441 if (textControl && textControl->placeholderShouldBeVisible())
442 return textControl->placeholderElement()->textContent();
446 #if ENABLE(INPUT_TYPE_COLOR)
447 void Internals::selectColorInColorChooser(Element* element, const String& colorValue)
449 if (!element->hasTagName(inputTag))
451 HTMLInputElement* inputElement = element->toInputElement();
454 inputElement->selectColorInColorChooser(Color(colorValue));
458 PassRefPtr<DOMStringList> Internals::formControlStateOfPreviousHistoryItem(ExceptionCode& ec)
460 HistoryItem* mainItem = frame()->loader()->history()->previousItem();
462 ec = INVALID_ACCESS_ERR;
465 String uniqueName = frame()->tree()->uniqueName();
466 if (mainItem->target() != uniqueName && !mainItem->childItemWithTarget(uniqueName)) {
467 ec = INVALID_ACCESS_ERR;
470 const Vector<String>& state = mainItem->target() == uniqueName ? mainItem->documentState() : mainItem->childItemWithTarget(uniqueName)->documentState();
471 RefPtr<DOMStringList> stringList = DOMStringList::create();
472 for (unsigned i = 0; i < state.size(); ++i)
473 stringList->append(state[i]);
474 return stringList.release();
477 void Internals::setFormControlStateOfPreviousHistoryItem(PassRefPtr<DOMStringList> state, ExceptionCode& ec)
479 HistoryItem* mainItem = frame()->loader()->history()->previousItem();
480 if (!state || !mainItem) {
481 ec = INVALID_ACCESS_ERR;
484 String uniqueName = frame()->tree()->uniqueName();
485 if (mainItem->target() == uniqueName)
486 mainItem->setDocumentState(*state.get());
487 else if (HistoryItem* subItem = mainItem->childItemWithTarget(uniqueName))
488 subItem->setDocumentState(*state.get());
490 ec = INVALID_ACCESS_ERR;
493 #if ENABLE(PAGE_POPUP)
494 PassRefPtr<PagePopupController> Internals::pagePopupController()
496 InternalSettings* settings = this->settings();
499 return settings->pagePopupController();
503 PassRefPtr<ClientRect> Internals::absoluteCaretBounds(Document* document, ExceptionCode& ec)
505 if (!document || !document->frame() || !document->frame()->selection()) {
506 ec = INVALID_ACCESS_ERR;
507 return ClientRect::create();
510 return ClientRect::create(document->frame()->selection()->absoluteCaretBounds());
513 PassRefPtr<ClientRect> Internals::boundingBox(Element* element, ExceptionCode& ec)
516 ec = INVALID_ACCESS_ERR;
517 return ClientRect::create();
520 element->document()->updateLayoutIgnorePendingStylesheets();
521 RenderObject* renderer = element->renderer();
523 return ClientRect::create();
524 return ClientRect::create(renderer->absoluteBoundingBoxRectIgnoringTransforms());
527 PassRefPtr<ClientRectList> Internals::inspectorHighlightRects(Document* document, ExceptionCode& ec)
529 #if ENABLE(INSPECTOR)
530 if (!document || !document->page() || !document->page()->inspectorController()) {
531 ec = INVALID_ACCESS_ERR;
532 return ClientRectList::create();
536 document->page()->inspectorController()->getHighlight(&highlight);
537 return ClientRectList::create(highlight.quads);
539 UNUSED_PARAM(document);
541 return ClientRectList::create();
545 #if PLATFORM(CHROMIUM)
546 void Internals::setBackgroundBlurOnNode(Node* node, int blurLength, ExceptionCode& ec)
549 ec = INVALID_ACCESS_ERR;
553 RenderObject* renderObject = node->renderer();
555 ec = INVALID_NODE_TYPE_ERR;
559 RenderLayer* renderLayer = renderObject->enclosingLayer();
560 if (!renderLayer || !renderLayer->isComposited()) {
561 ec = INVALID_STATE_ERR;
565 GraphicsLayer* graphicsLayer = renderLayer->backing()->graphicsLayer();
566 if (!graphicsLayer) {
567 ec = INVALID_NODE_TYPE_ERR;
571 FilterOperations filters;
572 filters.operations().append(BlurFilterOperation::create(Length(blurLength, Fixed), FilterOperation::BLUR));
573 static_cast<GraphicsLayerChromium*>(graphicsLayer)->setBackgroundFilters(filters);
576 void Internals::setBackgroundBlurOnNode(Node*, int, ExceptionCode&)
581 unsigned Internals::markerCountForNode(Node* node, const String& markerType, ExceptionCode& ec)
584 ec = INVALID_ACCESS_ERR;
588 DocumentMarker::MarkerTypes markerTypes = 0;
589 if (!markerTypesFrom(markerType, markerTypes)) {
594 return node->document()->markers()->markersFor(node, markerTypes).size();
597 DocumentMarker* Internals::markerAt(Node* node, const String& markerType, unsigned index, ExceptionCode& ec)
600 ec = INVALID_ACCESS_ERR;
604 DocumentMarker::MarkerTypes markerTypes = 0;
605 if (!markerTypesFrom(markerType, markerTypes)) {
610 Vector<DocumentMarker*> markers = node->document()->markers()->markersFor(node, markerTypes);
611 if (markers.size() <= index)
613 return markers[index];
616 PassRefPtr<Range> Internals::markerRangeForNode(Node* node, const String& markerType, unsigned index, ExceptionCode& ec)
618 DocumentMarker* marker = markerAt(node, markerType, index, ec);
621 return Range::create(node->document(), node, marker->startOffset(), node, marker->endOffset());
624 String Internals::markerDescriptionForNode(Node* node, const String& markerType, unsigned index, ExceptionCode& ec)
626 DocumentMarker* marker = markerAt(node, markerType, index, ec);
629 return marker->description();
632 void Internals::addTextMatchMarker(const Range* range, bool isActive)
634 range->ownerDocument()->updateLayoutIgnorePendingStylesheets();
635 range->ownerDocument()->markers()->addTextMatchMarker(range, isActive);
638 void Internals::setScrollViewPosition(Document* document, long x, long y, ExceptionCode& ec)
640 if (!document || !document->view()) {
641 ec = INVALID_ACCESS_ERR;
645 FrameView* frameView = document->view();
646 bool constrainsScrollingToContentEdgeOldValue = frameView->constrainsScrollingToContentEdge();
647 bool scrollbarsSuppressedOldValue = frameView->scrollbarsSuppressed();
649 frameView->setConstrainsScrollingToContentEdge(false);
650 frameView->setScrollbarsSuppressed(false);
651 frameView->setScrollOffsetFromInternals(IntPoint(x, y));
652 frameView->setScrollbarsSuppressed(scrollbarsSuppressedOldValue);
653 frameView->setConstrainsScrollingToContentEdge(constrainsScrollingToContentEdgeOldValue);
656 void Internals::setPagination(Document*, const String& mode, int gap, int pageLength, ExceptionCode& ec)
658 settings()->setPagination(mode, gap, pageLength, ec);
661 String Internals::configurationForViewport(Document*, float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight, ExceptionCode& ec)
663 return settings()->configurationForViewport(devicePixelRatio, deviceWidth, deviceHeight, availableWidth, availableHeight, ec);
666 bool Internals::wasLastChangeUserEdit(Element* textField, ExceptionCode& ec)
669 ec = INVALID_ACCESS_ERR;
673 if (HTMLInputElement* inputElement = textField->toInputElement())
674 return inputElement->lastChangeWasUserEdit();
676 // FIXME: We should be using hasTagName instead but Windows port doesn't link QualifiedNames properly.
677 if (textField->tagName() == "TEXTAREA")
678 return static_cast<HTMLTextAreaElement*>(textField)->lastChangeWasUserEdit();
680 ec = INVALID_NODE_TYPE_ERR;
684 String Internals::suggestedValue(Element* element, ExceptionCode& ec)
687 ec = INVALID_ACCESS_ERR;
691 HTMLInputElement* inputElement = element->toInputElement();
693 ec = INVALID_NODE_TYPE_ERR;
697 return inputElement->suggestedValue();
700 void Internals::setSuggestedValue(Element* element, const String& value, ExceptionCode& ec)
703 ec = INVALID_ACCESS_ERR;
707 HTMLInputElement* inputElement = element->toInputElement();
709 ec = INVALID_NODE_TYPE_ERR;
713 inputElement->setSuggestedValue(value);
716 void Internals::setEditingValue(Element* element, const String& value, ExceptionCode& ec)
719 ec = INVALID_ACCESS_ERR;
723 HTMLInputElement* inputElement = element->toInputElement();
725 ec = INVALID_NODE_TYPE_ERR;
729 inputElement->setEditingValue(value);
732 void Internals::scrollElementToRect(Element* element, long x, long y, long w, long h, ExceptionCode& ec)
734 if (!element || !element->document() || !element->document()->view()) {
735 ec = INVALID_ACCESS_ERR;
738 FrameView* frameView = element->document()->view();
739 frameView->scrollElementToRect(element, IntRect(x, y, w, h));
742 void Internals::paintControlTints(Document* document, ExceptionCode& ec)
744 if (!document || !document->view()) {
745 ec = INVALID_ACCESS_ERR;
749 FrameView* frameView = document->view();
750 frameView->paintControlTints();
753 PassRefPtr<Range> Internals::rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionCode& ec)
756 ec = INVALID_ACCESS_ERR;
760 return TextIterator::rangeFromLocationAndLength(scope, rangeLocation, rangeLength);
763 unsigned Internals::locationFromRange(Element* scope, const Range* range, ExceptionCode& ec)
765 if (!scope || !range) {
766 ec = INVALID_ACCESS_ERR;
771 size_t unusedLength = 0;
772 TextIterator::getLocationAndLengthFromRange(scope, range, location, unusedLength);
776 unsigned Internals::lengthFromRange(Element* scope, const Range* range, ExceptionCode& ec)
778 if (!scope || !range) {
779 ec = INVALID_ACCESS_ERR;
783 size_t unusedLocation = 0;
785 TextIterator::getLocationAndLengthFromRange(scope, range, unusedLocation, length);
789 String Internals::rangeAsText(const Range* range, ExceptionCode& ec)
792 ec = INVALID_ACCESS_ERR;
796 return range->text();
799 void Internals::setDelegatesScrolling(bool enabled, Document* document, ExceptionCode& ec)
801 // Delegate scrolling is valid only on mainframe's view.
802 if (!document || !document->view() || !document->page() || document->page()->mainFrame() != document->frame()) {
803 ec = INVALID_ACCESS_ERR;
807 document->view()->setDelegatesScrolling(enabled);
810 #if ENABLE(TOUCH_ADJUSTMENT)
811 PassRefPtr<WebKitPoint> Internals::touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
813 if (!document || !document->frame()) {
814 ec = INVALID_ACCESS_ERR;
818 IntSize radius(width / 2, height / 2);
819 IntPoint point(x + radius.width(), y + radius.height());
822 IntPoint adjustedPoint;
824 bool foundNode = document->frame()->eventHandler()->bestClickableNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
826 return WebKitPoint::create(adjustedPoint.x(), adjustedPoint.y());
831 Node* Internals::touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
833 if (!document || !document->frame()) {
834 ec = INVALID_ACCESS_ERR;
838 IntSize radius(width / 2, height / 2);
839 IntPoint point(x + radius.width(), y + radius.height());
842 IntPoint adjustedPoint;
843 document->frame()->eventHandler()->bestClickableNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
847 PassRefPtr<WebKitPoint> Internals::touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
849 if (!document || !document->frame()) {
850 ec = INVALID_ACCESS_ERR;
854 IntSize radius(width / 2, height / 2);
855 IntPoint point(x + radius.width(), y + radius.height());
857 Node* targetNode = 0;
858 IntPoint adjustedPoint;
860 bool foundNode = document->frame()->eventHandler()->bestContextMenuNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
862 return WebKitPoint::create(adjustedPoint.x(), adjustedPoint.y());
864 return WebKitPoint::create(x, y);
867 Node* Internals::touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
869 if (!document || !document->frame()) {
870 ec = INVALID_ACCESS_ERR;
874 IntSize radius(width / 2, height / 2);
875 IntPoint point(x + radius.width(), y + radius.height());
877 Node* targetNode = 0;
878 IntPoint adjustedPoint;
879 document->frame()->eventHandler()->bestContextMenuNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
883 PassRefPtr<ClientRect> Internals::bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
885 if (!document || !document->frame()) {
886 ec = INVALID_ACCESS_ERR;
890 IntSize radius(width / 2, height / 2);
891 IntPoint point(x + radius.width(), y + radius.height());
894 IntRect zoomableArea;
895 bool foundNode = document->frame()->eventHandler()->bestZoomableAreaForTouchPoint(point, radius, zoomableArea, targetNode);
897 return ClientRect::create(zoomableArea);
904 int Internals::lastSpellCheckRequestSequence(Document* document, ExceptionCode& ec)
906 SpellChecker* checker = spellchecker(document);
909 ec = INVALID_ACCESS_ERR;
913 return checker->lastRequestSequence();
916 int Internals::lastSpellCheckProcessedSequence(Document* document, ExceptionCode& ec)
918 SpellChecker* checker = spellchecker(document);
921 ec = INVALID_ACCESS_ERR;
925 return checker->lastProcessedSequence();
928 Vector<String> Internals::userPreferredLanguages() const
930 return settings()->userPreferredLanguages();
933 void Internals::setUserPreferredLanguages(const Vector<String>& languages)
935 settings()->setUserPreferredLanguages(languages);
938 void Internals::setShouldDisplayTrackKind(Document*, const String& kind, bool enabled, ExceptionCode& ec)
940 settings()->setShouldDisplayTrackKind(kind, enabled, ec);
943 bool Internals::shouldDisplayTrackKind(Document*, const String& kind, ExceptionCode& ec)
945 return settings()->shouldDisplayTrackKind(kind, ec);
948 unsigned Internals::wheelEventHandlerCount(Document* document, ExceptionCode& ec)
951 ec = INVALID_ACCESS_ERR;
955 return document->wheelEventHandlerCount();
958 unsigned Internals::touchEventHandlerCount(Document* document, ExceptionCode& ec)
961 ec = INVALID_ACCESS_ERR;
965 return document->touchEventHandlerCount();
968 PassRefPtr<NodeList> Internals::nodesFromRect(Document* document, int x, int y, unsigned topPadding, unsigned rightPadding,
969 unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent, ExceptionCode& ec) const
971 if (!document || !document->frame() || !document->frame()->view()) {
972 ec = INVALID_ACCESS_ERR;
975 HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly | HitTestRequest::Active;
977 hitType |= HitTestRequest::IgnoreClipping;
978 if (allowShadowContent)
979 hitType |= HitTestRequest::AllowShadowContent;
980 if (allowChildFrameContent)
981 hitType |= HitTestRequest::AllowChildFrameContent;
983 return document->nodesFromRect(x, y, topPadding, rightPadding, bottomPadding, leftPadding, hitType);
986 void Internals::emitInspectorDidBeginFrame()
988 InspectorInstrumentation::didBeginFrame(contextDocument()->frame()->page());
991 void Internals::emitInspectorDidCancelFrame()
993 InspectorInstrumentation::didCancelFrame(contextDocument()->frame()->page());
996 void Internals::setBatteryStatus(Document* document, const String& eventType, bool charging, double chargingTime, double dischargingTime, double level, ExceptionCode& ec)
998 if (!document || !document->page()) {
999 ec = INVALID_ACCESS_ERR;
1003 #if ENABLE(BATTERY_STATUS)
1004 BatteryController::from(document->page())->didChangeBatteryStatus(eventType, BatteryStatus::create(charging, chargingTime, dischargingTime, level));
1006 UNUSED_PARAM(eventType);
1007 UNUSED_PARAM(charging);
1008 UNUSED_PARAM(chargingTime);
1009 UNUSED_PARAM(dischargingTime);
1010 UNUSED_PARAM(level);
1014 void Internals::setNetworkInformation(Document* document, const String& eventType, double bandwidth, bool metered, ExceptionCode& ec)
1016 if (!document || !document->page()) {
1017 ec = INVALID_ACCESS_ERR;
1021 #if ENABLE(NETWORK_INFO)
1022 NetworkInfoController::from(document->page())->didChangeNetworkInformation(eventType, NetworkInfo::create(bandwidth, metered));
1024 UNUSED_PARAM(eventType);
1025 UNUSED_PARAM(bandwidth);
1026 UNUSED_PARAM(metered);
1030 bool Internals::hasSpellingMarker(Document* document, int from, int length, ExceptionCode&)
1032 if (!document || !document->frame())
1035 return document->frame()->editor()->selectionStartHasMarkerFor(DocumentMarker::Spelling, from, length);
1038 bool Internals::hasAutocorrectedMarker(Document* document, int from, int length, ExceptionCode&)
1040 if (!document || !document->frame())
1043 return document->frame()->editor()->selectionStartHasMarkerFor(DocumentMarker::Autocorrected, from, length);
1046 #if ENABLE(INSPECTOR)
1047 unsigned Internals::numberOfLiveNodes() const
1049 return InspectorCounters::counterValue(InspectorCounters::NodeCounter);
1052 unsigned Internals::numberOfLiveDocuments() const
1054 return InspectorCounters::counterValue(InspectorCounters::DocumentCounter);
1057 Vector<String> Internals::consoleMessageArgumentCounts(Document* document) const
1059 InstrumentingAgents* instrumentingAgents = instrumentationForPage(document->page());
1060 if (!instrumentingAgents)
1061 return Vector<String>();
1062 InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent();
1064 return Vector<String>();
1065 Vector<unsigned> counts = consoleAgent->consoleMessageArgumentCounts();
1066 Vector<String> result(counts.size());
1067 for (size_t i = 0; i < counts.size(); i++)
1068 result[i] = String::number(counts[i]);
1071 #endif // ENABLE(INSPECTOR)
1073 bool Internals::hasGrammarMarker(Document* document, int from, int length, ExceptionCode&)
1075 if (!document || !document->frame())
1078 return document->frame()->editor()->selectionStartHasMarkerFor(DocumentMarker::Grammar, from, length);
1081 unsigned Internals::numberOfScrollableAreas(Document* document, ExceptionCode&)
1084 Frame* frame = document->frame();
1085 if (frame->view()->scrollableAreas())
1086 count += frame->view()->scrollableAreas()->size();
1088 for (Frame* child = frame->tree()->firstChild(); child; child = child->tree()->nextSibling()) {
1089 if (child->view() && child->view()->scrollableAreas())
1090 count += child->view()->scrollableAreas()->size();
1096 bool Internals::isPageBoxVisible(Document* document, int pageNumber, ExceptionCode& ec)
1099 ec = INVALID_ACCESS_ERR;
1103 return document->isPageBoxVisible(pageNumber);
1106 void Internals::suspendAnimations(Document* document, ExceptionCode& ec) const
1108 if (!document || !document->frame()) {
1109 ec = INVALID_ACCESS_ERR;
1113 AnimationController* controller = document->frame()->animation();
1117 controller->suspendAnimations();
1120 void Internals::resumeAnimations(Document* document, ExceptionCode& ec) const
1122 if (!document || !document->frame()) {
1123 ec = INVALID_ACCESS_ERR;
1127 AnimationController* controller = document->frame()->animation();
1131 controller->resumeAnimations();
1134 void Internals::garbageCollectDocumentResources(Document* document, ExceptionCode& ec) const
1137 ec = INVALID_ACCESS_ERR;
1141 CachedResourceLoader* cachedResourceLoader = document->cachedResourceLoader();
1142 if (!cachedResourceLoader)
1144 cachedResourceLoader->garbageCollectDocumentResources();
1147 void Internals::allowRoundingHacks() const
1149 settings()->allowRoundingHacks();
1152 String Internals::counterValue(Element* element)
1157 return counterValueForElement(element);
1160 int Internals::pageNumber(Element* element, float pageWidth, float pageHeight)
1165 return PrintContext::pageNumberForElement(element, FloatSize(pageWidth, pageHeight));
1168 PassRefPtr<DOMStringList> Internals::iconURLs(Document* document) const
1170 Vector<IconURL> iconURLs = document->iconURLs();
1171 RefPtr<DOMStringList> stringList = DOMStringList::create();
1173 Vector<IconURL>::const_iterator iter(iconURLs.begin());
1174 for (; iter != iconURLs.end(); ++iter)
1175 stringList->append(iter->m_iconURL.string());
1177 return stringList.release();
1180 int Internals::numberOfPages(float pageWidth, float pageHeight)
1185 return PrintContext::numberOfPages(frame(), FloatSize(pageWidth, pageHeight));
1188 String Internals::pageProperty(String propertyName, int pageNumber, ExceptionCode& ec) const
1191 ec = INVALID_ACCESS_ERR;
1195 return PrintContext::pageProperty(frame(), propertyName.utf8().data(), pageNumber);
1198 String Internals::pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft, ExceptionCode& ec) const
1201 ec = INVALID_ACCESS_ERR;
1205 return PrintContext::pageSizeAndMarginsInPixels(frame(), pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft);
1208 #if ENABLE(FULLSCREEN_API)
1209 void Internals::webkitWillEnterFullScreenForElement(Document* document, Element* element)
1213 document->webkitWillEnterFullScreenForElement(element);
1216 void Internals::webkitDidEnterFullScreenForElement(Document* document, Element* element)
1220 document->webkitDidEnterFullScreenForElement(element);
1223 void Internals::webkitWillExitFullScreenForElement(Document* document, Element* element)
1227 document->webkitWillExitFullScreenForElement(element);
1230 void Internals::webkitDidExitFullScreenForElement(Document* document, Element* element)
1234 document->webkitDidExitFullScreenForElement(element);
1238 void Internals::registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme)
1240 SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy(scheme);
1243 void Internals::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme)
1245 SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(scheme);
1248 PassRefPtr<MallocStatistics> Internals::mallocStatistics() const
1250 return MallocStatistics::create();
1253 PassRefPtr<DOMStringList> Internals::getReferencedFilePaths() const
1255 RefPtr<DOMStringList> stringList = DOMStringList::create();
1256 frame()->loader()->history()->saveDocumentAndScrollState();
1257 const Vector<String>& filePaths = FormController::getReferencedFilePaths(frame()->loader()->history()->currentItem()->documentState());
1258 for (size_t i = 0; i < filePaths.size(); ++i)
1259 stringList->append(filePaths[i]);
1260 return stringList.release();