2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013-2015 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 "AXObjectCache.h"
31 #include "ActiveDOMCallbackMicrotask.h"
32 #include "AnimationController.h"
33 #include "ApplicationCacheStorage.h"
35 #include "BackForwardController.h"
36 #include "BitmapImage.h"
37 #include "CachedImage.h"
38 #include "CachedResourceLoader.h"
40 #include "ChromeClient.h"
41 #include "ClientRect.h"
42 #include "ClientRectList.h"
43 #include "ComposedTreeIterator.h"
46 #include "DOMStringList.h"
47 #include "DOMWindow.h"
48 #include "DisplayList.h"
50 #include "DocumentMarker.h"
51 #include "DocumentMarkerController.h"
54 #include "EventHandler.h"
55 #include "ExceptionCode.h"
56 #include "ExtensionStyleSheets.h"
58 #include "FontCache.h"
59 #include "FormController.h"
60 #include "FrameLoader.h"
61 #include "FrameView.h"
62 #include "HTMLCanvasElement.h"
63 #include "HTMLIFrameElement.h"
64 #include "HTMLImageElement.h"
65 #include "HTMLInputElement.h"
66 #include "HTMLLinkElement.h"
67 #include "HTMLNames.h"
68 #include "HTMLPlugInElement.h"
69 #include "HTMLPreloadScanner.h"
70 #include "HTMLSelectElement.h"
71 #include "HTMLTextAreaElement.h"
72 #include "HTMLVideoElement.h"
73 #include "HistoryController.h"
74 #include "HistoryItem.h"
75 #include "HitTestResult.h"
76 #include "IconController.h"
77 #include "InspectorClient.h"
78 #include "InspectorController.h"
79 #include "InspectorFrontendClientLocal.h"
80 #include "InspectorOverlay.h"
81 #include "InstrumentingAgents.h"
83 #include "InternalSettings.h"
85 #include "MainFrame.h"
86 #include "MallocStatistics.h"
87 #include "MediaPlayer.h"
88 #include "MemoryCache.h"
89 #include "MemoryInfo.h"
90 #include "MockPageOverlay.h"
91 #include "MockPageOverlayClient.h"
93 #include "PageCache.h"
94 #include "PageOverlay.h"
95 #include "PathUtilities.h"
96 #include "PlatformMediaSessionManager.h"
97 #include "PrintContext.h"
98 #include "PseudoElement.h"
100 #include "RenderEmbeddedObject.h"
101 #include "RenderLayerBacking.h"
102 #include "RenderLayerCompositor.h"
103 #include "RenderMenuList.h"
104 #include "RenderTreeAsText.h"
105 #include "RenderView.h"
106 #include "RenderedDocumentMarker.h"
107 #include "ResourceLoadObserver.h"
108 #include "RuntimeEnabledFeatures.h"
109 #include "SchemeRegistry.h"
110 #include "ScriptedAnimationController.h"
111 #include "ScrollingCoordinator.h"
112 #include "SerializedScriptValue.h"
113 #include "Settings.h"
114 #include "ShadowRoot.h"
115 #include "SourceBuffer.h"
116 #include "SpellChecker.h"
117 #include "StaticNodeList.h"
118 #include "StyleSheetContents.h"
119 #include "TextIterator.h"
120 #include "TreeScope.h"
121 #include "TypeConversions.h"
122 #include "UserMediaController.h"
123 #include "ViewportArguments.h"
124 #include "WebCoreJSClientData.h"
125 #include "WorkerThread.h"
126 #include "XMLHttpRequest.h"
127 #include <JavaScriptCore/Profile.h>
128 #include <bytecode/CodeBlock.h>
129 #include <inspector/InspectorAgentBase.h>
130 #include <inspector/InspectorFrontendChannel.h>
131 #include <inspector/InspectorValues.h>
132 #include <runtime/JSCInlines.h>
133 #include <runtime/JSCJSValue.h>
134 #include <wtf/text/CString.h>
135 #include <wtf/text/StringBuffer.h>
137 #if ENABLE(INPUT_TYPE_COLOR)
138 #include "ColorChooser.h"
141 #if ENABLE(BATTERY_STATUS)
142 #include "BatteryController.h"
145 #if ENABLE(PROXIMITY_EVENTS)
146 #include "DeviceProximityController.h"
149 #if ENABLE(MOUSE_CURSOR_SCALE)
150 #include <wtf/dtoa.h>
153 #if ENABLE(ENCRYPTED_MEDIA_V2)
158 #if ENABLE(VIDEO_TRACK)
159 #include "CaptionUserPreferences.h"
160 #include "PageGroup.h"
164 #include "HTMLMediaElement.h"
165 #include "TimeRanges.h"
168 #if ENABLE(SPEECH_SYNTHESIS)
169 #include "DOMWindowSpeechSynthesis.h"
170 #include "PlatformSpeechSynthesizerMock.h"
171 #include "SpeechSynthesis.h"
174 #if ENABLE(VIBRATION)
175 #include "Vibration.h"
178 #if ENABLE(MEDIA_STREAM)
179 #include "MockRealtimeMediaSourceCenter.h"
183 #include "MockMediaEndpoint.h"
184 #include "RTCPeerConnection.h"
185 #include "RTCPeerConnectionHandlerMock.h"
188 #if ENABLE(MEDIA_SOURCE)
189 #include "MockMediaPlayerMediaSource.h"
193 #include "DictionaryLookup.h"
196 #if ENABLE(CONTENT_FILTERING)
197 #include "MockContentFilterSettings.h"
200 #if ENABLE(WEB_AUDIO)
201 #include "AudioContext.h"
204 #if ENABLE(MEDIA_SESSION)
205 #include "MediaSession.h"
206 #include "MediaSessionManager.h"
209 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
210 #include "MediaPlaybackTargetContext.h"
213 #if PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000
214 #if __has_include(<AccessibilitySupport.h>)
215 #include <AccessibilitySupport.h>
218 void _AXSSetForceAllowWebScaling(Boolean);
225 using JSC::CodeBlock;
226 using JSC::FunctionExecutable;
227 using JSC::Identifier;
228 using JSC::JSFunction;
229 using JSC::JSGlobalObject;
232 using JSC::MarkedArgumentBuffer;
233 using JSC::PropertySlot;
234 using JSC::ScriptExecutable;
235 using JSC::StackVisitor;
237 using namespace Inspector;
241 using namespace HTMLNames;
243 class InspectorStubFrontend : public InspectorFrontendClientLocal, public FrontendChannel {
245 InspectorStubFrontend(Page& inspectedPage, RefPtr<DOMWindow>&& frontendWindow);
246 virtual ~InspectorStubFrontend();
248 // InspectorFrontendClient API
249 void attachWindow(DockSide) override { }
250 void detachWindow() override { }
251 void closeWindow() override;
252 void bringToFront() override { }
253 String localizedStringsURL() override { return String(); }
254 void inspectedURLChanged(const String&) override { }
256 void setAttachedWindowHeight(unsigned) override { }
257 void setAttachedWindowWidth(unsigned) override { }
260 // Inspector::FrontendChannel API
261 bool sendMessageToFrontend(const String& message) override;
262 ConnectionType connectionType() const override { return ConnectionType::Local; }
265 Page* frontendPage() const
267 if (!m_frontendWindow || !m_frontendWindow->document())
270 return m_frontendWindow->document()->page();
273 RefPtr<DOMWindow> m_frontendWindow;
274 InspectorController& m_frontendController;
277 InspectorStubFrontend::InspectorStubFrontend(Page& inspectedPage, RefPtr<DOMWindow>&& frontendWindow)
278 : InspectorFrontendClientLocal(&inspectedPage.inspectorController(), frontendWindow->document()->page(), std::make_unique<InspectorFrontendClientLocal::Settings>())
279 , m_frontendWindow(frontendWindow.copyRef())
280 , m_frontendController(frontendPage()->inspectorController())
282 ASSERT_ARG(frontendWindow, frontendWindow);
284 m_frontendController.setInspectorFrontendClient(this);
285 inspectedPage.inspectorController().connectFrontend(this);
288 InspectorStubFrontend::~InspectorStubFrontend()
293 void InspectorStubFrontend::closeWindow()
295 if (!m_frontendWindow)
298 m_frontendController.setInspectorFrontendClient(nullptr);
299 inspectedPage()->inspectorController().disconnectFrontend(this);
301 m_frontendWindow->close();
302 m_frontendWindow = nullptr;
305 bool InspectorStubFrontend::sendMessageToFrontend(const String& message)
307 ASSERT_ARG(message, !message.isEmpty());
309 return InspectorClient::doDispatchMessageOnFrontendPage(frontendPage(), message);
312 static bool markerTypeFrom(const String& markerType, DocumentMarker::MarkerType& result)
314 if (equalLettersIgnoringASCIICase(markerType, "spelling"))
315 result = DocumentMarker::Spelling;
316 else if (equalLettersIgnoringASCIICase(markerType, "grammar"))
317 result = DocumentMarker::Grammar;
318 else if (equalLettersIgnoringASCIICase(markerType, "textmatch"))
319 result = DocumentMarker::TextMatch;
320 else if (equalLettersIgnoringASCIICase(markerType, "replacement"))
321 result = DocumentMarker::Replacement;
322 else if (equalLettersIgnoringASCIICase(markerType, "correctionindicator"))
323 result = DocumentMarker::CorrectionIndicator;
324 else if (equalLettersIgnoringASCIICase(markerType, "rejectedcorrection"))
325 result = DocumentMarker::RejectedCorrection;
326 else if (equalLettersIgnoringASCIICase(markerType, "autocorrected"))
327 result = DocumentMarker::Autocorrected;
328 else if (equalLettersIgnoringASCIICase(markerType, "spellcheckingexemption"))
329 result = DocumentMarker::SpellCheckingExemption;
330 else if (equalLettersIgnoringASCIICase(markerType, "deletedautocorrection"))
331 result = DocumentMarker::DeletedAutocorrection;
332 else if (equalLettersIgnoringASCIICase(markerType, "dictationalternatives"))
333 result = DocumentMarker::DictationAlternatives;
334 #if ENABLE(TELEPHONE_NUMBER_DETECTION)
335 else if (equalLettersIgnoringASCIICase(markerType, "telephonenumber"))
336 result = DocumentMarker::TelephoneNumber;
344 static bool markerTypesFrom(const String& markerType, DocumentMarker::MarkerTypes& result)
346 DocumentMarker::MarkerType singularResult;
348 if (markerType.isEmpty() || equalLettersIgnoringASCIICase(markerType, "all"))
349 result = DocumentMarker::AllMarkers();
350 else if (markerTypeFrom(markerType, singularResult))
351 result = singularResult;
358 const char* Internals::internalsId = "internals";
360 Ref<Internals> Internals::create(Document& document)
362 return adoptRef(*new Internals(document));
365 Internals::~Internals()
369 void Internals::resetToConsistentState(Page& page)
371 page.setPageScaleFactor(1, IntPoint(0, 0));
372 page.setPagination(Pagination());
373 page.setPaginationLineGridEnabled(false);
375 page.setDefersLoading(false);
377 page.mainFrame().setTextZoomFactor(1.0f);
379 FrameView* mainFrameView = page.mainFrame().view();
381 mainFrameView->setHeaderHeight(0);
382 mainFrameView->setFooterHeight(0);
383 page.setTopContentInset(0);
384 mainFrameView->setUseFixedLayout(false);
385 mainFrameView->setFixedLayoutSize(IntSize());
388 WebCore::overrideUserPreferredLanguages(Vector<String>());
389 WebCore::Settings::setUsesOverlayScrollbars(false);
390 WebCore::Settings::setUsesMockScrollAnimator(false);
391 page.inspectorController().setLegacyProfilerEnabled(false);
392 #if ENABLE(VIDEO_TRACK)
393 page.group().captionPreferences().setCaptionsStyleSheetOverride(emptyString());
394 page.group().captionPreferences().setTestingMode(false);
396 if (!page.mainFrame().editor().isContinuousSpellCheckingEnabled())
397 page.mainFrame().editor().toggleContinuousSpellChecking();
398 if (page.mainFrame().editor().isOverwriteModeEnabled())
399 page.mainFrame().editor().toggleOverwriteModeEnabled();
400 page.mainFrame().loader().clearTestingOverrides();
401 ApplicationCacheStorage::singleton().setDefaultOriginQuota(ApplicationCacheStorage::noQuota());
403 PlatformMediaSessionManager::sharedManager().resetRestrictions();
404 PlatformMediaSessionManager::sharedManager().setWillIgnoreSystemInterruptions(true);
406 #if HAVE(ACCESSIBILITY)
407 AXObjectCache::setEnhancedUserInterfaceAccessibility(false);
408 AXObjectCache::disableAccessibility();
411 MockPageOverlayClient::singleton().uninstallAllOverlays();
413 #if ENABLE(CONTENT_FILTERING)
414 MockContentFilterSettings::reset();
417 page.setShowAllPlugins(false);
419 #if PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000
420 _AXSSetForceAllowWebScaling(false);
424 Internals::Internals(Document& document)
425 : ContextDestructionObserver(&document)
427 #if ENABLE(VIDEO_TRACK)
429 document.page()->group().captionPreferences().setTestingMode(true);
432 #if ENABLE(MEDIA_STREAM)
433 setMockMediaCaptureDevicesEnabled(true);
437 enableMockMediaEndpoint();
438 enableMockRTCPeerConnectionHandler();
441 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
443 document.page()->setMockMediaPlaybackTargetPickerEnabled(true);
447 Document* Internals::contextDocument() const
449 return downcast<Document>(scriptExecutionContext());
452 Frame* Internals::frame() const
454 if (!contextDocument())
456 return contextDocument()->frame();
459 InternalSettings* Internals::settings() const
461 Document* document = contextDocument();
464 Page* page = document->page();
467 return InternalSettings::from(page);
470 unsigned Internals::workerThreadCount() const
472 return WorkerThread::workerThreadCount();
475 String Internals::address(Node& node)
477 return String::format("%p", &node);
480 bool Internals::nodeNeedsStyleRecalc(Node& node)
482 return node.needsStyleRecalc();
485 static String styleChangeTypeToString(StyleChangeType type)
489 return "NoStyleChange";
490 case InlineStyleChange:
491 return "InlineStyleChange";
492 case FullStyleChange:
493 return "FullStyleChange";
494 case SyntheticStyleChange:
495 return "SyntheticStyleChange";
496 case ReconstructRenderTree:
497 return "ReconstructRenderTree";
499 ASSERT_NOT_REACHED();
503 String Internals::styleChangeType(Node& node)
505 return styleChangeTypeToString(node.styleChangeType());
508 String Internals::description(JSC::JSValue value)
510 return toString(value);
513 bool Internals::isPreloaded(const String& url)
515 Document* document = contextDocument();
516 return document->cachedResourceLoader().isPreloaded(url);
519 bool Internals::isLoadingFromMemoryCache(const String& url)
521 if (!contextDocument() || !contextDocument()->page())
524 ResourceRequest request(contextDocument()->completeURL(url));
525 #if ENABLE(CACHE_PARTITIONING)
526 request.setDomainForCachePartition(contextDocument()->topOrigin()->domainForCachePartition());
528 CachedResource* resource = MemoryCache::singleton().resourceForRequest(request, contextDocument()->page()->sessionID());
529 return resource && resource->status() == CachedResource::Cached;
532 String Internals::xhrResponseSource(XMLHttpRequest& request)
534 if (request.resourceResponse().isNull())
535 return "Null response";
536 switch (request.resourceResponse().source()) {
537 case ResourceResponse::Source::Unknown:
539 case ResourceResponse::Source::Network:
541 case ResourceResponse::Source::DiskCache:
543 case ResourceResponse::Source::DiskCacheAfterValidation:
544 return "Disk cache after validation";
545 case ResourceResponse::Source::MemoryCache:
546 return "Memory cache";
547 case ResourceResponse::Source::MemoryCacheAfterValidation:
548 return "Memory cache after validation";
550 ASSERT_NOT_REACHED();
554 bool Internals::isSharingStyleSheetContents(HTMLLinkElement& a, HTMLLinkElement& b)
556 if (!a.sheet() || !b.sheet())
558 return &a.sheet()->contents() == &b.sheet()->contents();
561 bool Internals::isStyleSheetLoadingSubresources(HTMLLinkElement& link)
563 return link.sheet() && link.sheet()->contents().isLoadingSubresources();
566 static ResourceRequestCachePolicy stringToResourceRequestCachePolicy(const String& policy)
568 if (policy == "UseProtocolCachePolicy")
569 return UseProtocolCachePolicy;
570 if (policy == "ReloadIgnoringCacheData")
571 return ReloadIgnoringCacheData;
572 if (policy == "ReturnCacheDataElseLoad")
573 return ReturnCacheDataElseLoad;
574 if (policy == "ReturnCacheDataDontLoad")
575 return ReturnCacheDataDontLoad;
576 ASSERT_NOT_REACHED();
577 return UseProtocolCachePolicy;
580 void Internals::setOverrideCachePolicy(const String& policy)
582 frame()->loader().setOverrideCachePolicyForTesting(stringToResourceRequestCachePolicy(policy));
585 void Internals::setCanShowModalDialogOverride(bool allow, ExceptionCode& ec)
587 if (!contextDocument() || !contextDocument()->domWindow()) {
588 ec = INVALID_ACCESS_ERR;
592 contextDocument()->domWindow()->setCanShowModalDialogOverride(allow);
595 static ResourceLoadPriority stringToResourceLoadPriority(const String& policy)
597 if (policy == "ResourceLoadPriorityVeryLow")
598 return ResourceLoadPriority::VeryLow;
599 if (policy == "ResourceLoadPriorityLow")
600 return ResourceLoadPriority::Low;
601 if (policy == "ResourceLoadPriorityMedium")
602 return ResourceLoadPriority::Medium;
603 if (policy == "ResourceLoadPriorityHigh")
604 return ResourceLoadPriority::High;
605 if (policy == "ResourceLoadPriorityVeryHigh")
606 return ResourceLoadPriority::VeryHigh;
607 ASSERT_NOT_REACHED();
608 return ResourceLoadPriority::Low;
611 void Internals::setOverrideResourceLoadPriority(const String& priority)
613 frame()->loader().setOverrideResourceLoadPriorityForTesting(stringToResourceLoadPriority(priority));
616 void Internals::setStrictRawResourceValidationPolicyDisabled(bool disabled)
618 frame()->loader().setStrictRawResourceValidationPolicyDisabledForTesting(disabled);
621 void Internals::clearMemoryCache()
623 MemoryCache::singleton().evictResources();
626 void Internals::pruneMemoryCacheToSize(unsigned size)
628 MemoryCache::singleton().pruneDeadResourcesToSize(size);
629 MemoryCache::singleton().pruneLiveResourcesToSize(size, true);
632 unsigned Internals::memoryCacheSize() const
634 return MemoryCache::singleton().size();
637 unsigned Internals::imageFrameIndex(HTMLImageElement& element)
639 auto* cachedImage = element.cachedImage();
643 auto* image = cachedImage->image();
644 return is<BitmapImage>(image) ? downcast<BitmapImage>(*image).currentFrame() : 0;
647 void Internals::clearPageCache()
649 PageCache::singleton().pruneToSizeNow(0, PruningReason::None);
652 unsigned Internals::pageCacheSize() const
654 return PageCache::singleton().pageCount();
657 Node* Internals::treeScopeRootNode(Node& node)
659 return &node.treeScope().rootNode();
662 Node* Internals::parentTreeScope(Node& node)
664 const TreeScope* parentTreeScope = node.treeScope().parentTreeScope();
665 return parentTreeScope ? &parentTreeScope->rootNode() : nullptr;
668 unsigned Internals::lastSpatialNavigationCandidateCount(ExceptionCode& ec) const
670 if (!contextDocument() || !contextDocument()->page()) {
671 ec = INVALID_ACCESS_ERR;
675 return contextDocument()->page()->lastSpatialNavigationCandidateCount();
678 unsigned Internals::numberOfActiveAnimations() const
680 return frame()->animation().numberOfActiveAnimations(frame()->document());
683 bool Internals::animationsAreSuspended(ExceptionCode& ec) const
685 Document* document = contextDocument();
686 if (!document || !document->frame()) {
687 ec = INVALID_ACCESS_ERR;
691 return document->frame()->animation().isSuspended();
694 void Internals::suspendAnimations(ExceptionCode& ec) const
696 Document* document = contextDocument();
697 if (!document || !document->frame()) {
698 ec = INVALID_ACCESS_ERR;
702 document->frame()->animation().suspendAnimations();
705 void Internals::resumeAnimations(ExceptionCode& ec) const
707 Document* document = contextDocument();
708 if (!document || !document->frame()) {
709 ec = INVALID_ACCESS_ERR;
713 document->frame()->animation().resumeAnimations();
716 bool Internals::pauseAnimationAtTimeOnElement(const String& animationName, double pauseTime, Element& element, ExceptionCode& ec)
719 ec = INVALID_ACCESS_ERR;
722 return frame()->animation().pauseAnimationAtTime(element.renderer(), AtomicString(animationName), pauseTime);
725 bool Internals::pauseAnimationAtTimeOnPseudoElement(const String& animationName, double pauseTime, Element& element, const String& pseudoId, ExceptionCode& ec)
728 ec = INVALID_ACCESS_ERR;
732 if (pseudoId != "before" && pseudoId != "after") {
733 ec = INVALID_ACCESS_ERR;
737 PseudoElement* pseudoElement = pseudoId == "before" ? element.beforePseudoElement() : element.afterPseudoElement();
738 if (!pseudoElement) {
739 ec = INVALID_ACCESS_ERR;
743 return frame()->animation().pauseAnimationAtTime(pseudoElement->renderer(), AtomicString(animationName), pauseTime);
746 bool Internals::pauseTransitionAtTimeOnElement(const String& propertyName, double pauseTime, Element& element, ExceptionCode& ec)
749 ec = INVALID_ACCESS_ERR;
752 return frame()->animation().pauseTransitionAtTime(element.renderer(), propertyName, pauseTime);
755 bool Internals::pauseTransitionAtTimeOnPseudoElement(const String& property, double pauseTime, Element& element, const String& pseudoId, ExceptionCode& ec)
758 ec = INVALID_ACCESS_ERR;
762 if (pseudoId != "before" && pseudoId != "after") {
763 ec = INVALID_ACCESS_ERR;
767 PseudoElement* pseudoElement = pseudoId == "before" ? element.beforePseudoElement() : element.afterPseudoElement();
768 if (!pseudoElement) {
769 ec = INVALID_ACCESS_ERR;
773 return frame()->animation().pauseTransitionAtTime(pseudoElement->renderer(), property, pauseTime);
776 String Internals::elementRenderTreeAsText(Element& element, ExceptionCode& ec)
778 element.document().updateStyleIfNeeded();
780 String representation = externalRepresentation(&element);
781 if (representation.isEmpty()) {
782 ec = INVALID_ACCESS_ERR;
786 return representation;
789 bool Internals::hasPausedImageAnimations(Element& element)
791 return element.renderer() && element.renderer()->hasPausedImageAnimations();
794 RefPtr<CSSComputedStyleDeclaration> Internals::computedStyleIncludingVisitedInfo(Node& node) const
796 bool allowVisitedStyle = true;
797 return CSSComputedStyleDeclaration::create(&node, allowVisitedStyle);
800 Node* Internals::ensureShadowRoot(Element& host, ExceptionCode& ec)
802 if (ShadowRoot* shadowRoot = host.shadowRoot())
805 return host.createShadowRoot(ec).get();
808 Node* Internals::ensureUserAgentShadowRoot(Element& host)
810 return &host.ensureUserAgentShadowRoot();
813 Node* Internals::createShadowRoot(Element& host, ExceptionCode& ec)
815 return host.createShadowRoot(ec).get();
818 Node* Internals::shadowRoot(Element& host)
820 return host.shadowRoot();
823 String Internals::shadowRootType(const Node& root, ExceptionCode& ec) const
825 if (!is<ShadowRoot>(root)) {
826 ec = INVALID_ACCESS_ERR;
830 switch (downcast<ShadowRoot>(root).type()) {
831 case ShadowRoot::Type::UserAgent:
832 return String("UserAgentShadowRoot");
833 case ShadowRoot::Type::Closed:
834 return String("ClosedShadowRoot");
835 case ShadowRoot::Type::Open:
836 return String("OpenShadowRoot");
838 ASSERT_NOT_REACHED();
839 return String("Unknown");
843 String Internals::shadowPseudoId(Element& element)
845 return element.shadowPseudoId().string();
848 void Internals::setShadowPseudoId(Element& element, const String& id)
850 return element.setPseudo(id);
853 bool Internals::isTimerThrottled(int timeoutId, ExceptionCode& ec)
855 DOMTimer* timer = scriptExecutionContext()->findTimeout(timeoutId);
860 return timer->m_throttleState == DOMTimer::ShouldThrottle;
863 bool Internals::isRequestAnimationFrameThrottled() const
865 #if ENABLE(REQUEST_ANIMATION_FRAME)
866 auto* scriptedAnimationController = contextDocument()->scriptedAnimationController();
867 if (!scriptedAnimationController)
869 return scriptedAnimationController->isThrottled();
875 bool Internals::areTimersThrottled() const
877 return contextDocument()->isTimerThrottlingEnabled();
880 String Internals::visiblePlaceholder(Element& element)
882 if (is<HTMLTextFormControlElement>(element)) {
883 const HTMLTextFormControlElement& textFormControlElement = downcast<HTMLTextFormControlElement>(element);
884 if (!textFormControlElement.isPlaceholderVisible())
886 if (HTMLElement* placeholderElement = textFormControlElement.placeholderElement())
887 return placeholderElement->textContent();
893 void Internals::selectColorInColorChooser(HTMLInputElement& element, const String& colorValue)
895 element.selectColor(Color(colorValue));
898 Vector<String> Internals::formControlStateOfPreviousHistoryItem(ExceptionCode& ec)
900 HistoryItem* mainItem = frame()->loader().history().previousItem();
902 ec = INVALID_ACCESS_ERR;
903 return Vector<String>();
905 String uniqueName = frame()->tree().uniqueName();
906 if (mainItem->target() != uniqueName && !mainItem->childItemWithTarget(uniqueName)) {
907 ec = INVALID_ACCESS_ERR;
908 return Vector<String>();
910 return mainItem->target() == uniqueName ? mainItem->documentState() : mainItem->childItemWithTarget(uniqueName)->documentState();
913 void Internals::setFormControlStateOfPreviousHistoryItem(const Vector<String>& state, ExceptionCode& ec)
915 HistoryItem* mainItem = frame()->loader().history().previousItem();
917 ec = INVALID_ACCESS_ERR;
920 String uniqueName = frame()->tree().uniqueName();
921 if (mainItem->target() == uniqueName)
922 mainItem->setDocumentState(state);
923 else if (HistoryItem* subItem = mainItem->childItemWithTarget(uniqueName))
924 subItem->setDocumentState(state);
926 ec = INVALID_ACCESS_ERR;
929 #if ENABLE(SPEECH_SYNTHESIS)
930 void Internals::enableMockSpeechSynthesizer()
932 Document* document = contextDocument();
933 if (!document || !document->domWindow())
935 SpeechSynthesis* synthesis = DOMWindowSpeechSynthesis::speechSynthesis(*document->domWindow());
939 synthesis->setPlatformSynthesizer(std::make_unique<PlatformSpeechSynthesizerMock>(synthesis));
944 void Internals::enableMockMediaEndpoint()
946 MediaEndpoint::create = MockMediaEndpoint::create;
949 void Internals::enableMockRTCPeerConnectionHandler()
951 RTCPeerConnectionHandler::create = RTCPeerConnectionHandlerMock::create;
955 #if ENABLE(MEDIA_STREAM)
956 void Internals::setMockMediaCaptureDevicesEnabled(bool enabled)
958 WebCore::Settings::setMockCaptureDevicesEnabled(enabled);
962 Ref<ClientRect> Internals::absoluteCaretBounds(ExceptionCode& ec)
964 Document* document = contextDocument();
965 if (!document || !document->frame()) {
966 ec = INVALID_ACCESS_ERR;
967 return ClientRect::create();
970 return ClientRect::create(document->frame()->selection().absoluteCaretBounds());
973 Ref<ClientRect> Internals::boundingBox(Element& element)
975 element.document().updateLayoutIgnorePendingStylesheets();
976 auto renderer = element.renderer();
978 return ClientRect::create();
979 return ClientRect::create(renderer->absoluteBoundingBoxRectIgnoringTransforms());
982 Ref<ClientRectList> Internals::inspectorHighlightRects(ExceptionCode& ec)
984 Document* document = contextDocument();
985 if (!document || !document->page()) {
986 ec = INVALID_ACCESS_ERR;
987 return ClientRectList::create();
991 document->page()->inspectorController().getHighlight(highlight, InspectorOverlay::CoordinateSystem::View);
992 return ClientRectList::create(highlight.quads);
995 String Internals::inspectorHighlightObject(ExceptionCode& ec)
997 Document* document = contextDocument();
998 if (!document || !document->page()) {
999 ec = INVALID_ACCESS_ERR;
1003 return document->page()->inspectorController().buildObjectForHighlightedNodes()->toJSONString();
1006 unsigned Internals::markerCountForNode(Node& node, const String& markerType, ExceptionCode& ec)
1008 DocumentMarker::MarkerTypes markerTypes = 0;
1009 if (!markerTypesFrom(markerType, markerTypes)) {
1014 node.document().frame()->editor().updateEditorUINowIfScheduled();
1015 return node.document().markers().markersFor(&node, markerTypes).size();
1018 RenderedDocumentMarker* Internals::markerAt(Node& node, const String& markerType, unsigned index, ExceptionCode& ec)
1020 node.document().updateLayoutIgnorePendingStylesheets();
1022 DocumentMarker::MarkerTypes markerTypes = 0;
1023 if (!markerTypesFrom(markerType, markerTypes)) {
1028 node.document().frame()->editor().updateEditorUINowIfScheduled();
1030 Vector<RenderedDocumentMarker*> markers = node.document().markers().markersFor(&node, markerTypes);
1031 if (markers.size() <= index)
1033 return markers[index];
1036 RefPtr<Range> Internals::markerRangeForNode(Node& node, const String& markerType, unsigned index, ExceptionCode& ec)
1038 RenderedDocumentMarker* marker = markerAt(node, markerType, index, ec);
1041 return Range::create(node.document(), &node, marker->startOffset(), &node, marker->endOffset());
1044 String Internals::markerDescriptionForNode(Node& node, const String& markerType, unsigned index, ExceptionCode& ec)
1046 RenderedDocumentMarker* marker = markerAt(node, markerType, index, ec);
1049 return marker->description();
1052 String Internals::dumpMarkerRects(const String& markerTypeString, ExceptionCode& ec)
1054 DocumentMarker::MarkerType markerType;
1055 if (!markerTypeFrom(markerTypeString, markerType)) {
1060 contextDocument()->markers().updateRectsForInvalidatedMarkersOfType(markerType);
1061 auto rects = contextDocument()->markers().renderedRectsForMarkers(markerType);
1063 StringBuilder rectString;
1064 rectString.appendLiteral("marker rects: ");
1065 for (const auto& rect : rects) {
1066 rectString.append('(');
1067 rectString.appendNumber(rect.x());
1068 rectString.appendLiteral(", ");
1069 rectString.appendNumber(rect.y());
1070 rectString.appendLiteral(", ");
1071 rectString.appendNumber(rect.width());
1072 rectString.appendLiteral(", ");
1073 rectString.appendNumber(rect.height());
1074 rectString.appendLiteral(") ");
1076 return rectString.toString();
1079 void Internals::addTextMatchMarker(const Range& range, bool isActive)
1081 range.ownerDocument().updateLayoutIgnorePendingStylesheets();
1082 range.ownerDocument().markers().addTextMatchMarker(&range, isActive);
1085 void Internals::setMarkedTextMatchesAreHighlighted(bool flag, ExceptionCode& ec)
1087 Document* document = contextDocument();
1088 if (!document || !document->frame()) {
1089 ec = INVALID_ACCESS_ERR;
1092 document->frame()->editor().setMarkedTextMatchesAreHighlighted(flag);
1095 void Internals::invalidateFontCache()
1097 FontCache::singleton().invalidate();
1100 void Internals::setScrollViewPosition(int x, int y, ExceptionCode& ec)
1102 Document* document = contextDocument();
1103 if (!document || !document->view()) {
1104 ec = INVALID_ACCESS_ERR;
1108 FrameView* frameView = document->view();
1109 bool constrainsScrollingToContentEdgeOldValue = frameView->constrainsScrollingToContentEdge();
1110 bool scrollbarsSuppressedOldValue = frameView->scrollbarsSuppressed();
1112 frameView->setConstrainsScrollingToContentEdge(false);
1113 frameView->setScrollbarsSuppressed(false);
1114 frameView->setScrollOffsetFromInternals({ x, y });
1115 frameView->setScrollbarsSuppressed(scrollbarsSuppressedOldValue);
1116 frameView->setConstrainsScrollingToContentEdge(constrainsScrollingToContentEdgeOldValue);
1119 void Internals::setViewBaseBackgroundColor(const String& colorValue, ExceptionCode& ec)
1121 Document* document = contextDocument();
1122 if (!document || !document->view()) {
1123 ec = INVALID_ACCESS_ERR;
1127 document->view()->setBaseBackgroundColor(Color(colorValue));
1130 void Internals::setPagination(const String& mode, int gap, int pageLength, ExceptionCode& ec)
1132 Document* document = contextDocument();
1133 if (!document || !document->page()) {
1134 ec = INVALID_ACCESS_ERR;
1137 Page* page = document->page();
1139 Pagination pagination;
1140 if (mode == "Unpaginated")
1141 pagination.mode = Pagination::Unpaginated;
1142 else if (mode == "LeftToRightPaginated")
1143 pagination.mode = Pagination::LeftToRightPaginated;
1144 else if (mode == "RightToLeftPaginated")
1145 pagination.mode = Pagination::RightToLeftPaginated;
1146 else if (mode == "TopToBottomPaginated")
1147 pagination.mode = Pagination::TopToBottomPaginated;
1148 else if (mode == "BottomToTopPaginated")
1149 pagination.mode = Pagination::BottomToTopPaginated;
1155 pagination.gap = gap;
1156 pagination.pageLength = pageLength;
1157 page->setPagination(pagination);
1160 void Internals::setPaginationLineGridEnabled(bool enabled, ExceptionCode& ec)
1162 Document* document = contextDocument();
1163 if (!document || !document->page()) {
1164 ec = INVALID_ACCESS_ERR;
1167 Page* page = document->page();
1168 page->setPaginationLineGridEnabled(enabled);
1171 String Internals::configurationForViewport(float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight, ExceptionCode& ec)
1173 Document* document = contextDocument();
1174 if (!document || !document->page()) {
1175 ec = INVALID_ACCESS_ERR;
1178 Page* page = document->page();
1180 const int defaultLayoutWidthForNonMobilePages = 980;
1182 ViewportArguments arguments = page->viewportArguments();
1183 ViewportAttributes attributes = computeViewportAttributes(arguments, defaultLayoutWidthForNonMobilePages, deviceWidth, deviceHeight, devicePixelRatio, IntSize(availableWidth, availableHeight));
1184 restrictMinimumScaleFactorToViewportSize(attributes, IntSize(availableWidth, availableHeight), devicePixelRatio);
1185 restrictScaleFactorToInitialScaleIfNotUserScalable(attributes);
1187 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");
1190 bool Internals::wasLastChangeUserEdit(Element& textField, ExceptionCode& ec)
1192 if (is<HTMLInputElement>(textField))
1193 return downcast<HTMLInputElement>(textField).lastChangeWasUserEdit();
1195 if (is<HTMLTextAreaElement>(textField))
1196 return downcast<HTMLTextAreaElement>(textField).lastChangeWasUserEdit();
1198 ec = INVALID_NODE_TYPE_ERR;
1202 bool Internals::elementShouldAutoComplete(HTMLInputElement& element)
1204 return element.shouldAutocomplete();
1207 void Internals::setEditingValue(HTMLInputElement& element, const String& value)
1209 element.setEditingValue(value);
1212 void Internals::setAutofilled(HTMLInputElement& element, bool enabled)
1214 element.setAutoFilled(enabled);
1217 static AutoFillButtonType stringToAutoFillButtonType(const String& autoFillButtonType)
1219 if (autoFillButtonType == "AutoFillButtonTypeNone")
1220 return AutoFillButtonType::None;
1221 if (autoFillButtonType == "AutoFillButtonTypeCredentials")
1222 return AutoFillButtonType::Credentials;
1223 if (autoFillButtonType == "AutoFillButtonTypeContacts")
1224 return AutoFillButtonType::Contacts;
1225 ASSERT_NOT_REACHED();
1226 return AutoFillButtonType::None;
1229 void Internals::setShowAutoFillButton(HTMLInputElement& element, const String& autoFillButtonType)
1231 element.setShowAutoFillButton(stringToAutoFillButtonType(autoFillButtonType));
1235 void Internals::scrollElementToRect(Element& element, int x, int y, int w, int h, ExceptionCode& ec)
1237 FrameView* frameView = element.document().view();
1239 ec = INVALID_ACCESS_ERR;
1242 frameView->scrollElementToRect(element, { x, y, w, h });
1245 String Internals::autofillFieldName(Element& element, ExceptionCode& ec)
1247 if (!is<HTMLFormControlElement>(element)) {
1248 ec = INVALID_NODE_TYPE_ERR;
1252 return downcast<HTMLFormControlElement>(element).autofillData().fieldName;
1255 void Internals::paintControlTints(ExceptionCode& ec)
1257 Document* document = contextDocument();
1258 if (!document || !document->view()) {
1259 ec = INVALID_ACCESS_ERR;
1263 FrameView* frameView = document->view();
1264 frameView->paintControlTints();
1267 RefPtr<Range> Internals::rangeFromLocationAndLength(Element& scope, int rangeLocation, int rangeLength)
1269 return TextIterator::rangeFromLocationAndLength(&scope, rangeLocation, rangeLength);
1272 unsigned Internals::locationFromRange(Element& scope, const Range& range)
1274 size_t location = 0;
1275 size_t unusedLength = 0;
1276 TextIterator::getLocationAndLengthFromRange(&scope, &range, location, unusedLength);
1280 unsigned Internals::lengthFromRange(Element& scope, const Range& range)
1282 size_t unusedLocation = 0;
1284 TextIterator::getLocationAndLengthFromRange(&scope, &range, unusedLocation, length);
1288 String Internals::rangeAsText(const Range& range)
1290 return range.text();
1293 RefPtr<Range> Internals::subrange(Range& range, int rangeLocation, int rangeLength)
1295 return TextIterator::subrange(&range, rangeLocation, rangeLength);
1298 RefPtr<Range> Internals::rangeForDictionaryLookupAtLocation(int x, int y, ExceptionCode& ec)
1301 Document* document = contextDocument();
1302 if (!document || !document->frame()) {
1303 ec = INVALID_ACCESS_ERR;
1307 document->updateLayoutIgnorePendingStylesheets();
1309 HitTestResult result = document->frame()->mainFrame().eventHandler().hitTestResultAtPoint(IntPoint(x, y));
1310 NSDictionary *options = nullptr;
1311 return DictionaryLookup::rangeAtHitTestResult(result, &options);
1315 ec = INVALID_ACCESS_ERR;
1320 void Internals::setDelegatesScrolling(bool enabled, ExceptionCode& ec)
1322 Document* document = contextDocument();
1323 // Delegate scrolling is valid only on mainframe's view.
1324 if (!document || !document->view() || !document->page() || &document->page()->mainFrame() != document->frame()) {
1325 ec = INVALID_ACCESS_ERR;
1329 document->view()->setDelegatesScrolling(enabled);
1332 int Internals::lastSpellCheckRequestSequence(ExceptionCode& ec)
1334 Document* document = contextDocument();
1335 if (!document || !document->frame()) {
1336 ec = INVALID_ACCESS_ERR;
1340 return document->frame()->editor().spellChecker().lastRequestSequence();
1343 int Internals::lastSpellCheckProcessedSequence(ExceptionCode& ec)
1345 Document* document = contextDocument();
1346 if (!document || !document->frame()) {
1347 ec = INVALID_ACCESS_ERR;
1351 return document->frame()->editor().spellChecker().lastProcessedSequence();
1354 Vector<String> Internals::userPreferredLanguages() const
1356 return WebCore::userPreferredLanguages();
1359 void Internals::setUserPreferredLanguages(const Vector<String>& languages)
1361 WebCore::overrideUserPreferredLanguages(languages);
1364 Vector<String> Internals::userPreferredAudioCharacteristics() const
1366 Document* document = contextDocument();
1367 if (!document || !document->page())
1368 return Vector<String>();
1369 #if ENABLE(VIDEO_TRACK)
1370 return document->page()->group().captionPreferences().preferredAudioCharacteristics();
1372 return Vector<String>();
1376 void Internals::setUserPreferredAudioCharacteristic(const String& characteristic)
1378 Document* document = contextDocument();
1379 if (!document || !document->page())
1381 #if ENABLE(VIDEO_TRACK)
1382 document->page()->group().captionPreferences().setPreferredAudioCharacteristic(characteristic);
1384 UNUSED_PARAM(characteristic);
1388 unsigned Internals::wheelEventHandlerCount(ExceptionCode& ec)
1390 Document* document = contextDocument();
1392 ec = INVALID_ACCESS_ERR;
1396 return document->wheelEventHandlerCount();
1399 unsigned Internals::touchEventHandlerCount(ExceptionCode& ec)
1401 Document* document = contextDocument();
1403 ec = INVALID_ACCESS_ERR;
1407 return document->touchEventHandlerCount();
1410 // FIXME: Remove the document argument. It is almost always the same as
1411 // contextDocument(), with the exception of a few tests that pass a
1412 // different document, and could just make the call through another Internals
1413 // instance instead.
1414 RefPtr<NodeList> Internals::nodesFromRect(Document& document, int centerX, int centerY, unsigned topPadding, unsigned rightPadding,
1415 unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent, ExceptionCode& ec) const
1417 if (!document.frame() || !document.frame()->view()) {
1418 ec = INVALID_ACCESS_ERR;
1422 Frame* frame = document.frame();
1423 FrameView* frameView = document.view();
1424 RenderView* renderView = document.renderView();
1428 document.updateLayoutIgnorePendingStylesheets();
1430 float zoomFactor = frame->pageZoomFactor();
1431 LayoutPoint point(centerX * zoomFactor + frameView->scrollX(), centerY * zoomFactor + frameView->scrollY());
1433 HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly | HitTestRequest::Active;
1435 hitType |= HitTestRequest::IgnoreClipping;
1436 if (!allowShadowContent)
1437 hitType |= HitTestRequest::DisallowShadowContent;
1438 if (allowChildFrameContent)
1439 hitType |= HitTestRequest::AllowChildFrameContent;
1441 HitTestRequest request(hitType);
1443 // When ignoreClipping is false, this method returns null for coordinates outside of the viewport.
1444 if (!request.ignoreClipping() && !frameView->visibleContentRect().intersects(HitTestLocation::rectForPoint(point, topPadding, rightPadding, bottomPadding, leftPadding)))
1447 Vector<Ref<Node>> matches;
1449 // Need padding to trigger a rect based hit test, but we want to return a NodeList
1450 // so we special case this.
1451 if (!topPadding && !rightPadding && !bottomPadding && !leftPadding) {
1452 HitTestResult result(point);
1453 renderView->hitTest(request, result);
1454 if (result.innerNode())
1455 matches.append(*result.innerNode()->deprecatedShadowAncestorNode());
1457 HitTestResult result(point, topPadding, rightPadding, bottomPadding, leftPadding);
1458 renderView->hitTest(request, result);
1460 const HitTestResult::NodeSet& nodeSet = result.rectBasedTestResult();
1461 matches.reserveInitialCapacity(nodeSet.size());
1462 for (auto& node : nodeSet)
1463 matches.uncheckedAppend(*node);
1466 return StaticNodeList::adopt(matches);
1469 class GetCallerCodeBlockFunctor {
1471 GetCallerCodeBlockFunctor()
1477 StackVisitor::Status operator()(StackVisitor& visitor) const
1480 if (m_iterations < 2)
1481 return StackVisitor::Continue;
1483 m_codeBlock = visitor->codeBlock();
1484 return StackVisitor::Done;
1487 CodeBlock* codeBlock() const { return m_codeBlock; }
1490 mutable int m_iterations;
1491 mutable CodeBlock* m_codeBlock;
1494 String Internals::parserMetaData(JSC::JSValue code)
1496 JSC::VM& vm = contextDocument()->vm();
1497 JSC::ExecState* exec = vm.topCallFrame;
1498 ScriptExecutable* executable;
1500 if (!code || code.isNull() || code.isUndefined()) {
1501 GetCallerCodeBlockFunctor iter;
1502 exec->iterate(iter);
1503 CodeBlock* codeBlock = iter.codeBlock();
1504 executable = codeBlock->ownerScriptExecutable();
1505 } else if (code.isFunction()) {
1506 JSFunction* funcObj = JSC::jsCast<JSFunction*>(code.toObject(exec));
1507 executable = funcObj->jsExecutable();
1511 unsigned startLine = executable->firstLine();
1512 unsigned startColumn = executable->startColumn();
1513 unsigned endLine = executable->lastLine();
1514 unsigned endColumn = executable->endColumn();
1516 StringBuilder result;
1518 if (executable->isFunctionExecutable()) {
1519 FunctionExecutable* funcExecutable = reinterpret_cast<FunctionExecutable*>(executable);
1520 String inferredName = funcExecutable->inferredName().string();
1521 result.appendLiteral("function \"");
1522 result.append(inferredName);
1524 } else if (executable->isEvalExecutable())
1525 result.appendLiteral("eval");
1526 else if (executable->isModuleProgramExecutable())
1527 result.appendLiteral("module");
1528 else if (executable->isProgramExecutable())
1529 result.appendLiteral("program");
1530 #if ENABLE(WEBASSEMBLY)
1531 else if (executable->isWebAssemblyExecutable())
1532 result.appendLiteral("WebAssembly");
1535 ASSERT_NOT_REACHED();
1537 result.appendLiteral(" { ");
1538 result.appendNumber(startLine);
1540 result.appendNumber(startColumn);
1541 result.appendLiteral(" - ");
1542 result.appendNumber(endLine);
1544 result.appendNumber(endColumn);
1545 result.appendLiteral(" }");
1547 return result.toString();
1550 void Internals::setBatteryStatus(const String& eventType, bool charging, double chargingTime, double dischargingTime, double level, ExceptionCode& ec)
1552 Document* document = contextDocument();
1553 if (!document || !document->page()) {
1554 ec = INVALID_ACCESS_ERR;
1558 #if ENABLE(BATTERY_STATUS)
1559 BatteryController::from(document->page())->didChangeBatteryStatus(eventType, BatteryStatus::create(charging, chargingTime, dischargingTime, level));
1561 UNUSED_PARAM(eventType);
1562 UNUSED_PARAM(charging);
1563 UNUSED_PARAM(chargingTime);
1564 UNUSED_PARAM(dischargingTime);
1565 UNUSED_PARAM(level);
1569 void Internals::setDeviceProximity(const String& eventType, double value, double min, double max, ExceptionCode& ec)
1571 Document* document = contextDocument();
1572 if (!document || !document->page()) {
1573 ec = INVALID_ACCESS_ERR;
1577 #if ENABLE(PROXIMITY_EVENTS)
1578 DeviceProximityController::from(document->page())->didChangeDeviceProximity(value, min, max);
1580 UNUSED_PARAM(eventType);
1581 UNUSED_PARAM(value);
1587 void Internals::updateEditorUINowIfScheduled()
1589 if (Document* document = contextDocument()) {
1590 if (Frame* frame = document->frame())
1591 frame->editor().updateEditorUINowIfScheduled();
1595 bool Internals::hasSpellingMarker(int from, int length, ExceptionCode&)
1597 Document* document = contextDocument();
1598 if (!document || !document->frame())
1601 updateEditorUINowIfScheduled();
1603 return document->frame()->editor().selectionStartHasMarkerFor(DocumentMarker::Spelling, from, length);
1606 bool Internals::hasAutocorrectedMarker(int from, int length, ExceptionCode&)
1608 Document* document = contextDocument();
1609 if (!document || !document->frame())
1612 updateEditorUINowIfScheduled();
1614 return document->frame()->editor().selectionStartHasMarkerFor(DocumentMarker::Autocorrected, from, length);
1617 void Internals::setContinuousSpellCheckingEnabled(bool enabled, ExceptionCode&)
1619 if (!contextDocument() || !contextDocument()->frame())
1622 if (enabled != contextDocument()->frame()->editor().isContinuousSpellCheckingEnabled())
1623 contextDocument()->frame()->editor().toggleContinuousSpellChecking();
1626 void Internals::setAutomaticQuoteSubstitutionEnabled(bool enabled, ExceptionCode&)
1628 if (!contextDocument() || !contextDocument()->frame())
1631 #if USE(AUTOMATIC_TEXT_REPLACEMENT)
1632 if (enabled != contextDocument()->frame()->editor().isAutomaticQuoteSubstitutionEnabled())
1633 contextDocument()->frame()->editor().toggleAutomaticQuoteSubstitution();
1635 UNUSED_PARAM(enabled);
1639 void Internals::setAutomaticLinkDetectionEnabled(bool enabled, ExceptionCode&)
1641 if (!contextDocument() || !contextDocument()->frame())
1644 #if USE(AUTOMATIC_TEXT_REPLACEMENT)
1645 if (enabled != contextDocument()->frame()->editor().isAutomaticLinkDetectionEnabled())
1646 contextDocument()->frame()->editor().toggleAutomaticLinkDetection();
1648 UNUSED_PARAM(enabled);
1652 void Internals::setAutomaticDashSubstitutionEnabled(bool enabled, ExceptionCode&)
1654 if (!contextDocument() || !contextDocument()->frame())
1657 #if USE(AUTOMATIC_TEXT_REPLACEMENT)
1658 if (enabled != contextDocument()->frame()->editor().isAutomaticDashSubstitutionEnabled())
1659 contextDocument()->frame()->editor().toggleAutomaticDashSubstitution();
1661 UNUSED_PARAM(enabled);
1665 void Internals::setAutomaticTextReplacementEnabled(bool enabled, ExceptionCode&)
1667 if (!contextDocument() || !contextDocument()->frame())
1670 #if USE(AUTOMATIC_TEXT_REPLACEMENT)
1671 if (enabled != contextDocument()->frame()->editor().isAutomaticTextReplacementEnabled())
1672 contextDocument()->frame()->editor().toggleAutomaticTextReplacement();
1674 UNUSED_PARAM(enabled);
1678 void Internals::setAutomaticSpellingCorrectionEnabled(bool enabled, ExceptionCode&)
1680 if (!contextDocument() || !contextDocument()->frame())
1683 #if USE(AUTOMATIC_TEXT_REPLACEMENT)
1684 if (enabled != contextDocument()->frame()->editor().isAutomaticSpellingCorrectionEnabled())
1685 contextDocument()->frame()->editor().toggleAutomaticSpellingCorrection();
1687 UNUSED_PARAM(enabled);
1691 void Internals::handleAcceptedCandidate(const String& candidate, ExceptionCode&)
1693 if (!contextDocument() || !contextDocument()->frame())
1696 TextCheckingResult result;
1697 result.type = TextCheckingTypeNone;
1698 result.length = candidate.length();
1699 result.replacement = candidate;
1700 contextDocument()->frame()->editor().handleAcceptedCandidate(result);
1703 bool Internals::isOverwriteModeEnabled(ExceptionCode&)
1705 Document* document = contextDocument();
1706 if (!document || !document->frame())
1709 return document->frame()->editor().isOverwriteModeEnabled();
1712 void Internals::toggleOverwriteModeEnabled(ExceptionCode&)
1714 Document* document = contextDocument();
1715 if (!document || !document->frame())
1718 document->frame()->editor().toggleOverwriteModeEnabled();
1721 unsigned Internals::countMatchesForText(const String& text, unsigned findOptions, const String& markMatches, ExceptionCode&)
1723 Document* document = contextDocument();
1724 if (!document || !document->frame())
1727 bool mark = markMatches == "mark";
1728 return document->frame()->editor().countMatchesForText(text, nullptr, findOptions, 1000, mark, nullptr);
1731 const ProfilesArray& Internals::consoleProfiles() const
1733 return contextDocument()->page()->console().profiles();
1736 unsigned Internals::numberOfLiveNodes() const
1738 unsigned nodeCount = 0;
1739 for (auto* document : Document::allDocuments())
1740 nodeCount += document->referencingNodeCount();
1744 unsigned Internals::numberOfLiveDocuments() const
1746 return Document::allDocuments().size();
1749 RefPtr<DOMWindow> Internals::openDummyInspectorFrontend(const String& url)
1751 Page* inspectedPage = contextDocument()->frame()->page();
1752 RefPtr<DOMWindow> window = inspectedPage->mainFrame().document()->domWindow();
1753 RefPtr<DOMWindow> frontendWindow = window->open(url, "", "", *window, *window);
1754 m_inspectorFrontend = std::make_unique<InspectorStubFrontend>(*inspectedPage, frontendWindow.copyRef());
1756 return frontendWindow;
1759 void Internals::closeDummyInspectorFrontend()
1761 m_inspectorFrontend = nullptr;
1764 void Internals::setLegacyJavaScriptProfilingEnabled(bool enabled, ExceptionCode& ec)
1766 Page* page = contextDocument()->frame()->page();
1768 ec = INVALID_ACCESS_ERR;
1772 page->inspectorController().setLegacyProfilerEnabled(enabled);
1775 void Internals::setInspectorIsUnderTest(bool isUnderTest, ExceptionCode& ec)
1777 Page* page = contextDocument()->frame()->page();
1779 ec = INVALID_ACCESS_ERR;
1783 page->inspectorController().setIsUnderTest(isUnderTest);
1786 bool Internals::hasGrammarMarker(int from, int length, ExceptionCode&)
1788 Document* document = contextDocument();
1789 if (!document || !document->frame())
1792 return document->frame()->editor().selectionStartHasMarkerFor(DocumentMarker::Grammar, from, length);
1795 unsigned Internals::numberOfScrollableAreas(ExceptionCode&)
1797 Document* document = contextDocument();
1798 if (!document || !document->frame())
1802 Frame* frame = document->frame();
1803 if (frame->view()->scrollableAreas())
1804 count += frame->view()->scrollableAreas()->size();
1806 for (Frame* child = frame->tree().firstChild(); child; child = child->tree().nextSibling()) {
1807 if (child->view() && child->view()->scrollableAreas())
1808 count += child->view()->scrollableAreas()->size();
1814 bool Internals::isPageBoxVisible(int pageNumber, ExceptionCode& ec)
1816 Document* document = contextDocument();
1818 ec = INVALID_ACCESS_ERR;
1822 return document->isPageBoxVisible(pageNumber);
1825 // FIXME: Remove the document argument. It is almost always the same as
1826 // contextDocument(), with the exception of a few tests that pass a
1827 // different document, and could just make the call through another Internals
1828 // instance instead.
1829 String Internals::layerTreeAsText(Document& document, ExceptionCode& ec) const
1831 return layerTreeAsText(document, 0, ec);
1834 String Internals::layerTreeAsText(Document& document, unsigned flags, ExceptionCode& ec) const
1836 if (!document.frame()) {
1837 ec = INVALID_ACCESS_ERR;
1841 LayerTreeFlags layerTreeFlags = 0;
1842 if (flags & LAYER_TREE_INCLUDES_VISIBLE_RECTS)
1843 layerTreeFlags |= LayerTreeFlagsIncludeVisibleRects;
1844 if (flags & LAYER_TREE_INCLUDES_TILE_CACHES)
1845 layerTreeFlags |= LayerTreeFlagsIncludeTileCaches;
1846 if (flags & LAYER_TREE_INCLUDES_REPAINT_RECTS)
1847 layerTreeFlags |= LayerTreeFlagsIncludeRepaintRects;
1848 if (flags & LAYER_TREE_INCLUDES_PAINTING_PHASES)
1849 layerTreeFlags |= LayerTreeFlagsIncludePaintingPhases;
1850 if (flags & LAYER_TREE_INCLUDES_CONTENT_LAYERS)
1851 layerTreeFlags |= LayerTreeFlagsIncludeContentLayers;
1853 return document.frame()->layerTreeAsText(layerTreeFlags);
1856 String Internals::repaintRectsAsText(ExceptionCode& ec) const
1858 Document* document = contextDocument();
1859 if (!document || !document->frame()) {
1860 ec = INVALID_ACCESS_ERR;
1864 return document->frame()->trackedRepaintRectsAsText();
1867 String Internals::scrollingStateTreeAsText(ExceptionCode& ec) const
1869 Document* document = contextDocument();
1870 if (!document || !document->frame()) {
1871 ec = INVALID_ACCESS_ERR;
1875 Page* page = document->page();
1879 return page->scrollingStateTreeAsText();
1882 String Internals::mainThreadScrollingReasons(ExceptionCode& ec) const
1884 Document* document = contextDocument();
1885 if (!document || !document->frame()) {
1886 ec = INVALID_ACCESS_ERR;
1890 Page* page = document->page();
1894 return page->synchronousScrollingReasonsAsText();
1897 RefPtr<ClientRectList> Internals::nonFastScrollableRects(ExceptionCode& ec) const
1899 Document* document = contextDocument();
1900 if (!document || !document->frame()) {
1901 ec = INVALID_ACCESS_ERR;
1905 Page* page = document->page();
1909 return page->nonFastScrollableRects();
1912 void Internals::setElementUsesDisplayListDrawing(Element& element, bool usesDisplayListDrawing, ExceptionCode& ec)
1914 Document* document = contextDocument();
1915 if (!document || !document->renderView()) {
1916 ec = INVALID_ACCESS_ERR;
1920 if (!element.renderer()) {
1921 ec = INVALID_ACCESS_ERR;
1925 if (is<HTMLCanvasElement>(element)) {
1926 downcast<HTMLCanvasElement>(element).setUsesDisplayListDrawing(usesDisplayListDrawing);
1930 if (!element.renderer()->hasLayer()) {
1931 ec = INVALID_ACCESS_ERR;
1935 RenderLayer* layer = downcast<RenderLayerModelObject>(element.renderer())->layer();
1936 if (!layer->isComposited()) {
1937 ec = INVALID_ACCESS_ERR;
1941 layer->backing()->setUsesDisplayListDrawing(usesDisplayListDrawing);
1944 void Internals::setElementTracksDisplayListReplay(Element& element, bool isTrackingReplay, ExceptionCode& ec)
1946 Document* document = contextDocument();
1947 if (!document || !document->renderView()) {
1948 ec = INVALID_ACCESS_ERR;
1952 if (!element.renderer()) {
1953 ec = INVALID_ACCESS_ERR;
1957 if (is<HTMLCanvasElement>(element)) {
1958 downcast<HTMLCanvasElement>(element).setTracksDisplayListReplay(isTrackingReplay);
1962 if (!element.renderer()->hasLayer()) {
1963 ec = INVALID_ACCESS_ERR;
1967 RenderLayer* layer = downcast<RenderLayerModelObject>(element.renderer())->layer();
1968 if (!layer->isComposited()) {
1969 ec = INVALID_ACCESS_ERR;
1973 layer->backing()->setIsTrackingDisplayListReplay(isTrackingReplay);
1976 String Internals::displayListForElement(Element& element, ExceptionCode& ec)
1978 return displayListForElement(element, 0, ec);
1981 String Internals::displayListForElement(Element& element, unsigned flags, ExceptionCode& ec)
1983 Document* document = contextDocument();
1984 if (!document || !document->renderView()) {
1985 ec = INVALID_ACCESS_ERR;
1989 if (!element.renderer()) {
1990 ec = INVALID_ACCESS_ERR;
1994 DisplayList::AsTextFlags displayListFlags = 0;
1995 if (flags & DISPLAY_LIST_INCLUDES_PLATFORM_OPERATIONS)
1996 displayListFlags |= DisplayList::AsTextFlag::IncludesPlatformOperations;
1998 if (is<HTMLCanvasElement>(element))
1999 return downcast<HTMLCanvasElement>(element).displayListAsText(displayListFlags);
2001 if (!element.renderer()->hasLayer()) {
2002 ec = INVALID_ACCESS_ERR;
2006 RenderLayer* layer = downcast<RenderLayerModelObject>(element.renderer())->layer();
2007 if (!layer->isComposited()) {
2008 ec = INVALID_ACCESS_ERR;
2012 return layer->backing()->displayListAsText(displayListFlags);
2015 String Internals::replayDisplayListForElement(Element& element, ExceptionCode& ec)
2017 return replayDisplayListForElement(element, 0, ec);
2020 String Internals::replayDisplayListForElement(Element& element, unsigned flags, ExceptionCode& ec)
2022 Document* document = contextDocument();
2023 if (!document || !document->renderView()) {
2024 ec = INVALID_ACCESS_ERR;
2028 if (!element.renderer()) {
2029 ec = INVALID_ACCESS_ERR;
2033 DisplayList::AsTextFlags displayListFlags = 0;
2034 if (flags & DISPLAY_LIST_INCLUDES_PLATFORM_OPERATIONS)
2035 displayListFlags |= DisplayList::AsTextFlag::IncludesPlatformOperations;
2037 if (is<HTMLCanvasElement>(element))
2038 return downcast<HTMLCanvasElement>(element).replayDisplayListAsText(displayListFlags);
2040 if (!element.renderer()->hasLayer()) {
2041 ec = INVALID_ACCESS_ERR;
2045 RenderLayer* layer = downcast<RenderLayerModelObject>(element.renderer())->layer();
2046 if (!layer->isComposited()) {
2047 ec = INVALID_ACCESS_ERR;
2051 return layer->backing()->replayDisplayListAsText(displayListFlags);
2054 void Internals::garbageCollectDocumentResources(ExceptionCode& ec) const
2056 Document* document = contextDocument();
2058 ec = INVALID_ACCESS_ERR;
2061 document->cachedResourceLoader().garbageCollectDocumentResources();
2064 void Internals::insertAuthorCSS(const String& css, ExceptionCode& ec) const
2066 Document* document = contextDocument();
2068 ec = INVALID_ACCESS_ERR;
2072 auto parsedSheet = StyleSheetContents::create(*document);
2073 parsedSheet.get().setIsUserStyleSheet(false);
2074 parsedSheet.get().parseString(css);
2075 document->extensionStyleSheets().addAuthorStyleSheetForTesting(WTFMove(parsedSheet));
2078 void Internals::insertUserCSS(const String& css, ExceptionCode& ec) const
2080 Document* document = contextDocument();
2082 ec = INVALID_ACCESS_ERR;
2086 auto parsedSheet = StyleSheetContents::create(*document);
2087 parsedSheet.get().setIsUserStyleSheet(true);
2088 parsedSheet.get().parseString(css);
2089 document->extensionStyleSheets().addUserStyleSheet(WTFMove(parsedSheet));
2092 String Internals::counterValue(Element& element)
2094 return counterValueForElement(&element);
2097 int Internals::pageNumber(Element& element, float pageWidth, float pageHeight)
2099 return PrintContext::pageNumberForElement(&element, { pageWidth, pageHeight });
2102 Vector<String> Internals::shortcutIconURLs() const
2104 Vector<String> vector;
2109 auto string = frame()->loader().icon().url().string();
2110 if (!string.isNull())
2111 vector.append(string);
2115 int Internals::numberOfPages(float pageWidth, float pageHeight)
2120 return PrintContext::numberOfPages(*frame(), FloatSize(pageWidth, pageHeight));
2123 String Internals::pageProperty(String propertyName, int pageNumber, ExceptionCode& ec) const
2126 ec = INVALID_ACCESS_ERR;
2130 return PrintContext::pageProperty(frame(), propertyName.utf8().data(), pageNumber);
2133 String Internals::pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft, ExceptionCode& ec) const
2136 ec = INVALID_ACCESS_ERR;
2140 return PrintContext::pageSizeAndMarginsInPixels(frame(), pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft);
2143 void Internals::setPageScaleFactor(float scaleFactor, int x, int y, ExceptionCode& ec)
2145 Document* document = contextDocument();
2146 if (!document || !document->page()) {
2147 ec = INVALID_ACCESS_ERR;
2150 Page* page = document->page();
2151 page->setPageScaleFactor(scaleFactor, IntPoint(x, y));
2154 void Internals::setPageZoomFactor(float zoomFactor, ExceptionCode& ec)
2156 Document* document = contextDocument();
2157 if (!document || !document->frame()) {
2158 ec = INVALID_ACCESS_ERR;
2161 Frame* frame = document->frame();
2162 frame->setPageZoomFactor(zoomFactor);
2165 void Internals::setTextZoomFactor(float zoomFactor, ExceptionCode& ec)
2167 Document* document = contextDocument();
2168 if (!document || !document->frame()) {
2169 ec = INVALID_ACCESS_ERR;
2172 Frame* frame = document->frame();
2173 frame->setTextZoomFactor(zoomFactor);
2176 void Internals::setUseFixedLayout(bool useFixedLayout, ExceptionCode& ec)
2178 Document* document = contextDocument();
2179 if (!document || !document->view()) {
2180 ec = INVALID_ACCESS_ERR;
2183 FrameView* frameView = document->view();
2184 frameView->setUseFixedLayout(useFixedLayout);
2187 void Internals::setFixedLayoutSize(int width, int height, ExceptionCode& ec)
2189 Document* document = contextDocument();
2190 if (!document || !document->view()) {
2191 ec = INVALID_ACCESS_ERR;
2194 FrameView* frameView = document->view();
2195 frameView->setFixedLayoutSize(IntSize(width, height));
2198 void Internals::setViewExposedRect(float x, float y, float width, float height, ExceptionCode& ec)
2200 Document* document = contextDocument();
2201 if (!document || !document->view()) {
2202 ec = INVALID_ACCESS_ERR;
2206 FrameView* frameView = document->view();
2207 frameView->setViewExposedRect(FloatRect(x, y, width, height));
2210 void Internals::setHeaderHeight(float height)
2212 Document* document = contextDocument();
2213 if (!document || !document->view())
2216 FrameView* frameView = document->view();
2217 frameView->setHeaderHeight(height);
2220 void Internals::setFooterHeight(float height)
2222 Document* document = contextDocument();
2223 if (!document || !document->view())
2226 FrameView* frameView = document->view();
2227 frameView->setFooterHeight(height);
2230 void Internals::setTopContentInset(float contentInset)
2232 Document* document = contextDocument();
2236 Page* page = document->page();
2237 page->setTopContentInset(contentInset);
2240 #if ENABLE(FULLSCREEN_API)
2241 void Internals::webkitWillEnterFullScreenForElement(Element& element)
2243 Document* document = contextDocument();
2246 document->webkitWillEnterFullScreenForElement(&element);
2249 void Internals::webkitDidEnterFullScreenForElement(Element& element)
2251 Document* document = contextDocument();
2254 document->webkitDidEnterFullScreenForElement(&element);
2257 void Internals::webkitWillExitFullScreenForElement(Element& element)
2259 Document* document = contextDocument();
2262 document->webkitWillExitFullScreenForElement(&element);
2265 void Internals::webkitDidExitFullScreenForElement(Element& element)
2267 Document* document = contextDocument();
2270 document->webkitDidExitFullScreenForElement(&element);
2274 void Internals::setApplicationCacheOriginQuota(unsigned long long quota)
2276 Document* document = contextDocument();
2279 ApplicationCacheStorage::singleton().storeUpdatedQuotaForOrigin(document->securityOrigin(), quota);
2282 void Internals::registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme)
2284 SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy(scheme);
2287 void Internals::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme)
2289 SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(scheme);
2292 Ref<MallocStatistics> Internals::mallocStatistics() const
2294 return MallocStatistics::create();
2297 Ref<TypeConversions> Internals::typeConversions() const
2299 return TypeConversions::create();
2302 Ref<MemoryInfo> Internals::memoryInfo() const
2304 return MemoryInfo::create();
2307 Vector<String> Internals::getReferencedFilePaths() const
2309 frame()->loader().history().saveDocumentAndScrollState();
2310 return FormController::getReferencedFilePaths(frame()->loader().history().currentItem()->documentState());
2313 void Internals::startTrackingRepaints(ExceptionCode& ec)
2315 Document* document = contextDocument();
2316 if (!document || !document->view()) {
2317 ec = INVALID_ACCESS_ERR;
2321 FrameView* frameView = document->view();
2322 frameView->setTracksRepaints(true);
2325 void Internals::stopTrackingRepaints(ExceptionCode& ec)
2327 Document* document = contextDocument();
2328 if (!document || !document->view()) {
2329 ec = INVALID_ACCESS_ERR;
2333 FrameView* frameView = document->view();
2334 frameView->setTracksRepaints(false);
2337 void Internals::startTrackingLayerFlushes(ExceptionCode& ec)
2339 Document* document = contextDocument();
2340 if (!document || !document->renderView()) {
2341 ec = INVALID_ACCESS_ERR;
2345 document->renderView()->compositor().startTrackingLayerFlushes();
2348 unsigned Internals::layerFlushCount(ExceptionCode& ec)
2350 Document* document = contextDocument();
2351 if (!document || !document->renderView()) {
2352 ec = INVALID_ACCESS_ERR;
2356 return document->renderView()->compositor().layerFlushCount();
2359 void Internals::startTrackingStyleRecalcs(ExceptionCode& ec)
2361 Document* document = contextDocument();
2363 ec = INVALID_ACCESS_ERR;
2366 document->startTrackingStyleRecalcs();
2369 unsigned Internals::styleRecalcCount(ExceptionCode& ec)
2371 Document* document = contextDocument();
2373 ec = INVALID_ACCESS_ERR;
2377 return document->styleRecalcCount();
2380 void Internals::startTrackingCompositingUpdates(ExceptionCode& ec)
2382 Document* document = contextDocument();
2383 if (!document || !document->renderView()) {
2384 ec = INVALID_ACCESS_ERR;
2388 document->renderView()->compositor().startTrackingCompositingUpdates();
2391 unsigned Internals::compositingUpdateCount(ExceptionCode& ec)
2393 Document* document = contextDocument();
2394 if (!document || !document->renderView()) {
2395 ec = INVALID_ACCESS_ERR;
2399 return document->renderView()->compositor().compositingUpdateCount();
2402 void Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionCode& ec)
2404 updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(nullptr, ec);
2407 void Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node* node, ExceptionCode& ec)
2411 document = contextDocument();
2412 else if (is<Document>(*node))
2413 document = downcast<Document>(node);
2414 else if (is<HTMLIFrameElement>(*node))
2415 document = downcast<HTMLIFrameElement>(*node).contentDocument();
2421 document->updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasks::Synchronously);
2424 unsigned Internals::layoutCount() const
2426 Document* document = contextDocument();
2427 if (!document || !document->view())
2429 return document->view()->layoutCount();
2433 static const char* cursorTypeToString(Cursor::Type cursorType)
2435 switch (cursorType) {
2436 case Cursor::Pointer: return "Pointer";
2437 case Cursor::Cross: return "Cross";
2438 case Cursor::Hand: return "Hand";
2439 case Cursor::IBeam: return "IBeam";
2440 case Cursor::Wait: return "Wait";
2441 case Cursor::Help: return "Help";
2442 case Cursor::EastResize: return "EastResize";
2443 case Cursor::NorthResize: return "NorthResize";
2444 case Cursor::NorthEastResize: return "NorthEastResize";
2445 case Cursor::NorthWestResize: return "NorthWestResize";
2446 case Cursor::SouthResize: return "SouthResize";
2447 case Cursor::SouthEastResize: return "SouthEastResize";
2448 case Cursor::SouthWestResize: return "SouthWestResize";
2449 case Cursor::WestResize: return "WestResize";
2450 case Cursor::NorthSouthResize: return "NorthSouthResize";
2451 case Cursor::EastWestResize: return "EastWestResize";
2452 case Cursor::NorthEastSouthWestResize: return "NorthEastSouthWestResize";
2453 case Cursor::NorthWestSouthEastResize: return "NorthWestSouthEastResize";
2454 case Cursor::ColumnResize: return "ColumnResize";
2455 case Cursor::RowResize: return "RowResize";
2456 case Cursor::MiddlePanning: return "MiddlePanning";
2457 case Cursor::EastPanning: return "EastPanning";
2458 case Cursor::NorthPanning: return "NorthPanning";
2459 case Cursor::NorthEastPanning: return "NorthEastPanning";
2460 case Cursor::NorthWestPanning: return "NorthWestPanning";
2461 case Cursor::SouthPanning: return "SouthPanning";
2462 case Cursor::SouthEastPanning: return "SouthEastPanning";
2463 case Cursor::SouthWestPanning: return "SouthWestPanning";
2464 case Cursor::WestPanning: return "WestPanning";
2465 case Cursor::Move: return "Move";
2466 case Cursor::VerticalText: return "VerticalText";
2467 case Cursor::Cell: return "Cell";
2468 case Cursor::ContextMenu: return "ContextMenu";
2469 case Cursor::Alias: return "Alias";
2470 case Cursor::Progress: return "Progress";
2471 case Cursor::NoDrop: return "NoDrop";
2472 case Cursor::Copy: return "Copy";
2473 case Cursor::None: return "None";
2474 case Cursor::NotAllowed: return "NotAllowed";
2475 case Cursor::ZoomIn: return "ZoomIn";
2476 case Cursor::ZoomOut: return "ZoomOut";
2477 case Cursor::Grab: return "Grab";
2478 case Cursor::Grabbing: return "Grabbing";
2479 case Cursor::Custom: return "Custom";
2482 ASSERT_NOT_REACHED();
2487 String Internals::getCurrentCursorInfo(ExceptionCode& ec)
2489 Document* document = contextDocument();
2490 if (!document || !document->frame()) {
2491 ec = INVALID_ACCESS_ERR;
2496 Cursor cursor = document->frame()->eventHandler().currentMouseCursor();
2498 StringBuilder result;
2499 result.appendLiteral("type=");
2500 result.append(cursorTypeToString(cursor.type()));
2501 result.appendLiteral(" hotSpot=");
2502 result.appendNumber(cursor.hotSpot().x());
2504 result.appendNumber(cursor.hotSpot().y());
2505 if (cursor.image()) {
2506 FloatSize size = cursor.image()->size();
2507 result.appendLiteral(" image=");
2508 result.appendNumber(size.width());
2510 result.appendNumber(size.height());
2512 #if ENABLE(MOUSE_CURSOR_SCALE)
2513 if (cursor.imageScaleFactor() != 1) {
2514 result.appendLiteral(" scale=");
2515 NumberToStringBuffer buffer;
2516 result.append(numberToFixedPrecisionString(cursor.imageScaleFactor(), 8, buffer, true));
2519 return result.toString();
2521 return "FAIL: Cursor details not available on this platform.";
2525 RefPtr<ArrayBuffer> Internals::serializeObject(PassRefPtr<SerializedScriptValue> value) const
2527 auto& bytes = value->data();
2528 return ArrayBuffer::create(bytes.data(), bytes.size());
2531 RefPtr<SerializedScriptValue> Internals::deserializeBuffer(ArrayBuffer& buffer) const
2533 Vector<uint8_t> bytes;
2534 bytes.append(static_cast<const uint8_t*>(buffer.data()), buffer.byteLength());
2535 return SerializedScriptValue::adopt(WTFMove(bytes));
2538 bool Internals::isFromCurrentWorld(JSC::JSValue value) const
2541 JSC::ExecState& state = *contextDocument()->vm().topCallFrame;
2542 return !value.isObject() || &worldForDOMObject(asObject(value)) == ¤tWorld(&state);
2545 void Internals::setUsesOverlayScrollbars(bool enabled)
2547 WebCore::Settings::setUsesOverlayScrollbars(enabled);
2550 void Internals::setUsesMockScrollAnimator(bool enabled)
2552 WebCore::Settings::setUsesMockScrollAnimator(enabled);
2555 void Internals::forceReload(bool endToEnd)
2557 frame()->loader().reload(endToEnd);
2560 void Internals::enableAutoSizeMode(bool enabled, int minimumWidth, int minimumHeight, int maximumWidth, int maximumHeight)
2562 Document* document = contextDocument();
2563 if (!document || !document->view())
2565 document->view()->enableAutoSizeMode(enabled, IntSize(minimumWidth, minimumHeight), IntSize(maximumWidth, maximumHeight));
2568 #if ENABLE(ENCRYPTED_MEDIA_V2)
2569 void Internals::initializeMockCDM()
2571 CDM::registerCDMFactory([](CDM* cdm) { return std::make_unique<MockCDM>(cdm); },
2572 MockCDM::supportsKeySystem, MockCDM::supportsKeySystemAndMimeType);
2576 String Internals::markerTextForListItem(Element& element)
2578 return WebCore::markerTextForListItem(&element);
2581 String Internals::toolTipFromElement(Element& element) const
2583 HitTestResult result;
2584 result.setInnerNode(&element);
2585 TextDirection direction;
2586 return result.title(direction);
2589 String Internals::getImageSourceURL(Element& element)
2591 return element.imageSourceURL();
2596 void Internals::simulateAudioInterruption(HTMLMediaElement& element)
2599 element.player()->simulateAudioInterruption();
2601 UNUSED_PARAM(element);
2605 bool Internals::mediaElementHasCharacteristic(HTMLMediaElement& element, const String& characteristic, ExceptionCode& ec)
2607 if (equalLettersIgnoringASCIICase(characteristic, "audible"))
2608 return element.hasAudio();
2609 if (equalLettersIgnoringASCIICase(characteristic, "visual"))
2610 return element.hasVideo();
2611 if (equalLettersIgnoringASCIICase(characteristic, "legible"))
2612 return element.hasClosedCaptions();
2619 bool Internals::isSelectPopupVisible(HTMLSelectElement& element)
2621 auto* renderer = element.renderer();
2623 if (!is<RenderMenuList>(*renderer))
2627 return downcast<RenderMenuList>(*renderer).popupIsVisible();
2633 String Internals::captionsStyleSheetOverride(ExceptionCode& ec)
2635 Document* document = contextDocument();
2636 if (!document || !document->page()) {
2637 ec = INVALID_ACCESS_ERR;
2638 return emptyString();
2641 #if ENABLE(VIDEO_TRACK)
2642 return document->page()->group().captionPreferences().captionsStyleSheetOverride();
2644 return emptyString();
2648 void Internals::setCaptionsStyleSheetOverride(const String& override, ExceptionCode& ec)
2650 Document* document = contextDocument();
2651 if (!document || !document->page()) {
2652 ec = INVALID_ACCESS_ERR;
2656 #if ENABLE(VIDEO_TRACK)
2657 document->page()->group().captionPreferences().setCaptionsStyleSheetOverride(override);
2659 UNUSED_PARAM(override);
2663 void Internals::setPrimaryAudioTrackLanguageOverride(const String& language, ExceptionCode& ec)
2665 Document* document = contextDocument();
2666 if (!document || !document->page()) {
2667 ec = INVALID_ACCESS_ERR;
2671 #if ENABLE(VIDEO_TRACK)
2672 document->page()->group().captionPreferences().setPrimaryAudioTrackLanguageOverride(language);
2674 UNUSED_PARAM(language);
2678 void Internals::setCaptionDisplayMode(const String& mode, ExceptionCode& ec)
2680 Document* document = contextDocument();
2681 if (!document || !document->page()) {
2682 ec = INVALID_ACCESS_ERR;
2686 #if ENABLE(VIDEO_TRACK)
2687 auto& captionPreferences = document->page()->group().captionPreferences();
2689 if (equalLettersIgnoringASCIICase(mode, "automatic"))
2690 captionPreferences.setCaptionDisplayMode(CaptionUserPreferences::Automatic);
2691 else if (equalLettersIgnoringASCIICase(mode, "forcedonly"))
2692 captionPreferences.setCaptionDisplayMode(CaptionUserPreferences::ForcedOnly);
2693 else if (equalLettersIgnoringASCIICase(mode, "alwayson"))
2694 captionPreferences.setCaptionDisplayMode(CaptionUserPreferences::AlwaysOn);
2695 else if (equalLettersIgnoringASCIICase(mode, "manual"))
2696 captionPreferences.setCaptionDisplayMode(CaptionUserPreferences::Manual);
2705 Ref<TimeRanges> Internals::createTimeRanges(Float32Array* startTimes, Float32Array* endTimes)
2707 ASSERT(startTimes && endTimes);
2708 ASSERT(startTimes->length() == endTimes->length());
2709 Ref<TimeRanges> ranges = TimeRanges::create();
2711 unsigned count = std::min(startTimes->length(), endTimes->length());
2712 for (unsigned i = 0; i < count; ++i)
2713 ranges->add(startTimes->item(i), endTimes->item(i));
2717 double Internals::closestTimeToTimeRanges(double time, TimeRanges& ranges)
2719 return ranges.nearest(time);
2723 Ref<ClientRect> Internals::selectionBounds(ExceptionCode& ec)
2725 Document* document = contextDocument();
2726 if (!document || !document->frame()) {
2727 ec = INVALID_ACCESS_ERR;
2728 return ClientRect::create();
2731 return ClientRect::create(document->frame()->selection().selectionBounds());
2734 #if ENABLE(VIBRATION)
2735 bool Internals::isVibrating()
2737 Page* page = contextDocument()->page();
2740 return Vibration::from(page)->isVibrating();
2744 bool Internals::isPluginUnavailabilityIndicatorObscured(Element& element, ExceptionCode& ec)
2746 auto* renderer = element.renderer();
2747 if (!is<RenderEmbeddedObject>(renderer)) {
2748 ec = INVALID_ACCESS_ERR;
2752 return downcast<RenderEmbeddedObject>(*renderer).isReplacementObscured();
2755 bool Internals::isPluginSnapshotted(Element& element)
2757 return is<HTMLPlugInElement>(element) && downcast<HTMLPlugInElement>(element).displayState() <= HTMLPlugInElement::DisplayingSnapshot;
2760 #if ENABLE(MEDIA_SOURCE)
2762 void Internals::initializeMockMediaSource()
2764 #if USE(AVFOUNDATION)
2765 WebCore::Settings::setAVFoundationEnabled(false);
2767 MediaPlayerFactorySupport::callRegisterMediaEngine(MockMediaPlayerMediaSource::registerMediaEngine);
2770 Vector<String> Internals::bufferedSamplesForTrackID(SourceBuffer& buffer, const AtomicString& trackID)
2772 return buffer.bufferedSamplesForTrackID(trackID);
2775 void Internals::setShouldGenerateTimestamps(SourceBuffer& buffer, bool flag)
2777 buffer.setShouldGenerateTimestamps(flag);
2784 void Internals::beginMediaSessionInterruption(const String& interruptionString, ExceptionCode& ec)
2786 PlatformMediaSession::InterruptionType interruption = PlatformMediaSession::SystemInterruption;
2788 if (equalLettersIgnoringASCIICase(interruptionString, "system"))
2789 interruption = PlatformMediaSession::SystemInterruption;
2790 else if (equalLettersIgnoringASCIICase(interruptionString, "systemsleep"))
2791 interruption = PlatformMediaSession::SystemSleep;
2792 else if (equalLettersIgnoringASCIICase(interruptionString, "enteringbackground"))
2793 interruption = PlatformMediaSession::EnteringBackground;
2795 ec = INVALID_ACCESS_ERR;
2799 PlatformMediaSessionManager::sharedManager().beginInterruption(interruption);
2802 void Internals::endMediaSessionInterruption(const String& flagsString)
2804 PlatformMediaSession::EndInterruptionFlags flags = PlatformMediaSession::NoFlags;
2806 if (equalLettersIgnoringASCIICase(flagsString, "mayresumeplaying"))
2807 flags = PlatformMediaSession::MayResumePlaying;
2809 PlatformMediaSessionManager::sharedManager().endInterruption(flags);
2812 void Internals::applicationDidEnterForeground() const
2814 PlatformMediaSessionManager::sharedManager().applicationDidEnterForeground();
2817 void Internals::applicationWillEnterBackground() const
2819 PlatformMediaSessionManager::sharedManager().applicationWillEnterBackground();
2822 void Internals::setMediaSessionRestrictions(const String& mediaTypeString, const String& restrictionsString, ExceptionCode& ec)
2824 PlatformMediaSession::MediaType mediaType = PlatformMediaSession::None;
2825 if (equalLettersIgnoringASCIICase(mediaTypeString, "video"))
2826 mediaType = PlatformMediaSession::Video;
2827 else if (equalLettersIgnoringASCIICase(mediaTypeString, "audio"))
2828 mediaType = PlatformMediaSession::Audio;
2829 else if (equalLettersIgnoringASCIICase(mediaTypeString, "webaudio"))
2830 mediaType = PlatformMediaSession::WebAudio;
2832 ec = INVALID_ACCESS_ERR;
2836 PlatformMediaSessionManager::SessionRestrictions restrictions = PlatformMediaSessionManager::sharedManager().restrictions(mediaType);
2837 PlatformMediaSessionManager::sharedManager().removeRestriction(mediaType, restrictions);
2839 restrictions = PlatformMediaSessionManager::NoRestrictions;
2841 Vector<String> restrictionsArray;
2842 restrictionsString.split(',', false, restrictionsArray);
2843 for (auto& restrictionString : restrictionsArray) {
2844 if (equalLettersIgnoringASCIICase(restrictionString, "concurrentplaybacknotpermitted"))
2845 restrictions |= PlatformMediaSessionManager::ConcurrentPlaybackNotPermitted;
2846 if (equalLettersIgnoringASCIICase(restrictionString, "backgroundprocessplaybackrestricted"))
2847 restrictions |= PlatformMediaSessionManager::BackgroundProcessPlaybackRestricted;
2848 if (equalLettersIgnoringASCIICase(restrictionString, "backgroundtabplaybackrestricted"))
2849 restrictions |= PlatformMediaSessionManager::BackgroundTabPlaybackRestricted;
2850 if (equalLettersIgnoringASCIICase(restrictionString, "interruptedplaybacknotpermitted"))
2851 restrictions |= PlatformMediaSessionManager::InterruptedPlaybackNotPermitted;
2853 PlatformMediaSessionManager::sharedManager().addRestriction(mediaType, restrictions);
2856 void Internals::setMediaElementRestrictions(HTMLMediaElement& element, const String& restrictionsString)
2858 MediaElementSession::BehaviorRestrictions restrictions = element.mediaSession().behaviorRestrictions();
2859 element.mediaSession().removeBehaviorRestriction(restrictions);
2861 restrictions = MediaElementSession::NoRestrictions;
2863 Vector<String> restrictionsArray;
2864 restrictionsString.split(',', false, restrictionsArray);
2865 for (auto& restrictionString : restrictionsArray) {
2866 if (equalLettersIgnoringASCIICase(restrictionString, "norestrictions"))
2867 restrictions |= MediaElementSession::NoRestrictions;
2868 if (equalLettersIgnoringASCIICase(restrictionString, "requireusergestureforload"))
2869 restrictions |= MediaElementSession::RequireUserGestureForLoad;
2870 if (equalLettersIgnoringASCIICase(restrictionString, "requireusergestureforvideoratechange"))
2871 restrictions |= MediaElementSession::RequireUserGestureForVideoRateChange;
2872 if (equalLettersIgnoringASCIICase(restrictionString, "requireusergestureforfullscreen"))
2873 restrictions |= MediaElementSession::RequireUserGestureForFullscreen;
2874 if (equalLettersIgnoringASCIICase(restrictionString, "requirepageconsenttoloadmedia"))
2875 restrictions |= MediaElementSession::RequirePageConsentToLoadMedia;
2876 if (equalLettersIgnoringASCIICase(restrictionString, "requirepageconsenttoresumemedia"))
2877 restrictions |= MediaElementSession::RequirePageConsentToResumeMedia;
2878 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
2879 if (equalLettersIgnoringASCIICase(restrictionString, "requireusergesturetoshowplaybacktargetpicker"))
2880 restrictions |= MediaElementSession::RequireUserGestureToShowPlaybackTargetPicker;
2881 if (equalLettersIgnoringASCIICase(restrictionString, "wirelessvideoplaybackdisabled"))
2882 restrictions |= MediaElementSession::WirelessVideoPlaybackDisabled;
2884 if (equalLettersIgnoringASCIICase(restrictionString, "requireusergestureforaudioratechange"))
2885 restrictions |= MediaElementSession::RequireUserGestureForAudioRateChange;
2886 if (equalLettersIgnoringASCIICase(restrictionString, "metadatapreloadingnotpermitted"))
2887 restrictions |= MediaElementSession::MetadataPreloadingNotPermitted;
2888 if (equalLettersIgnoringASCIICase(restrictionString, "autopreloadingnotpermitted"))
2889 restrictions |= MediaElementSession::AutoPreloadingNotPermitted;
2890 if (equalLettersIgnoringASCIICase(restrictionString, "invisibleautoplaynotpermitted"))
2891 restrictions |= MediaElementSession::InvisibleAutoplayNotPermitted;
2892 if (equalLettersIgnoringASCIICase(restrictionString, "overrideusergesturerequirementformaincontent"))
2893 restrictions |= MediaElementSession::OverrideUserGestureRequirementForMainContent;
2895 element.mediaSession().addBehaviorRestriction(restrictions);
2898 void Internals::postRemoteControlCommand(const String& commandString, ExceptionCode& ec)
2900 PlatformMediaSession::RemoteControlCommandType command;
2902 if (equalLettersIgnoringASCIICase(commandString, "play"))
2903 command = PlatformMediaSession::PlayCommand;
2904 else if (equalLettersIgnoringASCIICase(commandString, "pause"))
2905 command = PlatformMediaSession::PauseCommand;
2906 else if (equalLettersIgnoringASCIICase(commandString, "stop"))
2907 command = PlatformMediaSession::StopCommand;
2908 else if (equalLettersIgnoringASCIICase(commandString, "toggleplaypause"))
2909 command = PlatformMediaSession::TogglePlayPauseCommand;
2910 else if (equalLettersIgnoringASCIICase(commandString, "beginseekingbackward"))
2911 command = PlatformMediaSession::BeginSeekingBackwardCommand;
2912 else if (equalLettersIgnoringASCIICase(commandString, "endseekingbackward"))
2913 command = PlatformMediaSession::EndSeekingBackwardCommand;
2914 else if (equalLettersIgnoringASCIICase(commandString, "beginseekingforward"))
2915 command = PlatformMediaSession::BeginSeekingForwardCommand;
2916 else if (equalLettersIgnoringASCIICase(commandString, "endseekingforward"))
2917 command = PlatformMediaSession::EndSeekingForwardCommand;
2919 ec = INVALID_ACCESS_ERR;
2923 PlatformMediaSessionManager::sharedManager().didReceiveRemoteControlCommand(command);
2926 bool Internals::elementIsBlockingDisplaySleep(HTMLMediaElement& element) const
2928 return element.isDisablingSleep();
2931 #endif // ENABLE(VIDEO)
2933 #if ENABLE(MEDIA_SESSION)
2935 static MediaSessionInterruptingCategory interruptingCategoryFromString(const String& interruptingCategoryString)
2937 if (interruptingCategoryString == "content")
2938 return MediaSessionInterruptingCategory::Content;
2939 if (interruptingCategoryString == "transient")
2940 return MediaSessionInterruptingCategory::Transient;
2941 if (interruptingCategoryString == "transient-solo")
2942 return MediaSessionInterruptingCategory::TransientSolo;
2943 ASSERT_NOT_REACHED();
2944 return MediaSessionInterruptingCategory::Content;
2947 void Internals::sendMediaSessionStartOfInterruptionNotification(const String& interruptingCategoryString)
2949 MediaSessionManager::singleton().didReceiveStartOfInterruptionNotification(interruptingCategoryFromString(interruptingCategoryString));
2952 void Internals::sendMediaSessionEndOfInterruptionNotification(const String& interruptingCategoryString)
2954 MediaSessionManager::singleton().didReceiveEndOfInterruptionNotification(interruptingCategoryFromString(interruptingCategoryString));
2957 String Internals::mediaSessionCurrentState(MediaSession* session) const
2959 switch (session->currentState()) {
2960 case MediaSession::State::Active:
2962 case MediaSession::State::Interrupted:
2963 return "interrupted";
2964 case MediaSession::State::Idle:
2969 double Internals::mediaElementPlayerVolume(HTMLMediaElement* element) const
2971 ASSERT_ARG(element, element);
2972 return element->playerVolume();
2975 void Internals::sendMediaControlEvent(const String& event)
2977 if (event == "play-pause")
2978 MediaSessionManager::singleton().togglePlayback();
2979 else if (event == "next-track")
2980 MediaSessionManager::singleton().skipToNextTrack();
2981 else if (event == "previous-track")
2982 MediaSessionManager::singleton().skipToPreviousTrack();
2984 ASSERT_NOT_REACHED();
2987 #endif // ENABLE(MEDIA_SESSION)
2989 #if ENABLE(WEB_AUDIO)
2991 void Internals::setAudioContextRestrictions(AudioContext& context, const String& restrictionsString)
2993 AudioContext::BehaviorRestrictions restrictions = context.behaviorRestrictions();
2994 context.removeBehaviorRestriction(restrictions);
2996 restrictions = AudioContext::NoRestrictions;
2998 Vector<String> restrictionsArray;
2999 restrictionsString.split(',', false, restrictionsArray);
3000 for (auto& restrictionString : restrictionsArray) {
3001 if (equalLettersIgnoringASCIICase(restrictionString, "norestrictions"))
3002 restrictions |= AudioContext::NoRestrictions;
3003 if (equalLettersIgnoringASCIICase(restrictionString, "requireusergestureforaudiostart"))
3004 restrictions |= AudioContext::RequireUserGestureForAudioStartRestriction;
3005 if (equalLettersIgnoringASCIICase(restrictionString, "requirepageconsentforaudiostart"))
3006 restrictions |= AudioContext::RequirePageConsentForAudioStartRestriction;
3008 context.addBehaviorRestriction(restrictions);
3013 void Internals::simulateSystemSleep() const
3016 PlatformMediaSessionManager::sharedManager().systemWillSleep();
3020 void Internals::simulateSystemWake() const
3023 PlatformMediaSessionManager::sharedManager().systemDidWake();
3027 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
3029 void Internals::setMockMediaPlaybackTargetPickerEnabled(bool enabled)
3031 Page* page = contextDocument()->frame()->page();
3034 page->setMockMediaPlaybackTargetPickerEnabled(enabled);
3037 void Internals::setMockMediaPlaybackTargetPickerState(const String& deviceName, const String& deviceState, ExceptionCode& ec)
3039 Page* page = contextDocument()->frame()->page();
3042 MediaPlaybackTargetContext::State state = MediaPlaybackTargetContext::Unknown;
3044 if (equalLettersIgnoringASCIICase(deviceState, "deviceavailable"))
3045 state = MediaPlaybackTargetContext::OutputDeviceAvailable;
3046 else if (equalLettersIgnoringASCIICase(deviceState, "deviceunavailable"))
3047 state = MediaPlaybackTargetContext::OutputDeviceUnavailable;
3048 else if (equalLettersIgnoringASCIICase(deviceState, "unknown"))
3049 state = MediaPlaybackTargetContext::Unknown;
3051 ec = INVALID_ACCESS_ERR;
3055 page->setMockMediaPlaybackTargetPickerState(deviceName, state);
3060 RefPtr<MockPageOverlay> Internals::installMockPageOverlay(const String& overlayType, ExceptionCode& ec)
3062 Document* document = contextDocument();
3063 if (!document || !document->frame()) {
3064 ec = INVALID_ACCESS_ERR;
3068 return MockPageOverlayClient::singleton().installOverlay(document->frame()->mainFrame(), overlayType == "view" ? PageOverlay::OverlayType::View : PageOverlay::OverlayType::Document);
3071 String Internals::pageOverlayLayerTreeAsText(ExceptionCode& ec) const
3073 Document* document = contextDocument();
3074 if (!document || !document->frame()) {
3075 ec = INVALID_ACCESS_ERR;
3079 document->updateLayout();
3081 return MockPageOverlayClient::singleton().layerTreeAsText(document->frame()->mainFrame());
3084 void Internals::setPageMuted(bool muted)
3086 Document* document = contextDocument();
3090 if (Page* page = document->page())
3091 page->setMuted(muted);
3094 bool Internals::isPagePlayingAudio()
3096 Document* document = contextDocument();
3097 if (!document || !document->page())
3100 return !!(document->page()->mediaState() & MediaProducer::IsPlayingAudio);
3103 void Internals::setPageDefersLoading(bool defersLoading)
3105 Document* document = contextDocument();
3108 if (Page* page = document->page())
3109 page->setDefersLoading(defersLoading);
3112 RefPtr<File> Internals::createFile(const String& path)
3114 Document* document = contextDocument();
3118 URL url = document->completeURL(path);
3119 if (!url.isLocalFile())
3122 return File::create(url.fileSystemPath());
3125 void Internals::queueMicroTask(int testNumber)
3127 Document* document = contextDocument();
3131 auto microtask = std::make_unique<ActiveDOMCallbackMicrotask>(MicrotaskQueue::mainThreadQueue(), *document, [document, testNumber]() {
3132 document->addConsoleMessage(MessageSource::JS, MessageLevel::Debug, makeString("MicroTask #", String::number(testNumber), " has run."));
3135 MicrotaskQueue::mainThreadQueue().append(WTFMove(microtask));
3138 #if ENABLE(CONTENT_FILTERING)
3140 MockContentFilterSettings& Internals::mockContentFilterSettings()
3142 return MockContentFilterSettings::singleton();
3147 #if ENABLE(CSS_SCROLL_SNAP)
3149 static void appendOffsets(StringBuilder& builder, const Vector<LayoutUnit>& snapOffsets)
3151 bool justStarting = true;
3153 builder.append("{ ");
3154 for (auto& coordinate : snapOffsets) {
3156 builder.append(", ");
3158 justStarting = false;
3160 builder.append(String::number(coordinate.toUnsigned()));
3162 builder.append(" }");
3165 String Internals::scrollSnapOffsets(Element& element, ExceptionCode& ec)
3167 if (!element.renderBox())
3170 RenderBox& box = *element.renderBox();
3171 ScrollableArea* scrollableArea;
3174 FrameView* frameView = box.frame().mainFrame().view();
3175 if (!frameView || !frameView->isScrollable()) {
3176 ec = INVALID_ACCESS_ERR;
3179 scrollableArea = frameView;
3182 if (!box.canBeScrolledAndHasScrollableArea()) {
3183 ec = INVALID_ACCESS_ERR;
3186 scrollableArea = box.layer();
3189 if (!scrollableArea)
3192 StringBuilder result;
3194 if (scrollableArea->horizontalSnapOffsets()) {
3195 result.appendLiteral("horizontal = ");
3196 appendOffsets(result, *scrollableArea->horizontalSnapOffsets());
3199 if (scrollableArea->verticalSnapOffsets()) {
3200 if (result.length())
3201 result.appendLiteral(", ");
3203 result.appendLiteral("vertical = ");
3204 appendOffsets(result, *scrollableArea->verticalSnapOffsets());
3207 return result.toString();
3212 bool Internals::testPreloaderSettingViewport()
3214 return testPreloadScannerViewportSupport(contextDocument());
3217 String Internals::pathStringWithShrinkWrappedRects(Vector<double> rectComponents, double radius, ExceptionCode& ec)
3219 if (rectComponents.size() % 4) {
3220 ec = INVALID_ACCESS_ERR;
3224 Vector<FloatRect> rects;
3225 while (!rectComponents.isEmpty()) {
3226 double height = rectComponents.takeLast();
3227 double width = rectComponents.takeLast();
3228 double y = rectComponents.takeLast();
3229 double x = rectComponents.takeLast();
3231 rects.append(FloatRect(x, y, width, height));
3236 Path path = PathUtilities::pathWithShrinkWrappedRects(rects, radius);
3239 buildStringFromPath(path, pathString);
3245 String Internals::getCurrentMediaControlsStatusForElement(HTMLMediaElement& mediaElement)
3247 #if !ENABLE(MEDIA_CONTROLS_SCRIPT)
3248 UNUSED_PARAM(mediaElement);
3251 return mediaElement.getCurrentMediaControlsStatus();
3255 #if !PLATFORM(COCOA)
3257 String Internals::userVisibleString(const DOMURL&)
3259 // Cocoa-specific function. Could ASSERT_NOT_REACHED, but that's probably overkill.
3265 void Internals::setShowAllPlugins(bool show)
3267 Document* document = contextDocument();
3271 Page* page = document->page();
3275 page->setShowAllPlugins(show);
3278 #if ENABLE(STREAMS_API)
3280 bool Internals::isReadableStreamDisturbed(JSC::ExecState& state, JSValue stream)
3282 JSGlobalObject* globalObject = state.vmEntryGlobalObject();
3283 JSVMClientData* clientData = static_cast<JSVMClientData*>(state.vm().clientData);
3284 const Identifier& privateName = clientData->builtinFunctions().readableStreamInternalsBuiltins().isReadableStreamDisturbedPrivateName();
3286 PropertySlot propertySlot(value, PropertySlot::InternalMethodType::Get);
3287 globalObject->methodTable()->getOwnPropertySlot(globalObject, &state, privateName, propertySlot);
3288 value = propertySlot.getValue(&state, privateName);
3289 ASSERT(value.isFunction());
3291 JSObject* function = value.getObject();
3293 CallType callType = JSC::getCallData(function, callData);
3294 ASSERT(callType != JSC::CallType::None);
3295 MarkedArgumentBuffer arguments;
3296 arguments.append(stream);
3297 JSValue returnedValue = JSC::call(&state, function, callType, callData, JSC::jsUndefined(), arguments);
3298 ASSERT(returnedValue.isBoolean());
3300 return returnedValue.asBoolean();
3305 String Internals::resourceLoadStatisticsForOrigin(String origin)
3307 return ResourceLoadObserver::sharedObserver().statisticsForOrigin(origin);
3310 void Internals::setResourceLoadStatisticsEnabled(bool enable)
3312 Settings::setResourceLoadStatisticsEnabled(enable);
3315 String Internals::composedTreeAsText(Node& node)
3317 if (!is<ContainerNode>(node))
3318 return emptyString();
3319 return WebCore::composedTreeAsText(downcast<ContainerNode>(node));
3322 void Internals::setViewportForceAlwaysUserScalable(bool scalable)
3324 #if PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000
3325 _AXSSetForceAllowWebScaling(scalable);
3327 UNUSED_PARAM(scalable);