1 // Copyright 2016 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/ui/ash/launcher/settings_window_observer.h" 6 7 #include "ash/public/cpp/app_list/internal_app_id_constants.h" 8 #include "ash/public/cpp/shelf_item.h" 9 #include "ash/public/cpp/window_properties.h" 10 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser_window.h" 12 #include "chrome/browser/ui/settings_window_manager_chromeos.h" 13 #include "components/strings/grit/components_strings.h" 14 #include "ui/aura/window.h" 15 #include "ui/base/class_property.h" 16 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/gfx/image/image_skia.h" 18 19 namespace { 20 21 // A helper class that updates the title of Chrome OS Settings browser windows. 22 class AuraWindowSettingsTitleTracker : public aura::WindowTracker { 23 public: AuraWindowSettingsTitleTracker()24 AuraWindowSettingsTitleTracker() {} ~AuraWindowSettingsTitleTracker()25 ~AuraWindowSettingsTitleTracker() override {} 26 27 // aura::WindowTracker: OnWindowTitleChanged(aura::Window * window)28 void OnWindowTitleChanged(aura::Window* window) override { 29 // Name the window "Settings" instead of "Google Chrome - Settings". 30 window->SetTitle(l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); 31 } 32 33 private: 34 DISALLOW_COPY_AND_ASSIGN(AuraWindowSettingsTitleTracker); 35 }; 36 37 } // namespace 38 SettingsWindowObserver()39SettingsWindowObserver::SettingsWindowObserver() { 40 aura_window_tracker_ = std::make_unique<AuraWindowSettingsTitleTracker>(); 41 chrome::SettingsWindowManager::GetInstance()->AddObserver(this); 42 } 43 ~SettingsWindowObserver()44SettingsWindowObserver::~SettingsWindowObserver() { 45 chrome::SettingsWindowManager::GetInstance()->RemoveObserver(this); 46 } 47 OnNewSettingsWindow(Browser * settings_browser)48void SettingsWindowObserver::OnNewSettingsWindow(Browser* settings_browser) { 49 aura::Window* window = settings_browser->window()->GetNativeWindow(); 50 window->SetTitle(l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); 51 const ash::ShelfID shelf_id(ash::kInternalAppIdSettings); 52 window->SetProperty(ash::kShelfIDKey, shelf_id.Serialize()); 53 window->SetProperty(ash::kAppIDKey, shelf_id.app_id); 54 window->SetProperty<int>(ash::kShelfItemTypeKey, ash::TYPE_APP); 55 aura_window_tracker_->Add(window); 56 } 57