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

Side by Side Diff: chrome/worker/webworkerclient_proxy.cc

Issue 6691004: Move worker code from chrome\worker to content\worker. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/worker/webworkerclient_proxy.h ('k') | chrome/worker/worker_main.cc » ('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 // 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/webworkerclient_proxy.h"
6
7 #include "base/command_line.h"
8 #include "base/message_loop.h"
9 #include "chrome/worker/webworker_stub_base.h"
10 #include "chrome/worker/worker_thread.h"
11 #include "chrome/worker/worker_webapplicationcachehost_impl.h"
12 #include "content/common/content_switches.h"
13 #include "content/common/file_system/file_system_dispatcher.h"
14 #include "content/common/file_system/webfilesystem_callback_dispatcher.h"
15 #include "content/common/webmessageportchannel_impl.h"
16 #include "content/common/worker_messages.h"
17 // TODO(jam): uncomment this and WebWorkerClientProxy::createWorker when the
18 // renderer worker code moves to content. This code isn't used now since we
19 // don't support nested workers anyways.
20 //#include "content/renderer/webworker_proxy.h"
21 #include "ipc/ipc_logging.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback s.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorker.h"
28
29 using WebKit::WebApplicationCacheHost;
30 using WebKit::WebFrame;
31 using WebKit::WebMessagePortChannel;
32 using WebKit::WebMessagePortChannelArray;
33 using WebKit::WebSecurityOrigin;
34 using WebKit::WebString;
35 using WebKit::WebWorker;
36 using WebKit::WebWorkerClient;
37
38 // How long to wait for worker to finish after it's been told to terminate.
39 #define kMaxTimeForRunawayWorkerMs 3000
40
41 WebWorkerClientProxy::WebWorkerClientProxy(int route_id,
42 WebWorkerStubBase* stub)
43 : route_id_(route_id),
44 appcache_host_id_(0),
45 stub_(stub),
46 ALLOW_THIS_IN_INITIALIZER_LIST(kill_process_factory_(this)) {
47 }
48
49 WebWorkerClientProxy::~WebWorkerClientProxy() {
50 }
51
52 void WebWorkerClientProxy::postMessageToWorkerObject(
53 const WebString& message,
54 const WebMessagePortChannelArray& channels) {
55 std::vector<int> message_port_ids(channels.size());
56 std::vector<int> routing_ids(channels.size());
57 for (size_t i = 0; i < channels.size(); ++i) {
58 WebMessagePortChannelImpl* webchannel =
59 static_cast<WebMessagePortChannelImpl*>(channels[i]);
60 message_port_ids[i] = webchannel->message_port_id();
61 webchannel->QueueMessages();
62 DCHECK(message_port_ids[i] != MSG_ROUTING_NONE);
63 routing_ids[i] = MSG_ROUTING_NONE;
64 }
65
66 Send(new WorkerMsg_PostMessage(
67 route_id_, message, message_port_ids, routing_ids));
68 }
69
70 void WebWorkerClientProxy::postExceptionToWorkerObject(
71 const WebString& error_message,
72 int line_number,
73 const WebString& source_url) {
74 Send(new WorkerHostMsg_PostExceptionToWorkerObject(
75 route_id_, error_message, line_number, source_url));
76 }
77
78 void WebWorkerClientProxy::postConsoleMessageToWorkerObject(
79 int source,
80 int type,
81 int level,
82 const WebString& message,
83 int line_number,
84 const WebString& source_url) {
85 WorkerHostMsg_PostConsoleMessageToWorkerObject_Params params;
86 params.source_identifier = source;
87 params.message_type = type;
88 params.message_level = level;
89 params.message = message;
90 params.line_number = line_number;
91 params.source_url = source_url;
92 Send(new WorkerHostMsg_PostConsoleMessageToWorkerObject(route_id_, params));
93 }
94
95 void WebWorkerClientProxy::confirmMessageFromWorkerObject(
96 bool has_pending_activity) {
97 Send(new WorkerHostMsg_ConfirmMessageFromWorkerObject(
98 route_id_, has_pending_activity));
99 }
100
101 void WebWorkerClientProxy::reportPendingActivity(bool has_pending_activity) {
102 Send(new WorkerHostMsg_ReportPendingActivity(
103 route_id_, has_pending_activity));
104 }
105
106 void WebWorkerClientProxy::workerContextClosed() {
107 Send(new WorkerHostMsg_WorkerContextClosed(route_id_));
108 }
109
110 void WebWorkerClientProxy::workerContextDestroyed() {
111 Send(new WorkerHostMsg_WorkerContextDestroyed(route_id_));
112 // Tell the stub that the worker has shutdown - frees this object.
113 if (stub_)
114 stub_->Shutdown();
115 }
116
117 WebKit::WebWorker* WebWorkerClientProxy::createWorker(
118 WebKit::WebWorkerClient* client) {
119 // TODO(jam): see comment at top of file
120 //return new WebWorkerProxy(client, WorkerThread::current(),
121 // 0, appcache_host_id_);
122 return NULL;
123 }
124
125 WebKit::WebNotificationPresenter*
126 WebWorkerClientProxy::notificationPresenter() {
127 // TODO(johnnyg): Notifications are not yet hooked up to workers.
128 // Coming soon.
129 NOTREACHED();
130 return NULL;
131 }
132
133 WebApplicationCacheHost* WebWorkerClientProxy::createApplicationCacheHost(
134 WebKit::WebApplicationCacheHostClient* client) {
135 WorkerWebApplicationCacheHostImpl* host =
136 new WorkerWebApplicationCacheHostImpl(stub_->appcache_init_info(),
137 client);
138 // Remember the id of the instance we create so we have access to that
139 // value when creating nested dedicated workers in createWorker.
140 appcache_host_id_ = host->host_id();
141 return host;
142 }
143
144 bool WebWorkerClientProxy::allowDatabase(WebFrame* frame,
145 const WebString& name,
146 const WebString& display_name,
147 unsigned long estimated_size) {
148 WebSecurityOrigin origin = frame->securityOrigin();
149 if (origin.isEmpty())
150 return false;
151
152 bool result;
153 if (!Send(new WorkerProcessHostMsg_AllowDatabase(route_id_,
154 GURL(origin.toString().utf8()), name, display_name, estimated_size,
155 &result)))
156 return false;
157
158 return result;
159 }
160
161 void WebWorkerClientProxy::openFileSystem(
162 WebKit::WebFileSystem::Type type,
163 long long size,
164 bool create,
165 WebKit::WebFileSystemCallbacks* callbacks) {
166 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
167 stub_->url().GetOrigin(), static_cast<fileapi::FileSystemType>(type),
168 size, create, new WebFileSystemCallbackDispatcher(callbacks));
169 }
170
171 void WebWorkerClientProxy::openFileSystem(
172 WebKit::WebFileSystem::Type type,
173 long long size,
174 WebKit::WebFileSystemCallbacks* callbacks) {
175 openFileSystem(type, size, true, callbacks);
176 }
177
178 bool WebWorkerClientProxy::Send(IPC::Message* message) {
179 return WorkerThread::current()->Send(message);
180 }
181
182 void WebWorkerClientProxy::EnsureWorkerContextTerminates() {
183 // Avoid a worker doing a while(1) from never exiting.
184 if (CommandLine::ForCurrentProcess()->HasSwitch(
185 switches::kWebWorkerShareProcesses)) {
186 // Can't kill the process since there could be workers from other
187 // renderer process.
188 NOTIMPLEMENTED();
189 return;
190 }
191
192 // This shuts down the process cleanly from the perspective of the browser
193 // process, and avoids the crashed worker infobar from appearing to the new
194 // page. It's ok to post several of theese, because the first executed task
195 // will exit the message loop and subsequent ones won't be executed.
196 MessageLoop::current()->PostDelayedTask(FROM_HERE,
197 kill_process_factory_.NewRunnableMethod(
198 &WebWorkerClientProxy::workerContextDestroyed),
199 kMaxTimeForRunawayWorkerMs);
200 }
OLDNEW
« no previous file with comments | « chrome/worker/webworkerclient_proxy.h ('k') | chrome/worker/worker_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698