• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
initialize(WebKitClient * webKitClient)52 void initialize(WebKitClient* webKitClient)
53 {
54     ASSERT(webKitClient);
55     ASSERT(!s_webKitClient);
56     s_webKitClient = webKitClient;
57 
58     WTF::initializeThreading();
59     WebCore::AtomicString::init();
60 
61     // Chromium sets the minimum interval timeout to 4ms, overriding the
62     // default of 10ms.  We'd like to go lower, however there are poorly
63     // coded websites out there which do create CPU-spinning loops.  Using
64     // 4ms prevents the CPU from spinning too busily and provides a balance
65     // between CPU spinning and the smallest possible interval timer.
66     WebCore::DOMTimer::setMinTimerInterval(0.004);
67 
68     // There are some code paths (for example, running WebKit in the browser
69     // process and calling into LocalStorage before anything else) where the
70     // UTF8 string encoding tables are used on a background thread before
71     // they're set up.  This is a problem because their set up routines assert
72     // they're running on the main WebKitThread.  It might be possible to make
73     // the initialization thread-safe, but given that so many code paths use
74     // this, initializing this lazily probably doesn't buy us much.
75     WebCore::UTF8Encoding();
76 }
77 
shutdown()78 void shutdown()
79 {
80     s_webKitClient = 0;
81 }
82 
webKitClient()83 WebKitClient* webKitClient()
84 {
85     return s_webKitClient;
86 }
87 
setLayoutTestMode(bool value)88 void setLayoutTestMode(bool value)
89 {
90     s_layoutTestMode = value;
91 }
92 
layoutTestMode()93 bool layoutTestMode()
94 {
95     return s_layoutTestMode;
96 }
97 
enableLogChannel(const char * name)98 void enableLogChannel(const char* name)
99 {
100     WTFLogChannel* channel = WebCore::getChannelFromName(name);
101     if (channel)
102         channel->state = WTFLogChannelOn;
103 }
104 
resetPluginCache(bool reloadPages)105 void resetPluginCache(bool reloadPages)
106 {
107     WebCore::Page::refreshPlugins(reloadPages);
108 }
109 
110 } // namespace WebKit
111