Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / ash / launcher / browser_status_monitor.h
blobebdfb7f0794811d4b1160fe9588f2ecbfaecb6e7
1 // Copyright 2013 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 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_
6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_
8 #include <map>
9 #include <string>
11 #include "ash/shelf/scoped_observer_with_duplicated_sources.h"
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/scoped_observer.h"
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
16 #include "chrome/browser/ui/browser_list_observer.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
18 #include "content/public/browser/web_contents_observer.h"
19 #include "ui/aura/client/activation_change_observer.h"
20 #include "ui/aura/window_observer.h"
21 #include "ui/gfx/display_observer.h"
23 namespace aura {
24 class Window;
26 namespace client {
27 class ActivationClient;
29 } // namespace aura
31 class Browser;
33 // BrowserStatusMonitor monitors creation/deletion of Browser and its
34 // TabStripModel to keep the launcher representation up to date as the
35 // active tab changes.
36 class BrowserStatusMonitor : public aura::client::ActivationChangeObserver,
37 public aura::WindowObserver,
38 public chrome::BrowserListObserver,
39 public gfx::DisplayObserver,
40 public TabStripModelObserver {
41 public:
42 explicit BrowserStatusMonitor(ChromeLauncherController* launcher_controller);
43 virtual ~BrowserStatusMonitor();
45 // A function which gets called when the current user has changed.
46 // Note that this function is called by the ChromeLauncherController to be
47 // able to do the activation in a proper order - rather then setting an
48 // observer.
49 virtual void ActiveUserChanged(const std::string& user_email) {}
51 // A shortcut to call the ChromeLauncherController's UpdateAppState().
52 void UpdateAppItemState(content::WebContents* contents,
53 ChromeLauncherController::AppState app_state);
55 // A shortcut to call the BrowserShortcutLauncherItemController's
56 // UpdateBrowserItemState().
57 void UpdateBrowserItemState();
59 // aura::client::ActivationChangeObserver overrides:
60 virtual void OnWindowActivated(aura::Window* gained_active,
61 aura::Window* lost_active) OVERRIDE;
63 // aura::WindowObserver overrides:
64 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;
66 // chrome::BrowserListObserver overrides:
67 virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
68 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
70 // gfx::DisplayObserver overrides:
71 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE;
72 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE;
73 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE;
75 // TabStripModelObserver overrides:
76 virtual void ActiveTabChanged(content::WebContents* old_contents,
77 content::WebContents* new_contents,
78 int index,
79 int reason) OVERRIDE;
80 virtual void TabReplacedAt(TabStripModel* tab_strip_model,
81 content::WebContents* old_contents,
82 content::WebContents* new_contents,
83 int index) OVERRIDE;
84 virtual void TabInsertedAt(content::WebContents* contents,
85 int index,
86 bool foreground) OVERRIDE;
87 virtual void TabClosingAt(TabStripModel* tab_strip_mode,
88 content::WebContents* contents,
89 int index) OVERRIDE;
91 protected:
92 // Add a V1 application to the shelf. This can get overwritten for multi
93 // profile implementations.
94 virtual void AddV1AppToShelf(Browser* browser);
96 // Remove a V1 application from the shelf. This can get overwritten for multi
97 // profile implementations.
98 virtual void RemoveV1AppFromShelf(Browser* browser);
100 // Check if V1 application is currently in the shelf.
101 bool IsV1AppInShelf(Browser* browser);
103 private:
104 // This class monitors the WebContent of the all tab and notifies a navigation
105 // to the BrowserStatusMonitor.
106 class LocalWebContentsObserver : public content::WebContentsObserver {
107 public:
108 LocalWebContentsObserver(content::WebContents* contents,
109 BrowserStatusMonitor* monitor);
110 virtual ~LocalWebContentsObserver();
112 // content::WebContentsObserver overrides:
113 virtual void DidNavigateMainFrame(
114 const content::LoadCommittedDetails& details,
115 const content::FrameNavigateParams& params) OVERRIDE;
117 private:
118 BrowserStatusMonitor* monitor_;
120 DISALLOW_COPY_AND_ASSIGN(LocalWebContentsObserver);
123 typedef std::map<Browser*, std::string> BrowserToAppIDMap;
124 typedef std::map<content::WebContents*, LocalWebContentsObserver*>
125 WebContentsToObserverMap;
127 // Create LocalWebContentsObserver for |contents|.
128 void AddWebContentsObserver(content::WebContents* contents);
130 // Remove LocalWebContentsObserver for |contents|.
131 void RemoveWebContentsObserver(content::WebContents* contents);
133 // Retruns the LauncherID for |contents|.
134 ash::LauncherID GetLauncherIDForWebContents(content::WebContents* contents);
136 ChromeLauncherController* launcher_controller_;
138 // Hold all observed activation clients.
139 ScopedObserverWithDuplicatedSources<aura::client::ActivationClient,
140 aura::client::ActivationChangeObserver> observed_activation_clients_;
142 // Hold all observed root windows.
143 ScopedObserver<aura::Window, aura::WindowObserver> observed_root_windows_;
145 BrowserToAppIDMap browser_to_app_id_map_;
147 WebContentsToObserverMap webcontents_to_observer_map_;
149 DISALLOW_COPY_AND_ASSIGN(BrowserStatusMonitor);
152 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_