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

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

Issue 23068021: Remove PerBrowser launcher, reland step 1 of 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
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/chrome_launcher_controller_per_app.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/launcher/launcher.h" 10 #include "ash/launcher/launcher.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #include "chrome/browser/ui/extensions/extension_enable_flow.h" 54 #include "chrome/browser/ui/extensions/extension_enable_flow.h"
55 #include "chrome/browser/ui/host_desktop.h" 55 #include "chrome/browser/ui/host_desktop.h"
56 #include "chrome/browser/ui/tabs/tab_strip_model.h" 56 #include "chrome/browser/ui/tabs/tab_strip_model.h"
57 #include "chrome/browser/web_applications/web_app.h" 57 #include "chrome/browser/web_applications/web_app.h"
58 #include "chrome/common/chrome_switches.h" 58 #include "chrome/common/chrome_switches.h"
59 #include "chrome/common/extensions/extension.h" 59 #include "chrome/common/extensions/extension.h"
60 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" 60 #include "chrome/common/extensions/manifest_handlers/icons_handler.h"
61 #include "chrome/common/pref_names.h" 61 #include "chrome/common/pref_names.h"
62 #include "chrome/common/url_constants.h" 62 #include "chrome/common/url_constants.h"
63 #include "content/public/browser/navigation_entry.h" 63 #include "content/public/browser/navigation_entry.h"
64 #include "content/public/browser/notification_registrar.h"
64 #include "content/public/browser/notification_service.h" 65 #include "content/public/browser/notification_service.h"
65 #include "content/public/browser/web_contents.h" 66 #include "content/public/browser/web_contents.h"
66 #include "extensions/common/extension_resource.h" 67 #include "extensions/common/extension_resource.h"
67 #include "extensions/common/url_pattern.h" 68 #include "extensions/common/url_pattern.h"
68 #include "grit/ash_resources.h" 69 #include "grit/ash_resources.h"
69 #include "grit/chromium_strings.h" 70 #include "grit/chromium_strings.h"
70 #include "grit/generated_resources.h" 71 #include "grit/generated_resources.h"
71 #include "grit/theme_resources.h" 72 #include "grit/theme_resources.h"
72 #include "grit/ui_resources.h" 73 #include "grit/ui_resources.h"
73 #include "ui/aura/root_window.h" 74 #include "ui/aura/root_window.h"
74 #include "ui/aura/window.h" 75 #include "ui/aura/window.h"
75 #include "ui/base/l10n/l10n_util.h" 76 #include "ui/base/l10n/l10n_util.h"
76 #include "ui/views/corewm/window_animations.h" 77 #include "ui/views/corewm/window_animations.h"
77 78
78 #if defined(OS_CHROMEOS) 79 #if defined(OS_CHROMEOS)
79 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" 80 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h"
80 #endif 81 #endif
81 82
82 using extensions::Extension; 83 using extensions::Extension;
83 using extension_misc::kGmailAppId; 84 using extension_misc::kGmailAppId;
84 using content::WebContents; 85 using content::WebContents;
85 86
87 // static
88 ChromeLauncherController* ChromeLauncherController::instance_ = NULL;
89
86 namespace { 90 namespace {
87 91
88 std::string GetPrefKeyForRootWindow(aura::RootWindow* root_window) { 92 std::string GetPrefKeyForRootWindow(aura::RootWindow* root_window) {
89 gfx::Display display = gfx::Screen::GetScreenFor( 93 gfx::Display display = gfx::Screen::GetScreenFor(
90 root_window)->GetDisplayNearestWindow(root_window); 94 root_window)->GetDisplayNearestWindow(root_window);
91 DCHECK(display.is_valid()); 95 DCHECK(display.is_valid());
92 96
93 return base::Int64ToString(display.id()); 97 return base::Int64ToString(display.id());
94 } 98 }
95 99
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 if (!pref_service->FindPreference(local_path)->HasUserSetting() && 183 if (!pref_service->FindPreference(local_path)->HasUserSetting() &&
180 pref_service->IsSyncing()) { 184 pref_service->IsSyncing()) {
181 // First time the user is using this machine, propagate from remote to 185 // First time the user is using this machine, propagate from remote to
182 // local. 186 // local.
183 pref_service->SetString(local_path, pref_service->GetString(synced_path)); 187 pref_service->SetString(local_path, pref_service->GetString(synced_path));
184 } 188 }
185 } 189 }
186 190
187 } // namespace 191 } // namespace
188 192
189 ChromeLauncherControllerPerApp::ChromeLauncherControllerPerApp( 193 ChromeLauncherController::ChromeLauncherController(
190 Profile* profile, 194 Profile* profile,
191 ash::LauncherModel* model) 195 ash::LauncherModel* model)
192 : model_(model), 196 : model_(model),
193 profile_(profile), 197 profile_(profile),
194 app_sync_ui_state_(NULL), 198 app_sync_ui_state_(NULL),
195 ignore_persist_pinned_state_change_(false) { 199 ignore_persist_pinned_state_change_(false) {
196 if (!profile_) { 200 if (!profile_) {
197 // Use the original profile as on chromeos we may get a temporary off the 201 // Use the original profile as on chromeos we may get a temporary off the
198 // record profile. 202 // record profile.
199 profile_ = ProfileManager::GetDefaultProfile()->GetOriginalProfile(); 203 profile_ = ProfileManager::GetDefaultProfile()->GetOriginalProfile();
(...skipping 17 matching lines...) Expand all
217 221
218 notification_registrar_.Add(this, 222 notification_registrar_.Add(this,
219 chrome::NOTIFICATION_EXTENSION_LOADED, 223 chrome::NOTIFICATION_EXTENSION_LOADED,
220 content::Source<Profile>(profile_)); 224 content::Source<Profile>(profile_));
221 notification_registrar_.Add(this, 225 notification_registrar_.Add(this,
222 chrome::NOTIFICATION_EXTENSION_UNLOADED, 226 chrome::NOTIFICATION_EXTENSION_UNLOADED,
223 content::Source<Profile>(profile_)); 227 content::Source<Profile>(profile_));
224 pref_change_registrar_.Init(profile_->GetPrefs()); 228 pref_change_registrar_.Init(profile_->GetPrefs());
225 pref_change_registrar_.Add( 229 pref_change_registrar_.Add(
226 prefs::kPinnedLauncherApps, 230 prefs::kPinnedLauncherApps,
227 base::Bind(&ChromeLauncherControllerPerApp::UpdateAppLaunchersFromPref, 231 base::Bind(&ChromeLauncherController::UpdateAppLaunchersFromPref,
228 base::Unretained(this))); 232 base::Unretained(this)));
229 pref_change_registrar_.Add( 233 pref_change_registrar_.Add(
230 prefs::kShelfAlignmentLocal, 234 prefs::kShelfAlignmentLocal,
231 base::Bind(&ChromeLauncherControllerPerApp::SetShelfAlignmentFromPrefs, 235 base::Bind(&ChromeLauncherController::SetShelfAlignmentFromPrefs,
232 base::Unretained(this))); 236 base::Unretained(this)));
233 pref_change_registrar_.Add( 237 pref_change_registrar_.Add(
234 prefs::kShelfAutoHideBehaviorLocal, 238 prefs::kShelfAutoHideBehaviorLocal,
235 base::Bind(&ChromeLauncherControllerPerApp:: 239 base::Bind(&ChromeLauncherController::
236 SetShelfAutoHideBehaviorFromPrefs, 240 SetShelfAutoHideBehaviorFromPrefs,
237 base::Unretained(this))); 241 base::Unretained(this)));
238 pref_change_registrar_.Add( 242 pref_change_registrar_.Add(
239 prefs::kShelfPreferences, 243 prefs::kShelfPreferences,
240 base::Bind(&ChromeLauncherControllerPerApp::SetShelfBehaviorsFromPrefs, 244 base::Bind(&ChromeLauncherController::SetShelfBehaviorsFromPrefs,
241 base::Unretained(this))); 245 base::Unretained(this)));
242 } 246 }
243 247
244 ChromeLauncherControllerPerApp::~ChromeLauncherControllerPerApp() { 248 ChromeLauncherController::~ChromeLauncherController() {
245 // Reset the shell window controller here since it has a weak pointer to this. 249 // Reset the shell window controller here since it has a weak pointer to this.
246 shell_window_controller_.reset(); 250 shell_window_controller_.reset();
247 251
248 for (std::set<ash::Launcher*>::iterator iter = launchers_.begin(); 252 for (std::set<ash::Launcher*>::iterator iter = launchers_.begin();
249 iter != launchers_.end(); 253 iter != launchers_.end();
250 ++iter) 254 ++iter)
251 (*iter)->shelf_widget()->shelf_layout_manager()->RemoveObserver(this); 255 (*iter)->shelf_widget()->shelf_layout_manager()->RemoveObserver(this);
252 256
253 model_->RemoveObserver(this); 257 model_->RemoveObserver(this);
254 BrowserList::RemoveObserver(this); 258 BrowserList::RemoveObserver(this);
(...skipping 13 matching lines...) Expand all
268 model_->RemoveItemAt(index); 272 model_->RemoveItemAt(index);
269 } 273 }
270 274
271 if (ash::Shell::HasInstance()) 275 if (ash::Shell::HasInstance())
272 ash::Shell::GetInstance()->RemoveShellObserver(this); 276 ash::Shell::GetInstance()->RemoveShellObserver(this);
273 277
274 if (app_sync_ui_state_) 278 if (app_sync_ui_state_)
275 app_sync_ui_state_->RemoveObserver(this); 279 app_sync_ui_state_->RemoveObserver(this);
276 280
277 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); 281 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this);
282
283 if (instance_ == this)
284 instance_ = NULL;
278 } 285 }
279 286
280 void ChromeLauncherControllerPerApp::Init() { 287 // static
288 ChromeLauncherController* ChromeLauncherController::CreateInstance(
289 Profile* profile,
290 ash::LauncherModel* model) {
291 // We do not check here for re-creation of the ChromeLauncherController since
292 // it appears that it might be intentional that the ChromeLauncherController
293 // can be re-created.
294 instance_ = new ChromeLauncherController(profile, model);
295 return instance_;
296 }
297
298 void ChromeLauncherController::Init() {
281 UpdateAppLaunchersFromPref(); 299 UpdateAppLaunchersFromPref();
282 CreateBrowserShortcutLauncherItem(); 300 CreateBrowserShortcutLauncherItem();
283 301
284 // TODO(sky): update unit test so that this test isn't necessary. 302 // TODO(sky): update unit test so that this test isn't necessary.
285 if (ash::Shell::HasInstance()) { 303 if (ash::Shell::HasInstance()) {
286 SetShelfAutoHideBehaviorFromPrefs(); 304 SetShelfAutoHideBehaviorFromPrefs();
287 SetShelfAlignmentFromPrefs(); 305 SetShelfAlignmentFromPrefs();
288 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); 306 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_);
289 if (!prefs->FindPreference(prefs::kShelfAlignmentLocal)->HasUserSetting() || 307 if (!prefs->FindPreference(prefs::kShelfAlignmentLocal)->HasUserSetting() ||
290 !prefs->FindPreference(prefs::kShelfAutoHideBehaviorLocal)-> 308 !prefs->FindPreference(prefs::kShelfAutoHideBehaviorLocal)->
291 HasUserSetting()) { 309 HasUserSetting()) {
292 // This causes OnIsSyncingChanged to be called when the value of 310 // This causes OnIsSyncingChanged to be called when the value of
293 // PrefService::IsSyncing() changes. 311 // PrefService::IsSyncing() changes.
294 prefs->AddObserver(this); 312 prefs->AddObserver(this);
295 } 313 }
296 ash::Shell::GetInstance()->AddShellObserver(this); 314 ash::Shell::GetInstance()->AddShellObserver(this);
297 } 315 }
298 } 316 }
299 317
300 ChromeLauncherControllerPerApp* 318 ash::LauncherID ChromeLauncherController::CreateAppLauncherItem(
301 ChromeLauncherControllerPerApp::GetPerAppInterface() {
302 return this;
303 }
304
305 ash::LauncherID ChromeLauncherControllerPerApp::CreateTabbedLauncherItem(
306 LauncherItemController* controller,
307 IncognitoState is_incognito,
308 ash::LauncherItemStatus status) {
309 // The PerAppLauncher doesn't need an empty slot for TabbedLauncherItem and
310 // its LauncherItemController.
311 // TODO(skuhne): Remove function when PerBrowser launcher gets removed.
312 return 0;
313 }
314
315 ash::LauncherID ChromeLauncherControllerPerApp::CreateAppLauncherItem(
316 LauncherItemController* controller, 319 LauncherItemController* controller,
317 const std::string& app_id, 320 const std::string& app_id,
318 ash::LauncherItemStatus status) { 321 ash::LauncherItemStatus status) {
319 CHECK(controller); 322 CHECK(controller);
320 int index = 0; 323 int index = 0;
321 // Panels are inserted on the left so as not to push all existing panels over. 324 // Panels are inserted on the left so as not to push all existing panels over.
322 if (controller->GetLauncherItemType() != ash::TYPE_APP_PANEL) { 325 if (controller->GetLauncherItemType() != ash::TYPE_APP_PANEL) {
323 index = model_->item_count(); 326 index = model_->item_count();
324 // For the alternate shelf layout increment the index (after the app icon) 327 // For the alternate shelf layout increment the index (after the app icon)
325 if (ash::switches::UseAlternateShelfLayout()) 328 if (ash::switches::UseAlternateShelfLayout())
326 ++index; 329 ++index;
327 } 330 }
328 return InsertAppLauncherItem(controller, 331 return InsertAppLauncherItem(controller,
329 app_id, 332 app_id,
330 status, 333 status,
331 index, 334 index,
332 controller->GetLauncherItemType()); 335 controller->GetLauncherItemType());
333 } 336 }
334 337
335 void ChromeLauncherControllerPerApp::SetItemStatus( 338 void ChromeLauncherController::SetItemStatus(
336 ash::LauncherID id, 339 ash::LauncherID id,
337 ash::LauncherItemStatus status) { 340 ash::LauncherItemStatus status) {
338 int index = model_->ItemIndexByID(id); 341 int index = model_->ItemIndexByID(id);
339 // Since ordinary browser windows are not registered, we might get a negative 342 // Since ordinary browser windows are not registered, we might get a negative
340 // index here. 343 // index here.
341 if (index >= 0) { 344 if (index >= 0) {
342 ash::LauncherItem item = model_->items()[index]; 345 ash::LauncherItem item = model_->items()[index];
343 item.status = status; 346 item.status = status;
344 model_->Set(index, item); 347 model_->Set(index, item);
345 348
346 if (model_->items()[index].type == ash::TYPE_BROWSER_SHORTCUT) 349 if (model_->items()[index].type == ash::TYPE_BROWSER_SHORTCUT)
347 return; 350 return;
348 } 351 }
349 UpdateBrowserItemStatus(); 352 UpdateBrowserItemStatus();
350 } 353 }
351 354
352 void ChromeLauncherControllerPerApp::SetItemController( 355 void ChromeLauncherController::SetItemController(
353 ash::LauncherID id, 356 ash::LauncherID id,
354 LauncherItemController* controller) { 357 LauncherItemController* controller) {
355 CHECK(controller); 358 CHECK(controller);
356 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 359 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
357 CHECK(iter != id_to_item_controller_map_.end()); 360 CHECK(iter != id_to_item_controller_map_.end());
358 iter->second->OnRemoved(); 361 iter->second->OnRemoved();
359 iter->second = controller; 362 iter->second = controller;
360 controller->set_launcher_id(id); 363 controller->set_launcher_id(id);
361 } 364 }
362 365
363 void ChromeLauncherControllerPerApp::CloseLauncherItem(ash::LauncherID id) { 366 void ChromeLauncherController::CloseLauncherItem(ash::LauncherID id) {
364 CHECK(id); 367 CHECK(id);
365 if (IsPinned(id)) { 368 if (IsPinned(id)) {
366 // Create a new shortcut controller. 369 // Create a new shortcut controller.
367 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 370 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
368 CHECK(iter != id_to_item_controller_map_.end()); 371 CHECK(iter != id_to_item_controller_map_.end());
369 SetItemStatus(id, ash::STATUS_CLOSED); 372 SetItemStatus(id, ash::STATUS_CLOSED);
370 std::string app_id = iter->second->app_id(); 373 std::string app_id = iter->second->app_id();
371 iter->second->OnRemoved(); 374 iter->second->OnRemoved();
372 iter->second = new AppShortcutLauncherItemController(app_id, this); 375 iter->second = new AppShortcutLauncherItemController(app_id, this);
373 iter->second->set_launcher_id(id); 376 iter->second->set_launcher_id(id);
374 } else { 377 } else {
375 LauncherItemClosed(id); 378 LauncherItemClosed(id);
376 } 379 }
377 } 380 }
378 381
379 void ChromeLauncherControllerPerApp::Pin(ash::LauncherID id) { 382 void ChromeLauncherController::Pin(ash::LauncherID id) {
380 DCHECK(HasItemController(id)); 383 DCHECK(HasItemController(id));
381 384
382 int index = model_->ItemIndexByID(id); 385 int index = model_->ItemIndexByID(id);
383 DCHECK_GE(index, 0); 386 DCHECK_GE(index, 0);
384 387
385 ash::LauncherItem item = model_->items()[index]; 388 ash::LauncherItem item = model_->items()[index];
386 389
387 if (item.type == ash::TYPE_PLATFORM_APP || 390 if (item.type == ash::TYPE_PLATFORM_APP ||
388 item.type == ash::TYPE_WINDOWED_APP) { 391 item.type == ash::TYPE_WINDOWED_APP) {
389 item.type = ash::TYPE_APP_SHORTCUT; 392 item.type = ash::TYPE_APP_SHORTCUT;
390 model_->Set(index, item); 393 model_->Set(index, item);
391 } else if (item.type != ash::TYPE_APP_SHORTCUT) { 394 } else if (item.type != ash::TYPE_APP_SHORTCUT) {
392 return; 395 return;
393 } 396 }
394 397
395 if (CanPin()) 398 if (CanPin())
396 PersistPinnedState(); 399 PersistPinnedState();
397 } 400 }
398 401
399 void ChromeLauncherControllerPerApp::Unpin(ash::LauncherID id) { 402 void ChromeLauncherController::Unpin(ash::LauncherID id) {
400 DCHECK(HasItemController(id)); 403 DCHECK(HasItemController(id));
401 404
402 LauncherItemController* controller = id_to_item_controller_map_[id]; 405 LauncherItemController* controller = id_to_item_controller_map_[id];
403 if (controller->type() == LauncherItemController::TYPE_APP) { 406 if (controller->type() == LauncherItemController::TYPE_APP) {
404 int index = model_->ItemIndexByID(id); 407 int index = model_->ItemIndexByID(id);
405 DCHECK_GE(index, 0); 408 DCHECK_GE(index, 0);
406 ash::LauncherItem item = model_->items()[index]; 409 ash::LauncherItem item = model_->items()[index];
407 item.type = ash::TYPE_PLATFORM_APP; 410 item.type = ash::TYPE_PLATFORM_APP;
408 model_->Set(index, item); 411 model_->Set(index, item);
409 } else { 412 } else {
410 // Prevent the removal of items upon unpin if it is locked by a running 413 // Prevent the removal of items upon unpin if it is locked by a running
411 // windowed V1 app. 414 // windowed V1 app.
412 if (!controller->locked()) { 415 if (!controller->locked()) {
413 LauncherItemClosed(id); 416 LauncherItemClosed(id);
414 } else { 417 } else {
415 int index = model_->ItemIndexByID(id); 418 int index = model_->ItemIndexByID(id);
416 DCHECK_GE(index, 0); 419 DCHECK_GE(index, 0);
417 ash::LauncherItem item = model_->items()[index]; 420 ash::LauncherItem item = model_->items()[index];
418 item.type = ash::TYPE_WINDOWED_APP; 421 item.type = ash::TYPE_WINDOWED_APP;
419 model_->Set(index, item); 422 model_->Set(index, item);
420 } 423 }
421 } 424 }
422 if (CanPin()) 425 if (CanPin())
423 PersistPinnedState(); 426 PersistPinnedState();
424 } 427 }
425 428
426 bool ChromeLauncherControllerPerApp::IsPinned(ash::LauncherID id) { 429 bool ChromeLauncherController::IsPinned(ash::LauncherID id) {
427 int index = model_->ItemIndexByID(id); 430 int index = model_->ItemIndexByID(id);
428 if (index < 0) 431 if (index < 0)
429 return false; 432 return false;
430 ash::LauncherItemType type = model_->items()[index].type; 433 ash::LauncherItemType type = model_->items()[index].type;
431 return (type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_BROWSER_SHORTCUT); 434 return (type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_BROWSER_SHORTCUT);
432 } 435 }
433 436
434 void ChromeLauncherControllerPerApp::TogglePinned(ash::LauncherID id) { 437 void ChromeLauncherController::TogglePinned(ash::LauncherID id) {
435 if (!HasItemController(id)) 438 if (!HasItemController(id))
436 return; // May happen if item closed with menu open. 439 return; // May happen if item closed with menu open.
437 440
438 if (IsPinned(id)) 441 if (IsPinned(id))
439 Unpin(id); 442 Unpin(id);
440 else 443 else
441 Pin(id); 444 Pin(id);
442 } 445 }
443 446
444 bool ChromeLauncherControllerPerApp::IsPinnable(ash::LauncherID id) const { 447 bool ChromeLauncherController::IsPinnable(ash::LauncherID id) const {
445 int index = model_->ItemIndexByID(id); 448 int index = model_->ItemIndexByID(id);
446 if (index == -1) 449 if (index == -1)
447 return false; 450 return false;
448 451
449 ash::LauncherItemType type = model_->items()[index].type; 452 ash::LauncherItemType type = model_->items()[index].type;
450 return ((type == ash::TYPE_APP_SHORTCUT || 453 return ((type == ash::TYPE_APP_SHORTCUT ||
451 type == ash::TYPE_PLATFORM_APP || 454 type == ash::TYPE_PLATFORM_APP ||
452 type == ash::TYPE_WINDOWED_APP) && 455 type == ash::TYPE_WINDOWED_APP) &&
453 CanPin()); 456 CanPin());
454 } 457 }
455 458
456 void ChromeLauncherControllerPerApp::LockV1AppWithID( 459 void ChromeLauncherController::LockV1AppWithID(
457 const std::string& app_id) { 460 const std::string& app_id) {
458 ash::LauncherID id = GetLauncherIDForAppID(app_id); 461 ash::LauncherID id = GetLauncherIDForAppID(app_id);
459 if (!IsPinned(id) && !IsWindowedAppInLauncher(app_id)) { 462 if (!IsPinned(id) && !IsWindowedAppInLauncher(app_id)) {
460 CreateAppShortcutLauncherItemWithType(app_id, 463 CreateAppShortcutLauncherItemWithType(app_id,
461 model_->item_count(), 464 model_->item_count(),
462 ash::TYPE_WINDOWED_APP); 465 ash::TYPE_WINDOWED_APP);
463 id = GetLauncherIDForAppID(app_id); 466 id = GetLauncherIDForAppID(app_id);
464 } 467 }
465 CHECK(id); 468 CHECK(id);
466 id_to_item_controller_map_[id]->lock(); 469 id_to_item_controller_map_[id]->lock();
467 } 470 }
468 471
469 void ChromeLauncherControllerPerApp::UnlockV1AppWithID( 472 void ChromeLauncherController::UnlockV1AppWithID(
470 const std::string& app_id) { 473 const std::string& app_id) {
471 ash::LauncherID id = GetLauncherIDForAppID(app_id); 474 ash::LauncherID id = GetLauncherIDForAppID(app_id);
472 CHECK(IsPinned(id) || IsWindowedAppInLauncher(app_id)); 475 CHECK(IsPinned(id) || IsWindowedAppInLauncher(app_id));
473 CHECK(id); 476 CHECK(id);
474 LauncherItemController* controller = id_to_item_controller_map_[id]; 477 LauncherItemController* controller = id_to_item_controller_map_[id];
475 controller->unlock(); 478 controller->unlock();
476 if (!controller->locked() && !IsPinned(id)) 479 if (!controller->locked() && !IsPinned(id))
477 CloseLauncherItem(id); 480 CloseLauncherItem(id);
478 } 481 }
479 482
480 void ChromeLauncherControllerPerApp::Launch(ash::LauncherID id, 483 void ChromeLauncherController::Launch(ash::LauncherID id,
481 int event_flags) { 484 int event_flags) {
482 if (!HasItemController(id)) 485 if (!HasItemController(id))
483 return; // In case invoked from menu and item closed while menu up. 486 return; // In case invoked from menu and item closed while menu up.
484 id_to_item_controller_map_[id]->Launch(event_flags); 487 id_to_item_controller_map_[id]->Launch(event_flags);
485 } 488 }
486 489
487 void ChromeLauncherControllerPerApp::Close(ash::LauncherID id) { 490 void ChromeLauncherController::Close(ash::LauncherID id) {
488 if (!HasItemController(id)) 491 if (!HasItemController(id))
489 return; // May happen if menu closed. 492 return; // May happen if menu closed.
490 id_to_item_controller_map_[id]->Close(); 493 id_to_item_controller_map_[id]->Close();
491 } 494 }
492 495
493 bool ChromeLauncherControllerPerApp::IsOpen(ash::LauncherID id) { 496 bool ChromeLauncherController::IsOpen(ash::LauncherID id) {
494 if (!HasItemController(id)) 497 if (!HasItemController(id))
495 return false; 498 return false;
496 return id_to_item_controller_map_[id]->IsOpen(); 499 return id_to_item_controller_map_[id]->IsOpen();
497 } 500 }
498 501
499 bool ChromeLauncherControllerPerApp::IsPlatformApp(ash::LauncherID id) { 502 bool ChromeLauncherController::IsPlatformApp(ash::LauncherID id) {
500 if (!HasItemController(id)) 503 if (!HasItemController(id))
501 return false; 504 return false;
502 505
503 std::string app_id = GetAppIDForLauncherID(id); 506 std::string app_id = GetAppIDForLauncherID(id);
504 const Extension* extension = GetExtensionForAppID(app_id); 507 const Extension* extension = GetExtensionForAppID(app_id);
505 // An extension can be synced / updated at any time and therefore not be 508 // An extension can be synced / updated at any time and therefore not be
506 // available. 509 // available.
507 return extension ? extension->is_platform_app() : false; 510 return extension ? extension->is_platform_app() : false;
508 } 511 }
509 512
510 void ChromeLauncherControllerPerApp::LaunchApp(const std::string& app_id, 513 void ChromeLauncherController::LaunchApp(const std::string& app_id,
511 int event_flags) { 514 int event_flags) {
512 // |extension| could be NULL when it is being unloaded for updating. 515 // |extension| could be NULL when it is being unloaded for updating.
513 const Extension* extension = GetExtensionForAppID(app_id); 516 const Extension* extension = GetExtensionForAppID(app_id);
514 if (!extension) 517 if (!extension)
515 return; 518 return;
516 519
517 const ExtensionService* service = 520 const ExtensionService* service =
518 extensions::ExtensionSystem::Get(profile_)->extension_service(); 521 extensions::ExtensionSystem::Get(profile_)->extension_service();
519 if (!service->IsExtensionEnabledForLauncher(app_id)) { 522 if (!service->IsExtensionEnabledForLauncher(app_id)) {
520 // Do nothing if there is already a running enable flow. 523 // Do nothing if there is already a running enable flow.
521 if (extension_enable_flow_) 524 if (extension_enable_flow_)
522 return; 525 return;
523 526
524 extension_enable_flow_.reset( 527 extension_enable_flow_.reset(
525 new ExtensionEnableFlow(profile_, app_id, this)); 528 new ExtensionEnableFlow(profile_, app_id, this));
526 extension_enable_flow_->StartForNativeWindow(NULL); 529 extension_enable_flow_->StartForNativeWindow(NULL);
527 return; 530 return;
528 } 531 }
529 532
530 chrome::OpenApplication(chrome::AppLaunchParams(GetProfileForNewWindows(), 533 chrome::OpenApplication(chrome::AppLaunchParams(GetProfileForNewWindows(),
531 extension, 534 extension,
532 event_flags)); 535 event_flags));
533 } 536 }
534 537
535 void ChromeLauncherControllerPerApp::ActivateApp(const std::string& app_id, 538 void ChromeLauncherController::ActivateApp(const std::string& app_id,
536 int event_flags) { 539 int event_flags) {
537 // If there is an existing non-shortcut controller for this app, open it. 540 // If there is an existing non-shortcut controller for this app, open it.
538 ash::LauncherID id = GetLauncherIDForAppID(app_id); 541 ash::LauncherID id = GetLauncherIDForAppID(app_id);
539 if (id) { 542 if (id) {
540 LauncherItemController* controller = id_to_item_controller_map_[id]; 543 LauncherItemController* controller = id_to_item_controller_map_[id];
541 controller->Activate(); 544 controller->Activate();
542 return; 545 return;
543 } 546 }
544 547
545 // Create a temporary application launcher item and use it to see if there are 548 // Create a temporary application launcher item and use it to see if there are
546 // running instances. 549 // running instances.
547 scoped_ptr<AppShortcutLauncherItemController> app_controller( 550 scoped_ptr<AppShortcutLauncherItemController> app_controller(
548 new AppShortcutLauncherItemController(app_id, this)); 551 new AppShortcutLauncherItemController(app_id, this));
549 if (!app_controller->GetRunningApplications().empty()) 552 if (!app_controller->GetRunningApplications().empty())
550 app_controller->Activate(); 553 app_controller->Activate();
551 else 554 else
552 LaunchApp(app_id, event_flags); 555 LaunchApp(app_id, event_flags);
553 } 556 }
554 557
555 extensions::ExtensionPrefs::LaunchType 558 extensions::ExtensionPrefs::LaunchType
556 ChromeLauncherControllerPerApp::GetLaunchType(ash::LauncherID id) { 559 ChromeLauncherController::GetLaunchType(ash::LauncherID id) {
557 DCHECK(HasItemController(id)); 560 DCHECK(HasItemController(id));
558 561
559 const Extension* extension = GetExtensionForAppID( 562 const Extension* extension = GetExtensionForAppID(
560 id_to_item_controller_map_[id]->app_id()); 563 id_to_item_controller_map_[id]->app_id());
561 564
562 // An extension can be unloaded/updated/unavailable at any time. 565 // An extension can be unloaded/updated/unavailable at any time.
563 if (!extension) 566 if (!extension)
564 return extensions::ExtensionPrefs::LAUNCH_DEFAULT; 567 return extensions::ExtensionPrefs::LAUNCH_DEFAULT;
565 568
566 return profile_->GetExtensionService()->extension_prefs()->GetLaunchType( 569 return profile_->GetExtensionService()->extension_prefs()->GetLaunchType(
567 extension, 570 extension,
568 extensions::ExtensionPrefs::LAUNCH_DEFAULT); 571 extensions::ExtensionPrefs::LAUNCH_DEFAULT);
569 } 572 }
570 573
571 std::string ChromeLauncherControllerPerApp::GetAppID( 574 std::string ChromeLauncherController::GetAppID(content::WebContents* tab) {
572 content::WebContents* tab) {
573 return app_tab_helper_->GetAppID(tab); 575 return app_tab_helper_->GetAppID(tab);
574 } 576 }
575 577
576 ash::LauncherID ChromeLauncherControllerPerApp::GetLauncherIDForAppID( 578 ash::LauncherID ChromeLauncherController::GetLauncherIDForAppID(
577 const std::string& app_id) { 579 const std::string& app_id) {
578 for (IDToItemControllerMap::const_iterator i = 580 for (IDToItemControllerMap::const_iterator i =
579 id_to_item_controller_map_.begin(); 581 id_to_item_controller_map_.begin();
580 i != id_to_item_controller_map_.end(); ++i) { 582 i != id_to_item_controller_map_.end(); ++i) {
581 if (i->second->type() == LauncherItemController::TYPE_APP_PANEL) 583 if (i->second->type() == LauncherItemController::TYPE_APP_PANEL)
582 continue; // Don't include panels 584 continue; // Don't include panels
583 if (i->second->app_id() == app_id) 585 if (i->second->app_id() == app_id)
584 return i->first; 586 return i->first;
585 } 587 }
586 return 0; 588 return 0;
587 } 589 }
588 590
589 std::string ChromeLauncherControllerPerApp::GetAppIDForLauncherID( 591 std::string ChromeLauncherController::GetAppIDForLauncherID(
590 ash::LauncherID id) { 592 ash::LauncherID id) {
591 CHECK(HasItemController(id)); 593 CHECK(HasItemController(id));
592 return id_to_item_controller_map_[id]->app_id(); 594 return id_to_item_controller_map_[id]->app_id();
593 } 595 }
594 596
595 void ChromeLauncherControllerPerApp::SetAppImage( 597 void ChromeLauncherController::SetAppImage(const std::string& id,
596 const std::string& id, 598 const gfx::ImageSkia& image) {
597 const gfx::ImageSkia& image) {
598 // TODO: need to get this working for shortcuts. 599 // TODO: need to get this working for shortcuts.
599 600
600 for (IDToItemControllerMap::const_iterator i = 601 for (IDToItemControllerMap::const_iterator i =
601 id_to_item_controller_map_.begin(); 602 id_to_item_controller_map_.begin();
602 i != id_to_item_controller_map_.end(); ++i) { 603 i != id_to_item_controller_map_.end(); ++i) {
603 LauncherItemController* controller = i->second; 604 LauncherItemController* controller = i->second;
604 if (controller->app_id() != id) 605 if (controller->app_id() != id)
605 continue; 606 continue;
606 if (controller->image_set_by_controller()) 607 if (controller->image_set_by_controller())
607 continue; 608 continue;
608 int index = model_->ItemIndexByID(i->first); 609 int index = model_->ItemIndexByID(i->first);
609 if (index == -1) 610 if (index == -1)
610 continue; 611 continue;
611 ash::LauncherItem item = model_->items()[index]; 612 ash::LauncherItem item = model_->items()[index];
612 item.image = image; 613 item.image = image;
613 model_->Set(index, item); 614 model_->Set(index, item);
614 // It's possible we're waiting on more than one item, so don't break. 615 // It's possible we're waiting on more than one item, so don't break.
615 } 616 }
616 } 617 }
617 618
618 void ChromeLauncherControllerPerApp::OnAutoHideBehaviorChanged( 619 void ChromeLauncherController::OnAutoHideBehaviorChanged(
619 aura::RootWindow* root_window, 620 aura::RootWindow* root_window,
620 ash::ShelfAutoHideBehavior new_behavior) { 621 ash::ShelfAutoHideBehavior new_behavior) {
621 SetShelfAutoHideBehaviorPrefs(new_behavior, root_window); 622 SetShelfAutoHideBehaviorPrefs(new_behavior, root_window);
622 } 623 }
623 624
624 void ChromeLauncherControllerPerApp::SetLauncherItemImage( 625 void ChromeLauncherController::SetLauncherItemImage(
625 ash::LauncherID launcher_id, 626 ash::LauncherID launcher_id,
626 const gfx::ImageSkia& image) { 627 const gfx::ImageSkia& image) {
627 int index = model_->ItemIndexByID(launcher_id); 628 int index = model_->ItemIndexByID(launcher_id);
628 if (index == -1) 629 if (index == -1)
629 return; 630 return;
630 ash::LauncherItem item = model_->items()[index]; 631 ash::LauncherItem item = model_->items()[index];
631 item.image = image; 632 item.image = image;
632 model_->Set(index, item); 633 model_->Set(index, item);
633 } 634 }
634 635
635 bool ChromeLauncherControllerPerApp::IsAppPinned(const std::string& app_id) { 636 bool ChromeLauncherController::IsAppPinned(const std::string& app_id) {
636 for (IDToItemControllerMap::const_iterator i = 637 for (IDToItemControllerMap::const_iterator i =
637 id_to_item_controller_map_.begin(); 638 id_to_item_controller_map_.begin();
638 i != id_to_item_controller_map_.end(); ++i) { 639 i != id_to_item_controller_map_.end(); ++i) {
639 if (IsPinned(i->first) && i->second->app_id() == app_id) 640 if (IsPinned(i->first) && i->second->app_id() == app_id)
640 return true; 641 return true;
641 } 642 }
642 return false; 643 return false;
643 } 644 }
644 645
645 bool ChromeLauncherControllerPerApp::IsWindowedAppInLauncher( 646 bool ChromeLauncherController::IsWindowedAppInLauncher(
646 const std::string& app_id) { 647 const std::string& app_id) {
647 int index = model_->ItemIndexByID(GetLauncherIDForAppID(app_id)); 648 int index = model_->ItemIndexByID(GetLauncherIDForAppID(app_id));
648 if (index < 0) 649 if (index < 0)
649 return false; 650 return false;
650 651
651 ash::LauncherItemType type = model_->items()[index].type; 652 ash::LauncherItemType type = model_->items()[index].type;
652 return type == ash::TYPE_WINDOWED_APP; 653 return type == ash::TYPE_WINDOWED_APP;
653 } 654 }
654 655
655 void ChromeLauncherControllerPerApp::PinAppWithID(const std::string& app_id) { 656 void ChromeLauncherController::PinAppWithID(const std::string& app_id) {
656 if (CanPin()) 657 if (CanPin())
657 DoPinAppWithID(app_id); 658 DoPinAppWithID(app_id);
658 else 659 else
659 NOTREACHED(); 660 NOTREACHED();
660 } 661 }
661 662
662 void ChromeLauncherControllerPerApp::SetLaunchType( 663 void ChromeLauncherController::SetLaunchType(
663 ash::LauncherID id, 664 ash::LauncherID id,
664 extensions::ExtensionPrefs::LaunchType launch_type) { 665 extensions::ExtensionPrefs::LaunchType launch_type) {
665 if (!HasItemController(id)) 666 if (!HasItemController(id))
666 return; 667 return;
667 668
668 profile_->GetExtensionService()->extension_prefs()->SetLaunchType( 669 profile_->GetExtensionService()->extension_prefs()->SetLaunchType(
669 id_to_item_controller_map_[id]->app_id(), launch_type); 670 id_to_item_controller_map_[id]->app_id(), launch_type);
670 } 671 }
671 672
672 void ChromeLauncherControllerPerApp::UnpinAppsWithID( 673 void ChromeLauncherController::UnpinAppsWithID(const std::string& app_id) {
673 const std::string& app_id) {
674 if (CanPin()) 674 if (CanPin())
675 DoUnpinAppsWithID(app_id); 675 DoUnpinAppsWithID(app_id);
676 else 676 else
677 NOTREACHED(); 677 NOTREACHED();
678 } 678 }
679 679
680 bool ChromeLauncherControllerPerApp::IsLoggedInAsGuest() { 680 bool ChromeLauncherController::IsLoggedInAsGuest() {
681 return ProfileManager::GetDefaultProfileOrOffTheRecord()->IsOffTheRecord(); 681 return ProfileManager::GetDefaultProfileOrOffTheRecord()->IsOffTheRecord();
682 } 682 }
683 683
684 void ChromeLauncherControllerPerApp::CreateNewWindow() { 684 void ChromeLauncherController::CreateNewWindow() {
685 chrome::NewEmptyWindow( 685 chrome::NewEmptyWindow(
686 GetProfileForNewWindows(), chrome::HOST_DESKTOP_TYPE_ASH); 686 GetProfileForNewWindows(), chrome::HOST_DESKTOP_TYPE_ASH);
687 } 687 }
688 688
689 void ChromeLauncherControllerPerApp::CreateNewIncognitoWindow() { 689 void ChromeLauncherController::CreateNewIncognitoWindow() {
690 chrome::NewEmptyWindow(GetProfileForNewWindows()->GetOffTheRecordProfile(), 690 chrome::NewEmptyWindow(GetProfileForNewWindows()->GetOffTheRecordProfile(),
691 chrome::HOST_DESKTOP_TYPE_ASH); 691 chrome::HOST_DESKTOP_TYPE_ASH);
692 } 692 }
693 693
694 bool ChromeLauncherControllerPerApp::CanPin() const { 694 bool ChromeLauncherController::CanPin() const {
695 const PrefService::Preference* pref = 695 const PrefService::Preference* pref =
696 profile_->GetPrefs()->FindPreference(prefs::kPinnedLauncherApps); 696 profile_->GetPrefs()->FindPreference(prefs::kPinnedLauncherApps);
697 return pref && pref->IsUserModifiable(); 697 return pref && pref->IsUserModifiable();
698 } 698 }
699 699
700 void ChromeLauncherControllerPerApp::PersistPinnedState() { 700 void ChromeLauncherController::PersistPinnedState() {
701 if (ignore_persist_pinned_state_change_) 701 if (ignore_persist_pinned_state_change_)
702 return; 702 return;
703 // It is a coding error to call PersistPinnedState() if the pinned apps are 703 // It is a coding error to call PersistPinnedState() if the pinned apps are
704 // not user-editable. The code should check earlier and not perform any 704 // not user-editable. The code should check earlier and not perform any
705 // modification actions that trigger persisting the state. 705 // modification actions that trigger persisting the state.
706 if (!CanPin()) { 706 if (!CanPin()) {
707 NOTREACHED() << "Can't pin but pinned state being updated"; 707 NOTREACHED() << "Can't pin but pinned state being updated";
708 return; 708 return;
709 } 709 }
710 710
(...skipping 13 matching lines...) Expand all
724 if (app_value) 724 if (app_value)
725 updater->Append(app_value); 725 updater->Append(app_value);
726 } 726 }
727 } else if (model_->items()[i].type == ash::TYPE_BROWSER_SHORTCUT) { 727 } else if (model_->items()[i].type == ash::TYPE_BROWSER_SHORTCUT) {
728 PersistChromeItemIndex(i); 728 PersistChromeItemIndex(i);
729 } 729 }
730 } 730 }
731 } 731 }
732 pref_change_registrar_.Add( 732 pref_change_registrar_.Add(
733 prefs::kPinnedLauncherApps, 733 prefs::kPinnedLauncherApps,
734 base::Bind(&ChromeLauncherControllerPerApp::UpdateAppLaunchersFromPref, 734 base::Bind(&ChromeLauncherController::UpdateAppLaunchersFromPref,
735 base::Unretained(this))); 735 base::Unretained(this)));
736 } 736 }
737 737
738 ash::LauncherModel* ChromeLauncherControllerPerApp::model() { 738 ash::LauncherModel* ChromeLauncherController::model() {
739 return model_; 739 return model_;
740 } 740 }
741 741
742 Profile* ChromeLauncherControllerPerApp::profile() { 742 Profile* ChromeLauncherController::profile() {
743 return profile_; 743 return profile_;
744 } 744 }
745 745
746 ash::ShelfAutoHideBehavior 746 ash::ShelfAutoHideBehavior ChromeLauncherController::GetShelfAutoHideBehavior(
747 ChromeLauncherControllerPerApp::GetShelfAutoHideBehavior( 747 aura::RootWindow* root_window) const {
748 aura::RootWindow* root_window) const {
749 // Don't show the shelf in app mode. 748 // Don't show the shelf in app mode.
750 if (chrome::IsRunningInAppMode()) 749 if (chrome::IsRunningInAppMode())
751 return ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN; 750 return ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN;
752 751
753 // See comment in |kShelfAlignment| as to why we consider two prefs. 752 // See comment in |kShelfAlignment| as to why we consider two prefs.
754 const std::string behavior_value( 753 const std::string behavior_value(
755 GetPrefForRootWindow(profile_->GetPrefs(), 754 GetPrefForRootWindow(profile_->GetPrefs(),
756 root_window, 755 root_window,
757 prefs::kShelfAutoHideBehaviorLocal, 756 prefs::kShelfAutoHideBehaviorLocal,
758 prefs::kShelfAutoHideBehavior)); 757 prefs::kShelfAutoHideBehavior));
759 758
760 // Note: To maintain sync compatibility with old images of chrome/chromeos 759 // Note: To maintain sync compatibility with old images of chrome/chromeos
761 // the set of values that may be encountered includes the now-extinct 760 // the set of values that may be encountered includes the now-extinct
762 // "Default" as well as "Never" and "Always", "Default" should now 761 // "Default" as well as "Never" and "Always", "Default" should now
763 // be treated as "Never" (http://crbug.com/146773). 762 // be treated as "Never" (http://crbug.com/146773).
764 if (behavior_value == ash::kShelfAutoHideBehaviorAlways) 763 if (behavior_value == ash::kShelfAutoHideBehaviorAlways)
765 return ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; 764 return ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
766 return ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER; 765 return ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER;
767 } 766 }
768 767
769 bool ChromeLauncherControllerPerApp::CanUserModifyShelfAutoHideBehavior( 768 bool ChromeLauncherController::CanUserModifyShelfAutoHideBehavior(
770 aura::RootWindow* root_window) const { 769 aura::RootWindow* root_window) const {
771 return profile_->GetPrefs()-> 770 return profile_->GetPrefs()->
772 FindPreference(prefs::kShelfAutoHideBehaviorLocal)->IsUserModifiable(); 771 FindPreference(prefs::kShelfAutoHideBehaviorLocal)->IsUserModifiable();
773 } 772 }
774 773
775 void ChromeLauncherControllerPerApp::ToggleShelfAutoHideBehavior( 774 void ChromeLauncherController::ToggleShelfAutoHideBehavior(
776 aura::RootWindow* root_window) { 775 aura::RootWindow* root_window) {
777 ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) == 776 ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) ==
778 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ? 777 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ?
779 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER : 778 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER :
780 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; 779 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
781 SetShelfAutoHideBehaviorPrefs(behavior, root_window); 780 SetShelfAutoHideBehaviorPrefs(behavior, root_window);
782 return; 781 return;
783 } 782 }
784 783
785 void ChromeLauncherControllerPerApp::RemoveTabFromRunningApp( 784 void ChromeLauncherController::RemoveTabFromRunningApp(
786 WebContents* tab, 785 WebContents* tab,
787 const std::string& app_id) { 786 const std::string& app_id) {
788 web_contents_to_app_id_.erase(tab); 787 web_contents_to_app_id_.erase(tab);
789 AppIDToWebContentsListMap::iterator i_app_id = 788 AppIDToWebContentsListMap::iterator i_app_id =
790 app_id_to_web_contents_list_.find(app_id); 789 app_id_to_web_contents_list_.find(app_id);
791 if (i_app_id != app_id_to_web_contents_list_.end()) { 790 if (i_app_id != app_id_to_web_contents_list_.end()) {
792 WebContentsList* tab_list = &i_app_id->second; 791 WebContentsList* tab_list = &i_app_id->second;
793 tab_list->remove(tab); 792 tab_list->remove(tab);
794 if (tab_list->empty()) { 793 if (tab_list->empty()) {
795 app_id_to_web_contents_list_.erase(i_app_id); 794 app_id_to_web_contents_list_.erase(i_app_id);
796 i_app_id = app_id_to_web_contents_list_.end(); 795 i_app_id = app_id_to_web_contents_list_.end();
797 ash::LauncherID id = GetLauncherIDForAppID(app_id); 796 ash::LauncherID id = GetLauncherIDForAppID(app_id);
798 if (id) 797 if (id)
799 SetItemStatus(id, ash::STATUS_CLOSED); 798 SetItemStatus(id, ash::STATUS_CLOSED);
800 } 799 }
801 } 800 }
802 } 801 }
803 802
804 void ChromeLauncherControllerPerApp::UpdateAppState( 803 void ChromeLauncherController::UpdateAppState(content::WebContents* contents,
805 content::WebContents* contents, 804 AppState app_state) {
806 AppState app_state) {
807 std::string app_id = GetAppID(contents); 805 std::string app_id = GetAppID(contents);
808 806
809 // Check if the gMail app is loaded and it matches the given content. 807 // Check if the gMail app is loaded and it matches the given content.
810 // This special treatment is needed to address crbug.com/234268. 808 // This special treatment is needed to address crbug.com/234268.
811 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) 809 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents))
812 app_id = kGmailAppId; 810 app_id = kGmailAppId;
813 811
814 // Check the old |app_id| for a tab. If the contents has changed we need to 812 // Check the old |app_id| for a tab. If the contents has changed we need to
815 // remove it from the previous app. 813 // remove it from the previous app.
816 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) { 814 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 ash::LauncherID id = GetLauncherIDForAppID(app_id); 849 ash::LauncherID id = GetLauncherIDForAppID(app_id);
852 if (id) { 850 if (id) {
853 // If the window is active, mark the app as active. 851 // If the window is active, mark the app as active.
854 SetItemStatus(id, app_state == APP_STATE_WINDOW_ACTIVE ? 852 SetItemStatus(id, app_state == APP_STATE_WINDOW_ACTIVE ?
855 ash::STATUS_ACTIVE : ash::STATUS_RUNNING); 853 ash::STATUS_ACTIVE : ash::STATUS_RUNNING);
856 } 854 }
857 } 855 }
858 UpdateBrowserItemStatus(); 856 UpdateBrowserItemStatus();
859 } 857 }
860 858
861 void ChromeLauncherControllerPerApp::SetRefocusURLPatternForTest( 859 void ChromeLauncherController::SetRefocusURLPatternForTest(ash::LauncherID id,
862 ash::LauncherID id, 860 const GURL& url) {
863 const GURL& url) {
864 DCHECK(HasItemController(id)); 861 DCHECK(HasItemController(id));
865 LauncherItemController* controller = id_to_item_controller_map_[id]; 862 LauncherItemController* controller = id_to_item_controller_map_[id];
866 863
867 int index = model_->ItemIndexByID(id); 864 int index = model_->ItemIndexByID(id);
868 if (index == -1) { 865 if (index == -1) {
869 NOTREACHED() << "Invalid launcher id"; 866 NOTREACHED() << "Invalid launcher id";
870 return; 867 return;
871 } 868 }
872 869
873 ash::LauncherItemType type = model_->items()[index].type; 870 ash::LauncherItemType type = model_->items()[index].type;
874 if (type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_WINDOWED_APP) { 871 if (type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_WINDOWED_APP) {
875 AppShortcutLauncherItemController* app_controller = 872 AppShortcutLauncherItemController* app_controller =
876 static_cast<AppShortcutLauncherItemController*>(controller); 873 static_cast<AppShortcutLauncherItemController*>(controller);
877 app_controller->set_refocus_url(url); 874 app_controller->set_refocus_url(url);
878 } else { 875 } else {
879 NOTREACHED() << "Invalid launcher type"; 876 NOTREACHED() << "Invalid launcher type";
880 } 877 }
881 } 878 }
882 879
883 const Extension* ChromeLauncherControllerPerApp::GetExtensionForAppID( 880 const Extension* ChromeLauncherController::GetExtensionForAppID(
884 const std::string& app_id) const { 881 const std::string& app_id) const {
885 // Some unit tests do not have a real extension. 882 // Some unit tests do not have a real extension.
886 return (profile_->GetExtensionService()) ? 883 return (profile_->GetExtensionService()) ?
887 profile_->GetExtensionService()->GetInstalledExtension(app_id) : NULL; 884 profile_->GetExtensionService()->GetInstalledExtension(app_id) : NULL;
888 } 885 }
889 886
890 void ChromeLauncherControllerPerApp::ActivateWindowOrMinimizeIfActive( 887 void ChromeLauncherController::ActivateWindowOrMinimizeIfActive(
891 ui::BaseWindow* window, 888 ui::BaseWindow* window,
892 bool allow_minimize) { 889 bool allow_minimize) {
893 if (window->IsActive() && allow_minimize) { 890 if (window->IsActive() && allow_minimize) {
894 if (CommandLine::ForCurrentProcess()->HasSwitch( 891 if (CommandLine::ForCurrentProcess()->HasSwitch(
895 switches::kDisableMinimizeOnSecondLauncherItemClick)) { 892 switches::kDisableMinimizeOnSecondLauncherItemClick)) {
896 AnimateWindow(window->GetNativeWindow(), 893 AnimateWindow(window->GetNativeWindow(),
897 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE); 894 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE);
898 } else { 895 } else {
899 window->Minimize(); 896 window->Minimize();
900 } 897 }
901 } else { 898 } else {
902 window->Show(); 899 window->Show();
903 window->Activate(); 900 window->Activate();
904 } 901 }
905 } 902 }
906 903
907 void ChromeLauncherControllerPerApp::ItemSelected(const ash::LauncherItem& item, 904 void ChromeLauncherController::ItemSelected(const ash::LauncherItem& item,
908 const ui::Event& event) { 905 const ui::Event& event) {
909 DCHECK(HasItemController(item.id)); 906 DCHECK(HasItemController(item.id));
910 LauncherItemController* item_controller = id_to_item_controller_map_[item.id]; 907 LauncherItemController* item_controller = id_to_item_controller_map_[item.id];
911 #if defined(OS_CHROMEOS) 908 #if defined(OS_CHROMEOS)
912 if (!item_controller->app_id().empty()) { 909 if (!item_controller->app_id().empty()) {
913 chromeos::default_pinned_apps_field_trial::RecordShelfAppClick( 910 chromeos::default_pinned_apps_field_trial::RecordShelfAppClick(
914 item_controller->app_id()); 911 item_controller->app_id());
915 } 912 }
916 #endif 913 #endif
917 item_controller->Clicked(event); 914 item_controller->Clicked(event);
918 } 915 }
919 916
920 string16 ChromeLauncherControllerPerApp::GetTitle( 917 string16 ChromeLauncherController::GetTitle(const ash::LauncherItem& item) {
921 const ash::LauncherItem& item) {
922 DCHECK(HasItemController(item.id)); 918 DCHECK(HasItemController(item.id));
923 return id_to_item_controller_map_[item.id]->GetTitle(); 919 return id_to_item_controller_map_[item.id]->GetTitle();
924 } 920 }
925 921
926 ui::MenuModel* ChromeLauncherControllerPerApp::CreateContextMenu( 922 ui::MenuModel* ChromeLauncherController::CreateContextMenu(
927 const ash::LauncherItem& item, 923 const ash::LauncherItem& item,
928 aura::RootWindow* root_window) { 924 aura::RootWindow* root_window) {
929 return new LauncherContextMenu(this, &item, root_window); 925 return new LauncherContextMenu(this, &item, root_window);
930 } 926 }
931 927
932 ash::LauncherMenuModel* ChromeLauncherControllerPerApp::CreateApplicationMenu( 928 ash::LauncherMenuModel* ChromeLauncherController::CreateApplicationMenu(
933 const ash::LauncherItem& item, 929 const ash::LauncherItem& item,
934 int event_flags) { 930 int event_flags) {
935 return new LauncherApplicationMenuItemModel(GetApplicationList(item, 931 return new LauncherApplicationMenuItemModel(GetApplicationList(item,
936 event_flags)); 932 event_flags));
937 } 933 }
938 934
939 ash::LauncherID ChromeLauncherControllerPerApp::GetIDByWindow( 935 ash::LauncherID ChromeLauncherController::GetIDByWindow(aura::Window* window) {
940 aura::Window* window) {
941 int browser_index = ash::launcher::GetBrowserItemIndex(*model_); 936 int browser_index = ash::launcher::GetBrowserItemIndex(*model_);
942 DCHECK_GE(browser_index, 0); 937 DCHECK_GE(browser_index, 0);
943 ash::LauncherID browser_id = model_->items()[browser_index].id; 938 ash::LauncherID browser_id = model_->items()[browser_index].id;
944 939
945 IDToItemControllerMap::const_iterator i = id_to_item_controller_map_.begin(); 940 IDToItemControllerMap::const_iterator i = id_to_item_controller_map_.begin();
946 for (; i != id_to_item_controller_map_.end(); ++i) { 941 for (; i != id_to_item_controller_map_.end(); ++i) {
947 // Since a |window| can be used by multiple applications, an explicit 942 // Since a |window| can be used by multiple applications, an explicit
948 // application always gets chosen over the generic browser. 943 // application always gets chosen over the generic browser.
949 if (i->first != browser_id && i->second->IsCurrentlyShownInWindow(window)) 944 if (i->first != browser_id && i->second->IsCurrentlyShownInWindow(window))
950 return i->first; 945 return i->first;
951 } 946 }
952 947
953 if (i == id_to_item_controller_map_.end() && 948 if (i == id_to_item_controller_map_.end() &&
954 GetBrowserShortcutLauncherItemController()-> 949 GetBrowserShortcutLauncherItemController()->
955 IsCurrentlyShownInWindow(window)) 950 IsCurrentlyShownInWindow(window))
956 return browser_id; 951 return browser_id;
957 952
958 return 0; 953 return 0;
959 } 954 }
960 955
961 bool ChromeLauncherControllerPerApp::IsDraggable( 956 bool ChromeLauncherController::IsDraggable(const ash::LauncherItem& item) {
962 const ash::LauncherItem& item) {
963 return (item.type == ash::TYPE_APP_SHORTCUT || 957 return (item.type == ash::TYPE_APP_SHORTCUT ||
964 item.type == ash::TYPE_WINDOWED_APP) ? CanPin() : true; 958 item.type == ash::TYPE_WINDOWED_APP) ? CanPin() : true;
965 } 959 }
966 960
967 bool ChromeLauncherControllerPerApp::ShouldShowTooltip( 961 bool ChromeLauncherController::ShouldShowTooltip(
968 const ash::LauncherItem& item) { 962 const ash::LauncherItem& item) {
969 if (item.type == ash::TYPE_APP_PANEL && 963 if (item.type == ash::TYPE_APP_PANEL &&
970 id_to_item_controller_map_[item.id]->IsVisible()) 964 id_to_item_controller_map_[item.id]->IsVisible())
971 return false; 965 return false;
972 return true; 966 return true;
973 } 967 }
974 968
975 void ChromeLauncherControllerPerApp::OnLauncherCreated( 969 void ChromeLauncherController::OnLauncherCreated(ash::Launcher* launcher) {
976 ash::Launcher* launcher) {
977 launchers_.insert(launcher); 970 launchers_.insert(launcher);
978 launcher->shelf_widget()->shelf_layout_manager()->AddObserver(this); 971 launcher->shelf_widget()->shelf_layout_manager()->AddObserver(this);
979 } 972 }
980 973
981 void ChromeLauncherControllerPerApp::OnLauncherDestroyed( 974 void ChromeLauncherController::OnLauncherDestroyed(ash::Launcher* launcher) {
982 ash::Launcher* launcher) {
983 launchers_.erase(launcher); 975 launchers_.erase(launcher);
984 // RemoveObserver is not called here, since by the time this method is called 976 // RemoveObserver is not called here, since by the time this method is called
985 // Launcher is already in its destructor. 977 // Launcher is already in its destructor.
986 } 978 }
987 979
988 void ChromeLauncherControllerPerApp::LauncherItemAdded(int index) { 980 void ChromeLauncherController::LauncherItemAdded(int index) {
989 } 981 }
990 982
991 void ChromeLauncherControllerPerApp::LauncherItemRemoved( 983 void ChromeLauncherController::LauncherItemRemoved(int index,
992 int index, 984 ash::LauncherID id) {
993 ash::LauncherID id) {
994 } 985 }
995 986
996 void ChromeLauncherControllerPerApp::LauncherItemMoved( 987 void ChromeLauncherController::LauncherItemMoved(int start_index,
997 int start_index, 988 int target_index) {
998 int target_index) {
999 ash::LauncherID id = model_->items()[target_index].id; 989 ash::LauncherID id = model_->items()[target_index].id;
1000 if (HasItemController(id) && IsPinned(id)) 990 if (HasItemController(id) && IsPinned(id))
1001 PersistPinnedState(); 991 PersistPinnedState();
1002 } 992 }
1003 993
1004 void ChromeLauncherControllerPerApp::LauncherItemChanged( 994 void ChromeLauncherController::LauncherItemChanged(
1005 int index, 995 int index,
1006 const ash::LauncherItem& old_item) { 996 const ash::LauncherItem& old_item) {
1007 ash::LauncherID id = model_->items()[index].id; 997 ash::LauncherID id = model_->items()[index].id;
1008 DCHECK(HasItemController(id)); 998 DCHECK(HasItemController(id));
1009 id_to_item_controller_map_[id]->LauncherItemChanged(index, old_item); 999 id_to_item_controller_map_[id]->LauncherItemChanged(index, old_item);
1010 } 1000 }
1011 1001
1012 void ChromeLauncherControllerPerApp::LauncherStatusChanged() { 1002 void ChromeLauncherController::LauncherStatusChanged() {
1013 } 1003 }
1014 1004
1015 void ChromeLauncherControllerPerApp::Observe( 1005 void ChromeLauncherController::Observe(
1016 int type, 1006 int type,
1017 const content::NotificationSource& source, 1007 const content::NotificationSource& source,
1018 const content::NotificationDetails& details) { 1008 const content::NotificationDetails& details) {
1019 switch (type) { 1009 switch (type) {
1020 case chrome::NOTIFICATION_EXTENSION_LOADED: { 1010 case chrome::NOTIFICATION_EXTENSION_LOADED: {
1021 const Extension* extension = 1011 const Extension* extension =
1022 content::Details<const Extension>(details).ptr(); 1012 content::Details<const Extension>(details).ptr();
1023 if (IsAppPinned(extension->id())) { 1013 if (IsAppPinned(extension->id())) {
1024 // Clear and re-fetch to ensure icon is up-to-date. 1014 // Clear and re-fetch to ensure icon is up-to-date.
1025 app_icon_loader_->ClearImage(extension->id()); 1015 app_icon_loader_->ClearImage(extension->id());
(...skipping 23 matching lines...) Expand all
1049 app_icon_loader_->UpdateImage(id); 1039 app_icon_loader_->UpdateImage(id);
1050 } 1040 }
1051 } 1041 }
1052 break; 1042 break;
1053 } 1043 }
1054 default: 1044 default:
1055 NOTREACHED() << "Unexpected notification type=" << type; 1045 NOTREACHED() << "Unexpected notification type=" << type;
1056 } 1046 }
1057 } 1047 }
1058 1048
1059 void ChromeLauncherControllerPerApp::OnShelfAlignmentChanged( 1049 void ChromeLauncherController::OnShelfAlignmentChanged(
1060 aura::RootWindow* root_window) { 1050 aura::RootWindow* root_window) {
1061 const char* pref_value = NULL; 1051 const char* pref_value = NULL;
1062 switch (ash::Shell::GetInstance()->GetShelfAlignment(root_window)) { 1052 switch (ash::Shell::GetInstance()->GetShelfAlignment(root_window)) {
1063 case ash::SHELF_ALIGNMENT_BOTTOM: 1053 case ash::SHELF_ALIGNMENT_BOTTOM:
1064 pref_value = ash::kShelfAlignmentBottom; 1054 pref_value = ash::kShelfAlignmentBottom;
1065 break; 1055 break;
1066 case ash::SHELF_ALIGNMENT_LEFT: 1056 case ash::SHELF_ALIGNMENT_LEFT:
1067 pref_value = ash::kShelfAlignmentLeft; 1057 pref_value = ash::kShelfAlignmentLeft;
1068 break; 1058 break;
1069 case ash::SHELF_ALIGNMENT_RIGHT: 1059 case ash::SHELF_ALIGNMENT_RIGHT:
1070 pref_value = ash::kShelfAlignmentRight; 1060 pref_value = ash::kShelfAlignmentRight;
1071 break; 1061 break;
1072 case ash::SHELF_ALIGNMENT_TOP: 1062 case ash::SHELF_ALIGNMENT_TOP:
1073 pref_value = ash::kShelfAlignmentTop; 1063 pref_value = ash::kShelfAlignmentTop;
1074 } 1064 }
1075 1065
1076 UpdatePerDisplayPref( 1066 UpdatePerDisplayPref(
1077 profile_->GetPrefs(), root_window, prefs::kShelfAlignment, pref_value); 1067 profile_->GetPrefs(), root_window, prefs::kShelfAlignment, pref_value);
1078 1068
1079 if (root_window == ash::Shell::GetPrimaryRootWindow()) { 1069 if (root_window == ash::Shell::GetPrimaryRootWindow()) {
1080 // See comment in |kShelfAlignment| about why we have two prefs here. 1070 // See comment in |kShelfAlignment| about why we have two prefs here.
1081 profile_->GetPrefs()->SetString(prefs::kShelfAlignmentLocal, pref_value); 1071 profile_->GetPrefs()->SetString(prefs::kShelfAlignmentLocal, pref_value);
1082 profile_->GetPrefs()->SetString(prefs::kShelfAlignment, pref_value); 1072 profile_->GetPrefs()->SetString(prefs::kShelfAlignment, pref_value);
1083 } 1073 }
1084 } 1074 }
1085 1075
1086 void ChromeLauncherControllerPerApp::OnDisplayConfigurationChanging() { 1076 void ChromeLauncherController::OnDisplayConfigurationChanging() {
1087 } 1077 }
1088 1078
1089 void ChromeLauncherControllerPerApp::OnDisplayConfigurationChanged() { 1079 void ChromeLauncherController::OnDisplayConfigurationChanged() {
1090 SetShelfBehaviorsFromPrefs(); 1080 SetShelfBehaviorsFromPrefs();
1091 } 1081 }
1092 1082
1093 void ChromeLauncherControllerPerApp::OnIsSyncingChanged() { 1083 void ChromeLauncherController::OnIsSyncingChanged() {
1094 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); 1084 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_);
1095 MaybePropagatePrefToLocal(prefs, 1085 MaybePropagatePrefToLocal(prefs,
1096 prefs::kShelfAlignmentLocal, 1086 prefs::kShelfAlignmentLocal,
1097 prefs::kShelfAlignment); 1087 prefs::kShelfAlignment);
1098 MaybePropagatePrefToLocal(prefs, 1088 MaybePropagatePrefToLocal(prefs,
1099 prefs::kShelfAutoHideBehaviorLocal, 1089 prefs::kShelfAutoHideBehaviorLocal,
1100 prefs::kShelfAutoHideBehavior); 1090 prefs::kShelfAutoHideBehavior);
1101 } 1091 }
1102 1092
1103 void ChromeLauncherControllerPerApp::OnAppSyncUIStatusChanged() { 1093 void ChromeLauncherController::OnAppSyncUIStatusChanged() {
1104 if (app_sync_ui_state_->status() == AppSyncUIState::STATUS_SYNCING) 1094 if (app_sync_ui_state_->status() == AppSyncUIState::STATUS_SYNCING)
1105 model_->SetStatus(ash::LauncherModel::STATUS_LOADING); 1095 model_->SetStatus(ash::LauncherModel::STATUS_LOADING);
1106 else 1096 else
1107 model_->SetStatus(ash::LauncherModel::STATUS_NORMAL); 1097 model_->SetStatus(ash::LauncherModel::STATUS_NORMAL);
1108 } 1098 }
1109 1099
1110 void ChromeLauncherControllerPerApp::ExtensionEnableFlowFinished() { 1100 void ChromeLauncherController::ExtensionEnableFlowFinished() {
1111 LaunchApp(extension_enable_flow_->extension_id(), ui::EF_NONE); 1101 LaunchApp(extension_enable_flow_->extension_id(), ui::EF_NONE);
1112 extension_enable_flow_.reset(); 1102 extension_enable_flow_.reset();
1113 } 1103 }
1114 1104
1115 void ChromeLauncherControllerPerApp::ExtensionEnableFlowAborted( 1105 void ChromeLauncherController::ExtensionEnableFlowAborted(bool user_initiated) {
1116 bool user_initiated) {
1117 extension_enable_flow_.reset(); 1106 extension_enable_flow_.reset();
1118 } 1107 }
1119 1108
1120 ChromeLauncherAppMenuItems ChromeLauncherControllerPerApp::GetApplicationList( 1109 ChromeLauncherAppMenuItems ChromeLauncherController::GetApplicationList(
1121 const ash::LauncherItem& item, 1110 const ash::LauncherItem& item,
1122 int event_flags) { 1111 int event_flags) {
1123 // Make sure that there is a controller associated with the id and that the 1112 // Make sure that there is a controller associated with the id and that the
1124 // extension itself is a valid application and not a panel. 1113 // extension itself is a valid application and not a panel.
1125 if (!HasItemController(item.id) || 1114 if (!HasItemController(item.id) ||
1126 !GetLauncherIDForAppID(id_to_item_controller_map_[item.id]->app_id())) 1115 !GetLauncherIDForAppID(id_to_item_controller_map_[item.id]->app_id()))
1127 return ChromeLauncherAppMenuItems().Pass(); 1116 return ChromeLauncherAppMenuItems().Pass();
1128 1117
1129 return id_to_item_controller_map_[item.id]->GetApplicationList(event_flags); 1118 return id_to_item_controller_map_[item.id]->GetApplicationList(event_flags);
1130 } 1119 }
1131 1120
1132 std::vector<content::WebContents*> 1121 std::vector<content::WebContents*>
1133 ChromeLauncherControllerPerApp::GetV1ApplicationsFromAppId( 1122 ChromeLauncherController::GetV1ApplicationsFromAppId(std::string app_id) {
1134 std::string app_id) {
1135 ash::LauncherID id = GetLauncherIDForAppID(app_id); 1123 ash::LauncherID id = GetLauncherIDForAppID(app_id);
1136 1124
1137 // If there is no such an item pinned to the launcher, no menu gets created. 1125 // If there is no such an item pinned to the launcher, no menu gets created.
1138 if (id) { 1126 if (id) {
1139 LauncherItemController* controller = id_to_item_controller_map_[id]; 1127 LauncherItemController* controller = id_to_item_controller_map_[id];
1140 DCHECK(controller); 1128 DCHECK(controller);
1141 if (controller->type() == LauncherItemController::TYPE_SHORTCUT) 1129 if (controller->type() == LauncherItemController::TYPE_SHORTCUT)
1142 return GetV1ApplicationsFromController(controller); 1130 return GetV1ApplicationsFromController(controller);
1143 } 1131 }
1144 return std::vector<content::WebContents*>(); 1132 return std::vector<content::WebContents*>();
1145 } 1133 }
1146 1134
1147 void ChromeLauncherControllerPerApp::ActivateShellApp( 1135 void ChromeLauncherController::ActivateShellApp(const std::string& app_id,
1148 const std::string& app_id, 1136 int index) {
1149 int index) {
1150 ash::LauncherID id = GetLauncherIDForAppID(app_id); 1137 ash::LauncherID id = GetLauncherIDForAppID(app_id);
1151 if (id) { 1138 if (id) {
1152 LauncherItemController* controller = id_to_item_controller_map_[id]; 1139 LauncherItemController* controller = id_to_item_controller_map_[id];
1153 if (controller->type() == LauncherItemController::TYPE_APP) { 1140 if (controller->type() == LauncherItemController::TYPE_APP) {
1154 ShellWindowLauncherItemController* shell_window_controller = 1141 ShellWindowLauncherItemController* shell_window_controller =
1155 static_cast<ShellWindowLauncherItemController*>(controller); 1142 static_cast<ShellWindowLauncherItemController*>(controller);
1156 shell_window_controller->ActivateIndexedApp(index); 1143 shell_window_controller->ActivateIndexedApp(index);
1157 } 1144 }
1158 } 1145 }
1159 } 1146 }
1160 1147
1161 bool ChromeLauncherControllerPerApp::IsWebContentHandledByApplication( 1148 bool ChromeLauncherController::IsWebContentHandledByApplication(
1162 content::WebContents* web_contents, 1149 content::WebContents* web_contents,
1163 const std::string& app_id) { 1150 const std::string& app_id) {
1164 if ((web_contents_to_app_id_.find(web_contents) != 1151 if ((web_contents_to_app_id_.find(web_contents) !=
1165 web_contents_to_app_id_.end()) && 1152 web_contents_to_app_id_.end()) &&
1166 (web_contents_to_app_id_[web_contents] == app_id)) 1153 (web_contents_to_app_id_[web_contents] == app_id))
1167 return true; 1154 return true;
1168 return (app_id == kGmailAppId && ContentCanBeHandledByGmailApp(web_contents)); 1155 return (app_id == kGmailAppId && ContentCanBeHandledByGmailApp(web_contents));
1169 } 1156 }
1170 1157
1171 bool ChromeLauncherControllerPerApp::ContentCanBeHandledByGmailApp( 1158 bool ChromeLauncherController::ContentCanBeHandledByGmailApp(
1172 content::WebContents* web_contents) { 1159 content::WebContents* web_contents) {
1173 ash::LauncherID id = GetLauncherIDForAppID(kGmailAppId); 1160 ash::LauncherID id = GetLauncherIDForAppID(kGmailAppId);
1174 if (id) { 1161 if (id) {
1175 const GURL url = web_contents->GetURL(); 1162 const GURL url = web_contents->GetURL();
1176 // We need to extend the application matching for the gMail app beyond the 1163 // We need to extend the application matching for the gMail app beyond the
1177 // manifest file's specification. This is required because of the namespace 1164 // manifest file's specification. This is required because of the namespace
1178 // overlap with the offline app ("/mail/mu/"). 1165 // overlap with the offline app ("/mail/mu/").
1179 if (!MatchPattern(url.path(), "/mail/mu/*") && 1166 if (!MatchPattern(url.path(), "/mail/mu/*") &&
1180 MatchPattern(url.path(), "/mail/*") && 1167 MatchPattern(url.path(), "/mail/*") &&
1181 GetExtensionForAppID(kGmailAppId) && 1168 GetExtensionForAppID(kGmailAppId) &&
1182 GetExtensionForAppID(kGmailAppId)->OverlapsWithOrigin(url)) 1169 GetExtensionForAppID(kGmailAppId)->OverlapsWithOrigin(url))
1183 return true; 1170 return true;
1184 } 1171 }
1185 return false; 1172 return false;
1186 } 1173 }
1187 1174
1188 gfx::Image ChromeLauncherControllerPerApp::GetAppListIcon( 1175 gfx::Image ChromeLauncherController::GetAppListIcon(
1189 content::WebContents* web_contents) const { 1176 content::WebContents* web_contents) const {
1190 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1177 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1191 if (IsIncognito(web_contents)) 1178 if (IsIncognito(web_contents))
1192 return rb.GetImageNamed(IDR_AURA_LAUNCHER_LIST_INCOGNITO_BROWSER); 1179 return rb.GetImageNamed(IDR_AURA_LAUNCHER_LIST_INCOGNITO_BROWSER);
1193 FaviconTabHelper* favicon_tab_helper = 1180 FaviconTabHelper* favicon_tab_helper =
1194 FaviconTabHelper::FromWebContents(web_contents); 1181 FaviconTabHelper::FromWebContents(web_contents);
1195 gfx::Image result = favicon_tab_helper->GetFavicon(); 1182 gfx::Image result = favicon_tab_helper->GetFavicon();
1196 if (result.IsEmpty()) 1183 if (result.IsEmpty())
1197 return rb.GetImageNamed(IDR_DEFAULT_FAVICON); 1184 return rb.GetImageNamed(IDR_DEFAULT_FAVICON);
1198 return result; 1185 return result;
1199 } 1186 }
1200 1187
1201 string16 ChromeLauncherControllerPerApp::GetAppListTitle( 1188 string16 ChromeLauncherController::GetAppListTitle(
1202 content::WebContents* web_contents) const { 1189 content::WebContents* web_contents) const {
1203 string16 title = web_contents->GetTitle(); 1190 string16 title = web_contents->GetTitle();
1204 if (!title.empty()) 1191 if (!title.empty())
1205 return title; 1192 return title;
1206 WebContentsToAppIDMap::const_iterator iter = 1193 WebContentsToAppIDMap::const_iterator iter =
1207 web_contents_to_app_id_.find(web_contents); 1194 web_contents_to_app_id_.find(web_contents);
1208 if (iter != web_contents_to_app_id_.end()) { 1195 if (iter != web_contents_to_app_id_.end()) {
1209 std::string app_id = iter->second; 1196 std::string app_id = iter->second;
1210 const extensions::Extension* extension = GetExtensionForAppID(app_id); 1197 const extensions::Extension* extension = GetExtensionForAppID(app_id);
1211 if (extension) 1198 if (extension)
1212 return UTF8ToUTF16(extension->name()); 1199 return UTF8ToUTF16(extension->name());
1213 } 1200 }
1214 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); 1201 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE);
1215 } 1202 }
1216 1203
1217 void ChromeLauncherControllerPerApp::OnBrowserRemoved(Browser* browser) { 1204 void ChromeLauncherController::OnBrowserRemoved(Browser* browser) {
1218 // When called by a unit test it is possible that there is no shell. 1205 // When called by a unit test it is possible that there is no shell.
1219 // In that case, the following function should not get called. 1206 // In that case, the following function should not get called.
1220 if (ash::Shell::HasInstance()) 1207 if (ash::Shell::HasInstance())
1221 UpdateBrowserItemStatus(); 1208 UpdateBrowserItemStatus();
1222 } 1209 }
1223 1210
1224 ash::LauncherID ChromeLauncherControllerPerApp::CreateAppShortcutLauncherItem( 1211 ash::LauncherID ChromeLauncherController::CreateAppShortcutLauncherItem(
1225 const std::string& app_id, 1212 const std::string& app_id,
1226 int index) { 1213 int index) {
1227 return CreateAppShortcutLauncherItemWithType(app_id, 1214 return CreateAppShortcutLauncherItemWithType(app_id,
1228 index, 1215 index,
1229 ash::TYPE_APP_SHORTCUT); 1216 ash::TYPE_APP_SHORTCUT);
1230 } 1217 }
1231 1218
1232 void ChromeLauncherControllerPerApp::SetAppTabHelperForTest( 1219 void ChromeLauncherController::SetAppTabHelperForTest(AppTabHelper* helper) {
1233 AppTabHelper* helper) {
1234 app_tab_helper_.reset(helper); 1220 app_tab_helper_.reset(helper);
1235 } 1221 }
1236 1222
1237 void ChromeLauncherControllerPerApp::SetAppIconLoaderForTest( 1223 void ChromeLauncherController::SetAppIconLoaderForTest(
1238 extensions::AppIconLoader* loader) { 1224 extensions::AppIconLoader* loader) {
1239 app_icon_loader_.reset(loader); 1225 app_icon_loader_.reset(loader);
1240 } 1226 }
1241 1227
1242 const std::string& 1228 const std::string& ChromeLauncherController::GetAppIdFromLauncherIdForTest(
1243 ChromeLauncherControllerPerApp::GetAppIdFromLauncherIdForTest(
1244 ash::LauncherID id) { 1229 ash::LauncherID id) {
1245 return id_to_item_controller_map_[id]->app_id(); 1230 return id_to_item_controller_map_[id]->app_id();
1246 } 1231 }
1247 1232
1248 ash::LauncherID 1233 ash::LauncherID ChromeLauncherController::CreateAppShortcutLauncherItemWithType(
1249 ChromeLauncherControllerPerApp::CreateAppShortcutLauncherItemWithType(
1250 const std::string& app_id, 1234 const std::string& app_id,
1251 int index, 1235 int index,
1252 ash::LauncherItemType launcher_item_type) { 1236 ash::LauncherItemType launcher_item_type) {
1253 AppShortcutLauncherItemController* controller = 1237 AppShortcutLauncherItemController* controller =
1254 new AppShortcutLauncherItemController(app_id, this); 1238 new AppShortcutLauncherItemController(app_id, this);
1255 ash::LauncherID launcher_id = InsertAppLauncherItem( 1239 ash::LauncherID launcher_id = InsertAppLauncherItem(
1256 controller, app_id, ash::STATUS_CLOSED, index, launcher_item_type); 1240 controller, app_id, ash::STATUS_CLOSED, index, launcher_item_type);
1257 return launcher_id; 1241 return launcher_id;
1258 } 1242 }
1259 1243
1260 void ChromeLauncherControllerPerApp::UpdateBrowserItemStatus() { 1244 void ChromeLauncherController::UpdateBrowserItemStatus() {
1261 // Determine the new browser's active state and change if necessary. 1245 // Determine the new browser's active state and change if necessary.
1262 size_t browser_index = ash::launcher::GetBrowserItemIndex(*model_); 1246 size_t browser_index = ash::launcher::GetBrowserItemIndex(*model_);
1263 DCHECK_GE(browser_index, 0u); 1247 DCHECK_GE(browser_index, 0u);
1264 ash::LauncherItem browser_item = model_->items()[browser_index]; 1248 ash::LauncherItem browser_item = model_->items()[browser_index];
1265 ash::LauncherItemStatus browser_status = ash::STATUS_CLOSED; 1249 ash::LauncherItemStatus browser_status = ash::STATUS_CLOSED;
1266 1250
1267 aura::Window* window = ash::wm::GetActiveWindow(); 1251 aura::Window* window = ash::wm::GetActiveWindow();
1268 if (window) { 1252 if (window) {
1269 // Check if the active browser / tab is a browser which is not an app, 1253 // Check if the active browser / tab is a browser which is not an app,
1270 // a windowed app, a popup or any other item which is not a browser of 1254 // a windowed app, a popup or any other item which is not a browser of
(...skipping 22 matching lines...) Expand all
1293 browser_status = ash::STATUS_RUNNING; 1277 browser_status = ash::STATUS_RUNNING;
1294 } 1278 }
1295 } 1279 }
1296 1280
1297 if (browser_status != browser_item.status) { 1281 if (browser_status != browser_item.status) {
1298 browser_item.status = browser_status; 1282 browser_item.status = browser_status;
1299 model_->Set(browser_index, browser_item); 1283 model_->Set(browser_index, browser_item);
1300 } 1284 }
1301 } 1285 }
1302 1286
1303 Profile* ChromeLauncherControllerPerApp::GetProfileForNewWindows() { 1287 Profile* ChromeLauncherController::GetProfileForNewWindows() {
1304 return ProfileManager::GetDefaultProfileOrOffTheRecord(); 1288 return ProfileManager::GetDefaultProfileOrOffTheRecord();
1305 } 1289 }
1306 1290
1307 void ChromeLauncherControllerPerApp::LauncherItemClosed(ash::LauncherID id) { 1291 void ChromeLauncherController::LauncherItemClosed(ash::LauncherID id) {
1308 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 1292 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
1309 CHECK(iter != id_to_item_controller_map_.end()); 1293 CHECK(iter != id_to_item_controller_map_.end());
1310 CHECK(iter->second); 1294 CHECK(iter->second);
1311 app_icon_loader_->ClearImage(iter->second->app_id()); 1295 app_icon_loader_->ClearImage(iter->second->app_id());
1312 iter->second->OnRemoved(); 1296 iter->second->OnRemoved();
1313 id_to_item_controller_map_.erase(iter); 1297 id_to_item_controller_map_.erase(iter);
1314 int index = model_->ItemIndexByID(id); 1298 int index = model_->ItemIndexByID(id);
1315 // A "browser proxy" is not known to the model and this removal does 1299 // A "browser proxy" is not known to the model and this removal does
1316 // therefore not need to be propagated to the model. 1300 // therefore not need to be propagated to the model.
1317 if (index != -1) 1301 if (index != -1)
1318 model_->RemoveItemAt(index); 1302 model_->RemoveItemAt(index);
1319 } 1303 }
1320 1304
1321 void ChromeLauncherControllerPerApp::DoPinAppWithID( 1305 void ChromeLauncherController::DoPinAppWithID(const std::string& app_id) {
1322 const std::string& app_id) {
1323 // If there is an item, do nothing and return. 1306 // If there is an item, do nothing and return.
1324 if (IsAppPinned(app_id)) 1307 if (IsAppPinned(app_id))
1325 return; 1308 return;
1326 1309
1327 ash::LauncherID launcher_id = GetLauncherIDForAppID(app_id); 1310 ash::LauncherID launcher_id = GetLauncherIDForAppID(app_id);
1328 if (launcher_id) { 1311 if (launcher_id) {
1329 // App item exists, pin it 1312 // App item exists, pin it
1330 Pin(launcher_id); 1313 Pin(launcher_id);
1331 } else { 1314 } else {
1332 // Otherwise, create a shortcut item for it. 1315 // Otherwise, create a shortcut item for it.
1333 CreateAppShortcutLauncherItem(app_id, model_->item_count()); 1316 CreateAppShortcutLauncherItem(app_id, model_->item_count());
1334 if (CanPin()) 1317 if (CanPin())
1335 PersistPinnedState(); 1318 PersistPinnedState();
1336 } 1319 }
1337 } 1320 }
1338 1321
1339 void ChromeLauncherControllerPerApp::DoUnpinAppsWithID( 1322 void ChromeLauncherController::DoUnpinAppsWithID(const std::string& app_id) {
1340 const std::string& app_id) {
1341 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); 1323 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin();
1342 i != id_to_item_controller_map_.end(); ) { 1324 i != id_to_item_controller_map_.end(); ) {
1343 IDToItemControllerMap::iterator current(i); 1325 IDToItemControllerMap::iterator current(i);
1344 ++i; 1326 ++i;
1345 if (current->second->app_id() == app_id && IsPinned(current->first)) 1327 if (current->second->app_id() == app_id && IsPinned(current->first))
1346 Unpin(current->first); 1328 Unpin(current->first);
1347 } 1329 }
1348 } 1330 }
1349 1331
1350 void ChromeLauncherControllerPerApp::UpdateAppLaunchersFromPref() { 1332 void ChromeLauncherController::UpdateAppLaunchersFromPref() {
1351 // Construct a vector representation of to-be-pinned apps from the pref. 1333 // Construct a vector representation of to-be-pinned apps from the pref.
1352 std::vector<std::string> pinned_apps; 1334 std::vector<std::string> pinned_apps;
1353 int chrome_icon_index = GetChromeIconIndexFromPref(); 1335 int chrome_icon_index = GetChromeIconIndexFromPref();
1354 int index = 0; 1336 int index = 0;
1355 int max_index = model_->item_count(); 1337 int max_index = model_->item_count();
1356 // Using the alternate shelf layout the App Icon should be the first item in 1338 // Using the alternate shelf layout the App Icon should be the first item in
1357 // the list thus start adding items at slot 1 (instead of slot 0). 1339 // the list thus start adding items at slot 1 (instead of slot 0).
1358 if (ash::switches::UseAlternateShelfLayout()) { 1340 if (ash::switches::UseAlternateShelfLayout()) {
1359 ++index; 1341 ++index;
1360 ++max_index; 1342 ++max_index;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 1426
1445 // Append unprocessed items from the pref to the end of the model. 1427 // Append unprocessed items from the pref to the end of the model.
1446 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) { 1428 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) {
1447 // Ignore the chrome icon. 1429 // Ignore the chrome icon.
1448 if (*pref_app_id != extension_misc::kChromeAppId) 1430 if (*pref_app_id != extension_misc::kChromeAppId)
1449 DoPinAppWithID(*pref_app_id); 1431 DoPinAppWithID(*pref_app_id);
1450 } 1432 }
1451 1433
1452 } 1434 }
1453 1435
1454 void ChromeLauncherControllerPerApp::SetShelfAutoHideBehaviorPrefs( 1436 void ChromeLauncherController::SetShelfAutoHideBehaviorPrefs(
1455 ash::ShelfAutoHideBehavior behavior, 1437 ash::ShelfAutoHideBehavior behavior,
1456 aura::RootWindow* root_window) { 1438 aura::RootWindow* root_window) {
1457 const char* value = NULL; 1439 const char* value = NULL;
1458 switch (behavior) { 1440 switch (behavior) {
1459 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: 1441 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS:
1460 value = ash::kShelfAutoHideBehaviorAlways; 1442 value = ash::kShelfAutoHideBehaviorAlways;
1461 break; 1443 break;
1462 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER: 1444 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER:
1463 value = ash::kShelfAutoHideBehaviorNever; 1445 value = ash::kShelfAutoHideBehaviorNever;
1464 break; 1446 break;
1465 case ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN: 1447 case ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN:
1466 // This one should not be a valid preference option for now. We only want 1448 // This one should not be a valid preference option for now. We only want
1467 // to completely hide it when we run app mode. 1449 // to completely hide it when we run app mode.
1468 NOTREACHED(); 1450 NOTREACHED();
1469 return; 1451 return;
1470 } 1452 }
1471 1453
1472 UpdatePerDisplayPref( 1454 UpdatePerDisplayPref(
1473 profile_->GetPrefs(), root_window, prefs::kShelfAutoHideBehavior, value); 1455 profile_->GetPrefs(), root_window, prefs::kShelfAutoHideBehavior, value);
1474 1456
1475 if (root_window == ash::Shell::GetPrimaryRootWindow()) { 1457 if (root_window == ash::Shell::GetPrimaryRootWindow()) {
1476 // See comment in |kShelfAlignment| about why we have two prefs here. 1458 // See comment in |kShelfAlignment| about why we have two prefs here.
1477 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value); 1459 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value);
1478 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value); 1460 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value);
1479 } 1461 }
1480 } 1462 }
1481 1463
1482 void ChromeLauncherControllerPerApp::SetShelfAutoHideBehaviorFromPrefs() { 1464 void ChromeLauncherController::SetShelfAutoHideBehaviorFromPrefs() {
1483 ash::Shell::RootWindowList root_windows = ash::Shell::GetAllRootWindows(); 1465 ash::Shell::RootWindowList root_windows = ash::Shell::GetAllRootWindows();
1484 1466
1485 for (ash::Shell::RootWindowList::const_iterator iter = root_windows.begin(); 1467 for (ash::Shell::RootWindowList::const_iterator iter = root_windows.begin();
1486 iter != root_windows.end(); ++iter) { 1468 iter != root_windows.end(); ++iter) {
1487 ash::Shell::GetInstance()->SetShelfAutoHideBehavior( 1469 ash::Shell::GetInstance()->SetShelfAutoHideBehavior(
1488 GetShelfAutoHideBehavior(*iter), *iter); 1470 GetShelfAutoHideBehavior(*iter), *iter);
1489 } 1471 }
1490 } 1472 }
1491 1473
1492 void ChromeLauncherControllerPerApp::SetShelfAlignmentFromPrefs() { 1474 void ChromeLauncherController::SetShelfAlignmentFromPrefs() {
1493 if (!ash::ShelfWidget::ShelfAlignmentAllowed()) 1475 if (!ash::ShelfWidget::ShelfAlignmentAllowed())
1494 return; 1476 return;
1495 1477
1496 ash::Shell::RootWindowList root_windows = ash::Shell::GetAllRootWindows(); 1478 ash::Shell::RootWindowList root_windows = ash::Shell::GetAllRootWindows();
1497 1479
1498 for (ash::Shell::RootWindowList::const_iterator iter = root_windows.begin(); 1480 for (ash::Shell::RootWindowList::const_iterator iter = root_windows.begin();
1499 iter != root_windows.end(); ++iter) { 1481 iter != root_windows.end(); ++iter) {
1500 // See comment in |kShelfAlignment| as to why we consider two prefs. 1482 // See comment in |kShelfAlignment| as to why we consider two prefs.
1501 const std::string alignment_value( 1483 const std::string alignment_value(
1502 GetPrefForRootWindow(profile_->GetPrefs(), 1484 GetPrefForRootWindow(profile_->GetPrefs(),
1503 *iter, 1485 *iter,
1504 prefs::kShelfAlignmentLocal, 1486 prefs::kShelfAlignmentLocal,
1505 prefs::kShelfAlignment)); 1487 prefs::kShelfAlignment));
1506 ash::ShelfAlignment alignment = ash::SHELF_ALIGNMENT_BOTTOM; 1488 ash::ShelfAlignment alignment = ash::SHELF_ALIGNMENT_BOTTOM;
1507 if (alignment_value == ash::kShelfAlignmentLeft) 1489 if (alignment_value == ash::kShelfAlignmentLeft)
1508 alignment = ash::SHELF_ALIGNMENT_LEFT; 1490 alignment = ash::SHELF_ALIGNMENT_LEFT;
1509 else if (alignment_value == ash::kShelfAlignmentRight) 1491 else if (alignment_value == ash::kShelfAlignmentRight)
1510 alignment = ash::SHELF_ALIGNMENT_RIGHT; 1492 alignment = ash::SHELF_ALIGNMENT_RIGHT;
1511 else if (alignment_value == ash::kShelfAlignmentTop) 1493 else if (alignment_value == ash::kShelfAlignmentTop)
1512 alignment = ash::SHELF_ALIGNMENT_TOP; 1494 alignment = ash::SHELF_ALIGNMENT_TOP;
1513 ash::Shell::GetInstance()->SetShelfAlignment(alignment, *iter); 1495 ash::Shell::GetInstance()->SetShelfAlignment(alignment, *iter);
1514 } 1496 }
1515 } 1497 }
1516 1498
1517 void ChromeLauncherControllerPerApp::SetShelfBehaviorsFromPrefs() { 1499 void ChromeLauncherController::SetShelfBehaviorsFromPrefs() {
1518 SetShelfAutoHideBehaviorFromPrefs(); 1500 SetShelfAutoHideBehaviorFromPrefs();
1519 SetShelfAlignmentFromPrefs(); 1501 SetShelfAlignmentFromPrefs();
1520 } 1502 }
1521 1503
1522 WebContents* ChromeLauncherControllerPerApp::GetLastActiveWebContents( 1504 WebContents* ChromeLauncherController::GetLastActiveWebContents(
1523 const std::string& app_id) { 1505 const std::string& app_id) {
1524 AppIDToWebContentsListMap::const_iterator i = 1506 AppIDToWebContentsListMap::const_iterator i =
1525 app_id_to_web_contents_list_.find(app_id); 1507 app_id_to_web_contents_list_.find(app_id);
1526 if (i == app_id_to_web_contents_list_.end()) 1508 if (i == app_id_to_web_contents_list_.end())
1527 return NULL; 1509 return NULL;
1528 DCHECK_GT(i->second.size(), 0u); 1510 DCHECK_GT(i->second.size(), 0u);
1529 return *i->second.begin(); 1511 return *i->second.begin();
1530 } 1512 }
1531 1513
1532 ash::LauncherID ChromeLauncherControllerPerApp::InsertAppLauncherItem( 1514 ash::LauncherID ChromeLauncherController::InsertAppLauncherItem(
1533 LauncherItemController* controller, 1515 LauncherItemController* controller,
1534 const std::string& app_id, 1516 const std::string& app_id,
1535 ash::LauncherItemStatus status, 1517 ash::LauncherItemStatus status,
1536 int index, 1518 int index,
1537 ash::LauncherItemType launcher_item_type) { 1519 ash::LauncherItemType launcher_item_type) {
1538 ash::LauncherID id = model_->next_id(); 1520 ash::LauncherID id = model_->next_id();
1539 CHECK(!HasItemController(id)); 1521 CHECK(!HasItemController(id));
1540 CHECK(controller); 1522 CHECK(controller);
1541 id_to_item_controller_map_[id] = controller; 1523 id_to_item_controller_map_[id] = controller;
1542 controller->set_launcher_id(id); 1524 controller->set_launcher_id(id);
(...skipping 14 matching lines...) Expand all
1557 } 1539 }
1558 item.status = status; 1540 item.status = status;
1559 1541
1560 model_->AddAt(index, item); 1542 model_->AddAt(index, item);
1561 1543
1562 app_icon_loader_->FetchImage(app_id); 1544 app_icon_loader_->FetchImage(app_id);
1563 1545
1564 return id; 1546 return id;
1565 } 1547 }
1566 1548
1567 bool ChromeLauncherControllerPerApp::HasItemController( 1549 bool ChromeLauncherController::HasItemController(ash::LauncherID id) const {
1568 ash::LauncherID id) const {
1569 return id_to_item_controller_map_.find(id) != 1550 return id_to_item_controller_map_.find(id) !=
1570 id_to_item_controller_map_.end(); 1551 id_to_item_controller_map_.end();
1571 } 1552 }
1572 1553
1573 std::vector<content::WebContents*> 1554 std::vector<content::WebContents*>
1574 ChromeLauncherControllerPerApp::GetV1ApplicationsFromController( 1555 ChromeLauncherController::GetV1ApplicationsFromController(
1575 LauncherItemController* controller) { 1556 LauncherItemController* controller) {
1576 DCHECK(controller->type() == LauncherItemController::TYPE_SHORTCUT); 1557 DCHECK(controller->type() == LauncherItemController::TYPE_SHORTCUT);
1577 AppShortcutLauncherItemController* app_controller = 1558 AppShortcutLauncherItemController* app_controller =
1578 static_cast<AppShortcutLauncherItemController*>(controller); 1559 static_cast<AppShortcutLauncherItemController*>(controller);
1579 return app_controller->GetRunningApplications(); 1560 return app_controller->GetRunningApplications();
1580 } 1561 }
1581 1562
1582 bool ChromeLauncherControllerPerApp::IsBrowserRepresentedInBrowserList( 1563 bool ChromeLauncherController::IsBrowserRepresentedInBrowserList(
1583 Browser* browser) { 1564 Browser* browser) {
1584 return (browser && 1565 return (browser &&
1585 (browser->is_type_tabbed() || 1566 (browser->is_type_tabbed() ||
1586 !browser->is_app() || 1567 !browser->is_app() ||
1587 !browser->is_type_popup() || 1568 !browser->is_type_popup() ||
1588 GetLauncherIDForAppID(web_app::GetExtensionIdFromApplicationName( 1569 GetLauncherIDForAppID(web_app::GetExtensionIdFromApplicationName(
1589 browser->app_name())) <= 0)); 1570 browser->app_name())) <= 0));
1590 } 1571 }
1591 1572
1592 LauncherItemController* 1573 LauncherItemController*
1593 ChromeLauncherControllerPerApp::GetBrowserShortcutLauncherItemController() { 1574 ChromeLauncherController::GetBrowserShortcutLauncherItemController() {
1594 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); 1575 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin();
1595 i != id_to_item_controller_map_.end(); ++i) { 1576 i != id_to_item_controller_map_.end(); ++i) {
1596 int index = model_->ItemIndexByID(i->first); 1577 int index = model_->ItemIndexByID(i->first);
1597 const ash::LauncherItem& item = model_->items()[index]; 1578 const ash::LauncherItem& item = model_->items()[index];
1598 if (item.type == ash::TYPE_BROWSER_SHORTCUT) 1579 if (item.type == ash::TYPE_BROWSER_SHORTCUT)
1599 return i->second; 1580 return i->second;
1600 } 1581 }
1601 // LauncerItemController For Browser Shortcut must be existed. If it does not 1582 // LauncerItemController For Browser Shortcut must be existed. If it does not
1602 // existe create it. 1583 // existe create it.
1603 ash::LauncherID id = CreateBrowserShortcutLauncherItem(); 1584 ash::LauncherID id = CreateBrowserShortcutLauncherItem();
1604 DCHECK(id_to_item_controller_map_[id]); 1585 DCHECK(id_to_item_controller_map_[id]);
1605 return id_to_item_controller_map_[id]; 1586 return id_to_item_controller_map_[id];
1606 } 1587 }
1607 1588
1608 ash::LauncherID 1589 ash::LauncherID ChromeLauncherController::CreateBrowserShortcutLauncherItem() {
1609 ChromeLauncherControllerPerApp::CreateBrowserShortcutLauncherItem() {
1610 ash::LauncherItem browser_shortcut; 1590 ash::LauncherItem browser_shortcut;
1611 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; 1591 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT;
1612 browser_shortcut.is_incognito = false; 1592 browser_shortcut.is_incognito = false;
1613 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1593 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1614 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); 1594 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32);
1615 ash::LauncherID id = model_->next_id(); 1595 ash::LauncherID id = model_->next_id();
1616 size_t index = GetChromeIconIndexFromPref(); 1596 size_t index = GetChromeIconIndexFromPref();
1617 model_->AddAt(index, browser_shortcut); 1597 model_->AddAt(index, browser_shortcut);
1618 browser_item_controller_.reset( 1598 browser_item_controller_.reset(
1619 new BrowserShortcutLauncherItemController(this, profile_)); 1599 new BrowserShortcutLauncherItemController(this, profile_));
1620 id_to_item_controller_map_[id] = browser_item_controller_.get(); 1600 id_to_item_controller_map_[id] = browser_item_controller_.get();
1621 id_to_item_controller_map_[id]->set_launcher_id(id); 1601 id_to_item_controller_map_[id]->set_launcher_id(id);
1622 return id; 1602 return id;
1623 } 1603 }
1624 1604
1625 void ChromeLauncherControllerPerApp::PersistChromeItemIndex(int index) { 1605 void ChromeLauncherController::PersistChromeItemIndex(int index) {
1626 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index); 1606 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index);
1627 } 1607 }
1628 1608
1629 int ChromeLauncherControllerPerApp::GetChromeIconIndexFromPref() const { 1609 int ChromeLauncherController::GetChromeIconIndexFromPref() const {
1630 size_t index = profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex); 1610 size_t index = profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex);
1631 const base::ListValue* pinned_apps_pref = 1611 const base::ListValue* pinned_apps_pref =
1632 profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps); 1612 profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps);
1633 if (ash::switches::UseAlternateShelfLayout()) 1613 if (ash::switches::UseAlternateShelfLayout())
1634 return std::max(static_cast<size_t>(1), 1614 return std::max(static_cast<size_t>(1),
1635 std::min(pinned_apps_pref->GetSize() + 1, index)); 1615 std::min(pinned_apps_pref->GetSize() + 1, index));
1636 return std::max(static_cast<size_t>(0), 1616 return std::max(static_cast<size_t>(0),
1637 std::min(pinned_apps_pref->GetSize(), index)); 1617 std::min(pinned_apps_pref->GetSize(), index));
1638 } 1618 }
1639 1619
1640 bool ChromeLauncherControllerPerApp::IsIncognito( 1620 bool ChromeLauncherController::IsIncognito(
1641 content::WebContents* web_contents) const { 1621 content::WebContents* web_contents) const {
1642 const Profile* profile = 1622 const Profile* profile =
1643 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 1623 Profile::FromBrowserContext(web_contents->GetBrowserContext());
1644 return profile->IsOffTheRecord() && !profile->IsGuestSession(); 1624 return profile->IsOffTheRecord() && !profile->IsGuestSession();
1645 } 1625 }
1646 1626
1647 void ChromeLauncherControllerPerApp::CloseWindowedAppsFromRemovedExtension( 1627 void ChromeLauncherController::CloseWindowedAppsFromRemovedExtension(
1648 const std::string& app_id) { 1628 const std::string& app_id) {
1649 // This function cannot rely on the controller's enumeration functionality 1629 // This function cannot rely on the controller's enumeration functionality
1650 // since the extension has already be unloaded. 1630 // since the extension has already be unloaded.
1651 const BrowserList* ash_browser_list = 1631 const BrowserList* ash_browser_list =
1652 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); 1632 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
1653 std::vector<Browser*> browser_to_close; 1633 std::vector<Browser*> browser_to_close;
1654 for (BrowserList::const_reverse_iterator 1634 for (BrowserList::const_reverse_iterator
1655 it = ash_browser_list->begin_last_active(); 1635 it = ash_browser_list->begin_last_active();
1656 it != ash_browser_list->end_last_active(); ++it) { 1636 it != ash_browser_list->end_last_active(); ++it) {
1657 Browser* browser = *it; 1637 Browser* browser = *it;
1658 if (!browser->is_type_tabbed() && 1638 if (!browser->is_type_tabbed() &&
1659 browser->is_type_popup() && 1639 browser->is_type_popup() &&
1660 browser->is_app() && 1640 browser->is_app() &&
1661 app_id == web_app::GetExtensionIdFromApplicationName( 1641 app_id == web_app::GetExtensionIdFromApplicationName(
1662 browser->app_name())) { 1642 browser->app_name())) {
1663 browser_to_close.push_back(browser); 1643 browser_to_close.push_back(browser);
1664 } 1644 }
1665 } 1645 }
1666 while (!browser_to_close.empty()) { 1646 while (!browser_to_close.empty()) {
1667 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model(); 1647 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model();
1668 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); 1648 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE);
1669 browser_to_close.pop_back(); 1649 browser_to_close.pop_back();
1670 } 1650 }
1671 } 1651 }
1672 1652
1673 void 1653 void
1674 ChromeLauncherControllerPerApp::MoveItemWithoutPinnedStateChangeNotification( 1654 ChromeLauncherController::MoveItemWithoutPinnedStateChangeNotification(
1675 int source_index, int target_index) { 1655 int source_index, int target_index) {
1676 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); 1656 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true);
1677 model_->Move(source_index, target_index); 1657 model_->Move(source_index, target_index);
1678 } 1658 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698