 Chromium Code Reviews
 Chromium Code Reviews Issue 984853003:
  Service Worker: Clients.openWindow() should allow opening x-origin URLs  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 984853003:
  Service Worker: Clients.openWindow() should allow opening x-origin URLs  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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/stl_util.h" | 9 #include "base/stl_util.h" | 
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" | 
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 url, Referrer::SanitizeForRequest( | 262 url, Referrer::SanitizeForRequest( | 
| 263 url, Referrer(script_url, blink::WebReferrerPolicyDefault)), | 263 url, Referrer(script_url, blink::WebReferrerPolicyDefault)), | 
| 264 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 264 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 
| 265 true /* is_renderer_initiated */); | 265 true /* is_renderer_initiated */); | 
| 266 | 266 | 
| 267 GetContentClient()->browser()->OpenURL( | 267 GetContentClient()->browser()->OpenURL( | 
| 268 browser_context, params, | 268 browser_context, params, | 
| 269 base::Bind(&DidOpenURL, callback)); | 269 base::Bind(&DidOpenURL, callback)); | 
| 270 } | 270 } | 
| 271 | 271 | 
| 272 void KillEmbeddedWorkerProcess(int process_id, ResultCode code) { | |
| 273 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 274 | |
| 275 RenderProcessHost* render_process_host = | |
| 276 RenderProcessHost::FromID(process_id); | |
| 277 if (render_process_host->GetHandle() != base::kNullProcessHandle) | |
| 278 render_process_host->ReceivedBadMessage(); | |
| 279 } | |
| 280 | |
| 281 } // namespace | 272 } // namespace | 
| 282 | 273 | 
| 283 ServiceWorkerVersion::ServiceWorkerVersion( | 274 ServiceWorkerVersion::ServiceWorkerVersion( | 
| 284 ServiceWorkerRegistration* registration, | 275 ServiceWorkerRegistration* registration, | 
| 285 const GURL& script_url, | 276 const GURL& script_url, | 
| 286 int64 version_id, | 277 int64 version_id, | 
| 287 base::WeakPtr<ServiceWorkerContextCore> context) | 278 base::WeakPtr<ServiceWorkerContextCore> context) | 
| 288 : version_id_(version_id), | 279 : version_id_(version_id), | 
| 289 registration_id_(kInvalidServiceWorkerVersionId), | 280 registration_id_(kInvalidServiceWorkerVersionId), | 
| 290 script_url_(script_url), | 281 script_url_(script_url), | 
| (...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1144 scoped_refptr<ServiceWorkerVersion> protect(this); | 1135 scoped_refptr<ServiceWorkerVersion> protect(this); | 
| 1145 callback->Run(SERVICE_WORKER_OK, accept_connection); | 1136 callback->Run(SERVICE_WORKER_OK, accept_connection); | 
| 1146 RemoveCallbackAndStopIfDoomed(&cross_origin_connect_callbacks_, request_id); | 1137 RemoveCallbackAndStopIfDoomed(&cross_origin_connect_callbacks_, request_id); | 
| 1147 } | 1138 } | 
| 1148 | 1139 | 
| 1149 void ServiceWorkerVersion::OnOpenWindow(int request_id, const GURL& url) { | 1140 void ServiceWorkerVersion::OnOpenWindow(int request_id, const GURL& url) { | 
| 1150 // Just abort if we are shutting down. | 1141 // Just abort if we are shutting down. | 
| 1151 if (!context_) | 1142 if (!context_) | 
| 1152 return; | 1143 return; | 
| 1153 | 1144 | 
| 1154 if (url.GetOrigin() != script_url_.GetOrigin()) { | |
| 1155 // There should be a same origin check by Blink, if the request is still not | |
| 1156 // same origin, the process might be compromised and should be eliminated. | |
| 1157 DVLOG(1) << "Received a cross origin openWindow() request from a service " | |
| 1158 "worker. Killing associated process."; | |
| 1159 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 1160 base::Bind(&KillEmbeddedWorkerProcess, | |
| 1161 embedded_worker_->process_id(), | |
| 1162 RESULT_CODE_KILLED_BAD_MESSAGE)); | |
| 1163 return; | |
| 1164 } | |
| 1165 | |
| 1166 BrowserThread::PostTask( | 1145 BrowserThread::PostTask( | 
| 1167 BrowserThread::UI, FROM_HERE, | 1146 BrowserThread::UI, FROM_HERE, | 
| 1168 base::Bind(&OpenWindowOnUI, | 1147 base::Bind(&OpenWindowOnUI, | 
| 1169 url, | 1148 url, | 
| 1170 script_url_, | 1149 script_url_, | 
| 1171 embedded_worker_->process_id(), | 1150 embedded_worker_->process_id(), | 
| 1172 make_scoped_refptr(context_->wrapper()), | 1151 make_scoped_refptr(context_->wrapper()), | 
| 1173 base::Bind(&ServiceWorkerVersion::DidOpenWindow, | 1152 base::Bind(&ServiceWorkerVersion::DidOpenWindow, | 
| 1174 weak_factory_.GetWeakPtr(), | 1153 weak_factory_.GetWeakPtr(), | 
| 1175 request_id))); | 1154 request_id, | 
| 1155 url))); | |
| 
jsbell
2015/03/06 16:59:36
I agree this matches the spec, but it's a little w
 
jungkees
2015/03/09 05:53:01
Filed: https://github.com/slightlyoff/ServiceWorke
 | |
| 1176 } | 1156 } | 
| 1177 | 1157 | 
| 1178 void ServiceWorkerVersion::DidOpenWindow(int request_id, | 1158 void ServiceWorkerVersion::DidOpenWindow(int request_id, | 
| 1159 const GURL& url, | |
| 1179 int render_process_id, | 1160 int render_process_id, | 
| 1180 int render_frame_id) { | 1161 int render_frame_id) { | 
| 1181 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1162 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
| 1182 | 1163 | 
| 1183 if (running_status() != RUNNING) | 1164 if (running_status() != RUNNING) | 
| 1184 return; | 1165 return; | 
| 1185 | 1166 | 
| 1186 if (render_process_id == ChildProcessHost::kInvalidUniqueID && | 1167 if (render_process_id == ChildProcessHost::kInvalidUniqueID && | 
| 1187 render_frame_id == MSG_ROUTING_NONE) { | 1168 render_frame_id == MSG_ROUTING_NONE) { | 
| 1188 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowError(request_id)); | 1169 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowError(request_id)); | 
| 1189 return; | 1170 return; | 
| 1190 } | 1171 } | 
| 1191 | 1172 | 
| 1192 for (const auto& it : controllee_map_) { | 1173 for (const auto& it : controllee_map_) { | 
| 1193 const ServiceWorkerProviderHost* provider_host = it.first; | 1174 const ServiceWorkerProviderHost* provider_host = it.first; | 
| 1194 if (provider_host->process_id() != render_process_id || | 1175 if (provider_host->process_id() != render_process_id || | 
| 1195 provider_host->frame_id() != render_frame_id) { | 1176 provider_host->frame_id() != render_frame_id) { | 
| 1196 continue; | 1177 continue; | 
| 1197 } | 1178 } | 
| 1198 | 1179 | 
| 1199 // it.second is the client_id associated with the provider_host. | 1180 // it.second is the client_id associated with the provider_host. | 
| 1200 provider_host->GetClientInfo( | 1181 provider_host->GetClientInfo( | 
| 1201 base::Bind(&ServiceWorkerVersion::OnOpenWindowFinished, | 1182 base::Bind(&ServiceWorkerVersion::OnOpenWindowFinished, | 
| 1202 weak_factory_.GetWeakPtr(), request_id, it.second)); | 1183 weak_factory_.GetWeakPtr(), request_id, url, it.second)); | 
| 1203 return; | 1184 return; | 
| 1204 } | 1185 } | 
| 1205 | 1186 | 
| 1206 // If here, it means that no provider_host was found, in which case, the | 1187 // If here, it means that no provider_host was found, in which case, the | 
| 1207 // renderer should still be informed that the window was opened. | 1188 // renderer should still be informed that the window was opened. | 
| 1208 OnOpenWindowFinished(request_id, 0, ServiceWorkerClientInfo()); | 1189 OnOpenWindowFinished(request_id, url, 0, ServiceWorkerClientInfo()); | 
| 1209 } | 1190 } | 
| 1210 | 1191 | 
| 1211 void ServiceWorkerVersion::OnOpenWindowFinished( | 1192 void ServiceWorkerVersion::OnOpenWindowFinished( | 
| 1212 int request_id, | 1193 int request_id, | 
| 1194 const GURL& url, | |
| 1213 int client_id, | 1195 int client_id, | 
| 1214 const ServiceWorkerClientInfo& client_info) { | 1196 const ServiceWorkerClientInfo& client_info) { | 
| 1215 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1197 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
| 1216 | 1198 | 
| 1217 if (running_status() != RUNNING) | 1199 if (running_status() != RUNNING) | 
| 1218 return; | 1200 return; | 
| 1219 | 1201 | 
| 1220 ServiceWorkerClientInfo client(client_info); | 1202 ServiceWorkerClientInfo client(client_info); | 
| 1221 | 1203 | 
| 1222 // If the |client_info| is empty, it means that the opened window wasn't | 1204 // If the |client_info| is empty, it means that the opened window wasn't | 
| 1223 // controlled but the action still succeeded. The renderer process is | 1205 // controlled but the action still succeeded. The renderer process is | 
| 1224 // expecting an empty client in such case. | 1206 // expecting an empty client in such case. | 
| 1225 if (!client.IsEmpty()) | 1207 if (!client.IsEmpty()) | 
| 1226 client.client_id = client_id; | 1208 client.client_id = client_id; | 
| 1227 | 1209 | 
| 1228 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowResponse( | 1210 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowResponse( | 
| 1229 request_id, client)); | 1211 request_id, url, client)); | 
| 1230 } | 1212 } | 
| 1231 | 1213 | 
| 1232 void ServiceWorkerVersion::OnSetCachedMetadata(const GURL& url, | 1214 void ServiceWorkerVersion::OnSetCachedMetadata(const GURL& url, | 
| 1233 const std::vector<char>& data) { | 1215 const std::vector<char>& data) { | 
| 1234 int64 callback_id = base::TimeTicks::Now().ToInternalValue(); | 1216 int64 callback_id = base::TimeTicks::Now().ToInternalValue(); | 
| 1235 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 1217 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 
| 1236 "ServiceWorkerVersion::OnSetCachedMetadata", | 1218 "ServiceWorkerVersion::OnSetCachedMetadata", | 
| 1237 callback_id, "URL", url.spec()); | 1219 callback_id, "URL", url.spec()); | 
| 1238 script_cache_map_.WriteMetadata( | 1220 script_cache_map_.WriteMetadata( | 
| 1239 url, data, base::Bind(&ServiceWorkerVersion::OnSetCachedMetadataFinished, | 1221 url, data, base::Bind(&ServiceWorkerVersion::OnSetCachedMetadataFinished, | 
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1501 int request_id) { | 1483 int request_id) { | 
| 1502 callbacks->Remove(request_id); | 1484 callbacks->Remove(request_id); | 
| 1503 if (is_doomed_) { | 1485 if (is_doomed_) { | 
| 1504 // The stop should be already scheduled, but try to stop immediately, in | 1486 // The stop should be already scheduled, but try to stop immediately, in | 
| 1505 // order to release worker resources soon. | 1487 // order to release worker resources soon. | 
| 1506 StopWorkerIfIdle(); | 1488 StopWorkerIfIdle(); | 
| 1507 } | 1489 } | 
| 1508 } | 1490 } | 
| 1509 | 1491 | 
| 1510 } // namespace content | 1492 } // namespace content | 
| OLD | NEW |