Index: chrome/browser/ui/ash/launcher/settings_window_observer.cc |
diff --git a/chrome/browser/ui/ash/launcher/settings_window_observer.cc b/chrome/browser/ui/ash/launcher/settings_window_observer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f7263d8e8bb74ac25f3c827cdfc8fdbd5618f914 |
--- /dev/null |
+++ b/chrome/browser/ui/ash/launcher/settings_window_observer.cc |
@@ -0,0 +1,93 @@ |
+// Copyright 2016 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/settings_window_observer.h" |
+ |
+#include "ash/common/shelf/shelf_item_types.h" |
+#include "ash/common/wm_lookup.h" |
James Cook
2016/10/01 00:16:21
I think you have a few unnecessary headers here.
msw
2016/10/03 19:14:23
Done; let me know if I missed any.
|
+#include "ash/common/wm_window.h" |
+#include "ash/common/wm_window_property.h" |
+#include "ash/resources/grit/ash_resources.h" |
+#include "ash/wm/window_properties.h" |
+#include "chrome/browser/ui/ash/ash_util.h" |
+#include "chrome/browser/ui/ash/property_util.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/settings_window_manager.h" |
+#include "chrome/browser/ui/views/frame/browser_view.h" |
+#include "components/strings/grit/components_strings.h" |
+#include "services/ui/public/cpp/property_type_converters.h" |
+#include "services/ui/public/cpp/window.h" |
+#include "services/ui/public/interfaces/window_manager.mojom.h" |
+#include "ui/aura/mus/mus_util.h" |
+#include "ui/aura/window.h" |
+#include "ui/aura/window_property.h" |
+#include "ui/base/l10n/l10n_util.h" |
+ |
+namespace { |
+ |
+class AuraWindowSettingsTitleTracker : public aura::WindowTracker { |
James Cook
2016/10/01 00:16:21
This and the class below could use a comment about
msw
2016/10/03 19:14:23
Done.
|
+ public: |
+ AuraWindowSettingsTitleTracker() {} |
+ ~AuraWindowSettingsTitleTracker() override {} |
+ |
+ // aura::WindowTracker: |
+ void OnWindowTitleChanged(aura::Window* window) override { |
+ // Name the window "Settings" instead of "Google Chrome - Settings". |
+ window->SetTitle(l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); |
+ } |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(AuraWindowSettingsTitleTracker); |
+}; |
+ |
+class UiWindowSettingsTitleTracker : public ui::WindowTracker { |
+ public: |
+ UiWindowSettingsTitleTracker() {} |
+ ~UiWindowSettingsTitleTracker() override {} |
+ |
+ // ui::WindowTracker: |
+ void OnWindowSharedPropertyChanged( |
+ ui::Window* window, |
+ const std::string& name, |
+ const std::vector<uint8_t>* old_data, |
+ const std::vector<uint8_t>* new_data) override { |
+ if (name == ui::mojom::WindowManager::kWindowTitle_Property) { |
+ // Name the window "Settings" instead of "Google Chrome - Settings". |
+ window->SetSharedProperty<base::string16>( |
+ ui::mojom::WindowManager::kWindowTitle_Property, |
+ l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); |
+ } |
+ } |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(UiWindowSettingsTitleTracker); |
+}; |
+ |
+} // namespace |
+ |
+SettingsWindowObserver::SettingsWindowObserver() |
+ : aura_window_tracker_(new AuraWindowSettingsTitleTracker), |
James Cook
2016/10/01 00:16:21
Only create the one you need based on IsRunningInM
msw
2016/10/03 19:14:23
Done.
|
+ ui_window_tracker_(new UiWindowSettingsTitleTracker) { |
+ chrome::SettingsWindowManager::GetInstance()->AddObserver(this); |
+} |
+ |
+SettingsWindowObserver::~SettingsWindowObserver() { |
+ chrome::SettingsWindowManager::GetInstance()->RemoveObserver(this); |
+} |
+ |
+void SettingsWindowObserver::OnNewSettingsWindow(Browser* settings_browser) { |
+ BrowserView* view = BrowserView::GetBrowserViewForBrowser(settings_browser); |
+ aura::Window* window = view->GetWidget()->GetNativeView(); |
+ SetTitle(window, l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); |
James Cook
2016/10/01 00:16:21
This function, and the ones below, need to be in a
msw
2016/10/03 19:14:23
Done.
|
+ SetIntProperty(window, ash::kShelfItemTypeKey, ash::TYPE_DIALOG); |
+ SetIntProperty(window, ash::kShelfIconResourceIdKey, |
+ IDR_ASH_SHELF_ICON_SETTINGS); |
+ |
+ ui::Window* ui_window = aura::GetMusWindow(window); |
+ DCHECK_EQ(chrome::IsRunningInMash(), !!ui_window); |
+ if (ui_window) |
+ ui_window_tracker_->Add(ui_window); |
+ else |
+ aura_window_tracker_->Add(window); |
+} |