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
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_->session_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
90content::WebContents* SyncedTabDelegateAndroid::GetWebContents() const {
91  return web_contents_;
92}
93
94void SyncedTabDelegateAndroid::SetWebContents(
95    content::WebContents* web_contents) {
96  web_contents_ = web_contents;
97  TabContentsSyncedTabDelegate::CreateForWebContents(web_contents_);
98}
99
100void SyncedTabDelegateAndroid::ResetWebContents() { web_contents_ = NULL; }
101
102bool SyncedTabDelegateAndroid::ProfileIsSupervised() const {
103  return TabContentsSyncedTabDelegate::FromWebContents(web_contents_)
104      ->ProfileIsSupervised();
105}
106
107const std::vector<const content::NavigationEntry*>*
108SyncedTabDelegateAndroid::GetBlockedNavigations() const {
109  return TabContentsSyncedTabDelegate::FromWebContents(web_contents_)
110      ->GetBlockedNavigations();
111}
112
113int SyncedTabDelegateAndroid::GetSyncId() const {
114  return tab_android_->GetSyncId();
115}
116
117void SyncedTabDelegateAndroid::SetSyncId(int sync_id) {
118  tab_android_->SetSyncId(sync_id);
119}
120
121// static
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