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