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 20 matching lines...) Expand all Loading... | |
31 LauncherUpdater::LauncherUpdater(aura::Window* window, | 31 LauncherUpdater::LauncherUpdater(aura::Window* window, |
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 is_incognito_(false), | |
41 item_id_(-1) { | 42 item_id_(-1) { |
43 if (tab_model_->count() > 0) { | |
sky
2012/03/10 00:13:11
Use the profile from the TabStripModel, that way y
Zachary Kuznia
2012/03/10 00:28:36
Done.
| |
44 TabContentsWrapper* tab = tab_model_->GetTabContentsAt(0); | |
45 is_incognito_ = (tab->profile()->GetOriginalProfile() != tab->profile()); | |
46 } | |
42 } | 47 } |
43 | 48 |
44 LauncherUpdater::~LauncherUpdater() { | 49 LauncherUpdater::~LauncherUpdater() { |
45 tab_model_->RemoveObserver(this); | 50 tab_model_->RemoveObserver(this); |
46 if (item_id_ != -1) | 51 if (item_id_ != -1) |
47 launcher_delegate_->LauncherItemClosed(item_id_); | 52 launcher_delegate_->LauncherItemClosed(item_id_); |
48 for (AppTabMap::iterator i = app_map_.begin(); i != app_map_.end(); ++i) | 53 for (AppTabMap::iterator i = app_map_.begin(); i != app_map_.end(); ++i) |
49 launcher_delegate_->LauncherItemClosed(i->second.id); | 54 launcher_delegate_->LauncherItemClosed(i->second.id); |
50 } | 55 } |
51 | 56 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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(); |
274 } | 279 } |
275 ash::LauncherItem item(ash::TYPE_TABBED); | 280 ash::LauncherItem item; |
281 item.type = ash::TYPE_TABBED; | |
282 item.is_incognito = is_incognito_; | |
276 item.num_tabs = tab_model_->count(); | 283 item.num_tabs = tab_model_->count(); |
277 launcher_model()->Set(launcher_model()->ItemIndexByID(item_id_), item); | 284 launcher_model()->Set(launcher_model()->ItemIndexByID(item_id_), item); |
278 } else { | 285 } else { |
279 // We have a tabbed item, so we can remove the the app item. | 286 // We have a tabbed item, so we can remove the the app item. |
280 launcher_delegate_->LauncherItemClosed(launcher_id); | 287 launcher_delegate_->LauncherItemClosed(launcher_id); |
281 } | 288 } |
282 } else { | 289 } else { |
283 // Going from not showing to showing. | 290 // Going from not showing to showing. |
284 if (item_id_ != -1 && | 291 if (item_id_ != -1 && |
285 static_cast<int>(app_map_.size()) + 1 == tab_model_->count()) { | 292 static_cast<int>(app_map_.size()) + 1 == tab_model_->count()) { |
(...skipping 30 matching lines...) Expand all Loading... | |
316 void LauncherUpdater::RegisterAppItem(ash::LauncherID id, | 323 void LauncherUpdater::RegisterAppItem(ash::LauncherID id, |
317 TabContentsWrapper* tab) { | 324 TabContentsWrapper* tab) { |
318 AppTabDetails details; | 325 AppTabDetails details; |
319 details.id = id; | 326 details.id = id; |
320 details.app_id = launcher_delegate_->GetAppID(tab); | 327 details.app_id = launcher_delegate_->GetAppID(tab); |
321 app_map_[tab] = details; | 328 app_map_[tab] = details; |
322 } | 329 } |
323 | 330 |
324 void LauncherUpdater::CreateTabbedItem() { | 331 void LauncherUpdater::CreateTabbedItem() { |
325 DCHECK_EQ(-1, item_id_); | 332 DCHECK_EQ(-1, item_id_); |
326 item_id_ = launcher_delegate_->CreateTabbedLauncherItem(this); | 333 item_id_ = launcher_delegate_->CreateTabbedLauncherItem( |
334 this, | |
335 is_incognito_ ? ChromeLauncherDelegate::STATE_INCOGNITO : | |
336 ChromeLauncherDelegate::STATE_NOT_INCOGNITO); | |
327 } | 337 } |
328 | 338 |
329 bool LauncherUpdater::ContainsID(ash::LauncherID id, TabContentsWrapper** tab) { | 339 bool LauncherUpdater::ContainsID(ash::LauncherID id, TabContentsWrapper** tab) { |
330 if (item_id_ == id) | 340 if (item_id_ == id) |
331 return true; | 341 return true; |
332 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end(); | 342 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end(); |
333 ++i) { | 343 ++i) { |
334 if (i->second.id == id) { | 344 if (i->second.id == id) { |
335 *tab = i->first; | 345 *tab = i->first; |
336 return true; | 346 return true; |
337 } | 347 } |
338 } | 348 } |
339 return false; | 349 return false; |
340 } | 350 } |
341 | 351 |
342 ash::LauncherModel* LauncherUpdater::launcher_model() { | 352 ash::LauncherModel* LauncherUpdater::launcher_model() { |
343 return launcher_delegate_->model(); | 353 return launcher_delegate_->model(); |
344 } | 354 } |
OLD | NEW |