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/webworker_stub.h" | 5 #include "chrome/worker/webworker_stub.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/common/child_thread.h" |
8 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "chrome/common/file_system/file_system_dispatcher.h" |
9 #include "chrome/common/webmessageportchannel_impl.h" | 11 #include "chrome/common/webmessageportchannel_impl.h" |
10 #include "chrome/common/worker_messages.h" | 12 #include "chrome/common/worker_messages.h" |
11 #include "chrome/worker/nativewebworker_impl.h" | 13 #include "chrome/worker/nativewebworker_impl.h" |
12 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
13 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" | 15 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
14 #include "third_party/WebKit/WebKit/chromium/public/WebWorker.h" | 16 #include "third_party/WebKit/WebKit/chromium/public/WebWorker.h" |
15 | 17 |
16 using WebKit::WebWorker; | 18 using WebKit::WebWorker; |
17 | 19 |
18 static bool UrlIsNativeWorker(const GURL& url) { | 20 static bool UrlIsNativeWorker(const GURL& url) { |
19 // If the renderer was not passed the switch to enable native workers, | 21 // If the renderer was not passed the switch to enable native workers, |
20 // then the URL should be treated as a JavaScript worker. | 22 // then the URL should be treated as a JavaScript worker. |
21 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 23 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
22 switches::kEnableNativeWebWorkers)) { | 24 switches::kEnableNativeWebWorkers)) { |
23 return false; | 25 return false; |
24 } | 26 } |
25 // Based on the suffix, decide whether the url should be considered | 27 // Based on the suffix, decide whether the url should be considered |
26 // a NativeWebWorker (for .nexe) or a WebWorker (for anything else). | 28 // a NativeWebWorker (for .nexe) or a WebWorker (for anything else). |
27 const std::string kNativeSuffix(".nexe"); | 29 const std::string kNativeSuffix(".nexe"); |
28 std::string worker_url = url.path(); | 30 std::string worker_url = url.path(); |
29 // Compute the start index of the suffix. | 31 // Compute the start index of the suffix. |
30 std::string::size_type suffix_index = | 32 std::string::size_type suffix_index = |
31 worker_url.length() - kNativeSuffix.length(); | 33 worker_url.length() - kNativeSuffix.length(); |
32 std::string::size_type pos = worker_url.find(kNativeSuffix, suffix_index); | 34 std::string::size_type pos = worker_url.find(kNativeSuffix, suffix_index); |
33 return (suffix_index == pos); | 35 return (suffix_index == pos); |
34 } | 36 } |
35 | 37 |
36 WebWorkerStub::WebWorkerStub(const GURL& url, int route_id, | 38 WebWorkerStub::WebWorkerStub(const GURL& url, int route_id, |
37 const WorkerAppCacheInitInfo& appcache_init_info) | 39 const WorkerAppCacheInitInfo& appcache_init_info) |
38 : WebWorkerStubBase(route_id, appcache_init_info) { | 40 : WebWorkerStubBase(route_id, appcache_init_info), |
| 41 url_(url) { |
39 if (UrlIsNativeWorker(url)) { | 42 if (UrlIsNativeWorker(url)) { |
40 // Launch a native worker. | 43 // Launch a native worker. |
41 impl_ = NativeWebWorkerImpl::create(client()); | 44 impl_ = NativeWebWorkerImpl::create(client()); |
42 } else { | 45 } else { |
43 // Launch a JavaScript worker. | 46 // Launch a JavaScript worker. |
44 impl_ = WebKit::WebWorker::create(client()); | 47 impl_ = WebKit::WebWorker::create(client()); |
45 } | 48 } |
46 } | 49 } |
47 | 50 |
48 WebWorkerStub::~WebWorkerStub() { | 51 WebWorkerStub::~WebWorkerStub() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 const std::vector<int>& sent_message_port_ids, | 83 const std::vector<int>& sent_message_port_ids, |
81 const std::vector<int>& new_routing_ids) { | 84 const std::vector<int>& new_routing_ids) { |
82 WebKit::WebMessagePortChannelArray channels(sent_message_port_ids.size()); | 85 WebKit::WebMessagePortChannelArray channels(sent_message_port_ids.size()); |
83 for (size_t i = 0; i < sent_message_port_ids.size(); i++) { | 86 for (size_t i = 0; i < sent_message_port_ids.size(); i++) { |
84 channels[i] = new WebMessagePortChannelImpl( | 87 channels[i] = new WebMessagePortChannelImpl( |
85 new_routing_ids[i], sent_message_port_ids[i]); | 88 new_routing_ids[i], sent_message_port_ids[i]); |
86 } | 89 } |
87 | 90 |
88 impl_->postMessageToWorkerContext(message, channels); | 91 impl_->postMessageToWorkerContext(message, channels); |
89 } | 92 } |
OLD | NEW |