Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / sync / tab_contents_synced_tab_delegate.cc
blob2381c2d22ebaa061fcbba2fca74b2b0c59570b4b
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 "content/public/browser/navigation_controller.h"
12 #include "content/public/browser/navigation_entry.h"
13 #include "content/public/browser/web_contents.h"
15 #if defined(ENABLE_EXTENSIONS)
16 #include "chrome/browser/extensions/tab_helper.h"
17 #include "extensions/common/extension.h"
18 #endif
20 #if defined(ENABLE_SUPERVISED_USERS)
21 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h"
22 #endif
24 using content::NavigationEntry;
26 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabContentsSyncedTabDelegate);
28 TabContentsSyncedTabDelegate::TabContentsSyncedTabDelegate(
29 content::WebContents* web_contents)
30 : web_contents_(web_contents), sync_session_id_(0) {}
32 TabContentsSyncedTabDelegate::~TabContentsSyncedTabDelegate() {}
34 SessionID::id_type TabContentsSyncedTabDelegate::GetWindowId() const {
35 return SessionTabHelper::FromWebContents(web_contents_)->window_id().id();
38 SessionID::id_type TabContentsSyncedTabDelegate::GetSessionId() const {
39 return SessionTabHelper::FromWebContents(web_contents_)->session_id().id();
42 bool TabContentsSyncedTabDelegate::IsBeingDestroyed() const {
43 return web_contents_->IsBeingDestroyed();
46 Profile* TabContentsSyncedTabDelegate::profile() const {
47 return Profile::FromBrowserContext(web_contents_->GetBrowserContext());
50 std::string TabContentsSyncedTabDelegate::GetExtensionAppId() const {
51 #if defined(ENABLE_EXTENSIONS)
52 const scoped_refptr<const extensions::Extension> extension_app(
53 extensions::TabHelper::FromWebContents(web_contents_)->extension_app());
54 if (extension_app.get())
55 return extension_app->id();
56 #endif
57 return std::string();
60 int TabContentsSyncedTabDelegate::GetCurrentEntryIndex() const {
61 return web_contents_->GetController().GetCurrentEntryIndex();
64 int TabContentsSyncedTabDelegate::GetEntryCount() const {
65 return web_contents_->GetController().GetEntryCount();
68 int TabContentsSyncedTabDelegate::GetPendingEntryIndex() const {
69 return web_contents_->GetController().GetPendingEntryIndex();
72 NavigationEntry* TabContentsSyncedTabDelegate::GetPendingEntry() const {
73 return web_contents_->GetController().GetPendingEntry();
76 NavigationEntry* TabContentsSyncedTabDelegate::GetEntryAtIndex(int i) const {
77 return web_contents_->GetController().GetEntryAtIndex(i);
80 NavigationEntry* TabContentsSyncedTabDelegate::GetActiveEntry() const {
81 return web_contents_->GetController().GetVisibleEntry();
84 bool TabContentsSyncedTabDelegate::ProfileIsSupervised() const {
85 return profile()->IsSupervised();
88 const std::vector<const content::NavigationEntry*>*
89 TabContentsSyncedTabDelegate::GetBlockedNavigations() const {
90 #if defined(ENABLE_SUPERVISED_USERS)
91 SupervisedUserNavigationObserver* navigation_observer =
92 SupervisedUserNavigationObserver::FromWebContents(web_contents_);
93 DCHECK(navigation_observer);
94 return navigation_observer->blocked_navigations();
95 #else
96 NOTREACHED();
97 return NULL;
98 #endif
101 bool TabContentsSyncedTabDelegate::IsPinned() const {
102 const browser_sync::SyncedWindowDelegate* window = GetSyncedWindowDelegate();
104 // We might not have a parent window, e.g. Developer Tools.
105 return window ? window->IsTabPinned(this) : false;
108 bool TabContentsSyncedTabDelegate::HasWebContents() const { return true; }
110 content::WebContents* TabContentsSyncedTabDelegate::GetWebContents() const {
111 return web_contents_;
114 int TabContentsSyncedTabDelegate::GetSyncId() const {
115 return sync_session_id_;
118 void TabContentsSyncedTabDelegate::SetSyncId(int sync_id) {
119 sync_session_id_ = sync_id;