Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 #include "grit/ui_resources.h" | 21 #include "grit/ui_resources.h" |
| 22 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
| 23 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 24 | 24 |
| 25 LauncherUpdater::AppTabDetails::AppTabDetails() : id(0) { | 25 LauncherUpdater::AppTabDetails::AppTabDetails() : id(0) { |
| 26 } | 26 } |
| 27 | 27 |
| 28 LauncherUpdater::AppTabDetails::~AppTabDetails() { | 28 LauncherUpdater::AppTabDetails::~AppTabDetails() { |
| 29 } | 29 } |
| 30 | 30 |
| 31 LauncherUpdater::LauncherUpdater(aura::Window* window, | 31 LauncherUpdater::LauncherUpdater(aura::Window* window, |
|
sky
2012/03/09 22:40:46
A LauncherUpdater is always going to be associated
Zachary Kuznia
2012/03/09 23:23:10
Done.
| |
| 32 TabStripModel* tab_model, | 32 TabStripModel* tab_model, |
| 33 ChromeLauncherDelegate* delegate, | 33 ChromeLauncherDelegate* delegate, |
| 34 Type type, | 34 Type type, |
| 35 const std::string& app_id) | 35 const std::string& app_id) |
| 36 : window_(window), | 36 : window_(window), |
| 37 tab_model_(tab_model), | 37 tab_model_(tab_model), |
| 38 launcher_delegate_(delegate), | 38 launcher_delegate_(delegate), |
| 39 type_(type), | 39 type_(type), |
| 40 app_id_(app_id), | 40 app_id_(app_id), |
| 41 item_id_(-1) { | 41 item_id_(-1) { |
| (...skipping 10 matching lines...) Expand all 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); |
| 72 | 75 |
| 73 // Create items for the app tabs. | 76 // Create items for the app tabs. |
| 74 for (size_t i = 0; i < app_tabs.size(); ++i) | 77 for (size_t i = 0; i < app_tabs.size(); ++i) |
| 75 AddAppItem(app_tabs[i]); | 78 AddAppItem(app_tabs[i]); |
| 76 } | 79 } |
| 77 UpdateLauncher(tab_model_->GetActiveTabContents()); | 80 UpdateLauncher(tab_model_->GetActiveTabContents()); |
| 78 } | 81 } |
| 79 | 82 |
| 80 // static | 83 // static |
| 81 LauncherUpdater* LauncherUpdater::Create(Browser* browser) { | 84 LauncherUpdater* LauncherUpdater::Create(Browser* browser) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 item.image = *ResourceBundle::GetSharedInstance().GetBitmapNamed( | 223 item.image = *ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 221 IDR_DEFAULT_FAVICON); | 224 IDR_DEFAULT_FAVICON); |
| 222 } | 225 } |
| 223 } | 226 } |
| 224 } | 227 } |
| 225 launcher_model()->Set(item_index, item); | 228 launcher_model()->Set(item_index, item); |
| 226 } | 229 } |
| 227 | 230 |
| 228 void LauncherUpdater::UpdateAppTabState(TabContentsWrapper* tab, | 231 void LauncherUpdater::UpdateAppTabState(TabContentsWrapper* tab, |
| 229 UpdateType update_type) { | 232 UpdateType update_type) { |
| 233 bool is_incognito = (tab->profile()->GetOriginalProfile() != tab->profile()); | |
| 230 bool showing_app_item = app_map_.find(tab) != app_map_.end(); | 234 bool showing_app_item = app_map_.find(tab) != app_map_.end(); |
| 231 std::string app_id = update_type == UPDATE_TAB_REMOVED ? | 235 std::string app_id = update_type == UPDATE_TAB_REMOVED ? |
| 232 std::string() : launcher_delegate_->GetAppID(tab); | 236 std::string() : launcher_delegate_->GetAppID(tab); |
| 233 bool show_app = !app_id.empty(); | 237 bool show_app = !app_id.empty(); |
| 234 if (showing_app_item == show_app) { | 238 if (showing_app_item == show_app) { |
| 235 if (!show_app) { | 239 if (!show_app) { |
| 236 if (item_id_ == -1 && update_type == UPDATE_TAB_INSERTED) { | 240 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. | 241 // A new non-app tab was added and we have no app tabs. Add one now. |
| 238 CreateTabbedItem(); | 242 CreateTabbedItem(is_incognito); |
| 239 } else if (item_id_ != -1 && update_type == UPDATE_TAB_REMOVED && | 243 } else if (item_id_ != -1 && update_type == UPDATE_TAB_REMOVED && |
| 240 tab_model_->count() == (static_cast<int>(app_map_.size()))) { | 244 tab_model_->count() == (static_cast<int>(app_map_.size()))) { |
| 241 launcher_delegate_->LauncherItemClosed(item_id_); | 245 launcher_delegate_->LauncherItemClosed(item_id_); |
| 242 item_id_ = -1; | 246 item_id_ = -1; |
| 243 } | 247 } |
| 244 return; | 248 return; |
| 245 } | 249 } |
| 246 | 250 |
| 247 if (app_id != app_map_[tab].app_id) { | 251 if (app_id != app_map_[tab].app_id) { |
| 248 // The extension changed. | 252 // The extension changed. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 263 (tab_model_->count() != 1 && | 267 (tab_model_->count() != 1 && |
| 264 tab_model_->count() == (static_cast<int>(app_map_.size()) + 1)))) { | 268 tab_model_->count() == (static_cast<int>(app_map_.size()) + 1)))) { |
| 265 if (!launcher_delegate_->IsPinned(launcher_id)) { | 269 if (!launcher_delegate_->IsPinned(launcher_id)) { |
| 266 // Swap the item for a tabbed item. | 270 // Swap the item for a tabbed item. |
| 267 item_id_ = launcher_id; | 271 item_id_ = launcher_id; |
| 268 launcher_delegate_->ConvertAppToTabbed(item_id_); | 272 launcher_delegate_->ConvertAppToTabbed(item_id_); |
| 269 } else { | 273 } else { |
| 270 // If the app is pinned we have to leave it and create a new tabbed | 274 // If the app is pinned we have to leave it and create a new tabbed |
| 271 // item. | 275 // item. |
| 272 launcher_delegate_->LauncherItemClosed(launcher_id); | 276 launcher_delegate_->LauncherItemClosed(launcher_id); |
| 273 CreateTabbedItem(); | 277 CreateTabbedItem(is_incognito); |
| 274 } | 278 } |
| 275 ash::LauncherItem item(ash::TYPE_TABBED); | 279 ash::LauncherItem item; |
| 280 item.type = ash::TYPE_TABBED; | |
| 281 item.is_incognito = is_incognito; | |
| 276 item.num_tabs = tab_model_->count(); | 282 item.num_tabs = tab_model_->count(); |
| 277 launcher_model()->Set(launcher_model()->ItemIndexByID(item_id_), item); | 283 launcher_model()->Set(launcher_model()->ItemIndexByID(item_id_), item); |
| 278 } else { | 284 } else { |
| 279 // We have a tabbed item, so we can remove the the app item. | 285 // We have a tabbed item, so we can remove the the app item. |
| 280 launcher_delegate_->LauncherItemClosed(launcher_id); | 286 launcher_delegate_->LauncherItemClosed(launcher_id); |
| 281 } | 287 } |
| 282 } else { | 288 } else { |
| 283 // Going from not showing to showing. | 289 // Going from not showing to showing. |
| 284 if (item_id_ != -1 && | 290 if (item_id_ != -1 && |
| 285 static_cast<int>(app_map_.size()) + 1 == tab_model_->count()) { | 291 static_cast<int>(app_map_.size()) + 1 == tab_model_->count()) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 314 } | 320 } |
| 315 | 321 |
| 316 void LauncherUpdater::RegisterAppItem(ash::LauncherID id, | 322 void LauncherUpdater::RegisterAppItem(ash::LauncherID id, |
| 317 TabContentsWrapper* tab) { | 323 TabContentsWrapper* tab) { |
| 318 AppTabDetails details; | 324 AppTabDetails details; |
| 319 details.id = id; | 325 details.id = id; |
| 320 details.app_id = launcher_delegate_->GetAppID(tab); | 326 details.app_id = launcher_delegate_->GetAppID(tab); |
| 321 app_map_[tab] = details; | 327 app_map_[tab] = details; |
| 322 } | 328 } |
| 323 | 329 |
| 324 void LauncherUpdater::CreateTabbedItem() { | 330 void LauncherUpdater::CreateTabbedItem(bool is_private) { |
| 325 DCHECK_EQ(-1, item_id_); | 331 DCHECK_EQ(-1, item_id_); |
| 326 item_id_ = launcher_delegate_->CreateTabbedLauncherItem(this); | 332 item_id_ = launcher_delegate_->CreateTabbedLauncherItem( |
| 333 this, | |
| 334 is_private ? ChromeLauncherDelegate::STATE_INCOGNITO : | |
| 335 ChromeLauncherDelegate::STATE_NOT_INCOGNITO); | |
| 327 } | 336 } |
| 328 | 337 |
| 329 bool LauncherUpdater::ContainsID(ash::LauncherID id, TabContentsWrapper** tab) { | 338 bool LauncherUpdater::ContainsID(ash::LauncherID id, TabContentsWrapper** tab) { |
| 330 if (item_id_ == id) | 339 if (item_id_ == id) |
| 331 return true; | 340 return true; |
| 332 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end(); | 341 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end(); |
| 333 ++i) { | 342 ++i) { |
| 334 if (i->second.id == id) { | 343 if (i->second.id == id) { |
| 335 *tab = i->first; | 344 *tab = i->first; |
| 336 return true; | 345 return true; |
| 337 } | 346 } |
| 338 } | 347 } |
| 339 return false; | 348 return false; |
| 340 } | 349 } |
| 341 | 350 |
| 342 ash::LauncherModel* LauncherUpdater::launcher_model() { | 351 ash::LauncherModel* LauncherUpdater::launcher_model() { |
| 343 return launcher_delegate_->model(); | 352 return launcher_delegate_->model(); |
| 344 } | 353 } |
| OLD | NEW |