OSDN Git Service

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