tizen beta release
[framework/web/webkit-efl.git] / Source / WebKit / chromium / src / WebKit.cpp
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 "CCThreadImpl.h"
35 #include "cc/CCProxy.h"
36 #include "Logging.h"
37 #include "Page.h"
38 #include "RuntimeEnabledFeatures.h"
39 #include "Settings.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"
46 #include "v8.h"
47
48 #include <wtf/Assertions.h>
49 #include <wtf/MainThread.h>
50 #include <wtf/Threading.h>
51 #include <wtf/text/AtomicString.h>
52
53 namespace WebKit {
54
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;
58
59 static WebKitPlatformSupport* s_webKitPlatformSupport = 0;
60 static bool s_layoutTestMode = false;
61
62 static bool generateEntropy(unsigned char* buffer, size_t length)
63 {
64     if (s_webKitPlatformSupport) {
65         s_webKitPlatformSupport->cryptographicallyRandomValues(buffer, length);
66         return true;
67     }
68     return false;
69 }
70
71 void initialize(WebKitPlatformSupport* webKitPlatformSupport)
72 {
73     initializeWithoutV8(webKitPlatformSupport);
74
75     v8::V8::SetEntropySource(&generateEntropy);
76     v8::V8::Initialize();
77     WebCore::V8BindingPerIsolateData::ensureInitialized(v8::Isolate::GetCurrent());
78 }
79
80 void initializeWithoutV8(WebKitPlatformSupport* webKitPlatformSupport)
81 {
82     ASSERT(!s_webKitInitialized);
83     s_webKitInitialized = true;
84
85     ASSERT(webKitPlatformSupport);
86     ASSERT(!s_webKitPlatformSupport);
87     s_webKitPlatformSupport = webKitPlatformSupport;
88
89     WTF::initializeThreading();
90     WTF::initializeMainThread();
91     WTF::AtomicString::init();
92
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();
101
102     WebCore::CCProxy::setMainThread(CCThreadImpl::create(webKitPlatformSupport->currentThread()).leakPtr());
103 }
104
105
106 void shutdown()
107 {
108     delete WebCore::CCProxy::mainThread();
109     WebCore::CCProxy::setMainThread(0);
110     s_webKitPlatformSupport = 0;
111 }
112
113 WebKitPlatformSupport* webKitPlatformSupport()
114 {
115     return s_webKitPlatformSupport;
116 }
117
118 void setLayoutTestMode(bool value)
119 {
120     s_layoutTestMode = value;
121 }
122
123 bool layoutTestMode()
124 {
125     return s_layoutTestMode;
126 }
127
128 void enableLogChannel(const char* name)
129 {
130     WTFLogChannel* channel = WebCore::getChannelFromName(name);
131     if (channel)
132         channel->state = WTFLogChannelOn;
133 }
134
135 void resetPluginCache(bool reloadPages)
136 {
137     WebCore::Page::refreshPlugins(reloadPages);
138 }
139
140 } // namespace WebKit