OSDN Git Service

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