| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/worker/websharedworker_stub.h" | 5 #include "chrome/worker/websharedworker_stub.h" |
| 6 | 6 |
| 7 #include "chrome/common/webmessageportchannel_impl.h" | 7 #include "chrome/common/webmessageportchannel_impl.h" |
| 8 #include "chrome/common/worker_messages.h" | 8 #include "chrome/common/worker_messages.h" |
| 9 #include "third_party/WebKit/WebKit/chromium/public/WebSharedWorker.h" | 9 #include "third_party/WebKit/WebKit/chromium/public/WebSharedWorker.h" |
| 10 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 12 | 12 |
| 13 WebSharedWorkerStub::WebSharedWorkerStub( | 13 WebSharedWorkerStub::WebSharedWorkerStub( |
| 14 const string16& name, int route_id) | 14 const string16& name, int route_id, |
| 15 : WebWorkerStubBase(route_id), | 15 const WorkerAppCacheInitInfo& appcache_init_info) |
| 16 : WebWorkerStubBase(route_id, appcache_init_info), |
| 16 name_(name), | 17 name_(name), |
| 17 started_(false) { | 18 started_(false) { |
| 18 | |
| 19 // TODO(atwilson): Add support for NaCl when they support MessagePorts. | 19 // TODO(atwilson): Add support for NaCl when they support MessagePorts. |
| 20 impl_ = WebKit::WebSharedWorker::create(client()); | 20 impl_ = WebKit::WebSharedWorker::create(client()); |
| 21 | |
| 22 } | 21 } |
| 23 | 22 |
| 24 WebSharedWorkerStub::~WebSharedWorkerStub() { | 23 WebSharedWorkerStub::~WebSharedWorkerStub() { |
| 25 impl_->clientDestroyed(); | 24 impl_->clientDestroyed(); |
| 26 } | 25 } |
| 27 | 26 |
| 28 void WebSharedWorkerStub::OnMessageReceived(const IPC::Message& message) { | 27 void WebSharedWorkerStub::OnMessageReceived(const IPC::Message& message) { |
| 29 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerStub, message) | 28 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerStub, message) |
| 30 IPC_MESSAGE_HANDLER(WorkerMsg_StartWorkerContext, OnStartWorkerContext) | 29 IPC_MESSAGE_HANDLER(WorkerMsg_StartWorkerContext, OnStartWorkerContext) |
| 31 IPC_MESSAGE_HANDLER(WorkerMsg_TerminateWorkerContext, | 30 IPC_MESSAGE_HANDLER(WorkerMsg_TerminateWorkerContext, |
| 32 OnTerminateWorkerContext) | 31 OnTerminateWorkerContext) |
| 33 IPC_MESSAGE_HANDLER(WorkerMsg_Connect, OnConnect) | 32 IPC_MESSAGE_HANDLER(WorkerMsg_Connect, OnConnect) |
| 34 IPC_END_MESSAGE_MAP() | 33 IPC_END_MESSAGE_MAP() |
| 35 } | 34 } |
| 36 | 35 |
| 37 void WebSharedWorkerStub::OnChannelError() { | 36 void WebSharedWorkerStub::OnChannelError() { |
| 38 OnTerminateWorkerContext(); | 37 OnTerminateWorkerContext(); |
| 39 } | 38 } |
| 40 | 39 |
| 41 void WebSharedWorkerStub::OnStartWorkerContext( | 40 void WebSharedWorkerStub::OnStartWorkerContext( |
| 42 const GURL& url, const string16& user_agent, const string16& source_code) { | 41 const GURL& url, const string16& user_agent, const string16& source_code) { |
| 43 // Ignore multiple attempts to start this worker (can happen if two pages | 42 // Ignore multiple attempts to start this worker (can happen if two pages |
| 44 // try to start it simultaneously). | 43 // try to start it simultaneously). |
| 45 if (started_) | 44 if (started_) |
| 46 return; | 45 return; |
| 46 |
| 47 // TODO(michaeln): Fixup this callsite once |
| 48 // https://bugs.webkit.org/show_bug.cgi?id=38605 |
| 49 // has landed and rolled into view. |
| 47 impl_->startWorkerContext(url, name_, user_agent, source_code); | 50 impl_->startWorkerContext(url, name_, user_agent, source_code); |
| 48 started_ = true; | 51 started_ = true; |
| 49 | 52 |
| 50 // Process any pending connections. | 53 // Process any pending connections. |
| 51 for (PendingConnectInfoList::const_iterator iter = pending_connects_.begin(); | 54 for (PendingConnectInfoList::const_iterator iter = pending_connects_.begin(); |
| 52 iter != pending_connects_.end(); | 55 iter != pending_connects_.end(); |
| 53 ++iter) { | 56 ++iter) { |
| 54 OnConnect(iter->first, iter->second); | 57 OnConnect(iter->first, iter->second); |
| 55 } | 58 } |
| 56 pending_connects_.clear(); | 59 pending_connects_.clear(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 71 } | 74 } |
| 72 } | 75 } |
| 73 | 76 |
| 74 void WebSharedWorkerStub::OnTerminateWorkerContext() { | 77 void WebSharedWorkerStub::OnTerminateWorkerContext() { |
| 75 impl_->terminateWorkerContext(); | 78 impl_->terminateWorkerContext(); |
| 76 | 79 |
| 77 // Call the client to make sure context exits. | 80 // Call the client to make sure context exits. |
| 78 EnsureWorkerContextTerminates(); | 81 EnsureWorkerContextTerminates(); |
| 79 started_ = false; | 82 started_ = false; |
| 80 } | 83 } |
| OLD | NEW |