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

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"
7 #include "content/browser/frame_host/frame_tree_node.h" 8 #include "content/browser/frame_host/frame_tree_node.h"
8 #include "content/browser/frame_host/navigator.h" 9 #include "content/browser/frame_host/navigator.h"
9 #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"
10 #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"
11 #include "content/public/common/content_client.h" 17 #include "content/public/common/content_client.h"
18 #include "content/public/common/content_switches.h"
12 #include "net/url_request/redirect_info.h" 19 #include "net/url_request/redirect_info.h"
13 20
14 namespace content { 21 namespace content {
15 22
16 // static 23 // static
17 scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( 24 scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create(
18 const GURL& url, 25 const GURL& url,
19 FrameTreeNode* frame_tree_node) { 26 FrameTreeNode* frame_tree_node) {
20 return scoped_ptr<NavigationHandleImpl>( 27 return scoped_ptr<NavigationHandleImpl>(
21 new NavigationHandleImpl(url, frame_tree_node)); 28 new NavigationHandleImpl(url, frame_tree_node));
22 } 29 }
23 30
24 NavigationHandleImpl::NavigationHandleImpl(const GURL& url, 31 NavigationHandleImpl::NavigationHandleImpl(const GURL& url,
25 FrameTreeNode* frame_tree_node) 32 FrameTreeNode* frame_tree_node)
26 : url_(url), 33 : url_(url),
27 is_post_(false), 34 is_post_(false),
28 has_user_gesture_(false), 35 has_user_gesture_(false),
29 transition_(ui::PAGE_TRANSITION_LINK), 36 transition_(ui::PAGE_TRANSITION_LINK),
30 is_external_protocol_(false), 37 is_external_protocol_(false),
31 net_error_code_(net::OK), 38 net_error_code_(net::OK),
32 render_frame_host_(nullptr), 39 render_frame_host_(nullptr),
33 is_same_page_(false), 40 is_same_page_(false),
34 state_(INITIAL), 41 state_(INITIAL),
35 is_transferring_(false), 42 is_transferring_(false),
36 frame_tree_node_(frame_tree_node) { 43 frame_tree_node_(frame_tree_node),
44 service_worker_provider_id_(kInvalidServiceWorkerProviderId) {
37 GetDelegate()->DidStartNavigation(this); 45 GetDelegate()->DidStartNavigation(this);
38 } 46 }
39 47
40 NavigationHandleImpl::~NavigationHandleImpl() { 48 NavigationHandleImpl::~NavigationHandleImpl() {
49 // PlzNavigate
50 // Post a task to the IO thread to clean up the ServiceWorkerProviderHost.
51 // This is needed in case the navigation does not succeed.
52 if (service_worker_provider_id_ != kInvalidServiceWorkerProviderId) {
53 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
54 switches::kEnableBrowserSideNavigation));
55 BrowserContext* browser_context =
56 frame_tree_node_->navigator()->GetController()->GetBrowserContext();
57 DCHECK(browser_context);
58
59 // TODO(clamy): Picking the partition based on the URL is incorrect.
60 // See crbug.com/513539
61 StoragePartition* partition =
62 BrowserContext::GetStoragePartitionForSite(browser_context, url_);
63 DCHECK(partition);
64 ServiceWorkerContextWrapper* service_worker_context =
65 static_cast<ServiceWorkerContextWrapper*>(
66 partition->GetServiceWorkerContext());
67
68 BrowserThread::PostTask(
69 BrowserThread::IO, FROM_HERE,
70 base::Bind(&ServiceWorkerContextWrapper::RemoveNavigationProviderHost,
71 service_worker_context, service_worker_provider_id_));
72 }
41 GetDelegate()->DidFinishNavigation(this); 73 GetDelegate()->DidFinishNavigation(this);
42 } 74 }
43 75
44 NavigatorDelegate* NavigationHandleImpl::GetDelegate() const { 76 NavigatorDelegate* NavigationHandleImpl::GetDelegate() const {
45 return frame_tree_node_->navigator()->GetDelegate(); 77 return frame_tree_node_->navigator()->GetDelegate();
46 } 78 }
47 79
48 const GURL& NavigationHandleImpl::GetURL() { 80 const GURL& NavigationHandleImpl::GetURL() {
49 return url_; 81 return url_;
50 } 82 }
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 void NavigationHandleImpl::DidCommitNavigation( 242 void NavigationHandleImpl::DidCommitNavigation(
211 bool same_page, 243 bool same_page,
212 RenderFrameHostImpl* render_frame_host) { 244 RenderFrameHostImpl* render_frame_host) {
213 CHECK_IMPLIES(render_frame_host_, render_frame_host_ == render_frame_host); 245 CHECK_IMPLIES(render_frame_host_, render_frame_host_ == render_frame_host);
214 is_same_page_ = same_page; 246 is_same_page_ = same_page;
215 render_frame_host_ = render_frame_host; 247 render_frame_host_ = render_frame_host;
216 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE; 248 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE;
217 } 249 }
218 250
219 } // namespace content 251 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698