Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/sync/sessions/sync_sessions_router_tab_helper.h" | |
| 6 | |
| 7 #include "chrome/browser/sessions/session_tab_helper.h" | |
| 8 #include "chrome/browser/sync/sessions/sync_sessions_web_contents_router.h" | |
| 9 #include "components/sync_sessions/synced_tab_delegate.h" | |
| 10 #include "content/public/browser/navigation_entry.h" | |
| 11 #include "content/public/browser/navigation_handle.h" | |
| 12 #include "content/public/browser/render_frame_host.h" | |
| 13 | |
| 14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(sync_sessions::SyncSessionsRouterTabHelper); | |
| 15 | |
| 16 namespace sync_sessions { | |
| 17 | |
| 18 // static | |
| 19 void SyncSessionsRouterTabHelper::CreateForWebContents( | |
| 20 content::WebContents* web_contents, | |
| 21 SyncSessionsWebContentsRouter* router) { | |
| 22 DCHECK(web_contents); | |
| 23 if (!FromWebContents(web_contents)) { | |
| 24 web_contents->SetUserData( | |
| 25 UserDataKey(), new SyncSessionsRouterTabHelper(web_contents, router)); | |
| 26 } | |
| 27 } | |
| 28 | |
| 29 SyncSessionsRouterTabHelper::SyncSessionsRouterTabHelper( | |
| 30 content::WebContents* web_contents, | |
| 31 SyncSessionsWebContentsRouter* router) | |
| 32 : content::WebContentsObserver(web_contents), | |
| 33 router_(router), | |
| 34 source_tab_id_(kUnknownTabID) {} | |
| 35 | |
| 36 SyncSessionsRouterTabHelper::~SyncSessionsRouterTabHelper() {} | |
| 37 | |
| 38 void SyncSessionsRouterTabHelper::DidFinishNavigation( | |
| 39 content::NavigationHandle* navigation_handle) { | |
| 40 NotifyRouter(); | |
| 41 } | |
| 42 | |
| 43 void SyncSessionsRouterTabHelper::TitleWasSet(content::NavigationEntry* entry, | |
| 44 bool explicit_set) { | |
| 45 NotifyRouter(); | |
| 46 } | |
| 47 | |
| 48 void SyncSessionsRouterTabHelper::WebContentsDestroyed() { | |
| 49 NotifyRouter(); | |
| 50 } | |
| 51 | |
| 52 void SyncSessionsRouterTabHelper::DidFinishLoad( | |
| 53 content::RenderFrameHost* render_frame_host, | |
| 54 const GURL& validated_url) { | |
| 55 NotifyRouter(); | |
| 56 } | |
| 57 | |
| 58 void SyncSessionsRouterTabHelper::DidOpenRequestedURL( | |
| 59 content::WebContents* new_contents, | |
| 60 content::RenderFrameHost* source_render_frame_host, | |
| 61 const GURL& url, | |
| 62 const content::Referrer& referrer, | |
| 63 WindowOpenDisposition disposition, | |
| 64 ui::PageTransition transition, | |
| 65 bool started_from_context_menu, | |
| 66 bool renderer_initiated) { | |
| 67 SessionID::id_type source_tab_id = SessionTabHelper::IdForTab(web_contents()); | |
| 68 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.
| |
| 69 if (new_contents && | |
| 70 SyncSessionsRouterTabHelper::FromWebContents(new_contents) && | |
| 71 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.
| |
| 72 SyncSessionsRouterTabHelper::FromWebContents(new_contents) | |
| 73 ->SetSourceTabID(source_tab_id); | |
| 74 } | |
| 75 NotifyRouter(); | |
| 76 } | |
| 77 | |
| 78 void SyncSessionsRouterTabHelper::SetSourceTabID(const SessionID::id_type id) { | |
| 79 source_tab_id_ = id; | |
| 80 } | |
| 81 | |
| 82 void SyncSessionsRouterTabHelper::NotifyRouter() { | |
| 83 if (router_) | |
| 84 router_->NotifyTabModified(web_contents()); | |
| 85 } | |
| 86 | |
| 87 } // namespace sync_sessions | |
| OLD | NEW |