WebKit/chromium/src/WebKit.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2009 Google Inc. All rights reserved.
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or without
       
     5  * modification, are permitted provided that the following conditions are
       
     6  * met:
       
     7  *
       
     8  *     * Redistributions of source code must retain the above copyright
       
     9  * notice, this list of conditions and the following disclaimer.
       
    10  *     * Redistributions in binary form must reproduce the above
       
    11  * copyright notice, this list of conditions and the following disclaimer
       
    12  * in the documentation and/or other materials provided with the
       
    13  * distribution.
       
    14  *     * Neither the name of Google Inc. nor the names of its
       
    15  * contributors may be used to endorse or promote products derived from
       
    16  * this software without specific prior written permission.
       
    17  *
       
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    29  */
       
    30 
       
    31 #include "config.h"
       
    32 #include "WebKit.h"
       
    33 
       
    34 #include "AtomicString.h"
       
    35 #include "DOMTimer.h"
       
    36 #include "Logging.h"
       
    37 #include "Page.h"
       
    38 #include "RuntimeEnabledFeatures.h"
       
    39 #include "TextEncoding.h"
       
    40 #include "WebMediaPlayerClientImpl.h"
       
    41 #include "WebSocket.h"
       
    42 #include "WorkerContextExecutionProxy.h"
       
    43 
       
    44 #include <wtf/Assertions.h>
       
    45 #include <wtf/Threading.h>
       
    46 
       
    47 namespace WebKit {
       
    48 
       
    49 static WebKitClient* s_webKitClient = 0;
       
    50 static bool s_layoutTestMode = false;
       
    51 
       
    52 void initialize(WebKitClient* webKitClient)
       
    53 {
       
    54     ASSERT(webKitClient);
       
    55     ASSERT(!s_webKitClient);
       
    56     s_webKitClient = webKitClient;
       
    57 
       
    58     WTF::initializeThreading();
       
    59     WTF::initializeMainThread();
       
    60     WebCore::AtomicString::init();
       
    61 
       
    62     // Chromium sets the minimum interval timeout to 4ms, overriding the
       
    63     // default of 10ms.  We'd like to go lower, however there are poorly
       
    64     // coded websites out there which do create CPU-spinning loops.  Using
       
    65     // 4ms prevents the CPU from spinning too busily and provides a balance
       
    66     // between CPU spinning and the smallest possible interval timer.
       
    67     WebCore::DOMTimer::setMinTimerInterval(0.004);
       
    68 
       
    69     // There are some code paths (for example, running WebKit in the browser
       
    70     // process and calling into LocalStorage before anything else) where the
       
    71     // UTF8 string encoding tables are used on a background thread before
       
    72     // they're set up.  This is a problem because their set up routines assert
       
    73     // they're running on the main WebKitThread.  It might be possible to make
       
    74     // the initialization thread-safe, but given that so many code paths use
       
    75     // this, initializing this lazily probably doesn't buy us much.
       
    76     WebCore::UTF8Encoding();
       
    77 }
       
    78 
       
    79 void shutdown()
       
    80 {
       
    81     s_webKitClient = 0;
       
    82 }
       
    83 
       
    84 WebKitClient* webKitClient()
       
    85 {
       
    86     return s_webKitClient;
       
    87 }
       
    88 
       
    89 void setLayoutTestMode(bool value)
       
    90 {
       
    91     s_layoutTestMode = value;
       
    92 }
       
    93 
       
    94 bool layoutTestMode()
       
    95 {
       
    96     return s_layoutTestMode;
       
    97 }
       
    98 
       
    99 void enableLogChannel(const char* name)
       
   100 {
       
   101     WTFLogChannel* channel = WebCore::getChannelFromName(name);
       
   102     if (channel)
       
   103         channel->state = WTFLogChannelOn;
       
   104 }
       
   105 
       
   106 void resetPluginCache(bool reloadPages)
       
   107 {
       
   108     WebCore::Page::refreshPlugins(reloadPages);
       
   109 }
       
   110 
       
   111 } // namespace WebKit