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

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.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_browser. h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser. 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( 59 AppShortcutLauncherItemController(
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 410
411 AppShortcutLauncherItemController* app_controller = 411 AppShortcutLauncherItemController* app_controller =
412 static_cast<AppShortcutLauncherItemController*>(controller); 412 static_cast<AppShortcutLauncherItemController*>(controller);
413 const GURL refocus_url = app_controller->refocus_url(); 413 const GURL refocus_url = app_controller->refocus_url();
414 414
415 if (!refocus_url.is_empty()) 415 if (!refocus_url.is_empty())
416 refocus_pattern.Parse(refocus_url.spec()); 416 refocus_pattern.Parse(refocus_url.spec());
417 } 417 }
418 418
419 // Check if there are any open tabs for this app. 419 // Check if there are any open tabs for this app.
420 AppIDToTabContentsListMap::iterator app_i = 420 AppIDToWebContentsListMap::iterator app_i =
421 app_id_to_tab_contents_list_.find(app_id); 421 app_id_to_web_contents_list_.find(app_id);
422 if (app_i != app_id_to_tab_contents_list_.end()) { 422 if (app_i != app_id_to_web_contents_list_.end()) {
423 for (TabContentsList::iterator tab_i = app_i->second.begin(); 423 for (WebContentsList::iterator tab_i = app_i->second.begin();
424 tab_i != app_i->second.end(); 424 tab_i != app_i->second.end();
425 ++tab_i) { 425 ++tab_i) {
426 TabContents* tab = *tab_i; 426 WebContents* tab = *tab_i;
427 const GURL tab_url = tab->web_contents()->GetURL(); 427 const GURL tab_url = tab->GetURL();
428 if (refocus_pattern.MatchesURL(tab_url)) { 428 if (refocus_pattern.MatchesURL(tab_url)) {
429 Browser* browser = chrome::FindBrowserWithWebContents( 429 Browser* browser = chrome::FindBrowserWithWebContents(tab);
430 tab->web_contents());
431 TabStripModel* tab_strip = browser->tab_strip_model(); 430 TabStripModel* tab_strip = browser->tab_strip_model();
432 int index = tab_strip->GetIndexOfTabContents(tab); 431 int index = tab_strip->GetIndexOfWebContents(tab);
433 DCHECK_NE(TabStripModel::kNoTab, index); 432 DCHECK_NE(TabStripModel::kNoTab, index);
434 tab_strip->ActivateTabAt(index, false); 433 tab_strip->ActivateTabAt(index, false);
435 browser->window()->Show(); 434 browser->window()->Show();
436 ash::wm::ActivateWindow(browser->window()->GetNativeWindow()); 435 ash::wm::ActivateWindow(browser->window()->GetNativeWindow());
437 return; 436 return;
438 } 437 }
439 } 438 }
440 } 439 }
441 440
442 LaunchApp(app_id, event_flags); 441 LaunchApp(app_id, event_flags);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 aura::RootWindow* root_window) { 586 aura::RootWindow* root_window) {
588 ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) == 587 ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) ==
589 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ? 588 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ?
590 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER : 589 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER :
591 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; 590 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
592 SetShelfAutoHideBehaviorPrefs(behavior, root_window); 591 SetShelfAutoHideBehaviorPrefs(behavior, root_window);
593 return; 592 return;
594 } 593 }
595 594
596 void ChromeLauncherControllerPerBrowser::RemoveTabFromRunningApp( 595 void ChromeLauncherControllerPerBrowser::RemoveTabFromRunningApp(
597 TabContents* tab, 596 WebContents* tab,
598 const std::string& app_id) { 597 const std::string& app_id) {
599 tab_contents_to_app_id_.erase(tab); 598 web_contents_to_app_id_.erase(tab);
600 AppIDToTabContentsListMap::iterator i_app_id = 599 AppIDToWebContentsListMap::iterator i_app_id =
601 app_id_to_tab_contents_list_.find(app_id); 600 app_id_to_web_contents_list_.find(app_id);
602 if (i_app_id != app_id_to_tab_contents_list_.end()) { 601 if (i_app_id != app_id_to_web_contents_list_.end()) {
603 TabContentsList* tab_list = &i_app_id->second; 602 WebContentsList* tab_list = &i_app_id->second;
604 tab_list->remove(tab); 603 tab_list->remove(tab);
605 if (tab_list->empty()) { 604 if (tab_list->empty()) {
606 app_id_to_tab_contents_list_.erase(i_app_id); 605 app_id_to_web_contents_list_.erase(i_app_id);
607 i_app_id = app_id_to_tab_contents_list_.end(); 606 i_app_id = app_id_to_web_contents_list_.end();
608 ash::LauncherID id = GetLauncherIDForAppID(app_id); 607 ash::LauncherID id = GetLauncherIDForAppID(app_id);
609 if (id > 0) 608 if (id > 0)
610 SetItemStatus(id, ash::STATUS_CLOSED); 609 SetItemStatus(id, ash::STATUS_CLOSED);
611 } 610 }
612 } 611 }
613 } 612 }
614 613
615 void ChromeLauncherControllerPerBrowser::UpdateAppState( 614 void ChromeLauncherControllerPerBrowser::UpdateAppState(
616 content::WebContents* contents, 615 content::WebContents* contents,
617 AppState app_state) { 616 AppState app_state) {
618 std::string app_id = GetAppID(contents); 617 std::string app_id = GetAppID(contents);
619 618
620 // Check the old |app_id| for a tab. If the contents has changed we need to 619 // Check the old |app_id| for a tab. If the contents has changed we need to
621 // remove it from the previous app. 620 // remove it from the previous app.
622 TabContents* tab = TabContents::FromWebContents(contents); 621 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) {
623 if (tab_contents_to_app_id_.find(tab) != tab_contents_to_app_id_.end()) { 622 std::string last_app_id = web_contents_to_app_id_[contents];
624 std::string last_app_id = tab_contents_to_app_id_[tab];
625 if (last_app_id != app_id) 623 if (last_app_id != app_id)
626 RemoveTabFromRunningApp(tab, last_app_id); 624 RemoveTabFromRunningApp(contents, last_app_id);
627 } 625 }
628 626
629 if (app_id.empty()) 627 if (app_id.empty())
630 return; 628 return;
631 629
632 tab_contents_to_app_id_[tab] = app_id; 630 web_contents_to_app_id_[contents] = app_id;
633 631
634 if (app_state == APP_STATE_REMOVED) { 632 if (app_state == APP_STATE_REMOVED) {
635 // The tab has gone away. 633 // The tab has gone away.
636 RemoveTabFromRunningApp(tab, app_id); 634 RemoveTabFromRunningApp(contents, app_id);
637 } else { 635 } else {
638 TabContentsList& tab_list(app_id_to_tab_contents_list_[app_id]); 636 WebContentsList& tab_list(app_id_to_web_contents_list_[app_id]);
639 637
640 if (app_state == APP_STATE_INACTIVE) { 638 if (app_state == APP_STATE_INACTIVE) {
641 TabContentsList::const_iterator i_tab = 639 WebContentsList::const_iterator i_tab =
642 std::find(tab_list.begin(), tab_list.end(), tab); 640 std::find(tab_list.begin(), tab_list.end(), contents);
643 if (i_tab == tab_list.end()) 641 if (i_tab == tab_list.end())
644 tab_list.push_back(tab); 642 tab_list.push_back(contents);
645 if (i_tab != tab_list.begin()) { 643 if (i_tab != tab_list.begin()) {
646 // Going inactive, but wasn't the front tab, indicating that a new 644 // Going inactive, but wasn't the front tab, indicating that a new
647 // tab has already become active. 645 // tab has already become active.
648 return; 646 return;
649 } 647 }
650 } else { 648 } else {
651 tab_list.remove(tab); 649 tab_list.remove(contents);
652 tab_list.push_front(tab); 650 tab_list.push_front(contents);
653 } 651 }
654 ash::LauncherID id = GetLauncherIDForAppID(app_id); 652 ash::LauncherID id = GetLauncherIDForAppID(app_id);
655 if (id > 0) { 653 if (id > 0) {
656 // If the window is active, mark the app as active. 654 // If the window is active, mark the app as active.
657 SetItemStatus(id, app_state == APP_STATE_WINDOW_ACTIVE ? 655 SetItemStatus(id, app_state == APP_STATE_WINDOW_ACTIVE ?
658 ash::STATUS_ACTIVE : ash::STATUS_RUNNING); 656 ash::STATUS_ACTIVE : ash::STATUS_RUNNING);
659 } 657 }
660 } 658 }
661 } 659 }
662 660
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 ash::ShelfAlignment alignment = ash::SHELF_ALIGNMENT_BOTTOM; 1025 ash::ShelfAlignment alignment = ash::SHELF_ALIGNMENT_BOTTOM;
1028 if (alignment_value == ash::kShelfAlignmentLeft) 1026 if (alignment_value == ash::kShelfAlignmentLeft)
1029 alignment = ash::SHELF_ALIGNMENT_LEFT; 1027 alignment = ash::SHELF_ALIGNMENT_LEFT;
1030 else if (alignment_value == ash::kShelfAlignmentRight) 1028 else if (alignment_value == ash::kShelfAlignmentRight)
1031 alignment = ash::SHELF_ALIGNMENT_RIGHT; 1029 alignment = ash::SHELF_ALIGNMENT_RIGHT;
1032 // TODO(oshima): Support multiple displays. 1030 // TODO(oshima): Support multiple displays.
1033 ash::Shell::GetInstance()->SetShelfAlignment( 1031 ash::Shell::GetInstance()->SetShelfAlignment(
1034 alignment, ash::Shell::GetPrimaryRootWindow()); 1032 alignment, ash::Shell::GetPrimaryRootWindow());
1035 } 1033 }
1036 1034
1037 TabContents* ChromeLauncherControllerPerBrowser::GetLastActiveTabContents( 1035 WebContents* ChromeLauncherControllerPerBrowser::GetLastActiveWebContents(
1038 const std::string& app_id) { 1036 const std::string& app_id) {
1039 AppIDToTabContentsListMap::const_iterator i = 1037 AppIDToWebContentsListMap::const_iterator i =
1040 app_id_to_tab_contents_list_.find(app_id); 1038 app_id_to_web_contents_list_.find(app_id);
1041 if (i == app_id_to_tab_contents_list_.end()) 1039 if (i == app_id_to_web_contents_list_.end())
1042 return NULL; 1040 return NULL;
1043 DCHECK_GT(i->second.size(), 0u); 1041 DCHECK_GT(i->second.size(), 0u);
1044 return *i->second.begin(); 1042 return *i->second.begin();
1045 } 1043 }
1046 1044
1047 ash::LauncherID ChromeLauncherControllerPerBrowser::InsertAppLauncherItem( 1045 ash::LauncherID ChromeLauncherControllerPerBrowser::InsertAppLauncherItem(
1048 LauncherItemController* controller, 1046 LauncherItemController* controller,
1049 const std::string& app_id, 1047 const std::string& app_id,
1050 ash::LauncherItemStatus status, 1048 ash::LauncherItemStatus status,
1051 int index) { 1049 int index) {
1052 ash::LauncherID id = model_->next_id(); 1050 ash::LauncherID id = model_->next_id();
1053 DCHECK(!HasItemController(id)); 1051 DCHECK(!HasItemController(id));
1054 DCHECK(controller); 1052 DCHECK(controller);
1055 id_to_item_controller_map_[id] = controller; 1053 id_to_item_controller_map_[id] = controller;
1056 controller->set_launcher_id(id); 1054 controller->set_launcher_id(id);
1057 1055
1058 ash::LauncherItem item; 1056 ash::LauncherItem item;
1059 item.type = controller->GetLauncherItemType(); 1057 item.type = controller->GetLauncherItemType();
1060 item.is_incognito = false; 1058 item.is_incognito = false;
1061 item.image = Extension::GetDefaultIcon(true); 1059 item.image = Extension::GetDefaultIcon(true);
1062 1060
1063 TabContents* active_tab = GetLastActiveTabContents(app_id); 1061 WebContents* active_tab = GetLastActiveWebContents(app_id);
1064 if (active_tab) { 1062 if (active_tab) {
1065 Browser* browser = chrome::FindBrowserWithWebContents( 1063 Browser* browser = chrome::FindBrowserWithWebContents(active_tab);
1066 active_tab->web_contents());
1067 DCHECK(browser); 1064 DCHECK(browser);
1068 if (browser->window()->IsActive()) 1065 if (browser->window()->IsActive())
1069 status = ash::STATUS_ACTIVE; 1066 status = ash::STATUS_ACTIVE;
1070 else 1067 else
1071 status = ash::STATUS_RUNNING; 1068 status = ash::STATUS_RUNNING;
1072 } 1069 }
1073 item.status = status; 1070 item.status = status;
1074 1071
1075 model_->AddAt(index, item); 1072 model_->AddAt(index, item);
1076 1073
(...skipping 29 matching lines...) Expand all
1106 AppIconLoader* loader) { 1103 AppIconLoader* loader) {
1107 app_icon_loader_.reset(loader); 1104 app_icon_loader_.reset(loader);
1108 } 1105 }
1109 1106
1110 const std::string& 1107 const std::string&
1111 ChromeLauncherControllerPerBrowser::GetAppIdFromLauncherIdForTest( 1108 ChromeLauncherControllerPerBrowser::GetAppIdFromLauncherIdForTest(
1112 ash::LauncherID id) { 1109 ash::LauncherID id) {
1113 return id_to_item_controller_map_[id]->app_id(); 1110 return id_to_item_controller_map_[id]->app_id();
1114 } 1111 }
1115 1112
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698