OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/views/ash/launcher/launcher_updater.h" | 5 #include "chrome/browser/ui/views/ash/launcher/launcher_updater.h" |
6 | 6 |
7 #include "ash/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
8 #include "ash/launcher/launcher_model.h" | 8 #include "ash/launcher/launcher_model.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 void LauncherUpdater::Init() { | 52 void LauncherUpdater::Init() { |
53 tab_model_->AddObserver(this); | 53 tab_model_->AddObserver(this); |
54 if (type_ == TYPE_APP || type_ == TYPE_PANEL) { | 54 if (type_ == TYPE_APP || type_ == TYPE_PANEL) { |
55 // App type never changes, create the launcher item immediately. | 55 // App type never changes, create the launcher item immediately. |
56 ChromeLauncherDelegate::AppType app_type = | 56 ChromeLauncherDelegate::AppType app_type = |
57 type_ == TYPE_PANEL ? ChromeLauncherDelegate::APP_TYPE_PANEL | 57 type_ == TYPE_PANEL ? ChromeLauncherDelegate::APP_TYPE_PANEL |
58 : ChromeLauncherDelegate::APP_TYPE_WINDOW; | 58 : ChromeLauncherDelegate::APP_TYPE_WINDOW; |
59 item_id_ = launcher_delegate_->CreateAppLauncherItem( | 59 item_id_ = launcher_delegate_->CreateAppLauncherItem( |
60 this, app_id_, app_type); | 60 this, app_id_, app_type); |
61 } else { | 61 } else { |
62 bool is_private = false; | |
62 // Determine if we have any tabs that should get launcher items. | 63 // Determine if we have any tabs that should get launcher items. |
63 std::vector<TabContentsWrapper*> app_tabs; | 64 std::vector<TabContentsWrapper*> app_tabs; |
64 for (int i = 0; i < tab_model_->count(); ++i) { | 65 for (int i = 0; i < tab_model_->count(); ++i) { |
65 TabContentsWrapper* tab = tab_model_->GetTabContentsAt(i); | 66 TabContentsWrapper* tab = tab_model_->GetTabContentsAt(i); |
66 if (!launcher_delegate_->GetAppID(tab).empty()) | 67 if (!launcher_delegate_->GetAppID(tab).empty()) |
67 app_tabs.push_back(tab); | 68 app_tabs.push_back(tab); |
69 else if (tab->profile()->GetOriginalProfile() != tab->profile()) | |
70 is_private = true; | |
68 } | 71 } |
69 | 72 |
70 if (static_cast<int>(app_tabs.size()) != tab_model_->count()) | 73 if (static_cast<int>(app_tabs.size()) != tab_model_->count()) { |
71 CreateTabbedItem(); | 74 CreateTabbedItem(is_private); |
75 } | |
oshima
2012/03/09 17:54:02
remove {}
Zachary Kuznia
2012/03/09 22:17:35
Done.
| |
72 | 76 |
73 // Create items for the app tabs. | 77 // Create items for the app tabs. |
74 for (size_t i = 0; i < app_tabs.size(); ++i) | 78 for (size_t i = 0; i < app_tabs.size(); ++i) |
75 AddAppItem(app_tabs[i]); | 79 AddAppItem(app_tabs[i]); |
76 } | 80 } |
77 UpdateLauncher(tab_model_->GetActiveTabContents()); | 81 UpdateLauncher(tab_model_->GetActiveTabContents()); |
78 } | 82 } |
79 | 83 |
80 // static | 84 // static |
81 LauncherUpdater* LauncherUpdater::Create(Browser* browser) { | 85 LauncherUpdater* LauncherUpdater::Create(Browser* browser) { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 item.image = *ResourceBundle::GetSharedInstance().GetBitmapNamed( | 224 item.image = *ResourceBundle::GetSharedInstance().GetBitmapNamed( |
221 IDR_DEFAULT_FAVICON); | 225 IDR_DEFAULT_FAVICON); |
222 } | 226 } |
223 } | 227 } |
224 } | 228 } |
225 launcher_model()->Set(item_index, item); | 229 launcher_model()->Set(item_index, item); |
226 } | 230 } |
227 | 231 |
228 void LauncherUpdater::UpdateAppTabState(TabContentsWrapper* tab, | 232 void LauncherUpdater::UpdateAppTabState(TabContentsWrapper* tab, |
229 UpdateType update_type) { | 233 UpdateType update_type) { |
234 bool private_tab = (tab->profile()->GetOriginalProfile() != tab->profile()); | |
230 bool showing_app_item = app_map_.find(tab) != app_map_.end(); | 235 bool showing_app_item = app_map_.find(tab) != app_map_.end(); |
231 std::string app_id = update_type == UPDATE_TAB_REMOVED ? | 236 std::string app_id = update_type == UPDATE_TAB_REMOVED ? |
232 std::string() : launcher_delegate_->GetAppID(tab); | 237 std::string() : launcher_delegate_->GetAppID(tab); |
233 bool show_app = !app_id.empty(); | 238 bool show_app = !app_id.empty(); |
234 if (showing_app_item == show_app) { | 239 if (showing_app_item == show_app) { |
235 if (!show_app) { | 240 if (!show_app) { |
236 if (item_id_ == -1 && update_type == UPDATE_TAB_INSERTED) { | 241 if (item_id_ == -1 && update_type == UPDATE_TAB_INSERTED) { |
237 // A new non-app tab was added and we have no app tabs. Add one now. | 242 // A new non-app tab was added and we have no app tabs. Add one now. |
238 CreateTabbedItem(); | 243 CreateTabbedItem(private_tab); |
239 } else if (item_id_ != -1 && update_type == UPDATE_TAB_REMOVED && | 244 } else if (item_id_ != -1 && update_type == UPDATE_TAB_REMOVED && |
240 tab_model_->count() == (static_cast<int>(app_map_.size()))) { | 245 tab_model_->count() == (static_cast<int>(app_map_.size()))) { |
241 launcher_delegate_->LauncherItemClosed(item_id_); | 246 launcher_delegate_->LauncherItemClosed(item_id_); |
242 item_id_ = -1; | 247 item_id_ = -1; |
243 } | 248 } |
244 return; | 249 return; |
245 } | 250 } |
246 | 251 |
247 if (app_id != app_map_[tab].app_id) { | 252 if (app_id != app_map_[tab].app_id) { |
248 // The extension changed. | 253 // The extension changed. |
(...skipping 14 matching lines...) Expand all Loading... | |
263 (tab_model_->count() != 1 && | 268 (tab_model_->count() != 1 && |
264 tab_model_->count() == (static_cast<int>(app_map_.size()) + 1)))) { | 269 tab_model_->count() == (static_cast<int>(app_map_.size()) + 1)))) { |
265 if (!launcher_delegate_->IsPinned(launcher_id)) { | 270 if (!launcher_delegate_->IsPinned(launcher_id)) { |
266 // Swap the item for a tabbed item. | 271 // Swap the item for a tabbed item. |
267 item_id_ = launcher_id; | 272 item_id_ = launcher_id; |
268 launcher_delegate_->ConvertAppToTabbed(item_id_); | 273 launcher_delegate_->ConvertAppToTabbed(item_id_); |
269 } else { | 274 } else { |
270 // If the app is pinned we have to leave it and create a new tabbed | 275 // If the app is pinned we have to leave it and create a new tabbed |
271 // item. | 276 // item. |
272 launcher_delegate_->LauncherItemClosed(launcher_id); | 277 launcher_delegate_->LauncherItemClosed(launcher_id); |
273 CreateTabbedItem(); | 278 CreateTabbedItem(private_tab); |
274 } | 279 } |
275 ash::LauncherItem item(ash::TYPE_TABBED); | 280 ash::LauncherItem item(ash::TYPE_TABBED, private_tab); |
276 item.num_tabs = tab_model_->count(); | 281 item.num_tabs = tab_model_->count(); |
277 launcher_model()->Set(launcher_model()->ItemIndexByID(item_id_), item); | 282 launcher_model()->Set(launcher_model()->ItemIndexByID(item_id_), item); |
278 } else { | 283 } else { |
279 // We have a tabbed item, so we can remove the the app item. | 284 // We have a tabbed item, so we can remove the the app item. |
280 launcher_delegate_->LauncherItemClosed(launcher_id); | 285 launcher_delegate_->LauncherItemClosed(launcher_id); |
281 } | 286 } |
282 } else { | 287 } else { |
283 // Going from not showing to showing. | 288 // Going from not showing to showing. |
284 if (item_id_ != -1 && | 289 if (item_id_ != -1 && |
285 static_cast<int>(app_map_.size()) + 1 == tab_model_->count()) { | 290 static_cast<int>(app_map_.size()) + 1 == tab_model_->count()) { |
(...skipping 28 matching lines...) Expand all Loading... | |
314 } | 319 } |
315 | 320 |
316 void LauncherUpdater::RegisterAppItem(ash::LauncherID id, | 321 void LauncherUpdater::RegisterAppItem(ash::LauncherID id, |
317 TabContentsWrapper* tab) { | 322 TabContentsWrapper* tab) { |
318 AppTabDetails details; | 323 AppTabDetails details; |
319 details.id = id; | 324 details.id = id; |
320 details.app_id = launcher_delegate_->GetAppID(tab); | 325 details.app_id = launcher_delegate_->GetAppID(tab); |
321 app_map_[tab] = details; | 326 app_map_[tab] = details; |
322 } | 327 } |
323 | 328 |
324 void LauncherUpdater::CreateTabbedItem() { | 329 void LauncherUpdater::CreateTabbedItem(bool is_private) { |
325 DCHECK_EQ(-1, item_id_); | 330 DCHECK_EQ(-1, item_id_); |
326 item_id_ = launcher_delegate_->CreateTabbedLauncherItem(this); | 331 item_id_ = launcher_delegate_->CreateTabbedLauncherItem(this, is_private); |
327 } | 332 } |
328 | 333 |
329 bool LauncherUpdater::ContainsID(ash::LauncherID id, TabContentsWrapper** tab) { | 334 bool LauncherUpdater::ContainsID(ash::LauncherID id, TabContentsWrapper** tab) { |
330 if (item_id_ == id) | 335 if (item_id_ == id) |
331 return true; | 336 return true; |
332 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end(); | 337 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end(); |
333 ++i) { | 338 ++i) { |
334 if (i->second.id == id) { | 339 if (i->second.id == id) { |
335 *tab = i->first; | 340 *tab = i->first; |
336 return true; | 341 return true; |
337 } | 342 } |
338 } | 343 } |
339 return false; | 344 return false; |
340 } | 345 } |
341 | 346 |
342 ash::LauncherModel* LauncherUpdater::launcher_model() { | 347 ash::LauncherModel* LauncherUpdater::launcher_model() { |
343 return launcher_delegate_->model(); | 348 return launcher_delegate_->model(); |
344 } | 349 } |
OLD | NEW |