OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/chrome_launcher_controller_mus.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_mus.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile_manager.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.h" | 8 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
| 9 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" |
| 10 #include "extensions/grit/extensions_browser_resources.h" |
| 11 #include "mojo/common/common_type_converters.h" |
| 12 #include "ui/base/resource/resource_bundle.h" |
| 13 |
| 14 class ChromeShelfItemDelegate : public ash::mojom::ShelfItemDelegate { |
| 15 public: |
| 16 explicit ChromeShelfItemDelegate(const std::string& app_id, |
| 17 ChromeLauncherController* controller) |
| 18 : app_id_(app_id), |
| 19 item_delegate_binding_(this), |
| 20 controller_(controller) {} |
| 21 ~ChromeShelfItemDelegate() override {} |
| 22 |
| 23 ash::mojom::ShelfItemDelegateAssociatedPtrInfo CreateInterfacePtrInfoAndBind( |
| 24 mojo::AssociatedGroup* associated_group) { |
| 25 DCHECK(!item_delegate_binding_.is_bound()); |
| 26 ash::mojom::ShelfItemDelegateAssociatedPtrInfo ptr_info; |
| 27 item_delegate_binding_.Bind(&ptr_info, associated_group); |
| 28 return ptr_info; |
| 29 } |
| 30 |
| 31 private: |
| 32 // ash::mojom::ShelfItemDelegate: |
| 33 void LaunchItem() override { |
| 34 controller_->LaunchApp(app_id_, ash::LAUNCH_FROM_UNKNOWN, ui::EF_NONE); |
| 35 } |
| 36 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override { |
| 37 NOTIMPLEMENTED(); |
| 38 } |
| 39 void ItemPinned() override { NOTIMPLEMENTED(); } |
| 40 void ItemUnpinned() override { NOTIMPLEMENTED(); } |
| 41 void ItemReordered(uint32_t order) override { NOTIMPLEMENTED(); } |
| 42 |
| 43 std::string app_id_; |
| 44 mojo::AssociatedBinding<ash::mojom::ShelfItemDelegate> item_delegate_binding_; |
| 45 |
| 46 // Not owned. |
| 47 ChromeLauncherController* controller_; |
| 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(ChromeShelfItemDelegate); |
| 50 }; |
9 | 51 |
10 // static | 52 // static |
11 ChromeLauncherController* ChromeLauncherControllerMus::CreateInstance() { | 53 ChromeLauncherController* ChromeLauncherControllerMus::CreateInstance() { |
12 DCHECK(!ChromeLauncherController::instance()); | 54 DCHECK(!ChromeLauncherController::instance()); |
13 ChromeLauncherControllerMus* instance = new ChromeLauncherControllerMus(); | 55 ChromeLauncherControllerMus* instance = new ChromeLauncherControllerMus(); |
14 ChromeLauncherController::set_instance(instance); | 56 ChromeLauncherController::set_instance(instance); |
15 return instance; | 57 return instance; |
16 } | 58 } |
17 | 59 |
18 ChromeLauncherControllerMus::ChromeLauncherControllerMus() | |
19 : shelf_controller_(new ChromeMashShelfController) {} | |
20 | |
21 ChromeLauncherControllerMus::~ChromeLauncherControllerMus() {} | 60 ChromeLauncherControllerMus::~ChromeLauncherControllerMus() {} |
22 | 61 |
23 void ChromeLauncherControllerMus::Init() {} | 62 void ChromeLauncherControllerMus::Init() {} |
24 | 63 |
25 ash::ShelfID ChromeLauncherControllerMus::CreateAppLauncherItem( | 64 ash::ShelfID ChromeLauncherControllerMus::CreateAppLauncherItem( |
26 LauncherItemController* controller, | 65 LauncherItemController* controller, |
27 const std::string& app_id, | 66 const std::string& app_id, |
28 ash::ShelfItemStatus status) { | 67 ash::ShelfItemStatus status) { |
29 NOTIMPLEMENTED(); | 68 NOTIMPLEMENTED(); |
30 return ash::TYPE_UNDEFINED; | 69 return ash::TYPE_UNDEFINED; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 bool ChromeLauncherControllerMus::IsOpen(ash::ShelfID id) { | 125 bool ChromeLauncherControllerMus::IsOpen(ash::ShelfID id) { |
87 NOTIMPLEMENTED(); | 126 NOTIMPLEMENTED(); |
88 return false; | 127 return false; |
89 } | 128 } |
90 | 129 |
91 bool ChromeLauncherControllerMus::IsPlatformApp(ash::ShelfID id) { | 130 bool ChromeLauncherControllerMus::IsPlatformApp(ash::ShelfID id) { |
92 NOTIMPLEMENTED(); | 131 NOTIMPLEMENTED(); |
93 return false; | 132 return false; |
94 } | 133 } |
95 | 134 |
96 void ChromeLauncherControllerMus::LaunchApp(const std::string& app_id, | |
97 ash::LaunchSource source, | |
98 int event_flags) { | |
99 shelf_controller_->LaunchItem(app_id); | |
100 } | |
101 | |
102 void ChromeLauncherControllerMus::ActivateApp(const std::string& app_id, | 135 void ChromeLauncherControllerMus::ActivateApp(const std::string& app_id, |
103 ash::LaunchSource source, | 136 ash::LaunchSource source, |
104 int event_flags) { | 137 int event_flags) { |
105 NOTIMPLEMENTED(); | 138 NOTIMPLEMENTED(); |
106 } | 139 } |
107 | 140 |
108 extensions::LaunchType ChromeLauncherControllerMus::GetLaunchType( | 141 extensions::LaunchType ChromeLauncherControllerMus::GetLaunchType( |
109 ash::ShelfID id) { | 142 ash::ShelfID id) { |
110 NOTIMPLEMENTED(); | 143 NOTIMPLEMENTED(); |
111 return extensions::LAUNCH_TYPE_INVALID; | 144 return extensions::LAUNCH_TYPE_INVALID; |
(...skipping 10 matching lines...) Expand all Loading... |
122 NOTIMPLEMENTED(); | 155 NOTIMPLEMENTED(); |
123 return false; | 156 return false; |
124 } | 157 } |
125 | 158 |
126 void ChromeLauncherControllerMus::SetLaunchType( | 159 void ChromeLauncherControllerMus::SetLaunchType( |
127 ash::ShelfID id, | 160 ash::ShelfID id, |
128 extensions::LaunchType launch_type) { | 161 extensions::LaunchType launch_type) { |
129 NOTIMPLEMENTED(); | 162 NOTIMPLEMENTED(); |
130 } | 163 } |
131 | 164 |
132 Profile* ChromeLauncherControllerMus::GetProfile() { | |
133 return ProfileManager::GetActiveUserProfile(); | |
134 } | |
135 | |
136 void ChromeLauncherControllerMus::UpdateAppState(content::WebContents* contents, | 165 void ChromeLauncherControllerMus::UpdateAppState(content::WebContents* contents, |
137 AppState app_state) { | 166 AppState app_state) { |
138 NOTIMPLEMENTED(); | 167 NOTIMPLEMENTED(); |
139 } | 168 } |
140 | 169 |
141 ash::ShelfID ChromeLauncherControllerMus::GetShelfIDForWebContents( | 170 ash::ShelfID ChromeLauncherControllerMus::GetShelfIDForWebContents( |
142 content::WebContents* contents) { | 171 content::WebContents* contents) { |
143 NOTIMPLEMENTED(); | 172 NOTIMPLEMENTED(); |
144 return ash::TYPE_UNDEFINED; | 173 return ash::TYPE_UNDEFINED; |
145 } | 174 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 261 |
233 void ChromeLauncherControllerMus::OnUserProfileReadyToSwitch(Profile* profile) { | 262 void ChromeLauncherControllerMus::OnUserProfileReadyToSwitch(Profile* profile) { |
234 NOTIMPLEMENTED(); | 263 NOTIMPLEMENTED(); |
235 } | 264 } |
236 | 265 |
237 ArcAppDeferredLauncherController* | 266 ArcAppDeferredLauncherController* |
238 ChromeLauncherControllerMus::GetArcDeferredLauncher() { | 267 ChromeLauncherControllerMus::GetArcDeferredLauncher() { |
239 NOTIMPLEMENTED(); | 268 NOTIMPLEMENTED(); |
240 return nullptr; | 269 return nullptr; |
241 } | 270 } |
| 271 |
| 272 void ChromeLauncherControllerMus::OnAppImageUpdated( |
| 273 const std::string& app_id, |
| 274 const gfx::ImageSkia& image) { |
| 275 if (ConnectToShelfController()) |
| 276 shelf_controller()->SetItemImage(app_id, *image.bitmap()); |
| 277 } |
| 278 |
| 279 ChromeLauncherControllerMus::ChromeLauncherControllerMus() {} |
| 280 |
| 281 void ChromeLauncherControllerMus::PinAppsFromPrefs() { |
| 282 if (!ConnectToShelfController()) |
| 283 return; |
| 284 |
| 285 std::vector<std::string> pinned_apps = ash::launcher::GetPinnedAppsFromPrefs( |
| 286 profile()->GetPrefs(), launcher_controller_helper()); |
| 287 |
| 288 for (const auto& app : pinned_apps) { |
| 289 if (app == ash::launcher::kPinnedAppsPlaceholder) |
| 290 continue; |
| 291 |
| 292 ash::mojom::ShelfItemPtr item(ash::mojom::ShelfItem::New()); |
| 293 item->app_id = app; |
| 294 item->app_title = mojo::String::From( |
| 295 launcher_controller_helper()->GetAppTitle(profile(), app)); |
| 296 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 297 const gfx::Image& image = rb.GetImageNamed(IDR_APP_DEFAULT_ICON); |
| 298 item->image = *image.ToSkBitmap(); |
| 299 std::unique_ptr<ChromeShelfItemDelegate> delegate( |
| 300 new ChromeShelfItemDelegate(app, this)); |
| 301 shelf_controller()->PinItem(std::move(item), |
| 302 delegate->CreateInterfacePtrInfoAndBind( |
| 303 shelf_controller().associated_group())); |
| 304 app_id_to_item_delegate_.insert(std::make_pair(app, std::move(delegate))); |
| 305 |
| 306 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app); |
| 307 if (app_icon_loader) { |
| 308 app_icon_loader->FetchImage(app); |
| 309 app_icon_loader->UpdateImage(app); |
| 310 } |
| 311 } |
| 312 } |
OLD | NEW |