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

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

Issue 2090133003: Moved methods that don't rely on internal state out of ChromeLauncherController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit changes Created 4 years, 5 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 (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/ash/launcher/app_shortcut_launcher_item_controller.h " 5 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h "
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "ash/wm/window_util.h" 9 #include "ash/wm/window_util.h"
10 #include "chrome/browser/chromeos/arc/arc_support_host.h" 10 #include "chrome/browser/chromeos/arc/arc_support_host.h"
11 #include "chrome/browser/extensions/launch_util.h" 11 #include "chrome/browser/extensions/launch_util.h"
12 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" 12 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
13 #include "chrome/browser/ui/ash/launcher/arc_playstore_shortcut_launcher_item_co ntroller.h" 13 #include "chrome/browser/ui/ash/launcher/arc_playstore_shortcut_launcher_item_co ntroller.h"
14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h"
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h"
16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h"
17 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" 18 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h"
18 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" 19 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
19 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" 20 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h"
20 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" 21 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
21 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 22 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
22 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 23 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
23 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_finder.h" 25 #include "chrome/browser/ui/browser_finder.h"
25 #include "chrome/browser/ui/browser_list.h" 26 #include "chrome/browser/ui/browser_list.h"
26 #include "chrome/browser/ui/browser_window.h" 27 #include "chrome/browser/ui/browser_window.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // but do not have any associated windows (opening a shortcut will replace the 75 // but do not have any associated windows (opening a shortcut will replace the
75 // item with the appropriate LauncherItemController type). 76 // item with the appropriate LauncherItemController type).
76 AppShortcutLauncherItemController::AppShortcutLauncherItemController( 77 AppShortcutLauncherItemController::AppShortcutLauncherItemController(
77 const std::string& app_id, 78 const std::string& app_id,
78 ChromeLauncherController* controller) 79 ChromeLauncherController* controller)
79 : LauncherItemController(TYPE_SHORTCUT, app_id, controller), 80 : LauncherItemController(TYPE_SHORTCUT, app_id, controller),
80 chrome_launcher_controller_(controller) { 81 chrome_launcher_controller_(controller) {
81 // To detect V1 applications we use their domain and match them against the 82 // To detect V1 applications we use their domain and match them against the
82 // used URL. This will also work with applications like Google Drive. 83 // used URL. This will also work with applications like Google Drive.
83 const Extension* extension = 84 const Extension* extension =
84 launcher_controller()->GetExtensionForAppID(app_id); 85 GetExtensionForAppID(app_id, controller->GetProfile());
85 // Some unit tests have no real extension. 86 // Some unit tests have no real extension.
86 if (extension) { 87 if (extension) {
87 set_refocus_url(GURL( 88 set_refocus_url(GURL(
88 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*")); 89 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*"));
89 } 90 }
90 } 91 }
91 92
92 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() { 93 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() {
93 } 94 }
94 95
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 134 }
134 return ActivateContent(content); 135 return ActivateContent(content);
135 } 136 }
136 137
137 void AppShortcutLauncherItemController::Close() { 138 void AppShortcutLauncherItemController::Close() {
138 // Close all running 'programs' of this type. 139 // Close all running 'programs' of this type.
139 std::vector<content::WebContents*> content = 140 std::vector<content::WebContents*> content =
140 launcher_controller()->GetV1ApplicationsFromAppId(app_id()); 141 launcher_controller()->GetV1ApplicationsFromAppId(app_id());
141 for (size_t i = 0; i < content.size(); i++) { 142 for (size_t i = 0; i < content.size(); i++) {
142 Browser* browser = chrome::FindBrowserWithWebContents(content[i]); 143 Browser* browser = chrome::FindBrowserWithWebContents(content[i]);
143 if (!browser || !launcher_controller()->IsBrowserFromActiveUser(browser)) 144 if (!browser || !IsBrowserFromActiveUser(browser))
144 continue; 145 continue;
145 TabStripModel* tab_strip = browser->tab_strip_model(); 146 TabStripModel* tab_strip = browser->tab_strip_model();
146 int index = tab_strip->GetIndexOfWebContents(content[i]); 147 int index = tab_strip->GetIndexOfWebContents(content[i]);
147 DCHECK(index != TabStripModel::kNoTab); 148 DCHECK(index != TabStripModel::kNoTab);
148 tab_strip->CloseWebContentsAt(index, TabStripModel::CLOSE_NONE); 149 tab_strip->CloseWebContentsAt(index, TabStripModel::CLOSE_NONE);
149 } 150 }
150 } 151 }
151 152
152 ChromeLauncherAppMenuItems 153 ChromeLauncherAppMenuItems
153 AppShortcutLauncherItemController::GetApplicationList(int event_flags) { 154 AppShortcutLauncherItemController::GetApplicationList(int event_flags) {
(...skipping 20 matching lines...) Expand all
174 175
175 URLPattern refocus_pattern(URLPattern::SCHEME_ALL); 176 URLPattern refocus_pattern(URLPattern::SCHEME_ALL);
176 refocus_pattern.SetMatchAllURLs(true); 177 refocus_pattern.SetMatchAllURLs(true);
177 178
178 if (!refocus_url_.is_empty()) { 179 if (!refocus_url_.is_empty()) {
179 refocus_pattern.SetMatchAllURLs(false); 180 refocus_pattern.SetMatchAllURLs(false);
180 refocus_pattern.Parse(refocus_url_.spec()); 181 refocus_pattern.Parse(refocus_url_.spec());
181 } 182 }
182 183
183 const Extension* extension = 184 const Extension* extension =
184 launcher_controller()->GetExtensionForAppID(app_id()); 185 GetExtensionForAppID(app_id(), launcher_controller()->GetProfile());
185 186
186 // It is possible to come here While an extension gets loaded. 187 // It is possible to come here While an extension gets loaded.
187 if (!extension) 188 if (!extension)
188 return items; 189 return items;
189 190
190 for (auto* browser : *BrowserList::GetInstance()) { 191 for (auto* browser : *BrowserList::GetInstance()) {
191 if (!launcher_controller()->IsBrowserFromActiveUser(browser)) 192 if (!IsBrowserFromActiveUser(browser))
192 continue; 193 continue;
193 TabStripModel* tab_strip = browser->tab_strip_model(); 194 TabStripModel* tab_strip = browser->tab_strip_model();
194 for (int index = 0; index < tab_strip->count(); index++) { 195 for (int index = 0; index < tab_strip->count(); index++) {
195 content::WebContents* web_contents = tab_strip->GetWebContentsAt(index); 196 content::WebContents* web_contents = tab_strip->GetWebContentsAt(index);
196 if (WebContentMatchesApp( 197 if (WebContentMatchesApp(
197 extension, refocus_pattern, web_contents, browser)) 198 extension, refocus_pattern, web_contents, browser))
198 items.push_back(web_contents); 199 items.push_back(web_contents);
199 } 200 }
200 } 201 }
201 return items; 202 return items;
(...skipping 18 matching lines...) Expand all
220 ash::ShelfMenuModel* AppShortcutLauncherItemController::CreateApplicationMenu( 221 ash::ShelfMenuModel* AppShortcutLauncherItemController::CreateApplicationMenu(
221 int event_flags) { 222 int event_flags) {
222 return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags)); 223 return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags));
223 } 224 }
224 225
225 bool AppShortcutLauncherItemController::IsDraggable() { 226 bool AppShortcutLauncherItemController::IsDraggable() {
226 return true; 227 return true;
227 } 228 }
228 229
229 bool AppShortcutLauncherItemController::CanPin() const { 230 bool AppShortcutLauncherItemController::CanPin() const {
230 return launcher_controller()->GetPinnable(app_id()) == 231 return GetPinnableForAppID(app_id(), launcher_controller()->GetProfile()) ==
231 AppListControllerDelegate::PIN_EDITABLE; 232 AppListControllerDelegate::PIN_EDITABLE;
232 } 233 }
233 234
234 bool AppShortcutLauncherItemController::ShouldShowTooltip() { 235 bool AppShortcutLauncherItemController::ShouldShowTooltip() {
235 return true; 236 return true;
236 } 237 }
237 238
238 content::WebContents* AppShortcutLauncherItemController::GetLRUApplication() { 239 content::WebContents* AppShortcutLauncherItemController::GetLRUApplication() {
239 URLPattern refocus_pattern(URLPattern::SCHEME_ALL); 240 URLPattern refocus_pattern(URLPattern::SCHEME_ALL);
240 refocus_pattern.SetMatchAllURLs(true); 241 refocus_pattern.SetMatchAllURLs(true);
241 242
242 if (!refocus_url_.is_empty()) { 243 if (!refocus_url_.is_empty()) {
243 refocus_pattern.SetMatchAllURLs(false); 244 refocus_pattern.SetMatchAllURLs(false);
244 refocus_pattern.Parse(refocus_url_.spec()); 245 refocus_pattern.Parse(refocus_url_.spec());
245 } 246 }
246 247
247 const Extension* extension = 248 const Extension* extension =
248 launcher_controller()->GetExtensionForAppID(app_id()); 249 GetExtensionForAppID(app_id(), launcher_controller()->GetProfile());
249 250
250 // We may get here while the extension is loading (and NULL). 251 // We may get here while the extension is loading (and NULL).
251 if (!extension) 252 if (!extension)
252 return NULL; 253 return NULL;
253 254
254 const BrowserList* browser_list = BrowserList::GetInstance(); 255 const BrowserList* browser_list = BrowserList::GetInstance();
255 for (BrowserList::const_reverse_iterator it = 256 for (BrowserList::const_reverse_iterator it =
256 browser_list->begin_last_active(); 257 browser_list->begin_last_active();
257 it != browser_list->end_last_active(); ++it) { 258 it != browser_list->end_last_active(); ++it) {
258 Browser* browser = *it; 259 Browser* browser = *it;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 } 362 }
362 return true; 363 return true;
363 } 364 }
364 } 365 }
365 } 366 }
366 return false; 367 return false;
367 } 368 }
368 369
369 bool AppShortcutLauncherItemController::IsV2App() { 370 bool AppShortcutLauncherItemController::IsV2App() {
370 const Extension* extension = 371 const Extension* extension =
371 launcher_controller()->GetExtensionForAppID(app_id()); 372 GetExtensionForAppID(app_id(), launcher_controller()->GetProfile());
372 return extension && extension->is_platform_app(); 373 return extension && extension->is_platform_app();
373 } 374 }
374 375
375 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { 376 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() {
376 if (last_launch_attempt_.is_null() || 377 if (last_launch_attempt_.is_null() ||
377 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( 378 last_launch_attempt_ + base::TimeDelta::FromMilliseconds(
378 kClickSuppressionInMS) < base::Time::Now()) { 379 kClickSuppressionInMS) < base::Time::Now()) {
379 last_launch_attempt_ = base::Time::Now(); 380 last_launch_attempt_ = base::Time::Now();
380 return true; 381 return true;
381 } 382 }
382 return false; 383 return false;
383 } 384 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698