Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / sync / tab_contents_synced_tab_delegate.cc
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.
4
5 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
6
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"
14
15 #if defined(ENABLE_EXTENSIONS)
16 #include "chrome/browser/extensions/tab_helper.h"
17 #include "extensions/common/extension.h"
18 #endif
19
20 #if defined(ENABLE_MANAGED_USERS)
21 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h"
22 #endif
23
24 using content::NavigationEntry;
25
26 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabContentsSyncedTabDelegate);
27
28 TabContentsSyncedTabDelegate::TabContentsSyncedTabDelegate(
29     content::WebContents* web_contents)
30     : web_contents_(web_contents), sync_session_id_(0) {}
31
32 TabContentsSyncedTabDelegate::~TabContentsSyncedTabDelegate() {}
33
34 SessionID::id_type TabContentsSyncedTabDelegate::GetWindowId() const {
35   return SessionTabHelper::FromWebContents(web_contents_)->window_id().id();
36 }
37
38 SessionID::id_type TabContentsSyncedTabDelegate::GetSessionId() const {
39   return SessionTabHelper::FromWebContents(web_contents_)->session_id().id();
40 }
41
42 bool TabContentsSyncedTabDelegate::IsBeingDestroyed() const {
43   return web_contents_->IsBeingDestroyed();
44 }
45
46 Profile* TabContentsSyncedTabDelegate::profile() const {
47   return Profile::FromBrowserContext(web_contents_->GetBrowserContext());
48 }
49
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();
58 }
59
60 int TabContentsSyncedTabDelegate::GetCurrentEntryIndex() const {
61   return web_contents_->GetController().GetCurrentEntryIndex();
62 }
63
64 int TabContentsSyncedTabDelegate::GetEntryCount() const {
65   return web_contents_->GetController().GetEntryCount();
66 }
67
68 int TabContentsSyncedTabDelegate::GetPendingEntryIndex() const {
69   return web_contents_->GetController().GetPendingEntryIndex();
70 }
71
72 NavigationEntry* TabContentsSyncedTabDelegate::GetPendingEntry() const {
73   return web_contents_->GetController().GetPendingEntry();
74 }
75
76 NavigationEntry* TabContentsSyncedTabDelegate::GetEntryAtIndex(int i) const {
77   return web_contents_->GetController().GetEntryAtIndex(i);
78 }
79
80 NavigationEntry* TabContentsSyncedTabDelegate::GetActiveEntry() const {
81   return web_contents_->GetController().GetVisibleEntry();
82 }
83
84 bool TabContentsSyncedTabDelegate::ProfileIsSupervised() const {
85   return profile()->IsSupervised();
86 }
87
88 const std::vector<const content::NavigationEntry*>*
89 TabContentsSyncedTabDelegate::GetBlockedNavigations() const {
90 #if defined(ENABLE_MANAGED_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
99 }
100
101 bool TabContentsSyncedTabDelegate::IsPinned() const {
102   const browser_sync::SyncedWindowDelegate* window =
103       browser_sync::SyncedWindowDelegate::FindSyncedWindowDelegateWithId(
104           GetWindowId());
105   // We might not have a parent window, e.g. Developer Tools.
106   return window ? window->IsTabPinned(this) : false;
107 }
108
109 bool TabContentsSyncedTabDelegate::HasWebContents() const { return true; }
110
111 content::WebContents* TabContentsSyncedTabDelegate::GetWebContents() const {
112   return web_contents_;
113 }
114
115 int TabContentsSyncedTabDelegate::GetSyncId() const {
116   return sync_session_id_;
117 }
118
119 void TabContentsSyncedTabDelegate::SetSyncId(int sync_id) {
120   sync_session_id_ = sync_id;
121 }