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