.: Expose symbols for internals
[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 "FrameLoader.h"
51 #include "FrameView.h"
52 #include "HTMLContentElement.h"
53 #include "HTMLInputElement.h"
54 #include "HTMLNames.h"
55 #include "HTMLTextAreaElement.h"
56 #include "HistoryItem.h"
57 #include "InspectorClient.h"
58 #include "InspectorConsoleAgent.h"
59 #include "InspectorController.h"
60 #include "InspectorCounters.h"
61 #include "InspectorFrontendChannel.h"
62 #include "InspectorFrontendClientLocal.h"
63 #include "InspectorInstrumentation.h"
64 #include "InspectorOverlay.h"
65 #include "InstrumentingAgents.h"
66 #include "InternalSettings.h"
67 #include "IntRect.h"
68 #include "Language.h"
69 #include "MallocStatistics.h"
70 #include "MemoryCache.h"
71 #include "MockPagePopupDriver.h"
72 #include "NodeRenderingContext.h"
73 #include "Page.h"
74 #include "PrintContext.h"
75 #include "PseudoElement.h"
76 #include "Range.h"
77 #include "RenderObject.h"
78 #include "RenderTreeAsText.h"
79 #include "RuntimeEnabledFeatures.h"
80 #include "SchemeRegistry.h"
81 #include "ScrollingCoordinator.h"
82 #include "SelectRuleFeatureSet.h"
83 #include "SerializedScriptValue.h"
84 #include "Settings.h"
85 #include "ShadowRoot.h"
86 #include "SpellChecker.h"
87 #include "StyleSheetContents.h"
88 #include "TextIterator.h"
89 #include "TreeScope.h"
90 #include "TypeConversions.h"
91 #include "ViewportArguments.h"
92 #include "WorkerThread.h"
93 #include <wtf/text/StringBuffer.h>
94
95 #if ENABLE(INPUT_TYPE_COLOR)
96 #include "ColorChooser.h"
97 #endif
98
99 #if ENABLE(BATTERY_STATUS)
100 #include "BatteryController.h"
101 #endif
102
103 #if ENABLE(NETWORK_INFO)
104 #include "NetworkInfo.h"
105 #include "NetworkInfoController.h"
106 #endif
107
108 #if ENABLE(PROXIMITY_EVENTS)
109 #include "DeviceProximityController.h"
110 #endif
111
112 #if ENABLE(PAGE_POPUP)
113 #include "PagePopupController.h"
114 #endif
115
116 #if ENABLE(TOUCH_ADJUSTMENT)
117 #include "WebKitPoint.h"
118 #endif
119
120 #if ENABLE(MOUSE_CURSOR_SCALE)
121 #include <wtf/dtoa.h>
122 #endif
123
124 #if PLATFORM(CHROMIUM)
125 #include "FilterOperation.h"
126 #include "FilterOperations.h"
127 #include "GraphicsLayer.h"
128 #include "GraphicsLayerChromium.h"
129 #include "RenderLayerBacking.h"
130 #endif
131
132 #if ENABLE(ENCRYPTED_MEDIA_V2)
133 #include "CDM.h"
134 #include "MockCDM.h"
135 #endif
136
137 #if ENABLE(VIDEO_TRACK)
138 #include "CaptionUserPreferences.h"
139 #include "PageGroup.h"
140 #endif
141
142 #if ENABLE(SPEECH_SYNTHESIS)
143 #include "DOMWindowSpeechSynthesis.h"
144 #include "PlatformSpeechSynthesizerMock.h"
145 #include "SpeechSynthesis.h"
146 #endif
147
148 namespace WebCore {
149
150 #if ENABLE(PAGE_POPUP)
151 static MockPagePopupDriver* s_pagePopupDriver = 0;
152 #endif
153
154 using namespace HTMLNames;
155
156 #if ENABLE(INSPECTOR)
157 class InspectorFrontendClientDummy : public InspectorFrontendClientLocal {
158 public:
159     InspectorFrontendClientDummy(InspectorController*, Page*);
160     virtual ~InspectorFrontendClientDummy() { }
161     virtual void attachWindow() OVERRIDE { }
162     virtual void detachWindow() OVERRIDE { }
163
164     virtual String localizedStringsURL() 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 bool Internals::elementShouldAutoComplete(Element* element, ExceptionCode& ec)
1109 {
1110     if (!element) {
1111         ec = INVALID_ACCESS_ERR;
1112         return false;
1113     }
1114
1115     if (HTMLInputElement* inputElement = element->toInputElement())
1116         return inputElement->shouldAutocomplete();
1117
1118     ec = INVALID_NODE_TYPE_ERR;
1119     return false;
1120 }
1121
1122 String Internals::suggestedValue(Element* element, ExceptionCode& ec)
1123 {
1124     if (!element) {
1125         ec = INVALID_ACCESS_ERR;
1126         return String();
1127     }
1128
1129     HTMLInputElement* inputElement = element->toInputElement();
1130     if (!inputElement) {
1131         ec = INVALID_NODE_TYPE_ERR;
1132         return String();
1133     }
1134
1135     return inputElement->suggestedValue();
1136 }
1137
1138 void Internals::setSuggestedValue(Element* element, const String& value, ExceptionCode& ec)
1139 {
1140     if (!element) {
1141         ec = INVALID_ACCESS_ERR;
1142         return;
1143     }
1144
1145     HTMLInputElement* inputElement = element->toInputElement();
1146     if (!inputElement) {
1147         ec = INVALID_NODE_TYPE_ERR;
1148         return;
1149     }
1150
1151     inputElement->setSuggestedValue(value);
1152 }
1153
1154 void Internals::setEditingValue(Element* element, const String& value, ExceptionCode& ec)
1155 {
1156     if (!element) {
1157         ec = INVALID_ACCESS_ERR;
1158         return;
1159     }
1160
1161     HTMLInputElement* inputElement = element->toInputElement();
1162     if (!inputElement) {
1163         ec = INVALID_NODE_TYPE_ERR;
1164         return;
1165     }
1166
1167     inputElement->setEditingValue(value);
1168 }
1169
1170 void Internals::setAutofilled(Element* element, bool enabled, ExceptionCode& ec)
1171 {
1172     HTMLInputElement* inputElement = element->toInputElement();
1173     if (!inputElement) {
1174         ec = INVALID_ACCESS_ERR;
1175         return;
1176     }
1177     inputElement->setAutofilled(enabled);
1178 }
1179
1180 void Internals::scrollElementToRect(Element* element, long x, long y, long w, long h, ExceptionCode& ec)
1181 {
1182     if (!element || !element->document() || !element->document()->view()) {
1183         ec = INVALID_ACCESS_ERR;
1184         return;
1185     }
1186     FrameView* frameView = element->document()->view();
1187     frameView->scrollElementToRect(element, IntRect(x, y, w, h));
1188 }
1189
1190 void Internals::paintControlTints(Document* document, ExceptionCode& ec)
1191 {
1192     if (!document || !document->view()) {
1193         ec = INVALID_ACCESS_ERR;
1194         return;
1195     }
1196
1197     FrameView* frameView = document->view();
1198     frameView->paintControlTints();
1199 }
1200
1201 PassRefPtr<Range> Internals::rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionCode& ec)
1202 {
1203     if (!scope) {
1204         ec = INVALID_ACCESS_ERR;
1205         return 0;
1206     }
1207
1208     return TextIterator::rangeFromLocationAndLength(scope, rangeLocation, rangeLength);
1209 }
1210
1211 unsigned Internals::locationFromRange(Element* scope, const Range* range, ExceptionCode& ec)
1212 {
1213     if (!scope || !range) {
1214         ec = INVALID_ACCESS_ERR;
1215         return 0;
1216     }
1217
1218     size_t location = 0;
1219     size_t unusedLength = 0;
1220     TextIterator::getLocationAndLengthFromRange(scope, range, location, unusedLength);
1221     return location;
1222 }
1223
1224 unsigned Internals::lengthFromRange(Element* scope, const Range* range, ExceptionCode& ec)
1225 {
1226     if (!scope || !range) {
1227         ec = INVALID_ACCESS_ERR;
1228         return 0;
1229     }
1230
1231     size_t unusedLocation = 0;
1232     size_t length = 0;
1233     TextIterator::getLocationAndLengthFromRange(scope, range, unusedLocation, length);
1234     return length;
1235 }
1236
1237 String Internals::rangeAsText(const Range* range, ExceptionCode& ec)
1238 {
1239     if (!range) {
1240         ec = INVALID_ACCESS_ERR;
1241         return String();
1242     }
1243
1244     return range->text();
1245 }
1246
1247 void Internals::setDelegatesScrolling(bool enabled, Document* document, ExceptionCode& ec)
1248 {
1249     // Delegate scrolling is valid only on mainframe's view.
1250     if (!document || !document->view() || !document->page() || document->page()->mainFrame() != document->frame()) {
1251         ec = INVALID_ACCESS_ERR;
1252         return;
1253     }
1254
1255     document->view()->setDelegatesScrolling(enabled);
1256 }
1257
1258 #if ENABLE(TOUCH_ADJUSTMENT)
1259 PassRefPtr<WebKitPoint> Internals::touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
1260 {
1261     if (!document || !document->frame()) {
1262         ec = INVALID_ACCESS_ERR;
1263         return 0;
1264     }
1265
1266     IntSize radius(width / 2, height / 2);
1267     IntPoint point(x + radius.width(), y + radius.height());
1268
1269     Node* targetNode;
1270     IntPoint adjustedPoint;
1271
1272     bool foundNode = document->frame()->eventHandler()->bestClickableNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1273     if (foundNode)
1274         return WebKitPoint::create(adjustedPoint.x(), adjustedPoint.y());
1275
1276     return 0;
1277 }
1278
1279 Node* Internals::touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
1280 {
1281     if (!document || !document->frame()) {
1282         ec = INVALID_ACCESS_ERR;
1283         return 0;
1284     }
1285
1286     IntSize radius(width / 2, height / 2);
1287     IntPoint point(x + radius.width(), y + radius.height());
1288
1289     Node* targetNode;
1290     IntPoint adjustedPoint;
1291     document->frame()->eventHandler()->bestClickableNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1292     return targetNode;
1293 }
1294
1295 PassRefPtr<WebKitPoint> Internals::touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
1296 {
1297     if (!document || !document->frame()) {
1298         ec = INVALID_ACCESS_ERR;
1299         return 0;
1300     }
1301
1302     IntSize radius(width / 2, height / 2);
1303     IntPoint point(x + radius.width(), y + radius.height());
1304
1305     Node* targetNode = 0;
1306     IntPoint adjustedPoint;
1307
1308     bool foundNode = document->frame()->eventHandler()->bestContextMenuNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1309     if (foundNode)
1310         return WebKitPoint::create(adjustedPoint.x(), adjustedPoint.y());
1311
1312     return WebKitPoint::create(x, y);
1313 }
1314
1315 Node* Internals::touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
1316 {
1317     if (!document || !document->frame()) {
1318         ec = INVALID_ACCESS_ERR;
1319         return 0;
1320     }
1321
1322     IntSize radius(width / 2, height / 2);
1323     IntPoint point(x + radius.width(), y + radius.height());
1324
1325     Node* targetNode = 0;
1326     IntPoint adjustedPoint;
1327     document->frame()->eventHandler()->bestContextMenuNodeForTouchPoint(point, radius, adjustedPoint, targetNode);
1328     return targetNode;
1329 }
1330
1331 PassRefPtr<ClientRect> Internals::bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document* document, ExceptionCode& ec)
1332 {
1333     if (!document || !document->frame()) {
1334         ec = INVALID_ACCESS_ERR;
1335         return 0;
1336     }
1337
1338     IntSize radius(width / 2, height / 2);
1339     IntPoint point(x + radius.width(), y + radius.height());
1340
1341     Node* targetNode;
1342     IntRect zoomableArea;
1343     bool foundNode = document->frame()->eventHandler()->bestZoomableAreaForTouchPoint(point, radius, zoomableArea, targetNode);
1344     if (foundNode)
1345         return ClientRect::create(zoomableArea);
1346
1347     return 0;
1348 }
1349 #endif
1350
1351
1352 int Internals::lastSpellCheckRequestSequence(Document* document, ExceptionCode& ec)
1353 {
1354     SpellChecker* checker = spellchecker(document);
1355
1356     if (!checker) {
1357         ec = INVALID_ACCESS_ERR;
1358         return -1;
1359     }
1360
1361     return checker->lastRequestSequence();
1362 }
1363
1364 int Internals::lastSpellCheckProcessedSequence(Document* document, ExceptionCode& ec)
1365 {
1366     SpellChecker* checker = spellchecker(document);
1367
1368     if (!checker) {
1369         ec = INVALID_ACCESS_ERR;
1370         return -1;
1371     }
1372
1373     return checker->lastProcessedSequence();
1374 }
1375
1376 Vector<String> Internals::userPreferredLanguages() const
1377 {
1378     return WebCore::userPreferredLanguages();
1379 }
1380
1381 void Internals::setUserPreferredLanguages(const Vector<String>& languages)
1382 {
1383     WebCore::overrideUserPreferredLanguages(languages);
1384 }
1385
1386 unsigned Internals::wheelEventHandlerCount(Document* document, ExceptionCode& ec)
1387 {
1388     if (!document) {
1389         ec = INVALID_ACCESS_ERR;
1390         return 0;
1391     }
1392
1393     return document->wheelEventHandlerCount();
1394 }
1395
1396 unsigned Internals::touchEventHandlerCount(Document* document, ExceptionCode& ec)
1397 {
1398     if (!document) {
1399         ec = INVALID_ACCESS_ERR;
1400         return 0;
1401     }
1402
1403     const TouchEventTargetSet* touchHandlers = document->touchEventTargets();
1404     if (!touchHandlers)
1405         return 0;
1406
1407     unsigned count = 0;
1408     for (TouchEventTargetSet::const_iterator iter = touchHandlers->begin(); iter != touchHandlers->end(); ++iter)
1409         count += iter->value;
1410     return count;
1411 }
1412
1413 #if ENABLE(TOUCH_EVENT_TRACKING)
1414 PassRefPtr<ClientRectList> Internals::touchEventTargetClientRects(Document* document, ExceptionCode& ec)
1415 {
1416     if (!document || !document->view() || !document->page()) {
1417         ec = INVALID_ACCESS_ERR;
1418         return 0;
1419     }
1420     if (!document->page()->scrollingCoordinator())
1421         return ClientRectList::create();
1422
1423     document->updateLayoutIgnorePendingStylesheets();
1424
1425     Vector<IntRect> absoluteRects;
1426     document->page()->scrollingCoordinator()->computeAbsoluteTouchEventTargetRects(document, absoluteRects);
1427     Vector<FloatQuad> absoluteQuads(absoluteRects.size());
1428
1429     for (size_t i = 0; i < absoluteRects.size(); ++i)
1430         absoluteQuads[i] = FloatQuad(absoluteRects[i]);
1431
1432     return ClientRectList::create(absoluteQuads);
1433 }
1434 #endif
1435
1436 PassRefPtr<NodeList> Internals::nodesFromRect(Document* document, int x, int y, unsigned topPadding, unsigned rightPadding,
1437     unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent, ExceptionCode& ec) const
1438 {
1439     if (!document || !document->frame() || !document->frame()->view()) {
1440         ec = INVALID_ACCESS_ERR;
1441         return 0;
1442     }
1443
1444     HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly | HitTestRequest::Active;
1445     if (ignoreClipping)
1446         hitType |= HitTestRequest::IgnoreClipping;
1447     if (allowShadowContent)
1448         hitType |= HitTestRequest::AllowShadowContent;
1449     if (allowChildFrameContent)
1450         hitType |= HitTestRequest::AllowChildFrameContent;
1451
1452     return document->nodesFromRect(x, y, topPadding, rightPadding, bottomPadding, leftPadding, hitType);
1453 }
1454
1455 void Internals::emitInspectorDidBeginFrame()
1456 {
1457 #if ENABLE(INSPECTOR)
1458     InspectorController* inspectorController = contextDocument()->frame()->page()->inspectorController();
1459     inspectorController->didBeginFrame();
1460 #endif
1461 }
1462
1463 void Internals::emitInspectorDidCancelFrame()
1464 {
1465 #if ENABLE(INSPECTOR)
1466     InspectorController* inspectorController = contextDocument()->frame()->page()->inspectorController();
1467     inspectorController->didCancelFrame();
1468 #endif
1469 }
1470
1471 void Internals::setBatteryStatus(Document* document, const String& eventType, bool charging, double chargingTime, double dischargingTime, double level, ExceptionCode& ec)
1472 {
1473     if (!document || !document->page()) {
1474         ec = INVALID_ACCESS_ERR;
1475         return;
1476     }
1477
1478 #if ENABLE(BATTERY_STATUS)
1479     BatteryController::from(document->page())->didChangeBatteryStatus(eventType, BatteryStatus::create(charging, chargingTime, dischargingTime, level));
1480 #else
1481     UNUSED_PARAM(eventType);
1482     UNUSED_PARAM(charging);
1483     UNUSED_PARAM(chargingTime);
1484     UNUSED_PARAM(dischargingTime);
1485     UNUSED_PARAM(level);
1486 #endif
1487 }
1488
1489 void Internals::setNetworkInformation(Document* document, const String& eventType, double bandwidth, bool metered, ExceptionCode& ec)
1490 {
1491     if (!document || !document->page()) {
1492         ec = INVALID_ACCESS_ERR;
1493         return;
1494     }
1495
1496 #if ENABLE(NETWORK_INFO)
1497     NetworkInfoController::from(document->page())->didChangeNetworkInformation(eventType, NetworkInfo::create(bandwidth, metered));
1498 #else
1499     UNUSED_PARAM(eventType);
1500     UNUSED_PARAM(bandwidth);
1501     UNUSED_PARAM(metered);
1502 #endif
1503 }
1504
1505 void Internals::setDeviceProximity(Document* document, const String& eventType, double value, double min, double max, ExceptionCode& ec)
1506 {
1507     if (!document || !document->page()) {
1508         ec = INVALID_ACCESS_ERR;
1509         return;
1510     }
1511
1512 #if ENABLE(PROXIMITY_EVENTS)
1513     DeviceProximityController::from(document->page())->didChangeDeviceProximity(value, min, max);
1514 #else
1515     UNUSED_PARAM(eventType);
1516     UNUSED_PARAM(value);
1517     UNUSED_PARAM(min);
1518     UNUSED_PARAM(max);
1519 #endif
1520 }
1521
1522 bool Internals::hasSpellingMarker(Document* document, int from, int length, ExceptionCode&)
1523 {
1524     if (!document || !document->frame())
1525         return 0;
1526
1527     return document->frame()->editor()->selectionStartHasMarkerFor(DocumentMarker::Spelling, from, length);
1528 }
1529     
1530 bool Internals::hasAutocorrectedMarker(Document* document, int from, int length, ExceptionCode&)
1531 {
1532     if (!document || !document->frame())
1533         return 0;
1534     
1535     return document->frame()->editor()->selectionStartHasMarkerFor(DocumentMarker::Autocorrected, from, length);
1536 }
1537
1538 #if ENABLE(INSPECTOR)
1539 unsigned Internals::numberOfLiveNodes() const
1540 {
1541     return InspectorCounters::counterValue(InspectorCounters::NodeCounter);
1542 }
1543
1544 unsigned Internals::numberOfLiveDocuments() const
1545 {
1546     return InspectorCounters::counterValue(InspectorCounters::DocumentCounter);
1547 }
1548
1549 Vector<String> Internals::consoleMessageArgumentCounts(Document* document) const
1550 {
1551     InstrumentingAgents* instrumentingAgents = instrumentationForPage(document->page());
1552     if (!instrumentingAgents)
1553         return Vector<String>();
1554     InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent();
1555     if (!consoleAgent)
1556         return Vector<String>();
1557     Vector<unsigned> counts = consoleAgent->consoleMessageArgumentCounts();
1558     Vector<String> result(counts.size());
1559     for (size_t i = 0; i < counts.size(); i++)
1560         result[i] = String::number(counts[i]);
1561     return result;
1562 }
1563
1564 PassRefPtr<DOMWindow> Internals::openDummyInspectorFrontend(const String& url)
1565 {
1566     Page* page = contextDocument()->frame()->page();
1567     ASSERT(page);
1568
1569     DOMWindow* window = page->mainFrame()->document()->domWindow();
1570     ASSERT(window);
1571
1572     m_frontendWindow = window->open(url, "", "", window, window);
1573     ASSERT(m_frontendWindow);
1574
1575     Page* frontendPage = m_frontendWindow->document()->page();
1576     ASSERT(frontendPage);
1577
1578     OwnPtr<InspectorFrontendClientDummy> frontendClient = adoptPtr(new InspectorFrontendClientDummy(page->inspectorController(), frontendPage));
1579
1580     frontendPage->inspectorController()->setInspectorFrontendClient(frontendClient.release());
1581
1582     m_frontendChannel = adoptPtr(new InspectorFrontendChannelDummy(frontendPage));
1583
1584     page->inspectorController()->connectFrontend(m_frontendChannel.get());
1585
1586     return m_frontendWindow;
1587 }
1588
1589 void Internals::closeDummyInspectorFrontend()
1590 {
1591     Page* page = contextDocument()->frame()->page();
1592     ASSERT(page);
1593     ASSERT(m_frontendWindow);
1594
1595     page->inspectorController()->disconnectFrontend();
1596
1597     m_frontendChannel.release();
1598
1599     m_frontendWindow->close(m_frontendWindow->scriptExecutionContext());
1600     m_frontendWindow.release();
1601 }
1602
1603 void Internals::setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionCode& ec)
1604 {
1605     Page* page = contextDocument()->frame()->page();
1606     if (!page || !page->inspectorController()) {
1607         ec = INVALID_ACCESS_ERR;
1608         return;
1609     }
1610     page->inspectorController()->setResourcesDataSizeLimitsFromInternals(maximumResourcesContentSize, maximumSingleResourceContentSize);
1611 }
1612
1613 void Internals::setJavaScriptProfilingEnabled(bool enabled, ExceptionCode& ec)
1614 {
1615     Page* page = contextDocument()->frame()->page();
1616     if (!page || !page->inspectorController()) {
1617         ec = INVALID_ACCESS_ERR;
1618         return;
1619     }
1620
1621     page->inspectorController()->setProfilerEnabled(enabled);
1622 }
1623 #endif // ENABLE(INSPECTOR)
1624
1625 bool Internals::hasGrammarMarker(Document* document, int from, int length, ExceptionCode&)
1626 {
1627     if (!document || !document->frame())
1628         return 0;
1629
1630     return document->frame()->editor()->selectionStartHasMarkerFor(DocumentMarker::Grammar, from, length);
1631 }
1632
1633 unsigned Internals::numberOfScrollableAreas(Document* document, ExceptionCode&)
1634 {
1635     unsigned count = 0;
1636     Frame* frame = document->frame();
1637     if (frame->view()->scrollableAreas())
1638         count += frame->view()->scrollableAreas()->size();
1639
1640     for (Frame* child = frame->tree()->firstChild(); child; child = child->tree()->nextSibling()) {
1641         if (child->view() && child->view()->scrollableAreas())
1642             count += child->view()->scrollableAreas()->size();
1643     }
1644
1645     return count;
1646 }
1647     
1648 bool Internals::isPageBoxVisible(Document* document, int pageNumber, ExceptionCode& ec)
1649 {
1650     if (!document) {
1651         ec = INVALID_ACCESS_ERR;
1652         return false;
1653     }
1654
1655     return document->isPageBoxVisible(pageNumber);
1656 }
1657
1658 String Internals::layerTreeAsText(Document* document, ExceptionCode& ec) const
1659 {
1660     return layerTreeAsText(document, 0, ec);
1661 }
1662
1663 String Internals::layerTreeAsText(Document* document, unsigned flags, ExceptionCode& ec) const
1664 {
1665     if (!document || !document->frame()) {
1666         ec = INVALID_ACCESS_ERR;
1667         return String();
1668     }
1669
1670     LayerTreeFlags layerTreeFlags = 0;
1671     if (flags & LAYER_TREE_INCLUDES_VISIBLE_RECTS)
1672         layerTreeFlags |= LayerTreeFlagsIncludeVisibleRects;
1673     if (flags & LAYER_TREE_INCLUDES_TILE_CACHES)
1674         layerTreeFlags |= LayerTreeFlagsIncludeTileCaches;
1675     if (flags & LAYER_TREE_INCLUDES_REPAINT_RECTS)
1676         layerTreeFlags |= LayerTreeFlagsIncludeRepaintRects;
1677     if (flags & LAYER_TREE_INCLUDES_PAINTING_PHASES)
1678         layerTreeFlags |= LayerTreeFlagsIncludePaintingPhases;
1679
1680     return document->frame()->layerTreeAsText(layerTreeFlags);
1681 }
1682
1683 String Internals::repaintRectsAsText(Document* document, ExceptionCode& ec) const
1684 {
1685     if (!document || !document->frame()) {
1686         ec = INVALID_ACCESS_ERR;
1687         return String();
1688     }
1689
1690     return document->frame()->trackedRepaintRectsAsText();
1691 }
1692
1693 String Internals::scrollingStateTreeAsText(Document* document, ExceptionCode& ec) const
1694 {
1695     if (!document || !document->frame()) {
1696         ec = INVALID_ACCESS_ERR;
1697         return String();
1698     }
1699
1700     Page* page = document->page();
1701     if (!page)
1702         return String();
1703
1704     return page->scrollingStateTreeAsText();
1705 }
1706
1707 String Internals::mainThreadScrollingReasons(Document* document, ExceptionCode& ec) const
1708 {
1709     if (!document || !document->frame()) {
1710         ec = INVALID_ACCESS_ERR;
1711         return String();
1712     }
1713
1714     Page* page = document->page();
1715     if (!page)
1716         return String();
1717
1718     return page->mainThreadScrollingReasonsAsText();
1719 }
1720
1721 PassRefPtr<ClientRectList> Internals::nonFastScrollableRects(Document* document, ExceptionCode& ec) const
1722 {
1723     if (!document || !document->frame()) {
1724         ec = INVALID_ACCESS_ERR;
1725         return 0;
1726     }
1727
1728     Page* page = document->page();
1729     if (!page)
1730         return 0;
1731
1732     return page->nonFastScrollableRects(document->frame());
1733 }
1734
1735 void Internals::garbageCollectDocumentResources(Document* document, ExceptionCode& ec) const
1736 {
1737     if (!document) {
1738         ec = INVALID_ACCESS_ERR;
1739         return;
1740     }
1741
1742     CachedResourceLoader* cachedResourceLoader = document->cachedResourceLoader();
1743     if (!cachedResourceLoader)
1744         return;
1745     cachedResourceLoader->garbageCollectDocumentResources();
1746 }
1747
1748 void Internals::allowRoundingHacks() const
1749 {
1750     TextRun::setAllowsRoundingHacks(true);
1751 }
1752
1753 void Internals::insertAuthorCSS(Document* document, const String& css) const
1754 {
1755     RefPtr<StyleSheetContents> parsedSheet = StyleSheetContents::create(document);
1756     parsedSheet->setIsUserStyleSheet(false);
1757     parsedSheet->parseString(css);
1758     document->styleSheetCollection()->addAuthorSheet(parsedSheet);
1759 }
1760
1761 void Internals::insertUserCSS(Document* document, const String& css) const
1762 {
1763     RefPtr<StyleSheetContents> parsedSheet = StyleSheetContents::create(document);
1764     parsedSheet->setIsUserStyleSheet(true);
1765     parsedSheet->parseString(css);
1766     document->styleSheetCollection()->addUserSheet(parsedSheet);
1767 }
1768
1769 String Internals::counterValue(Element* element)
1770 {
1771     if (!element)
1772         return String();
1773
1774     return counterValueForElement(element);
1775 }
1776
1777 int Internals::pageNumber(Element* element, float pageWidth, float pageHeight)
1778 {
1779     if (!element)
1780         return 0;
1781
1782     return PrintContext::pageNumberForElement(element, FloatSize(pageWidth, pageHeight));
1783 }
1784
1785 Vector<String> Internals::iconURLs(Document* document, int iconTypesMask) const
1786 {
1787     Vector<IconURL> iconURLs = document->iconURLs(iconTypesMask);
1788     Vector<String> array;
1789
1790     Vector<IconURL>::const_iterator iter(iconURLs.begin());
1791     for (; iter != iconURLs.end(); ++iter)
1792         array.append(iter->m_iconURL.string());
1793
1794     return array;
1795 }
1796
1797 Vector<String> Internals::shortcutIconURLs(Document* document) const
1798 {
1799     return iconURLs(document, Favicon);
1800 }
1801
1802 Vector<String> Internals::allIconURLs(Document* document) const
1803 {
1804     return iconURLs(document, Favicon | TouchIcon | TouchPrecomposedIcon);
1805 }
1806
1807 int Internals::numberOfPages(float pageWidth, float pageHeight)
1808 {
1809     if (!frame())
1810         return -1;
1811
1812     return PrintContext::numberOfPages(frame(), FloatSize(pageWidth, pageHeight));
1813 }
1814
1815 String Internals::pageProperty(String propertyName, int pageNumber, ExceptionCode& ec) const
1816 {
1817     if (!frame()) {
1818         ec = INVALID_ACCESS_ERR;
1819         return String();
1820     }
1821
1822     return PrintContext::pageProperty(frame(), propertyName.utf8().data(), pageNumber);
1823 }
1824
1825 String Internals::pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft, ExceptionCode& ec) const
1826 {
1827     if (!frame()) {
1828         ec = INVALID_ACCESS_ERR;
1829         return String();
1830     }
1831
1832     return PrintContext::pageSizeAndMarginsInPixels(frame(), pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft);
1833 }
1834
1835 void Internals::setPageScaleFactor(float scaleFactor, int x, int y, ExceptionCode& ec)
1836 {
1837     Document* document = contextDocument();
1838     if (!document || !document->page()) {
1839         ec = INVALID_ACCESS_ERR;
1840         return;
1841     }
1842     Page* page = document->page();
1843     page->setPageScaleFactor(scaleFactor, IntPoint(x, y));
1844 }
1845
1846 #if ENABLE(FULLSCREEN_API)
1847 void Internals::webkitWillEnterFullScreenForElement(Document* document, Element* element)
1848 {
1849     if (!document)
1850         return;
1851     document->webkitWillEnterFullScreenForElement(element);
1852 }
1853
1854 void Internals::webkitDidEnterFullScreenForElement(Document* document, Element* element)
1855 {
1856     if (!document)
1857         return;
1858     document->webkitDidEnterFullScreenForElement(element);
1859 }
1860
1861 void Internals::webkitWillExitFullScreenForElement(Document* document, Element* element)
1862 {
1863     if (!document)
1864         return;
1865     document->webkitWillExitFullScreenForElement(element);
1866 }
1867
1868 void Internals::webkitDidExitFullScreenForElement(Document* document, Element* element)
1869 {
1870     if (!document)
1871         return;
1872     document->webkitDidExitFullScreenForElement(element);
1873 }
1874 #endif
1875
1876 void Internals::registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme)
1877 {
1878     SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy(scheme);
1879 }
1880
1881 void Internals::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme)
1882 {
1883     SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(scheme);
1884 }
1885
1886 PassRefPtr<MallocStatistics> Internals::mallocStatistics() const
1887 {
1888     return MallocStatistics::create();
1889 }
1890
1891 PassRefPtr<TypeConversions> Internals::typeConversions() const
1892 {
1893     return TypeConversions::create();
1894 }
1895
1896 Vector<String> Internals::getReferencedFilePaths() const
1897 {
1898     frame()->loader()->history()->saveDocumentAndScrollState();
1899     return FormController::getReferencedFilePaths(frame()->loader()->history()->currentItem()->documentState());
1900 }
1901
1902 void Internals::startTrackingRepaints(Document* document, ExceptionCode& ec)
1903 {
1904     if (!document || !document->view()) {
1905         ec = INVALID_ACCESS_ERR;
1906         return;
1907     }
1908
1909     FrameView* frameView = document->view();
1910     frameView->setTracksRepaints(true);
1911 }
1912
1913 void Internals::stopTrackingRepaints(Document* document, ExceptionCode& ec)
1914 {
1915     if (!document || !document->view()) {
1916         ec = INVALID_ACCESS_ERR;
1917         return;
1918     }
1919
1920     FrameView* frameView = document->view();
1921     frameView->setTracksRepaints(false);
1922 }
1923
1924 #if USE(LAZY_NATIVE_CURSOR)
1925 static const char* cursorTypeToString(Cursor::Type cursorType)
1926 {
1927     switch (cursorType) {
1928     case Cursor::Pointer: return "Pointer";
1929     case Cursor::Cross: return "Cross";
1930     case Cursor::Hand: return "Hand";
1931     case Cursor::IBeam: return "IBeam";
1932     case Cursor::Wait: return "Wait";
1933     case Cursor::Help: return "Help";
1934     case Cursor::EastResize: return "EastResize";
1935     case Cursor::NorthResize: return "NorthResize";
1936     case Cursor::NorthEastResize: return "NorthEastResize";
1937     case Cursor::NorthWestResize: return "NorthWestResize";
1938     case Cursor::SouthResize: return "SouthResize";
1939     case Cursor::SouthEastResize: return "SouthEastResize";
1940     case Cursor::SouthWestResize: return "SouthWestResize";
1941     case Cursor::WestResize: return "WestResize";
1942     case Cursor::NorthSouthResize: return "NorthSouthResize";
1943     case Cursor::EastWestResize: return "EastWestResize";
1944     case Cursor::NorthEastSouthWestResize: return "NorthEastSouthWestResize";
1945     case Cursor::NorthWestSouthEastResize: return "NorthWestSouthEastResize";
1946     case Cursor::ColumnResize: return "ColumnResize";
1947     case Cursor::RowResize: return "RowResize";
1948     case Cursor::MiddlePanning: return "MiddlePanning";
1949     case Cursor::EastPanning: return "EastPanning";
1950     case Cursor::NorthPanning: return "NorthPanning";
1951     case Cursor::NorthEastPanning: return "NorthEastPanning";
1952     case Cursor::NorthWestPanning: return "NorthWestPanning";
1953     case Cursor::SouthPanning: return "SouthPanning";
1954     case Cursor::SouthEastPanning: return "SouthEastPanning";
1955     case Cursor::SouthWestPanning: return "SouthWestPanning";
1956     case Cursor::WestPanning: return "WestPanning";
1957     case Cursor::Move: return "Move";
1958     case Cursor::VerticalText: return "VerticalText";
1959     case Cursor::Cell: return "Cell";
1960     case Cursor::ContextMenu: return "ContextMenu";
1961     case Cursor::Alias: return "Alias";
1962     case Cursor::Progress: return "Progress";
1963     case Cursor::NoDrop: return "NoDrop";
1964     case Cursor::Copy: return "Copy";
1965     case Cursor::None: return "None";
1966     case Cursor::NotAllowed: return "NotAllowed";
1967     case Cursor::ZoomIn: return "ZoomIn";
1968     case Cursor::ZoomOut: return "ZoomOut";
1969     case Cursor::Grab: return "Grab";
1970     case Cursor::Grabbing: return "Grabbing";
1971     case Cursor::Custom: return "Custom";
1972     }
1973
1974     ASSERT_NOT_REACHED();
1975     return "UNKNOWN";
1976 }
1977 #endif
1978
1979 String Internals::getCurrentCursorInfo(Document* document, ExceptionCode& ec)
1980 {
1981     if (!document || !document->frame()) {
1982         ec = INVALID_ACCESS_ERR;
1983         return String();
1984     }
1985
1986     Cursor cursor = document->frame()->eventHandler()->currentMouseCursor();
1987
1988 #if USE(LAZY_NATIVE_CURSOR)
1989     StringBuilder result;
1990     result.append("type=");
1991     result.append(cursorTypeToString(cursor.type()));
1992     result.append(" hotSpot=");
1993     result.appendNumber(cursor.hotSpot().x());
1994     result.append(",");
1995     result.appendNumber(cursor.hotSpot().y());
1996     if (cursor.image()) {
1997         IntSize size = cursor.image()->size();
1998         result.append(" image=");
1999         result.appendNumber(size.width());
2000         result.append("x");
2001         result.appendNumber(size.height());
2002     }
2003 #if ENABLE(MOUSE_CURSOR_SCALE)
2004     if (cursor.imageScaleFactor() != 1) {
2005         result.append(" scale=");
2006         NumberToStringBuffer buffer;
2007         result.append(numberToFixedPrecisionString(cursor.imageScaleFactor(), 8, buffer, true));
2008     }
2009 #endif
2010     return result.toString();
2011 #else
2012     return "FAIL: Cursor details not available on this platform.";
2013 #endif
2014 }
2015
2016 PassRefPtr<ArrayBuffer> Internals::serializeObject(PassRefPtr<SerializedScriptValue> value) const
2017 {
2018 #if USE(V8)
2019     String stringValue = value->toWireString();
2020     return ArrayBuffer::create(static_cast<const void*>(stringValue.impl()->characters()), stringValue.sizeInBytes());
2021 #else
2022     Vector<uint8_t> bytes = value->data();
2023     return ArrayBuffer::create(bytes.data(), bytes.size());
2024 #endif
2025 }
2026
2027 PassRefPtr<SerializedScriptValue> Internals::deserializeBuffer(PassRefPtr<ArrayBuffer> buffer) const
2028 {
2029 #if USE(V8)
2030     String value(static_cast<const UChar*>(buffer->data()), buffer->byteLength() / sizeof(UChar));
2031     return SerializedScriptValue::createFromWire(value);
2032 #else
2033     Vector<uint8_t> bytes;
2034     bytes.append(static_cast<const uint8_t*>(buffer->data()), buffer->byteLength());
2035     return SerializedScriptValue::adopt(bytes);
2036 #endif
2037 }
2038
2039 void Internals::setUsesOverlayScrollbars(bool enabled)
2040 {
2041     WebCore::Settings::setUsesOverlayScrollbars(enabled);
2042 }
2043
2044 void Internals::forceReload(bool endToEnd)
2045 {
2046     frame()->loader()->reload(endToEnd);
2047 }
2048
2049 #if ENABLE(ENCRYPTED_MEDIA_V2)
2050 void Internals::initializeMockCDM()
2051 {
2052     CDM::registerCDMFactory(MockCDM::create, MockCDM::supportsKeySytem);
2053 }
2054 #endif
2055
2056 String Internals::markerTextForListItem(Element* element, ExceptionCode& ec)
2057 {
2058     if (!element) {
2059         ec = INVALID_ACCESS_ERR;
2060         return String();
2061     }
2062     return WebCore::markerTextForListItem(element);
2063 }
2064
2065 }