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_(kInvalidTabID) {} |
| 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 if (new_contents && |
| 69 SyncSessionsRouterTabHelper::FromWebContents(new_contents) && |
| 70 new_contents != web_contents() && source_tab_id != kInvalidTabID) { |
| 71 SyncSessionsRouterTabHelper::FromWebContents(new_contents) |
| 72 ->set_source_tab_id(source_tab_id); |
| 73 } |
| 74 NotifyRouter(); |
| 75 } |
| 76 |
| 77 void SyncSessionsRouterTabHelper::NotifyRouter() { |
| 78 if (router_) |
| 79 router_->NotifyTabModified(web_contents()); |
| 80 } |
| 81 |
| 82 } // namespace sync_sessions |
OLD | NEW |