summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsimon.hong81@gmail.com <simon.hong81@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-28 15:34:32 +0000
committersimon.hong81@gmail.com <simon.hong81@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-28 15:34:32 +0000
commit8d181bfcdc9134e9d98577d77ce340501e8ee922 (patch)
treec5c6c3b589e677d002000ab6a734cc31e629e3df /chrome
parentf21df145f1fb916ad95dc375c6a0bf3485fbf875 (diff)
downloadchromium_src-8d181bfcdc9134e9d98577d77ce340501e8ee922.zip
chromium_src-8d181bfcdc9134e9d98577d77ce340501e8ee922.tar.gz
chromium_src-8d181bfcdc9134e9d98577d77ce340501e8ee922.tar.bz2
Remove BrowserLauncherItemController and ash::TYPE_TABBED
After removing old launcher, new launcher don't need BrowserLauncherItemController as LauncherItemController. New launcher only needs the functionality of monitoring browser and its status change. To handle this, BrowserStatusMonitor is introduced. BrowserStatusMonitor monitors BrowserLists to detects creation and deletion of Browser and its TabStripModel to keep the launcher representation up to date as the active tab changes. Also ash::TYPE_TABBED is removed from LauncherItemType since ash::TYPE_TABBED is only used by PerBrowser Launcher. Existing unit tests that used TYPE_TABBED is replaced with TYPE_PLATFORM_APP. No new unit tests are added for this. Existing unit tests(browser_tests, unit_tests, ash_unittests) can cover this modification. R=skuhne@chromium.org, sky@chromium.org BUG=169303, 277241 TEST=Compiles, Manual test, unit_tests, browser_tests, ash_unittests Review URL: https://chromiumcodereview.appspot.com/22795003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220035 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/ui/ash/launcher/browser_launcher_item_controller.cc268
-rw-r--r--chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h144
-rw-r--r--chrome/browser/ui/ash/launcher/browser_status_monitor.cc196
-rw-r--r--chrome/browser/ui/ash/launcher/browser_status_monitor.h99
-rw-r--r--chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc23
-rw-r--r--chrome/browser/ui/ash/launcher/chrome_launcher_controller.h15
-rw-r--r--chrome/browser/ui/ash/launcher/launcher_favicon_loader.cc2
-rw-r--r--chrome/browser/ui/ash/launcher/launcher_item_controller.cc2
-rw-r--r--chrome/browser/ui/ash/launcher/launcher_item_controller.h1
-rw-r--r--chrome/browser/ui/views/frame/browser_view.cc25
-rw-r--r--chrome/browser/ui/views/frame/browser_view.h25
-rw-r--r--chrome/chrome_browser_ui.gypi4
12 files changed, 313 insertions, 491 deletions
diff --git a/chrome/browser/ui/ash/launcher/browser_launcher_item_controller.cc b/chrome/browser/ui/ash/launcher/browser_launcher_item_controller.cc
deleted file mode 100644
index 04668bb..0000000
--- a/chrome/browser/ui/ash/launcher/browser_launcher_item_controller.cc
+++ /dev/null
@@ -1,268 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h"
-
-#include "ash/launcher/launcher.h"
-#include "ash/launcher/launcher_model.h"
-#include "ash/shell.h"
-#include "ash/wm/window_util.h"
-#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/tab_helper.h"
-#include "chrome/browser/favicon/favicon_tab_helper.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h"
-#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_list.h"
-#include "chrome/browser/ui/browser_window.h"
-#include "chrome/browser/ui/tabs/tab_strip_model.h"
-#include "chrome/browser/web_applications/web_app.h"
-#include "chrome/common/extensions/manifest_handlers/icons_handler.h"
-#include "content/public/browser/web_contents.h"
-#include "grit/ui_resources.h"
-#include "ui/aura/client/aura_constants.h"
-#include "ui/aura/window.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/views/widget/widget.h"
-
-BrowserLauncherItemController::BrowserLauncherItemController(
- Type type,
- aura::Window* window,
- TabStripModel* tab_model,
- ChromeLauncherController* launcher_controller,
- const std::string& app_id)
- : LauncherItemController(type, app_id, launcher_controller),
- window_(window),
- tab_model_(tab_model),
- is_incognito_(tab_model->profile()->GetOriginalProfile() !=
- tab_model->profile() &&
- !tab_model->profile()->IsGuestSession()) {
- DCHECK(window_);
- window_->AddObserver(this);
-}
-
-BrowserLauncherItemController::~BrowserLauncherItemController() {
- tab_model_->RemoveObserver(this);
- window_->RemoveObserver(this);
- if (launcher_id() > 0)
- launcher_controller()->CloseLauncherItem(launcher_id());
- if (type() == TYPE_WINDOWED_APP)
- launcher_controller()->UnlockV1AppWithID(LauncherItemController::app_id());
-}
-
-const std::string& BrowserLauncherItemController::app_id() const {
- if (type() == TYPE_WINDOWED_APP)
- return empty_app_id_;
- return LauncherItemController::app_id();
-}
-
-void BrowserLauncherItemController::Init() {
- tab_model_->AddObserver(this);
- ash::LauncherItemStatus app_status =
- ash::wm::IsActiveWindow(window_) ?
- ash::STATUS_ACTIVE : ash::STATUS_RUNNING;
- if (type() != TYPE_TABBED && type() != TYPE_WINDOWED_APP)
- launcher_controller()->CreateAppLauncherItem(this, app_id(), app_status);
- else if (type() == TYPE_WINDOWED_APP)
- launcher_controller()->LockV1AppWithID(LauncherItemController::app_id());
-
- // In testing scenarios we can get tab strips with no active contents.
- if (tab_model_->active_index() != TabStripModel::kNoTab)
- UpdateLauncher(tab_model_->GetActiveWebContents());
-}
-
-// static
-BrowserLauncherItemController* BrowserLauncherItemController::Create(
- Browser* browser) {
- // Under testing this can be called before the controller is created.
- if (!ChromeLauncherController::instance())
- return NULL;
-
- Type type;
- std::string app_id;
- if (browser->is_type_tabbed() || browser->is_type_popup()) {
- type = TYPE_TABBED;
- if (!browser->is_type_tabbed() &&
- browser->is_type_popup() &&
- browser->is_app()) {
- app_id = web_app::GetExtensionIdFromApplicationName(
- browser->app_name());
- // Only allow this for known applications. Some unit tests for example
- // do not have one.
- if (!app_id.empty())
- type = TYPE_WINDOWED_APP;
- }
- } else if (browser->is_app()) {
- type = TYPE_TABBED;
- app_id = web_app::GetExtensionIdFromApplicationName(browser->app_name());
- } else {
- return NULL;
- }
- BrowserLauncherItemController* controller =
- new BrowserLauncherItemController(type,
- browser->window()->GetNativeWindow(),
- browser->tab_strip_model(),
- ChromeLauncherController::instance(),
- app_id);
- controller->Init();
- return controller;
-}
-
-void BrowserLauncherItemController::BrowserActivationStateChanged() {
- content::WebContents* active_contents = tab_model_->GetActiveWebContents();
- if (active_contents)
- UpdateAppState(active_contents);
- UpdateItemStatus();
-}
-
-string16 BrowserLauncherItemController::GetTitle() {
- if (type() == TYPE_TABBED) {
- if (tab_model_->active_index() != TabStripModel::kNoTab) {
- const content::WebContents* contents = tab_model_->GetActiveWebContents();
- if (contents)
- return contents->GetTitle();
- }
- }
- return GetAppTitle();
-}
-
-bool BrowserLauncherItemController::IsCurrentlyShownInWindow(
- aura::Window* window) const {
- return window_ == window;
-}
-
-bool BrowserLauncherItemController::IsOpen() const {
- return true;
-}
-
-bool BrowserLauncherItemController::IsVisible() const {
- return window_->IsVisible();
-}
-
-void BrowserLauncherItemController::Launch(int event_flags) {
- DCHECK(!app_id().empty());
- launcher_controller()->LaunchApp(app_id(), event_flags);
-}
-
-void BrowserLauncherItemController::Activate() {
- window_->Show();
- ash::wm::ActivateWindow(window_);
-}
-
-void BrowserLauncherItemController::Close() {
- views::Widget* widget = views::Widget::GetWidgetForNativeView(window_);
- if (widget)
- widget->Close();
-}
-
-void BrowserLauncherItemController::Clicked(const ui::Event& event) {
- views::Widget* widget =
- views::Widget::GetWidgetForNativeView(window_);
- if (widget && widget->IsActive()) {
- widget->Minimize();
- } else {
- Activate();
- }
-}
-
-void BrowserLauncherItemController::OnRemoved() {
-}
-
-void BrowserLauncherItemController::LauncherItemChanged(
- int index,
- const ash::LauncherItem& old_item) {
-}
-
-ChromeLauncherAppMenuItems
-BrowserLauncherItemController::GetApplicationList(int event_flags) {
- // This will never be called and the entire class will go away.
- ChromeLauncherAppMenuItems items;
- return items.Pass();
-}
-
-void BrowserLauncherItemController::ActiveTabChanged(
- content::WebContents* old_contents,
- content::WebContents* new_contents,
- int index,
- int reason) {
- // Update immediately on a tab change.
- if (old_contents &&
- TabStripModel::kNoTab !=
- tab_model_->GetIndexOfWebContents(old_contents))
- UpdateAppState(old_contents);
- UpdateAppState(new_contents);
- UpdateLauncher(new_contents);
-}
-
-void BrowserLauncherItemController::TabInsertedAt(
- content::WebContents* contents,
- int index,
- bool foreground) {
- UpdateAppState(contents);
-}
-
-void BrowserLauncherItemController::TabDetachedAt(
- content::WebContents* contents,
- int index) {
- launcher_controller()->UpdateAppState(
- contents, ChromeLauncherController::APP_STATE_REMOVED);
-}
-
-void BrowserLauncherItemController::TabChangedAt(
- content::WebContents* contents,
- int index,
- TabStripModelObserver::TabChangeType change_type) {
- UpdateAppState(contents);
- if (index != tab_model_->active_index() ||
- !(change_type != TabStripModelObserver::LOADING_ONLY &&
- change_type != TabStripModelObserver::TITLE_NOT_LOADING)) {
- return;
- }
-
- UpdateLauncher(contents);
-}
-
-void BrowserLauncherItemController::TabReplacedAt(
- TabStripModel* tab_strip_model,
- content::WebContents* old_contents,
- content::WebContents* new_contents,
- int index) {
- launcher_controller()->UpdateAppState(
- old_contents,
- ChromeLauncherController::APP_STATE_REMOVED);
- UpdateAppState(new_contents);
-}
-
-void BrowserLauncherItemController::OnWindowPropertyChanged(
- aura::Window* window,
- const void* key,
- intptr_t old) {
- if (key == aura::client::kDrawAttentionKey)
- UpdateItemStatus();
-}
-
-void BrowserLauncherItemController::UpdateItemStatus() {
-}
-
-void BrowserLauncherItemController::UpdateLauncher(content::WebContents* tab) {
-}
-
-void BrowserLauncherItemController::UpdateAppState(content::WebContents* tab) {
- ChromeLauncherController::AppState app_state;
-
- if (tab_model_->GetActiveWebContents() == tab) {
- if (ash::wm::IsActiveWindow(window_))
- app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE;
- else
- app_state = ChromeLauncherController::APP_STATE_ACTIVE;
- } else {
- app_state = ChromeLauncherController::APP_STATE_INACTIVE;
- }
- launcher_controller()->UpdateAppState(tab, app_state);
-}
-
-ash::LauncherModel* BrowserLauncherItemController::launcher_model() {
- return launcher_controller()->model();
-}
diff --git a/chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h b/chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h
deleted file mode 100644
index 51fbc33..0000000
--- a/chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h
+++ /dev/null
@@ -1,144 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_LAUNCHER_ITEM_CONTROLLER_H_
-#define CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_LAUNCHER_ITEM_CONTROLLER_H_
-
-#include <string>
-
-#include "ash/launcher/launcher_types.h"
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "base/gtest_prod_util.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/strings/string16.h"
-#include "chrome/browser/ui/ash/launcher/launcher_favicon_loader.h"
-#include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
-#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
-#include "ui/aura/window_observer.h"
-
-class Browser;
-
-namespace ash {
-class LauncherModel;
-}
-
-// BrowserLauncherItemController is responsible for keeping the launcher
-// representation of a window up to date as the active tab changes.
-class BrowserLauncherItemController : public LauncherItemController,
- public TabStripModelObserver,
- public aura::WindowObserver {
- public:
- // This API is to be used as part of testing only.
- class TestApi {
- public:
- explicit TestApi(BrowserLauncherItemController* controller)
- : controller_(controller) {}
- ~TestApi() {}
-
- // Returns the launcher id for the browser window.
- ash::LauncherID item_id() const { return controller_->launcher_id(); }
-
- private:
- BrowserLauncherItemController* controller_;
- };
-
- BrowserLauncherItemController(Type type,
- aura::Window* window,
- TabStripModel* tab_model,
- ChromeLauncherController* launcher_controller,
- const std::string& app_id);
- virtual ~BrowserLauncherItemController();
-
- // Overriding the app id for V1 apps.
- virtual const std::string& app_id() const OVERRIDE;
-
- // Sets up this BrowserLauncherItemController.
- void Init();
-
- // Creates and returns a new BrowserLauncherItemController for |browser|. This
- // returns NULL if a BrowserLauncherItemController is not needed for the
- // specified browser.
- static BrowserLauncherItemController* Create(Browser* browser);
-
- // Call to indicate that the window the tabcontents are in has changed its
- // activation state.
- void BrowserActivationStateChanged();
-
- // LauncherItemController overrides:
- virtual string16 GetTitle() OVERRIDE;
- virtual bool IsCurrentlyShownInWindow(aura::Window* window) const OVERRIDE;
- virtual bool IsOpen() const OVERRIDE;
- virtual bool IsVisible() const OVERRIDE;
- virtual void Launch(int event_flags) OVERRIDE;
- virtual void Activate() OVERRIDE;
- virtual void Close() OVERRIDE;
- virtual void Clicked(const ui::Event& event) OVERRIDE;
- virtual void OnRemoved() OVERRIDE;
- virtual void LauncherItemChanged(int index,
- const ash::LauncherItem& old_item) OVERRIDE;
- virtual ChromeLauncherAppMenuItems GetApplicationList(
- int event_flags) OVERRIDE;
-
- // TabStripModel overrides:
- virtual void ActiveTabChanged(content::WebContents* old_contents,
- content::WebContents* new_contents,
- int index,
- int reason) OVERRIDE;
- virtual void TabInsertedAt(content::WebContents* contents,
- int index,
- bool foreground) OVERRIDE;
- virtual void TabDetachedAt(content::WebContents* contents,
- int index) OVERRIDE;
- virtual void TabChangedAt(
- content::WebContents* contents,
- int index,
- TabStripModelObserver::TabChangeType change_type) OVERRIDE;
- virtual void TabReplacedAt(TabStripModel* tab_strip_model,
- content::WebContents* old_contents,
- content::WebContents* new_contents,
- int index) OVERRIDE;
-
- // aura::WindowObserver overrides:
- virtual void OnWindowPropertyChanged(aura::Window* window,
- const void* key,
- intptr_t old) OVERRIDE;
-
- private:
- FRIEND_TEST_ALL_PREFIXES(BrowserLauncherItemControllerTest, PanelItem);
-
- // Used to identify what an update corresponds to.
- enum UpdateType {
- UPDATE_TAB_REMOVED,
- UPDATE_TAB_CHANGED,
- UPDATE_TAB_INSERTED,
- };
-
- // Updates the launcher item status base on the activation and attention
- // state of the window.
- void UpdateItemStatus();
-
- // Updates the launcher from |tab|.
- void UpdateLauncher(content::WebContents* tab);
-
- void UpdateAppState(content::WebContents* tab);
-
- ash::LauncherModel* launcher_model();
-
- // Browser window we're in.
- aura::Window* window_;
-
- // If running a windowed V1 app with the new launcher, this (empty) app id
- // will be returned by app_id().
- std::string empty_app_id_;
-
- TabStripModel* tab_model_;
-
- // Whether this is associated with an incognito profile.
- const bool is_incognito_;
-
- DISALLOW_COPY_AND_ASSIGN(BrowserLauncherItemController);
-};
-
-#endif // CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_LAUNCHER_ITEM_CONTROLLER_H_
diff --git a/chrome/browser/ui/ash/launcher/browser_status_monitor.cc b/chrome/browser/ui/ash/launcher/browser_status_monitor.cc
new file mode 100644
index 0000000..06b0178
--- /dev/null
+++ b/chrome/browser/ui/ash/launcher/browser_status_monitor.cc
@@ -0,0 +1,196 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/ash/launcher/browser_status_monitor.h"
+
+#include "ash/shell.h"
+#include "ash/wm/window_util.h"
+#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/web_applications/web_app.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_view.h"
+#include "ui/aura/client/activation_client.h"
+#include "ui/aura/root_window.h"
+#include "ui/aura/window.h"
+#include "ui/gfx/screen.h"
+
+BrowserStatusMonitor::BrowserStatusMonitor(
+ ChromeLauncherController* launcher_controller)
+ : launcher_controller_(launcher_controller),
+ observed_activation_clients_(this),
+ observed_root_windows_(this) {
+ DCHECK(launcher_controller_);
+ BrowserList* browser_list =
+ BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
+
+ browser_list->AddObserver(this);
+
+ // This check needs for win7_aura. Without this, all tests in
+ // ChromeLauncherController will fail in win7_aura.
+ if (ash::Shell::HasInstance()) {
+ // We can't assume all RootWindows have the same ActivationClient.
+ // Add a RootWindow and its ActivationClient to the observed list.
+ ash::Shell::RootWindowList root_windows = ash::Shell::GetAllRootWindows();
+ ash::Shell::RootWindowList::const_iterator iter = root_windows.begin();
+ for (; iter != root_windows.end(); ++iter) {
+ // |observed_activation_clients_| can have the same activation client
+ // multiple times - which would be handled by the used
+ // |ScopedObserverWithDuplicatedSources|.
+ observed_activation_clients_.Add(
+ aura::client::GetActivationClient(*iter));
+ observed_root_windows_.Add(static_cast<aura::Window*>(*iter));
+ }
+ ash::Shell::GetInstance()->GetScreen()->AddObserver(this);
+ }
+}
+
+BrowserStatusMonitor::~BrowserStatusMonitor() {
+ // This check needs for win7_aura. Without this, all tests in
+ // ChromeLauncherController will fail in win7_aura.
+ if (ash::Shell::HasInstance())
+ ash::Shell::GetInstance()->GetScreen()->RemoveObserver(this);
+
+ BrowserList* browser_list =
+ BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
+
+ browser_list->RemoveObserver(this);
+}
+
+void BrowserStatusMonitor::OnWindowActivated(aura::Window* gained_active,
+ aura::Window* lost_active) {
+ Browser* browser = chrome::FindBrowserWithWindow(lost_active);
+ content::WebContents* active_contents = NULL;
+
+ if (browser) {
+ active_contents = browser->tab_strip_model()->GetActiveWebContents();
+ if (active_contents)
+ UpdateAppState(active_contents);
+ }
+
+ browser = chrome::FindBrowserWithWindow(gained_active);
+ if (browser) {
+ active_contents = browser->tab_strip_model()->GetActiveWebContents();
+ if (active_contents)
+ UpdateAppState(active_contents);
+ }
+}
+
+void BrowserStatusMonitor::OnWindowDestroyed(aura::Window* window) {
+ // Remove RootWindow and its ActivationClient from observed list.
+ observed_root_windows_.Remove(window);
+ observed_activation_clients_.Remove(aura::client::GetActivationClient(
+ static_cast<aura::RootWindow*>(window)));
+}
+
+void BrowserStatusMonitor::OnBrowserAdded(Browser* browser) {
+ browser->tab_strip_model()->AddObserver(this);
+
+ if (browser->is_type_popup() && browser->is_app()) {
+ std::string app_id =
+ web_app::GetExtensionIdFromApplicationName(browser->app_name());
+ if (!app_id.empty()) {
+ browser_to_app_id_map_[browser] = app_id;
+ launcher_controller_->LockV1AppWithID(app_id);
+ }
+ }
+}
+
+void BrowserStatusMonitor::OnBrowserRemoved(Browser* browser) {
+ browser->tab_strip_model()->RemoveObserver(this);
+
+ if (browser_to_app_id_map_.find(browser) != browser_to_app_id_map_.end()) {
+ launcher_controller_->UnlockV1AppWithID(browser_to_app_id_map_[browser]);
+ browser_to_app_id_map_.erase(browser);
+ }
+ launcher_controller_->UpdateBrowserItemStatus();
+}
+
+void BrowserStatusMonitor::OnDisplayBoundsChanged(
+ const gfx::Display& display) {
+ // Do nothing here.
+}
+
+void BrowserStatusMonitor::OnDisplayAdded(const gfx::Display& new_display) {
+ // Add a new RootWindow and its ActivationClient to observed list.
+ aura::RootWindow* root_window = ash::Shell::GetInstance()->
+ display_controller()->GetRootWindowForDisplayId(new_display.id());
+ observed_activation_clients_.Add(
+ aura::client::GetActivationClient(root_window));
+}
+
+void BrowserStatusMonitor::OnDisplayRemoved(const gfx::Display& old_display) {
+ // When this is called, RootWindow of |old_display| is already removed.
+ // Instead, we can remove RootWindow and its ActivationClient in the
+ // OnWindowRemoved().
+ // Do nothing here.
+}
+
+void BrowserStatusMonitor::ActiveTabChanged(content::WebContents* old_contents,
+ content::WebContents* new_contents,
+ int index,
+ int reason) {
+ Browser* browser = NULL;
+ if (old_contents)
+ browser = chrome::FindBrowserWithWebContents(old_contents);
+
+ // Update immediately on a tab change.
+ if (browser &&
+ (TabStripModel::kNoTab !=
+ browser->tab_strip_model()->GetIndexOfWebContents(old_contents)))
+ UpdateAppState(old_contents);
+
+ UpdateAppState(new_contents);
+}
+
+void BrowserStatusMonitor::TabInsertedAt(content::WebContents* contents,
+ int index,
+ bool foreground) {
+ UpdateAppState(contents);
+}
+
+void BrowserStatusMonitor::TabDetachedAt(content::WebContents* contents,
+ int index) {
+ launcher_controller_->UpdateAppState(
+ contents, ChromeLauncherController::APP_STATE_REMOVED);
+}
+
+void BrowserStatusMonitor::TabChangedAt(
+ content::WebContents* contents,
+ int index,
+ TabStripModelObserver::TabChangeType change_type) {
+ UpdateAppState(contents);
+}
+
+void BrowserStatusMonitor::TabReplacedAt(TabStripModel* tab_strip_model,
+ content::WebContents* old_contents,
+ content::WebContents* new_contents,
+ int index) {
+ launcher_controller_->UpdateAppState(
+ old_contents,
+ ChromeLauncherController::APP_STATE_REMOVED);
+ UpdateAppState(new_contents);
+}
+
+void BrowserStatusMonitor::UpdateAppState(content::WebContents* contents) {
+ if (!contents)
+ return;
+
+ ChromeLauncherController::AppState app_state =
+ ChromeLauncherController::APP_STATE_INACTIVE;
+
+ Browser* browser = chrome::FindBrowserWithWebContents(contents);
+ if (browser->tab_strip_model()->GetActiveWebContents() == contents) {
+ if (browser->window()->IsActive())
+ app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE;
+ else
+ app_state = ChromeLauncherController::APP_STATE_ACTIVE;
+ }
+
+ launcher_controller_->UpdateAppState(contents, app_state);
+}
diff --git a/chrome/browser/ui/ash/launcher/browser_status_monitor.h b/chrome/browser/ui/ash/launcher/browser_status_monitor.h
new file mode 100644
index 0000000..9c2880a
--- /dev/null
+++ b/chrome/browser/ui/ash/launcher/browser_status_monitor.h
@@ -0,0 +1,99 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_
+#define CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_
+
+#include <map>
+#include <string>
+
+#include "ash/launcher/scoped_observer_with_duplicated_sources.h"
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/scoped_observer.h"
+#include "chrome/browser/ui/browser_list_observer.h"
+#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
+#include "ui/aura/client/activation_change_observer.h"
+#include "ui/aura/window_observer.h"
+#include "ui/gfx/display_observer.h"
+
+namespace aura {
+class Window;
+
+namespace client {
+class ActivationClient;
+}
+} // namespace aura
+
+class Browser;
+class ChromeLauncherController;
+
+// BrowserStatusMonitor monitors creation/deletion of Browser and its
+// TabStripModel to keep the launcher representation up to date as the
+// active tab changes.
+class BrowserStatusMonitor : public aura::client::ActivationChangeObserver,
+ public aura::WindowObserver,
+ public chrome::BrowserListObserver,
+ public gfx::DisplayObserver,
+ public TabStripModelObserver {
+ public:
+ explicit BrowserStatusMonitor(ChromeLauncherController* launcher_controller);
+ virtual ~BrowserStatusMonitor();
+
+ // aura::client::ActivationChangeObserver overrides:
+ virtual void OnWindowActivated(aura::Window* gained_active,
+ aura::Window* lost_active) OVERRIDE;
+
+ // aura::WindowObserver overrides:
+ virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;
+
+ // chrome::BrowserListObserver overrides:
+ virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
+ virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
+
+ // gfx::DisplayObserver overrides:
+ virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE;
+ virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE;
+ virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE;
+
+ // TabStripModelObserver overrides:
+ virtual void ActiveTabChanged(content::WebContents* old_contents,
+ content::WebContents* new_contents,
+ int index,
+ int reason) OVERRIDE;
+ virtual void TabInsertedAt(content::WebContents* contents,
+ int index,
+ bool foreground) OVERRIDE;
+ virtual void TabDetachedAt(content::WebContents* contents,
+ int index) OVERRIDE;
+ virtual void TabChangedAt(
+ content::WebContents* contents,
+ int index,
+ TabStripModelObserver::TabChangeType change_type) OVERRIDE;
+ virtual void TabReplacedAt(TabStripModel* tab_strip_model,
+ content::WebContents* old_contents,
+ content::WebContents* new_contents,
+ int index) OVERRIDE;
+
+ private:
+ typedef std::map<Browser*, std::string> BrowserToAppIDMap;
+
+ // Update app state for |contents|.
+ void UpdateAppState(content::WebContents* contents);
+
+ ChromeLauncherController* launcher_controller_;
+
+ // Hold all observed activation clients.
+ ScopedObserverWithDuplicatedSources<aura::client::ActivationClient,
+ aura::client::ActivationChangeObserver> observed_activation_clients_;
+
+ // Hold all observed root windows.
+ ScopedObserver<aura::Window, aura::WindowObserver> observed_root_windows_;
+
+ BrowserToAppIDMap browser_to_app_id_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(BrowserStatusMonitor);
+};
+
+#endif // CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_
diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
index a072cac..9b0bc44 100644
--- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
+++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
@@ -36,6 +36,7 @@
#include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
#include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h"
#include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.h"
+#include "chrome/browser/ui/ash/launcher/browser_status_monitor.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h"
@@ -208,8 +209,8 @@ ChromeLauncherController::ChromeLauncherController(
app_sync_ui_state_->AddObserver(this);
}
+ browser_status_monitor_.reset(new BrowserStatusMonitor(this));
model_->AddObserver(this);
- BrowserList::AddObserver(this);
// Right now ash::Shell isn't created for tests.
// TODO(mukai): Allows it to observe display change and write tests.
if (ash::Shell::HasInstance())
@@ -261,15 +262,11 @@ ChromeLauncherController::~ChromeLauncherController() {
(*iter)->shelf_widget()->shelf_layout_manager()->RemoveObserver(this);
model_->RemoveObserver(this);
- BrowserList::RemoveObserver(this);
if (ash::Shell::HasInstance())
ash::Shell::GetInstance()->display_controller()->RemoveObserver(this);
for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin();
i != id_to_item_controller_map_.end(); ++i) {
i->second->OnRemoved();
- // TODO(skuhne): After getting rid of the old launcher, get also rid of the
- // BrowserLauncherItemController (since it is only used for activation
- // tracking at that point.
int index = model_->ItemIndexByID(i->first);
// A "browser proxy" is not known to the model and this removal does
// therefore not need to be propagated to the model.
@@ -1206,13 +1203,6 @@ string16 ChromeLauncherController::GetAppListTitle(
return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE);
}
-void ChromeLauncherController::OnBrowserRemoved(Browser* browser) {
- // When called by a unit test it is possible that there is no shell.
- // In that case, the following function should not get called.
- if (ash::Shell::HasInstance())
- UpdateBrowserItemStatus();
-}
-
ash::LauncherID ChromeLauncherController::CreateAppShortcutLauncherItem(
const std::string& app_id,
int index) {
@@ -1247,6 +1237,12 @@ ash::LauncherID ChromeLauncherController::CreateAppShortcutLauncherItemWithType(
}
void ChromeLauncherController::UpdateBrowserItemStatus() {
+ // This check needs for win7_aura. UpdateBrowserItemStatus() access Shell.
+ // Without this ChromeLauncherControllerTest.BrowserMenuGeneration test will
+ // fail.
+ if (!ash::Shell::HasInstance())
+ return;
+
// Determine the new browser's active state and change if necessary.
size_t browser_index = ash::launcher::GetBrowserItemIndex(*model_);
DCHECK_GE(browser_index, 0u);
@@ -1526,7 +1522,6 @@ ash::LauncherID ChromeLauncherController::InsertAppLauncherItem(
ash::LauncherItem item;
item.type = launcher_item_type;
- item.is_incognito = false;
item.image = extensions::IconsInfo::GetDefaultAppIcon();
WebContents* active_tab = GetLastActiveWebContents(app_id);
@@ -1590,7 +1585,6 @@ ChromeLauncherController::GetBrowserShortcutLauncherItemController() {
ash::LauncherID ChromeLauncherController::CreateBrowserShortcutLauncherItem() {
ash::LauncherItem browser_shortcut;
browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT;
- browser_shortcut.is_incognito = false;
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32);
ash::LauncherID id = model_->next_id();
@@ -1663,7 +1657,6 @@ void ChromeLauncherController::RegisterLauncherItemDelegate() {
// is created.
ash::LauncherItemDelegateManager* manager =
ash::Shell::GetInstance()->launcher_item_delegate_manager();
- manager->RegisterLauncherItemDelegate(ash::TYPE_TABBED, this);
manager->RegisterLauncherItemDelegate(ash::TYPE_APP_PANEL, this);
manager->RegisterLauncherItemDelegate(ash::TYPE_APP_SHORTCUT, this);
manager->RegisterLauncherItemDelegate(ash::TYPE_BROWSER_SHORTCUT, this);
diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h
index 5ae9218..4cd78e9 100644
--- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h
+++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h
@@ -29,7 +29,6 @@
#include "chrome/browser/prefs/pref_service_syncable_observer.h"
#include "chrome/browser/ui/ash/app_sync_ui_state_observer.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h"
-#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h"
#include "content/public/browser/notification_observer.h"
#include "ui/aura/window_observer.h"
@@ -37,6 +36,7 @@
class AppSyncUIState;
class Browser;
class BrowserShortcutLauncherItemController;
+class BrowserStatusMonitor;
class ExtensionEnableFlow;
class GURL;
class LauncherItemController;
@@ -84,7 +84,6 @@ class ChromeLauncherController : public ash::LauncherDelegate,
public PrefServiceSyncableObserver,
public AppSyncUIStateObserver,
public ExtensionEnableFlowDelegate,
- public chrome::BrowserListObserver,
public ash::ShelfLayoutManagerObserver {
public:
// Indicates if a launcher item is incognito or not.
@@ -361,9 +360,6 @@ class ChromeLauncherController : public ash::LauncherDelegate,
// If |web_contents| has not loaded, returns "Net Tab".
string16 GetAppListTitle(content::WebContents* web_contents) const;
- // Overridden from chrome::BrowserListObserver.
- virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
-
// Returns true when the given |browser| is listed in the browser application
// list.
bool IsBrowserRepresentedInBrowserList(Browser* browser);
@@ -371,6 +367,9 @@ class ChromeLauncherController : public ash::LauncherDelegate,
// Returns the LauncherItemController of BrowserShortcut.
LauncherItemController* GetBrowserShortcutLauncherItemController();
+ // Updates the activation state of the Broswer item.
+ void UpdateBrowserItemStatus();
+
protected:
// Creates a new app shortcut item and controller on the launcher at |index|.
// Use kInsertItemAtEnd to add a shortcut as the last item.
@@ -401,9 +400,6 @@ class ChromeLauncherController : public ash::LauncherDelegate,
int index,
ash::LauncherItemType launcher_item_type);
- // Updates the activation state of the Broswer item.
- void UpdateBrowserItemStatus();
-
// Returns the profile used for new windows.
Profile* GetProfileForNewWindows();
@@ -513,6 +509,9 @@ class ChromeLauncherController : public ash::LauncherDelegate,
// The owned browser shortcut item.
scoped_ptr<BrowserShortcutLauncherItemController> browser_item_controller_;
+ // The owned browser status monitor.
+ scoped_ptr<BrowserStatusMonitor> browser_status_monitor_;
+
// If true, incoming pinned state changes should be ignored.
bool ignore_persist_pinned_state_change_;
diff --git a/chrome/browser/ui/ash/launcher/launcher_favicon_loader.cc b/chrome/browser/ui/ash/launcher/launcher_favicon_loader.cc
index 442e458..2b63cfd 100644
--- a/chrome/browser/ui/ash/launcher/launcher_favicon_loader.cc
+++ b/chrome/browser/ui/ash/launcher/launcher_favicon_loader.cc
@@ -4,9 +4,9 @@
#include "chrome/browser/ui/ash/launcher/launcher_favicon_loader.h"
+#include "ash/launcher/launcher_types.h"
#include "base/logging.h"
#include "base/memory/weak_ptr.h"
-#include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
diff --git a/chrome/browser/ui/ash/launcher/launcher_item_controller.cc b/chrome/browser/ui/ash/launcher/launcher_item_controller.cc
index d0cb781..f8858bc 100644
--- a/chrome/browser/ui/ash/launcher/launcher_item_controller.cc
+++ b/chrome/browser/ui/ash/launcher/launcher_item_controller.cc
@@ -48,8 +48,6 @@ ash::LauncherItemType LauncherItemController::GetLauncherItemType() const {
return ash::TYPE_PLATFORM_APP;
case LauncherItemController::TYPE_APP_PANEL:
return ash::TYPE_APP_PANEL;
- case LauncherItemController::TYPE_TABBED:
- return ash::TYPE_TABBED;
}
NOTREACHED();
return ash::TYPE_APP_SHORTCUT;
diff --git a/chrome/browser/ui/ash/launcher/launcher_item_controller.h b/chrome/browser/ui/ash/launcher/launcher_item_controller.h
index 631a66f..c374b1f 100644
--- a/chrome/browser/ui/ash/launcher/launcher_item_controller.h
+++ b/chrome/browser/ui/ash/launcher/launcher_item_controller.h
@@ -32,7 +32,6 @@ class LauncherItemController {
TYPE_APP,
TYPE_APP_PANEL,
TYPE_SHORTCUT,
- TYPE_TABBED,
TYPE_WINDOWED_APP
};
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index f191d07..975abcc 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -132,7 +132,6 @@
#include "ash/launcher/launcher_model.h"
#include "ash/shell.h"
#include "chrome/browser/ui/ash/ash_util.h"
-#include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h"
#endif
#if defined(USE_AURA)
@@ -422,12 +421,6 @@ BrowserView::BrowserView()
}
BrowserView::~BrowserView() {
-#if defined(USE_ASH)
- // Destroy BrowserLauncherItemController early on as it listens to the
- // TabstripModel, which is destroyed by the browser.
- launcher_item_controller_.reset();
-#endif
-
// Immersive mode may need to reparent views before they are removed/deleted.
immersive_mode_controller_.reset();
@@ -634,8 +627,6 @@ void BrowserView::Show() {
return;
}
- CreateLauncherIcon();
-
// Showing the window doesn't make the browser window active right away.
// This can cause SetFocusToLocationBar() to skip setting focus to the
// location bar. To avoid this we explicilty let SetFocusToLocationBar()
@@ -666,7 +657,6 @@ void BrowserView::Show() {
void BrowserView::ShowInactive() {
if (frame_->IsVisible())
return;
- CreateLauncherIcon();
frame_->ShowInactive();
}
@@ -1656,11 +1646,6 @@ views::ClientView* BrowserView::CreateClientView(views::Widget* widget) {
void BrowserView::OnWidgetActivationChanged(views::Widget* widget,
bool active) {
-#if defined(USE_ASH)
- if (launcher_item_controller_.get())
- launcher_item_controller_->BrowserActivationStateChanged();
-#endif
-
if (active)
BrowserList::SetLastActive(browser_.get());
}
@@ -2524,16 +2509,6 @@ void BrowserView::UpdateAcceleratorMetrics(
#endif
}
-void BrowserView::CreateLauncherIcon() {
-#if defined(USE_ASH)
- if (chrome::IsNativeWindowInAsh(GetNativeWindow()) &&
- !launcher_item_controller_.get()) {
- launcher_item_controller_.reset(
- BrowserLauncherItemController::Create(browser_.get()));
- }
-#endif // defined(USE_ASH)
-}
-
// static
BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) {
// Create the view and the frame. The frame will attach itself via the view
diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h
index 4c865e0..72e94e7 100644
--- a/chrome/browser/ui/views/frame/browser_view.h
+++ b/chrome/browser/ui/views/frame/browser_view.h
@@ -61,10 +61,6 @@ class TopContainerView;
class JumpList;
#endif
-#if defined(USE_ASH)
-class BrowserLauncherItemController;
-#endif
-
namespace autofill {
class PasswordGenerator;
}
@@ -256,17 +252,6 @@ class BrowserView : public BrowserWindow,
// animations.
void ToolbarSizeChanged(bool is_animating);
-#if defined(USE_ASH)
- // Test support.
- // Note: This is only needed to be BrowserLauncherItemController instead of
- // LauncherItemController because of the "favicon_loader" member - to be more
- // exact that member function is the only one being called.
- // TODO(skuhne): Remove once per-app is default.
- BrowserLauncherItemController* launcher_item_controller() const {
- return launcher_item_controller_.get();
- }
-#endif
-
// Overridden from BrowserWindow:
virtual void Show() OVERRIDE;
virtual void ShowInactive() OVERRIDE;
@@ -583,9 +568,6 @@ class BrowserView : public BrowserWindow,
void UpdateAcceleratorMetrics(const ui::Accelerator& accelerator,
int command_id);
- // Create an icon for this window in the launcher (currently only for Ash).
- void CreateLauncherIcon();
-
// Calls |method| which is either RenderWidgetHost::Cut, ::Copy, or ::Paste,
// first trying the content WebContents, then the devtools WebContents, and
// lastly the Views::Textfield if one is focused.
@@ -745,13 +727,6 @@ class BrowserView : public BrowserWindow,
scoped_refptr<JumpList> jumplist_;
#endif
-#if defined(USE_ASH)
- // Needs to be BrowserLauncerItemController for
- // "BrowserActivationStateChanged" and "favicon_loader".
- // TODO(skuhne): Remove once per-app is default.
- scoped_ptr<BrowserLauncherItemController> launcher_item_controller_;
-#endif
-
// The timer used to update frames for the Loading Animation.
base::RepeatingTimer<BrowserView> loading_animation_timer_;
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index ff550f5..f2d4270 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -223,10 +223,10 @@
'browser/ui/ash/ime_controller_chromeos.h',
'browser/ui/ash/launcher/app_shortcut_launcher_item_controller.cc',
'browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h',
- 'browser/ui/ash/launcher/browser_launcher_item_controller.cc',
- 'browser/ui/ash/launcher/browser_launcher_item_controller.h',
'browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.cc',
'browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.h',
+ 'browser/ui/ash/launcher/browser_status_monitor.cc',
+ 'browser/ui/ash/launcher/browser_status_monitor.h',
'browser/ui/ash/launcher/chrome_launcher_app_menu_item.cc',
'browser/ui/ash/launcher/chrome_launcher_app_menu_item.h',
'browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.cc',