1 // Copyright 2013 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/glue/synced_tab_delegate_android.h" 6 7 #include "base/memory/ref_counted.h" 8 #include "chrome/browser/android/tab_android.h" 9 #include "chrome/browser/extensions/tab_helper.h" 10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/sessions/session_tab_helper.h" 12 #include "chrome/browser/sync/glue/synced_window_delegate.h" 13 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" 14 #include "content/public/browser/navigation_controller.h" 15 #include "content/public/browser/navigation_entry.h" 16 #include "content/public/browser/web_contents.h" 17 #include "extensions/common/extension.h" 18 19 using content::NavigationEntry; 20 21 namespace browser_sync { SyncedTabDelegateAndroid(TabAndroid * tab_android)22SyncedTabDelegateAndroid::SyncedTabDelegateAndroid(TabAndroid* tab_android) 23 : web_contents_(NULL), tab_android_(tab_android) {} 24 ~SyncedTabDelegateAndroid()25SyncedTabDelegateAndroid::~SyncedTabDelegateAndroid() {} 26 GetWindowId() const27SessionID::id_type SyncedTabDelegateAndroid::GetWindowId() const { 28 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 29 ->GetWindowId(); 30 } 31 GetSessionId() const32SessionID::id_type SyncedTabDelegateAndroid::GetSessionId() const { 33 return tab_android_->session_id().id(); 34 } 35 IsBeingDestroyed() const36bool SyncedTabDelegateAndroid::IsBeingDestroyed() const { 37 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 38 ->IsBeingDestroyed(); 39 } 40 profile() const41Profile* SyncedTabDelegateAndroid::profile() const { 42 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 43 ->profile(); 44 } 45 GetExtensionAppId() const46std::string SyncedTabDelegateAndroid::GetExtensionAppId() const { 47 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 48 ->GetExtensionAppId(); 49 } 50 GetCurrentEntryIndex() const51int SyncedTabDelegateAndroid::GetCurrentEntryIndex() const { 52 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 53 ->GetCurrentEntryIndex(); 54 } 55 GetEntryCount() const56int SyncedTabDelegateAndroid::GetEntryCount() const { 57 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 58 ->GetEntryCount(); 59 } 60 GetPendingEntryIndex() const61int SyncedTabDelegateAndroid::GetPendingEntryIndex() const { 62 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 63 ->GetPendingEntryIndex(); 64 } 65 GetPendingEntry() const66NavigationEntry* SyncedTabDelegateAndroid::GetPendingEntry() const { 67 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 68 ->GetPendingEntry(); 69 } 70 GetEntryAtIndex(int i) const71NavigationEntry* SyncedTabDelegateAndroid::GetEntryAtIndex(int i) const { 72 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 73 ->GetEntryAtIndex(i); 74 } 75 GetActiveEntry() const76NavigationEntry* SyncedTabDelegateAndroid::GetActiveEntry() const { 77 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 78 ->GetActiveEntry(); 79 } 80 IsPinned() const81bool SyncedTabDelegateAndroid::IsPinned() const { 82 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 83 ->IsPinned(); 84 } 85 HasWebContents() const86bool SyncedTabDelegateAndroid::HasWebContents() const { 87 return web_contents_ != NULL; 88 } 89 GetWebContents() const90content::WebContents* SyncedTabDelegateAndroid::GetWebContents() const { 91 return web_contents_; 92 } 93 SetWebContents(content::WebContents * web_contents)94void SyncedTabDelegateAndroid::SetWebContents( 95 content::WebContents* web_contents) { 96 web_contents_ = web_contents; 97 TabContentsSyncedTabDelegate::CreateForWebContents(web_contents_); 98 } 99 ResetWebContents()100void SyncedTabDelegateAndroid::ResetWebContents() { web_contents_ = NULL; } 101 ProfileIsManaged() const102bool SyncedTabDelegateAndroid::ProfileIsManaged() const { 103 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 104 ->ProfileIsManaged(); 105 } 106 107 const std::vector<const content::NavigationEntry*>* GetBlockedNavigations() const108SyncedTabDelegateAndroid::GetBlockedNavigations() const { 109 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 110 ->GetBlockedNavigations(); 111 } 112 GetSyncId() const113int SyncedTabDelegateAndroid::GetSyncId() const { 114 return tab_android_->GetSyncId(); 115 } 116 SetSyncId(int sync_id)117void SyncedTabDelegateAndroid::SetSyncId(int sync_id) { 118 tab_android_->SetSyncId(sync_id); 119 } 120 121 // static ImplFromWebContents(content::WebContents * web_contents)122SyncedTabDelegate* SyncedTabDelegate::ImplFromWebContents( 123 content::WebContents* web_contents) { 124 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); 125 return tab ? tab->GetSyncedTabDelegate() : NULL; 126 } 127 } // namespace browser_sync 128