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 "chrome/common/extensions/extension.h" 15 #include "content/public/browser/navigation_controller.h" 16 #include "content/public/browser/navigation_entry.h" 17 #include "content/public/browser/web_contents.h" 18 19 using content::NavigationEntry; 20 21 namespace browser_sync { 22 SyncedTabDelegateAndroid::SyncedTabDelegateAndroid(TabAndroid* tab_android) 23 : web_contents_(NULL), tab_android_(tab_android) {} 24 25 SyncedTabDelegateAndroid::~SyncedTabDelegateAndroid() {} 26 27 SessionID::id_type SyncedTabDelegateAndroid::GetWindowId() const { 28 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 29 ->GetWindowId(); 30 } 31 32 SessionID::id_type SyncedTabDelegateAndroid::GetSessionId() const { 33 return tab_android_->id().id(); 34 } 35 36 bool SyncedTabDelegateAndroid::IsBeingDestroyed() const { 37 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 38 ->IsBeingDestroyed(); 39 } 40 41 Profile* SyncedTabDelegateAndroid::profile() const { 42 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 43 ->profile(); 44 } 45 46 std::string SyncedTabDelegateAndroid::GetExtensionAppId() const { 47 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 48 ->GetExtensionAppId(); 49 } 50 51 int SyncedTabDelegateAndroid::GetCurrentEntryIndex() const { 52 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 53 ->GetCurrentEntryIndex(); 54 } 55 56 int SyncedTabDelegateAndroid::GetEntryCount() const { 57 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 58 ->GetEntryCount(); 59 } 60 61 int SyncedTabDelegateAndroid::GetPendingEntryIndex() const { 62 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 63 ->GetPendingEntryIndex(); 64 } 65 66 NavigationEntry* SyncedTabDelegateAndroid::GetPendingEntry() const { 67 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 68 ->GetPendingEntry(); 69 } 70 71 NavigationEntry* SyncedTabDelegateAndroid::GetEntryAtIndex(int i) const { 72 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 73 ->GetEntryAtIndex(i); 74 } 75 76 NavigationEntry* SyncedTabDelegateAndroid::GetActiveEntry() const { 77 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 78 ->GetActiveEntry(); 79 } 80 81 bool SyncedTabDelegateAndroid::IsPinned() const { 82 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 83 ->IsPinned(); 84 } 85 86 bool SyncedTabDelegateAndroid::HasWebContents() const { 87 return web_contents_ != NULL; 88 } 89 90 void SyncedTabDelegateAndroid::SetWebContents( 91 content::WebContents* web_contents) { 92 web_contents_ = web_contents; 93 TabContentsSyncedTabDelegate::CreateForWebContents(web_contents_); 94 } 95 96 void SyncedTabDelegateAndroid::ResetWebContents() { web_contents_ = NULL; } 97 98 bool SyncedTabDelegateAndroid::ProfileIsManaged() const { 99 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 100 ->ProfileIsManaged(); 101 } 102 103 const std::vector<const content::NavigationEntry*>* 104 SyncedTabDelegateAndroid::GetBlockedNavigations() const { 105 return TabContentsSyncedTabDelegate::FromWebContents(web_contents_) 106 ->GetBlockedNavigations(); 107 } 108 109 int SyncedTabDelegateAndroid::GetSyncId() const { 110 return tab_android_->GetSyncId(); 111 } 112 113 void SyncedTabDelegateAndroid::SetSyncId(int sync_id) { 114 tab_android_->SetSyncId(sync_id); 115 } 116 117 // static 118 SyncedTabDelegate* SyncedTabDelegate::ImplFromWebContents( 119 content::WebContents* web_contents) { 120 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); 121 return tab ? tab->GetSyncedTabDelegate() : NULL; 122 } 123 } // namespace browser_sync 124