Chromium Code Reviews| 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" | 7 #include "ash/aura/wm_window_aura.h" |
| 8 #include "ash/common/shelf/shelf_item_types.h" | 8 #include "ash/common/shelf/shelf_item_types.h" |
| 9 #include "ash/common/wm_window_property.h" | 9 #include "ash/common/wm_window_property.h" |
| 10 #include "ash/common/wm_window_tracker.h" | |
| 10 #include "ash/resources/grit/ash_resources.h" | 11 #include "ash/resources/grit/ash_resources.h" |
| 11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 12 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 15 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" | 16 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" |
| 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" | 18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" |
| 18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
| 20 #include "chrome/browser/ui/browser_list.h" | 21 #include "chrome/browser/ui/browser_list.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chrome/browser/ui/settings_window_manager.h" | 23 #include "chrome/browser/ui/settings_window_manager.h" |
| 23 #include "chrome/browser/ui/settings_window_manager_observer.h" | 24 #include "chrome/browser/ui/settings_window_manager_observer.h" |
| 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 25 #include "chrome/browser/web_applications/web_app.h" | 26 #include "chrome/browser/web_applications/web_app.h" |
| 26 #include "chrome/grit/generated_resources.h" | |
| 27 #include "components/strings/grit/components_strings.h" | 27 #include "components/strings/grit/components_strings.h" |
| 28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/browser/web_contents_observer.h" | 29 #include "content/public/browser/web_contents_observer.h" |
| 30 #include "ui/aura/window.h" | 30 #include "ui/aura/window.h" |
| 31 #include "ui/aura/window_event_dispatcher.h" | 31 #include "ui/aura/window_event_dispatcher.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 33 #include "ui/wm/public/activation_client.h" | 33 #include "ui/wm/public/activation_client.h" |
| 34 | 34 |
| 35 // This class monitors the WebContent of the all tab and notifies a navigation | 35 // This class monitors the WebContent of the all tab and notifies a navigation |
| 36 // to the BrowserStatusMonitor. | 36 // to the BrowserStatusMonitor. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 BrowserStatusMonitor* monitor_; | 80 BrowserStatusMonitor* monitor_; |
| 81 | 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(LocalWebContentsObserver); | 82 DISALLOW_COPY_AND_ASSIGN(LocalWebContentsObserver); |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 // Observes any new settings windows and sets their shelf icon (since they | 85 // Observes any new settings windows and sets their shelf icon (since they |
| 86 // are excluded from BrowserShortcutLauncherItem). | 86 // are excluded from BrowserShortcutLauncherItem). |
| 87 class BrowserStatusMonitor::SettingsWindowObserver | 87 class BrowserStatusMonitor::SettingsWindowObserver |
| 88 : public chrome::SettingsWindowManagerObserver { | 88 : public chrome::SettingsWindowManagerObserver, |
| 89 public ash::WmWindowTracker { | |
|
James Cook
2016/09/29 02:49:46
Neat, I wasn't familiar with this.
msw
2016/09/29 06:23:36
Yeah, seems like commonly desired observer behavio
| |
| 89 public: | 90 public: |
| 90 SettingsWindowObserver() {} | 91 SettingsWindowObserver() {} |
| 91 ~SettingsWindowObserver() override {} | 92 ~SettingsWindowObserver() override {} |
| 92 | 93 |
| 93 // SettingsWindowManagerObserver | 94 // SettingsWindowManagerObserver: |
| 94 void OnNewSettingsWindow(Browser* settings_browser) override { | 95 void OnNewSettingsWindow(Browser* settings_browser) override { |
| 95 ash::ShelfItemDetails item_details; | |
| 96 item_details.type = ash::TYPE_DIALOG; | |
| 97 item_details.image_resource_id = IDR_ASH_SHELF_ICON_SETTINGS; | |
| 98 item_details.title = l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE); | |
| 99 aura::Window* aura_window = settings_browser->window()->GetNativeWindow(); | 96 aura::Window* aura_window = settings_browser->window()->GetNativeWindow(); |
| 100 ash::WmWindowAura::Get(aura_window)->SetShelfItemDetails(item_details); | 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_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)); | |
| 101 } | 111 } |
| 102 | 112 |
| 103 private: | 113 private: |
| 104 DISALLOW_COPY_AND_ASSIGN(SettingsWindowObserver); | 114 DISALLOW_COPY_AND_ASSIGN(SettingsWindowObserver); |
| 105 }; | 115 }; |
| 106 | 116 |
| 107 BrowserStatusMonitor::BrowserStatusMonitor( | 117 BrowserStatusMonitor::BrowserStatusMonitor( |
| 108 ChromeLauncherController* launcher_controller) | 118 ChromeLauncherController* launcher_controller) |
| 109 : launcher_controller_(launcher_controller), | 119 : launcher_controller_(launcher_controller), |
| 110 settings_window_observer_(new SettingsWindowObserver), | 120 settings_window_observer_(new SettingsWindowObserver), |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 content::WebContents* contents) { | 336 content::WebContents* contents) { |
| 327 return launcher_controller_->GetShelfIDForWebContents(contents); | 337 return launcher_controller_->GetShelfIDForWebContents(contents); |
| 328 } | 338 } |
| 329 | 339 |
| 330 void BrowserStatusMonitor::SetShelfIDForBrowserWindowContents( | 340 void BrowserStatusMonitor::SetShelfIDForBrowserWindowContents( |
| 331 Browser* browser, | 341 Browser* browser, |
| 332 content::WebContents* web_contents) { | 342 content::WebContents* web_contents) { |
| 333 launcher_controller_->GetBrowserShortcutLauncherItemController()-> | 343 launcher_controller_->GetBrowserShortcutLauncherItemController()-> |
| 334 SetShelfIDForBrowserWindowContents(browser, web_contents); | 344 SetShelfIDForBrowserWindowContents(browser, web_contents); |
| 335 } | 345 } |
| OLD | NEW |