| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser_status_monitor.h" | 5 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_window_aura.h" | |
| 8 #include "ash/common/shelf/shelf_item_types.h" | 7 #include "ash/common/shelf/shelf_item_types.h" |
| 9 #include "ash/common/wm_window_property.h" | |
| 10 #include "ash/common/wm_window_tracker.h" | |
| 11 #include "ash/resources/grit/ash_resources.h" | |
| 12 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 13 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
| 14 #include "base/macros.h" | 10 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 16 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" | 12 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" |
| 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" | 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" |
| 19 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_finder.h" | 16 #include "chrome/browser/ui/browser_finder.h" |
| 21 #include "chrome/browser/ui/browser_list.h" | 17 #include "chrome/browser/ui/browser_list.h" |
| 22 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
| 23 #include "chrome/browser/ui/settings_window_manager.h" | |
| 24 #include "chrome/browser/ui/settings_window_manager_observer.h" | |
| 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 26 #include "chrome/browser/web_applications/web_app.h" | 20 #include "chrome/browser/web_applications/web_app.h" |
| 27 #include "components/strings/grit/components_strings.h" | |
| 28 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/browser/web_contents_observer.h" | 22 #include "content/public/browser/web_contents_observer.h" |
| 30 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
| 31 #include "ui/aura/window_event_dispatcher.h" | 24 #include "ui/aura/window_event_dispatcher.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | |
| 33 #include "ui/wm/public/activation_client.h" | 25 #include "ui/wm/public/activation_client.h" |
| 34 | 26 |
| 35 // This class monitors the WebContent of the all tab and notifies a navigation | 27 // This class monitors the WebContent of the all tab and notifies a navigation |
| 36 // to the BrowserStatusMonitor. | 28 // to the BrowserStatusMonitor. |
| 37 class BrowserStatusMonitor::LocalWebContentsObserver | 29 class BrowserStatusMonitor::LocalWebContentsObserver |
| 38 : public content::WebContentsObserver { | 30 : public content::WebContentsObserver { |
| 39 public: | 31 public: |
| 40 LocalWebContentsObserver(content::WebContents* contents, | 32 LocalWebContentsObserver(content::WebContents* contents, |
| 41 BrowserStatusMonitor* monitor) | 33 BrowserStatusMonitor* monitor) |
| 42 : content::WebContentsObserver(contents), | 34 : content::WebContentsObserver(contents), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 monitor_->WebContentsDestroyed(web_contents()); | 67 monitor_->WebContentsDestroyed(web_contents()); |
| 76 // |this| is gone now. | 68 // |this| is gone now. |
| 77 } | 69 } |
| 78 | 70 |
| 79 private: | 71 private: |
| 80 BrowserStatusMonitor* monitor_; | 72 BrowserStatusMonitor* monitor_; |
| 81 | 73 |
| 82 DISALLOW_COPY_AND_ASSIGN(LocalWebContentsObserver); | 74 DISALLOW_COPY_AND_ASSIGN(LocalWebContentsObserver); |
| 83 }; | 75 }; |
| 84 | 76 |
| 85 // Observes any new settings windows and sets their shelf icon (since they | |
| 86 // are excluded from BrowserShortcutLauncherItem). | |
| 87 class BrowserStatusMonitor::SettingsWindowObserver | |
| 88 : public chrome::SettingsWindowManagerObserver, | |
| 89 public ash::WmWindowTracker { | |
| 90 public: | |
| 91 SettingsWindowObserver() {} | |
| 92 ~SettingsWindowObserver() override {} | |
| 93 | |
| 94 // SettingsWindowManagerObserver: | |
| 95 void OnNewSettingsWindow(Browser* settings_browser) override { | |
| 96 aura::Window* aura_window = settings_browser->window()->GetNativeWindow(); | |
| 97 ash::WmWindow* window = ash::WmWindowAura::Get(aura_window); | |
| 98 window->SetTitle(l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); | |
| 99 window->SetIntProperty(ash::WmWindowProperty::SHELF_ITEM_TYPE, | |
| 100 ash::TYPE_DIALOG); | |
| 101 window->SetIntProperty(ash::WmWindowProperty::SHELF_ICON_RESOURCE_ID, | |
| 102 IDR_ASH_SHELF_ICON_SETTINGS); | |
| 103 Add(window); | |
| 104 } | |
| 105 | |
| 106 // ash::WmWindowTracker: | |
| 107 void OnWindowTitleChanged(ash::WmWindow* window) override { | |
| 108 // Name the window "Settings" instead of "Google Chrome - Settings". | |
| 109 if (window->GetTitle() != l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)) | |
| 110 window->SetTitle(l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); | |
| 111 } | |
| 112 | |
| 113 private: | |
| 114 DISALLOW_COPY_AND_ASSIGN(SettingsWindowObserver); | |
| 115 }; | |
| 116 | |
| 117 BrowserStatusMonitor::BrowserStatusMonitor( | 77 BrowserStatusMonitor::BrowserStatusMonitor( |
| 118 ChromeLauncherController* launcher_controller) | 78 ChromeLauncherController* launcher_controller) |
| 119 : launcher_controller_(launcher_controller), | 79 : launcher_controller_(launcher_controller), |
| 120 settings_window_observer_(new SettingsWindowObserver), | |
| 121 browser_tab_strip_tracker_(this, this, this) { | 80 browser_tab_strip_tracker_(this, this, this) { |
| 122 DCHECK(launcher_controller_); | 81 DCHECK(launcher_controller_); |
| 123 | 82 |
| 124 chrome::SettingsWindowManager::GetInstance()->AddObserver( | |
| 125 settings_window_observer_.get()); | |
| 126 ash::Shell::GetInstance()->activation_client()->AddObserver(this); | 83 ash::Shell::GetInstance()->activation_client()->AddObserver(this); |
| 127 | 84 |
| 128 browser_tab_strip_tracker_.Init( | 85 browser_tab_strip_tracker_.Init( |
| 129 BrowserTabStripTracker::InitWith::ALL_BROWERS); | 86 BrowserTabStripTracker::InitWith::ALL_BROWERS); |
| 130 } | 87 } |
| 131 | 88 |
| 132 BrowserStatusMonitor::~BrowserStatusMonitor() { | 89 BrowserStatusMonitor::~BrowserStatusMonitor() { |
| 133 ash::Shell::GetInstance()->activation_client()->RemoveObserver(this); | 90 ash::Shell::GetInstance()->activation_client()->RemoveObserver(this); |
| 134 chrome::SettingsWindowManager::GetInstance()->RemoveObserver( | |
| 135 settings_window_observer_.get()); | |
| 136 | |
| 137 browser_tab_strip_tracker_.StopObservingAndSendOnBrowserRemoved(); | 91 browser_tab_strip_tracker_.StopObservingAndSendOnBrowserRemoved(); |
| 138 } | 92 } |
| 139 | 93 |
| 140 void BrowserStatusMonitor::UpdateAppItemState( | 94 void BrowserStatusMonitor::UpdateAppItemState( |
| 141 content::WebContents* contents, | 95 content::WebContents* contents, |
| 142 ChromeLauncherController::AppState app_state) { | 96 ChromeLauncherController::AppState app_state) { |
| 143 DCHECK(contents); | 97 DCHECK(contents); |
| 144 // It is possible to come here from Browser::SwapTabContent where the contents | 98 // It is possible to come here from Browser::SwapTabContent where the contents |
| 145 // cannot be associated with a browser. A removal however should be properly | 99 // cannot be associated with a browser. A removal however should be properly |
| 146 // processed. | 100 // processed. |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 content::WebContents* contents) { | 286 content::WebContents* contents) { |
| 333 return launcher_controller_->GetShelfIDForWebContents(contents); | 287 return launcher_controller_->GetShelfIDForWebContents(contents); |
| 334 } | 288 } |
| 335 | 289 |
| 336 void BrowserStatusMonitor::SetShelfIDForBrowserWindowContents( | 290 void BrowserStatusMonitor::SetShelfIDForBrowserWindowContents( |
| 337 Browser* browser, | 291 Browser* browser, |
| 338 content::WebContents* web_contents) { | 292 content::WebContents* web_contents) { |
| 339 launcher_controller_->GetBrowserShortcutLauncherItemController()-> | 293 launcher_controller_->GetBrowserShortcutLauncherItemController()-> |
| 340 SetShelfIDForBrowserWindowContents(browser, web_contents); | 294 SetShelfIDForBrowserWindowContents(browser, web_contents); |
| 341 } | 295 } |
| OLD | NEW |