Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: sky/engine/web/WebKit.cpp

Issue 676933002: Rename WebKit.h/cpp to Sky.h/cpp (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/engine/web/Sky.cpp ('k') | sky/engine/web/tests/RunAllTests.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 "public/web/WebKit.h"
33
34 #include "base/message_loop/message_loop.h"
35 #include "bindings/core/v8/V8Binding.h"
36 #include "bindings/core/v8/V8GCController.h"
37 #include "bindings/core/v8/V8Initializer.h"
38 #include "core/Init.h"
39 #include "core/animation/AnimationClock.h"
40 #include "core/dom/Microtask.h"
41 #include "core/frame/Settings.h"
42 #include "core/page/Page.h"
43 #include "gin/public/v8_platform.h"
44 #include "mojo/common/message_pump_mojo.h"
45 #include "platform/LayoutTestSupport.h"
46 #include "platform/Logging.h"
47 #include "platform/RuntimeEnabledFeatures.h"
48 #include "platform/graphics/ImageDecodingStore.h"
49 #include "platform/graphics/media/MediaPlayer.h"
50 #include "platform/heap/Heap.h"
51 #include "public/platform/Platform.h"
52 #include "web/WebMediaPlayerClientImpl.h"
53 #include "wtf/Assertions.h"
54 #include "wtf/CryptographicallyRandomNumber.h"
55 #include "wtf/MainThread.h"
56 #include "wtf/WTF.h"
57 #include "wtf/text/AtomicString.h"
58 #include "wtf/text/TextEncoding.h"
59 #include <v8.h>
60
61 namespace blink {
62
63 namespace {
64
65 void willProcessTask()
66 {
67 AnimationClock::notifyTaskStart();
68 }
69
70 void didProcessTask()
71 {
72 Microtask::performCheckpoint();
73 V8GCController::reportDOMMemoryUsageToV8(mainThreadIsolate());
74 }
75
76 class TaskObserver : public base::MessageLoop::TaskObserver {
77 public:
78 void WillProcessTask(const base::PendingTask& pending_task) override { willP rocessTask(); }
79 void DidProcessTask(const base::PendingTask& pending_task) override { didPro cessTask(); }
80 };
81
82 class SignalObserver : public mojo::common::MessagePumpMojo::Observer {
83 public:
84 void WillSignalHandler() override { willProcessTask(); }
85 void DidSignalHandler() override { didProcessTask(); }
86 };
87
88 static TaskObserver* s_taskObserver = 0;
89 static SignalObserver* s_signalObserver = 0;
90
91 void addMessageLoopObservers()
92 {
93 ASSERT(!s_taskObserver);
94 s_taskObserver = new TaskObserver;
95
96 ASSERT(!s_signalObserver);
97 s_signalObserver = new SignalObserver;
98
99 base::MessageLoop::current()->AddTaskObserver(s_taskObserver);
100 mojo::common::MessagePumpMojo::current()->AddObserver(s_signalObserver);
101 }
102
103 void removeMessageLoopObservers()
104 {
105 base::MessageLoop::current()->RemoveTaskObserver(s_taskObserver);
106 mojo::common::MessagePumpMojo::current()->RemoveObserver(s_signalObserver);
107
108 ASSERT(s_taskObserver);
109 delete s_taskObserver;
110 s_taskObserver = 0;
111
112 ASSERT(s_signalObserver);
113 delete s_signalObserver;
114 s_signalObserver = 0;
115 }
116
117 } // namespace
118
119 static ThreadState::Interruptor* s_isolateInterruptor = 0;
120
121 // Make sure we are not re-initialized in the same address space.
122 // Doing so may cause hard to reproduce crashes.
123 static bool s_webKitInitialized = false;
124
125 void initialize(Platform* platform)
126 {
127 initializeWithoutV8(platform);
128
129 V8Initializer::initializeMainThreadIfNeeded();
130
131 s_isolateInterruptor = new V8IsolateInterruptor(V8PerIsolateData::mainThread Isolate());
132 ThreadState::current()->addInterruptor(s_isolateInterruptor);
133
134 addMessageLoopObservers();
135 }
136
137 v8::Isolate* mainThreadIsolate()
138 {
139 return V8PerIsolateData::mainThreadIsolate();
140 }
141
142 static double currentTimeFunction()
143 {
144 return Platform::current()->currentTime();
145 }
146
147 static double monotonicallyIncreasingTimeFunction()
148 {
149 return Platform::current()->monotonicallyIncreasingTime();
150 }
151
152 static void cryptographicallyRandomValues(unsigned char* buffer, size_t length)
153 {
154 Platform::current()->cryptographicallyRandomValues(buffer, length);
155 }
156
157 static void callOnMainThreadFunction(WTF::MainThreadFunction function, void* con text)
158 {
159 Platform::current()->callOnMainThread(function, context);
160 }
161
162 void initializeWithoutV8(Platform* platform)
163 {
164 ASSERT(!s_webKitInitialized);
165 s_webKitInitialized = true;
166
167 ASSERT(platform);
168 Platform::initialize(platform);
169
170 WTF::setRandomSource(cryptographicallyRandomValues);
171 WTF::initialize(currentTimeFunction, monotonicallyIncreasingTimeFunction);
172 WTF::initializeMainThread(callOnMainThreadFunction);
173 Heap::init();
174
175 ThreadState::attachMainThread();
176
177 DEFINE_STATIC_LOCAL(CoreInitializer, initializer, ());
178 initializer.init();
179
180 // There are some code paths (for example, running WebKit in the browser
181 // process and calling into LocalStorage before anything else) where the
182 // UTF8 string encoding tables are used on a background thread before
183 // they're set up. This is a problem because their set up routines assert
184 // they're running on the main WebKitThread. It might be possible to make
185 // the initialization thread-safe, but given that so many code paths use
186 // this, initializing this lazily probably doesn't buy us much.
187 WTF::UTF8Encoding();
188
189 MediaPlayer::setMediaEngineCreateFunction(WebMediaPlayerClientImpl::create);
190 }
191
192 void shutdown()
193 {
194 removeMessageLoopObservers();
195
196 ASSERT(s_isolateInterruptor);
197 ThreadState::current()->removeInterruptor(s_isolateInterruptor);
198
199 // Detach the main thread before starting the shutdown sequence
200 // so that the main thread won't get involved in a GC during the shutdown.
201 ThreadState::detachMainThread();
202
203 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate();
204 V8PerIsolateData::dispose(isolate);
205
206 shutdownWithoutV8();
207 }
208
209 void shutdownWithoutV8()
210 {
211 CoreInitializer::shutdown();
212 Heap::shutdown();
213 WTF::shutdown();
214 Platform::shutdown();
215 }
216
217 void setLayoutTestMode(bool value)
218 {
219 LayoutTestSupport::setIsRunningLayoutTest(value);
220 }
221
222 bool layoutTestMode()
223 {
224 return LayoutTestSupport::isRunningLayoutTest();
225 }
226
227 void setFontAntialiasingEnabledForTest(bool value)
228 {
229 LayoutTestSupport::setFontAntialiasingEnabledForTest(value);
230 }
231
232 bool fontAntialiasingEnabledForTest()
233 {
234 return LayoutTestSupport::isFontAntialiasingEnabledForTest();
235 }
236
237 void enableLogChannel(const char* name)
238 {
239 #if !LOG_DISABLED
240 WTFLogChannel* channel = getChannelFromName(name);
241 if (channel)
242 channel->state = WTFLogChannelOn;
243 #endif // !LOG_DISABLED
244 }
245
246 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/web/Sky.cpp ('k') | sky/engine/web/tests/RunAllTests.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698