| 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/webworker_stub.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "content/common/child_thread.h" | |
| 9 #include "content/common/file_system/file_system_dispatcher.h" | |
| 10 #include "content/common/webmessageportchannel_impl.h" | |
| 11 #include "content/common/worker_messages.h" | |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorker.h" | |
| 15 | |
| 16 using WebKit::WebWorker; | |
| 17 | |
| 18 WebWorkerStub::WebWorkerStub(const GURL& url, int route_id, | |
| 19 const WorkerAppCacheInitInfo& appcache_init_info) | |
| 20 : WebWorkerStubBase(route_id, appcache_init_info), | |
| 21 ALLOW_THIS_IN_INITIALIZER_LIST(impl_(WebWorker::create(client()))), | |
| 22 url_(url) { | |
| 23 } | |
| 24 | |
| 25 WebWorkerStub::~WebWorkerStub() { | |
| 26 impl_->clientDestroyed(); | |
| 27 } | |
| 28 | |
| 29 void WebWorkerStub::OnChannelError() { | |
| 30 OnTerminateWorkerContext(); | |
| 31 } | |
| 32 | |
| 33 const GURL& WebWorkerStub::url() const { | |
| 34 return url_; | |
| 35 } | |
| 36 | |
| 37 bool WebWorkerStub::OnMessageReceived(const IPC::Message& message) { | |
| 38 if (!impl_) | |
| 39 return false; | |
| 40 | |
| 41 bool handled = true; | |
| 42 IPC_BEGIN_MESSAGE_MAP(WebWorkerStub, message) | |
| 43 IPC_MESSAGE_FORWARD(WorkerMsg_StartWorkerContext, impl_, | |
| 44 WebWorker::startWorkerContext) | |
| 45 IPC_MESSAGE_HANDLER(WorkerMsg_TerminateWorkerContext, | |
| 46 OnTerminateWorkerContext) | |
| 47 IPC_MESSAGE_HANDLER(WorkerMsg_PostMessage, OnPostMessage) | |
| 48 IPC_MESSAGE_FORWARD(WorkerMsg_WorkerObjectDestroyed, impl_, | |
| 49 WebWorker::workerObjectDestroyed) | |
| 50 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 51 IPC_END_MESSAGE_MAP() | |
| 52 return handled; | |
| 53 } | |
| 54 | |
| 55 void WebWorkerStub::OnTerminateWorkerContext() { | |
| 56 impl_->terminateWorkerContext(); | |
| 57 | |
| 58 // Call the client to make sure context exits. | |
| 59 EnsureWorkerContextTerminates(); | |
| 60 } | |
| 61 | |
| 62 void WebWorkerStub::OnPostMessage( | |
| 63 const string16& message, | |
| 64 const std::vector<int>& sent_message_port_ids, | |
| 65 const std::vector<int>& new_routing_ids) { | |
| 66 WebKit::WebMessagePortChannelArray channels(sent_message_port_ids.size()); | |
| 67 for (size_t i = 0; i < sent_message_port_ids.size(); i++) { | |
| 68 channels[i] = new WebMessagePortChannelImpl( | |
| 69 new_routing_ids[i], sent_message_port_ids[i]); | |
| 70 } | |
| 71 | |
| 72 impl_->postMessageToWorkerContext(message, channels); | |
| 73 } | |
| OLD | NEW |