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

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

Issue 1399363004: PlzNavigate: Make ServiceWorker work with PlzNavigate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/browser/service_worker/service_worker_navigation_handle.h"
13 #include "content/public/browser/browser_context.h"
10 #include "content/public/browser/content_browser_client.h" 14 #include "content/public/browser/content_browser_client.h"
15 #include "content/public/browser/storage_partition.h"
11 #include "content/public/common/content_client.h" 16 #include "content/public/common/content_client.h"
17 #include "content/public/common/content_switches.h"
12 #include "net/url_request/redirect_info.h" 18 #include "net/url_request/redirect_info.h"
19 #include "third_party/WebKit/public/web/WebSandboxFlags.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 // PlzNavigate
45 // Initialize the ServiceWorkerNavigationHandle if it can be created for this
46 // frame.
47 bool can_create_service_worker =
48 (frame_tree_node_->current_replication_state().sandbox_flags &
49 blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin;
50 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
51 switches::kEnableBrowserSideNavigation) &&
52 can_create_service_worker) {
53 BrowserContext* browser_context =
54 frame_tree_node_->navigator()->GetController()->GetBrowserContext();
55 // TODO(clamy): Picking the partition based on the URL is incorrect.
56 // See crbug.com/513539
57 StoragePartition* partition =
58 BrowserContext::GetStoragePartitionForSite(browser_context, url_);
59 DCHECK(partition);
60 ServiceWorkerContextWrapper* service_worker_context =
61 static_cast<ServiceWorkerContextWrapper*>(
62 partition->GetServiceWorkerContext());
63 service_worker_handle_.reset(
64 new ServiceWorkerNavigationHandle(service_worker_context));
65 }
nasko 2015/10/20 23:07:42 Why put this code here instead of NavigationReques
clamy 2015/10/21 16:33:48 We need the SWHandle to persist until navigation c
66
37 GetDelegate()->DidStartNavigation(this); 67 GetDelegate()->DidStartNavigation(this);
38 } 68 }
39 69
40 NavigationHandleImpl::~NavigationHandleImpl() { 70 NavigationHandleImpl::~NavigationHandleImpl() {
41 GetDelegate()->DidFinishNavigation(this); 71 GetDelegate()->DidFinishNavigation(this);
42 } 72 }
43 73
44 NavigatorDelegate* NavigationHandleImpl::GetDelegate() const { 74 NavigatorDelegate* NavigationHandleImpl::GetDelegate() const {
45 return frame_tree_node_->navigator()->GetDelegate(); 75 return frame_tree_node_->navigator()->GetDelegate();
46 } 76 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 void NavigationHandleImpl::DidCommitNavigation( 240 void NavigationHandleImpl::DidCommitNavigation(
211 bool same_page, 241 bool same_page,
212 RenderFrameHostImpl* render_frame_host) { 242 RenderFrameHostImpl* render_frame_host) {
213 CHECK_IMPLIES(render_frame_host_, render_frame_host_ == render_frame_host); 243 CHECK_IMPLIES(render_frame_host_, render_frame_host_ == render_frame_host);
214 is_same_page_ = same_page; 244 is_same_page_ = same_page;
215 render_frame_host_ = render_frame_host; 245 render_frame_host_ = render_frame_host;
216 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE; 246 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE;
217 } 247 }
218 248
219 } // namespace content 249 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698