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/navigator_delegate.h" | 8 #include "content/browser/frame_host/navigator_delegate.h" |
| 9 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 10 #include "content/public/browser/browser_context.h" |
| 11 #include "content/public/browser/browser_thread.h" |
8 #include "content/public/browser/content_browser_client.h" | 12 #include "content/public/browser/content_browser_client.h" |
| 13 #include "content/public/browser/storage_partition.h" |
9 #include "content/public/common/content_client.h" | 14 #include "content/public/common/content_client.h" |
| 15 #include "content/public/common/content_switches.h" |
10 #include "net/url_request/redirect_info.h" | 16 #include "net/url_request/redirect_info.h" |
11 | 17 |
12 namespace content { | 18 namespace content { |
13 | 19 |
14 // static | 20 // static |
15 scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( | 21 scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( |
16 const GURL& url, | 22 const GURL& url, |
17 bool is_main_frame, | 23 bool is_main_frame, |
18 NavigatorDelegate* delegate) { | 24 NavigatorDelegate* delegate, |
19 return scoped_ptr<NavigationHandleImpl>( | 25 int service_worker_provider_id) { |
20 new NavigationHandleImpl(url, is_main_frame, delegate)); | 26 return scoped_ptr<NavigationHandleImpl>(new NavigationHandleImpl( |
| 27 url, is_main_frame, delegate, service_worker_provider_id)); |
21 } | 28 } |
22 | 29 |
23 NavigationHandleImpl::NavigationHandleImpl(const GURL& url, | 30 |
24 const bool is_main_frame, | 31 NavigationHandleImpl::NavigationHandleImpl( |
25 NavigatorDelegate* delegate) | 32 const GURL& url, |
| 33 bool is_main_frame, |
| 34 NavigatorDelegate* delegate, |
| 35 int service_worker_provider_id) |
26 : url_(url), | 36 : url_(url), |
27 is_main_frame_(is_main_frame), | 37 is_main_frame_(is_main_frame), |
28 is_post_(false), | 38 is_post_(false), |
29 has_user_gesture_(false), | 39 has_user_gesture_(false), |
30 transition_(ui::PAGE_TRANSITION_LINK), | 40 transition_(ui::PAGE_TRANSITION_LINK), |
31 is_external_protocol_(false), | 41 is_external_protocol_(false), |
32 net_error_code_(net::OK), | 42 net_error_code_(net::OK), |
33 render_frame_host_(nullptr), | 43 render_frame_host_(nullptr), |
34 is_same_page_(false), | 44 is_same_page_(false), |
35 state_(INITIAL), | 45 state_(INITIAL), |
36 is_transferring_(false), | 46 is_transferring_(false), |
37 delegate_(delegate) { | 47 delegate_(delegate), |
| 48 service_worker_provider_id_(service_worker_provider_id) { |
| 49 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 50 switches::kEnableBrowserSideNavigation)) { |
| 51 BrowserContext* browser_context = delegate_->GetBrowserContext(); |
| 52 DCHECK(browser_context); |
| 53 // Picking the partition based on the URL is incorrect. |
| 54 // See crbug.com/513539 |
| 55 StoragePartition* partition = BrowserContext::GetStoragePartitionForSite( |
| 56 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 BrowserThread::PostTask( |
| 71 BrowserThread::IO, |
| 72 FROM_HERE, |
| 73 base::Bind(&ServiceWorkerContextWrapper::RemoveNavigationProviderHost, |
| 74 service_worker_context_, |
| 75 service_worker_provider_id_)); |
| 76 } |
42 delegate_->DidFinishNavigation(this); | 77 delegate_->DidFinishNavigation(this); |
43 } | 78 } |
44 | 79 |
45 const GURL& NavigationHandleImpl::GetURL() { | 80 const GURL& NavigationHandleImpl::GetURL() { |
46 return url_; | 81 return url_; |
47 } | 82 } |
48 | 83 |
49 bool NavigationHandleImpl::IsInMainFrame() { | 84 bool NavigationHandleImpl::IsInMainFrame() { |
50 return is_main_frame_; | 85 return is_main_frame_; |
51 } | 86 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 void NavigationHandleImpl::DidCommitNavigation( | 242 void NavigationHandleImpl::DidCommitNavigation( |
208 bool same_page, | 243 bool same_page, |
209 RenderFrameHostImpl* render_frame_host) { | 244 RenderFrameHostImpl* render_frame_host) { |
210 CHECK_IMPLIES(render_frame_host_, render_frame_host_ == render_frame_host); | 245 CHECK_IMPLIES(render_frame_host_, render_frame_host_ == render_frame_host); |
211 is_same_page_ = same_page; | 246 is_same_page_ = same_page; |
212 render_frame_host_ = render_frame_host; | 247 render_frame_host_ = render_frame_host; |
213 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; |
214 } | 249 } |
215 | 250 |
216 } // namespace content | 251 } // namespace content |
OLD | NEW |