| 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" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/extension_tab_helper.h" | 12 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 13 #include "chrome/browser/favicon/favicon_tab_helper.h" | 13 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 14 #include "chrome/browser/tabs/tab_strip_model.h" | 14 #include "chrome/browser/tabs/tab_strip_model.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 18 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.h" | 18 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.h" |
| 19 #include "chrome/browser/web_applications/web_app.h" | 19 #include "chrome/browser/web_applications/web_app.h" |
| 20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 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 namespace { | |
| 26 | |
| 27 ChromeLauncherDelegate::AppType GetDelegateType(LauncherUpdater::Type type) { | |
| 28 switch (type) { | |
| 29 case LauncherUpdater::TYPE_APP_PANEL: | |
| 30 return ChromeLauncherDelegate::APP_TYPE_APP_PANEL; | |
| 31 case LauncherUpdater::TYPE_EXTENSION_PANEL: | |
| 32 return ChromeLauncherDelegate::APP_TYPE_EXTENSION_PANEL; | |
| 33 case LauncherUpdater::TYPE_TABBED: | |
| 34 NOTREACHED(); | |
| 35 } | |
| 36 return ChromeLauncherDelegate::APP_TYPE_WINDOW; | |
| 37 } | |
| 38 | |
| 39 } // namespace | |
| 40 | |
| 41 LauncherUpdater::LauncherUpdater(aura::Window* window, | 25 LauncherUpdater::LauncherUpdater(aura::Window* window, |
| 42 TabStripModel* tab_model, | 26 TabStripModel* tab_model, |
| 43 ChromeLauncherDelegate* delegate, | 27 ChromeLauncherDelegate* delegate, |
| 44 Type type, | 28 Type type, |
| 45 const std::string& app_id) | 29 const std::string& app_id) |
| 46 : window_(window), | 30 : window_(window), |
| 47 tab_model_(tab_model), | 31 tab_model_(tab_model), |
| 48 launcher_delegate_(delegate), | 32 launcher_delegate_(delegate), |
| 49 type_(type), | 33 type_(type), |
| 50 app_id_(app_id), | 34 app_id_(app_id), |
| 51 is_incognito_(tab_model->profile()->GetOriginalProfile() != | 35 is_incognito_(tab_model->profile()->GetOriginalProfile() != |
| 52 tab_model->profile()), | 36 tab_model->profile()), |
| 53 item_id_(-1) { | 37 item_id_(-1) { |
| 54 } | 38 } |
| 55 | 39 |
| 56 LauncherUpdater::~LauncherUpdater() { | 40 LauncherUpdater::~LauncherUpdater() { |
| 57 tab_model_->RemoveObserver(this); | 41 tab_model_->RemoveObserver(this); |
| 58 if (item_id_ != -1) | 42 if (item_id_ != -1) |
| 59 launcher_delegate_->LauncherItemClosed(item_id_); | 43 launcher_delegate_->LauncherItemClosed(item_id_); |
| 60 } | 44 } |
| 61 | 45 |
| 62 void LauncherUpdater::Init() { | 46 void LauncherUpdater::Init() { |
| 63 tab_model_->AddObserver(this); | 47 tab_model_->AddObserver(this); |
| 64 ash::LauncherItemStatus app_status = | 48 ash::LauncherItemStatus app_status = |
| 65 ash::wm::IsActiveWindow(window_) ? | 49 ash::wm::IsActiveWindow(window_) ? |
| 66 ash::STATUS_ACTIVE : ash::STATUS_RUNNING; | 50 ash::STATUS_ACTIVE : ash::STATUS_RUNNING; |
| 67 if (type_ != TYPE_TABBED) { | 51 if (type_ != TYPE_TABBED) { |
| 68 ChromeLauncherDelegate::AppType app_type = GetDelegateType(type_); | |
| 69 item_id_ = launcher_delegate_->CreateAppLauncherItem( | 52 item_id_ = launcher_delegate_->CreateAppLauncherItem( |
| 70 this, app_id_, app_type, app_status); | 53 this, app_id_, app_status); |
| 71 } else { | 54 } else { |
| 72 item_id_ = launcher_delegate_->CreateTabbedLauncherItem( | 55 item_id_ = launcher_delegate_->CreateTabbedLauncherItem( |
| 73 this, | 56 this, |
| 74 is_incognito_ ? ChromeLauncherDelegate::STATE_INCOGNITO : | 57 is_incognito_ ? ChromeLauncherDelegate::STATE_INCOGNITO : |
| 75 ChromeLauncherDelegate::STATE_NOT_INCOGNITO, | 58 ChromeLauncherDelegate::STATE_NOT_INCOGNITO, |
| 76 app_status); | 59 app_status); |
| 77 } | 60 } |
| 78 // In testing scenarios we can get tab strips with no active contents. | 61 // In testing scenarios we can get tab strips with no active contents. |
| 79 if (tab_model_->GetActiveTabContents()) | 62 if (tab_model_->GetActiveTabContents()) |
| 80 UpdateLauncher(tab_model_->GetActiveTabContents()); | 63 UpdateLauncher(tab_model_->GetActiveTabContents()); |
| 81 } | 64 } |
| 82 | 65 |
| 83 // static | 66 // static |
| 84 LauncherUpdater* LauncherUpdater::Create(Browser* browser) { | 67 LauncherUpdater* LauncherUpdater::Create(Browser* browser) { |
| 85 Type type; | 68 Type type; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 } else { | 172 } else { |
| 190 item.image = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); | 173 item.image = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); |
| 191 } | 174 } |
| 192 } | 175 } |
| 193 launcher_model()->Set(item_index, item); | 176 launcher_model()->Set(item_index, item); |
| 194 } | 177 } |
| 195 | 178 |
| 196 ash::LauncherModel* LauncherUpdater::launcher_model() { | 179 ash::LauncherModel* LauncherUpdater::launcher_model() { |
| 197 return launcher_delegate_->model(); | 180 return launcher_delegate_->model(); |
| 198 } | 181 } |
| OLD | NEW |