[AiS] Mac AiS on two lines
[chromium-blink-merge.git] / chrome / browser / ui / sync / tab_contents_synced_tab_delegate.cc
blob9b59f78cfb204f535afc7d88a3a45a606a2282b1
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
7 #include "base/memory/ref_counted.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/sessions/session_tab_helper.h"
10 #include "chrome/browser/sync/glue/synced_window_delegate.h"
11 #include "chrome/browser/sync/sessions/sessions_util.h"
12 #include "content/public/browser/navigation_controller.h"
13 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/browser/web_contents.h"
16 #if defined(ENABLE_EXTENSIONS)
17 #include "chrome/browser/extensions/tab_helper.h"
18 #include "extensions/common/extension.h"
19 #endif
21 #if defined(ENABLE_SUPERVISED_USERS)
22 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h"
23 #endif
25 using content::NavigationEntry;
27 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabContentsSyncedTabDelegate);
29 TabContentsSyncedTabDelegate::TabContentsSyncedTabDelegate(
30 content::WebContents* web_contents)
31 : web_contents_(web_contents), sync_session_id_(0) {}
33 TabContentsSyncedTabDelegate::~TabContentsSyncedTabDelegate() {}
35 SessionID::id_type TabContentsSyncedTabDelegate::GetWindowId() const {
36 return SessionTabHelper::FromWebContents(web_contents_)->window_id().id();
39 SessionID::id_type TabContentsSyncedTabDelegate::GetSessionId() const {
40 return SessionTabHelper::FromWebContents(web_contents_)->session_id().id();
43 bool TabContentsSyncedTabDelegate::IsBeingDestroyed() const {
44 return web_contents_->IsBeingDestroyed();
47 Profile* TabContentsSyncedTabDelegate::profile() const {
48 return Profile::FromBrowserContext(web_contents_->GetBrowserContext());
51 std::string TabContentsSyncedTabDelegate::GetExtensionAppId() const {
52 #if defined(ENABLE_EXTENSIONS)
53 const scoped_refptr<const extensions::Extension> extension_app(
54 extensions::TabHelper::FromWebContents(web_contents_)->extension_app());
55 if (extension_app.get())
56 return extension_app->id();
57 #endif
58 return std::string();
61 int TabContentsSyncedTabDelegate::GetCurrentEntryIndex() const {
62 return web_contents_->GetController().GetCurrentEntryIndex();
65 int TabContentsSyncedTabDelegate::GetEntryCount() const {
66 return web_contents_->GetController().GetEntryCount();
69 int TabContentsSyncedTabDelegate::GetPendingEntryIndex() const {
70 return web_contents_->GetController().GetPendingEntryIndex();
73 NavigationEntry* TabContentsSyncedTabDelegate::GetPendingEntry() const {
74 return web_contents_->GetController().GetPendingEntry();
77 NavigationEntry* TabContentsSyncedTabDelegate::GetEntryAtIndex(int i) const {
78 return web_contents_->GetController().GetEntryAtIndex(i);
81 NavigationEntry* TabContentsSyncedTabDelegate::GetActiveEntry() const {
82 return web_contents_->GetController().GetVisibleEntry();
85 bool TabContentsSyncedTabDelegate::ProfileIsSupervised() const {
86 return profile()->IsSupervised();
89 const std::vector<const content::NavigationEntry*>*
90 TabContentsSyncedTabDelegate::GetBlockedNavigations() const {
91 #if defined(ENABLE_SUPERVISED_USERS)
92 SupervisedUserNavigationObserver* navigation_observer =
93 SupervisedUserNavigationObserver::FromWebContents(web_contents_);
94 DCHECK(navigation_observer);
95 return navigation_observer->blocked_navigations();
96 #else
97 NOTREACHED();
98 return NULL;
99 #endif
102 bool TabContentsSyncedTabDelegate::IsPinned() const {
103 const browser_sync::SyncedWindowDelegate* window =
104 browser_sync::SyncedWindowDelegate::FindById(GetWindowId());
105 // We might not have a parent window, e.g. Developer Tools.
106 return window ? window->IsTabPinned(this) : false;
109 bool TabContentsSyncedTabDelegate::HasWebContents() const { return true; }
111 content::WebContents* TabContentsSyncedTabDelegate::GetWebContents() const {
112 return web_contents_;
115 int TabContentsSyncedTabDelegate::GetSyncId() const {
116 return sync_session_id_;
119 void TabContentsSyncedTabDelegate::SetSyncId(int sync_id) {
120 sync_session_id_ = sync_id;
123 bool TabContentsSyncedTabDelegate::ShouldSync() const {
124 return browser_sync::sessions_util::ShouldSyncTab(*this);