browser_window_property_manager_win.cc revision 0f1bc08d4cfcc34181b0b5cbf065c40f687bf740
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 3// found in the LICENSE file. 4 5#include "chrome/browser/ui/views/frame/browser_window_property_manager_win.h" 6 7#include "base/command_line.h" 8#include "base/prefs/pref_service.h" 9#include "base/strings/utf_string_conversions.h" 10#include "base/win/windows_version.h" 11#include "chrome/browser/browser_process.h" 12#include "chrome/browser/profiles/profile.h" 13#include "chrome/browser/profiles/profile_manager.h" 14#include "chrome/browser/profiles/profile_shortcut_manager_win.h" 15#include "chrome/browser/shell_integration.h" 16#include "chrome/browser/ui/host_desktop.h" 17#include "chrome/browser/ui/views/frame/browser_view.h" 18#include "chrome/common/pref_names.h" 19#include "ui/base/win/shell.h" 20#include "ui/views/win/hwnd_util.h" 21 22BrowserWindowPropertyManager::BrowserWindowPropertyManager(BrowserView* view) 23 : view_(view) { 24 DCHECK(view_); 25 profile_pref_registrar_.Init(view_->browser()->profile()->GetPrefs()); 26 27 // Monitor the profile icon version on Windows so that we can set the browser 28 // relaunch icon when the version changes (e.g on initial icon creation). 29 profile_pref_registrar_.Add( 30 prefs::kProfileIconVersion, 31 base::Bind(&BrowserWindowPropertyManager::OnProfileIconVersionChange, 32 base::Unretained(this))); 33} 34 35BrowserWindowPropertyManager::~BrowserWindowPropertyManager() { 36} 37 38void BrowserWindowPropertyManager::UpdateWindowProperties(HWND hwnd) { 39 DCHECK(hwnd); 40 Browser* browser = view_->browser(); 41 Profile* profile = browser->profile(); 42 43 // Set the app user model id for this application to that of the application 44 // name. See http://crbug.com/7028. 45 string16 app_id = browser->is_app() ? 46 ShellIntegration::GetAppModelIdForProfile(UTF8ToWide(browser->app_name()), 47 profile->GetPath()) : 48 ShellIntegration::GetChromiumModelIdForProfile(profile->GetPath()); 49 string16 icon_path_string; 50 string16 command_line_string; 51 string16 pinned_name; 52 ProfileManager* profile_manager = g_browser_process->profile_manager(); 53 ProfileShortcutManager* shortcut_manager = NULL; 54 55 // The profile manager may be NULL in testing. 56 if (profile_manager) 57 shortcut_manager = profile_manager->profile_shortcut_manager(); 58 59 if (shortcut_manager && 60 profile->GetPrefs()->HasPrefPath(prefs::kProfileIconVersion)) { 61 const base::FilePath& profile_path = profile->GetPath(); 62 63 // Set relaunch details to use profile. 64 CommandLine command_line(CommandLine::NO_PROGRAM); 65 base::FilePath icon_path; 66 shortcut_manager->GetShortcutProperties(profile_path, &command_line, 67 &pinned_name, &icon_path); 68 command_line_string = command_line.GetCommandLineString(); 69 icon_path_string = icon_path.value(); 70 } 71 ui::win::SetAppDetailsForWindow( 72 app_id, 73 icon_path_string, 74 command_line_string, 75 pinned_name, 76 hwnd); 77} 78 79// static 80scoped_ptr<BrowserWindowPropertyManager> 81 BrowserWindowPropertyManager::CreateBrowserWindowPropertyManager( 82 BrowserView* view) { 83 if (base::win::GetVersion() < base::win::VERSION_WIN7 || 84 view->browser()->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) { 85 return scoped_ptr<BrowserWindowPropertyManager>(); 86 } 87 88 return scoped_ptr<BrowserWindowPropertyManager>( 89 new BrowserWindowPropertyManager(view)); 90} 91 92void BrowserWindowPropertyManager::OnProfileIconVersionChange() { 93 UpdateWindowProperties(views::HWNDForNativeWindow(view_->GetNativeWindow())); 94} 95