OSDN Git Service

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