| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/renderer/websharedworker_proxy.h" | 5 #include "content/renderer/websharedworker_proxy.h" |
| 6 #include "content/common/child_thread.h" | 6 #include "content/common/child_thread.h" |
| 7 #include "content/common/view_messages.h" | 7 #include "content/common/view_messages.h" |
| 8 #include "content/common/webmessageportchannel_impl.h" | 8 #include "content/common/webmessageportchannel_impl.h" |
| 9 #include "content/common/worker_messages.h" | 9 #include "content/common/worker_messages.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSharedWorkerClient
.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSharedWorkerClient
.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 38 return; | 38 return; |
| 39 | 39 |
| 40 // So the messages from WorkerContext (like WorkerContextDestroyed) do not | 40 // So the messages from WorkerContext (like WorkerContextDestroyed) do not |
| 41 // come after nobody is listening. Since Worker and WorkerContext can | 41 // come after nobody is listening. Since Worker and WorkerContext can |
| 42 // terminate independently, already sent messages may still be in the pipe. | 42 // terminate independently, already sent messages may still be in the pipe. |
| 43 child_thread_->RemoveRoute(route_id_); | 43 child_thread_->RemoveRoute(route_id_); |
| 44 | 44 |
| 45 route_id_ = MSG_ROUTING_NONE; | 45 route_id_ = MSG_ROUTING_NONE; |
| 46 } | 46 } |
| 47 | 47 |
| 48 void WebSharedWorkerProxy::CreateWorkerContext( | 48 void WebSharedWorkerProxy::CreateWorkerContext(const GURL& script_url, |
| 49 const GURL& script_url, | 49 bool is_shared, |
| 50 bool is_shared, | 50 const string16& name, |
| 51 const string16& name, | 51 const string16& user_agent, |
| 52 const string16& user_agent, | 52 const string16& source_code, |
| 53 const string16& source_code, | 53 int pending_route_id, |
| 54 const string16& content_security_policy, | 54 int64 script_resource_appcache_id) { |
| 55 bool report_only, | |
| 56 int pending_route_id, | |
| 57 int64 script_resource_appcache_id) { | |
| 58 DCHECK(route_id_ == MSG_ROUTING_NONE); | 55 DCHECK(route_id_ == MSG_ROUTING_NONE); |
| 59 ViewHostMsg_CreateWorker_Params params; | 56 ViewHostMsg_CreateWorker_Params params; |
| 60 params.url = script_url; | 57 params.url = script_url; |
| 61 params.name = name; | 58 params.name = name; |
| 62 params.document_id = document_id_; | 59 params.document_id = document_id_; |
| 63 params.render_view_route_id = render_view_route_id_; | 60 params.render_view_route_id = render_view_route_id_; |
| 64 params.route_id = pending_route_id; | 61 params.route_id = pending_route_id; |
| 65 params.script_resource_appcache_id = script_resource_appcache_id; | 62 params.script_resource_appcache_id = script_resource_appcache_id; |
| 66 IPC::Message* create_message = new ViewHostMsg_CreateWorker( | 63 IPC::Message* create_message = new ViewHostMsg_CreateWorker( |
| 67 params, &route_id_); | 64 params, &route_id_); |
| 68 child_thread_->Send(create_message); | 65 child_thread_->Send(create_message); |
| 69 if (route_id_ == MSG_ROUTING_NONE) | 66 if (route_id_ == MSG_ROUTING_NONE) |
| 70 return; | 67 return; |
| 71 | 68 |
| 72 child_thread_->AddRoute(route_id_, this); | 69 child_thread_->AddRoute(route_id_, this); |
| 73 | 70 |
| 74 // We make sure that the start message is the first, since postMessage or | 71 // We make sure that the start message is the first, since postMessage or |
| 75 // connect might have already been called. | 72 // connect might have already been called. |
| 76 queued_messages_.insert(queued_messages_.begin(), | 73 queued_messages_.insert(queued_messages_.begin(), |
| 77 new WorkerMsg_StartWorkerContext( | 74 new WorkerMsg_StartWorkerContext( |
| 78 route_id_, script_url, user_agent, source_code, | 75 route_id_, script_url, user_agent, source_code)); |
| 79 content_security_policy, report_only)); | |
| 80 } | 76 } |
| 81 | 77 |
| 82 bool WebSharedWorkerProxy::IsStarted() { | 78 bool WebSharedWorkerProxy::IsStarted() { |
| 83 // Worker is started if we have a route ID and there are no queued messages | 79 // Worker is started if we have a route ID and there are no queued messages |
| 84 // (meaning we've sent the WorkerMsg_StartWorkerContext already). | 80 // (meaning we've sent the WorkerMsg_StartWorkerContext already). |
| 85 return (route_id_ != MSG_ROUTING_NONE && queued_messages_.empty()); | 81 return (route_id_ != MSG_ROUTING_NONE && queued_messages_.empty()); |
| 86 } | 82 } |
| 87 | 83 |
| 88 bool WebSharedWorkerProxy::Send(IPC::Message* message) { | 84 bool WebSharedWorkerProxy::Send(IPC::Message* message) { |
| 89 // It's possible that messages will be sent before the worker is created, in | 85 // It's possible that messages will be sent before the worker is created, in |
| (...skipping 28 matching lines...) Expand all Loading... |
| 118 } | 114 } |
| 119 | 115 |
| 120 void WebSharedWorkerProxy::startWorkerContext( | 116 void WebSharedWorkerProxy::startWorkerContext( |
| 121 const WebKit::WebURL& script_url, | 117 const WebKit::WebURL& script_url, |
| 122 const WebKit::WebString& name, | 118 const WebKit::WebString& name, |
| 123 const WebKit::WebString& user_agent, | 119 const WebKit::WebString& user_agent, |
| 124 const WebKit::WebString& source_code, | 120 const WebKit::WebString& source_code, |
| 125 long long script_resource_appcache_id) { | 121 long long script_resource_appcache_id) { |
| 126 DCHECK(!isStarted()); | 122 DCHECK(!isStarted()); |
| 127 CreateWorkerContext(script_url, true, name, user_agent, source_code, | 123 CreateWorkerContext(script_url, true, name, user_agent, source_code, |
| 128 string16(), false, pending_route_id_, | |
| 129 script_resource_appcache_id); | |
| 130 } | |
| 131 | |
| 132 void WebSharedWorkerProxy::startWorkerContext( | |
| 133 const WebKit::WebURL& script_url, | |
| 134 const WebKit::WebString& name, | |
| 135 const WebKit::WebString& user_agent, | |
| 136 const WebKit::WebString& source_code, | |
| 137 const WebKit::WebString& content_security_policy, | |
| 138 bool report_only, | |
| 139 long long script_resource_appcache_id) { | |
| 140 DCHECK(!isStarted()); | |
| 141 CreateWorkerContext(script_url, true, name, user_agent, source_code, | |
| 142 content_security_policy, report_only, | |
| 143 pending_route_id_, script_resource_appcache_id); | 124 pending_route_id_, script_resource_appcache_id); |
| 144 } | 125 } |
| 145 | 126 |
| 146 void WebSharedWorkerProxy::terminateWorkerContext() { | 127 void WebSharedWorkerProxy::terminateWorkerContext() { |
| 147 // This API should only be invoked from worker context. | 128 // This API should only be invoked from worker context. |
| 148 NOTREACHED(); | 129 NOTREACHED(); |
| 149 } | 130 } |
| 150 | 131 |
| 151 void WebSharedWorkerProxy::clientDestroyed() { | 132 void WebSharedWorkerProxy::clientDestroyed() { |
| 152 // This API should only be invoked from worker context. | 133 // This API should only be invoked from worker context. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // The worker is created - now send off the CreateWorkerContext message and | 166 // The worker is created - now send off the CreateWorkerContext message and |
| 186 // any other queued messages | 167 // any other queued messages |
| 187 SendQueuedMessages(); | 168 SendQueuedMessages(); |
| 188 | 169 |
| 189 // Inform any listener that the pending connect event has been sent | 170 // Inform any listener that the pending connect event has been sent |
| 190 // (this can result in this object being freed). | 171 // (this can result in this object being freed). |
| 191 if (connect_listener_) { | 172 if (connect_listener_) { |
| 192 connect_listener_->connected(); | 173 connect_listener_->connected(); |
| 193 } | 174 } |
| 194 } | 175 } |
| OLD | NEW |