Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/service_worker/service_worker_version.h" | 5 #include "content/browser/service_worker/service_worker_version.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "content/browser/child_process_security_policy_impl.h" | |
| 14 #include "content/browser/message_port_message_filter.h" | 15 #include "content/browser/message_port_message_filter.h" |
| 15 #include "content/browser/message_port_service.h" | 16 #include "content/browser/message_port_service.h" |
| 16 #include "content/browser/service_worker/embedded_worker_instance.h" | 17 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 17 #include "content/browser/service_worker/embedded_worker_registry.h" | 18 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 18 #include "content/browser/service_worker/service_worker_context_core.h" | 19 #include "content/browser/service_worker/service_worker_context_core.h" |
| 19 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 20 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 20 #include "content/browser/service_worker/service_worker_registration.h" | 21 #include "content/browser/service_worker/service_worker_registration.h" |
| 21 #include "content/browser/service_worker/service_worker_utils.h" | 22 #include "content/browser/service_worker/service_worker_utils.h" |
| 22 #include "content/browser/storage_partition_impl.h" | 23 #include "content/browser/storage_partition_impl.h" |
| 23 #include "content/common/service_worker/service_worker_messages.h" | 24 #include "content/common/service_worker/service_worker_messages.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 url, Referrer::SanitizeForRequest( | 265 url, Referrer::SanitizeForRequest( |
| 265 url, Referrer(script_url, blink::WebReferrerPolicyDefault)), | 266 url, Referrer(script_url, blink::WebReferrerPolicyDefault)), |
| 266 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 267 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 267 true /* is_renderer_initiated */); | 268 true /* is_renderer_initiated */); |
| 268 | 269 |
| 269 GetContentClient()->browser()->OpenURL( | 270 GetContentClient()->browser()->OpenURL( |
| 270 browser_context, params, | 271 browser_context, params, |
| 271 base::Bind(&DidOpenURL, callback)); | 272 base::Bind(&DidOpenURL, callback)); |
| 272 } | 273 } |
| 273 | 274 |
| 274 void KillEmbeddedWorkerProcess(int process_id, ResultCode code) { | |
| 275 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 276 | |
| 277 RenderProcessHost* render_process_host = | |
| 278 RenderProcessHost::FromID(process_id); | |
| 279 if (render_process_host->GetHandle() != base::kNullProcessHandle) | |
| 280 render_process_host->ReceivedBadMessage(); | |
| 281 } | |
| 282 | |
| 283 void ClearTick(base::TimeTicks* time) { | 275 void ClearTick(base::TimeTicks* time) { |
| 284 *time = base::TimeTicks(); | 276 *time = base::TimeTicks(); |
| 285 } | 277 } |
| 286 | 278 |
| 287 void RestartTick(base::TimeTicks* time) { | 279 void RestartTick(base::TimeTicks* time) { |
| 288 *time = base::TimeTicks().Now(); | 280 *time = base::TimeTicks().Now(); |
| 289 } | 281 } |
| 290 | 282 |
| 291 base::TimeDelta GetTickDuration(const base::TimeTicks& time) { | 283 base::TimeDelta GetTickDuration(const base::TimeTicks& time) { |
| 292 if (time.is_null()) | 284 if (time.is_null()) |
| (...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1164 scoped_refptr<ServiceWorkerVersion> protect(this); | 1156 scoped_refptr<ServiceWorkerVersion> protect(this); |
| 1165 callback->Run(SERVICE_WORKER_OK, accept_connection); | 1157 callback->Run(SERVICE_WORKER_OK, accept_connection); |
| 1166 RemoveCallbackAndStopIfDoomed(&cross_origin_connect_callbacks_, request_id); | 1158 RemoveCallbackAndStopIfDoomed(&cross_origin_connect_callbacks_, request_id); |
| 1167 } | 1159 } |
| 1168 | 1160 |
| 1169 void ServiceWorkerVersion::OnOpenWindow(int request_id, const GURL& url) { | 1161 void ServiceWorkerVersion::OnOpenWindow(int request_id, const GURL& url) { |
| 1170 // Just abort if we are shutting down. | 1162 // Just abort if we are shutting down. |
| 1171 if (!context_) | 1163 if (!context_) |
| 1172 return; | 1164 return; |
| 1173 | 1165 |
| 1174 if (url.GetOrigin() != script_url_.GetOrigin()) { | 1166 GURL sanitized_url = url; |
| 1175 // There should be a same origin check by Blink, if the request is still not | 1167 |
| 1176 // same origin, the process might be compromised and should be eliminated. | 1168 // Blink consider all about: scheme URLs as about:blank. We need to sanitize |
| 1177 DVLOG(1) << "Received a cross origin openWindow() request from a service " | 1169 // them accordingly to prevent CanRequestURL() call below to fail on them. |
| 1178 "worker. Killing associated process."; | 1170 if (sanitized_url.SchemeIs(url::kAboutScheme)) |
| 1179 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 1171 sanitized_url = GURL(url::kAboutBlankURL); |
| 1180 base::Bind(&KillEmbeddedWorkerProcess, | 1172 |
| 1181 embedded_worker_->process_id(), | 1173 // This call will check whether the process should be able to access the given |
| 1182 RESULT_CODE_KILLED_BAD_MESSAGE)); | 1174 // URL. It is possible to receive requests to open such URLs because the |
| 1183 return; | 1175 // renderer side checks are slightly different. For example, view-source |
| 1176 // scheme will not be filtered out by Blink. | |
| 1177 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL( | |
| 1178 embedded_worker_->process_id(), sanitized_url)) { | |
| 1179 sanitized_url = GURL(url::kAboutBlankURL); | |
|
michaeln
2015/03/06 23:26:03
Are you sure about opening about:blank in this cas
mlamouri (slow - plz ping)
2015/03/06 23:40:40
Just to make sure it's clear: the CanRequestURL()
| |
| 1184 } | 1180 } |
| 1185 | 1181 |
| 1186 BrowserThread::PostTask( | 1182 BrowserThread::PostTask( |
| 1187 BrowserThread::UI, FROM_HERE, | 1183 BrowserThread::UI, FROM_HERE, |
| 1188 base::Bind(&OpenWindowOnUI, | 1184 base::Bind(&OpenWindowOnUI, |
| 1189 url, | 1185 sanitized_url, |
| 1190 script_url_, | 1186 script_url_, |
| 1191 embedded_worker_->process_id(), | 1187 embedded_worker_->process_id(), |
| 1192 make_scoped_refptr(context_->wrapper()), | 1188 make_scoped_refptr(context_->wrapper()), |
| 1193 base::Bind(&ServiceWorkerVersion::DidOpenWindow, | 1189 base::Bind(&ServiceWorkerVersion::DidOpenWindow, |
| 1194 weak_factory_.GetWeakPtr(), | 1190 weak_factory_.GetWeakPtr(), |
| 1195 request_id))); | 1191 request_id))); |
| 1196 } | 1192 } |
| 1197 | 1193 |
| 1198 void ServiceWorkerVersion::DidOpenWindow(int request_id, | 1194 void ServiceWorkerVersion::DidOpenWindow(int request_id, |
| 1199 int render_process_id, | 1195 int render_process_id, |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1587 int request_id) { | 1583 int request_id) { |
| 1588 callbacks->Remove(request_id); | 1584 callbacks->Remove(request_id); |
| 1589 if (is_doomed_) { | 1585 if (is_doomed_) { |
| 1590 // The stop should be already scheduled, but try to stop immediately, in | 1586 // The stop should be already scheduled, but try to stop immediately, in |
| 1591 // order to release worker resources soon. | 1587 // order to release worker resources soon. |
| 1592 StopWorkerIfIdle(); | 1588 StopWorkerIfIdle(); |
| 1593 } | 1589 } |
| 1594 } | 1590 } |
| 1595 | 1591 |
| 1596 } // namespace content | 1592 } // namespace content |
| OLD | NEW |