Range constructors should take a Document&.
[WebKit-https.git] / Source / WebKit / gtk / WebCoreSupport / DumpRenderTreeSupportGtk.cpp
1 /*
2  *  Copyright (C) Research In Motion Limited 2010. All rights reserved.
3  *  Copyright (C) 2010 Joone Hur <joone@kldp.org>
4  *  Copyright (C) 2009 Google Inc. All rights reserved.
5  *  Copyright (C) 2011 Igalia S.L.
6  *  Copyright (C) 2012, 2013 Apple Inc. All Rights Reserved.
7  *
8  *  This library is free software; you can redistribute it and/or
9  *  modify it under the terms of the GNU Lesser General Public
10  *  License as published by the Free Software Foundation; either
11  *  version 2 of the License, or (at your option) any later version.
12  *
13  *  This library is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  *  Lesser General Public License for more details.
17  *
18  *  You should have received a copy of the GNU Lesser General Public
19  *  License along with this library; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #include "config.h"
24 #include "DumpRenderTreeSupportGtk.h"
25
26 #include "APICast.h"
27 #include "AXObjectCache.h"
28 #include "AccessibilityObject.h"
29 #include "AnimationController.h"
30 #include "ApplicationCacheStorage.h"
31 #include "Chrome.h"
32 #include "ChromeClientGtk.h"
33 #include "DOMWrapperWorld.h"
34 #include "Document.h"
35 #include "Editor.h"
36 #include "EditorClientGtk.h"
37 #include "Element.h"
38 #include "FocusController.h"
39 #include "FrameTree.h"
40 #include "FrameView.h"
41 #include "GCController.h"
42 #include "GeolocationClientMock.h"
43 #include "GeolocationController.h"
44 #include "GeolocationError.h"
45 #include "GeolocationPosition.h"
46 #include "GraphicsContext.h"
47 #include "HTMLInputElement.h"
48 #include "JSCJSValue.h"
49 #include "JSCSSStyleDeclaration.h"
50 #include "JSDOMWindow.h"
51 #include "JSDocument.h"
52 #include "JSElement.h"
53 #include "JSLock.h"
54 #include "JSNodeList.h"
55 #include "MemoryCache.h"
56 #include "MutationObserver.h"
57 #include "NodeList.h"
58 #include "PageGroup.h"
59 #include "PrintContext.h"
60 #include "RenderListItem.h"
61 #include "RenderTreeAsText.h"
62 #include "RenderView.h"
63 #include "ResourceLoadScheduler.h"
64 #include "RuntimeEnabledFeatures.h"
65 #include "SchemeRegistry.h"
66 #include "SecurityOrigin.h"
67 #include "SecurityPolicy.h"
68 #include "Settings.h"
69 #include "TextIterator.h"
70 #include "WebKitAccessibleWrapperAtk.h"
71 #include "webkitglobalsprivate.h"
72 #include "webkitwebframe.h"
73 #include "webkitwebframeprivate.h"
74 #include "webkitwebview.h"
75 #include "webkitwebviewprivate.h"
76 #include <JavaScriptCore/APICast.h>
77 #include <wtf/text/WTFString.h>
78
79 using namespace JSC;
80 using namespace WebCore;
81 using namespace WebKit;
82
83 bool DumpRenderTreeSupportGtk::s_drtRun = false;
84 bool DumpRenderTreeSupportGtk::s_linksIncludedInTabChain = true;
85 DumpRenderTreeSupportGtk::FrameLoadEventCallback DumpRenderTreeSupportGtk::s_frameLoadEventCallback = 0;
86 DumpRenderTreeSupportGtk::AuthenticationCallback DumpRenderTreeSupportGtk::s_authenticationCallback = 0;
87
88 DumpRenderTreeSupportGtk::DumpRenderTreeSupportGtk()
89 {
90 }
91
92 DumpRenderTreeSupportGtk::~DumpRenderTreeSupportGtk()
93 {
94 }
95
96 void DumpRenderTreeSupportGtk::setDumpRenderTreeModeEnabled(bool enabled)
97 {
98     s_drtRun = enabled;
99 }
100
101 bool DumpRenderTreeSupportGtk::dumpRenderTreeModeEnabled()
102 {
103     return s_drtRun;
104 }
105 void DumpRenderTreeSupportGtk::setLinksIncludedInFocusChain(bool enabled)
106 {
107     s_linksIncludedInTabChain = enabled;
108 }
109
110 bool DumpRenderTreeSupportGtk::linksIncludedInFocusChain()
111 {
112     return s_linksIncludedInTabChain;
113 }
114
115 /**
116  * getFrameChildren:
117  * @frame: a #WebKitWebFrame
118  *
119  * Return value: child frames of @frame
120  */
121 GSList* DumpRenderTreeSupportGtk::getFrameChildren(WebKitWebFrame* frame)
122 {
123     g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0);
124
125     Frame* coreFrame = core(frame);
126     if (!coreFrame)
127         return 0;
128
129     GSList* children = 0;
130     for (Frame* child = coreFrame->tree().firstChild(); child; child = child->tree().nextSibling()) {
131         WebKitWebFrame* kitFrame = kit(child);
132         if (kitFrame)
133           children = g_slist_append(children, kitFrame);
134     }
135
136     return children;
137 }
138
139 /**
140  * getInnerText:
141  * @frame: a #WebKitWebFrame
142  *
143  * Return value: inner text of @frame
144  */
145 CString DumpRenderTreeSupportGtk::getInnerText(WebKitWebFrame* frame)
146 {
147     g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), CString(""));
148
149     Frame* coreFrame = core(frame);
150     if (!coreFrame)
151         return CString("");
152
153     FrameView* view = coreFrame->view();
154     if (view && view->layoutPending())
155         view->layout();
156
157     Element* documentElement = coreFrame->document()->documentElement();
158     if (!documentElement)
159         return CString("");
160     return documentElement->innerText().utf8();
161 }
162
163 /**
164  * dumpRenderTree:
165  * @frame: a #WebKitWebFrame
166  *
167  * Return value: Non-recursive render tree dump of @frame
168  */
169 CString DumpRenderTreeSupportGtk::dumpRenderTree(WebKitWebFrame* frame)
170 {
171     g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), CString(""));
172
173     Frame* coreFrame = core(frame);
174     if (!coreFrame)
175         return CString("");
176
177     FrameView* view = coreFrame->view();
178
179     if (view && view->layoutPending())
180         view->layout();
181
182     return externalRepresentation(coreFrame).utf8();
183 }
184
185 void DumpRenderTreeSupportGtk::addUserScript(WebKitWebFrame* frame, const char* sourceCode, bool runAtStart, bool allFrames)
186 {
187     g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame));
188
189     Frame* coreFrame = core(frame);
190     if (!coreFrame)
191         return;
192
193     WebKitWebView* webView = getViewFromFrame(frame);
194     Page* page = core(webView);
195     page->group().addUserScriptToWorld(mainThreadNormalWorld(), sourceCode, URL(), Vector<String>(), Vector<String>(),
196         runAtStart ? InjectAtDocumentStart : InjectAtDocumentEnd, allFrames ? InjectInAllFrames : InjectInTopFrameOnly);
197 }
198
199 /**
200  * addUserStyleSheet
201  * @frame: a #WebKitWebFrame
202  * @sourceCode: code of a user stylesheet
203  *
204  */
205 void DumpRenderTreeSupportGtk::addUserStyleSheet(WebKitWebFrame* frame, const char* sourceCode, bool allFrames)
206 {
207     g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame));
208
209     Frame* coreFrame = core(frame);
210     if (!coreFrame)
211         return;
212
213     WebKitWebView* webView = getViewFromFrame(frame);
214     Page* page = core(webView);
215     page->group().addUserStyleSheetToWorld(mainThreadNormalWorld(), sourceCode, URL(), Vector<String>(), Vector<String>(), allFrames ? InjectInAllFrames : InjectInTopFrameOnly); 
216 }
217
218 /**
219  * getPendingUnloadEventCount:
220  * @frame: a #WebKitWebFrame
221  *
222  * Return value: number of pending unload events
223  */
224 guint DumpRenderTreeSupportGtk::getPendingUnloadEventCount(WebKitWebFrame* frame)
225 {
226     g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0);
227
228     return core(frame)->document()->domWindow()->pendingUnloadEventListeners();
229 }
230
231 void DumpRenderTreeSupportGtk::clearMainFrameName(WebKitWebFrame* frame)
232 {
233     g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame));
234
235     core(frame)->tree().clearName();
236 }
237
238 AtkObject* DumpRenderTreeSupportGtk::getRootAccessibleElement(WebKitWebFrame* frame)
239 {
240     g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0);
241
242 #if HAVE(ACCESSIBILITY)
243     if (!AXObjectCache::accessibilityEnabled())
244         AXObjectCache::enableAccessibility();
245
246     WebKitWebFramePrivate* priv = frame->priv;
247     if (!priv->coreFrame || !priv->coreFrame->document())
248         return 0;
249
250     AtkObject* wrapper =  priv->coreFrame->document()->axObjectCache()->rootObject()->wrapper();
251     if (!wrapper)
252         return 0;
253
254     return wrapper;
255 #else
256     return 0;
257 #endif
258 }
259
260 AtkObject* DumpRenderTreeSupportGtk::getFocusedAccessibleElement(WebKitWebFrame* frame)
261 {
262 #if HAVE(ACCESSIBILITY)
263     AtkObject* wrapper = getRootAccessibleElement(frame);
264     if (!wrapper)
265         return 0;
266
267     return webkitAccessibleGetFocusedElement(WEBKIT_ACCESSIBLE(wrapper));
268 #else
269     return 0;
270 #endif
271 }
272
273 void DumpRenderTreeSupportGtk::executeCoreCommandByName(WebKitWebView* webView, const gchar* name, const gchar* value)
274 {
275     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
276     g_return_if_fail(name);
277     g_return_if_fail(value);
278
279     core(webView)->focusController().focusedOrMainFrame().editor().command(name).execute(value);
280 }
281
282 bool DumpRenderTreeSupportGtk::isCommandEnabled(WebKitWebView* webView, const gchar* name)
283 {
284     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
285     g_return_val_if_fail(name, FALSE);
286
287     return core(webView)->focusController().focusedOrMainFrame().editor().command(name).isEnabled();
288 }
289
290 void DumpRenderTreeSupportGtk::setComposition(WebKitWebView* webView, const char* text, int start, int length)
291 {
292     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
293     g_return_if_fail(text);
294
295     Frame& frame = core(webView)->focusController().focusedOrMainFrame();
296     Editor& editor = frame.editor();
297     if (!editor.canEdit() && !editor.hasComposition())
298         return;
299
300     String compositionString = String::fromUTF8(text);
301     Vector<CompositionUnderline> underlines;
302     underlines.append(CompositionUnderline(0, compositionString.length(), Color(0, 0, 0), false));
303     editor.setComposition(compositionString, underlines, start, start + length);
304 }
305
306 bool DumpRenderTreeSupportGtk::hasComposition(WebKitWebView* webView)
307 {
308     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), false);
309     Frame& frame = core(webView)->focusController().focusedOrMainFrame();
310     return frame.editor().hasComposition();
311 }
312
313 bool DumpRenderTreeSupportGtk::compositionRange(WebKitWebView* webView, int* start, int* length)
314 {
315     g_return_val_if_fail(start && length, false);
316     *start = *length = 0;
317
318     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), false);
319     Frame& frame = core(webView)->focusController().focusedOrMainFrame();
320     Editor& editor = frame.editor();
321     if (!editor.hasComposition())
322         return false;
323
324     *start = editor.compositionStart();
325     *length = editor.compositionEnd() - *start;
326     return true;
327 }
328
329 void DumpRenderTreeSupportGtk::confirmComposition(WebKitWebView* webView, const char* text)
330 {
331     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
332
333     Frame& frame = core(webView)->focusController().focusedOrMainFrame();
334     Editor& editor = frame.editor();
335
336     if (!editor.hasComposition()) {
337         editor.insertText(String::fromUTF8(text), 0);
338         return;
339     }
340     if (text) {
341         editor.confirmComposition(String::fromUTF8(text));
342         return;
343     }
344     editor.confirmComposition();
345 }
346
347 void DumpRenderTreeSupportGtk::doCommand(WebKitWebView* webView, const char* command)
348 {
349     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
350     Frame& frame = core(webView)->focusController().focusedOrMainFrame();
351     Editor& editor = frame.editor();
352
353     String commandString(command);
354     // Remove ending : here.
355     if (commandString.endsWith(":", true))
356         commandString = commandString.left(commandString.length() - 1);
357
358     // Make the first char in upper case.
359     String firstChar = commandString.left(1);
360     commandString = commandString.right(commandString.length() - 1);
361     commandString.insert(firstChar.upper(), 0);
362
363     editor.command(commandString).execute();
364 }
365
366 bool DumpRenderTreeSupportGtk::firstRectForCharacterRange(WebKitWebView* webView, int location, int length, cairo_rectangle_int_t* rect)
367 {
368     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), false);
369     g_return_val_if_fail(rect, false);
370
371     if ((location + length < location) && (location + length))
372         length = 0;
373
374     Frame& frame = core(webView)->focusController().focusedOrMainFrame();
375     Editor& editor = frame.editor();
376
377     RefPtr<Range> range = TextIterator::rangeFromLocationAndLength(frame.selection().rootEditableElementOrDocumentElement(), location, length);
378     if (!range)
379         return false;
380
381     *rect = editor.firstRectForRange(range.get());
382     return true;
383 }
384
385 bool DumpRenderTreeSupportGtk::selectedRange(WebKitWebView* webView, int* start, int* length)
386 {
387     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), false);
388     g_return_val_if_fail(start && length, false);
389
390     Frame& frame = core(webView)->focusController().focusedOrMainFrame();
391
392     RefPtr<Range> range = frame.selection().toNormalizedRange().get();
393     if (!range)
394         return false;
395
396     Element* selectionRoot = frame.selection().rootEditableElement();
397     Element* scope = selectionRoot ? selectionRoot : frame.document()->documentElement();
398
399     RefPtr<Range> testRange = Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset());
400     ASSERT(testRange->startContainer() == scope);
401     *start = TextIterator::rangeLength(testRange.get());
402
403     ExceptionCode ec;
404     testRange->setEnd(range->endContainer(), range->endOffset(), ec);
405     ASSERT(testRange->startContainer() == scope);
406     *length = TextIterator::rangeLength(testRange.get());
407
408     return true;
409 }
410
411 void DumpRenderTreeSupportGtk::setDefersLoading(WebKitWebView* webView, bool defers)
412 {
413     core(webView)->setDefersLoading(defers);
414 }
415
416 void DumpRenderTreeSupportGtk::forceWebViewPaint(WebKitWebView* webView)
417 {
418     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
419
420     static_cast<WebKit::ChromeClient&>(core(webView)->chrome().client()).forcePaint();
421 }
422
423 void DumpRenderTreeSupportGtk::whiteListAccessFromOrigin(const gchar* sourceOrigin, const gchar* destinationProtocol, const gchar* destinationHost, bool allowDestinationSubdomains)
424 {
425     SecurityPolicy::addOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
426 }
427
428 void DumpRenderTreeSupportGtk::removeWhiteListAccessFromOrigin(const char* sourceOrigin, const char* destinationProtocol, const char* destinationHost, bool allowDestinationSubdomains)
429 {
430     SecurityPolicy::removeOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
431 }
432
433 void DumpRenderTreeSupportGtk::resetOriginAccessWhiteLists()
434 {
435     SecurityPolicy::resetOriginAccessWhitelists();
436 }
437
438 void DumpRenderTreeSupportGtk::gcCollectJavascriptObjects()
439 {
440     gcController().garbageCollectNow();
441 }
442
443 void DumpRenderTreeSupportGtk::gcCollectJavascriptObjectsOnAlternateThread(bool waitUntilDone)
444 {
445     gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
446 }
447
448 unsigned long DumpRenderTreeSupportGtk::gcCountJavascriptObjects()
449 {
450     JSC::JSLockHolder lock(JSDOMWindow::commonVM());
451     return JSDOMWindow::commonVM()->heap.objectCount();
452 }
453
454 void DumpRenderTreeSupportGtk::layoutFrame(WebKitWebFrame* frame)
455 {
456     Frame* coreFrame = core(frame);
457     if (!coreFrame)
458         return;
459
460     FrameView* view = coreFrame->view();
461     if (!view)
462         return;
463
464     view->layout();
465 }
466
467 void DumpRenderTreeSupportGtk::clearOpener(WebKitWebFrame* frame)
468 {
469     Frame* coreFrame = core(frame);
470     if (coreFrame)
471         coreFrame->loader().setOpener(0);
472 }
473
474 bool DumpRenderTreeSupportGtk::findString(WebKitWebView* webView, const gchar* targetString, WebKitFindOptions findOptions)
475 {
476     return core(webView)->findString(String::fromUTF8(targetString), findOptions);
477 }
478
479 void DumpRenderTreeSupportGtk::setValueForUser(JSContextRef context, JSValueRef nodeObject, JSStringRef value)
480 {
481     JSC::ExecState* exec = toJS(context);
482     Element* element = toElement(toJS(exec, nodeObject));
483     if (!element)
484         return;
485     HTMLInputElement* inputElement = element->toInputElement();
486     if (!inputElement)
487         return;
488
489     size_t bufferSize = JSStringGetMaximumUTF8CStringSize(value);
490     GOwnPtr<gchar> valueBuffer(static_cast<gchar*>(g_malloc(bufferSize)));
491     JSStringGetUTF8CString(value, valueBuffer.get(), bufferSize);
492     inputElement->setValueForUser(String::fromUTF8(valueBuffer.get()));
493 }
494
495 void DumpRenderTreeSupportGtk::rectangleForSelection(WebKitWebFrame* frame, cairo_rectangle_int_t* rectangle)
496 {
497     Frame* coreFrame = core(frame);
498     if (!coreFrame)
499         return;
500
501     IntRect bounds = enclosingIntRect(coreFrame->selection().bounds());
502     rectangle->x = bounds.x();
503     rectangle->y = bounds.y();
504     rectangle->width = bounds.width();
505     rectangle->height = bounds.height();
506 }
507
508 bool DumpRenderTreeSupportGtk::shouldClose(WebKitWebFrame* frame)
509 {
510     Frame* coreFrame = core(frame);
511     if (!coreFrame)
512         return true;
513     return coreFrame->loader().shouldClose();
514 }
515
516 void DumpRenderTreeSupportGtk::scalePageBy(WebKitWebView* webView, float scaleFactor, float x, float y)
517 {
518     core(webView)->setPageScaleFactor(scaleFactor, IntPoint(x, y));
519 }
520
521 void DumpRenderTreeSupportGtk::resetGeolocationClientMock(WebKitWebView* webView)
522 {
523 #if ENABLE(GEOLOCATION)
524     GeolocationClientMock* mock = static_cast<GeolocationClientMock*>(GeolocationController::from(core(webView))->client());
525     mock->reset();
526 #endif
527 }
528
529 void DumpRenderTreeSupportGtk::setMockGeolocationPermission(WebKitWebView* webView, bool allowed)
530 {
531 #if ENABLE(GEOLOCATION)
532     GeolocationClientMock* mock = static_cast<GeolocationClientMock*>(GeolocationController::from(core(webView))->client());
533     mock->setPermission(allowed);
534 #endif
535 }
536
537 void DumpRenderTreeSupportGtk::setMockGeolocationPosition(WebKitWebView* webView, double latitude, double longitude, double accuracy)
538 {
539 #if ENABLE(GEOLOCATION)
540     GeolocationClientMock* mock = static_cast<GeolocationClientMock*>(GeolocationController::from(core(webView))->client());
541
542     double timestamp = g_get_real_time() / 1000000.0;
543     mock->setPosition(GeolocationPosition::create(timestamp, latitude, longitude, accuracy));
544 #endif
545 }
546
547 void DumpRenderTreeSupportGtk::setMockGeolocationPositionUnavailableError(WebKitWebView* webView, const gchar* errorMessage)
548 {
549 #if ENABLE(GEOLOCATION)
550     GeolocationClientMock* mock = static_cast<GeolocationClientMock*>(GeolocationController::from(core(webView))->client());
551     mock->setPositionUnavailableError(errorMessage);
552 #endif
553 }
554
555 int DumpRenderTreeSupportGtk::numberOfPendingGeolocationPermissionRequests(WebKitWebView* webView)
556 {
557 #if ENABLE(GEOLOCATION)
558     GeolocationClientMock* mock = static_cast<GeolocationClientMock*>(GeolocationController::from(core(webView))->client());
559     return mock->numberOfPendingPermissionRequests();
560 #else
561     return 0;
562 #endif
563 }
564
565 void DumpRenderTreeSupportGtk::setPageCacheSupportsPlugins(WebKitWebView* webView, bool enabled)
566 {
567     core(webView)->settings().setPageCacheSupportsPlugins(enabled);
568 }
569
570 void DumpRenderTreeSupportGtk::setCSSGridLayoutEnabled(WebKitWebView* webView, bool enabled)
571 {
572     core(webView)->settings().setCSSGridLayoutEnabled(enabled);
573 }
574
575 void DumpRenderTreeSupportGtk::setCSSRegionsEnabled(WebKitWebView* webView, bool enabled)
576 {
577     RuntimeEnabledFeatures::sharedFeatures().setCSSRegionsEnabled(enabled);
578 }
579
580 void DumpRenderTreeSupportGtk::setCSSCustomFilterEnabled(WebKitWebView* webView, bool enabled)
581 {
582 #if ENABLE(CSS_SHADERS)
583     core(webView)->settings().setCSSCustomFilterEnabled(enabled);
584 #endif
585 }
586
587 void DumpRenderTreeSupportGtk::setExperimentalContentSecurityPolicyFeaturesEnabled(bool enabled)
588 {
589 #if ENABLE(CSP_NEXT)
590     RuntimeEnabledFeatures::sharedFeatures().setExperimentalContentSecurityPolicyFeaturesEnabled(enabled);
591 #endif
592 }
593
594 void DumpRenderTreeSupportGtk::setSeamlessIFramesEnabled(bool enabled)
595 {
596 #if ENABLE(IFRAME_SEAMLESS)
597     RuntimeEnabledFeatures::sharedFeatures().setSeamlessIFramesEnabled(enabled);
598 #endif
599 }
600
601 void DumpRenderTreeSupportGtk::setShadowDOMEnabled(bool enabled)
602 {
603 #if ENABLE(SHADOW_DOM)
604     RuntimeEnabledFeatures::sharedFeatures().setShadowDOMEnabled(enabled);
605 #endif
606 }
607
608 void DumpRenderTreeSupportGtk::deliverAllMutationsIfNecessary()
609 {
610     MutationObserver::deliverAllMutations();
611 }
612
613 void DumpRenderTreeSupportGtk::setDomainRelaxationForbiddenForURLScheme(bool forbidden, const char* urlScheme)
614 {
615     SchemeRegistry::setDomainRelaxationForbiddenForURLScheme(forbidden, String::fromUTF8(urlScheme));
616 }
617
618 void DumpRenderTreeSupportGtk::setSerializeHTTPLoads(bool enabled)
619 {
620     resourceLoadScheduler()->setSerialLoadingEnabled(enabled);
621 }
622
623 void DumpRenderTreeSupportGtk::setTracksRepaints(WebKitWebFrame* frame, bool tracks)
624 {
625     g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame));
626
627     Frame* coreFrame = core(frame);
628     if (coreFrame && coreFrame->view())
629         coreFrame->view()->setTracksRepaints(tracks);
630 }
631
632 bool DumpRenderTreeSupportGtk::isTrackingRepaints(WebKitWebFrame* frame)
633 {
634     g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), false);
635
636     Frame* coreFrame = core(frame);
637     if (coreFrame && coreFrame->view())
638         return coreFrame->view()->isTrackingRepaints();
639
640     return false;
641 }
642
643 GSList* DumpRenderTreeSupportGtk::trackedRepaintRects(WebKitWebFrame* frame)
644 {
645     g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0);
646
647     Frame* coreFrame = core(frame);
648     if (!coreFrame || !coreFrame->view())
649         return 0;
650
651     GSList* rects = 0;
652     const Vector<IntRect>& repaintRects = coreFrame->view()->trackedRepaintRects();
653     for (unsigned i = 0; i < repaintRects.size(); i++) {
654         GdkRectangle* rect = g_new0(GdkRectangle, 1);
655         rect->x = repaintRects[i].x();
656         rect->y = repaintRects[i].y();
657         rect->width = repaintRects[i].width();
658         rect->height = repaintRects[i].height();
659         rects = g_slist_append(rects, rect);
660     }
661
662     return rects;
663 }
664
665 void DumpRenderTreeSupportGtk::resetTrackedRepaints(WebKitWebFrame* frame)
666 {
667     g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame));
668
669     Frame* coreFrame = core(frame);
670     if (coreFrame && coreFrame->view())
671         coreFrame->view()->resetTrackedRepaints();
672 }
673
674 void DumpRenderTreeSupportGtk::clearMemoryCache()
675 {
676     memoryCache()->evictResources();
677 }
678
679 void DumpRenderTreeSupportGtk::clearApplicationCache()
680 {
681     cacheStorage().empty();
682     cacheStorage().vacuumDatabaseFile();
683 }
684
685 void DumpRenderTreeSupportGtk::setFrameLoadEventCallback(FrameLoadEventCallback frameLoadEventCallback)
686 {
687     s_frameLoadEventCallback = frameLoadEventCallback;
688 }
689
690 void DumpRenderTreeSupportGtk::setAuthenticationCallback(AuthenticationCallback authenticationCallback)
691 {
692     s_authenticationCallback = authenticationCallback;
693 }
694
695 void DumpRenderTreeSupportGtk::setPageVisibility(WebKitWebView* webView, WebCore::PageVisibilityState visibilityState, bool isInitialState)
696 {
697 #if ENABLE(PAGE_VISIBILITY_API)
698     Page* page = core(webView);
699     if (!page)
700         return;
701
702     page->setVisibilityState(visibilityState, isInitialState);
703 #endif
704 }