2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
34 #include "CCThreadImpl.h"
35 #include "cc/CCProxy.h"
38 #include "RuntimeEnabledFeatures.h"
40 #include "TextEncoding.h"
41 #include "V8Binding.h"
42 #include "WebKitPlatformSupport.h"
43 #include "WebMediaPlayerClientImpl.h"
44 #include "WebSocket.h"
45 #include "WorkerContextExecutionProxy.h"
48 #include <wtf/Assertions.h>
49 #include <wtf/MainThread.h>
50 #include <wtf/Threading.h>
51 #include <wtf/text/AtomicString.h>
55 // Make sure we are not re-initialized in the same address space.
56 // Doing so may cause hard to reproduce crashes.
57 static bool s_webKitInitialized = false;
59 static WebKitPlatformSupport* s_webKitPlatformSupport = 0;
60 static bool s_layoutTestMode = false;
62 static bool generateEntropy(unsigned char* buffer, size_t length)
64 if (s_webKitPlatformSupport) {
65 s_webKitPlatformSupport->cryptographicallyRandomValues(buffer, length);
71 void initialize(WebKitPlatformSupport* webKitPlatformSupport)
73 initializeWithoutV8(webKitPlatformSupport);
75 v8::V8::SetEntropySource(&generateEntropy);
77 WebCore::V8BindingPerIsolateData::ensureInitialized(v8::Isolate::GetCurrent());
80 void initializeWithoutV8(WebKitPlatformSupport* webKitPlatformSupport)
82 ASSERT(!s_webKitInitialized);
83 s_webKitInitialized = true;
85 ASSERT(webKitPlatformSupport);
86 ASSERT(!s_webKitPlatformSupport);
87 s_webKitPlatformSupport = webKitPlatformSupport;
89 WTF::initializeThreading();
90 WTF::initializeMainThread();
91 WTF::AtomicString::init();
93 // There are some code paths (for example, running WebKit in the browser
94 // process and calling into LocalStorage before anything else) where the
95 // UTF8 string encoding tables are used on a background thread before
96 // they're set up. This is a problem because their set up routines assert
97 // they're running on the main WebKitThread. It might be possible to make
98 // the initialization thread-safe, but given that so many code paths use
99 // this, initializing this lazily probably doesn't buy us much.
100 WebCore::UTF8Encoding();
102 WebCore::CCProxy::setMainThread(CCThreadImpl::create(webKitPlatformSupport->currentThread()).leakPtr());
108 delete WebCore::CCProxy::mainThread();
109 WebCore::CCProxy::setMainThread(0);
110 s_webKitPlatformSupport = 0;
113 WebKitPlatformSupport* webKitPlatformSupport()
115 return s_webKitPlatformSupport;
118 void setLayoutTestMode(bool value)
120 s_layoutTestMode = value;
123 bool layoutTestMode()
125 return s_layoutTestMode;
128 void enableLogChannel(const char* name)
130 WTFLogChannel* channel = WebCore::getChannelFromName(name);
132 channel->state = WTFLogChannelOn;
135 void resetPluginCache(bool reloadPages)
137 WebCore::Page::refreshPlugins(reloadPages);
140 } // namespace WebKit