OLD | NEW |
---|---|
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 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
52 switches::kEnableBrowserSideNavigation) && | |
michaeln
2015/10/07 01:16:44
nit: would we ever expect a valid id value when th
Fabrice (no longer in Chrome)
2015/10/07 12:59:43
Sounds good.
| |
53 service_worker_provider_id_ != kInvalidServiceWorkerProviderId) { | |
54 BrowserContext* browser_context = | |
55 frame_tree_node_->navigator()->GetController()->GetBrowserContext(); | |
56 DCHECK(browser_context); | |
57 | |
58 // TODO: Picking the partition based on the URL is incorrect. | |
clamy
2015/10/07 07:53:30
nit: name in TODO. You can put mine if you want.
Fabrice (no longer in Chrome)
2015/10/07 12:59:43
Done.
| |
59 // See crbug.com/513539 | |
60 StoragePartition* partition = | |
61 BrowserContext::GetStoragePartitionForSite(browser_context, url_); | |
62 DCHECK(partition); | |
63 ServiceWorkerContextWrapper* service_worker_context = | |
64 static_cast<ServiceWorkerContextWrapper*>( | |
65 partition->GetServiceWorkerContext()); | |
66 | |
67 BrowserThread::PostTask( | |
68 BrowserThread::IO, FROM_HERE, | |
69 base::Bind(&ServiceWorkerContextWrapper::RemoveNavigationProviderHost, | |
70 service_worker_context, service_worker_provider_id_)); | |
71 } | |
41 GetDelegate()->DidFinishNavigation(this); | 72 GetDelegate()->DidFinishNavigation(this); |
42 } | 73 } |
43 | 74 |
44 NavigatorDelegate* NavigationHandleImpl::GetDelegate() const { | 75 NavigatorDelegate* NavigationHandleImpl::GetDelegate() const { |
45 return frame_tree_node_->navigator()->GetDelegate(); | 76 return frame_tree_node_->navigator()->GetDelegate(); |
46 } | 77 } |
47 | 78 |
48 const GURL& NavigationHandleImpl::GetURL() { | 79 const GURL& NavigationHandleImpl::GetURL() { |
49 return url_; | 80 return url_; |
50 } | 81 } |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 void NavigationHandleImpl::DidCommitNavigation( | 241 void NavigationHandleImpl::DidCommitNavigation( |
211 bool same_page, | 242 bool same_page, |
212 RenderFrameHostImpl* render_frame_host) { | 243 RenderFrameHostImpl* render_frame_host) { |
213 CHECK_IMPLIES(render_frame_host_, render_frame_host_ == render_frame_host); | 244 CHECK_IMPLIES(render_frame_host_, render_frame_host_ == render_frame_host); |
214 is_same_page_ = same_page; | 245 is_same_page_ = same_page; |
215 render_frame_host_ = render_frame_host; | 246 render_frame_host_ = render_frame_host; |
216 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; |
217 } | 248 } |
218 | 249 |
219 } // namespace content | 250 } // namespace content |
OLD | NEW |