Patch for https://bugs.webkit.org/show_bug.cgi?id=43305
[WebKit-https.git] / WebKitTools / WebKitTestRunner / InjectedBundle / InjectedBundlePage.cpp
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "InjectedBundlePage.h"
27
28 #include "InjectedBundle.h"
29 #include <JavaScriptCore/JSRetainPtr.h>
30 #include <WebKit2/WKArray.h>
31 #include <WebKit2/WKBundleFrame.h>
32 #include <WebKit2/WKBundleFramePrivate.h>
33 #include <WebKit2/WKBundleNode.h>
34 #include <WebKit2/WKBundlePagePrivate.h>
35 #include <WebKit2/WKRetainPtr.h>
36 #include <WebKit2/WKBundleRange.h>
37 #include <WebKit2/WKString.h>
38 #include <WebKit2/WKStringCF.h>
39 #include <wtf/PassOwnPtr.h>
40 #include <wtf/RetainPtr.h>
41 #include <wtf/Vector.h>
42
43 using namespace std;
44
45 namespace WTR {
46
47 static ostream& operator<<(ostream& out, CFStringRef stringRef)
48 {
49     if (!stringRef)
50         return out;
51     CFIndex bufferLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(stringRef), kCFStringEncodingUTF8) + 1;
52     Vector<char> buffer(bufferLength);
53     if (!CFStringGetCString(stringRef, buffer.data(), bufferLength, kCFStringEncodingUTF8))
54         return out;
55     return out << buffer.data();
56 }
57
58 static ostream& operator<<(ostream& out, const RetainPtr<CFStringRef>& stringRef)
59 {
60     return out << stringRef.get();
61 }
62
63 static ostream& operator<<(ostream& out, WKStringRef stringRef)
64 {
65     if (!stringRef)
66         return out;
67     RetainPtr<CFStringRef> cfString(AdoptCF, WKStringCopyCFString(0, stringRef));
68     return out << cfString;
69 }
70
71 static ostream& operator<<(ostream& out, const WKRetainPtr<WKStringRef>& stringRef)
72 {
73     return out << stringRef.get();
74 }
75
76 static string dumpPath(WKBundleNodeRef node)
77 {
78     if (!node)
79         return "(null)";
80     WKRetainPtr<WKStringRef> nodeName(AdoptWK, WKBundleNodeCopyNodeName(node));
81     ostringstream out;
82     out << nodeName;
83     if (WKBundleNodeRef parent = WKBundleNodeGetParent(node))
84         out << " > " << dumpPath(parent);
85     return out.str();
86 }
87
88 static ostream& operator<<(ostream& out, WKBundleRangeRef rangeRef)
89 {
90     if (rangeRef)
91         out << "range from " << WKBundleRangeGetStartOffset(rangeRef) << " of " << dumpPath(WKBundleRangeGetStartContainer(rangeRef)) << " to " << WKBundleRangeGetEndOffset(rangeRef) << " of " << dumpPath(WKBundleRangeGetEndContainer(rangeRef));
92     else
93         out << "(null)";
94
95     return out;
96 }
97
98 static ostream& operator<<(ostream& out, WKBundleCSSStyleDeclarationRef style)
99 {
100     // DumpRenderTree calls -[DOMCSSStyleDeclaration description], which just dumps class name and object address.
101     // No existing tests actually hit this code path at the time of this writing, because WebCore doesn't call
102     // the editing client if the styling operation source is CommandFromDOM or CommandFromDOMWithUserInterface.
103     out << "<DOMCSSStyleDeclaration ADDRESS>";
104     return out;
105 }
106
107 InjectedBundlePage::InjectedBundlePage(WKBundlePageRef page)
108     : m_page(page)
109     , m_isLoading(false)
110 {
111     WKBundlePageLoaderClient loaderClient = {
112         0,
113         this,
114         _didStartProvisionalLoadForFrame,
115         _didReceiveServerRedirectForProvisionalLoadForFrame,
116         _didFailProvisionalLoadWithErrorForFrame,
117         _didCommitLoadForFrame,
118         _didFinishLoadForFrame,
119         _didFailLoadWithErrorForFrame,
120         _didReceiveTitleForFrame,
121         _didClearWindowForFrame
122     };
123     WKBundlePageSetLoaderClient(m_page, &loaderClient);
124
125     WKBundlePageUIClient uiClient = {
126         0,
127         this,
128         _willAddMessageToConsole,
129         _willSetStatusbarText,
130         _willRunJavaScriptAlert,
131         _willRunJavaScriptConfirm,
132         _willRunJavaScriptPrompt
133     };
134     WKBundlePageSetUIClient(m_page, &uiClient);
135
136     WKBundlePageEditorClient editorClient = {
137         0,
138         this,
139         _shouldBeginEditing,
140         _shouldEndEditing,
141         _shouldInsertNode,
142         _shouldInsertText,
143         _shouldDeleteRange,
144         _shouldChangeSelectedRange,
145         _shouldApplyStyle,
146         _didBeginEditing,
147         _didEndEditing,
148         _didChange,
149         _didChangeSelection
150     };
151     WKBundlePageSetEditorClient(m_page, &editorClient);
152 }
153
154 InjectedBundlePage::~InjectedBundlePage()
155 {
156 }
157
158 // Loader Client Callbacks
159
160 void InjectedBundlePage::_didStartProvisionalLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo)
161 {
162     static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didStartProvisionalLoadForFrame(frame);
163 }
164
165 void InjectedBundlePage::_didReceiveServerRedirectForProvisionalLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo)
166 {
167     static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didReceiveServerRedirectForProvisionalLoadForFrame(frame);
168 }
169
170 void InjectedBundlePage::_didFailProvisionalLoadWithErrorForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo)
171 {
172     static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didFailProvisionalLoadWithErrorForFrame(frame);
173 }
174
175 void InjectedBundlePage::_didCommitLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo)
176 {
177     static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didCommitLoadForFrame(frame);
178 }
179
180 void InjectedBundlePage::_didFinishLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo)
181 {
182     static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didFinishLoadForFrame(frame);
183 }
184
185 void InjectedBundlePage::_didFailLoadWithErrorForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo)
186 {
187     static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didFailLoadWithErrorForFrame(frame);
188 }
189
190 void InjectedBundlePage::_didReceiveTitleForFrame(WKBundlePageRef page, WKStringRef title, WKBundleFrameRef frame, const void *clientInfo)
191 {
192     static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didReceiveTitleForFrame(title, frame);
193 }
194
195 void InjectedBundlePage::_didClearWindowForFrame(WKBundlePageRef page, WKBundleFrameRef frame, JSGlobalContextRef context, JSObjectRef window, const void *clientInfo)
196 {
197     static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didClearWindowForFrame(frame, context, window);
198 }
199
200 void InjectedBundlePage::didStartProvisionalLoadForFrame(WKBundleFrameRef frame)
201 {
202     if (frame == WKBundlePageGetMainFrame(m_page))
203         m_isLoading = true;
204 }
205
206 void InjectedBundlePage::didReceiveServerRedirectForProvisionalLoadForFrame(WKBundleFrameRef frame)
207 {
208 }
209
210 void InjectedBundlePage::didFailProvisionalLoadWithErrorForFrame(WKBundleFrameRef frame)
211 {
212 }
213
214 void InjectedBundlePage::didCommitLoadForFrame(WKBundleFrameRef frame)
215 {
216 }
217
218 static JSValueRef propertyValue(JSContextRef context, JSObjectRef object, const char* propertyName)
219 {
220     if (!object)
221         return 0;
222     JSRetainPtr<JSStringRef> propertyNameString(Adopt, JSStringCreateWithUTF8CString(propertyName));
223     JSValueRef exception;
224     return JSObjectGetProperty(context, object, propertyNameString.get(), &exception);
225 }
226
227 static double numericWindowPropertyValue(WKBundleFrameRef frame, const char* propertyName)
228 {
229     JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame);
230     JSValueRef value = propertyValue(context, JSContextGetGlobalObject(context), propertyName);
231     if (!value)
232         return 0;
233     JSValueRef exception;
234     return JSValueToNumber(context, value, &exception);
235 }
236
237 enum FrameNamePolicy { ShouldNotIncludeFrameName, ShouldIncludeFrameName };
238
239 static void dumpFrameScrollPosition(WKBundleFrameRef frame, FrameNamePolicy shouldIncludeFrameName = ShouldNotIncludeFrameName)
240 {
241     double x = numericWindowPropertyValue(frame, "pageXOffset");
242     double y = numericWindowPropertyValue(frame, "pageYOffset");
243     if (fabs(x) > 0.00000001 || fabs(y) > 0.00000001) {
244         if (shouldIncludeFrameName) {
245             WKRetainPtr<WKStringRef> name(AdoptWK, WKBundleFrameCopyName(frame));
246             InjectedBundle::shared().os() << "frame '" << name << "' ";
247         }
248         InjectedBundle::shared().os() << "scrolled to " << x << "," << y << "\n";
249     }
250 }
251
252 static void dumpDescendantFrameScrollPositions(WKBundleFrameRef frame)
253 {
254     WKRetainPtr<WKArrayRef> childFrames(AdoptWK, WKBundleFrameCopyChildFrames(frame));
255     size_t size = WKArrayGetSize(childFrames.get());
256     for (size_t i = 0; i < size; ++i) {
257         WKBundleFrameRef subframe = static_cast<WKBundleFrameRef>(WKArrayGetItemAtIndex(childFrames.get(), i));
258         dumpFrameScrollPosition(subframe, ShouldIncludeFrameName);
259         dumpDescendantFrameScrollPositions(subframe);
260     }
261 }
262
263 void InjectedBundlePage::dumpAllFrameScrollPositions()
264 {
265     WKBundleFrameRef frame = WKBundlePageGetMainFrame(m_page);
266     dumpFrameScrollPosition(frame);
267     dumpDescendantFrameScrollPositions(frame);
268 }
269
270 static void dumpFrameText(WKBundleFrameRef frame)
271 {
272     WKRetainPtr<WKStringRef> text(AdoptWK, WKBundleFrameCopyInnerText(frame));
273     InjectedBundle::shared().os() << text << "\n";
274 }
275
276 static void dumpDescendantFramesText(WKBundleFrameRef frame)
277 {
278     WKRetainPtr<WKArrayRef> childFrames(AdoptWK, WKBundleFrameCopyChildFrames(frame));
279     size_t size = WKArrayGetSize(childFrames.get());
280     for (size_t i = 0; i < size; ++i) {
281         WKBundleFrameRef subframe = static_cast<WKBundleFrameRef>(WKArrayGetItemAtIndex(childFrames.get(), i));
282         WKRetainPtr<WKStringRef> subframeName(AdoptWK, WKBundleFrameCopyName(subframe));
283         InjectedBundle::shared().os() << "\n--------\nFrame: '" << subframeName << "'\n--------\n";
284         dumpFrameText(subframe);
285         dumpDescendantFramesText(subframe);
286     }
287 }
288
289 void InjectedBundlePage::dumpAllFramesText()
290 {
291     WKBundleFrameRef frame = WKBundlePageGetMainFrame(m_page);
292     dumpFrameText(frame);
293     dumpDescendantFramesText(frame);
294 }
295
296 void InjectedBundlePage::dump()
297 {
298     InjectedBundle::shared().layoutTestController()->invalidateWaitToDumpWatchdog();
299
300     switch (InjectedBundle::shared().layoutTestController()->whatToDump()) {
301     case LayoutTestController::RenderTree: {
302         WKRetainPtr<WKStringRef> text(AdoptWK, WKBundlePageCopyRenderTreeExternalRepresentation(m_page));
303         InjectedBundle::shared().os() << text;
304         break;
305     }
306     case LayoutTestController::MainFrameText:
307         dumpFrameText(WKBundlePageGetMainFrame(m_page));
308         break;
309     case LayoutTestController::AllFramesText:
310         dumpAllFramesText();
311         break;
312     }
313
314     if (InjectedBundle::shared().layoutTestController()->shouldDumpAllFrameScrollPositions())
315         dumpAllFrameScrollPositions();
316     else if (InjectedBundle::shared().layoutTestController()->shouldDumpMainFrameScrollPosition())
317         dumpFrameScrollPosition(WKBundlePageGetMainFrame(m_page));
318
319     InjectedBundle::shared().done();
320 }
321
322 void InjectedBundlePage::didFinishLoadForFrame(WKBundleFrameRef frame)
323 {
324     if (!WKBundleFrameIsMainFrame(frame))
325         return;
326
327     m_isLoading = false;
328
329     if (InjectedBundle::shared().layoutTestController()->waitToDump())
330         return;
331
332     dump();
333 }
334
335 void InjectedBundlePage::didFailLoadWithErrorForFrame(WKBundleFrameRef frame)
336 {
337     if (!WKBundleFrameIsMainFrame(frame))
338         return;
339
340     m_isLoading = false;
341
342     InjectedBundle::shared().done();
343 }
344
345 void InjectedBundlePage::didReceiveTitleForFrame(WKStringRef title, WKBundleFrameRef frame)
346 {
347 }
348
349 void InjectedBundlePage::didClearWindowForFrame(WKBundleFrameRef frame, JSGlobalContextRef context, JSObjectRef window)
350 {
351     JSValueRef exception = 0;
352     InjectedBundle::shared().layoutTestController()->makeWindowObject(context, window, &exception);
353 }
354
355 // UI Client Callbacks
356
357 void InjectedBundlePage::_willAddMessageToConsole(WKBundlePageRef page, WKStringRef message, uint32_t lineNumber, const void *clientInfo)
358 {
359     static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willAddMessageToConsole(message, lineNumber);
360 }
361
362 void InjectedBundlePage::_willSetStatusbarText(WKBundlePageRef page, WKStringRef statusbarText, const void *clientInfo)
363 {
364     static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willSetStatusbarText(statusbarText);
365 }
366
367 void InjectedBundlePage::_willRunJavaScriptAlert(WKBundlePageRef page, WKStringRef message, WKBundleFrameRef frame, const void *clientInfo)
368 {
369     static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willRunJavaScriptAlert(message, frame);
370 }
371
372 void InjectedBundlePage::_willRunJavaScriptConfirm(WKBundlePageRef page, WKStringRef message, WKBundleFrameRef frame, const void *clientInfo)
373 {
374     return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willRunJavaScriptConfirm(message, frame);
375 }
376
377 void InjectedBundlePage::_willRunJavaScriptPrompt(WKBundlePageRef page, WKStringRef message, WKStringRef defaultValue, WKBundleFrameRef frame, const void *clientInfo)
378 {
379     static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willRunJavaScriptPrompt(message, defaultValue, frame);
380 }
381
382 void InjectedBundlePage::willAddMessageToConsole(WKStringRef message, uint32_t lineNumber)
383 {
384     // FIXME: Strip file: urls.
385     InjectedBundle::shared().os() << "CONSOLE MESSAGE: line " << lineNumber << ": " << message << "\n";
386 }
387
388 void InjectedBundlePage::willSetStatusbarText(WKStringRef statusbarText)
389 {
390     if (!InjectedBundle::shared().layoutTestController()->shouldDumpStatusCallbacks())
391         return;
392
393     InjectedBundle::shared().os() << "UI DELEGATE STATUS CALLBACK: setStatusText:" << statusbarText << "\n";
394 }
395
396 void InjectedBundlePage::willRunJavaScriptAlert(WKStringRef message, WKBundleFrameRef)
397 {
398     InjectedBundle::shared().os() << "ALERT: " << message << "\n";
399 }
400
401 void InjectedBundlePage::willRunJavaScriptConfirm(WKStringRef message, WKBundleFrameRef)
402 {
403     InjectedBundle::shared().os() << "CONFIRM: " << message << "\n";
404 }
405
406 void InjectedBundlePage::willRunJavaScriptPrompt(WKStringRef message, WKStringRef defaultValue, WKBundleFrameRef)
407 {
408     InjectedBundle::shared().os() << "PROMPT: " << message << ", default text: " << defaultValue <<  "\n";
409 }
410
411 // Editor Client Callbacks
412
413 bool InjectedBundlePage::_shouldBeginEditing(WKBundlePageRef page, WKBundleRangeRef range, const void* clientInfo)
414 {
415     return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->shouldBeginEditing(range);
416 }
417
418 bool InjectedBundlePage::_shouldEndEditing(WKBundlePageRef page, WKBundleRangeRef range, const void* clientInfo)
419 {
420     return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->shouldEndEditing(range);
421 }
422
423 bool InjectedBundlePage::_shouldInsertNode(WKBundlePageRef page, WKBundleNodeRef node, WKBundleRangeRef rangeToReplace, WKInsertActionType action, const void* clientInfo)
424 {
425     return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->shouldInsertNode(node, rangeToReplace, action);
426 }
427
428 bool InjectedBundlePage::_shouldInsertText(WKBundlePageRef page, WKStringRef text, WKBundleRangeRef rangeToReplace, WKInsertActionType action, const void* clientInfo)
429 {
430     return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->shouldInsertText(text, rangeToReplace, action);
431 }
432
433 bool InjectedBundlePage::_shouldDeleteRange(WKBundlePageRef page, WKBundleRangeRef range, const void* clientInfo)
434 {
435     return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->shouldDeleteRange(range);
436 }
437
438 bool InjectedBundlePage::_shouldChangeSelectedRange(WKBundlePageRef page, WKBundleRangeRef fromRange, WKBundleRangeRef toRange, WKAffinityType affinity, bool stillSelecting, const void* clientInfo)
439 {
440     return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->shouldChangeSelectedRange(fromRange, toRange, affinity, stillSelecting);
441 }
442
443 bool InjectedBundlePage::_shouldApplyStyle(WKBundlePageRef page, WKBundleCSSStyleDeclarationRef style, WKBundleRangeRef range, const void* clientInfo)
444 {
445     return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->shouldApplyStyle(style, range);
446 }
447
448 void InjectedBundlePage::_didBeginEditing(WKBundlePageRef page, WKStringRef notificationName, const void* clientInfo)
449 {
450     static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didBeginEditing(notificationName);
451 }
452
453 void InjectedBundlePage::_didEndEditing(WKBundlePageRef page, WKStringRef notificationName, const void* clientInfo)
454 {
455     static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didEndEditing(notificationName);
456 }
457
458 void InjectedBundlePage::_didChange(WKBundlePageRef page, WKStringRef notificationName, const void* clientInfo)
459 {
460     static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didChange(notificationName);
461 }
462
463 void InjectedBundlePage::_didChangeSelection(WKBundlePageRef page, WKStringRef notificationName, const void* clientInfo)
464 {
465     static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didChangeSelection(notificationName);
466 }
467
468 bool InjectedBundlePage::shouldBeginEditing(WKBundleRangeRef range)
469 {
470     if (InjectedBundle::shared().layoutTestController()->shouldDumpEditingCallbacks())
471         InjectedBundle::shared().os() << "EDITING DELEGATE: shouldBeginEditingInDOMRange:" << range << "\n";
472     return InjectedBundle::shared().layoutTestController()->shouldAllowEditing();
473 }
474
475 bool InjectedBundlePage::shouldEndEditing(WKBundleRangeRef range)
476 {
477     if (InjectedBundle::shared().layoutTestController()->shouldDumpEditingCallbacks())
478         InjectedBundle::shared().os() << "EDITING DELEGATE: shouldEndEditingInDOMRange:" << range << "\n";
479     return InjectedBundle::shared().layoutTestController()->shouldAllowEditing();
480 }
481
482 bool InjectedBundlePage::shouldInsertNode(WKBundleNodeRef node, WKBundleRangeRef rangeToReplace, WKInsertActionType action)
483 {
484     static const char *insertactionstring[] = {
485         "WebViewInsertActionTyped",
486         "WebViewInsertActionPasted",
487         "WebViewInsertActionDropped",
488     };
489
490     if (InjectedBundle::shared().layoutTestController()->shouldDumpEditingCallbacks())
491         InjectedBundle::shared().os() << "EDITING DELEGATE: shouldInsertNode:" << dumpPath(node) << " replacingDOMRange:" << rangeToReplace << " givenAction:" << insertactionstring[action] << "\n";
492     return InjectedBundle::shared().layoutTestController()->shouldAllowEditing();
493 }
494
495 bool InjectedBundlePage::shouldInsertText(WKStringRef text, WKBundleRangeRef rangeToReplace, WKInsertActionType action)
496 {
497     static const char *insertactionstring[] = {
498         "WebViewInsertActionTyped",
499         "WebViewInsertActionPasted",
500         "WebViewInsertActionDropped",
501     };
502
503     if (InjectedBundle::shared().layoutTestController()->shouldDumpEditingCallbacks())
504         InjectedBundle::shared().os() << "EDITING DELEGATE: shouldInsertText:" << text << " replacingDOMRange:" << rangeToReplace << " givenAction:" << insertactionstring[action] << "\n";
505     return InjectedBundle::shared().layoutTestController()->shouldAllowEditing();
506 }
507
508 bool InjectedBundlePage::shouldDeleteRange(WKBundleRangeRef range)
509 {
510     if (InjectedBundle::shared().layoutTestController()->shouldDumpEditingCallbacks())
511         InjectedBundle::shared().os() << "EDITING DELEGATE: shouldDeleteDOMRange:" << range << "\n";
512     return InjectedBundle::shared().layoutTestController()->shouldAllowEditing();
513 }
514
515 bool InjectedBundlePage::shouldChangeSelectedRange(WKBundleRangeRef fromRange, WKBundleRangeRef toRange, WKAffinityType affinity, bool stillSelecting)
516 {
517     static const char *affinitystring[] = {
518         "NSSelectionAffinityUpstream",
519         "NSSelectionAffinityDownstream"
520     };
521     static const char *boolstring[] = {
522         "FALSE",
523         "TRUE"
524     };
525
526     if (InjectedBundle::shared().layoutTestController()->shouldDumpEditingCallbacks())
527         InjectedBundle::shared().os() << "EDITING DELEGATE: shouldChangeSelectedDOMRange:" << fromRange << " toDOMRange:" << toRange << " affinity:" << affinitystring[affinity] << " stillSelecting:" << boolstring[stillSelecting] << "\n";
528     return InjectedBundle::shared().layoutTestController()->shouldAllowEditing();
529 }
530
531 bool InjectedBundlePage::shouldApplyStyle(WKBundleCSSStyleDeclarationRef style, WKBundleRangeRef range)
532 {
533     if (InjectedBundle::shared().layoutTestController()->shouldDumpEditingCallbacks())
534         InjectedBundle::shared().os() << "EDITING DELEGATE: shouldApplyStyle:" << style << " toElementsInDOMRange:" << range << "\n";
535     return InjectedBundle::shared().layoutTestController()->shouldAllowEditing();
536 }
537
538 void InjectedBundlePage::didBeginEditing(WKStringRef notificationName)
539 {
540     if (InjectedBundle::shared().layoutTestController()->shouldDumpEditingCallbacks())
541         InjectedBundle::shared().os() << "EDITING DELEGATE: webViewDidBeginEditing:" << notificationName << "\n";
542 }
543
544 void InjectedBundlePage::didEndEditing(WKStringRef notificationName)
545 {
546     if (InjectedBundle::shared().layoutTestController()->shouldDumpEditingCallbacks())
547         InjectedBundle::shared().os() << "EDITING DELEGATE: webViewDidEndEditing:" << notificationName << "\n";
548 }
549
550 void InjectedBundlePage::didChange(WKStringRef notificationName)
551 {
552     if (InjectedBundle::shared().layoutTestController()->shouldDumpEditingCallbacks())
553         InjectedBundle::shared().os() << "EDITING DELEGATE: webViewDidChange:" << notificationName << "\n";
554 }
555
556 void InjectedBundlePage::didChangeSelection(WKStringRef notificationName)
557 {
558     if (InjectedBundle::shared().layoutTestController()->shouldDumpEditingCallbacks())
559         InjectedBundle::shared().os() << "EDITING DELEGATE: webViewDidChangeSelection:" << notificationName << "\n";
560 }
561
562
563 } // namespace WTR