OLD | NEW |
| (Empty) |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/worker/worker_thread.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/lazy_instance.h" | |
9 #include "base/threading/thread_local.h" | |
10 #include "chrome/worker/webworker_stub.h" | |
11 #include "chrome/worker/websharedworker_stub.h" | |
12 #include "chrome/worker/worker_webkitclient_impl.h" | |
13 #include "content/common/appcache/appcache_dispatcher.h" | |
14 #include "content/common/content_switches.h" | |
15 #include "content/common/db_message_filter.h" | |
16 #include "content/common/web_database_observer_impl.h" | |
17 #include "content/common/worker_messages.h" | |
18 #include "ipc/ipc_sync_channel.h" | |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobRegistry.h" | |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h" | |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" | |
23 #include "webkit/glue/webkit_glue.h" | |
24 | |
25 using WebKit::WebRuntimeFeatures; | |
26 | |
27 static base::LazyInstance<base::ThreadLocalPointer<WorkerThread> > lazy_tls( | |
28 base::LINKER_INITIALIZED); | |
29 | |
30 | |
31 WorkerThread::WorkerThread() { | |
32 lazy_tls.Pointer()->Set(this); | |
33 webkit_client_.reset(new WorkerWebKitClientImpl); | |
34 WebKit::initialize(webkit_client_.get()); | |
35 | |
36 appcache_dispatcher_.reset(new AppCacheDispatcher(this)); | |
37 | |
38 web_database_observer_impl_.reset(new WebDatabaseObserverImpl(this)); | |
39 WebKit::WebDatabase::setObserver(web_database_observer_impl_.get()); | |
40 db_message_filter_ = new DBMessageFilter(); | |
41 channel()->AddFilter(db_message_filter_.get()); | |
42 | |
43 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
44 | |
45 webkit_glue::EnableWebCoreLogChannels( | |
46 command_line.GetSwitchValueASCII(switches::kWebCoreLogChannels)); | |
47 | |
48 WebKit::WebRuntimeFeatures::enableDatabase( | |
49 !command_line.HasSwitch(switches::kDisableDatabases)); | |
50 | |
51 WebKit::WebRuntimeFeatures::enableApplicationCache( | |
52 !command_line.HasSwitch(switches::kDisableApplicationCache)); | |
53 | |
54 #if defined(OS_WIN) | |
55 // We don't yet support notifications on non-Windows, so hide it from pages. | |
56 WebRuntimeFeatures::enableNotifications( | |
57 !command_line.HasSwitch(switches::kDisableDesktopNotifications)); | |
58 #endif | |
59 | |
60 WebRuntimeFeatures::enableSockets( | |
61 !command_line.HasSwitch(switches::kDisableWebSockets)); | |
62 | |
63 WebRuntimeFeatures::enableFileSystem( | |
64 !command_line.HasSwitch(switches::kDisableFileSystem)); | |
65 | |
66 WebRuntimeFeatures::enableWebGL( | |
67 !command_line.HasSwitch(switches::kDisable3DAPIs) && | |
68 !command_line.HasSwitch(switches::kDisableExperimentalWebGL)); | |
69 } | |
70 | |
71 WorkerThread::~WorkerThread() { | |
72 // Shutdown in reverse of the initialization order. | |
73 channel()->RemoveFilter(db_message_filter_.get()); | |
74 db_message_filter_ = NULL; | |
75 | |
76 WebKit::shutdown(); | |
77 lazy_tls.Pointer()->Set(NULL); | |
78 } | |
79 | |
80 WorkerThread* WorkerThread::current() { | |
81 return lazy_tls.Pointer()->Get(); | |
82 } | |
83 | |
84 bool WorkerThread::OnControlMessageReceived(const IPC::Message& msg) { | |
85 // Appcache messages are handled by a delegate. | |
86 if (appcache_dispatcher_->OnMessageReceived(msg)) | |
87 return true; | |
88 | |
89 bool handled = true; | |
90 IPC_BEGIN_MESSAGE_MAP(WorkerThread, msg) | |
91 IPC_MESSAGE_HANDLER(WorkerProcessMsg_CreateWorker, OnCreateWorker) | |
92 IPC_MESSAGE_UNHANDLED(handled = false) | |
93 IPC_END_MESSAGE_MAP() | |
94 return handled; | |
95 } | |
96 | |
97 void WorkerThread::OnCreateWorker( | |
98 const WorkerProcessMsg_CreateWorker_Params& params) { | |
99 WorkerAppCacheInitInfo appcache_init_info( | |
100 params.is_shared, params.creator_process_id, | |
101 params.creator_appcache_host_id, | |
102 params.shared_worker_appcache_id); | |
103 | |
104 // WebWorkerStub and WebSharedWorkerStub own themselves. | |
105 if (params.is_shared) | |
106 new WebSharedWorkerStub(params.name, params.route_id, appcache_init_info); | |
107 else | |
108 new WebWorkerStub(params.url, params.route_id, appcache_init_info); | |
109 } | |
110 | |
111 // The browser process is likely dead. Terminate all workers. | |
112 void WorkerThread::OnChannelError() { | |
113 set_on_channel_error_called(true); | |
114 | |
115 for (WorkerStubsList::iterator it = worker_stubs_.begin(); | |
116 it != worker_stubs_.end(); ++it) { | |
117 (*it)->OnChannelError(); | |
118 } | |
119 } | |
120 | |
121 void WorkerThread::RemoveWorkerStub(WebWorkerStubBase* stub) { | |
122 worker_stubs_.erase(stub); | |
123 } | |
124 | |
125 void WorkerThread::AddWorkerStub(WebWorkerStubBase* stub) { | |
126 worker_stubs_.insert(stub); | |
127 } | |
OLD | NEW |