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

Side by Side Diff: content/browser/frame_host/navigation_handle_impl.cc

Issue 1294243004: PlzNavigate: Make ServiceWorker work with PlzNavigate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/frame_host/navigation_handle_impl.h" 5 #include "content/browser/frame_host/navigation_handle_impl.h"
6 6
7 #include "base/command_line.h"
8 #include "content/browser/frame_host/frame_tree_node.h"
9 #include "content/browser/frame_host/navigator.h"
7 #include "content/browser/frame_host/navigator_delegate.h" 10 #include "content/browser/frame_host/navigator_delegate.h"
11 #include "content/browser/service_worker/service_worker_context_wrapper.h"
12 #include "content/common/service_worker/service_worker_types.h"
13 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/browser_thread.h"
8 #include "content/public/browser/content_browser_client.h" 15 #include "content/public/browser/content_browser_client.h"
16 #include "content/public/browser/storage_partition.h"
9 #include "content/public/common/content_client.h" 17 #include "content/public/common/content_client.h"
18 #include "content/public/common/content_switches.h"
10 #include "net/url_request/redirect_info.h" 19 #include "net/url_request/redirect_info.h"
11 20
12 namespace content { 21 namespace content {
13 22
14 // static 23 // static
15 scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( 24 scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create(
16 const GURL& url, 25 const GURL& url,
17 bool is_main_frame, 26 bool is_main_frame,
18 NavigatorDelegate* delegate) { 27 FrameTreeNode* frame_tree_node) {
19 return scoped_ptr<NavigationHandleImpl>( 28 return scoped_ptr<NavigationHandleImpl>(
20 new NavigationHandleImpl(url, is_main_frame, delegate)); 29 new NavigationHandleImpl(url, is_main_frame, frame_tree_node));
21 } 30 }
22 31
23 NavigationHandleImpl::NavigationHandleImpl(const GURL& url, 32 NavigationHandleImpl::NavigationHandleImpl(const GURL& url,
24 const bool is_main_frame, 33 bool is_main_frame,
25 NavigatorDelegate* delegate) 34 FrameTreeNode* frame_tree_node)
26 : url_(url), 35 : url_(url),
27 is_main_frame_(is_main_frame), 36 is_main_frame_(is_main_frame),
28 is_post_(false), 37 is_post_(false),
29 has_user_gesture_(false), 38 has_user_gesture_(false),
30 transition_(ui::PAGE_TRANSITION_LINK), 39 transition_(ui::PAGE_TRANSITION_LINK),
31 is_external_protocol_(false), 40 is_external_protocol_(false),
32 net_error_code_(net::OK), 41 net_error_code_(net::OK),
33 render_frame_host_(nullptr), 42 render_frame_host_(nullptr),
34 is_same_page_(false), 43 is_same_page_(false),
35 state_(INITIAL), 44 state_(INITIAL),
36 is_transferring_(false), 45 is_transferring_(false),
37 delegate_(delegate) { 46 delegate_(frame_tree_node->navigator()->GetDelegate()),
47 service_worker_provider_id_(kInvalidServiceWorkerProviderId) {
48 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
49 switches::kEnableBrowserSideNavigation)) {
50 BrowserContext* browser_context =
51 frame_tree_node->navigator()->GetController()->GetBrowserContext();
52 DCHECK(browser_context);
53 // Picking the partition based on the URL is incorrect.
nasko 2015/10/02 22:09:45 Is this supposed to be a TODO? nit: Empty line be
Fabrice (no longer in Chrome) 2015/10/06 17:21:37 Done.
54 // See crbug.com/513539
55 StoragePartition* partition =
56 BrowserContext::GetStoragePartitionForSite(browser_context, url);
57 DCHECK(partition);
58 service_worker_context_ = scoped_refptr<ServiceWorkerContextWrapper>(
59 static_cast<ServiceWorkerContextWrapper*>(
60 partition->GetServiceWorkerContext()));
61 }
38 delegate_->DidStartNavigation(this); 62 delegate_->DidStartNavigation(this);
39 } 63 }
40 64
41 NavigationHandleImpl::~NavigationHandleImpl() { 65 NavigationHandleImpl::~NavigationHandleImpl() {
66 // PlzNavigate
67 // Post a task to the IO thread to clean up the ServiceWorkerProviderHost.
68 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
69 switches::kEnableBrowserSideNavigation) &&
70 service_worker_provider_id_ != kInvalidServiceWorkerProviderId) {
71 BrowserThread::PostTask(
72 BrowserThread::IO, FROM_HERE,
73 base::Bind(&ServiceWorkerContextWrapper::RemoveNavigationProviderHost,
74 service_worker_context_, service_worker_provider_id_));
75 }
42 delegate_->DidFinishNavigation(this); 76 delegate_->DidFinishNavigation(this);
43 } 77 }
44 78
45 const GURL& NavigationHandleImpl::GetURL() { 79 const GURL& NavigationHandleImpl::GetURL() {
46 return url_; 80 return url_;
47 } 81 }
48 82
49 bool NavigationHandleImpl::IsInMainFrame() { 83 bool NavigationHandleImpl::IsInMainFrame() {
50 return is_main_frame_; 84 return is_main_frame_;
51 } 85 }
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 void NavigationHandleImpl::DidCommitNavigation( 241 void NavigationHandleImpl::DidCommitNavigation(
208 bool same_page, 242 bool same_page,
209 RenderFrameHostImpl* render_frame_host) { 243 RenderFrameHostImpl* render_frame_host) {
210 CHECK_IMPLIES(render_frame_host_, render_frame_host_ == render_frame_host); 244 CHECK_IMPLIES(render_frame_host_, render_frame_host_ == render_frame_host);
211 is_same_page_ = same_page; 245 is_same_page_ = same_page;
212 render_frame_host_ = render_frame_host; 246 render_frame_host_ = render_frame_host;
213 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE; 247 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE;
214 } 248 }
215 249
216 } // namespace content 250 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698