OSDN Git Service

Merge WebKit at r74534: Initial merge by git.
[android-x86/external-webkit.git] / Tools / DumpRenderTree / LayoutTestController.cpp
1 /*
2  * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
3  * Copyright (C) 2010 Joone Hur <joone@kldp.org>
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  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15  *     its contributors may be used to endorse or promote products derived
16  *     from this software without specific prior written permission. 
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include "config.h"
31 #include "LayoutTestController.h"
32
33 #include "WorkQueue.h"
34 #include "WorkQueueItem.h"
35 #include <cstring>
36 #include <JavaScriptCore/JSContextRef.h>
37 #include <JavaScriptCore/JSObjectRef.h>
38 #include <JavaScriptCore/JSRetainPtr.h>
39 #include <stdio.h>
40 #include <wtf/Assertions.h>
41 #include <wtf/MathExtras.h>
42 #include <wtf/RefPtr.h>
43
44 LayoutTestController::LayoutTestController(const std::string& testPathOrURL, const std::string& expectedPixelHash)
45     : m_dumpApplicationCacheDelegateCallbacks(false)
46     , m_dumpAsPDF(false)
47     , m_dumpAsText(false)
48     , m_dumpBackForwardList(false)
49     , m_dumpChildFrameScrollPositions(false)
50     , m_dumpChildFramesAsText(false)
51     , m_dumpDOMAsWebArchive(false)
52     , m_dumpDatabaseCallbacks(false)
53     , m_dumpEditingCallbacks(false)
54     , m_dumpFrameLoadCallbacks(false)
55     , m_dumpUserGestureInFrameLoadCallbacks(false)
56     , m_dumpHistoryDelegateCallbacks(false)
57     , m_dumpResourceLoadCallbacks(false)
58     , m_dumpResourceResponseMIMETypes(false)
59     , m_dumpSelectionRect(false)
60     , m_dumpSourceAsWebArchive(false)
61     , m_dumpStatusCallbacks(false)
62     , m_dumpTitleChanges(false)
63     , m_dumpIconChanges(false)
64     , m_dumpVisitedLinksCallback(false)
65     , m_dumpWillCacheResponse(false)
66     , m_generatePixelResults(true)
67     , m_callCloseOnWebViews(true)
68     , m_canOpenWindows(false)
69     , m_closeRemainingWindowsWhenComplete(true)
70     , m_newWindowsCopyBackForwardList(false)
71     , m_stopProvisionalFrameLoads(false)
72     , m_testOnscreen(false)
73     , m_testRepaint(false)
74     , m_testRepaintSweepHorizontally(false)
75     , m_waitToDump(false)
76     , m_willSendRequestReturnsNull(false)
77     , m_willSendRequestReturnsNullOnRedirect(false)
78     , m_windowIsKey(true)
79     , m_alwaysAcceptCookies(false)
80     , m_globalFlag(false)
81     , m_isGeolocationPermissionSet(false)
82     , m_geolocationPermission(false)
83     , m_handlesAuthenticationChallenges(false)
84     , m_isPrinting(false)
85     , m_deferMainResourceDataLoad(true)
86     , m_testPathOrURL(testPathOrURL)
87     , m_expectedPixelHash(expectedPixelHash)
88 {
89 }
90
91 PassRefPtr<LayoutTestController> LayoutTestController::create(const std::string& testPathOrURL, const std::string& expectedPixelHash)
92 {
93     return adoptRef(new LayoutTestController(testPathOrURL, expectedPixelHash));
94 }
95
96 // Static Functions
97
98 static JSValueRef dumpApplicationCacheDelegateCallbacksCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
99 {
100     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
101     controller->setDumpApplicationCacheDelegateCallbacks(true);
102     return JSValueMakeUndefined(context);
103 }
104
105 static JSValueRef dumpAsPDFCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
106 {
107     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
108     controller->setDumpAsPDF(true);
109     return JSValueMakeUndefined(context);
110 }
111
112 static JSValueRef dumpAsTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
113 {
114     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
115     controller->setDumpAsText(true);
116
117     // Optional paramater, describing whether it's allowed to dump pixel results in dumpAsText mode.
118     controller->setGeneratePixelResults(argumentCount > 0 ? JSValueToBoolean(context, arguments[0]) : false);
119
120     return JSValueMakeUndefined(context);
121 }
122
123 static JSValueRef dumpBackForwardListCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
124 {
125     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
126     controller->setDumpBackForwardList(true);
127     return JSValueMakeUndefined(context);
128 }
129
130 static JSValueRef dumpChildFramesAsTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
131 {
132     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
133     controller->setDumpChildFramesAsText(true);
134     return JSValueMakeUndefined(context);
135 }
136
137 static JSValueRef dumpChildFrameScrollPositionsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
138 {
139     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
140     controller->setDumpChildFrameScrollPositions(true);
141     return JSValueMakeUndefined(context);
142 }
143
144 static JSValueRef dumpConfigurationForViewportCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
145 {
146     if (argumentCount < 2)
147         return JSValueMakeUndefined(context);
148
149     double availableWidth = JSValueToNumber(context, arguments[0], exception);
150     ASSERT(!*exception);
151     double availableHeight = JSValueToNumber(context, arguments[1], exception);
152     ASSERT(!*exception);
153
154     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
155     controller->dumpConfigurationForViewport(static_cast<int>(availableWidth), static_cast<int>(availableHeight));
156    
157     return JSValueMakeUndefined(context);
158 }
159
160 static JSValueRef dumpDatabaseCallbacksCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
161 {
162     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
163     controller->setDumpDatabaseCallbacks(true);
164     return JSValueMakeUndefined(context);
165 }
166
167 static JSValueRef dumpDOMAsWebArchiveCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
168 {
169     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
170     controller->setDumpDOMAsWebArchive(true);
171     return JSValueMakeUndefined(context);
172 }
173
174 static JSValueRef dumpEditingCallbacksCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
175 {
176     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
177     controller->setDumpEditingCallbacks(true);
178     return JSValueMakeUndefined(context);
179 }
180
181 static JSValueRef dumpFrameLoadCallbacksCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
182 {
183     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
184     controller->setDumpFrameLoadCallbacks(true);
185     return JSValueMakeUndefined(context);
186 }
187
188 static JSValueRef dumpUserGestureInFrameLoadCallbacksCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
189 {
190     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
191     controller->setDumpUserGestureInFrameLoadCallbacks(true);
192     return JSValueMakeUndefined(context);
193 }
194
195 static JSValueRef dumpResourceLoadCallbacksCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
196 {
197     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
198     controller->setDumpResourceLoadCallbacks(true);
199     return JSValueMakeUndefined(context);
200 }
201
202 static JSValueRef dumpResourceResponseMIMETypesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
203 {
204     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
205     controller->setDumpResourceResponseMIMETypes(true);
206     return JSValueMakeUndefined(context);
207 }
208
209 static JSValueRef dumpSelectionRectCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
210 {
211     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
212     controller->setDumpSelectionRect(true);
213     return JSValueMakeUndefined(context);
214 }
215
216 static JSValueRef dumpSourceAsWebArchiveCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
217 {
218     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
219     controller->setDumpSourceAsWebArchive(true);
220     return JSValueMakeUndefined(context);
221 }
222
223 static JSValueRef dumpStatusCallbacksCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
224 {
225     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
226     controller->setDumpStatusCallbacks(true);
227     return JSValueMakeUndefined(context);
228 }
229
230 static JSValueRef dumpTitleChangesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
231 {
232     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
233     controller->setDumpTitleChanges(true);
234     return JSValueMakeUndefined(context);
235 }
236
237 static JSValueRef dumpIconChangesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
238 {
239     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
240     controller->setDumpIconChanges(true);
241     return JSValueMakeUndefined(context);
242 }
243
244 static JSValueRef dumpWillCacheResponseCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
245 {
246     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
247     controller->setDumpWillCacheResponse(true);
248     return JSValueMakeUndefined(context);
249 }
250
251 static JSValueRef pathToLocalResourceCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
252 {
253     if (argumentCount < 1)
254         return JSValueMakeUndefined(context);
255
256     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
257     JSRetainPtr<JSStringRef> localPath(Adopt, JSValueToStringCopy(context, arguments[0], exception));
258     ASSERT(!*exception);
259
260     JSRetainPtr<JSStringRef> convertedPath(Adopt, controller->pathToLocalResource(context, localPath.get()));
261     if (!convertedPath)
262         return JSValueMakeUndefined(context);
263
264     return JSValueMakeString(context, convertedPath.get());
265 }
266
267 static JSValueRef removeAllVisitedLinksCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
268 {
269     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
270     controller->setDumpVisitedLinksCallback(true);
271     controller->removeAllVisitedLinks();
272     return JSValueMakeUndefined(context);
273 }
274
275 static JSValueRef repaintSweepHorizontallyCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
276 {
277     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
278     controller->setTestRepaintSweepHorizontally(true);
279     return JSValueMakeUndefined(context);
280 }
281
282 static JSValueRef setCallCloseOnWebViewsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
283 {
284     if (argumentCount < 1)
285         return JSValueMakeUndefined(context);
286
287     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
288     controller->setCallCloseOnWebViews(JSValueToBoolean(context, arguments[0]));
289     return JSValueMakeUndefined(context);
290 }
291
292 static JSValueRef setCanOpenWindowsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
293 {
294     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
295     controller->setCanOpenWindows(true);
296     return JSValueMakeUndefined(context);
297 }
298
299 static JSValueRef setCloseRemainingWindowsWhenCompleteCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
300 {
301     if (argumentCount < 1)
302         return JSValueMakeUndefined(context);
303
304     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
305     controller->setCloseRemainingWindowsWhenComplete(JSValueToBoolean(context, arguments[0]));
306     return JSValueMakeUndefined(context);
307 }
308
309 static JSValueRef testOnscreenCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
310 {
311     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
312     controller->setTestOnscreen(true);
313     return JSValueMakeUndefined(context);
314 }
315
316 static JSValueRef testRepaintCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
317 {
318     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
319     controller->setTestRepaint(true);
320     return JSValueMakeUndefined(context);
321 }
322
323 static JSValueRef addDisallowedURLCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
324 {
325     // Has mac implementation
326     if (argumentCount < 1)
327         return JSValueMakeUndefined(context);
328
329     JSRetainPtr<JSStringRef> url(Adopt, JSValueToStringCopy(context, arguments[0], exception));
330     ASSERT(!*exception);
331
332     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
333     controller->addDisallowedURL(url.get());
334
335     return JSValueMakeUndefined(context);
336 }
337
338 static JSValueRef callShouldCloseOnWebViewCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
339 {
340     // Has mac & windows implementation
341     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
342
343     return JSValueMakeBoolean(context, controller->callShouldCloseOnWebView());
344 }
345
346 static JSValueRef clearAllApplicationCachesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
347 {
348     // Has mac implementation
349     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
350     controller->clearAllApplicationCaches();
351
352     return JSValueMakeUndefined(context);
353 }
354
355 static JSValueRef clearAllDatabasesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
356 {
357     // Has mac & windows implementation
358     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
359     controller->clearAllDatabases();
360
361     return JSValueMakeUndefined(context);
362 }
363
364 static JSValueRef clearBackForwardListCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
365 {
366     // Has mac & windows implementation
367     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
368     controller->clearBackForwardList();
369
370     return JSValueMakeUndefined(context);
371 }
372
373 static JSValueRef clearPersistentUserStyleSheetCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
374 {
375     // Has mac & windows implementation
376     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
377     controller->clearPersistentUserStyleSheet();
378
379     return JSValueMakeUndefined(context);
380 }
381
382 static JSValueRef decodeHostNameCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
383 {
384     // Has mac implementation
385     if (argumentCount < 1)
386         return JSValueMakeUndefined(context);
387
388     JSRetainPtr<JSStringRef> name(Adopt, JSValueToStringCopy(context, arguments[0], exception));
389     ASSERT(!*exception);
390
391     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
392     JSRetainPtr<JSStringRef> decodedHostName(Adopt, controller->copyDecodedHostName(name.get()));
393     return JSValueMakeString(context, decodedHostName.get());
394 }
395
396 static JSValueRef disableImageLoadingCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
397 {
398     // Has mac implementation, needs windows implementation
399     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
400     controller->disableImageLoading();
401     
402     return JSValueMakeUndefined(context);
403 }
404
405 static JSValueRef dispatchPendingLoadRequestsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
406 {
407     // Has mac implementation, needs windows implementation
408     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
409     controller->dispatchPendingLoadRequests();
410     
411     return JSValueMakeUndefined(context);
412 }
413
414 static JSValueRef displayCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
415 {
416     // Has mac & windows implementation
417     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
418     controller->display();
419
420     return JSValueMakeUndefined(context);
421 }
422
423 static JSValueRef encodeHostNameCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
424 {
425     // Has mac implementation
426     if (argumentCount < 1)
427         return JSValueMakeUndefined(context);
428
429     JSRetainPtr<JSStringRef> name(Adopt, JSValueToStringCopy(context, arguments[0], exception));
430     ASSERT(!*exception);
431
432     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
433     JSRetainPtr<JSStringRef> encodedHostName(Adopt, controller->copyEncodedHostName(name.get()));
434     return JSValueMakeString(context, encodedHostName.get());
435 }
436
437 static JSValueRef execCommandCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
438 {
439     // Has Mac & Windows implementations.
440     if (argumentCount < 1)
441         return JSValueMakeUndefined(context);
442
443     JSRetainPtr<JSStringRef> name(Adopt, JSValueToStringCopy(context, arguments[0], exception));
444     ASSERT(!*exception);
445
446     // Ignoring the second parameter (userInterface), as this command emulates a manual action.
447
448     JSRetainPtr<JSStringRef> value;
449     if (argumentCount >= 3) {
450         value.adopt(JSValueToStringCopy(context, arguments[2], exception));
451         ASSERT(!*exception);
452     } else
453         value.adopt(JSStringCreateWithUTF8CString(""));
454
455
456     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
457     controller->execCommand(name.get(), value.get());
458
459     return JSValueMakeUndefined(context);
460 }
461
462 static JSValueRef findStringCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
463 {
464     // Has Mac implementation.
465     if (argumentCount < 2)
466         return JSValueMakeUndefined(context);
467
468     JSRetainPtr<JSStringRef> target(Adopt, JSValueToStringCopy(context, arguments[0], exception));
469     ASSERT(!*exception);
470
471     JSObjectRef options = JSValueToObject(context, arguments[1], exception);
472     ASSERT(!*exception);
473
474     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
475     return JSValueMakeBoolean(context, controller->findString(context, target.get(), options));
476 }
477
478 static JSValueRef counterValueForElementByIdCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
479 {
480     if (argumentCount < 1)
481         return JSValueMakeUndefined(context);
482
483     JSRetainPtr<JSStringRef> elementId(Adopt, JSValueToStringCopy(context, arguments[0], exception));
484     if (*exception)
485         return JSValueMakeUndefined(context);
486
487     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
488     JSRetainPtr<JSStringRef> counterValue(controller->counterValueForElementById(elementId.get()));
489     if (!counterValue.get())
490         return JSValueMakeUndefined(context);
491     return JSValueMakeString(context, counterValue.get());
492 }
493
494 static JSValueRef grantDesktopNotificationPermissionCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
495 {
496     // Has Windows implementation
497     if (argumentCount < 1)
498         return JSValueMakeUndefined(context);
499
500     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
501
502     controller->grantDesktopNotificationPermission(JSValueToStringCopy(context, arguments[0], NULL));
503         
504     return JSValueMakeUndefined(context);
505 }
506
507 static JSValueRef isCommandEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
508 {
509     // Has Mac implementation.
510
511     if (argumentCount < 1)
512         return JSValueMakeUndefined(context);
513
514     JSRetainPtr<JSStringRef> name(Adopt, JSValueToStringCopy(context, arguments[0], exception));
515     ASSERT(!*exception);
516
517     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
518
519     return JSValueMakeBoolean(context, controller->isCommandEnabled(name.get()));
520 }
521
522 static JSValueRef overridePreferenceCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
523 {
524     if (argumentCount < 2)
525         return JSValueMakeUndefined(context);
526
527     JSRetainPtr<JSStringRef> key(Adopt, JSValueToStringCopy(context, arguments[0], exception));
528     ASSERT(!*exception);
529     JSRetainPtr<JSStringRef> value(Adopt, JSValueToStringCopy(context, arguments[1], exception));
530     ASSERT(!*exception);
531
532     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
533     controller->overridePreference(key.get(), value.get());
534
535     return JSValueMakeUndefined(context);
536 }
537
538 static JSValueRef keepWebHistoryCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
539 {
540     // Has mac implementation
541     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
542     controller->keepWebHistory();
543
544     return JSValueMakeUndefined(context);
545 }
546
547 static JSValueRef computedStyleIncludingVisitedInfoCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
548 {
549     if (argumentCount != 1)
550         return JSValueMakeUndefined(context);
551     
552     // Has mac implementation
553     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
554     return controller->computedStyleIncludingVisitedInfo(context, arguments[0]);
555 }
556
557 static JSValueRef nodesFromRectCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
558 {
559     if (argumentCount != 8)
560         return JSValueMakeUndefined(context);
561
562     int x = JSValueToNumber(context, arguments[1], NULL);
563     int y = JSValueToNumber(context, arguments[2], NULL);
564     int top = static_cast<unsigned>(JSValueToNumber(context, arguments[3], NULL));
565     int right = static_cast<unsigned>(JSValueToNumber(context, arguments[4], NULL));
566     int bottom = static_cast<unsigned>(JSValueToNumber(context, arguments[5], NULL));
567     int left = static_cast<unsigned>(JSValueToNumber(context, arguments[6], NULL));
568     bool ignoreClipping = JSValueToBoolean(context, arguments[7]);
569
570     // Has mac implementation.
571     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
572     return controller->nodesFromRect(context, arguments[0], x, y, top, right, bottom, left, ignoreClipping);
573 }
574
575 static JSValueRef layerTreeAsTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
576 {
577     // Has mac & windows implementation
578     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
579     return JSValueMakeString(context, controller->layerTreeAsText().get());
580 }
581
582 static JSValueRef notifyDoneCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
583 {
584     // Has mac & windows implementation
585     // May be able to be made platform independant by using shared WorkQueue
586     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
587     controller->notifyDone();
588     return JSValueMakeUndefined(context);
589 }
590
591 static bool parsePageParameters(JSContextRef context, int argumentCount, const JSValueRef* arguments, JSValueRef* exception, float& pageWidthInPixels, float& pageHeightInPixels)
592 {
593     pageWidthInPixels = LayoutTestController::maxViewWidth;
594     pageHeightInPixels = LayoutTestController::maxViewHeight;
595     switch (argumentCount) {
596     case 2:
597         pageWidthInPixels = static_cast<float>(JSValueToNumber(context, arguments[0], exception));
598         if (*exception)
599             return false;
600         pageHeightInPixels = static_cast<float>(JSValueToNumber(context, arguments[1], exception));
601         if (*exception)
602             return false;
603     case 0: // Fall through.
604         break;
605     default:
606         return false;
607     }
608     return true;
609 }
610
611 // Caller needs to delete[] propertyName.
612 static bool parsePagePropertyParameters(JSContextRef context, int argumentCount, const JSValueRef* arguments, JSValueRef* exception, char*& propertyName, int& pageNumber)
613 {
614     pageNumber = 0;
615     switch (argumentCount) {
616     case 2:
617         pageNumber = static_cast<float>(JSValueToNumber(context, arguments[1], exception));
618         if (*exception)
619             return false;
620         // Fall through.
621     case 1: {
622         JSRetainPtr<JSStringRef> propertyNameString(Adopt, JSValueToStringCopy(context, arguments[0], exception));
623         if (*exception)
624             return false;
625
626         size_t maxLength = JSStringGetMaximumUTF8CStringSize(propertyNameString.get());
627         propertyName = new char[maxLength + 1];
628         JSStringGetUTF8CString(propertyNameString.get(), propertyName, maxLength + 1);
629         return true;
630     }
631     case 0:
632     default:
633         return false;
634     }
635 }
636
637 static bool parsePageNumber(JSContextRef context, int argumentCount, const JSValueRef* arguments, JSValueRef* exception, int& pageNumber)
638 {
639     pageNumber = 0;
640     switch (argumentCount) {
641     case 1:
642         pageNumber = static_cast<int>(JSValueToNumber(context, arguments[0], exception));
643         if (*exception)
644             return false;
645         // Fall through.
646     case 0:
647         return true;
648     default:
649         return false;
650     }
651 }
652
653 static bool parsePageNumberSizeMarings(JSContextRef context, int argumentCount, const JSValueRef* arguments, JSValueRef* exception, int& pageNumber, int& width, int& height, int& marginTop, int& marginRight, int& marginBottom, int& marginLeft)
654 {
655     pageNumber = 0;
656     width = height = 0;
657     marginTop = marginRight = marginBottom = marginLeft = 0;
658
659     switch (argumentCount) {
660     case 7:
661         marginLeft = static_cast<int>(JSValueToNumber(context, arguments[6], exception));
662         if (*exception)
663             return false;
664         // Fall through.
665     case 6:
666         marginBottom = static_cast<int>(JSValueToNumber(context, arguments[5], exception));
667         if (*exception)
668             return false;
669         // Fall through.
670     case 5:
671         marginRight = static_cast<int>(JSValueToNumber(context, arguments[4], exception));
672         if (*exception)
673             return false;
674         // Fall through.
675     case 4:
676         marginTop = static_cast<int>(JSValueToNumber(context, arguments[3], exception));
677         if (*exception)
678             return false;
679         // Fall through.
680     case 3:
681         height = static_cast<int>(JSValueToNumber(context, arguments[2], exception));
682         if (*exception)
683             return false;
684         // Fall through.
685     case 2:
686         width = static_cast<int>(JSValueToNumber(context, arguments[1], exception));
687         if (*exception)
688             return false;
689         // Fall through.
690     case 1:
691         pageNumber = static_cast<int>(JSValueToNumber(context, arguments[0], exception));
692         if (*exception)
693             return false;
694         // Fall through.
695         return true;
696     default:
697         return false;
698     }
699 }
700
701 static JSValueRef pageNumberForElementByIdCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
702 {
703     float pageWidthInPixels = 0;
704     float pageHeightInPixels = 0;
705     if (!parsePageParameters(context, argumentCount - 1, arguments + 1, exception, pageWidthInPixels, pageHeightInPixels))
706         return JSValueMakeUndefined(context);
707
708     JSRetainPtr<JSStringRef> elementId(Adopt, JSValueToStringCopy(context, arguments[0], exception));
709     if (*exception)
710         return JSValueMakeUndefined(context);
711
712     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
713     int pageNumber = controller->pageNumberForElementById(elementId.get(), pageWidthInPixels, pageHeightInPixels);
714     return JSValueMakeNumber(context, pageNumber);
715 }
716
717 static JSValueRef numberOfPagesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
718 {
719     float pageWidthInPixels = 0;
720     float pageHeightInPixels = 0;
721     if (!parsePageParameters(context, argumentCount, arguments, exception, pageWidthInPixels, pageHeightInPixels))
722         return JSValueMakeUndefined(context);
723
724     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
725     return JSValueMakeNumber(context, controller->numberOfPages(pageWidthInPixels, pageHeightInPixels));
726 }
727
728 static JSValueRef pagePropertyCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
729 {
730     char* propertyName = 0;
731     int pageNumber = 0;
732     if (!parsePagePropertyParameters(context, argumentCount, arguments, exception, propertyName, pageNumber))
733         return JSValueMakeUndefined(context);
734
735     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
736     JSValueRef value = JSValueMakeString(context, controller->pageProperty(propertyName, pageNumber).get());
737
738     delete[] propertyName;
739     return value;
740 }
741
742 static JSValueRef isPageBoxVisibleCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
743 {
744     int pageNumber = 0;
745     if (!parsePageNumber(context, argumentCount, arguments, exception, pageNumber))
746         return JSValueMakeUndefined(context);
747
748     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
749     return JSValueMakeBoolean(context, controller->isPageBoxVisible(pageNumber));
750 }
751
752 static JSValueRef pageSizeAndMarginsInPixelsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
753 {
754     int pageNumber = 0;
755     int width = 0, height = 0;
756     int marginTop = 0, marginRight = 0, marginBottom = 0, marginLeft = 0;
757     if (!parsePageNumberSizeMarings(context, argumentCount, arguments, exception, pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft))
758         return JSValueMakeUndefined(context);
759
760     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
761     return JSValueMakeString(context, controller->pageSizeAndMarginsInPixels(pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft).get());
762 }
763
764 static JSValueRef queueBackNavigationCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
765 {
766     // Has mac & windows implementation
767     // May be able to be made platform independant by using shared WorkQueue
768     if (argumentCount < 1)
769         return JSValueMakeUndefined(context);
770
771     double howFarBackDouble = JSValueToNumber(context, arguments[0], exception);
772     ASSERT(!*exception);
773
774     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
775     controller->queueBackNavigation(static_cast<int>(howFarBackDouble));
776
777     return JSValueMakeUndefined(context);
778 }
779
780 static JSValueRef queueForwardNavigationCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
781 {
782     // Has mac & windows implementation
783     // May be able to be made platform independant by using shared WorkQueue
784     if (argumentCount < 1)
785         return JSValueMakeUndefined(context);
786
787     double howFarForwardDouble = JSValueToNumber(context, arguments[0], exception);
788     ASSERT(!*exception);
789
790     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
791     controller->queueForwardNavigation(static_cast<int>(howFarForwardDouble));
792
793     return JSValueMakeUndefined(context);
794 }
795
796 static JSValueRef queueLoadCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
797 {
798     // Has mac & windows implementation
799     // May be able to be made platform independant by using shared WorkQueue
800     if (argumentCount < 1)
801         return JSValueMakeUndefined(context);
802
803     JSRetainPtr<JSStringRef> url(Adopt, JSValueToStringCopy(context, arguments[0], exception));
804     ASSERT(!*exception);
805
806     JSRetainPtr<JSStringRef> target;
807     if (argumentCount >= 2) {
808         target.adopt(JSValueToStringCopy(context, arguments[1], exception));
809         ASSERT(!*exception);
810     } else
811         target.adopt(JSStringCreateWithUTF8CString(""));
812
813     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
814     controller->queueLoad(url.get(), target.get());
815
816     return JSValueMakeUndefined(context);
817 }
818
819 static JSValueRef queueLoadHTMLStringCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
820 {
821     // Has Mac & Windows implementation
822     if (argumentCount < 1)
823         return JSValueMakeUndefined(context);
824
825     JSRetainPtr<JSStringRef> content(Adopt, JSValueToStringCopy(context, arguments[0], exception));
826     ASSERT(!*exception);
827
828     JSRetainPtr<JSStringRef> baseURL;
829     if (argumentCount >= 2) {
830         baseURL.adopt(JSValueToStringCopy(context, arguments[1], exception));
831         ASSERT(!*exception);
832     } else
833         baseURL.adopt(JSStringCreateWithUTF8CString(""));
834
835     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
836     controller->queueLoadHTMLString(content.get(), baseURL.get());
837
838     return JSValueMakeUndefined(context);
839 }
840
841 static JSValueRef queueReloadCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
842 {
843     // Has mac & windows implementation
844     // May be able to be made platform independant by using shared WorkQueue
845
846     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
847     controller->queueReload();
848
849     return JSValueMakeUndefined(context);
850 }
851
852 static JSValueRef queueLoadingScriptCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
853 {
854     // Has mac & windows implementation
855     // May be able to be made platform independant by using shared WorkQueue
856     if (argumentCount < 1)
857         return JSValueMakeUndefined(context);
858
859     JSRetainPtr<JSStringRef> script(Adopt, JSValueToStringCopy(context, arguments[0], exception));
860     ASSERT(!*exception);
861
862     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
863     controller->queueLoadingScript(script.get());
864
865     return JSValueMakeUndefined(context);
866 }
867
868 static JSValueRef queueNonLoadingScriptCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
869 {
870     // Has mac & windows implementation
871     // May be able to be made platform independant by using shared WorkQueue
872     if (argumentCount < 1)
873         return JSValueMakeUndefined(context);
874
875     JSRetainPtr<JSStringRef> script(Adopt, JSValueToStringCopy(context, arguments[0], exception));
876     ASSERT(!*exception);
877
878     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
879     controller->queueNonLoadingScript(script.get());
880
881     return JSValueMakeUndefined(context);
882 }
883
884 static JSValueRef setAcceptsEditingCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
885 {
886     // Has mac & windows implementation
887     if (argumentCount < 1)
888         return JSValueMakeUndefined(context);
889
890     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
891     controller->setAcceptsEditing(JSValueToBoolean(context, arguments[0]));
892
893     return JSValueMakeUndefined(context);
894 }
895
896 static JSValueRef setAlwaysAcceptCookiesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
897 {
898     // Has mac & windows implementation
899     if (argumentCount < 1)
900         return JSValueMakeUndefined(context);
901
902     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
903     controller->setAlwaysAcceptCookies(JSValueToBoolean(context, arguments[0]));
904
905     return JSValueMakeUndefined(context);
906 }
907
908 static JSValueRef setAppCacheMaximumSizeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
909 {
910     // Has mac implementation
911     if (argumentCount < 1)
912         return JSValueMakeUndefined(context);
913
914     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
915
916     double size = JSValueToNumber(context, arguments[0], NULL);
917     if (!isnan(size))
918         controller->setAppCacheMaximumSize(static_cast<unsigned long long>(size));
919         
920     return JSValueMakeUndefined(context);
921 }
922
923 static JSValueRef setApplicationCacheOriginQuotaCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
924 {
925     // Has mac implementation
926     if (argumentCount < 1)
927         return JSValueMakeUndefined(context);
928
929     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
930
931     double size = JSValueToNumber(context, arguments[0], NULL);
932     if (!isnan(size))
933         controller->setApplicationCacheOriginQuota(static_cast<unsigned long long>(size));
934
935     return JSValueMakeUndefined(context);
936 }
937
938 static JSValueRef setAuthenticationPasswordCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
939 {
940     // Has mac & windows implementation
941     if (argumentCount < 1)
942         return JSValueMakeUndefined(context);
943
944     JSRetainPtr<JSStringRef> password(Adopt, JSValueToStringCopy(context, arguments[0], exception));
945     ASSERT(!*exception);
946
947     size_t maxLength = JSStringGetMaximumUTF8CStringSize(password.get());
948     char* passwordBuffer = new char[maxLength + 1];
949     JSStringGetUTF8CString(password.get(), passwordBuffer, maxLength + 1);
950     
951     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
952     controller->setAuthenticationPassword(passwordBuffer);
953     delete[] passwordBuffer;
954
955     return JSValueMakeUndefined(context);
956 }
957
958 static JSValueRef setAuthenticationUsernameCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
959 {
960     // Has mac & windows implementation
961     if (argumentCount < 1)
962         return JSValueMakeUndefined(context);
963
964     JSRetainPtr<JSStringRef> username(Adopt, JSValueToStringCopy(context, arguments[0], exception));
965     ASSERT(!*exception);
966
967     size_t maxLength = JSStringGetMaximumUTF8CStringSize(username.get());
968     char* usernameBuffer = new char[maxLength + 1];
969     JSStringGetUTF8CString(username.get(), usernameBuffer, maxLength + 1);
970     
971     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
972     controller->setAuthenticationUsername(usernameBuffer);
973     delete[] usernameBuffer;
974
975     return JSValueMakeUndefined(context);
976 }
977
978 static JSValueRef setAuthorAndUserStylesEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
979 {
980     // Has mac & windows implementation
981     if (argumentCount < 1)
982         return JSValueMakeUndefined(context);
983
984     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
985     controller->setAuthorAndUserStylesEnabled(JSValueToBoolean(context, arguments[0]));
986
987     return JSValueMakeUndefined(context);
988 }
989
990 static JSValueRef setCacheModelCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
991 {
992     // Has Mac implementation.
993     if (argumentCount < 1)
994         return JSValueMakeUndefined(context);
995
996     int cacheModel = JSValueToNumber(context, arguments[0], exception);
997     ASSERT(!*exception);
998
999     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1000     controller->setCacheModel(cacheModel);
1001
1002     return JSValueMakeUndefined(context);
1003 }
1004
1005 static JSValueRef setCustomPolicyDelegateCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1006 {
1007     // Has mac implementation
1008     if (argumentCount < 1)
1009         return JSValueMakeUndefined(context);
1010     
1011     bool permissive = false;
1012     if (argumentCount >= 2)
1013         permissive = JSValueToBoolean(context, arguments[1]);
1014
1015     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1016     controller->setCustomPolicyDelegate(JSValueToBoolean(context, arguments[0]), permissive);
1017
1018     return JSValueMakeUndefined(context);
1019 }
1020
1021 static JSValueRef setDatabaseQuotaCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1022 {
1023     // Has mac implementation
1024     if (argumentCount < 1)
1025         return JSValueMakeUndefined(context);
1026
1027     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1028
1029     double quota = JSValueToNumber(context, arguments[0], NULL);
1030     if (!isnan(quota))
1031         controller->setDatabaseQuota(static_cast<unsigned long long>(quota));
1032         
1033     return JSValueMakeUndefined(context);
1034 }
1035
1036 static JSValueRef setDeferMainResourceDataLoadCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1037 {
1038     // Has Mac and Windows implementation
1039     if (argumentCount < 1)
1040         return JSValueMakeUndefined(context);
1041
1042     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1043     controller->setDeferMainResourceDataLoad(JSValueToBoolean(context, arguments[0]));
1044
1045     return JSValueMakeUndefined(context);
1046 }
1047
1048 static JSValueRef setDomainRelaxationForbiddenForURLSchemeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1049 {
1050     // Has Mac and Windows implementation
1051     if (argumentCount < 2)
1052         return JSValueMakeUndefined(context);
1053
1054     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1055
1056     bool forbidden = JSValueToBoolean(context, arguments[0]);
1057     JSRetainPtr<JSStringRef> scheme(Adopt, JSValueToStringCopy(context, arguments[1], 0));
1058     controller->setDomainRelaxationForbiddenForURLScheme(forbidden, scheme.get());
1059
1060     return JSValueMakeUndefined(context);
1061 }
1062
1063 static JSValueRef setMockDeviceOrientationCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1064 {
1065     if (argumentCount < 6)
1066         return JSValueMakeUndefined(context);
1067
1068     bool canProvideAlpha = JSValueToBoolean(context, arguments[0]);
1069     double alpha = JSValueToNumber(context, arguments[1], exception);
1070     ASSERT(!*exception);
1071     bool canProvideBeta = JSValueToBoolean(context, arguments[2]);
1072     double beta = JSValueToNumber(context, arguments[3], exception);
1073     ASSERT(!*exception);
1074     bool canProvideGamma = JSValueToBoolean(context, arguments[4]);
1075     double gamma = JSValueToNumber(context, arguments[5], exception);
1076     ASSERT(!*exception);
1077
1078     LayoutTestController* controller = reinterpret_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1079     controller->setMockDeviceOrientation(canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma);
1080
1081     return JSValueMakeUndefined(context);
1082 }
1083
1084 static JSValueRef setMockGeolocationPositionCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1085 {
1086     if (argumentCount < 3)
1087         return JSValueMakeUndefined(context);
1088
1089     LayoutTestController* controller = reinterpret_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1090     controller->setMockGeolocationPosition(JSValueToNumber(context, arguments[0], NULL),  // latitude
1091                                            JSValueToNumber(context, arguments[1], NULL),  // longitude
1092                                            JSValueToNumber(context, arguments[2], NULL));  // accuracy
1093
1094     return JSValueMakeUndefined(context);
1095 }
1096
1097 static JSValueRef setMockGeolocationErrorCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1098 {
1099     if (argumentCount < 2)
1100         return JSValueMakeUndefined(context);
1101
1102     int code = JSValueToNumber(context, arguments[0], NULL);
1103     JSRetainPtr<JSStringRef> message(Adopt, JSValueToStringCopy(context, arguments[1], exception));
1104     ASSERT(!*exception);
1105
1106     LayoutTestController* controller = reinterpret_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1107     controller->setMockGeolocationError(code, message.get());
1108
1109     return JSValueMakeUndefined(context);
1110 }
1111
1112 static JSValueRef addMockSpeechInputResultCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1113 {
1114     if (argumentCount < 3)
1115         return JSValueMakeUndefined(context);
1116
1117     JSRetainPtr<JSStringRef> result(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1118     ASSERT(!*exception);
1119
1120     double confidence = JSValueToNumber(context, arguments[1], exception);
1121
1122     JSRetainPtr<JSStringRef> language(Adopt, JSValueToStringCopy(context, arguments[2], exception));
1123     ASSERT(!*exception);
1124
1125     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1126     controller->addMockSpeechInputResult(result.get(), confidence, language.get());
1127
1128     return JSValueMakeUndefined(context);
1129 }
1130
1131 static JSValueRef setNewWindowsCopyBackForwardListCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1132 {
1133     // Has mac implementation
1134     if (argumentCount < 1)
1135         return JSValueMakeUndefined(context);
1136     
1137     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1138     controller->setNewWindowsCopyBackForwardList(JSValueToBoolean(context, arguments[0]));
1139
1140     return JSValueMakeUndefined(context);
1141 }
1142
1143 static JSValueRef setGeolocationPermissionCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1144 {
1145     // Has mac implementation
1146     if (argumentCount < 1)
1147         return JSValueMakeUndefined(context);
1148
1149     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1150     controller->setGeolocationPermission(JSValueToBoolean(context, arguments[0]));
1151
1152     return JSValueMakeUndefined(context);
1153 }
1154
1155 static JSValueRef setHandlesAuthenticationChallengesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1156 {
1157     // Has mac & windows implementation
1158     if (argumentCount < 1)
1159         return JSValueMakeUndefined(context);
1160
1161     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1162     controller->setHandlesAuthenticationChallenges(JSValueToBoolean(context, arguments[0]));
1163
1164     return JSValueMakeUndefined(context);
1165 }
1166
1167 static JSValueRef setPOSIXLocaleCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1168 {
1169     if (argumentCount < 1)
1170         return JSValueMakeUndefined(context);
1171
1172     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1173     JSRetainPtr<JSStringRef> locale(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1174     ASSERT(!*exception);
1175     controller->setPOSIXLocale(locale.get());
1176
1177     return JSValueMakeUndefined(context);
1178 }
1179
1180 static JSValueRef setIconDatabaseEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1181 {
1182     // Has mac & windows implementation
1183     if (argumentCount < 1)
1184         return JSValueMakeUndefined(context);
1185
1186     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1187     controller->setIconDatabaseEnabled(JSValueToBoolean(context, arguments[0]));
1188
1189     return JSValueMakeUndefined(context);
1190 }
1191
1192 static JSValueRef setJavaScriptProfilingEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1193 {
1194     if (argumentCount < 1)
1195         return JSValueMakeUndefined(context);
1196
1197     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1198     controller->setJavaScriptProfilingEnabled(JSValueToBoolean(context, arguments[0]));
1199
1200     return JSValueMakeUndefined(context);
1201 }
1202
1203 static JSValueRef setMainFrameIsFirstResponderCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1204 {
1205     // Has mac implementation
1206     if (argumentCount < 1)
1207         return JSValueMakeUndefined(context);
1208
1209     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1210     controller->setMainFrameIsFirstResponder(JSValueToBoolean(context, arguments[0]));
1211
1212     return JSValueMakeUndefined(context);
1213 }
1214
1215 static JSValueRef setPersistentUserStyleSheetLocationCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1216 {
1217     // Has mac implementation
1218     if (argumentCount < 1)
1219         return JSValueMakeUndefined(context);
1220
1221     JSRetainPtr<JSStringRef> path(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1222     ASSERT(!*exception);
1223
1224     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1225     controller->setPersistentUserStyleSheetLocation(path.get());
1226
1227     return JSValueMakeUndefined(context);
1228 }
1229
1230 static JSValueRef setPrivateBrowsingEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1231 {
1232     // Has mac & windows implementation
1233     if (argumentCount < 1)
1234         return JSValueMakeUndefined(context);
1235
1236     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1237     controller->setPrivateBrowsingEnabled(JSValueToBoolean(context, arguments[0]));
1238
1239     return JSValueMakeUndefined(context);
1240 }
1241
1242 static JSValueRef setJavaScriptCanAccessClipboardCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1243 {
1244     // Has mac & windows implementation
1245     if (argumentCount < 1)
1246         return JSValueMakeUndefined(context);
1247
1248     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1249     controller->setJavaScriptCanAccessClipboard(JSValueToBoolean(context, arguments[0]));
1250
1251     return JSValueMakeUndefined(context);
1252 }
1253
1254 static JSValueRef setXSSAuditorEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1255 {
1256     // Has mac & windows implementation
1257     if (argumentCount < 1)
1258         return JSValueMakeUndefined(context);
1259
1260     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1261     controller->setXSSAuditorEnabled(JSValueToBoolean(context, arguments[0]));
1262
1263     return JSValueMakeUndefined(context);
1264 }
1265
1266 static JSValueRef setSpatialNavigationEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1267 {
1268     // Has mac implementation.
1269     if (argumentCount < 1)
1270         return JSValueMakeUndefined(context);
1271
1272     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1273     controller->setSpatialNavigationEnabled(JSValueToBoolean(context, arguments[0]));
1274
1275     return JSValueMakeUndefined(context);
1276 }
1277
1278 static JSValueRef setPrintingCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1279 {
1280     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1281     controller->setIsPrinting(true);
1282     return JSValueMakeUndefined(context);
1283 }
1284
1285
1286 static JSValueRef setFrameFlatteningEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1287 {
1288     // Has mac & windows implementation
1289     if (argumentCount < 1)
1290         return JSValueMakeUndefined(context);
1291
1292     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1293     controller->setFrameFlatteningEnabled(JSValueToBoolean(context, arguments[0]));
1294
1295     return JSValueMakeUndefined(context);
1296 }
1297
1298 static JSValueRef setAllowUniversalAccessFromFileURLsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1299 {
1300     // Has mac & windows implementation
1301     if (argumentCount < 1)
1302         return JSValueMakeUndefined(context);
1303
1304     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1305     controller->setAllowUniversalAccessFromFileURLs(JSValueToBoolean(context, arguments[0]));
1306
1307     return JSValueMakeUndefined(context);
1308 }
1309
1310 static JSValueRef setAllowFileAccessFromFileURLsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1311 {
1312     // Has mac & windows implementation
1313     if (argumentCount < 1)
1314         return JSValueMakeUndefined(context);
1315
1316     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1317     controller->setAllowFileAccessFromFileURLs(JSValueToBoolean(context, arguments[0]));
1318
1319     return JSValueMakeUndefined(context);
1320 }
1321
1322 static JSValueRef setTabKeyCyclesThroughElementsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1323 {
1324     // Has mac & windows implementation
1325     if (argumentCount < 1)
1326         return JSValueMakeUndefined(context);
1327
1328     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1329     controller->setTabKeyCyclesThroughElements(JSValueToBoolean(context, arguments[0]));
1330
1331     return JSValueMakeUndefined(context);
1332 }
1333
1334 static JSValueRef setTimelineProfilingEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1335 {
1336     if (argumentCount < 1)
1337         return JSValueMakeUndefined(context);
1338
1339     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1340     controller->setTimelineProfilingEnabled(JSValueToBoolean(context, arguments[0]));
1341     return JSValueMakeUndefined(context);
1342 }
1343
1344 static JSValueRef setUseDashboardCompatibilityModeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1345 {
1346     // Has mac implementation
1347     if (argumentCount < 1)
1348         return JSValueMakeUndefined(context);
1349
1350     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1351     controller->setUseDashboardCompatibilityMode(JSValueToBoolean(context, arguments[0]));
1352
1353     return JSValueMakeUndefined(context);
1354 }
1355
1356 static JSValueRef setUserStyleSheetEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1357 {
1358     // Has mac implementation
1359     if (argumentCount < 1)
1360         return JSValueMakeUndefined(context);
1361
1362     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1363     controller->setUserStyleSheetEnabled(JSValueToBoolean(context, arguments[0]));
1364
1365     return JSValueMakeUndefined(context);
1366 }
1367
1368 static JSValueRef setUserStyleSheetLocationCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1369 {
1370     // Has mac implementation
1371     if (argumentCount < 1)
1372         return JSValueMakeUndefined(context);
1373
1374     JSRetainPtr<JSStringRef> path(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1375     ASSERT(!*exception);
1376
1377     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1378     controller->setUserStyleSheetLocation(path.get());
1379
1380     return JSValueMakeUndefined(context);
1381 }
1382
1383 static JSValueRef setViewModeMediaFeatureCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1384 {
1385     // Has mac implementation
1386     if (argumentCount < 1)
1387         return JSValueMakeUndefined(context);
1388
1389     JSRetainPtr<JSStringRef> mode(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1390     ASSERT(!*exception);
1391
1392     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1393     controller->setViewModeMediaFeature(mode.get());
1394
1395     return JSValueMakeUndefined(context);
1396 }
1397
1398 static JSValueRef setWillSendRequestClearHeaderCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1399 {
1400     // Has mac & windows implementation
1401     if (argumentCount < 1)
1402         return JSValueMakeUndefined(context);
1403
1404     JSRetainPtr<JSStringRef> header(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1405     ASSERT(!*exception);
1406
1407     size_t maxLength = JSStringGetMaximumUTF8CStringSize(header.get());
1408     char* headerBuffer = new char[maxLength + 1];
1409     JSStringGetUTF8CString(header.get(), headerBuffer, maxLength + 1);
1410
1411     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1412     controller->setWillSendRequestClearHeader(headerBuffer);
1413
1414     return JSValueMakeUndefined(context);
1415 }
1416
1417 static JSValueRef setWillSendRequestReturnsNullCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1418 {
1419     // Has cross-platform implementation
1420     if (argumentCount < 1)
1421         return JSValueMakeUndefined(context);
1422
1423     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1424     controller->setWillSendRequestReturnsNull(JSValueToBoolean(context, arguments[0]));
1425
1426     return JSValueMakeUndefined(context);
1427 }
1428
1429 static JSValueRef setWillSendRequestReturnsNullOnRedirectCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1430 {
1431     // Has cross-platform implementation
1432     if (argumentCount < 1)
1433         return JSValueMakeUndefined(context);
1434
1435     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1436     controller->setWillSendRequestReturnsNullOnRedirect(JSValueToBoolean(context, arguments[0]));
1437
1438     return JSValueMakeUndefined(context);
1439 }
1440
1441 static JSValueRef setWindowIsKeyCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1442 {
1443     // Has mac implementation
1444     if (argumentCount < 1)
1445         return JSValueMakeUndefined(context);
1446
1447     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1448     controller->setWindowIsKey(JSValueToBoolean(context, arguments[0]));
1449
1450     return JSValueMakeUndefined(context);
1451 }
1452
1453 static JSValueRef waitUntilDoneCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1454 {
1455     // Has mac & windows implementation
1456     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1457     controller->setWaitToDump(true);
1458
1459     return JSValueMakeUndefined(context);
1460 }
1461
1462 static JSValueRef windowCountCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1463 {
1464     // Has mac implementation
1465     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1466     int windows = controller->windowCount();
1467     return JSValueMakeNumber(context, windows);
1468 }
1469
1470 static JSValueRef setPopupBlockingEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1471 {
1472     // Has mac & windows implementation
1473     if (argumentCount < 1)
1474         return JSValueMakeUndefined(context);
1475
1476     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1477     controller->setPopupBlockingEnabled(JSValueToBoolean(context, arguments[0]));
1478
1479     return JSValueMakeUndefined(context);
1480 }
1481
1482 static JSValueRef setPluginsEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1483 {
1484     // Has mac & windows implementation
1485     if (argumentCount < 1)
1486         return JSValueMakeUndefined(context);
1487     
1488     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1489     controller->setPluginsEnabled(JSValueToBoolean(context, arguments[0]));
1490     
1491     return JSValueMakeUndefined(context);
1492 }    
1493
1494 static JSValueRef setSmartInsertDeleteEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1495 {
1496     if (argumentCount < 1)
1497         return JSValueMakeUndefined(context);
1498
1499     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1500     controller->setSmartInsertDeleteEnabled(JSValueToBoolean(context, arguments[0]));
1501     return JSValueMakeUndefined(context);
1502 }
1503
1504 static JSValueRef setSelectTrailingWhitespaceEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1505 {
1506     if (argumentCount < 1)
1507         return JSValueMakeUndefined(context);
1508
1509     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1510     controller->setSelectTrailingWhitespaceEnabled(JSValueToBoolean(context, arguments[0]));
1511     return JSValueMakeUndefined(context);
1512 }
1513
1514 static JSValueRef setStopProvisionalFrameLoadsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1515 {
1516     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1517     controller->setStopProvisionalFrameLoads(true);
1518     return JSValueMakeUndefined(context);
1519 }
1520
1521 static JSValueRef setAsynchronousSpellCheckingEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1522 {
1523     if (argumentCount < 1)
1524         return JSValueMakeUndefined(context);
1525
1526     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1527     controller->setAsynchronousSpellCheckingEnabled(JSValueToBoolean(context, arguments[0]));
1528     return JSValueMakeUndefined(context);
1529 }
1530
1531 static JSValueRef showWebInspectorCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1532 {
1533     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1534     controller->showWebInspector();
1535     return JSValueMakeUndefined(context);
1536 }
1537
1538 static JSValueRef closeWebInspectorCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1539 {
1540     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1541     controller->setTimelineProfilingEnabled(false);
1542     controller->closeWebInspector();
1543     return JSValueMakeUndefined(context);
1544 }
1545
1546 static JSValueRef evaluateInWebInspectorCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1547 {
1548     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1549     double callId = JSValueToNumber(context, arguments[0], exception);
1550     ASSERT(!*exception);
1551     JSRetainPtr<JSStringRef> script(Adopt, JSValueToStringCopy(context, arguments[1], exception));
1552     ASSERT(!*exception);
1553
1554     controller->evaluateInWebInspector(static_cast<long>(callId), script.get());
1555     return JSValueMakeUndefined(context);
1556 }
1557
1558 static JSValueRef evaluateScriptInIsolatedWorldCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1559 {
1560     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1561     double worldID = JSValueToNumber(context, arguments[0], exception);
1562     ASSERT(!*exception);
1563     JSRetainPtr<JSStringRef> script(Adopt, JSValueToStringCopy(context, arguments[1], exception));
1564     ASSERT(!*exception);
1565
1566     controller->evaluateScriptInIsolatedWorld(static_cast<unsigned>(worldID), JSContextGetGlobalObject(context), script.get());
1567     return JSValueMakeUndefined(context);
1568 }
1569
1570 static JSValueRef elementDoesAutoCompleteForElementWithIdCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1571 {
1572     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1573     JSRetainPtr<JSStringRef> elementId(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1574     ASSERT(!*exception);
1575
1576     bool autoCompletes = controller->elementDoesAutoCompleteForElementWithId(elementId.get());
1577
1578     return JSValueMakeBoolean(context, autoCompletes);
1579 }
1580
1581 static JSValueRef pauseAnimationAtTimeOnElementWithIdCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1582 {
1583     if (argumentCount != 3)
1584         return JSValueMakeUndefined(context);
1585
1586     JSRetainPtr<JSStringRef> animationName(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1587     ASSERT(!*exception);
1588     double time = JSValueToNumber(context, arguments[1], exception);
1589     ASSERT(!*exception);
1590     JSRetainPtr<JSStringRef> elementId(Adopt, JSValueToStringCopy(context, arguments[2], exception));
1591     ASSERT(!*exception);
1592
1593     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1594     return JSValueMakeBoolean(context, controller->pauseAnimationAtTimeOnElementWithId(animationName.get(), time, elementId.get()));
1595 }
1596
1597 static JSValueRef pauseTransitionAtTimeOnElementWithIdCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1598 {
1599     if (argumentCount != 3)
1600         return JSValueMakeUndefined(context);
1601
1602     JSRetainPtr<JSStringRef> propertyName(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1603     ASSERT(!*exception);
1604     double time = JSValueToNumber(context, arguments[1], exception);
1605     ASSERT(!*exception);
1606     JSRetainPtr<JSStringRef> elementId(Adopt, JSValueToStringCopy(context, arguments[2], exception));
1607     ASSERT(!*exception);
1608
1609     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1610     return JSValueMakeBoolean(context, controller->pauseTransitionAtTimeOnElementWithId(propertyName.get(), time, elementId.get()));
1611 }
1612
1613 static JSValueRef sampleSVGAnimationForElementAtTimeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1614 {
1615     if (argumentCount != 3)
1616         return JSValueMakeUndefined(context);
1617
1618     JSRetainPtr<JSStringRef> animationId(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1619     ASSERT(!*exception);
1620     double time = JSValueToNumber(context, arguments[1], exception);
1621     ASSERT(!*exception);
1622     JSRetainPtr<JSStringRef> elementId(Adopt, JSValueToStringCopy(context, arguments[2], exception));
1623     ASSERT(!*exception);
1624
1625     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1626     return JSValueMakeBoolean(context, controller->sampleSVGAnimationForElementAtTime(animationId.get(), time, elementId.get()));
1627 }
1628
1629 static JSValueRef numberOfActiveAnimationsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1630 {
1631     if (argumentCount != 0)
1632         return JSValueMakeUndefined(context);
1633
1634     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1635     return JSValueMakeNumber(context, controller->numberOfActiveAnimations());
1636 }
1637
1638 static JSValueRef suspendAnimationsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1639 {
1640     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1641     controller->suspendAnimations();
1642     return JSValueMakeUndefined(context);
1643 }
1644
1645 static JSValueRef resumeAnimationsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1646 {
1647     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1648     controller->resumeAnimations();
1649     return JSValueMakeUndefined(context);
1650 }
1651
1652 static JSValueRef waitForPolicyDelegateCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t, const JSValueRef[], JSValueRef*)
1653 {
1654     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1655     controller->waitForPolicyDelegate();
1656     return JSValueMakeUndefined(context);
1657 }
1658
1659 static JSValueRef addOriginAccessWhitelistEntryCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1660 {
1661     if (argumentCount != 4)
1662         return JSValueMakeUndefined(context);
1663
1664     JSRetainPtr<JSStringRef> sourceOrigin(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1665     ASSERT(!*exception);
1666     JSRetainPtr<JSStringRef> destinationProtocol(Adopt, JSValueToStringCopy(context, arguments[1], exception));
1667     ASSERT(!*exception);
1668     JSRetainPtr<JSStringRef> destinationHost(Adopt, JSValueToStringCopy(context, arguments[2], exception));
1669     ASSERT(!*exception);
1670     bool allowDestinationSubdomains = JSValueToBoolean(context, arguments[3]);
1671
1672     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1673     controller->addOriginAccessWhitelistEntry(sourceOrigin.get(), destinationProtocol.get(), destinationHost.get(), allowDestinationSubdomains);
1674     return JSValueMakeUndefined(context);
1675 }
1676
1677 static JSValueRef removeOriginAccessWhitelistEntryCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1678 {
1679     if (argumentCount != 4)
1680         return JSValueMakeUndefined(context);
1681
1682     JSRetainPtr<JSStringRef> sourceOrigin(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1683     ASSERT(!*exception);
1684     JSRetainPtr<JSStringRef> destinationProtocol(Adopt, JSValueToStringCopy(context, arguments[1], exception));
1685     ASSERT(!*exception);
1686     JSRetainPtr<JSStringRef> destinationHost(Adopt, JSValueToStringCopy(context, arguments[2], exception));
1687     ASSERT(!*exception);
1688     bool allowDestinationSubdomains = JSValueToBoolean(context, arguments[3]);
1689
1690     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1691     controller->removeOriginAccessWhitelistEntry(sourceOrigin.get(), destinationProtocol.get(), destinationHost.get(), allowDestinationSubdomains);
1692     return JSValueMakeUndefined(context);
1693 }
1694
1695 static JSValueRef setScrollbarPolicyCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1696 {
1697     if (argumentCount != 2)
1698         return JSValueMakeUndefined(context);
1699
1700     JSRetainPtr<JSStringRef> orientation(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1701     ASSERT(!*exception);
1702     JSRetainPtr<JSStringRef> policy(Adopt, JSValueToStringCopy(context, arguments[1], exception));
1703     ASSERT(!*exception);
1704
1705     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1706     controller->setScrollbarPolicy(orientation.get(), policy.get());
1707     return JSValueMakeUndefined(context);
1708 }
1709
1710 static JSValueRef addUserScriptCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1711 {
1712     if (argumentCount != 3)
1713         return JSValueMakeUndefined(context);
1714     
1715     JSRetainPtr<JSStringRef> source(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1716     ASSERT(!*exception);
1717     bool runAtStart = JSValueToBoolean(context, arguments[1]);
1718     bool allFrames = JSValueToBoolean(context, arguments[2]);
1719     
1720     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1721     controller->addUserScript(source.get(), runAtStart, allFrames);
1722     return JSValueMakeUndefined(context);
1723 }
1724  
1725 static JSValueRef addUserStyleSheetCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1726 {
1727     if (argumentCount != 2)
1728         return JSValueMakeUndefined(context);
1729     
1730     JSRetainPtr<JSStringRef> source(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1731     ASSERT(!*exception);
1732     bool allFrames = JSValueToBoolean(context, arguments[1]);
1733    
1734     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1735     controller->addUserStyleSheet(source.get(), allFrames);
1736     return JSValueMakeUndefined(context);
1737 }
1738
1739 static JSValueRef apiTestNewWindowDataLoadBaseURLCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1740 {
1741     if (argumentCount != 2)
1742         return JSValueMakeUndefined(context);
1743
1744     JSRetainPtr<JSStringRef> utf8Data(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1745     ASSERT(!*exception);
1746
1747     JSRetainPtr<JSStringRef> baseURL(Adopt, JSValueToStringCopy(context, arguments[1], exception));
1748     ASSERT(!*exception);
1749         
1750     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1751     controller->apiTestNewWindowDataLoadBaseURL(utf8Data.get(), baseURL.get());
1752     return JSValueMakeUndefined(context);
1753 }
1754
1755 static JSValueRef apiTestGoToCurrentBackForwardItemCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1756 {
1757     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1758     controller->apiTestGoToCurrentBackForwardItem();
1759     return JSValueMakeUndefined(context);
1760 }
1761
1762 static JSValueRef setWebViewEditableCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1763 {
1764     // Has Mac implementation
1765     if (argumentCount < 1)
1766         return JSValueMakeUndefined(context);
1767
1768     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1769     controller->setWebViewEditable(JSValueToBoolean(context, arguments[0]));
1770
1771     return JSValueMakeUndefined(context);
1772 }
1773
1774
1775 static JSValueRef abortModalCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1776 {
1777     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1778     controller->abortModal();
1779     return JSValueMakeUndefined(context);
1780 }
1781
1782 static JSValueRef hasSpellingMarkerCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1783 {
1784     if (argumentCount != 2)
1785         return JSValueMakeUndefined(context);
1786
1787     int from = JSValueToNumber(context, arguments[0], 0);
1788     int length = JSValueToNumber(context, arguments[1], 0);
1789     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1790     bool ok = controller->hasSpellingMarker(from, length);
1791
1792     return JSValueMakeBoolean(context, ok);
1793 }
1794
1795 static JSValueRef markerTextForListItemCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1796 {
1797     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1798     if (argumentCount < 1)
1799         return JSValueMakeUndefined(context);
1800     return JSValueMakeString(context, controller->markerTextForListItem(context, arguments[0]).get());
1801 }
1802
1803 static JSValueRef authenticateSessionCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1804 {
1805     // authenticateSession(url, username, password)
1806     if (argumentCount != 3)
1807         return JSValueMakeUndefined(context);
1808
1809     JSRetainPtr<JSStringRef> url(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1810     ASSERT(!*exception);
1811     JSRetainPtr<JSStringRef> username(Adopt, JSValueToStringCopy(context, arguments[1], exception));
1812     ASSERT(!*exception);
1813     JSRetainPtr<JSStringRef> password(Adopt, JSValueToStringCopy(context, arguments[2], exception));
1814     ASSERT(!*exception);
1815
1816     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1817     controller->authenticateSession(url.get(), username.get(), password.get());
1818     return JSValueMakeUndefined(context);
1819 }
1820
1821 static JSValueRef setEditingBehaviorCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1822 {
1823     // The editing behavior string.
1824     if (argumentCount < 1)
1825         return JSValueMakeUndefined(context);
1826
1827     JSRetainPtr<JSStringRef> editingBehavior(Adopt, JSValueToStringCopy(context, arguments[0], exception));
1828     ASSERT(!*exception);
1829
1830     size_t maxLength = JSStringGetMaximumUTF8CStringSize(editingBehavior.get());
1831     char* behaviorBuffer = new char[maxLength + 1];
1832     JSStringGetUTF8CString(editingBehavior.get(), behaviorBuffer, maxLength);
1833
1834     if (strcmp(behaviorBuffer, "mac") && strcmp(behaviorBuffer, "win") && strcmp(behaviorBuffer, "unix")) {
1835         JSRetainPtr<JSStringRef> invalidArgument(JSStringCreateWithUTF8CString("Passed invalid editing behavior. Must be 'mac', 'win', or 'unix'."));
1836         *exception = JSValueMakeString(context, invalidArgument.get());
1837         return JSValueMakeUndefined(context);
1838     }
1839
1840     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1841     controller->setEditingBehavior(behaviorBuffer);
1842
1843     delete [] behaviorBuffer;
1844
1845     return JSValueMakeUndefined(context);
1846 }
1847
1848 static JSValueRef setSerializeHTTPLoadsCallback(JSContextRef context, JSObjectRef, JSObjectRef, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1849 {
1850     bool serialize = true;
1851     if (argumentCount == 1)
1852         serialize = JSValueToBoolean(context, arguments[0]);
1853
1854     LayoutTestController::setSerializeHTTPLoads(serialize);
1855     return JSValueMakeUndefined(context);
1856 }
1857
1858 // Static Values
1859
1860 static JSValueRef getGlobalFlagCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
1861 {
1862     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1863     return JSValueMakeBoolean(context, controller->globalFlag());
1864 }
1865
1866 static JSValueRef getWebHistoryItemCountCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
1867 {
1868     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1869     return JSValueMakeNumber(context, controller->webHistoryItemCount());
1870 }
1871
1872 static JSValueRef getWorkerThreadCountCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
1873 {
1874     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1875     return JSValueMakeNumber(context, controller->workerThreadCount());
1876 }
1877
1878 static bool setGlobalFlagCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
1879 {
1880     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
1881     controller->setGlobalFlag(JSValueToBoolean(context, value));
1882     return true;
1883 }
1884
1885 static void layoutTestControllerObjectFinalize(JSObjectRef object)
1886 {
1887     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(object));
1888     controller->deref();
1889 }
1890
1891 // Object Creation
1892
1893 void LayoutTestController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
1894 {
1895     JSRetainPtr<JSStringRef> layoutTestContollerStr(Adopt, JSStringCreateWithUTF8CString("layoutTestController"));
1896     ref();
1897
1898     JSClassRef classRef = getJSClass();
1899     JSValueRef layoutTestContollerObject = JSObjectMake(context, classRef, this);
1900     JSClassRelease(classRef);
1901
1902     JSObjectSetProperty(context, windowObject, layoutTestContollerStr.get(), layoutTestContollerObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
1903 }
1904
1905 JSClassRef LayoutTestController::getJSClass()
1906 {
1907     static JSStaticValue* staticValues = LayoutTestController::staticValues();
1908     static JSStaticFunction* staticFunctions = LayoutTestController::staticFunctions();
1909     static JSClassDefinition classDefinition = {
1910         0, kJSClassAttributeNone, "LayoutTestController", 0, staticValues, staticFunctions,
1911         0, layoutTestControllerObjectFinalize, 0, 0, 0, 0, 0, 0, 0, 0, 0
1912     };
1913
1914     return JSClassCreate(&classDefinition);
1915 }
1916
1917 JSStaticValue* LayoutTestController::staticValues()
1918 {
1919     static JSStaticValue staticValues[] = {
1920         { "globalFlag", getGlobalFlagCallback, setGlobalFlagCallback, kJSPropertyAttributeNone },
1921         { "webHistoryItemCount", getWebHistoryItemCountCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1922         { "workerThreadCount", getWorkerThreadCountCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1923         { 0, 0, 0, 0 }
1924     };
1925     return staticValues;
1926 }
1927
1928 JSStaticFunction* LayoutTestController::staticFunctions()
1929 {
1930     static JSStaticFunction staticFunctions[] = {
1931         { "abortModal", abortModalCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1932         { "addDisallowedURL", addDisallowedURLCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1933         { "addUserScript", addUserScriptCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1934         { "addUserStyleSheet", addUserStyleSheetCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1935         { "apiTestNewWindowDataLoadBaseURL", apiTestNewWindowDataLoadBaseURLCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1936         { "apiTestGoToCurrentBackForwardItem", apiTestGoToCurrentBackForwardItemCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1937         { "callShouldCloseOnWebView", callShouldCloseOnWebViewCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1938         { "clearAllApplicationCaches", clearAllApplicationCachesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1939         { "clearAllDatabases", clearAllDatabasesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1940         { "clearBackForwardList", clearBackForwardListCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1941         { "clearPersistentUserStyleSheet", clearPersistentUserStyleSheetCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1942         { "closeWebInspector", closeWebInspectorCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1943         { "computedStyleIncludingVisitedInfo", computedStyleIncludingVisitedInfoCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1944         { "nodesFromRect", nodesFromRectCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1945         { "decodeHostName", decodeHostNameCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1946         { "disableImageLoading", disableImageLoadingCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1947         { "dispatchPendingLoadRequests", dispatchPendingLoadRequestsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1948         { "display", displayCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1949         { "dumpApplicationCacheDelegateCallbacks", dumpApplicationCacheDelegateCallbacksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1950         { "dumpAsText", dumpAsTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1951         { "dumpBackForwardList", dumpBackForwardListCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1952         { "dumpChildFrameScrollPositions", dumpChildFrameScrollPositionsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1953         { "dumpChildFramesAsText", dumpChildFramesAsTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1954         { "dumpConfigurationForViewport", dumpConfigurationForViewportCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1955         { "dumpDOMAsWebArchive", dumpDOMAsWebArchiveCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1956         { "dumpDatabaseCallbacks", dumpDatabaseCallbacksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1957         { "dumpEditingCallbacks", dumpEditingCallbacksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1958         { "dumpFrameLoadCallbacks", dumpFrameLoadCallbacksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1959         { "dumpUserGestureInFrameLoadCallbacks", dumpUserGestureInFrameLoadCallbacksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },        
1960         { "dumpResourceLoadCallbacks", dumpResourceLoadCallbacksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1961         { "dumpResourceResponseMIMETypes", dumpResourceResponseMIMETypesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1962         { "dumpSelectionRect", dumpSelectionRectCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1963         { "dumpSourceAsWebArchive", dumpSourceAsWebArchiveCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1964         { "dumpStatusCallbacks", dumpStatusCallbacksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1965         { "dumpTitleChanges", dumpTitleChangesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1966         { "dumpIconChanges", dumpIconChangesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1967         { "dumpWillCacheResponse", dumpWillCacheResponseCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1968         { "elementDoesAutoCompleteForElementWithId", elementDoesAutoCompleteForElementWithIdCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1969         { "encodeHostName", encodeHostNameCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1970         { "evaluateInWebInspector", evaluateInWebInspectorCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1971         { "evaluateScriptInIsolatedWorld", evaluateScriptInIsolatedWorldCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1972         { "execCommand", execCommandCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1973         { "findString", findStringCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1974         { "counterValueForElementById", counterValueForElementByIdCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1975         { "grantDesktopNotificationPermission", grantDesktopNotificationPermissionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, 
1976         { "hasSpellingMarker", hasSpellingMarkerCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1977         { "isCommandEnabled", isCommandEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1978         { "isPageBoxVisible", isPageBoxVisibleCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1979         { "keepWebHistory", keepWebHistoryCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1980         { "layerTreeAsText", layerTreeAsTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1981         { "numberOfPages", numberOfPagesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1982         { "markerTextForListItem", markerTextForListItemCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1983         { "notifyDone", notifyDoneCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1984         { "numberOfActiveAnimations", numberOfActiveAnimationsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1985         { "suspendAnimations", suspendAnimationsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1986         { "resumeAnimations", resumeAnimationsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1987         { "overridePreference", overridePreferenceCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1988         { "pageNumberForElementById", pageNumberForElementByIdCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1989         { "pageSizeAndMarginsInPixels", pageSizeAndMarginsInPixelsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1990         { "pageProperty", pagePropertyCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1991         { "pathToLocalResource", pathToLocalResourceCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1992         { "pauseAnimationAtTimeOnElementWithId", pauseAnimationAtTimeOnElementWithIdCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1993         { "pauseTransitionAtTimeOnElementWithId", pauseTransitionAtTimeOnElementWithIdCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1994         { "sampleSVGAnimationForElementAtTime", sampleSVGAnimationForElementAtTimeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1995         { "printToPDF", dumpAsPDFCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1996         { "queueBackNavigation", queueBackNavigationCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1997         { "queueForwardNavigation", queueForwardNavigationCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1998         { "queueLoad", queueLoadCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1999         { "queueLoadHTMLString", queueLoadHTMLStringCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2000         { "queueLoadingScript", queueLoadingScriptCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2001         { "queueNonLoadingScript", queueNonLoadingScriptCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2002         { "queueReload", queueReloadCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2003         { "removeAllVisitedLinks", removeAllVisitedLinksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2004         { "removeOriginAccessWhitelistEntry", removeOriginAccessWhitelistEntryCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2005         { "repaintSweepHorizontally", repaintSweepHorizontallyCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2006         { "setAcceptsEditing", setAcceptsEditingCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2007         { "setAllowUniversalAccessFromFileURLs", setAllowUniversalAccessFromFileURLsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2008         { "setAllowFileAccessFromFileURLs", setAllowFileAccessFromFileURLsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2009         { "setAlwaysAcceptCookies", setAlwaysAcceptCookiesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2010         { "setAppCacheMaximumSize", setAppCacheMaximumSizeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2011         { "setApplicationCacheOriginQuota", setApplicationCacheOriginQuotaCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2012         { "setAuthenticationPassword", setAuthenticationPasswordCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2013         { "setAuthenticationUsername", setAuthenticationUsernameCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2014         { "setAuthorAndUserStylesEnabled", setAuthorAndUserStylesEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2015         { "setCacheModel", setCacheModelCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2016         { "setCallCloseOnWebViews", setCallCloseOnWebViewsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2017         { "setCanOpenWindows", setCanOpenWindowsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2018         { "setCloseRemainingWindowsWhenComplete", setCloseRemainingWindowsWhenCompleteCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2019         { "setCustomPolicyDelegate", setCustomPolicyDelegateCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2020         { "setDatabaseQuota", setDatabaseQuotaCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, 
2021         { "setDeferMainResourceDataLoad", setDeferMainResourceDataLoadCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2022         { "setDomainRelaxationForbiddenForURLScheme", setDomainRelaxationForbiddenForURLSchemeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2023         { "setEditingBehavior", setEditingBehaviorCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2024         { "setFrameFlatteningEnabled", setFrameFlatteningEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2025         { "setGeolocationPermission", setGeolocationPermissionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2026         { "setHandlesAuthenticationChallenges", setHandlesAuthenticationChallengesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2027         { "setIconDatabaseEnabled", setIconDatabaseEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2028         { "setJavaScriptProfilingEnabled", setJavaScriptProfilingEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2029         { "setMainFrameIsFirstResponder", setMainFrameIsFirstResponderCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2030         { "setMockDeviceOrientation", setMockDeviceOrientationCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2031         { "setMockGeolocationError", setMockGeolocationErrorCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2032         { "setMockGeolocationPosition", setMockGeolocationPositionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2033         { "addMockSpeechInputResult", addMockSpeechInputResultCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2034         { "setNewWindowsCopyBackForwardList", setNewWindowsCopyBackForwardListCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2035         { "setPOSIXLocale", setPOSIXLocaleCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2036         { "setPersistentUserStyleSheetLocation", setPersistentUserStyleSheetLocationCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2037         { "setPopupBlockingEnabled", setPopupBlockingEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2038         { "setPluginsEnabled", setPluginsEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2039         { "setPrinting", setPrintingCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2040         { "setPrivateBrowsingEnabled", setPrivateBrowsingEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2041         { "setSelectTrailingWhitespaceEnabled", setSelectTrailingWhitespaceEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2042         { "setSerializeHTTPLoads", setSerializeHTTPLoadsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2043         { "setSmartInsertDeleteEnabled", setSmartInsertDeleteEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2044         { "setSpatialNavigationEnabled", setSpatialNavigationEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2045         { "setStopProvisionalFrameLoads", setStopProvisionalFrameLoadsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2046         { "setTabKeyCyclesThroughElements", setTabKeyCyclesThroughElementsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2047         { "setTimelineProfilingEnabled", setTimelineProfilingEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2048         { "setUseDashboardCompatibilityMode", setUseDashboardCompatibilityModeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2049         { "setUserStyleSheetEnabled", setUserStyleSheetEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2050         { "setUserStyleSheetLocation", setUserStyleSheetLocationCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2051         { "setViewModeMediaFeature", setViewModeMediaFeatureCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2052         { "setWebViewEditable", setWebViewEditableCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2053         { "setWillSendRequestClearHeader", setWillSendRequestClearHeaderCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2054         { "setWillSendRequestReturnsNull", setWillSendRequestReturnsNullCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2055         { "setWillSendRequestReturnsNullOnRedirect", setWillSendRequestReturnsNullOnRedirectCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2056         { "setWindowIsKey", setWindowIsKeyCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2057         { "setJavaScriptCanAccessClipboard", setJavaScriptCanAccessClipboardCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2058         { "setXSSAuditorEnabled", setXSSAuditorEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2059         { "setAsynchronousSpellCheckingEnabled", setAsynchronousSpellCheckingEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2060         { "showWebInspector", showWebInspectorCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2061         { "testOnscreen", testOnscreenCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2062         { "testRepaint", testRepaintCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2063         { "waitForPolicyDelegate", waitForPolicyDelegateCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2064         { "waitUntilDone", waitUntilDoneCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2065         { "windowCount", windowCountCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2066         { "addOriginAccessWhitelistEntry", addOriginAccessWhitelistEntryCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2067         { "setScrollbarPolicy", setScrollbarPolicyCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2068         { "authenticateSession", authenticateSessionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
2069         { 0, 0, 0 }
2070     };
2071
2072     return staticFunctions;
2073 }
2074
2075 void LayoutTestController::queueLoadHTMLString(JSStringRef content, JSStringRef baseURL)
2076 {
2077     WorkQueue::shared()->queue(new LoadHTMLStringItem(content, baseURL));
2078 }
2079
2080 void LayoutTestController::queueBackNavigation(int howFarBack)
2081 {
2082     WorkQueue::shared()->queue(new BackItem(howFarBack));
2083 }
2084
2085 void LayoutTestController::queueForwardNavigation(int howFarForward)
2086 {
2087     WorkQueue::shared()->queue(new ForwardItem(howFarForward));
2088 }
2089
2090 void LayoutTestController::queueLoadingScript(JSStringRef script)
2091 {
2092     WorkQueue::shared()->queue(new LoadingScriptItem(script));
2093 }
2094
2095 void LayoutTestController::queueNonLoadingScript(JSStringRef script)
2096 {
2097     WorkQueue::shared()->queue(new NonLoadingScriptItem(script));
2098 }
2099
2100 void LayoutTestController::queueReload()
2101 {
2102     WorkQueue::shared()->queue(new ReloadItem);
2103 }
2104
2105 void LayoutTestController::grantDesktopNotificationPermission(JSStringRef origin)
2106 {
2107     m_desktopNotificationAllowedOrigins.push_back(JSStringRetain(origin));
2108 }
2109
2110 bool LayoutTestController::checkDesktopNotificationPermission(JSStringRef origin)
2111 {
2112     std::vector<JSStringRef>::iterator i;
2113     for (i = m_desktopNotificationAllowedOrigins.begin();
2114          i != m_desktopNotificationAllowedOrigins.end();
2115          ++i) {
2116         if (JSStringIsEqual(*i, origin))
2117             return true;
2118     }
2119     return false;
2120 }
2121
2122 void LayoutTestController::waitToDumpWatchdogTimerFired()
2123 {
2124     const char* message = "FAIL: Timed out waiting for notifyDone to be called\n";
2125     fprintf(stderr, "%s", message);
2126     fprintf(stdout, "%s", message);
2127     notifyDone();
2128 }
2129
2130 void LayoutTestController::setGeolocationPermissionCommon(bool allow)
2131 {
2132     m_isGeolocationPermissionSet = true;
2133     m_geolocationPermission = allow;
2134 }
2135
2136 void LayoutTestController::setPOSIXLocale(JSStringRef locale)
2137 {
2138     char localeBuf[32];
2139     JSStringGetUTF8CString(locale, localeBuf, sizeof(localeBuf));
2140     setlocale(LC_ALL, localeBuf);
2141 }
2142
2143 const unsigned LayoutTestController::maxViewWidth = 800;
2144 const unsigned LayoutTestController::maxViewHeight = 600;