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 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1159 if (!callback) { | 1151 if (!callback) { |
1160 NOTREACHED() << "Got unexpected message: " << request_id; | 1152 NOTREACHED() << "Got unexpected message: " << request_id; |
1161 return; | 1153 return; |
1162 } | 1154 } |
1163 | 1155 |
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, 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; |
falken
2015/03/08 15:01:50
We should kill the renderer if !url.is_valid(). It
mlamouri (slow - plz ping)
2015/03/08 17:53:56
Very good point. That actually crossed my mind the
| |
1173 | 1165 |
1174 if (url.GetOrigin() != script_url_.GetOrigin()) { | 1166 // The renderer treats all URLs in the about: scheme as being about:blank. |
1175 // There should be a same origin check by Blink, if the request is still not | 1167 // Canonicalize about: URLs to about:blank. |
1176 // same origin, the process might be compromised and should be eliminated. | 1168 if (url.SchemeIs(url::kAboutScheme)) |
1177 DVLOG(1) << "Received a cross origin openWindow() request from a service " | 1169 url = GURL(url::kAboutBlankURL); |
1178 "worker. Killing associated process."; | 1170 |
1179 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 1171 //Reject requests for URLs that the process is not allowed to access. It's |
falken
2015/03/08 15:01:50
nit: space after //
mlamouri (slow - plz ping)
2015/03/08 17:53:56
Done.
| |
1180 base::Bind(&KillEmbeddedWorkerProcess, | 1172 // possible to receive such requests since the renderer-side checks are |
1181 embedded_worker_->process_id(), | 1173 // slightly different. For example, the view-source scheme will not be |
1182 RESULT_CODE_KILLED_BAD_MESSAGE)); | 1174 // filtered out by Blink. |
1175 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL( | |
1176 embedded_worker_->process_id(), url)) { | |
1177 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowError( | |
1178 request_id, url.spec() + " cannot be opened.")); | |
1183 return; | 1179 return; |
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 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, |
1200 int render_frame_id) { | 1196 int render_frame_id) { |
1201 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1197 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1202 | 1198 |
1203 if (running_status() != RUNNING) | 1199 if (running_status() != RUNNING) |
1204 return; | 1200 return; |
1205 | 1201 |
1206 if (render_process_id == ChildProcessHost::kInvalidUniqueID && | 1202 if (render_process_id == ChildProcessHost::kInvalidUniqueID && |
1207 render_frame_id == MSG_ROUTING_NONE) { | 1203 render_frame_id == MSG_ROUTING_NONE) { |
1208 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowError(request_id)); | 1204 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowError( |
1205 request_id, "Something went wrong while trying to open the window.")); | |
1209 return; | 1206 return; |
1210 } | 1207 } |
1211 | 1208 |
1212 for (const auto& it : controllee_map_) { | 1209 for (const auto& it : controllee_map_) { |
1213 const ServiceWorkerProviderHost* provider_host = it.first; | 1210 const ServiceWorkerProviderHost* provider_host = it.first; |
1214 if (provider_host->process_id() != render_process_id || | 1211 if (provider_host->process_id() != render_process_id || |
1215 provider_host->frame_id() != render_frame_id) { | 1212 provider_host->frame_id() != render_frame_id) { |
1216 continue; | 1213 continue; |
1217 } | 1214 } |
1218 | 1215 |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1587 int request_id) { | 1584 int request_id) { |
1588 callbacks->Remove(request_id); | 1585 callbacks->Remove(request_id); |
1589 if (is_doomed_) { | 1586 if (is_doomed_) { |
1590 // The stop should be already scheduled, but try to stop immediately, in | 1587 // The stop should be already scheduled, but try to stop immediately, in |
1591 // order to release worker resources soon. | 1588 // order to release worker resources soon. |
1592 StopWorkerIfIdle(); | 1589 StopWorkerIfIdle(); |
1593 } | 1590 } |
1594 } | 1591 } |
1595 | 1592 |
1596 } // namespace content | 1593 } // namespace content |
OLD | NEW |