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