3ddeff7fa01709c5c7e06b02c6b5fe2afe970160
[WebKit-https.git] / Source / WebCore / testing / Internals.cpp
1 /*
2  * Copyright (C) 2012 Google Inc. All rights reserved.
3  * Copyright (C) 2013 Apple Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
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.
14  *
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.
25  */
26
27 #include "config.h"
28 #include "Internals.h"
29
30 #include "BackForwardController.h"
31 #include "CachedResourceLoader.h"
32 #include "Chrome.h"
33 #include "ChromeClient.h"
34 #include "ClientRect.h"
35 #include "ClientRectList.h"
36 #include "ComposedShadowTreeWalker.h"
37 #include "ContentDistributor.h"
38 #include "Cursor.h"
39 #include "DOMStringList.h"
40 #include "DOMWindow.h"
41 #include "Document.h"
42 #include "DocumentMarker.h"
43 #include "DocumentMarkerController.h"
44 #include "Element.h"
45 #include "ElementShadow.h"
46 #include "EventHandler.h"
47 #include "ExceptionCode.h"
48 #include "FormController.h"
49 #include "Frame.h"
50 #include "FrameView.h"
51 #include "HTMLContentElement.h"
52 #include "HTMLInputElement.h"
53 #include "HTMLNames.h"
54 #include "HTMLTextAreaElement.h"
55 #include "HistoryItem.h"
56 #include "InspectorClient.h"
57 #include "InspectorConsoleAgent.h"
58 #include "InspectorController.h"
59 #include "InspectorCounters.h"
60 #include "InspectorFrontendChannel.h"
61 #include "InspectorFrontendClientLocal.h"
62 #include "InspectorInstrumentation.h"
63 #include "InspectorOverlay.h"
64 #include "InstrumentingAgents.h"
65 #include "InternalSettings.h"
66 #include "IntRect.h"
67 #include "Language.h"
68 #include "MallocStatistics.h"
69 #include "MemoryCache.h"
70 #include "MockPagePopupDriver.h"
71 #include "NodeRenderingContext.h"
72 #include "Page.h"
73 #include "PrintContext.h"
74 #include "PseudoElement.h"
75 #include "Range.h"
76 #include "RenderObject.h"
77 #include "RenderTreeAsText.h"
78 #include "RuntimeEnabledFeatures.h"
79 #include "SchemeRegistry.h"
80 #include "ScrollingCoordinator.h"
81 #include "SelectRuleFeatureSet.h"
82 #include "SerializedScriptValue.h"
83 #include "Settings.h"
84 #include "ShadowRoot.h"
85 #include "SpellChecker.h"
86 #include "StyleSheetContents.h"
87 #include "TextIterator.h"
88 #include "TreeScope.h"
89 #include "TypeConversions.h"
90 #include "ViewportArguments.h"
91 #include "WorkerThread.h"
92 #include <wtf/text/StringBuffer.h>
93
94 #if ENABLE(INPUT_TYPE_COLOR)
95 #include "ColorChooser.h"
96 #endif
97
98 #if ENABLE(BATTERY_STATUS)
99 #include "BatteryController.h"
100 #endif
101
102 #if ENABLE(NETWORK_INFO)
103 #include "NetworkInfo.h"
104 #include "NetworkInfoController.h"
105 #endif
106
107 #if ENABLE(PROXIMITY_EVENTS)
108 #include "DeviceProximityController.h"
109 #endif
110
111 #if ENABLE(PAGE_POPUP)
112 #include "PagePopupController.h"
113 #endif
114
115 #if ENABLE(TOUCH_ADJUSTMENT)
116 #include "WebKitPoint.h"
117 #endif
118
119 #if ENABLE(MOUSE_CURSOR_SCALE)
120 #include <wtf/dtoa.h>
121 #endif
122
123 #if PLATFORM(CHROMIUM)
124 #include "FilterOperation.h"
125 #include "FilterOperations.h"
126 #include "GraphicsLayer.h"
127 #include "GraphicsLayerChromium.h"
128 #include "RenderLayerBacking.h"
129 #endif
130
131 #if ENABLE(ENCRYPTED_MEDIA_V2)
132 #include "CDM.h"
133 #include "MockCDM.h"
134 #endif
135
136 #if ENABLE(VIDEO_TRACK)
137 #include "CaptionUserPreferences.h"
138 #include "PageGroup.h"
139 #endif
140
141 #if ENABLE(SPEECH_SYNTHESIS)
142 #include "DOMWindowSpeechSynthesis.h"
143 #include "PlatformSpeechSynthesizerMock.h"
144 #include "SpeechSynthesis.h"
145 #endif
146
147 namespace WebCore {
148
149 #if ENABLE(PAGE_POPUP)
150 static MockPagePopupDriver* s_pagePopupDriver = 0;
151 #endif
152
153 using namespace HTMLNames;
154
155 #if ENABLE(INSPECTOR)
156 class InspectorFrontendClientDummy : public InspectorFrontendClientLocal {
157 public:
158     InspectorFrontendClientDummy(InspectorController*, Page*);
159     virtual ~InspectorFrontendClientDummy() { }
160     virtual void attachWindow() OVERRIDE { }
161     virtual void detachWindow() OVERRIDE { }
162
163     virtual String localizedStringsURL() OVERRIDE { return String(); }
164     virtual String hiddenPanels() OVERRIDE { return String(); }
165
166     virtual void bringToFront() OVERRIDE { }
167     virtual void closeWindow() OVERRIDE { }
168
169     virtual void inspectedURLChanged(const String&) OVERRIDE { }
170
171 protected:
172     virtual void setAttachedWindowHeight(unsigned) OVERRIDE { }
173 };
174
175 InspectorFrontendClientDummy::InspectorFrontendClientDummy(InspectorController* controller, Page* page)
176     : InspectorFrontendClientLocal(controller, page, adoptPtr(new InspectorFrontendClientLocal::Settings()))
177 {
178 }
179
180 class InspectorFrontendChannelDummy : public InspectorFrontendChannel {
181 public:
182     explicit InspectorFrontendChannelDummy(Page*);
183     virtual ~InspectorFrontendChannelDummy() { }
184     virtual bool sendMessageToFrontend(const String& message) OVERRIDE;
185
186 private:
187     Page* m_frontendPage;
188 };
189
190 InspectorFrontendChannelDummy::InspectorFrontendChannelDummy(Page* page)
191     : m_frontendPage(page)
192 {
193 }
194
195 bool InspectorFrontendChannelDummy::sendMessageToFrontend(const String& message)
196 {
197     return InspectorClient::doDispatchMessageOnFrontendPage(m_frontendPage, message);
198 }
199 #endif // ENABLE(INSPECTOR)
200
201 static bool markerTypesFrom(const String& markerType, DocumentMarker::MarkerTypes& result)
202 {
203     if (markerType.isEmpty() || equalIgnoringCase(markerType, "all"))
204         result = DocumentMarker::AllMarkers();
205     else if (equalIgnoringCase(markerType, "Spelling"))
206         result =  DocumentMarker::Spelling;
207     else if (equalIgnoringCase(markerType, "Grammar"))
208         result =  DocumentMarker::Grammar;
209     else if (equalIgnoringCase(markerType, "TextMatch"))
210         result =  DocumentMarker::TextMatch;
211     else if (equalIgnoringCase(markerType, "Replacement"))
212         result =  DocumentMarker::Replacement;
213     else if (equalIgnoringCase(markerType, "CorrectionIndicator"))
214         result =  DocumentMarker::CorrectionIndicator;
215     else if (equalIgnoringCase(markerType, "RejectedCorrection"))
216         result =  DocumentMarker::RejectedCorrection;
217     else if (equalIgnoringCase(markerType, "Autocorrected"))
218         result =  DocumentMarker::Autocorrected;
219     else if (equalIgnoringCase(markerType, "SpellCheckingExemption"))
220         result =  DocumentMarker::SpellCheckingExemption;
221     else if (equalIgnoringCase(markerType, "DeletedAutocorrection"))
222         result =  DocumentMarker::DeletedAutocorrection;
223     else if (equalIgnoringCase(markerType, "DictationAlternatives"))
224         result =  DocumentMarker::DictationAlternatives;
225     else
226         return false;
227
228     return true;
229 }
230
231 static SpellChecker* spellchecker(Document* document)
232 {
233     if (!document || !document->frame() || !document->frame()->editor())
234         return 0;
235
236     return document->frame()->editor()->spellChecker();
237 }
238
239 const char* Internals::internalsId = "internals";
240
241 PassRefPtr<Internals> Internals::create(Document* document)
242 {
243     return adoptRef(new Internals(document));
244 }
245
246 Internals::~Internals()
247 {
248 }
249
250 void Internals::resetToConsistentState(Page* page)
251 {
252     ASSERT(page);
253
254     page->setPageScaleFactor(1, IntPoint(0, 0));
255     page->setPagination(Pagination());
256     TextRun::setAllowsRoundingHacks(false);
257     WebCore::overrideUserPreferredLanguages(Vector<String>());
258     WebCore::Settings::setUsesOverlayScrollbars(false);
259 #if ENABLE(PAGE_POPUP)
260     delete s_pagePopupDriver;
261     s_pagePopupDriver = 0;
262     if (page->chrome())
263         page->chrome()->client()->resetPagePopupDriver();
264 #endif
265 #if ENABLE(INSPECTOR) && ENABLE(JAVASCRIPT_DEBUGGER)
266     if (page->inspectorController())
267         page->inspectorController()->setProfilerEnabled(false);
268 #endif
269 #if ENABLE(VIDEO_TRACK) && !PLATFORM(WIN)
270     page->group().captionPreferences()->setTestingMode(false);
271 #endif
272 }
273
274 Internals::Internals(Document* document)
275     : ContextDestructionObserver(document)
276 {
277 #if ENABLE(VIDEO_TRACK) && !PLATFORM(WIN)
278     if (document && document->page())
279         document->page()->group().captionPreferences()->setTestingMode(true);
280 #endif
281 }
282
283 Document* Internals::contextDocument() const
284 {
285     return static_cast<Document*>(scriptExecutionContext());
286 }
287
288 Frame* Internals::frame() const
289 {
290     if (!contextDocument())
291         return 0;
292     return contextDocument()->frame();
293 }
294
295 InternalSettings* Internals::settings() const
296 {
297     Document* document = contextDocument();
298     if (!document)
299         return 0;
300     Page* page = document->page();
301     if (!page)
302         return 0;
303     return InternalSettings::from(page);
304 }
305
306 unsigned Internals::workerThreadCount() const
307 {
308 #if ENABLE(WORKERS)
309     return WorkerThread::workerThreadCount();
310 #else
311     return 0;
312 #endif
313 }
314
315 String Internals::address(Node* node)
316 {
317     char buf[32];
318     sprintf(buf, "%p", node);
319
320     return String(buf);
321 }
322
323 bool Internals::isPreloaded(const String& url)
324 {
325     Document* document = contextDocument();
326     return document->cachedResourceLoader()->isPreloaded(url);
327 }
328
329 bool Internals::isLoadingFromMemoryCache(const String& url)
330 {
331     if (!contextDocument())
332         return false;
333     CachedResource* resource = memoryCache()->resourceForURL(contextDocument()->completeURL(url));
334     return resource && resource->status() == CachedResource::Cached;
335 }
336
337 PassRefPtr<Element> Internals::createContentElement(ExceptionCode& ec)
338 {
339     Document* document = contextDocument();
340     if (!document) {
341         ec = INVALID_ACCESS_ERR;
342         return 0;
343     }
344
345 #if ENABLE(SHADOW_DOM)
346     return HTMLContentElement::create(document);
347 #else
348     return 0;
349 #endif
350 }
351
352 bool Internals::isValidContentSelect(Element* insertionPoint, ExceptionCode& ec)
353 {
354     if (!insertionPoint || !insertionPoint->isInsertionPoint()) {
355         ec = INVALID_ACCESS_ERR;
356         return false;
357     }
358
359 #if ENABLE(SHADOW_DOM)
360     return isHTMLContentElement(insertionPoint) && toHTMLContentElement(insertionPoint)->isSelectValid();
361 #else
362     return false;
363 #endif
364 }
365
366 Node* Internals::treeScopeRootNode(Node* node, ExceptionCode& ec)
367 {
368     if (!node) {
369         ec = INVALID_ACCESS_ERR;
370         return 0;
371     }
372
373     return node->treeScope()->rootNode();
374 }
375
376 Node* Internals::parentTreeScope(Node* node, ExceptionCode& ec)
377 {
378     if (!node) {
379         ec = INVALID_ACCESS_ERR;
380         return 0;
381     }
382     const TreeScope* parentTreeScope = node->treeScope()->parentTreeScope();
383     return parentTreeScope ? parentTreeScope->rootNode() : 0;
384 }
385
386 bool Internals::hasSelectorForIdInShadow(Element* host, const String& idValue, ExceptionCode& ec)
387 {
388     if (!host || !host->shadow()) {
389         ec = INVALID_ACCESS_ERR;
390         return 0;
391     }
392
393     return host->shadow()->distributor().ensureSelectFeatureSet(host->shadow()).hasSelectorForId(idValue);
394 }
395
396 bool Internals::hasSelectorForClassInShadow(Element* host, const String& className, ExceptionCode& ec)
397 {
398     if (!host || !host->shadow()) {
399         ec = INVALID_ACCESS_ERR;
400         return 0;
401     }
402
403     return host->shadow()->distributor().ensureSelectFeatureSet(host->shadow()).hasSelectorForClass(className);
404 }
405
406 bool Internals::hasSelectorForAttributeInShadow(Element* host, const String& attributeName, ExceptionCode& ec)
407 {
408     if (!host || !host->shadow()) {
409         ec = INVALID_ACCESS_ERR;
410         return 0;
411     }
412
413     return host->shadow()->distributor().ensureSelectFeatureSet(host->shadow()).hasSelectorForAttribute(attributeName);
414 }
415
416 bool Internals::hasSelectorForPseudoClassInShadow(Element* host, const String& pseudoClass, ExceptionCode& ec)
417 {
418     if (!host || !host->shadow()) {
419         ec = INVALID_ACCESS_ERR;
420         return 0;
421     }
422
423     const SelectRuleFeatureSet& featureSet = host->shadow()->distributor().ensureSelectFeatureSet(host->shadow());
424     if (pseudoClass == "checked")
425         return featureSet.hasSelectorForChecked();
426     if (pseudoClass == "enabled")
427         return featureSet.hasSelectorForEnabled();
428     if (pseudoClass == "disabled")
429         return featureSet.hasSelectorForDisabled();
430     if (pseudoClass == "indeterminate")
431         return featureSet.hasSelectorForIndeterminate();
432     if (pseudoClass == "link")
433         return featureSet.hasSelectorForLink();
434     if (pseudoClass == "target")
435         return featureSet.hasSelectorForTarget();
436     if (pseudoClass == "visited")
437         return featureSet.hasSelectorForVisited();
438
439     ASSERT_NOT_REACHED();
440     return false;
441 }
442
443 unsigned Internals::numberOfActiveAnimations() const
444 {
445     Frame* contextFrame = frame();
446     if (AnimationController* controller = contextFrame->animation())
447         return controller->numberOfActiveAnimations(contextFrame->document());
448     return 0;
449 }
450
451 void Internals::suspendAnimations(Document* document, ExceptionCode& ec) const
452 {
453     if (!document || !document->frame()) {
454         ec = INVALID_ACCESS_ERR;
455         return;
456     }
457
458     AnimationController* controller = document->frame()->animation();
459     if (!controller)
460         return;
461
462     controller->suspendAnimations();
463 }
464
465 void Internals::resumeAnimations(Document* document, ExceptionCode& ec) const
466 {
467     if (!document || !document->frame()) {
468         ec = INVALID_ACCESS_ERR;
469         return;
470     }
471
472     AnimationController* controller = document->frame()->animation();
473     if (!controller)
474         return;
475
476     controller->resumeAnimations();
477 }
478
479 bool Internals::pauseAnimationAtTimeOnElement(const String& animationName, double pauseTime, Element* element, ExceptionCode& ec)
480 {
481     if (!element || pauseTime < 0) {
482         ec = INVALID_ACCESS_ERR;
483         return false;
484     }
485     AnimationController* controller = frame()->animation();
486     return controller->pauseAnimationAtTime(element->renderer(), AtomicString(animationName), pauseTime);
487 }
488
489 bool Internals::pauseAnimationAtTimeOnPseudoElement(const String& animationName, double pauseTime, Element* element, const String& pseudoId, ExceptionCode& ec)
490 {
491     if (!element || pauseTime < 0) {
492         ec = INVALID_ACCESS_ERR;
493         return false;
494     }
495
496     if (pseudoId != "before" && pseudoId != "after") {
497         ec = INVALID_ACCESS_ERR;
498         return false;
499     }
500
501     PseudoElement* pseudoElement = element->pseudoElement(pseudoId == "before" ? BEFORE : AFTER);
502     if (!pseudoElement) {
503         ec = INVALID_ACCESS_ERR;
504         return false;
505     }
506
507     return frame()->animation()->pauseAnimationAtTime(pseudoElement->renderer(), AtomicString(animationName), pauseTime);
508 }
509
510 bool Internals::pauseTransitionAtTimeOnElement(const String& propertyName, double pauseTime, Element* element, ExceptionCode& ec)
511 {
512     if (!element || pauseTime < 0) {
513         ec = INVALID_ACCESS_ERR;
514         return false;
515     }
516     AnimationController* controller = frame()->animation();
517     return controller->pauseTransitionAtTime(element->renderer(), propertyName, pauseTime);
518 }
519
520 bool Internals::pauseTransitionAtTimeOnPseudoElement(const String& property, double pauseTime, Element* element, const String& pseudoId, ExceptionCode& ec)
521 {
522     if (!element || pauseTime < 0) {
523         ec = INVALID_ACCESS_ERR;
524         return false;
525     }
526
527     if (pseudoId != "before" && pseudoId != "after") {
528         ec = INVALID_ACCESS_ERR;
529         return false;
530     }
531
532     PseudoElement* pseudoElement = element->pseudoElement(pseudoId == "before" ? BEFORE : AFTER);
533     if (!pseudoElement) {
534         ec = INVALID_ACCESS_ERR;
535         return false;
536     }
537
538     return frame()->animation()->pauseTransitionAtTime(pseudoElement->renderer(), property, pauseTime);
539 }
540
541 bool Internals::hasShadowInsertionPoint(const Node* root, ExceptionCode& ec) const
542 {
543     if (root && root->isShadowRoot())
544         return ScopeContentDistribution::hasShadowElement(toShadowRoot(root));
545
546     ec = INVALID_ACCESS_ERR;
547     return 0;
548 }
549
550 bool Internals::hasContentElement(const Node* root, ExceptionCode& ec) const
551 {
552     if (root && root->isShadowRoot())
553         return ScopeContentDistribution::hasContentElement(toShadowRoot(root));
554
555     ec = INVALID_ACCESS_ERR;
556     return 0;
557 }
558
559 size_t Internals::countElementShadow(const Node* root, ExceptionCode& ec) const
560 {
561     if (!root || !root->isShadowRoot()) {
562         ec = INVALID_ACCESS_ERR;
563         return 0;
564     }
565
566     return ScopeContentDistribution::countElementShadow(toShadowRoot(root));
567 }
568
569 bool Internals::attached(Node* node, ExceptionCode& ec)
570 {
571     if (!node) {
572         ec = INVALID_ACCESS_ERR;
573         return false;
574     }
575
576     return node->attached();
577 }
578
579 Node* Internals::nextSiblingByWalker(Node* node, ExceptionCode& ec)
580 {
581     if (!node) {
582         ec = INVALID_ACCESS_ERR;
583         return 0;
584     }
585     ComposedShadowTreeWalker walker(node);
586     walker.nextSibling();
587     return walker.get();
588 }
589
590 Node* Internals::firstChildByWalker(Node* node, ExceptionCode& ec)
591 {
592     if (!node) {
593         ec = INVALID_ACCESS_ERR;
594         return 0;
595     }
596     ComposedShadowTreeWalker walker(node);
597     walker.firstChild();
598     return walker.get();
599 }
600
601 Node* Internals::lastChildByWalker(Node* node, ExceptionCode& ec)
602 {
603     if (!node) {
604         ec = INVALID_ACCESS_ERR;
605         return 0;
606     }
607     ComposedShadowTreeWalker walker(node);
608     walker.lastChild();
609     return walker.get();
610 }
611
612 Node* Internals::nextNodeByWalker(Node* node, ExceptionCode& ec)
613 {
614     if (!node) {
615         ec = INVALID_ACCESS_ERR;
616         return 0;
617     }
618     ComposedShadowTreeWalker walker(node);
619     walker.next();
620     return walker.get();
621 }
622
623 Node* Internals::previousNodeByWalker(Node* node, ExceptionCode& ec)
624 {
625     if (!node) {
626         ec = INVALID_ACCESS_ERR;
627         return 0;
628     }
629     ComposedShadowTreeWalker walker(node);
630     walker.previous();
631     return walker.get();
632 }
633
634 String Internals::elementRenderTreeAsText(Element* element, ExceptionCode& ec)
635 {
636     if (!element) {
637         ec = INVALID_ACCESS_ERR;
638         return String();
639     }
640
641     String representation = externalRepresentation(element);
642     if (representation.isEmpty()) {
643         ec = INVALID_ACCESS_ERR;
644         return String();
645     }
646
647     return representation;
648 }
649
650 size_t Internals::numberOfScopedHTMLStyleChildren(const Node* scope, ExceptionCode& ec) const
651 {
652     if (scope && (scope->isElementNode() || scope->isShadowRoot()))
653 #if ENABLE(STYLE_SCOPED)
654         return scope->numberOfScopedHTMLStyleChildren();
655 #else
656         return 0;
657 #endif
658
659     ec = INVALID_ACCESS_ERR;
660     return 0;
661 }
662
663 PassRefPtr<CSSComputedStyleDeclaration> Internals::computedStyleIncludingVisitedInfo(Node* node, ExceptionCode& ec) const
664 {
665     if (!node) {
666         ec = INVALID_ACCESS_ERR;
667         return 0;
668     }
669
670     bool allowVisitedStyle = true;
671     return CSSComputedStyleDeclaration::create(node, allowVisitedStyle);
672 }
673
674 Internals::ShadowRootIfShadowDOMEnabledOrNode* Internals::ensureShadowRoot(Element* host, ExceptionCode& ec)
675 {
676     if (!host) {
677         ec = INVALID_ACCESS_ERR;
678         return 0;
679     }
680
681     if (ElementShadow* shadow = host->shadow())
682         return shadow->youngestShadowRoot();
683
684     return host->createShadowRoot(ec).get();
685 }
686
687 Internals::ShadowRootIfShadowDOMEnabledOrNode* Internals::createShadowRoot(Element* host, ExceptionCode& ec)
688 {
689     if (!host) {
690         ec = INVALID_ACCESS_ERR;
691         return 0;
692     }
693     return host->createShadowRoot(ec).get();
694 }
695
696 Internals::ShadowRootIfShadowDOMEnabledOrNode* Internals::shadowRoot(Element* host, ExceptionCode& ec)
697 {
698     // FIXME: Internals::shadowRoot() in tests should be converted to youngestShadowRoot() or oldestShadowRoot().
699     // https://bugs.webkit.org/show_bug.cgi?id=78465
700     return youngestShadowRoot(host, ec);
701 }
702
703 Internals::ShadowRootIfShadowDOMEnabledOrNode* Internals::youngestShadowRoot(Element* host, ExceptionCode& ec)
704 {
705     if (!host) {
706         ec = INVALID_ACCESS_ERR;
707         return 0;
708     }
709
710     if (ElementShadow* shadow = host->shadow())
711         return shadow->youngestShadowRoot();
712     return 0;
713 }
714
715 Internals::ShadowRootIfShadowDOMEnabledOrNode* Internals::oldestShadowRoot(Element* host, ExceptionCode& ec)
716 {
717     if (!host) {
718         ec = INVALID_ACCESS_ERR;
719         return 0;
720     }
721
722     if (ElementShadow* shadow = host->shadow())
723         return shadow->oldestShadowRoot();
724     return 0;
725 }
726
727 Internals::ShadowRootIfShadowDOMEnabledOrNode* Internals::youngerShadowRoot(Node* shadow, ExceptionCode& ec)
728 {
729     if (!shadow || !shadow->isShadowRoot()) {
730         ec = INVALID_ACCESS_ERR;
731         return 0;
732     }
733
734     return toShadowRoot(shadow)->youngerShadowRoot();
735 }
736
737 Internals::ShadowRootIfShadowDOMEnabledOrNode* Internals::olderShadowRoot(Node* shadow, ExceptionCode& ec)
738 {
739     if (!shadow || !shadow->isShadowRoot()) {
740         ec = INVALID_ACCESS_ERR;
741         return 0;
742     }
743
744     return toShadowRoot(shadow)->olderShadowRoot();
745 }
746
747 String Internals::shadowRootType(const Node* root, ExceptionCode& ec) const
748 {
749     if (!root || !root->isShadowRoot()) {
750         ec = INVALID_ACCESS_ERR;
751         return String();
752     }
753
754     switch (toShadowRoot(root)->type()) {
755     case ShadowRoot::UserAgentShadowRoot:
756         return String("UserAgentShadowRoot");
757     case ShadowRoot::AuthorShadowRoot:
758         return String("AuthorShadowRoot");
759     default:
760         ASSERT_NOT_REACHED();
761         return String("Unknown");
762     }
763 }
764
765 Element* Internals::includerFor(Node* node, ExceptionCode& ec)
766 {
767     if (!node) {
768         ec = INVALID_ACCESS_ERR;
769         return 0;
770     }
771
772     return NodeRenderingContext(node).insertionPoint();
773 }
774
775 String Internals::shadowPseudoId(Element* element, ExceptionCode& ec)
776 {
777     if (!element) {
778         ec = INVALID_ACCESS_ERR;
779         return String();
780     }
781
782     return element->shadowPseudoId().string();
783 }
784
785 void Internals::setShadowPseudoId(Element* element, const String& id, ExceptionCode& ec)
786 {
787     if (!element) {
788         ec = INVALID_ACCESS_ERR;
789         return;
790     }
791
792     return element->setPseudo(id);
793 }
794
795 String Internals::visiblePlaceholder(Element* element)
796 {
797     if (element && isHTMLTextFormControlElement(element)) {
798         if (toHTMLTextFormControlElement(element)->placeholderShouldBeVisible())
799             return toHTMLTextFormControlElement(element)->placeholderElement()->textContent();
800     }
801
802     return String();
803 }
804
805 #if ENABLE(INPUT_TYPE_COLOR)
806 void Internals::selectColorInColorChooser(Element* element, const String& colorValue)
807 {
808     if (!element->hasTagName(inputTag))
809         return;
810     HTMLInputElement* inputElement = element->toInputElement();
811     if (!inputElement)
812         return;
813     inputElement->selectColorInColorChooser(Color(colorValue));
814 }
815 #endif
816
817 Vector<String> Internals::formControlStateOfPreviousHistoryItem(ExceptionCode& ec)
818 {
819     HistoryItem* mainItem = frame()->loader()->history()->previousItem();
820     if (!mainItem) {
821         ec = INVALID_ACCESS_ERR;
822         return Vector<String>();
823     }
824     String uniqueName = frame()->tree()->uniqueName();
825     if (mainItem->target() != uniqueName && !mainItem->childItemWithTarget(uniqueName)) {
826         ec = INVALID_ACCESS_ERR;
827         return Vector<String>();
828     }
829     return mainItem->target() == uniqueName ? mainItem->documentState() : mainItem->childItemWithTarget(uniqueName)->documentState();
830 }
831
832 void Internals::setFormControlStateOfPreviousHistoryItem(const Vector<String>& state, ExceptionCode& ec)
833 {
834     HistoryItem* mainItem = frame()->loader()->history()->previousItem();
835     if (!mainItem) {
836         ec = INVALID_ACCESS_ERR;
837         return;
838     }
839     String uniqueName = frame()->tree()->uniqueName();
840     if (mainItem->target() == uniqueName)
841         mainItem->setDocumentState(state);
842     else if (HistoryItem* subItem = mainItem->childItemWithTarget(uniqueName))
843         subItem->setDocumentState(state);
844     else
845         ec = INVALID_ACCESS_ERR;
846 }
847
848 #if ENABLE(SPEECH_SYNTHESIS)
849 void Internals::enableMockSpeechSynthesizer()
850 {
851     Document* document = contextDocument();
852     if (!document || !document->domWindow())
853         return;
854     SpeechSynthesis* synthesis = DOMWindowSpeechSynthesis::speechSynthesis(document->domWindow());
855     if (!synthesis)
856         return;
857     
858     synthesis->setPlatformSynthesizer(PlatformSpeechSynthesizerMock::create(synthesis));
859 }
860 #endif
861     
862 void Internals::setEnableMockPagePopup(bool enabled, ExceptionCode& ec)
863 {
864 #if ENABLE(PAGE_POPUP)
865     Document* document = contextDocument();
866     if (!document || !document->page() || !document->page()->chrome())
867         return;
868     Page* page = document->page();
869     if (!enabled) {
870         page->chrome()->client()->resetPagePopupDriver();
871         return;
872     }
873     if (!s_pagePopupDriver)
874         s_pagePopupDriver = MockPagePopupDriver::create(page->mainFrame()).leakPtr();
875     page->chrome()->client()->setPagePopupDriver(s_pagePopupDriver);
876 #else
877     UNUSED_PARAM(enabled);
878     UNUSED_PARAM(ec);
879 #endif
880 }
881
882 #if ENABLE(PAGE_POPUP)
883 PassRefPtr<PagePopupController> Internals::pagePopupController()
884 {
885     return s_pagePopupDriver ? s_pagePopupDriver->pagePopupController() : 0;
886 }
887 #endif
888
889 PassRefPtr<ClientRect> Internals::absoluteCaretBounds(ExceptionCode& ec)
890 {
891     Document* document = contextDocument();
892     if (!document || !document->frame() || !document->frame()->selection()) {
893         ec = INVALID_ACCESS_ERR;
894         return ClientRect::create();
895     }
896
897     return ClientRect::create(document->frame()->selection()->absoluteCaretBounds());
898 }
899
900 PassRefPtr<ClientRect> Internals::boundingBox(Element* element, ExceptionCode& ec)
901 {
902     if (!element) {
903         ec = INVALID_ACCESS_ERR;
904         return ClientRect::create();
905     }
906
907     element->document()->updateLayoutIgnorePendingStylesheets();
908     RenderObject* renderer = element->renderer();
909     if (!renderer)
910         return ClientRect::create();
911     return ClientRect::create(renderer->absoluteBoundingBoxRectIgnoringTransforms());
912 }
913
914 PassRefPtr<ClientRectList> Internals::inspectorHighlightRects(Document* document, ExceptionCode& ec)
915 {
916 #if ENABLE(INSPECTOR)
917     if (!document || !document->page() || !document->page()->inspectorController()) {
918         ec = INVALID_ACCESS_ERR;
919         return ClientRectList::create();
920     }
921
922     Highlight highlight;
923     document->page()->inspectorController()->getHighlight(&highlight);
924     return ClientRectList::create(highlight.quads);
925 #else
926     UNUSED_PARAM(document);
927     UNUSED_PARAM(ec);
928     return ClientRectList::create();
929 #endif
930 }
931
932 #if PLATFORM(CHROMIUM)
933 void Internals::setBackgroundBlurOnNode(Node* node, int blurLength, ExceptionCode& ec)
934 {
935     if (!node) {
936         ec = INVALID_ACCESS_ERR;
937         return;
938     }
939
940     RenderObject* renderObject = node->renderer();
941     if (!renderObject) {
942         ec = INVALID_NODE_TYPE_ERR;
943         return;
944     }
945
946     RenderLayer* renderLayer = renderObject->enclosingLayer();
947     if (!renderLayer || !renderLayer->isComposited()) {
948         ec = INVALID_STATE_ERR;
949         return;
950     }
951
952     GraphicsLayer* graphicsLayer = renderLayer->backing()->graphicsLayer();
953     if (!graphicsLayer) {
954         ec = INVALID_NODE_TYPE_ERR;
955         return;
956     }
957
958     FilterOperations filters;
959     filters.operations().append(BlurFilterOperation::create(Length(blurLength, Fixed), FilterOperation::BLUR));
960     static_cast<GraphicsLayerChromium*>(graphicsLayer)->setBackgroundFilters(filters);
961 }
962 #else
963 void Internals::setBackgroundBlurOnNode(Node*, int, ExceptionCode&)
964 {
965 }
966 #endif
967
968 unsigned Internals::markerCountForNode(Node* node, const String& markerType, ExceptionCode& ec)
969 {
970     if (!node) {
971         ec = INVALID_ACCESS_ERR;
972         return 0;
973     }
974
975     DocumentMarker::MarkerTypes markerTypes = 0;
976     if (!markerTypesFrom(markerType, markerTypes)) {
977         ec = SYNTAX_ERR;
978         return 0;
979     }
980
981     return node->document()->markers()->markersFor(node, markerTypes).size();
982 }
983
984 DocumentMarker* Internals::markerAt(Node* node, const String& markerType, unsigned index, ExceptionCode& ec)
985 {
986     if (!node) {
987         ec = INVALID_ACCESS_ERR;
988         return 0;
989     }
990
991     DocumentMarker::MarkerTypes markerTypes = 0;
992     if (!markerTypesFrom(markerType, markerTypes)) {
993         ec = SYNTAX_ERR;
994         return 0;
995     }
996
997     Vector<DocumentMarker*> markers = node->document()->markers()->markersFor(node, markerTypes);
998     if (markers.size() <= index)
999         return 0;
1000     return markers[index];
1001 }
1002
1003 PassRefPtr<Range> Internals::markerRangeForNode(Node* node, const String& markerType, unsigned index, ExceptionCode& ec)
1004 {
1005     DocumentMarker* marker = markerAt(node, markerType, index, ec);
1006     if (!marker)
1007         return 0;
1008     return Range::create(node->document(), node, marker->startOffset(), node, marker->endOffset());
1009 }
1010
1011 String Internals::markerDescriptionForNode(Node* node, const String& markerType, unsigned index, ExceptionCode& ec)
1012 {
1013     DocumentMarker* marker = markerAt(node, markerType, index, ec);
1014     if (!marker)
1015         return String();
1016     return marker->description();
1017 }
1018
1019 void Internals::addTextMatchMarker(const Range* range, bool isActive)
1020 {
1021     range->ownerDocument()->updateLayoutIgnorePendingStylesheets();
1022     range->ownerDocument()->markers()->addTextMatchMarker(range, isActive);
1023 }
1024
1025 void Internals::setScrollViewPosition(Document* document, long x, long y, ExceptionCode& ec)
1026 {
1027     if (!document || !document->view()) {
1028         ec = INVALID_ACCESS_ERR;
1029         return;
1030     }
1031
1032     FrameView* frameView = document->view();
1033     bool constrainsScrollingToContentEdgeOldValue = frameView->constrainsScrollingToContentEdge();
1034     bool scrollbarsSuppressedOldValue = frameView->scrollbarsSuppressed();
1035
1036     frameView->setConstrainsScrollingToContentEdge(false);
1037     frameView->setScrollbarsSuppressed(false);
1038     frameView->setScrollOffsetFromInternals(IntPoint(x, y));
1039     frameView->setScrollbarsSuppressed(scrollbarsSuppressedOldValue);
1040     frameView->setConstrainsScrollingToContentEdge(constrainsScrollingToContentEdgeOldValue);
1041 }
1042
1043 void Internals::setPagination(Document* document, const String& mode, int gap, int pageLength, ExceptionCode& ec)
1044 {
1045     if (!document || !document->page()) {
1046         ec = INVALID_ACCESS_ERR;
1047         return;
1048     }
1049     Page* page = document->page();
1050
1051     Pagination pagination;
1052     if (mode == "Unpaginated")
1053         pagination.mode = Pagination::Unpaginated;
1054     else if (mode == "LeftToRightPaginated")
1055         pagination.mode = Pagination::LeftToRightPaginated;
1056     else if (mode == "RightToLeftPaginated")
1057         pagination.mode = Pagination::RightToLeftPaginated;
1058     else if (mode == "TopToBottomPaginated")
1059         pagination.mode = Pagination::TopToBottomPaginated;
1060     else if (mode == "BottomToTopPaginated")
1061         pagination.mode = Pagination::BottomToTopPaginated;
1062     else {
1063         ec = SYNTAX_ERR;
1064         return;
1065     }
1066
1067     pagination.gap = gap;
1068     pagination.pageLength = pageLength;
1069     page->setPagination(pagination);
1070 }
1071
1072 String Internals::configurationForViewport(Document* document, float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight, ExceptionCode& ec)
1073 {
1074     if (!document || !document->page()) {
1075         ec = INVALID_ACCESS_ERR;
1076         return String();
1077     }
1078     Page* page = document->page();
1079
1080     const int defaultLayoutWidthForNonMobilePages = 980;
1081
1082     ViewportArguments arguments = page->viewportArguments();
1083     ViewportAttributes attributes = computeViewportAttributes(arguments, defaultLayoutWidthForNonMobilePages, deviceWidth, deviceHeight, devicePixelRatio, IntSize(availableWidth, availableHeight));
1084     restrictMinimumScaleFactorToViewportSize(attributes, IntSize(availableWidth, availableHeight), devicePixelRatio);
1085     restrictScaleFactorToInitialScaleIfNotUserScalable(attributes);
1086
1087     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");
1088 }
1089
1090 bool Internals::wasLastChangeUserEdit(Element* textField, ExceptionCode& ec)
1091 {
1092     if (!textField) {
1093         ec = INVALID_ACCESS_ERR;
1094         return false;
1095     }
1096
1097     if (HTMLInputElement* inputElement = textField->toInputElement())
1098         return inputElement->lastChangeWasUserEdit();
1099
1100     // FIXME: We should be using hasTagName instead but Windows port doesn't link QualifiedNames properly.
1101     if (textField->tagName() == "TEXTAREA")
1102         return static_cast<HTMLTextAreaElement*>(textField)->lastChangeWasUserEdit();
1103
1104     ec = INVALID_NODE_TYPE_ERR;
1105     return false;
1106 }
1107
1108 String Internals::suggestedValue(Element* element, ExceptionCode& ec)
1109 {
1110     if (!element) {
1111         ec = INVALID_ACCESS_ERR;
1112         return String();
1113     }
1114
1115     HTMLInputElement* inputElement = element->toInputElement();
1116     if (!inputElement) {
1117         ec = INVALID_NODE_TYPE_ERR;
1118         return String();
1119     }
1120
1121     return inputElement->suggestedValue();
1122 }
1123
1124 void Internals::setSuggestedValue(Element* element, const String& value, ExceptionCode& ec)
1125 {
1126     if (!element) {
1127         ec = INVALID_ACCESS_ERR;
1128         return;
1129     }
1130
1131     HTMLInputElement* inputElement = element->toInputElement();
1132     if (!inputElement) {
1133         ec = INVALID_NODE_TYPE_ERR;
1134         return;
1135     }
1136
1137     inputElement->setSuggestedValue(value);
1138 }
1139
1140 void Internals::setEditingValue(Element* element, const String& value, ExceptionCode& ec)
1141 {
1142     if (!element) {
1143         ec = INVALID_ACCESS_ERR;
1144         return;
1145     }
1146
1147     HTMLInputElement* inputElement = element->toInputElement();
1148     if (!inputElement) {
1149         ec = INVALID_NODE_TYPE_ERR;
1150         return;
1151     }
1152
1153     inputElement->setEditingValue(value);
1154 }
1155
1156 void Internals::setAutofilled(Element* element, bool enabled, ExceptionCode& ec)
1157 {
1158     HTMLInputElement* inputElement = element->toInputElement();
1159     if (!inputElement) {
1160         ec = INVALID_ACCESS_ERR;
1161         return;
1162     }
1163     inputElement->setAutofilled(enabled);
1164 }
1165
1166 void Internals::scrollElementToRect(Element* element, long x, long y, long w, long h, ExceptionCode& ec)
1167 {
1168     if (!element || !element->document() || !element->document()->view()) {
1169         ec = INVALID_ACCESS_ERR;
1170         return;
1171     }
1172     FrameView* frameView = element->document()->view();
1173     frameView->scrollElementToRect(element, IntRect(x, y, w, h));
1174 }
1175
1176 void Internals::paintControlTints(Document* document, ExceptionCode& ec)
1177 {
1178     if (!document || !document->view()) {
1179         ec = INVALID_ACCESS_ERR;
1180         return;
1181     }
1182
1183     FrameView* frameView = document->view();
1184     frameView->paintControlTints();
1185 }
1186
1187 PassRefPtr<Range> Internals::rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionCode& ec)
1188 {
1189     if (!scope) {
1190         ec = INVALID_ACCESS_ERR;
1191         return 0;
1192     }
1193
1194     return TextIterator::rangeFromLocationAndLength(scope, rangeLocation, rangeLength);
1195 }
1196
1197 unsigned Internals::locationFromRange(Element* scope, const Range* range, ExceptionCode& ec)
1198 {
1199     if (!scope || !range) {
1200         ec = INVALID_ACCESS_ERR;
1201         return 0;
1202     }
1203
1204     size_t location = 0;
1205     size_t unusedLength = 0;
1206     TextIterator::getLocationAndLengthFromRange(scope, range, location, unusedLength);
1207     return location;
1208 }
1209
1210 unsigned Internals::lengthFromRange(Element* scope, const Range* range, ExceptionCode& ec)
1211 {
1212     if (!scope || !range) {
1213         ec = INVALID_ACCESS_ERR;
1214         return 0;
1215     }
1216
1217     size_t unusedLocation = 0;
1218     size_t length = 0;
1219     TextIterator::getLocationAndLengthFromRange(scope, range, unusedLocation, length);
1220     return length;
1221 }
1222
1223 String Internals::rangeAsText(const Range* range, ExceptionCode& ec)
1224 {
1225     if (!range) {
1226         ec = INVALID_ACCESS_ERR;
1227         return String();
1228     }
1229
1230     return range->text();
1231 }
1232
1233 void Internals::setDelegatesScrolling(bool enabled, Document* document, ExceptionCode& ec)
1234 {
1235     // Delegate scrolling is valid only on mainframe's view.
1236     if (!document || !document->view() || !document->page() || document->page()->mainFrame() != document->frame()) {
1237         ec = INVALID_ACCESS_ERR;
1238         return;
1239     }
1240
1241     document->view()->setDelegatesScrolling(enabled);
1242 }
1243
1244 #if ENABLE(TOUCH_ADJUSTMENT)
1245 PassRefPtr<WebKitPoint> Internals::touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
1246 {
1247     if (!document || !document->frame()) {
1248         ec = INVALID_ACCESS_ERR;
1249         return 0;
1250     }
1251
1252     IntSize radius(width / 2, height / 2);
1253     IntPoint point(x + radius.width(), y + radius.height());
1254
1255     Node* targetNode;
1256     IntPoint adjustedPoint;
1257
1258     bool foundNode = document->frame()->eventHandler()->bestClickableNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1259     if (foundNode)
1260         return WebKitPoint::create(adjustedPoint.x(), adjustedPoint.y());
1261
1262     return 0;
1263 }
1264
1265 Node* Internals::touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
1266 {
1267     if (!document || !document->frame()) {
1268         ec = INVALID_ACCESS_ERR;
1269         return 0;
1270     }
1271
1272     IntSize radius(width / 2, height / 2);
1273     IntPoint point(x + radius.width(), y + radius.height());
1274
1275     Node* targetNode;
1276     IntPoint adjustedPoint;
1277     document->frame()->eventHandler()->bestClickableNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1278     return targetNode;
1279 }
1280
1281 PassRefPtr<WebKitPoint> Internals::touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
1282 {
1283     if (!document || !document->frame()) {
1284         ec = INVALID_ACCESS_ERR;
1285         return 0;
1286     }
1287
1288     IntSize radius(width / 2, height / 2);
1289     IntPoint point(x + radius.width(), y + radius.height());
1290
1291     Node* targetNode = 0;
1292     IntPoint adjustedPoint;
1293
1294     bool foundNode = document->frame()->eventHandler()->bestContextMenuNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1295     if (foundNode)
1296         return WebKitPoint::create(adjustedPoint.x(), adjustedPoint.y());
1297
1298     return WebKitPoint::create(x, y);
1299 }
1300
1301 Node* Internals::touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
1302 {
1303     if (!document || !document->frame()) {
1304         ec = INVALID_ACCESS_ERR;
1305         return 0;
1306     }
1307
1308     IntSize radius(width / 2, height / 2);
1309     IntPoint point(x + radius.width(), y + radius.height());
1310
1311     Node* targetNode = 0;
1312     IntPoint adjustedPoint;
1313     document->frame()->eventHandler()->bestContextMenuNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1314     return targetNode;
1315 }
1316
1317 PassRefPtr<ClientRect> Internals::bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
1318 {
1319     if (!document || !document->frame()) {
1320         ec = INVALID_ACCESS_ERR;
1321         return 0;
1322     }
1323
1324     IntSize radius(width / 2, height / 2);
1325     IntPoint point(x + radius.width(), y + radius.height());
1326
1327     Node* targetNode;
1328     IntRect zoomableArea;
1329     bool foundNode = document->frame()->eventHandler()->bestZoomableAreaForTouchPoint(point, radius, zoomableArea, targetNode);
1330     if (foundNode)
1331         return ClientRect::create(zoomableArea);
1332
1333     return 0;
1334 }
1335 #endif
1336
1337
1338 int Internals::lastSpellCheckRequestSequence(Document* document, ExceptionCode& ec)
1339 {
1340     SpellChecker* checker = spellchecker(document);
1341
1342     if (!checker) {
1343         ec = INVALID_ACCESS_ERR;
1344         return -1;
1345     }
1346
1347     return checker->lastRequestSequence();
1348 }
1349
1350 int Internals::lastSpellCheckProcessedSequence(Document* document, ExceptionCode& ec)
1351 {
1352     SpellChecker* checker = spellchecker(document);
1353
1354     if (!checker) {
1355         ec = INVALID_ACCESS_ERR;
1356         return -1;
1357     }
1358
1359     return checker->lastProcessedSequence();
1360 }
1361
1362 Vector<String> Internals::userPreferredLanguages() const
1363 {
1364     return WebCore::userPreferredLanguages();
1365 }
1366
1367 void Internals::setUserPreferredLanguages(const Vector<String>& languages)
1368 {
1369     WebCore::overrideUserPreferredLanguages(languages);
1370 }
1371
1372 unsigned Internals::wheelEventHandlerCount(Document* document, ExceptionCode& ec)
1373 {
1374     if (!document) {
1375         ec = INVALID_ACCESS_ERR;
1376         return 0;
1377     }
1378
1379     return document->wheelEventHandlerCount();
1380 }
1381
1382 unsigned Internals::touchEventHandlerCount(Document* document, ExceptionCode& ec)
1383 {
1384     if (!document) {
1385         ec = INVALID_ACCESS_ERR;
1386         return 0;
1387     }
1388
1389     const TouchEventTargetSet* touchHandlers = document->touchEventTargets();
1390     if (!touchHandlers)
1391         return 0;
1392
1393     unsigned count = 0;
1394     for (TouchEventTargetSet::const_iterator iter = touchHandlers->begin(); iter != touchHandlers->end(); ++iter)
1395         count += iter->value;
1396     return count;
1397 }
1398
1399 #if ENABLE(TOUCH_EVENT_TRACKING)
1400 PassRefPtr<ClientRectList> Internals::touchEventTargetClientRects(Document* document, ExceptionCode& ec)
1401 {
1402     if (!document || !document->view() || !document->page()) {
1403         ec = INVALID_ACCESS_ERR;
1404         return 0;
1405     }
1406     if (!document->page()->scrollingCoordinator())
1407         return ClientRectList::create();
1408
1409     document->updateLayoutIgnorePendingStylesheets();
1410
1411     Vector<IntRect> absoluteRects;
1412     document->page()->scrollingCoordinator()->computeAbsoluteTouchEventTargetRects(document, absoluteRects);
1413     Vector<FloatQuad> absoluteQuads(absoluteRects.size());
1414
1415     for (size_t i = 0; i < absoluteRects.size(); ++i)
1416         absoluteQuads[i] = FloatQuad(absoluteRects[i]);
1417
1418     return ClientRectList::create(absoluteQuads);
1419 }
1420 #endif
1421
1422 PassRefPtr<NodeList> Internals::nodesFromRect(Document* document, int x, int y, unsigned topPadding, unsigned rightPadding,
1423     unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent, ExceptionCode& ec) const
1424 {
1425     if (!document || !document->frame() || !document->frame()->view()) {
1426         ec = INVALID_ACCESS_ERR;
1427         return 0;
1428     }
1429
1430     HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly | HitTestRequest::Active;
1431     if (ignoreClipping)
1432         hitType |= HitTestRequest::IgnoreClipping;
1433     if (allowShadowContent)
1434         hitType |= HitTestRequest::AllowShadowContent;
1435     if (allowChildFrameContent)
1436         hitType |= HitTestRequest::AllowChildFrameContent;
1437
1438     return document->nodesFromRect(x, y, topPadding, rightPadding, bottomPadding, leftPadding, hitType);
1439 }
1440
1441 void Internals::emitInspectorDidBeginFrame()
1442 {
1443 #if ENABLE(INSPECTOR)
1444     InspectorController* inspectorController = contextDocument()->frame()->page()->inspectorController();
1445     inspectorController->didBeginFrame();
1446 #endif
1447 }
1448
1449 void Internals::emitInspectorDidCancelFrame()
1450 {
1451 #if ENABLE(INSPECTOR)
1452     InspectorController* inspectorController = contextDocument()->frame()->page()->inspectorController();
1453     inspectorController->didCancelFrame();
1454 #endif
1455 }
1456
1457 void Internals::setBatteryStatus(Document* document, const String& eventType, bool charging, double chargingTime, double dischargingTime, double level, ExceptionCode& ec)
1458 {
1459     if (!document || !document->page()) {
1460         ec = INVALID_ACCESS_ERR;
1461         return;
1462     }
1463
1464 #if ENABLE(BATTERY_STATUS)
1465     BatteryController::from(document->page())->didChangeBatteryStatus(eventType, BatteryStatus::create(charging, chargingTime, dischargingTime, level));
1466 #else
1467     UNUSED_PARAM(eventType);
1468     UNUSED_PARAM(charging);
1469     UNUSED_PARAM(chargingTime);
1470     UNUSED_PARAM(dischargingTime);
1471     UNUSED_PARAM(level);
1472 #endif
1473 }
1474
1475 void Internals::setNetworkInformation(Document* document, const String& eventType, double bandwidth, bool metered, ExceptionCode& ec)
1476 {
1477     if (!document || !document->page()) {
1478         ec = INVALID_ACCESS_ERR;
1479         return;
1480     }
1481
1482 #if ENABLE(NETWORK_INFO)
1483     NetworkInfoController::from(document->page())->didChangeNetworkInformation(eventType, NetworkInfo::create(bandwidth, metered));
1484 #else
1485     UNUSED_PARAM(eventType);
1486     UNUSED_PARAM(bandwidth);
1487     UNUSED_PARAM(metered);
1488 #endif
1489 }
1490
1491 void Internals::setDeviceProximity(Document* document, const String& eventType, double value, double min, double max, ExceptionCode& ec)
1492 {
1493     if (!document || !document->page()) {
1494         ec = INVALID_ACCESS_ERR;
1495         return;
1496     }
1497
1498 #if ENABLE(PROXIMITY_EVENTS)
1499     DeviceProximityController::from(document->page())->didChangeDeviceProximity(value, min, max);
1500 #else
1501     UNUSED_PARAM(eventType);
1502     UNUSED_PARAM(value);
1503     UNUSED_PARAM(min);
1504     UNUSED_PARAM(max);
1505 #endif
1506 }
1507
1508 bool Internals::hasSpellingMarker(Document* document, int from, int length, ExceptionCode&)
1509 {
1510     if (!document || !document->frame())
1511         return 0;
1512
1513     return document->frame()->editor()->selectionStartHasMarkerFor(DocumentMarker::Spelling, from, length);
1514 }
1515     
1516 bool Internals::hasAutocorrectedMarker(Document* document, int from, int length, ExceptionCode&)
1517 {
1518     if (!document || !document->frame())
1519         return 0;
1520     
1521     return document->frame()->editor()->selectionStartHasMarkerFor(DocumentMarker::Autocorrected, from, length);
1522 }
1523
1524 #if ENABLE(INSPECTOR)
1525 unsigned Internals::numberOfLiveNodes() const
1526 {
1527     return InspectorCounters::counterValue(InspectorCounters::NodeCounter);
1528 }
1529
1530 unsigned Internals::numberOfLiveDocuments() const
1531 {
1532     return InspectorCounters::counterValue(InspectorCounters::DocumentCounter);
1533 }
1534
1535 Vector<String> Internals::consoleMessageArgumentCounts(Document* document) const
1536 {
1537     InstrumentingAgents* instrumentingAgents = instrumentationForPage(document->page());
1538     if (!instrumentingAgents)
1539         return Vector<String>();
1540     InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent();
1541     if (!consoleAgent)
1542         return Vector<String>();
1543     Vector<unsigned> counts = consoleAgent->consoleMessageArgumentCounts();
1544     Vector<String> result(counts.size());
1545     for (size_t i = 0; i < counts.size(); i++)
1546         result[i] = String::number(counts[i]);
1547     return result;
1548 }
1549
1550 PassRefPtr<DOMWindow> Internals::openDummyInspectorFrontend(const String& url)
1551 {
1552     Page* page = contextDocument()->frame()->page();
1553     ASSERT(page);
1554
1555     DOMWindow* window = page->mainFrame()->document()->domWindow();
1556     ASSERT(window);
1557
1558     m_frontendWindow = window->open(url, "", "", window, window);
1559     ASSERT(m_frontendWindow);
1560
1561     Page* frontendPage = m_frontendWindow->document()->page();
1562     ASSERT(frontendPage);
1563
1564     OwnPtr<InspectorFrontendClientDummy> frontendClient = adoptPtr(new InspectorFrontendClientDummy(page->inspectorController(), frontendPage));
1565
1566     frontendPage->inspectorController()->setInspectorFrontendClient(frontendClient.release());
1567
1568     m_frontendChannel = adoptPtr(new InspectorFrontendChannelDummy(frontendPage));
1569
1570     page->inspectorController()->connectFrontend(m_frontendChannel.get());
1571
1572     return m_frontendWindow;
1573 }
1574
1575 void Internals::closeDummyInspectorFrontend()
1576 {
1577     Page* page = contextDocument()->frame()->page();
1578     ASSERT(page);
1579     ASSERT(m_frontendWindow);
1580
1581     page->inspectorController()->disconnectFrontend();
1582
1583     m_frontendChannel.release();
1584
1585     m_frontendWindow->close(m_frontendWindow->scriptExecutionContext());
1586     m_frontendWindow.release();
1587 }
1588
1589 void Internals::setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionCode& ec)
1590 {
1591     Page* page = contextDocument()->frame()->page();
1592     if (!page || !page->inspectorController()) {
1593         ec = INVALID_ACCESS_ERR;
1594         return;
1595     }
1596     page->inspectorController()->setResourcesDataSizeLimitsFromInternals(maximumResourcesContentSize, maximumSingleResourceContentSize);
1597 }
1598
1599 void Internals::setJavaScriptProfilingEnabled(bool enabled, ExceptionCode& ec)
1600 {
1601     Page* page = contextDocument()->frame()->page();
1602     if (!page || !page->inspectorController()) {
1603         ec = INVALID_ACCESS_ERR;
1604         return;
1605     }
1606
1607     page->inspectorController()->setProfilerEnabled(enabled);
1608 }
1609 #endif // ENABLE(INSPECTOR)
1610
1611 bool Internals::hasGrammarMarker(Document* document, int from, int length, ExceptionCode&)
1612 {
1613     if (!document || !document->frame())
1614         return 0;
1615
1616     return document->frame()->editor()->selectionStartHasMarkerFor(DocumentMarker::Grammar, from, length);
1617 }
1618
1619 unsigned Internals::numberOfScrollableAreas(Document* document, ExceptionCode&)
1620 {
1621     unsigned count = 0;
1622     Frame* frame = document->frame();
1623     if (frame->view()->scrollableAreas())
1624         count += frame->view()->scrollableAreas()->size();
1625
1626     for (Frame* child = frame->tree()->firstChild(); child; child = child->tree()->nextSibling()) {
1627         if (child->view() && child->view()->scrollableAreas())
1628             count += child->view()->scrollableAreas()->size();
1629     }
1630
1631     return count;
1632 }
1633     
1634 bool Internals::isPageBoxVisible(Document* document, int pageNumber, ExceptionCode& ec)
1635 {
1636     if (!document) {
1637         ec = INVALID_ACCESS_ERR;
1638         return false;
1639     }
1640
1641     return document->isPageBoxVisible(pageNumber);
1642 }
1643
1644 String Internals::layerTreeAsText(Document* document, ExceptionCode& ec) const
1645 {
1646     return layerTreeAsText(document, 0, ec);
1647 }
1648
1649 String Internals::layerTreeAsText(Document* document, unsigned flags, ExceptionCode& ec) const
1650 {
1651     if (!document || !document->frame()) {
1652         ec = INVALID_ACCESS_ERR;
1653         return String();
1654     }
1655
1656     LayerTreeFlags layerTreeFlags = 0;
1657     if (flags & LAYER_TREE_INCLUDES_VISIBLE_RECTS)
1658         layerTreeFlags |= LayerTreeFlagsIncludeVisibleRects;
1659     if (flags & LAYER_TREE_INCLUDES_TILE_CACHES)
1660         layerTreeFlags |= LayerTreeFlagsIncludeTileCaches;
1661     if (flags & LAYER_TREE_INCLUDES_REPAINT_RECTS)
1662         layerTreeFlags |= LayerTreeFlagsIncludeRepaintRects;
1663
1664     return document->frame()->layerTreeAsText(layerTreeFlags);
1665 }
1666
1667 String Internals::repaintRectsAsText(Document* document, ExceptionCode& ec) const
1668 {
1669     if (!document || !document->frame()) {
1670         ec = INVALID_ACCESS_ERR;
1671         return String();
1672     }
1673
1674     return document->frame()->trackedRepaintRectsAsText();
1675 }
1676
1677 String Internals::scrollingStateTreeAsText(Document* document, ExceptionCode& ec) const
1678 {
1679     if (!document || !document->frame()) {
1680         ec = INVALID_ACCESS_ERR;
1681         return String();
1682     }
1683
1684     Page* page = document->page();
1685     if (!page)
1686         return String();
1687
1688     return page->scrollingStateTreeAsText();
1689 }
1690
1691 String Internals::mainThreadScrollingReasons(Document* document, ExceptionCode& ec) const
1692 {
1693     if (!document || !document->frame()) {
1694         ec = INVALID_ACCESS_ERR;
1695         return String();
1696     }
1697
1698     Page* page = document->page();
1699     if (!page)
1700         return String();
1701
1702     return page->mainThreadScrollingReasonsAsText();
1703 }
1704
1705 PassRefPtr<ClientRectList> Internals::nonFastScrollableRects(Document* document, ExceptionCode& ec) const
1706 {
1707     if (!document || !document->frame()) {
1708         ec = INVALID_ACCESS_ERR;
1709         return 0;
1710     }
1711
1712     Page* page = document->page();
1713     if (!page)
1714         return 0;
1715
1716     return page->nonFastScrollableRects(document->frame());
1717 }
1718
1719 void Internals::garbageCollectDocumentResources(Document* document, ExceptionCode& ec) const
1720 {
1721     if (!document) {
1722         ec = INVALID_ACCESS_ERR;
1723         return;
1724     }
1725
1726     CachedResourceLoader* cachedResourceLoader = document->cachedResourceLoader();
1727     if (!cachedResourceLoader)
1728         return;
1729     cachedResourceLoader->garbageCollectDocumentResources();
1730 }
1731
1732 void Internals::allowRoundingHacks() const
1733 {
1734     TextRun::setAllowsRoundingHacks(true);
1735 }
1736
1737 void Internals::insertAuthorCSS(Document* document, const String& css) const
1738 {
1739     RefPtr<StyleSheetContents> parsedSheet = StyleSheetContents::create(document);
1740     parsedSheet->setIsUserStyleSheet(false);
1741     parsedSheet->parseString(css);
1742     document->styleSheetCollection()->addAuthorSheet(parsedSheet);
1743 }
1744
1745 void Internals::insertUserCSS(Document* document, const String& css) const
1746 {
1747     RefPtr<StyleSheetContents> parsedSheet = StyleSheetContents::create(document);
1748     parsedSheet->setIsUserStyleSheet(true);
1749     parsedSheet->parseString(css);
1750     document->styleSheetCollection()->addUserSheet(parsedSheet);
1751 }
1752
1753 String Internals::counterValue(Element* element)
1754 {
1755     if (!element)
1756         return String();
1757
1758     return counterValueForElement(element);
1759 }
1760
1761 int Internals::pageNumber(Element* element, float pageWidth, float pageHeight)
1762 {
1763     if (!element)
1764         return 0;
1765
1766     return PrintContext::pageNumberForElement(element, FloatSize(pageWidth, pageHeight));
1767 }
1768
1769 Vector<String> Internals::iconURLs(Document* document) const
1770 {
1771     Vector<IconURL> iconURLs = document->iconURLs();
1772     Vector<String> array;
1773
1774     Vector<IconURL>::const_iterator iter(iconURLs.begin());
1775     for (; iter != iconURLs.end(); ++iter)
1776         array.append(iter->m_iconURL.string());
1777
1778     return array;
1779 }
1780
1781 int Internals::numberOfPages(float pageWidth, float pageHeight)
1782 {
1783     if (!frame())
1784         return -1;
1785
1786     return PrintContext::numberOfPages(frame(), FloatSize(pageWidth, pageHeight));
1787 }
1788
1789 String Internals::pageProperty(String propertyName, int pageNumber, ExceptionCode& ec) const
1790 {
1791     if (!frame()) {
1792         ec = INVALID_ACCESS_ERR;
1793         return String();
1794     }
1795
1796     return PrintContext::pageProperty(frame(), propertyName.utf8().data(), pageNumber);
1797 }
1798
1799 String Internals::pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft, ExceptionCode& ec) const
1800 {
1801     if (!frame()) {
1802         ec = INVALID_ACCESS_ERR;
1803         return String();
1804     }
1805
1806     return PrintContext::pageSizeAndMarginsInPixels(frame(), pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft);
1807 }
1808
1809 void Internals::setPageScaleFactor(float scaleFactor, int x, int y, ExceptionCode& ec)
1810 {
1811     Document* document = contextDocument();
1812     if (!document || !document->page()) {
1813         ec = INVALID_ACCESS_ERR;
1814         return;
1815     }
1816     Page* page = document->page();
1817     page->setPageScaleFactor(scaleFactor, IntPoint(x, y));
1818 }
1819
1820 #if ENABLE(FULLSCREEN_API)
1821 void Internals::webkitWillEnterFullScreenForElement(Document* document, Element* element)
1822 {
1823     if (!document)
1824         return;
1825     document->webkitWillEnterFullScreenForElement(element);
1826 }
1827
1828 void Internals::webkitDidEnterFullScreenForElement(Document* document, Element* element)
1829 {
1830     if (!document)
1831         return;
1832     document->webkitDidEnterFullScreenForElement(element);
1833 }
1834
1835 void Internals::webkitWillExitFullScreenForElement(Document* document, Element* element)
1836 {
1837     if (!document)
1838         return;
1839     document->webkitWillExitFullScreenForElement(element);
1840 }
1841
1842 void Internals::webkitDidExitFullScreenForElement(Document* document, Element* element)
1843 {
1844     if (!document)
1845         return;
1846     document->webkitDidExitFullScreenForElement(element);
1847 }
1848 #endif
1849
1850 void Internals::registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme)
1851 {
1852     SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy(scheme);
1853 }
1854
1855 void Internals::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme)
1856 {
1857     SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(scheme);
1858 }
1859
1860 PassRefPtr<MallocStatistics> Internals::mallocStatistics() const
1861 {
1862     return MallocStatistics::create();
1863 }
1864
1865 PassRefPtr<TypeConversions> Internals::typeConversions() const
1866 {
1867     return TypeConversions::create();
1868 }
1869
1870 Vector<String> Internals::getReferencedFilePaths() const
1871 {
1872     frame()->loader()->history()->saveDocumentAndScrollState();
1873     return FormController::getReferencedFilePaths(frame()->loader()->history()->currentItem()->documentState());
1874 }
1875
1876 void Internals::startTrackingRepaints(Document* document, ExceptionCode& ec)
1877 {
1878     if (!document || !document->view()) {
1879         ec = INVALID_ACCESS_ERR;
1880         return;
1881     }
1882
1883     FrameView* frameView = document->view();
1884     frameView->setTracksRepaints(true);
1885 }
1886
1887 void Internals::stopTrackingRepaints(Document* document, ExceptionCode& ec)
1888 {
1889     if (!document || !document->view()) {
1890         ec = INVALID_ACCESS_ERR;
1891         return;
1892     }
1893
1894     FrameView* frameView = document->view();
1895     frameView->setTracksRepaints(false);
1896 }
1897
1898 #if USE(LAZY_NATIVE_CURSOR)
1899 static const char* cursorTypeToString(Cursor::Type cursorType)
1900 {
1901     switch (cursorType) {
1902     case Cursor::Pointer: return "Pointer";
1903     case Cursor::Cross: return "Cross";
1904     case Cursor::Hand: return "Hand";
1905     case Cursor::IBeam: return "IBeam";
1906     case Cursor::Wait: return "Wait";
1907     case Cursor::Help: return "Help";
1908     case Cursor::EastResize: return "EastResize";
1909     case Cursor::NorthResize: return "NorthResize";
1910     case Cursor::NorthEastResize: return "NorthEastResize";
1911     case Cursor::NorthWestResize: return "NorthWestResize";
1912     case Cursor::SouthResize: return "SouthResize";
1913     case Cursor::SouthEastResize: return "SouthEastResize";
1914     case Cursor::SouthWestResize: return "SouthWestResize";
1915     case Cursor::WestResize: return "WestResize";
1916     case Cursor::NorthSouthResize: return "NorthSouthResize";
1917     case Cursor::EastWestResize: return "EastWestResize";
1918     case Cursor::NorthEastSouthWestResize: return "NorthEastSouthWestResize";
1919     case Cursor::NorthWestSouthEastResize: return "NorthWestSouthEastResize";
1920     case Cursor::ColumnResize: return "ColumnResize";
1921     case Cursor::RowResize: return "RowResize";
1922     case Cursor::MiddlePanning: return "MiddlePanning";
1923     case Cursor::EastPanning: return "EastPanning";
1924     case Cursor::NorthPanning: return "NorthPanning";
1925     case Cursor::NorthEastPanning: return "NorthEastPanning";
1926     case Cursor::NorthWestPanning: return "NorthWestPanning";
1927     case Cursor::SouthPanning: return "SouthPanning";
1928     case Cursor::SouthEastPanning: return "SouthEastPanning";
1929     case Cursor::SouthWestPanning: return "SouthWestPanning";
1930     case Cursor::WestPanning: return "WestPanning";
1931     case Cursor::Move: return "Move";
1932     case Cursor::VerticalText: return "VerticalText";
1933     case Cursor::Cell: return "Cell";
1934     case Cursor::ContextMenu: return "ContextMenu";
1935     case Cursor::Alias: return "Alias";
1936     case Cursor::Progress: return "Progress";
1937     case Cursor::NoDrop: return "NoDrop";
1938     case Cursor::Copy: return "Copy";
1939     case Cursor::None: return "None";
1940     case Cursor::NotAllowed: return "NotAllowed";
1941     case Cursor::ZoomIn: return "ZoomIn";
1942     case Cursor::ZoomOut: return "ZoomOut";
1943     case Cursor::Grab: return "Grab";
1944     case Cursor::Grabbing: return "Grabbing";
1945     case Cursor::Custom: return "Custom";
1946     }
1947
1948     ASSERT_NOT_REACHED();
1949     return "UNKNOWN";
1950 }
1951 #endif
1952
1953 String Internals::getCurrentCursorInfo(Document* document, ExceptionCode& ec)
1954 {
1955     if (!document || !document->frame()) {
1956         ec = INVALID_ACCESS_ERR;
1957         return String();
1958     }
1959
1960     Cursor cursor = document->frame()->eventHandler()->currentMouseCursor();
1961
1962 #if USE(LAZY_NATIVE_CURSOR)
1963     StringBuilder result;
1964     result.append("type=");
1965     result.append(cursorTypeToString(cursor.type()));
1966     result.append(" hotSpot=");
1967     result.appendNumber(cursor.hotSpot().x());
1968     result.append(",");
1969     result.appendNumber(cursor.hotSpot().y());
1970     if (cursor.image()) {
1971         IntSize size = cursor.image()->size();
1972         result.append(" image=");
1973         result.appendNumber(size.width());
1974         result.append("x");
1975         result.appendNumber(size.height());
1976     }
1977 #if ENABLE(MOUSE_CURSOR_SCALE)
1978     if (cursor.imageScaleFactor() != 1) {
1979         result.append(" scale=");
1980         NumberToStringBuffer buffer;
1981         result.append(numberToFixedPrecisionString(cursor.imageScaleFactor(), 8, buffer, true));
1982     }
1983 #endif
1984     return result.toString();
1985 #else
1986     return "FAIL: Cursor details not available on this platform.";
1987 #endif
1988 }
1989
1990 PassRefPtr<ArrayBuffer> Internals::serializeObject(PassRefPtr<SerializedScriptValue> value) const
1991 {
1992 #if USE(V8)
1993     String stringValue = value->toWireString();
1994     return ArrayBuffer::create(static_cast<const void*>(stringValue.impl()->characters()), stringValue.sizeInBytes());
1995 #else
1996     Vector<uint8_t> bytes = value->data();
1997     return ArrayBuffer::create(bytes.data(), bytes.size());
1998 #endif
1999 }
2000
2001 PassRefPtr<SerializedScriptValue> Internals::deserializeBuffer(PassRefPtr<ArrayBuffer> buffer) const
2002 {
2003 #if USE(V8)
2004     String value(static_cast<const UChar*>(buffer->data()), buffer->byteLength() / sizeof(UChar));
2005     return SerializedScriptValue::createFromWire(value);
2006 #else
2007     Vector<uint8_t> bytes;
2008     bytes.append(static_cast<const uint8_t*>(buffer->data()), buffer->byteLength());
2009     return SerializedScriptValue::adopt(bytes);
2010 #endif
2011 }
2012
2013 void Internals::setUsesOverlayScrollbars(bool enabled)
2014 {
2015     WebCore::Settings::setUsesOverlayScrollbars(enabled);
2016 }
2017
2018 #if ENABLE(ENCRYPTED_MEDIA_V2)
2019 void Internals::initializeMockCDM()
2020 {
2021     CDM::registerCDMFactory(MockCDM::create, MockCDM::supportsKeySytem);
2022 }
2023 #endif
2024
2025 String Internals::markerTextForListItem(Element* element, ExceptionCode& ec)
2026 {
2027     if (!element) {
2028         ec = INVALID_ACCESS_ERR;
2029         return String();
2030     }
2031     return WebCore::markerTextForListItem(element);
2032 }
2033
2034 }