Index: chrome/browser/sync/sessions/sync_sessions_router_tab_helper.cc |
diff --git a/chrome/browser/sync/sessions/sync_sessions_router_tab_helper.cc b/chrome/browser/sync/sessions/sync_sessions_router_tab_helper.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..28041146ca01c8ba49ae2bdfbfdd042160b234ed |
--- /dev/null |
+++ b/chrome/browser/sync/sessions/sync_sessions_router_tab_helper.cc |
@@ -0,0 +1,87 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/sync/sessions/sync_sessions_router_tab_helper.h" |
+ |
+#include "chrome/browser/sessions/session_tab_helper.h" |
+#include "chrome/browser/sync/sessions/sync_sessions_web_contents_router.h" |
+#include "components/sync_sessions/synced_tab_delegate.h" |
+#include "content/public/browser/navigation_entry.h" |
+#include "content/public/browser/navigation_handle.h" |
+#include "content/public/browser/render_frame_host.h" |
+ |
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(sync_sessions::SyncSessionsRouterTabHelper); |
+ |
+namespace sync_sessions { |
+ |
+// static |
+void SyncSessionsRouterTabHelper::CreateForWebContents( |
+ content::WebContents* web_contents, |
+ SyncSessionsWebContentsRouter* router) { |
+ DCHECK(web_contents); |
+ if (!FromWebContents(web_contents)) { |
+ web_contents->SetUserData( |
+ UserDataKey(), new SyncSessionsRouterTabHelper(web_contents, router)); |
+ } |
+} |
+ |
+SyncSessionsRouterTabHelper::SyncSessionsRouterTabHelper( |
+ content::WebContents* web_contents, |
+ SyncSessionsWebContentsRouter* router) |
+ : content::WebContentsObserver(web_contents), |
+ router_(router), |
+ source_tab_id_(kUnknownTabID) {} |
+ |
+SyncSessionsRouterTabHelper::~SyncSessionsRouterTabHelper() {} |
+ |
+void SyncSessionsRouterTabHelper::DidFinishNavigation( |
+ content::NavigationHandle* navigation_handle) { |
+ NotifyRouter(); |
+} |
+ |
+void SyncSessionsRouterTabHelper::TitleWasSet(content::NavigationEntry* entry, |
+ bool explicit_set) { |
+ NotifyRouter(); |
+} |
+ |
+void SyncSessionsRouterTabHelper::WebContentsDestroyed() { |
+ NotifyRouter(); |
+} |
+ |
+void SyncSessionsRouterTabHelper::DidFinishLoad( |
+ content::RenderFrameHost* render_frame_host, |
+ const GURL& validated_url) { |
+ NotifyRouter(); |
+} |
+ |
+void SyncSessionsRouterTabHelper::DidOpenRequestedURL( |
+ content::WebContents* new_contents, |
+ content::RenderFrameHost* source_render_frame_host, |
+ const GURL& url, |
+ const content::Referrer& referrer, |
+ WindowOpenDisposition disposition, |
+ ui::PageTransition transition, |
+ bool started_from_context_menu, |
+ bool renderer_initiated) { |
+ SessionID::id_type source_tab_id = SessionTabHelper::IdForTab(web_contents()); |
+ DLOG(WARNING) << source_tab_id; |
Nicolas Zea
2017/03/16 19:57:43
forget to remove?
Patrick Noland
2017/03/17 00:20:09
Done.
|
+ if (new_contents && |
+ SyncSessionsRouterTabHelper::FromWebContents(new_contents) && |
+ new_contents != web_contents() && source_tab_id != kUnknownTabID) { |
Nicolas Zea
2017/03/16 19:57:42
looks like kUnknownTabID already exists? Perhaps r
Nicolas Zea
2017/03/16 19:57:43
Does new_contents != web_contents() prevent source
Patrick Noland
2017/03/16 20:23:27
It's defined in a few places(TabNodePool as an enu
Patrick Noland
2017/03/16 20:23:27
Yes.
|
+ SyncSessionsRouterTabHelper::FromWebContents(new_contents) |
+ ->SetSourceTabID(source_tab_id); |
+ } |
+ NotifyRouter(); |
+} |
+ |
+void SyncSessionsRouterTabHelper::SetSourceTabID(const SessionID::id_type id) { |
+ source_tab_id_ = id; |
+} |
+ |
+void SyncSessionsRouterTabHelper::NotifyRouter() { |
+ if (router_) |
+ router_->NotifyTabModified(web_contents()); |
+} |
+ |
+} // namespace sync_sessions |