tab_contents_synced_tab_delegate.cc revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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/extensions/tab_helper.h"
9#include "chrome/browser/profiles/profile.h"
10#include "chrome/browser/sessions/session_tab_helper.h"
11#include "chrome/browser/sync/glue/synced_window_delegate.h"
12#include "chrome/common/extensions/extension.h"
13#include "content/public/browser/navigation_controller.h"
14#include "content/public/browser/navigation_entry.h"
15#include "content/public/browser/web_contents.h"
16
17using content::NavigationEntry;
18
19DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabContentsSyncedTabDelegate);
20
21TabContentsSyncedTabDelegate::TabContentsSyncedTabDelegate(
22    content::WebContents* web_contents)
23        : web_contents_(web_contents) {}
24
25TabContentsSyncedTabDelegate::~TabContentsSyncedTabDelegate() {}
26
27SessionID::id_type TabContentsSyncedTabDelegate::GetWindowId() const {
28  return SessionTabHelper::FromWebContents(web_contents_)->window_id().id();
29}
30
31SessionID::id_type TabContentsSyncedTabDelegate::GetSessionId() const {
32  return SessionTabHelper::FromWebContents(web_contents_)->session_id().id();
33}
34
35bool TabContentsSyncedTabDelegate::IsBeingDestroyed() const {
36  return web_contents_->IsBeingDestroyed();
37}
38
39Profile* TabContentsSyncedTabDelegate::profile() const {
40  return Profile::FromBrowserContext(web_contents_->GetBrowserContext());
41}
42
43std::string TabContentsSyncedTabDelegate::GetExtensionAppId() const {
44  const scoped_refptr<const extensions::Extension> extension_app(
45      extensions::TabHelper::FromWebContents(web_contents_)->extension_app());
46  return (extension_app.get() ? extension_app->id() : std::string());
47}
48
49int TabContentsSyncedTabDelegate::GetCurrentEntryIndex() const {
50  return web_contents_->GetController().GetCurrentEntryIndex();
51}
52
53int TabContentsSyncedTabDelegate::GetEntryCount() const {
54  return web_contents_->GetController().GetEntryCount();
55}
56
57int TabContentsSyncedTabDelegate::GetPendingEntryIndex() const {
58  return web_contents_->GetController().GetPendingEntryIndex();
59}
60
61NavigationEntry* TabContentsSyncedTabDelegate::GetPendingEntry() const {
62  return web_contents_->GetController().GetPendingEntry();
63}
64
65NavigationEntry* TabContentsSyncedTabDelegate::GetEntryAtIndex(int i) const {
66  return web_contents_->GetController().GetEntryAtIndex(i);
67}
68
69NavigationEntry* TabContentsSyncedTabDelegate::GetActiveEntry() const {
70  return web_contents_->GetController().GetActiveEntry();
71}
72
73bool TabContentsSyncedTabDelegate::IsPinned() const {
74  const browser_sync::SyncedWindowDelegate* window =
75      browser_sync::SyncedWindowDelegate::FindSyncedWindowDelegateWithId(
76          GetWindowId());
77  // We might not have a parent window, e.g. Developer Tools.
78  return window ? window->IsTabPinned(this) : false;
79}
80