Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: content/browser/service_worker/service_worker_version.cc

Issue 1335303004: ServiceWorker: Fix the bug in navigate() if windowclient is nested frame. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/guid.h" 12 #include "base/guid.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/strings/string16.h" 18 #include "base/strings/string16.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/thread_task_runner_handle.h" 20 #include "base/thread_task_runner_handle.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "content/browser/bad_message.h" 22 #include "content/browser/bad_message.h"
23 #include "content/browser/child_process_security_policy_impl.h" 23 #include "content/browser/child_process_security_policy_impl.h"
24 #include "content/browser/frame_host/frame_tree_node.h"
25 #include "content/browser/frame_host/render_frame_host_impl.h"
24 #include "content/browser/message_port_message_filter.h" 26 #include "content/browser/message_port_message_filter.h"
25 #include "content/browser/message_port_service.h" 27 #include "content/browser/message_port_service.h"
26 #include "content/browser/service_worker/embedded_worker_instance.h" 28 #include "content/browser/service_worker/embedded_worker_instance.h"
27 #include "content/browser/service_worker/embedded_worker_registry.h" 29 #include "content/browser/service_worker/embedded_worker_registry.h"
28 #include "content/browser/service_worker/service_worker_context_core.h" 30 #include "content/browser/service_worker/service_worker_context_core.h"
29 #include "content/browser/service_worker/service_worker_context_wrapper.h" 31 #include "content/browser/service_worker/service_worker_context_wrapper.h"
30 #include "content/browser/service_worker/service_worker_metrics.h" 32 #include "content/browser/service_worker/service_worker_metrics.h"
31 #include "content/browser/service_worker/service_worker_registration.h" 33 #include "content/browser/service_worker/service_worker_registration.h"
32 #include "content/browser/storage_partition_impl.h" 34 #include "content/browser/storage_partition_impl.h"
33 #include "content/common/service_worker/service_worker_messages.h" 35 #include "content/common/service_worker/service_worker_messages.h"
34 #include "content/common/service_worker/service_worker_type_converters.h" 36 #include "content/common/service_worker/service_worker_type_converters.h"
35 #include "content/common/service_worker/service_worker_utils.h" 37 #include "content/common/service_worker/service_worker_utils.h"
36 #include "content/public/browser/browser_thread.h" 38 #include "content/public/browser/browser_thread.h"
37 #include "content/public/browser/content_browser_client.h" 39 #include "content/public/browser/content_browser_client.h"
38 #include "content/public/browser/page_navigator.h" 40 #include "content/public/browser/page_navigator.h"
39 #include "content/public/browser/render_frame_host.h"
40 #include "content/public/browser/render_process_host.h" 41 #include "content/public/browser/render_process_host.h"
41 #include "content/public/browser/web_contents.h" 42 #include "content/public/browser/web_contents.h"
42 #include "content/public/browser/web_contents_observer.h" 43 #include "content/public/browser/web_contents_observer.h"
43 #include "content/public/common/background_sync.mojom.h" 44 #include "content/public/common/background_sync.mojom.h"
44 #include "content/public/common/child_process_host.h" 45 #include "content/public/common/child_process_host.h"
45 #include "content/public/common/content_client.h" 46 #include "content/public/common/content_client.h"
46 #include "content/public/common/content_switches.h" 47 #include "content/public/common/content_switches.h"
47 #include "content/public/common/result_codes.h" 48 #include "content/public/common/result_codes.h"
48 #include "content/public/common/service_registry.h" 49 #include "content/public/common/service_registry.h"
49 #include "mojo/common/common_type_converters.h" 50 #include "mojo/common/common_type_converters.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 using OpenURLCallback = base::Callback<void(int, int)>; 181 using OpenURLCallback = base::Callback<void(int, int)>;
181 182
182 // The OpenURLObserver class is a WebContentsObserver that will wait for a 183 // The OpenURLObserver class is a WebContentsObserver that will wait for a
183 // WebContents to be initialized, run the |callback| passed to its constructor 184 // WebContents to be initialized, run the |callback| passed to its constructor
184 // then self destroy. 185 // then self destroy.
185 // The callback will receive the process and frame ids. If something went wrong 186 // The callback will receive the process and frame ids. If something went wrong
186 // those will be (kInvalidUniqueID, MSG_ROUTING_NONE). 187 // those will be (kInvalidUniqueID, MSG_ROUTING_NONE).
187 // The callback will be called in the IO thread. 188 // The callback will be called in the IO thread.
188 class OpenURLObserver : public WebContentsObserver { 189 class OpenURLObserver : public WebContentsObserver {
189 public: 190 public:
190 OpenURLObserver(WebContents* web_contents, const OpenURLCallback& callback) 191 OpenURLObserver(WebContents* web_contents,
191 : WebContentsObserver(web_contents), callback_(callback) {} 192 int frame_tree_node_id,
193 const OpenURLCallback& callback)
194 : WebContentsObserver(web_contents),
195 frame_tree_node_id_(frame_tree_node_id),
196 callback_(callback) {}
192 197
193 void DidCommitProvisionalLoadForFrame( 198 void DidCommitProvisionalLoadForFrame(
194 RenderFrameHost* render_frame_host, 199 RenderFrameHost* render_frame_host,
195 const GURL& validated_url, 200 const GURL& validated_url,
196 ui::PageTransition transition_type) override { 201 ui::PageTransition transition_type) override {
197 DCHECK(web_contents()); 202 DCHECK(web_contents());
198 203
199 if (render_frame_host != web_contents()->GetMainFrame()) 204 RenderFrameHostImpl* rfhi =
205 static_cast<RenderFrameHostImpl*>(render_frame_host);
206 if (rfhi->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_)
200 return; 207 return;
201 208
202 RunCallback(render_frame_host->GetProcess()->GetID(), 209 RunCallback(render_frame_host->GetProcess()->GetID(),
203 render_frame_host->GetRoutingID()); 210 render_frame_host->GetRoutingID());
204 } 211 }
205 212
206 void RenderProcessGone(base::TerminationStatus status) override { 213 void RenderProcessGone(base::TerminationStatus status) override {
207 RunCallback(ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE); 214 RunCallback(ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE);
208 } 215 }
209 216
210 void WebContentsDestroyed() override { 217 void WebContentsDestroyed() override {
211 RunCallback(ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE); 218 RunCallback(ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE);
212 } 219 }
213 220
214 private: 221 private:
215 void RunCallback(int render_process_id, int render_frame_id) { 222 void RunCallback(int render_process_id, int render_frame_id) {
216 // After running the callback, |this| will stop observing, thus 223 // After running the callback, |this| will stop observing, thus
217 // web_contents() should return nullptr and |RunCallback| should no longer 224 // web_contents() should return nullptr and |RunCallback| should no longer
218 // be called. Then, |this| will self destroy. 225 // be called. Then, |this| will self destroy.
219 DCHECK(web_contents()); 226 DCHECK(web_contents());
220 227
221 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 228 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
222 base::Bind(callback_, 229 base::Bind(callback_,
223 render_process_id, 230 render_process_id,
224 render_frame_id)); 231 render_frame_id));
225 Observe(nullptr); 232 Observe(nullptr);
226 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 233 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
227 } 234 }
228 235
236 int frame_tree_node_id_;
229 const OpenURLCallback callback_; 237 const OpenURLCallback callback_;
230 238
231 DISALLOW_COPY_AND_ASSIGN(OpenURLObserver); 239 DISALLOW_COPY_AND_ASSIGN(OpenURLObserver);
232 }; 240 };
233 241
242 // This is only called for main frame navigations in OpenWindowOnUI().
234 void DidOpenURL(const OpenURLCallback& callback, WebContents* web_contents) { 243 void DidOpenURL(const OpenURLCallback& callback, WebContents* web_contents) {
235 DCHECK(web_contents); 244 DCHECK(web_contents);
236 245
237 new OpenURLObserver(web_contents, callback); 246 RenderFrameHostImpl* rfhi =
247 static_cast<RenderFrameHostImpl*>(web_contents->GetMainFrame());
248 new OpenURLObserver(web_contents,
249 rfhi->frame_tree_node()->frame_tree_node_id(), callback);
238 } 250 }
239 251
240 void NavigateClientOnUI(const GURL& url, 252 void NavigateClientOnUI(const GURL& url,
241 const GURL& script_url, 253 const GURL& script_url,
242 int process_id, 254 int process_id,
243 int frame_id, 255 int frame_id,
244 const OpenURLCallback& callback) { 256 const OpenURLCallback& callback) {
245 DCHECK_CURRENTLY_ON(BrowserThread::UI); 257 DCHECK_CURRENTLY_ON(BrowserThread::UI);
246 258
247 RenderFrameHost* render_frame_host = 259 RenderFrameHostImpl* rfhi = RenderFrameHostImpl::FromID(process_id, frame_id);
248 RenderFrameHost::FromID(process_id, frame_id); 260 WebContents* web_contents = WebContents::FromRenderFrameHost(rfhi);
249 WebContents* web_contents =
250 WebContents::FromRenderFrameHost(render_frame_host);
251 261
252 if (!render_frame_host || !web_contents) { 262 if (!rfhi || !web_contents) {
253 BrowserThread::PostTask( 263 BrowserThread::PostTask(
254 BrowserThread::IO, FROM_HERE, 264 BrowserThread::IO, FROM_HERE,
255 base::Bind(callback, ChildProcessHost::kInvalidUniqueID, 265 base::Bind(callback, ChildProcessHost::kInvalidUniqueID,
256 MSG_ROUTING_NONE)); 266 MSG_ROUTING_NONE));
257 return; 267 return;
258 } 268 }
259 269
270 ui::PageTransition transition = rfhi->GetParent()
271 ? ui::PAGE_TRANSITION_AUTO_SUBFRAME
272 : ui::PAGE_TRANSITION_AUTO_TOPLEVEL;
273 int frame_tree_node_id = rfhi->frame_tree_node()->frame_tree_node_id();
274
260 OpenURLParams params( 275 OpenURLParams params(
261 url, Referrer::SanitizeForRequest( 276 url, Referrer::SanitizeForRequest(
262 url, Referrer(script_url, blink::WebReferrerPolicyDefault)), 277 url, Referrer(script_url, blink::WebReferrerPolicyDefault)),
263 CURRENT_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, 278 frame_tree_node_id, CURRENT_TAB, transition,
264 true /* is_renderer_initiated */); 279 true /* is_renderer_initiated */);
265 web_contents->OpenURL(params); 280 web_contents->OpenURL(params);
266 DidOpenURL(callback, web_contents); 281 new OpenURLObserver(web_contents, frame_tree_node_id, callback);
267 } 282 }
268 283
269 void OpenWindowOnUI( 284 void OpenWindowOnUI(
270 const GURL& url, 285 const GURL& url,
271 const GURL& script_url, 286 const GURL& script_url,
272 int process_id, 287 int process_id,
273 const scoped_refptr<ServiceWorkerContextWrapper>& context_wrapper, 288 const scoped_refptr<ServiceWorkerContextWrapper>& context_wrapper,
274 const OpenURLCallback& callback) { 289 const OpenURLCallback& callback) {
275 DCHECK_CURRENTLY_ON(BrowserThread::UI); 290 DCHECK_CURRENTLY_ON(BrowserThread::UI);
276 291
(...skipping 2077 matching lines...) Expand 10 before | Expand all | Expand 10 after
2354 void ServiceWorkerVersion::OnBeginEvent() { 2369 void ServiceWorkerVersion::OnBeginEvent() {
2355 if (should_exclude_from_uma_ || running_status() != RUNNING || 2370 if (should_exclude_from_uma_ || running_status() != RUNNING ||
2356 idle_time_.is_null()) { 2371 idle_time_.is_null()) {
2357 return; 2372 return;
2358 } 2373 }
2359 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - 2374 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() -
2360 idle_time_); 2375 idle_time_);
2361 } 2376 }
2362 2377
2363 } // namespace content 2378 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698