| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/shared_worker/shared_worker_host.h" | 5 #include "content/browser/shared_worker/shared_worker_host.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/strings/string_split.h" |
| 9 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/devtools/embedded_worker_devtools_manager.h" | 10 #include "content/browser/devtools/embedded_worker_devtools_manager.h" |
| 9 #include "content/browser/frame_host/render_frame_host_delegate.h" | 11 #include "content/browser/frame_host/render_frame_host_delegate.h" |
| 10 #include "content/browser/frame_host/render_frame_host_impl.h" | 12 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 11 #include "content/browser/message_port_service.h" | 13 #include "content/browser/message_port_service.h" |
| 12 #include "content/browser/shared_worker/shared_worker_instance.h" | 14 #include "content/browser/shared_worker/shared_worker_instance.h" |
| 13 #include "content/browser/shared_worker/shared_worker_message_filter.h" | 15 #include "content/browser/shared_worker/shared_worker_message_filter.h" |
| 14 #include "content/browser/shared_worker/shared_worker_service_impl.h" | 16 #include "content/browser/shared_worker/shared_worker_service_impl.h" |
| 15 #include "content/browser/shared_worker/worker_document_set.h" | 17 #include "content/browser/shared_worker/worker_document_set.h" |
| 16 #include "content/common/view_messages.h" | 18 #include "content/common/view_messages.h" |
| 17 #include "content/common/worker_messages.h" | 19 #include "content/common/worker_messages.h" |
| 18 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/content_browser_client.h" | 21 #include "content/public/browser/content_browser_client.h" |
| 20 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| 23 #include "content/public/browser/resource_context.h" |
| 21 #include "content/public/common/content_client.h" | 24 #include "content/public/common/content_client.h" |
| 25 #include "net/url_request/static_http_user_agent_settings.h" |
| 26 #include "net/url_request/url_request_context.h" |
| 22 | 27 |
| 23 namespace content { | 28 namespace content { |
| 24 namespace { | 29 namespace { |
| 25 | 30 |
| 26 // Notifies RenderViewHost that one or more worker objects crashed. | 31 // Notifies RenderViewHost that one or more worker objects crashed. |
| 27 void WorkerCrashCallback(int render_process_unique_id, int render_frame_id) { | 32 void WorkerCrashCallback(int render_process_unique_id, int render_frame_id) { |
| 28 RenderFrameHostImpl* host = | 33 RenderFrameHostImpl* host = |
| 29 RenderFrameHostImpl::FromID(render_process_unique_id, render_frame_id); | 34 RenderFrameHostImpl::FromID(render_process_unique_id, render_frame_id); |
| 30 if (host) | 35 if (host) |
| 31 host->delegate()->WorkerCrashed(host); | 36 host->delegate()->WorkerCrashed(host); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 FROM_HERE, | 70 FROM_HERE, |
| 66 base::Bind(NotifyWorkerDestroyed, worker_process_id, worker_route_id)); | 71 base::Bind(NotifyWorkerDestroyed, worker_process_id, worker_route_id)); |
| 67 return; | 72 return; |
| 68 } | 73 } |
| 69 EmbeddedWorkerDevToolsManager::GetInstance()->WorkerDestroyed( | 74 EmbeddedWorkerDevToolsManager::GetInstance()->WorkerDestroyed( |
| 70 worker_process_id, worker_route_id); | 75 worker_process_id, worker_route_id); |
| 71 } | 76 } |
| 72 | 77 |
| 73 } // namespace | 78 } // namespace |
| 74 | 79 |
| 80 static std::string HttpAcceptHeaderToAcceptLanguagesString( |
| 81 const std::string& http_accept_languages,const std::string& default_language) |
| 82 { |
| 83 std::vector<string> languages; |
| 84 |
| 85 if (!http_accept_languages.length()) { |
| 86 return default_language; |
| 87 } |
| 88 base::SplitString(http_accept_languages, ',', &languages); |
| 89 |
| 90 std::string accept_languages_string; |
| 91 for(unsigned int i = 0; i < languages.size(); i++) { |
| 92 std::string lang = languages[i]; |
| 93 size_t semi_colon_pos = lang.find(";"); |
| 94 if(semi_colon_pos != string::npos) |
| 95 lang.erase(semi_colon_pos, lang.length() - semi_colon_pos); |
| 96 accept_languages_string.append(lang); |
| 97 if(i != languages.size() - 1){ |
| 98 accept_languages_string.append(1, ','); |
| 99 } |
| 100 } |
| 101 return accept_languages_string; |
| 102 } |
| 103 |
| 75 SharedWorkerHost::SharedWorkerHost(SharedWorkerInstance* instance, | 104 SharedWorkerHost::SharedWorkerHost(SharedWorkerInstance* instance, |
| 76 SharedWorkerMessageFilter* filter, | 105 SharedWorkerMessageFilter* filter, |
| 77 int worker_route_id) | 106 int worker_route_id) |
| 78 : instance_(instance), | 107 : instance_(instance), |
| 79 worker_document_set_(new WorkerDocumentSet()), | 108 worker_document_set_(new WorkerDocumentSet()), |
| 80 container_render_filter_(filter), | 109 container_render_filter_(filter), |
| 81 worker_process_id_(filter->render_process_id()), | 110 worker_process_id_(filter->render_process_id()), |
| 82 worker_route_id_(worker_route_id), | 111 worker_route_id_(worker_route_id), |
| 83 load_failed_(false), | 112 load_failed_(false), |
| 84 closed_(false), | 113 closed_(false), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 150 } |
| 122 | 151 |
| 123 void SharedWorkerHost::Start(bool pause_on_start) { | 152 void SharedWorkerHost::Start(bool pause_on_start) { |
| 124 WorkerProcessMsg_CreateWorker_Params params; | 153 WorkerProcessMsg_CreateWorker_Params params; |
| 125 params.url = instance_->url(); | 154 params.url = instance_->url(); |
| 126 params.name = instance_->name(); | 155 params.name = instance_->name(); |
| 127 params.content_security_policy = instance_->content_security_policy(); | 156 params.content_security_policy = instance_->content_security_policy(); |
| 128 params.security_policy_type = instance_->security_policy_type(); | 157 params.security_policy_type = instance_->security_policy_type(); |
| 129 params.pause_on_start = pause_on_start; | 158 params.pause_on_start = pause_on_start; |
| 130 params.route_id = worker_route_id_; | 159 params.route_id = worker_route_id_; |
| 160 net::URLRequestContext* req_context = |
| 161 instance_->resource_context()->GetRequestContext(); |
| 162 std::string accept_languages_string = HttpAcceptHeaderToAcceptLanguagesString( |
| 163 req_context->http_user_agent_settings()->GetAcceptLanguage() |
| 164 , GetContentClient()->browser()->GetApplicationLocale()); |
| 165 params.accept_languages = base::UTF8ToUTF16(accept_languages_string); |
| 131 Send(new WorkerProcessMsg_CreateWorker(params)); | 166 Send(new WorkerProcessMsg_CreateWorker(params)); |
| 132 | 167 |
| 133 for (FilterList::const_iterator i = filters_.begin(); i != filters_.end(); | 168 for (FilterList::const_iterator i = filters_.begin(); i != filters_.end(); |
| 134 ++i) { | 169 ++i) { |
| 135 i->filter()->Send(new ViewMsg_WorkerCreated(i->route_id())); | 170 i->filter()->Send(new ViewMsg_WorkerCreated(i->route_id())); |
| 136 } | 171 } |
| 137 } | 172 } |
| 138 | 173 |
| 139 bool SharedWorkerHost::FilterMessage(const IPC::Message& message, | 174 bool SharedWorkerHost::FilterMessage(const IPC::Message& message, |
| 140 SharedWorkerMessageFilter* filter) { | 175 SharedWorkerMessageFilter* filter) { |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 int route_id, | 394 int route_id, |
| 360 int message_port_id) { | 395 int message_port_id) { |
| 361 for (FilterList::iterator i = filters_.begin(); i != filters_.end(); ++i) { | 396 for (FilterList::iterator i = filters_.begin(); i != filters_.end(); ++i) { |
| 362 if (i->filter() == filter && i->route_id() == route_id) { | 397 if (i->filter() == filter && i->route_id() == route_id) { |
| 363 i->set_message_port_id(message_port_id); | 398 i->set_message_port_id(message_port_id); |
| 364 return; | 399 return; |
| 365 } | 400 } |
| 366 } | 401 } |
| 367 } | 402 } |
| 368 | 403 |
| 404 void SharedWorkerHost::AcceptLanguageChanged(const base::string16& languages) |
| 405 { |
| 406 WorkerProcessMsg_LanguageChange_Params params; |
| 407 params.route_id = worker_route_id_; |
| 408 net::URLRequestContext* req_context = |
| 409 instance_->resource_context()->GetRequestContext(); |
| 410 std::string accept_languages_string = HttpAcceptHeaderToAcceptLanguagesString( |
| 411 req_context->http_user_agent_settings()->GetAcceptLanguage() |
| 412 , GetContentClient()->browser()->GetApplicationLocale()); |
| 413 params.accept_languages = base::UTF8ToUTF16(accept_languages_string); |
| 414 Send(new WorkerProcessMsg_LanguageChange(params)); |
| 415 } |
| 416 |
| 417 |
| 369 } // namespace content | 418 } // namespace content |
| OLD | NEW |