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

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

Issue 11451019: Remove TabContents from ui/ash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 8 years 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/launcher/launcher_model.h" 9 #include "ash/launcher/launcher_model.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/ui/ash/launcher/launcher_app_icon_loader.h" 24 #include "chrome/browser/ui/ash/launcher/launcher_app_icon_loader.h"
25 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h" 25 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h"
26 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" 26 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
27 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" 27 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
28 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h" 28 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h"
29 #include "chrome/browser/ui/browser.h" 29 #include "chrome/browser/ui/browser.h"
30 #include "chrome/browser/ui/browser_commands.h" 30 #include "chrome/browser/ui/browser_commands.h"
31 #include "chrome/browser/ui/browser_finder.h" 31 #include "chrome/browser/ui/browser_finder.h"
32 #include "chrome/browser/ui/browser_tabstrip.h" 32 #include "chrome/browser/ui/browser_tabstrip.h"
33 #include "chrome/browser/ui/browser_window.h" 33 #include "chrome/browser/ui/browser_window.h"
34 #include "chrome/browser/ui/tab_contents/tab_contents.h"
35 #include "chrome/browser/ui/tabs/tab_strip_model.h" 34 #include "chrome/browser/ui/tabs/tab_strip_model.h"
36 #include "chrome/browser/web_applications/web_app.h" 35 #include "chrome/browser/web_applications/web_app.h"
37 #include "chrome/common/chrome_notification_types.h" 36 #include "chrome/common/chrome_notification_types.h"
38 #include "chrome/common/chrome_switches.h" 37 #include "chrome/common/chrome_switches.h"
39 #include "chrome/common/extensions/extension.h" 38 #include "chrome/common/extensions/extension.h"
40 #include "chrome/common/extensions/extension_resource.h" 39 #include "chrome/common/extensions/extension_resource.h"
41 #include "chrome/common/pref_names.h" 40 #include "chrome/common/pref_names.h"
42 #include "chrome/common/url_constants.h" 41 #include "chrome/common/url_constants.h"
43 #include "content/public/browser/navigation_entry.h" 42 #include "content/public/browser/navigation_entry.h"
44 #include "content/public/browser/notification_service.h" 43 #include "content/public/browser/notification_service.h"
45 #include "content/public/browser/web_contents.h" 44 #include "content/public/browser/web_contents.h"
46 #include "extensions/common/url_pattern.h" 45 #include "extensions/common/url_pattern.h"
47 #include "grit/theme_resources.h" 46 #include "grit/theme_resources.h"
48 #include "ui/aura/window.h" 47 #include "ui/aura/window.h"
49 48
49 using content::WebContents;
50 using extensions::Extension; 50 using extensions::Extension;
51 51
52 namespace { 52 namespace {
53 53
54 // Item controller for an app shortcut. Shortcuts track app and launcher ids, 54 // Item controller for an app shortcut. Shortcuts track app and launcher ids,
55 // but do not have any associated windows (opening a shortcut will replace the 55 // but do not have any associated windows (opening a shortcut will replace the
56 // item with the appropriate LauncherItemController type). 56 // item with the appropriate LauncherItemController type).
57 class AppShortcutLauncherItemController : public LauncherItemController { 57 class AppShortcutLauncherItemController : public LauncherItemController {
58 public: 58 public:
59 AppShortcutLauncherItemController(const std::string& app_id, 59 AppShortcutLauncherItemController(const std::string& app_id,
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 405
406 AppShortcutLauncherItemController* app_controller = 406 AppShortcutLauncherItemController* app_controller =
407 static_cast<AppShortcutLauncherItemController*>(controller); 407 static_cast<AppShortcutLauncherItemController*>(controller);
408 const GURL refocus_url = app_controller->refocus_url(); 408 const GURL refocus_url = app_controller->refocus_url();
409 409
410 if (!refocus_url.is_empty()) 410 if (!refocus_url.is_empty())
411 refocus_pattern.Parse(refocus_url.spec()); 411 refocus_pattern.Parse(refocus_url.spec());
412 } 412 }
413 413
414 // Check if there are any open tabs for this app. 414 // Check if there are any open tabs for this app.
415 AppIDToTabContentsListMap::iterator app_i = 415 AppIDToWebContentsListMap::iterator app_i =
416 app_id_to_tab_contents_list_.find(app_id); 416 app_id_to_web_contents_list_.find(app_id);
417 if (app_i != app_id_to_tab_contents_list_.end()) { 417 if (app_i != app_id_to_web_contents_list_.end()) {
418 for (TabContentsList::iterator tab_i = app_i->second.begin(); 418 for (WebContentsList::iterator tab_i = app_i->second.begin();
419 tab_i != app_i->second.end(); 419 tab_i != app_i->second.end();
420 ++tab_i) { 420 ++tab_i) {
421 TabContents* tab = *tab_i; 421 WebContents* tab = *tab_i;
422 const GURL tab_url = tab->web_contents()->GetURL(); 422 const GURL tab_url = tab->GetURL();
423 if (refocus_pattern.MatchesURL(tab_url)) { 423 if (refocus_pattern.MatchesURL(tab_url)) {
424 Browser* browser = chrome::FindBrowserWithWebContents( 424 Browser* browser = chrome::FindBrowserWithWebContents(tab);
425 tab->web_contents());
426 TabStripModel* tab_strip = browser->tab_strip_model(); 425 TabStripModel* tab_strip = browser->tab_strip_model();
427 int index = tab_strip->GetIndexOfTabContents(tab); 426 int index = tab_strip->GetIndexOfWebContents(tab);
428 DCHECK_NE(TabStripModel::kNoTab, index); 427 DCHECK_NE(TabStripModel::kNoTab, index);
429 tab_strip->ActivateTabAt(index, false); 428 tab_strip->ActivateTabAt(index, false);
430 browser->window()->Show(); 429 browser->window()->Show();
431 ash::wm::ActivateWindow(browser->window()->GetNativeWindow()); 430 ash::wm::ActivateWindow(browser->window()->GetNativeWindow());
432 return; 431 return;
433 } 432 }
434 } 433 }
435 } 434 }
436 435
437 LaunchApp(app_id, event_flags); 436 LaunchApp(app_id, event_flags);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 aura::RootWindow* root_window) { 580 aura::RootWindow* root_window) {
582 ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) == 581 ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) ==
583 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ? 582 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ?
584 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER : 583 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER :
585 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; 584 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
586 SetShelfAutoHideBehaviorPrefs(behavior, root_window); 585 SetShelfAutoHideBehaviorPrefs(behavior, root_window);
587 return; 586 return;
588 } 587 }
589 588
590 void ChromeLauncherControllerPerApp::RemoveTabFromRunningApp( 589 void ChromeLauncherControllerPerApp::RemoveTabFromRunningApp(
591 TabContents* tab, 590 WebContents* tab,
592 const std::string& app_id) { 591 const std::string& app_id) {
593 tab_contents_to_app_id_.erase(tab); 592 web_contents_to_app_id_.erase(tab);
594 AppIDToTabContentsListMap::iterator i_app_id = 593 AppIDToWebContentsListMap::iterator i_app_id =
595 app_id_to_tab_contents_list_.find(app_id); 594 app_id_to_web_contents_list_.find(app_id);
596 if (i_app_id != app_id_to_tab_contents_list_.end()) { 595 if (i_app_id != app_id_to_web_contents_list_.end()) {
597 TabContentsList* tab_list = &i_app_id->second; 596 WebContentsList* tab_list = &i_app_id->second;
598 tab_list->remove(tab); 597 tab_list->remove(tab);
599 if (tab_list->empty()) { 598 if (tab_list->empty()) {
600 app_id_to_tab_contents_list_.erase(i_app_id); 599 app_id_to_web_contents_list_.erase(i_app_id);
601 i_app_id = app_id_to_tab_contents_list_.end(); 600 i_app_id = app_id_to_web_contents_list_.end();
602 ash::LauncherID id = GetLauncherIDForAppID(app_id); 601 ash::LauncherID id = GetLauncherIDForAppID(app_id);
603 if (id > 0) 602 if (id > 0)
604 SetItemStatus(id, ash::STATUS_CLOSED); 603 SetItemStatus(id, ash::STATUS_CLOSED);
605 } 604 }
606 } 605 }
607 } 606 }
608 607
609 void ChromeLauncherControllerPerApp::UpdateAppState( 608 void ChromeLauncherControllerPerApp::UpdateAppState(
610 content::WebContents* contents, 609 content::WebContents* contents,
611 AppState app_state) { 610 AppState app_state) {
612 std::string app_id = GetAppID(contents); 611 std::string app_id = GetAppID(contents);
613 612
614 // Check the old |app_id| for a tab. If the contents has changed we need to 613 // Check the old |app_id| for a tab. If the contents has changed we need to
615 // remove it from the previous app. 614 // remove it from the previous app.
616 TabContents* tab = TabContents::FromWebContents(contents); 615 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) {
617 if (tab_contents_to_app_id_.find(tab) != tab_contents_to_app_id_.end()) { 616 std::string last_app_id = web_contents_to_app_id_[contents];
618 std::string last_app_id = tab_contents_to_app_id_[tab];
619 if (last_app_id != app_id) 617 if (last_app_id != app_id)
620 RemoveTabFromRunningApp(tab, last_app_id); 618 RemoveTabFromRunningApp(contents, last_app_id);
621 } 619 }
622 620
623 if (app_id.empty()) 621 if (app_id.empty())
624 return; 622 return;
625 623
626 tab_contents_to_app_id_[tab] = app_id; 624 web_contents_to_app_id_[contents] = app_id;
627 625
628 if (app_state == APP_STATE_REMOVED) { 626 if (app_state == APP_STATE_REMOVED) {
629 // The tab has gone away. 627 // The tab has gone away.
630 RemoveTabFromRunningApp(tab, app_id); 628 RemoveTabFromRunningApp(contents, app_id);
631 } else { 629 } else {
632 TabContentsList& tab_list(app_id_to_tab_contents_list_[app_id]); 630 WebContentsList& tab_list(app_id_to_web_contents_list_[app_id]);
633 631
634 if (app_state == APP_STATE_INACTIVE) { 632 if (app_state == APP_STATE_INACTIVE) {
635 TabContentsList::const_iterator i_tab = 633 WebContentsList::const_iterator i_tab =
636 std::find(tab_list.begin(), tab_list.end(), tab); 634 std::find(tab_list.begin(), tab_list.end(), contents);
637 if (i_tab == tab_list.end()) 635 if (i_tab == tab_list.end())
638 tab_list.push_back(tab); 636 tab_list.push_back(contents);
639 if (i_tab != tab_list.begin()) { 637 if (i_tab != tab_list.begin()) {
640 // Going inactive, but wasn't the front tab, indicating that a new 638 // Going inactive, but wasn't the front tab, indicating that a new
641 // tab has already become active. 639 // tab has already become active.
642 return; 640 return;
643 } 641 }
644 } else { 642 } else {
645 tab_list.remove(tab); 643 tab_list.remove(contents);
646 tab_list.push_front(tab); 644 tab_list.push_front(contents);
647 } 645 }
648 ash::LauncherID id = GetLauncherIDForAppID(app_id); 646 ash::LauncherID id = GetLauncherIDForAppID(app_id);
649 if (id > 0) { 647 if (id > 0) {
650 // If the window is active, mark the app as active. 648 // If the window is active, mark the app as active.
651 SetItemStatus(id, app_state == APP_STATE_WINDOW_ACTIVE ? 649 SetItemStatus(id, app_state == APP_STATE_WINDOW_ACTIVE ?
652 ash::STATUS_ACTIVE : ash::STATUS_RUNNING); 650 ash::STATUS_ACTIVE : ash::STATUS_RUNNING);
653 } 651 }
654 } 652 }
655 } 653 }
656 654
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 ash::ShelfAlignment alignment = ash::SHELF_ALIGNMENT_BOTTOM; 1016 ash::ShelfAlignment alignment = ash::SHELF_ALIGNMENT_BOTTOM;
1019 if (alignment_value == ash::kShelfAlignmentLeft) 1017 if (alignment_value == ash::kShelfAlignmentLeft)
1020 alignment = ash::SHELF_ALIGNMENT_LEFT; 1018 alignment = ash::SHELF_ALIGNMENT_LEFT;
1021 else if (alignment_value == ash::kShelfAlignmentRight) 1019 else if (alignment_value == ash::kShelfAlignmentRight)
1022 alignment = ash::SHELF_ALIGNMENT_RIGHT; 1020 alignment = ash::SHELF_ALIGNMENT_RIGHT;
1023 // TODO(oshima): Support multiple displays. 1021 // TODO(oshima): Support multiple displays.
1024 ash::Shell::GetInstance()->SetShelfAlignment( 1022 ash::Shell::GetInstance()->SetShelfAlignment(
1025 alignment, ash::Shell::GetPrimaryRootWindow()); 1023 alignment, ash::Shell::GetPrimaryRootWindow());
1026 } 1024 }
1027 1025
1028 TabContents* ChromeLauncherControllerPerApp::GetLastActiveTabContents( 1026 WebContents* ChromeLauncherControllerPerApp::GetLastActiveWebContents(
1029 const std::string& app_id) { 1027 const std::string& app_id) {
1030 AppIDToTabContentsListMap::const_iterator i = 1028 AppIDToWebContentsListMap::const_iterator i =
1031 app_id_to_tab_contents_list_.find(app_id); 1029 app_id_to_web_contents_list_.find(app_id);
1032 if (i == app_id_to_tab_contents_list_.end()) 1030 if (i == app_id_to_web_contents_list_.end())
1033 return NULL; 1031 return NULL;
1034 DCHECK_GT(i->second.size(), 0u); 1032 DCHECK_GT(i->second.size(), 0u);
1035 return *i->second.begin(); 1033 return *i->second.begin();
1036 } 1034 }
1037 1035
1038 ash::LauncherID ChromeLauncherControllerPerApp::InsertAppLauncherItem( 1036 ash::LauncherID ChromeLauncherControllerPerApp::InsertAppLauncherItem(
1039 LauncherItemController* controller, 1037 LauncherItemController* controller,
1040 const std::string& app_id, 1038 const std::string& app_id,
1041 ash::LauncherItemStatus status, 1039 ash::LauncherItemStatus status,
1042 int index) { 1040 int index) {
1043 ash::LauncherID id = model_->next_id(); 1041 ash::LauncherID id = model_->next_id();
1044 DCHECK(!HasItemController(id)); 1042 DCHECK(!HasItemController(id));
1045 DCHECK(controller); 1043 DCHECK(controller);
1046 id_to_item_controller_map_[id] = controller; 1044 id_to_item_controller_map_[id] = controller;
1047 controller->set_launcher_id(id); 1045 controller->set_launcher_id(id);
1048 1046
1049 ash::LauncherItem item; 1047 ash::LauncherItem item;
1050 item.type = controller->GetLauncherItemType(); 1048 item.type = controller->GetLauncherItemType();
1051 item.is_incognito = false; 1049 item.is_incognito = false;
1052 item.image = Extension::GetDefaultIcon(true); 1050 item.image = Extension::GetDefaultIcon(true);
1053 1051
1054 TabContents* active_tab = GetLastActiveTabContents(app_id); 1052 WebContents* active_tab = GetLastActiveWebContents(app_id);
1055 if (active_tab) { 1053 if (active_tab) {
1056 Browser* browser = chrome::FindBrowserWithWebContents( 1054 Browser* browser = chrome::FindBrowserWithWebContents(active_tab);
1057 active_tab->web_contents());
1058 DCHECK(browser); 1055 DCHECK(browser);
1059 if (browser->window()->IsActive()) 1056 if (browser->window()->IsActive())
1060 status = ash::STATUS_ACTIVE; 1057 status = ash::STATUS_ACTIVE;
1061 else 1058 else
1062 status = ash::STATUS_RUNNING; 1059 status = ash::STATUS_RUNNING;
1063 } 1060 }
1064 item.status = status; 1061 item.status = status;
1065 1062
1066 model_->AddAt(index, item); 1063 model_->AddAt(index, item);
1067 1064
(...skipping 27 matching lines...) Expand all
1095 void ChromeLauncherControllerPerApp::SetAppIconLoaderForTest( 1092 void ChromeLauncherControllerPerApp::SetAppIconLoaderForTest(
1096 AppIconLoader* loader) { 1093 AppIconLoader* loader) {
1097 app_icon_loader_.reset(loader); 1094 app_icon_loader_.reset(loader);
1098 } 1095 }
1099 1096
1100 const std::string& 1097 const std::string&
1101 ChromeLauncherControllerPerApp::GetAppIdFromLauncherIdForTest( 1098 ChromeLauncherControllerPerApp::GetAppIdFromLauncherIdForTest(
1102 ash::LauncherID id) { 1099 ash::LauncherID id) {
1103 return id_to_item_controller_map_[id]->app_id(); 1100 return id_to_item_controller_map_[id]->app_id();
1104 } 1101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698