OSDN Git Service

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