summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h
blob: 2bfb72411866452de204a5d5035eff97dca90a67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_LAUNCHER_ITEM_CONTROLLER_H_
#define CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_LAUNCHER_ITEM_CONTROLLER_H_

#include <string>

#include "ash/launcher/launcher_types.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
#include "chrome/browser/ui/ash/launcher/launcher_favicon_loader.h"
#include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "ui/aura/window_observer.h"

class Browser;
class LauncherFaviconLoader;
class TabContents;

namespace ash {
class LauncherModel;
}

// BrowserLauncherItemController is responsible for keeping the launcher
// representation of a window up to date as the active tab changes.
class BrowserLauncherItemController : public LauncherItemController,
                                      public TabStripModelObserver,
                                      public LauncherFaviconLoader::Delegate,
                                      public aura::WindowObserver {
 public:
  // This API is to be used as part of testing only.
  class TestApi {
   public:
    explicit TestApi(BrowserLauncherItemController* controller)
        : controller_(controller) {}
    ~TestApi() {}

    // Returns the launcher id for the browser window.
    ash::LauncherID item_id() const { return controller_->launcher_id(); }

   private:
    BrowserLauncherItemController* controller_;
  };

  BrowserLauncherItemController(Type type,
                                aura::Window* window,
                                TabStripModel* tab_model,
                                ChromeLauncherController* launcher_controller,
                                const std::string& app_id);
  virtual ~BrowserLauncherItemController();

  // Sets up this BrowserLauncherItemController.
  void Init();

  // Creates and returns a new BrowserLauncherItemController for |browser|. This
  // returns NULL if a BrowserLauncherItemController is not needed for the
  // specified browser.
  static BrowserLauncherItemController* Create(Browser* browser);

  LauncherFaviconLoader* favicon_loader() const {
    return favicon_loader_.get();
  }

  // Call to indicate that the window the tabcontents are in has changed its
  // activation state.
  void BrowserActivationStateChanged();

  // LauncherItemController overrides:
  virtual string16 GetTitle() OVERRIDE;
  virtual bool HasWindow(aura::Window* window) const OVERRIDE;
  virtual void Open() OVERRIDE;
  virtual void Close() OVERRIDE;
  virtual void Clicked() OVERRIDE;

  // TabStripModel overrides:
  virtual void ActiveTabChanged(TabContents* old_contents,
                                TabContents* new_contents,
                                int index,
                                bool user_gesture) OVERRIDE;
  virtual void TabInsertedAt(TabContents* contents,
                             int index,
                             bool foreground) OVERRIDE;
  virtual void TabDetachedAt(TabContents* contents, int index) OVERRIDE;
  virtual void TabChangedAt(
      TabContents* tab,
      int index,
      TabStripModelObserver::TabChangeType change_type) OVERRIDE;
  virtual void TabReplacedAt(TabStripModel* tab_strip_model,
                             TabContents* old_contents,
                             TabContents* new_contents,
                             int index) OVERRIDE;

  // LauncherFaviconLoader::Delegate overrides:
  virtual void FaviconUpdated() OVERRIDE;

  // aura::WindowObserver overrides:
  virtual void OnWindowPropertyChanged(aura::Window* window,
                                       const void* key,
                                       intptr_t old) OVERRIDE;

 private:
  FRIEND_TEST_ALL_PREFIXES(BrowserLauncherItemControllerTest, PanelItem);

  // Used to identify what an update corresponds to.
  enum UpdateType {
    UPDATE_TAB_REMOVED,
    UPDATE_TAB_CHANGED,
    UPDATE_TAB_INSERTED,
  };

  // Updates the launcher item status base on the activation and attention
  // state of the window.
  void UpdateItemStatus();

  // Updates the launcher from |tab|.
  void UpdateLauncher(TabContents* tab);

  void UpdateAppState(TabContents* tab);

  ash::LauncherModel* launcher_model();

  // Browser window we're in.
  aura::Window* window_;

  TabStripModel* tab_model_;

  const std::string app_id_;

  // Whether this is associated with an incognito profile.
  const bool is_incognito_;

  // Loads launcher sized favicons for panels.
  scoped_ptr<LauncherFaviconLoader> favicon_loader_;

  DISALLOW_COPY_AND_ASSIGN(BrowserLauncherItemController);
};

#endif  // CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_LAUNCHER_ITEM_CONTROLLER_H_