Index: content/browser/frame_host/navigation_handle_impl.cc |
diff --git a/content/browser/frame_host/navigation_handle_impl.cc b/content/browser/frame_host/navigation_handle_impl.cc |
index 18a2fcd24ab4115fecf54d92e5332f4349d6696c..d930cfd9d67d33f1419aca18b79f04b0640a9f4c 100644 |
--- a/content/browser/frame_host/navigation_handle_impl.cc |
+++ b/content/browser/frame_host/navigation_handle_impl.cc |
@@ -4,9 +4,18 @@ |
#include "content/browser/frame_host/navigation_handle_impl.h" |
+#include "base/command_line.h" |
+#include "content/browser/frame_host/frame_tree_node.h" |
+#include "content/browser/frame_host/navigator.h" |
#include "content/browser/frame_host/navigator_delegate.h" |
+#include "content/browser/service_worker/service_worker_context_wrapper.h" |
+#include "content/common/service_worker/service_worker_types.h" |
+#include "content/public/browser/browser_context.h" |
+#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/content_browser_client.h" |
+#include "content/public/browser/storage_partition.h" |
#include "content/public/common/content_client.h" |
+#include "content/public/common/content_switches.h" |
#include "net/url_request/redirect_info.h" |
namespace content { |
@@ -15,14 +24,14 @@ namespace content { |
scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( |
const GURL& url, |
bool is_main_frame, |
- NavigatorDelegate* delegate) { |
+ FrameTreeNode* frame_tree_node) { |
return scoped_ptr<NavigationHandleImpl>( |
- new NavigationHandleImpl(url, is_main_frame, delegate)); |
+ new NavigationHandleImpl(url, is_main_frame, frame_tree_node)); |
} |
NavigationHandleImpl::NavigationHandleImpl(const GURL& url, |
- const bool is_main_frame, |
- NavigatorDelegate* delegate) |
+ bool is_main_frame, |
+ FrameTreeNode* frame_tree_node) |
: url_(url), |
is_main_frame_(is_main_frame), |
is_post_(false), |
@@ -34,11 +43,36 @@ NavigationHandleImpl::NavigationHandleImpl(const GURL& url, |
is_same_page_(false), |
state_(INITIAL), |
is_transferring_(false), |
- delegate_(delegate) { |
+ delegate_(frame_tree_node->navigator()->GetDelegate()), |
+ service_worker_provider_id_(kInvalidServiceWorkerProviderId) { |
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kEnableBrowserSideNavigation)) { |
+ BrowserContext* browser_context = |
+ frame_tree_node->navigator()->GetController()->GetBrowserContext(); |
+ DCHECK(browser_context); |
+ // 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.
|
+ // See crbug.com/513539 |
+ StoragePartition* partition = |
+ BrowserContext::GetStoragePartitionForSite(browser_context, url); |
+ DCHECK(partition); |
+ service_worker_context_ = scoped_refptr<ServiceWorkerContextWrapper>( |
+ static_cast<ServiceWorkerContextWrapper*>( |
+ partition->GetServiceWorkerContext())); |
+ } |
delegate_->DidStartNavigation(this); |
} |
NavigationHandleImpl::~NavigationHandleImpl() { |
+ // PlzNavigate |
+ // Post a task to the IO thread to clean up the ServiceWorkerProviderHost. |
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kEnableBrowserSideNavigation) && |
+ service_worker_provider_id_ != kInvalidServiceWorkerProviderId) { |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&ServiceWorkerContextWrapper::RemoveNavigationProviderHost, |
+ service_worker_context_, service_worker_provider_id_)); |
+ } |
delegate_->DidFinishNavigation(this); |
} |