#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/settings_window_manager.h"
+#include "chrome/browser/ui/settings_window_manager_observer.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 "ui/aura/client/activation_client.h"
-#include "ui/aura/root_window.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "grit/ash_resources.h"
+#include "grit/generated_resources.h"
#include "ui/aura/window.h"
+#include "ui/aura/window_event_dispatcher.h"
+#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/screen.h"
+#include "ui/wm/public/activation_client.h"
+
+// This class monitors the WebContent of the all tab and notifies a navigation
+// to the BrowserStatusMonitor.
+class BrowserStatusMonitor::LocalWebContentsObserver
+ : public content::WebContentsObserver {
+ public:
+ LocalWebContentsObserver(content::WebContents* contents,
+ BrowserStatusMonitor* monitor)
+ : content::WebContentsObserver(contents),
+ monitor_(monitor) {}
+
+ virtual ~LocalWebContentsObserver() {}
+
+ // content::WebContentsObserver
+ virtual void DidNavigateMainFrame(
+ const content::LoadCommittedDetails& details,
+ const content::FrameNavigateParams& params) OVERRIDE {
+ Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
+ ChromeLauncherController::AppState state =
+ ChromeLauncherController::APP_STATE_INACTIVE;
+ if (browser->window()->IsActive() &&
+ browser->tab_strip_model()->GetActiveWebContents() == web_contents())
+ state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE;
+ else if (browser->window()->IsActive())
+ state = ChromeLauncherController::APP_STATE_ACTIVE;
+
+ monitor_->UpdateAppItemState(web_contents(), state);
+ monitor_->UpdateBrowserItemState();
+
+ // Navigating may change the ShelfID associated with the WebContents.
+ if (browser->tab_strip_model()->GetActiveWebContents() == web_contents())
+ monitor_->SetShelfIDForBrowserWindowContents(browser, web_contents());
+ }
-BrowserStatusMonitor::LocalWebContentsObserver::LocalWebContentsObserver(
- content::WebContents* contents,
- BrowserStatusMonitor* monitor)
- : content::WebContentsObserver(contents),
- monitor_(monitor) {
-}
-
-BrowserStatusMonitor::LocalWebContentsObserver::~LocalWebContentsObserver() {
-}
-
-void BrowserStatusMonitor::LocalWebContentsObserver::DidNavigateMainFrame(
- const content::LoadCommittedDetails& details,
- const content::FrameNavigateParams& params) {
- Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
- ChromeLauncherController::AppState state =
- ChromeLauncherController::APP_STATE_INACTIVE;
- if (browser->window()->IsActive() &&
- browser->tab_strip_model()->GetActiveWebContents() == web_contents())
- state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE;
- else if (browser->window()->IsActive())
- state = ChromeLauncherController::APP_STATE_ACTIVE;
-
- monitor_->UpdateAppItemState(web_contents(), state);
- monitor_->UpdateBrowserItemState();
+ virtual void WebContentsDestroyed() OVERRIDE {
+ // We can only come here when there was a non standard termination like
+ // an app got un-installed while running, etc.
+ monitor_->WebContentsDestroyed(web_contents());
+ // |this| is gone now.
+ }
- // Navigating may change the LauncherID associated with the WebContents.
- if (browser->tab_strip_model()->GetActiveWebContents() == web_contents()) {
- ash::SetLauncherIDForWindow(
- monitor_->GetLauncherIDForWebContents(web_contents()),
- browser->window()->GetNativeWindow());
+ private:
+ BrowserStatusMonitor* monitor_;
+
+ DISALLOW_COPY_AND_ASSIGN(LocalWebContentsObserver);
+};
+
+// Observes any new settings windows and sets their shelf icon (since they
+// are excluded from BrowserShortcutLauncherItem).
+class BrowserStatusMonitor::SettingsWindowObserver
+ : public chrome::SettingsWindowManagerObserver {
+ public:
+ SettingsWindowObserver() {}
+ virtual ~SettingsWindowObserver() {}
+
+ // SettingsWindowManagerObserver
+ virtual void OnNewSettingsWindow(Browser* settings_browser) OVERRIDE {
+ ash::SetShelfItemDetailsForDialogWindow(
+ settings_browser->window()->GetNativeWindow(),
+ IDR_ASH_SHELF_ICON_SETTINGS,
+ l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE));
}
-}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SettingsWindowObserver);
+};
BrowserStatusMonitor::BrowserStatusMonitor(
ChromeLauncherController* launcher_controller)
: launcher_controller_(launcher_controller),
observed_activation_clients_(this),
- observed_root_windows_(this) {
+ observed_root_windows_(this),
+ settings_window_observer_(new SettingsWindowObserver) {
DCHECK(launcher_controller_);
BrowserList::AddObserver(this);
+ chrome::SettingsWindowManager::GetInstance()->AddObserver(
+ settings_window_observer_.get());
// This check needs for win7_aura. Without this, all tests in
// ChromeLauncherController will fail in win7_aura.
ChromeLauncherController::AppState app_state) {
DCHECK(contents);
// It is possible to come here from Browser::SwapTabContent where the contents
- // cannot be associated with a browser.
+ // cannot be associated with a browser. A removal however should be properly
+ // processed.
Browser* browser = chrome::FindBrowserWithWebContents(contents);
- if (browser && launcher_controller_->IsBrowserFromActiveUser(browser))
+ if (app_state == ChromeLauncherController::APP_STATE_REMOVED ||
+ (browser && launcher_controller_->IsBrowserFromActiveUser(browser)))
launcher_controller_->UpdateAppState(contents, app_state);
}
UpdateBrowserItemState();
}
-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::Window* root_window = ash::Shell::GetInstance()->
// Do nothing here.
}
+void BrowserStatusMonitor::OnDisplayMetricsChanged(const gfx::Display&,
+ uint32_t) {
+ // Do nothing here.
+}
+
void BrowserStatusMonitor::ActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
ChromeLauncherController::APP_STATE_ACTIVE;
UpdateAppItemState(new_contents, state);
UpdateBrowserItemState();
- ash::SetLauncherIDForWindow(
- GetLauncherIDForWebContents(new_contents),
- browser->window()->GetNativeWindow());
+ SetShelfIDForBrowserWindowContents(browser, new_contents);
}
}
UpdateAppItemState(new_contents, state);
UpdateBrowserItemState();
- if (tab_strip_model->GetActiveWebContents() == new_contents) {
- ash::SetLauncherIDForWindow(
- GetLauncherIDForWebContents(new_contents),
- browser->window()->GetNativeWindow());
- }
+ if (tab_strip_model->GetActiveWebContents() == new_contents)
+ SetShelfIDForBrowserWindowContents(browser, new_contents);
AddWebContentsObserver(new_contents);
}
RemoveWebContentsObserver(contents);
}
+void BrowserStatusMonitor::WebContentsDestroyed(
+ content::WebContents* contents) {
+ UpdateAppItemState(contents, ChromeLauncherController::APP_STATE_REMOVED);
+ RemoveWebContentsObserver(contents);
+}
+
void BrowserStatusMonitor::AddV1AppToShelf(Browser* browser) {
DCHECK(browser->is_type_popup() && browser->is_app());
webcontents_to_observer_map_.erase(contents);
}
-ash::LauncherID BrowserStatusMonitor::GetLauncherIDForWebContents(
+ash::ShelfID BrowserStatusMonitor::GetShelfIDForWebContents(
content::WebContents* contents) {
- return launcher_controller_->GetLauncherIDForWebContents(contents);
+ return launcher_controller_->GetShelfIDForWebContents(contents);
+}
+
+void BrowserStatusMonitor::SetShelfIDForBrowserWindowContents(
+ Browser* browser,
+ content::WebContents* web_contents) {
+ launcher_controller_->GetBrowserShortcutLauncherItemController()->
+ SetShelfIDForBrowserWindowContents(browser, web_contents);
}