Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.cc

Issue 1951523002: Add basic support for launching mash shelf pinned apps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only LaunchItem with no windows; otherwise kNoAction (for CreateApplicationMenu). Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_mash_shelf_controller.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.h"
6 6
7 #include "chrome/browser/extensions/extension_app_icon_loader.h" 7 #include "chrome/browser/extensions/extension_app_icon_loader.h"
8 #include "chrome/browser/profiles/profile_manager.h" 8 #include "chrome/browser/profiles/profile_manager.h"
9 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" 9 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
10 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" 10 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h"
11 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" 11 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
12 #include "chrome/grit/theme_resources.h" 12 #include "chrome/grit/theme_resources.h"
13 #include "content/public/common/mojo_shell_connection.h" 13 #include "content/public/common/mojo_shell_connection.h"
14 #include "extensions/common/constants.h" 14 #include "extensions/common/constants.h"
15 #include "extensions/grit/extensions_browser_resources.h" 15 #include "extensions/grit/extensions_browser_resources.h"
16 #include "mojo/common/common_type_converters.h" 16 #include "mojo/common/common_type_converters.h"
17 #include "services/shell/public/cpp/connector.h" 17 #include "services/shell/public/cpp/connector.h"
18 #include "skia/public/type_converters.h" 18 #include "skia/public/type_converters.h"
19 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/display/screen.h" 20 #include "ui/display/screen.h"
21 21
22 #if defined(OS_CHROMEOS) 22 #if defined(OS_CHROMEOS)
23 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" 23 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h"
24 #endif 24 #endif
25 25
26 class ChromeShelfItemDelegate : public mash::shelf::mojom::ShelfItemDelegate { 26 class ChromeShelfItemDelegate : public mash::shelf::mojom::ShelfItemDelegate {
27 public: 27 public:
28 ChromeShelfItemDelegate() : item_delegate_binding_(this) {} 28 explicit ChromeShelfItemDelegate(const std::string& app_id)
29 : app_id_(app_id), item_delegate_binding_(this) {}
29 ~ChromeShelfItemDelegate() override {} 30 ~ChromeShelfItemDelegate() override {}
30 31
31 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo 32 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo
32 CreateInterfacePtrInfoAndBind(mojo::AssociatedGroup* associated_group) { 33 CreateInterfacePtrInfoAndBind(mojo::AssociatedGroup* associated_group) {
33 DCHECK(!item_delegate_binding_.is_bound()); 34 DCHECK(!item_delegate_binding_.is_bound());
34 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo ptr_info; 35 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo ptr_info;
35 item_delegate_binding_.Bind(&ptr_info, associated_group); 36 item_delegate_binding_.Bind(&ptr_info, associated_group);
36 return ptr_info; 37 return ptr_info;
37 } 38 }
38 39
39 private: 40 private:
40 // mash::shelf::mojom::ShelfItemDelegate: 41 // mash::shelf::mojom::ShelfItemDelegate:
42 void LaunchItem() override {
43 ChromeMashShelfController::instance()->LaunchItem(app_id_);
44 }
41 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override { 45 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override {
42 NOTIMPLEMENTED(); 46 NOTIMPLEMENTED();
43 } 47 }
44 void ItemPinned() override { NOTIMPLEMENTED(); } 48 void ItemPinned() override { NOTIMPLEMENTED(); }
45 void ItemUnpinned() override { NOTIMPLEMENTED(); } 49 void ItemUnpinned() override { NOTIMPLEMENTED(); }
46 void ItemReordered(uint32_t order) override { NOTIMPLEMENTED(); } 50 void ItemReordered(uint32_t order) override { NOTIMPLEMENTED(); }
47 51
52 std::string app_id_;
48 mojo::AssociatedBinding<mash::shelf::mojom::ShelfItemDelegate> 53 mojo::AssociatedBinding<mash::shelf::mojom::ShelfItemDelegate>
49 item_delegate_binding_; 54 item_delegate_binding_;
50 55
51 DISALLOW_COPY_AND_ASSIGN(ChromeShelfItemDelegate); 56 DISALLOW_COPY_AND_ASSIGN(ChromeShelfItemDelegate);
52 }; 57 };
53 58
54 // static 59 // static
55 ChromeMashShelfController* ChromeMashShelfController::instance_ = nullptr; 60 ChromeMashShelfController* ChromeMashShelfController::instance_ = nullptr;
56 61
57 ChromeMashShelfController::~ChromeMashShelfController() {} 62 ChromeMashShelfController::~ChromeMashShelfController() {}
58 63
59 // static 64 // static
60 ChromeMashShelfController* ChromeMashShelfController::CreateInstance() { 65 ChromeMashShelfController* ChromeMashShelfController::CreateInstance() {
61 DCHECK(!instance_); 66 DCHECK(!instance_);
62 instance_ = new ChromeMashShelfController(); 67 instance_ = new ChromeMashShelfController();
63 instance_->Init(); 68 instance_->Init();
64 return instance_; 69 return instance_;
65 } 70 }
66 71
72 void ChromeMashShelfController::LaunchItem(const std::string& app_id) {
73 helper_.LaunchApp(app_id, ash::LAUNCH_FROM_UNKNOWN, ui::EF_NONE);
74 }
75
67 ChromeMashShelfController::ChromeMashShelfController() 76 ChromeMashShelfController::ChromeMashShelfController()
68 : observer_binding_(this) {} 77 : helper_(ProfileManager::GetActiveUserProfile()),
78 observer_binding_(this) {}
69 79
70 void ChromeMashShelfController::Init() { 80 void ChromeMashShelfController::Init() {
71 shell::Connector* connector = 81 shell::Connector* connector =
72 content::MojoShellConnection::Get()->GetConnector(); 82 content::MojoShellConnection::Get()->GetConnector();
73 connector->ConnectToInterface("mojo:ash_sysui", &shelf_controller_); 83 connector->ConnectToInterface("mojo:ash_sysui", &shelf_controller_);
74 84
75 // Set shelf alignment and auto-hide behavior from preferences. 85 // Set shelf alignment and auto-hide behavior from preferences.
76 Profile* profile = ProfileManager::GetActiveUserProfile(); 86 Profile* profile = ProfileManager::GetActiveUserProfile();
77 int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 87 int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
78 shelf_controller_->SetAlignment(static_cast<mash::shelf::mojom::Alignment>( 88 shelf_controller_->SetAlignment(static_cast<mash::shelf::mojom::Alignment>(
(...skipping 21 matching lines...) Expand all
100 PinAppsFromPrefs(); 110 PinAppsFromPrefs();
101 111
102 // Start observing the shelf now that it has been initialized. 112 // Start observing the shelf now that it has been initialized.
103 mash::shelf::mojom::ShelfObserverAssociatedPtrInfo ptr_info; 113 mash::shelf::mojom::ShelfObserverAssociatedPtrInfo ptr_info;
104 observer_binding_.Bind(&ptr_info, shelf_controller_.associated_group()); 114 observer_binding_.Bind(&ptr_info, shelf_controller_.associated_group());
105 shelf_controller_->AddObserver(std::move(ptr_info)); 115 shelf_controller_->AddObserver(std::move(ptr_info));
106 } 116 }
107 117
108 void ChromeMashShelfController::PinAppsFromPrefs() { 118 void ChromeMashShelfController::PinAppsFromPrefs() {
109 Profile* profile = ProfileManager::GetActiveUserProfile(); 119 Profile* profile = ProfileManager::GetActiveUserProfile();
110 LauncherControllerHelper helper(profile);
111 std::vector<std::string> pinned_apps = 120 std::vector<std::string> pinned_apps =
112 ash::GetPinnedAppsFromPrefs(profile->GetPrefs(), &helper); 121 ash::GetPinnedAppsFromPrefs(profile->GetPrefs(), &helper_);
113 122
114 for (const auto& app : pinned_apps) { 123 for (const auto& app : pinned_apps) {
115 if (app == ash::kPinnedAppsPlaceholder) 124 if (app == ash::kPinnedAppsPlaceholder)
116 continue; 125 continue;
117 126
118 mash::shelf::mojom::ShelfItemPtr item(mash::shelf::mojom::ShelfItem::New()); 127 mash::shelf::mojom::ShelfItemPtr item(mash::shelf::mojom::ShelfItem::New());
119 item->app_id = app; 128 item->app_id = app;
120 item->app_title = mojo::String::From(helper.GetAppTitle(profile, app)); 129 item->app_title = mojo::String::From(helper_.GetAppTitle(profile, app));
121 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 130 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
122 const gfx::Image& image = rb.GetImageNamed(IDR_APP_DEFAULT_ICON); 131 const gfx::Image& image = rb.GetImageNamed(IDR_APP_DEFAULT_ICON);
123 item->image = skia::mojom::Bitmap::From(*image.ToSkBitmap()); 132 item->image = skia::mojom::Bitmap::From(*image.ToSkBitmap());
124 std::unique_ptr<ChromeShelfItemDelegate> delegate( 133 std::unique_ptr<ChromeShelfItemDelegate> delegate(
125 new ChromeShelfItemDelegate()); 134 new ChromeShelfItemDelegate(app));
126 shelf_controller_->PinItem(std::move(item), 135 shelf_controller_->PinItem(std::move(item),
127 delegate->CreateInterfacePtrInfoAndBind( 136 delegate->CreateInterfacePtrInfoAndBind(
128 shelf_controller_.associated_group())); 137 shelf_controller_.associated_group()));
129 app_id_to_item_delegate_.insert(std::make_pair(app, std::move(delegate))); 138 app_id_to_item_delegate_.insert(std::make_pair(app, std::move(delegate)));
130 139
131 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app); 140 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app);
132 if (app_icon_loader) { 141 if (app_icon_loader) {
133 app_icon_loader->FetchImage(app); 142 app_icon_loader->FetchImage(app);
134 app_icon_loader->UpdateImage(app); 143 app_icon_loader->UpdateImage(app);
135 } 144 }
(...skipping 24 matching lines...) Expand all
160 ProfileManager::GetActiveUserProfile()->GetPrefs(), 169 ProfileManager::GetActiveUserProfile()->GetPrefs(),
161 display::Screen::GetScreen()->GetPrimaryDisplay().id(), 170 display::Screen::GetScreen()->GetPrimaryDisplay().id(),
162 static_cast<ash::ShelfAutoHideBehavior>(auto_hide)); 171 static_cast<ash::ShelfAutoHideBehavior>(auto_hide));
163 } 172 }
164 173
165 void ChromeMashShelfController::OnAppImageUpdated(const std::string& app_id, 174 void ChromeMashShelfController::OnAppImageUpdated(const std::string& app_id,
166 const gfx::ImageSkia& image) { 175 const gfx::ImageSkia& image) {
167 shelf_controller_->SetItemImage(app_id, 176 shelf_controller_->SetItemImage(app_id,
168 skia::mojom::Bitmap::From(*image.bitmap())); 177 skia::mojom::Bitmap::From(*image.bitmap()));
169 } 178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698