Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: chrome/browser/ui/ash/launcher/browser_status_monitor.cc

Issue 23534022: Handling browser item status in BrowserShortcutLauncherItemController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CreateAppAndBrowserState() Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" 5 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/wm/window_util.h" 8 #include "ash/wm/window_util.h"
9 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h"
9 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 10 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
10 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_finder.h" 12 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/browser_list.h" 13 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/browser_window.h" 14 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/browser/web_applications/web_app.h" 16 #include "chrome/browser/web_applications/web_app.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_contents_view.h" 18 #include "content/public/browser/web_contents_view.h"
18 #include "ui/aura/client/activation_client.h" 19 #include "ui/aura/client/activation_client.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 59
59 BrowserList* browser_list = 60 BrowserList* browser_list =
60 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); 61 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
61 62
62 browser_list->RemoveObserver(this); 63 browser_list->RemoveObserver(this);
63 } 64 }
64 65
65 void BrowserStatusMonitor::OnWindowActivated(aura::Window* gained_active, 66 void BrowserStatusMonitor::OnWindowActivated(aura::Window* gained_active,
66 aura::Window* lost_active) { 67 aura::Window* lost_active) {
67 Browser* browser = chrome::FindBrowserWithWindow(lost_active); 68 Browser* browser = chrome::FindBrowserWithWindow(lost_active);
68 content::WebContents* active_contents = NULL;
69
70 if (browser) { 69 if (browser) {
71 active_contents = browser->tab_strip_model()->GetActiveWebContents(); 70 UpdateAppAndBrowserState(
72 if (active_contents) 71 browser->tab_strip_model()->GetActiveWebContents());
73 UpdateAppState(active_contents);
74 } 72 }
75 73
76 browser = chrome::FindBrowserWithWindow(gained_active); 74 browser = chrome::FindBrowserWithWindow(gained_active);
77 if (browser) { 75 if (browser) {
78 active_contents = browser->tab_strip_model()->GetActiveWebContents(); 76 UpdateAppAndBrowserState(
79 if (active_contents) 77 browser->tab_strip_model()->GetActiveWebContents());
80 UpdateAppState(active_contents);
81 } 78 }
82 } 79 }
83 80
84 void BrowserStatusMonitor::OnWindowDestroyed(aura::Window* window) { 81 void BrowserStatusMonitor::OnWindowDestroyed(aura::Window* window) {
85 // Remove RootWindow and its ActivationClient from observed list. 82 // Remove RootWindow and its ActivationClient from observed list.
86 observed_root_windows_.Remove(window); 83 observed_root_windows_.Remove(window);
87 observed_activation_clients_.Remove(aura::client::GetActivationClient( 84 observed_activation_clients_.Remove(aura::client::GetActivationClient(
88 static_cast<aura::RootWindow*>(window))); 85 static_cast<aura::RootWindow*>(window)));
89 } 86 }
90 87
(...skipping 10 matching lines...) Expand all
101 } 98 }
102 } 99 }
103 100
104 void BrowserStatusMonitor::OnBrowserRemoved(Browser* browser) { 101 void BrowserStatusMonitor::OnBrowserRemoved(Browser* browser) {
105 browser->tab_strip_model()->RemoveObserver(this); 102 browser->tab_strip_model()->RemoveObserver(this);
106 103
107 if (browser_to_app_id_map_.find(browser) != browser_to_app_id_map_.end()) { 104 if (browser_to_app_id_map_.find(browser) != browser_to_app_id_map_.end()) {
108 launcher_controller_->UnlockV1AppWithID(browser_to_app_id_map_[browser]); 105 launcher_controller_->UnlockV1AppWithID(browser_to_app_id_map_[browser]);
109 browser_to_app_id_map_.erase(browser); 106 browser_to_app_id_map_.erase(browser);
110 } 107 }
111 launcher_controller_->UpdateBrowserItemStatus(); 108 UpdateBrowserItemState();
112 } 109 }
113 110
114 void BrowserStatusMonitor::OnDisplayBoundsChanged( 111 void BrowserStatusMonitor::OnDisplayBoundsChanged(
115 const gfx::Display& display) { 112 const gfx::Display& display) {
116 // Do nothing here. 113 // Do nothing here.
117 } 114 }
118 115
119 void BrowserStatusMonitor::OnDisplayAdded(const gfx::Display& new_display) { 116 void BrowserStatusMonitor::OnDisplayAdded(const gfx::Display& new_display) {
120 // Add a new RootWindow and its ActivationClient to observed list. 117 // Add a new RootWindow and its ActivationClient to observed list.
121 aura::RootWindow* root_window = ash::Shell::GetInstance()-> 118 aura::RootWindow* root_window = ash::Shell::GetInstance()->
(...skipping 18 matching lines...) Expand all
140 content::WebContents* new_contents, 137 content::WebContents* new_contents,
141 int index, 138 int index,
142 int reason) { 139 int reason) {
143 Browser* browser = NULL; 140 Browser* browser = NULL;
144 if (old_contents) 141 if (old_contents)
145 browser = chrome::FindBrowserWithWebContents(old_contents); 142 browser = chrome::FindBrowserWithWebContents(old_contents);
146 143
147 // Update immediately on a tab change. 144 // Update immediately on a tab change.
148 if (browser && 145 if (browser &&
149 (TabStripModel::kNoTab != 146 (TabStripModel::kNoTab !=
150 browser->tab_strip_model()->GetIndexOfWebContents(old_contents))) 147 browser->tab_strip_model()->GetIndexOfWebContents(old_contents))) {
151 UpdateAppState(old_contents); 148 launcher_controller_->UpdateAppState(
149 old_contents,
150 ChromeLauncherController::APP_STATE_INACTIVE);
151 }
152 152
153 UpdateAppState(new_contents); 153 UpdateAppAndBrowserState(new_contents);
154 } 154 }
155 155
156 void BrowserStatusMonitor::TabInsertedAt(content::WebContents* contents, 156 void BrowserStatusMonitor::TabInsertedAt(content::WebContents* contents,
157 int index, 157 int index,
158 bool foreground) { 158 bool foreground) {
159 UpdateAppState(contents); 159 UpdateAppAndBrowserState(contents);
160 } 160 }
161 161
162 void BrowserStatusMonitor::TabDetachedAt(content::WebContents* contents, 162 void BrowserStatusMonitor::TabDetachedAt(content::WebContents* contents,
163 int index) { 163 int index) {
164 launcher_controller_->UpdateAppState( 164 launcher_controller_->UpdateAppState(
165 contents, ChromeLauncherController::APP_STATE_REMOVED); 165 contents, ChromeLauncherController::APP_STATE_REMOVED);
166 UpdateBrowserItemState();
166 } 167 }
167 168
168 void BrowserStatusMonitor::TabChangedAt( 169 void BrowserStatusMonitor::TabChangedAt(
169 content::WebContents* contents, 170 content::WebContents* contents,
170 int index, 171 int index,
171 TabStripModelObserver::TabChangeType change_type) { 172 TabStripModelObserver::TabChangeType change_type) {
172 UpdateAppState(contents); 173 UpdateAppAndBrowserState(contents);
173 } 174 }
174 175
175 void BrowserStatusMonitor::TabReplacedAt(TabStripModel* tab_strip_model, 176 void BrowserStatusMonitor::TabReplacedAt(TabStripModel* tab_strip_model,
176 content::WebContents* old_contents, 177 content::WebContents* old_contents,
177 content::WebContents* new_contents, 178 content::WebContents* new_contents,
178 int index) { 179 int index) {
179 launcher_controller_->UpdateAppState( 180 launcher_controller_->UpdateAppState(
180 old_contents, 181 old_contents,
181 ChromeLauncherController::APP_STATE_REMOVED); 182 ChromeLauncherController::APP_STATE_REMOVED);
182 UpdateAppState(new_contents); 183 UpdateAppAndBrowserState(new_contents);
183 } 184 }
184 185
185 void BrowserStatusMonitor::UpdateAppState(content::WebContents* contents) { 186 void BrowserStatusMonitor::UpdateAppAndBrowserState(
186 if (!contents) 187 content::WebContents* contents) {
187 return; 188 if (contents) {
189 ChromeLauncherController::AppState app_state =
190 ChromeLauncherController::APP_STATE_INACTIVE;
188 191
189 ChromeLauncherController::AppState app_state = 192 Browser* browser = chrome::FindBrowserWithWebContents(contents);
190 ChromeLauncherController::APP_STATE_INACTIVE; 193 if (browser->tab_strip_model()->GetActiveWebContents() == contents) {
194 if (browser->window()->IsActive())
195 app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE;
196 else
197 app_state = ChromeLauncherController::APP_STATE_ACTIVE;
198 }
191 199
192 Browser* browser = chrome::FindBrowserWithWebContents(contents); 200 launcher_controller_->UpdateAppState(contents, app_state);
193 if (browser->tab_strip_model()->GetActiveWebContents() == contents) {
194 if (browser->window()->IsActive())
195 app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE;
196 else
197 app_state = ChromeLauncherController::APP_STATE_ACTIVE;
198 } 201 }
202 UpdateBrowserItemState();
203 }
199 204
200 launcher_controller_->UpdateAppState(contents, app_state); 205 void BrowserStatusMonitor::UpdateBrowserItemState() {
206 launcher_controller_->GetBrowserShortcutLauncherItemController()->
207 UpdateBrowserItemState();
201 } 208 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/browser_status_monitor.h ('k') | chrome/browser/ui/ash/launcher/chrome_launcher_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698