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.
5 #include "chrome/browser/ui/views/frame/browser_window_property_manager_win.h"
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"
22 BrowserWindowPropertyManager::BrowserWindowPropertyManager(BrowserView
* view
)
25 profile_pref_registrar_
.Init(view_
->browser()->profile()->GetPrefs());
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)));
35 BrowserWindowPropertyManager::~BrowserWindowPropertyManager() {
38 void BrowserWindowPropertyManager::UpdateWindowProperties(HWND hwnd
) {
40 Browser
* browser
= view_
->browser();
41 Profile
* profile
= browser
->profile();
43 // Set the app user model id for this application to that of the application
44 // name. See http://crbug.com/7028.
45 base::string16 app_id
= browser
->is_app() ?
46 ShellIntegration::GetAppModelIdForProfile(
47 base::UTF8ToWide(browser
->app_name()),
49 ShellIntegration::GetChromiumModelIdForProfile(profile
->GetPath());
50 base::string16 icon_path_string
;
51 base::string16 command_line_string
;
52 base::string16 pinned_name
;
53 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
54 ProfileShortcutManager
* shortcut_manager
= NULL
;
56 // The profile manager may be NULL in testing.
58 shortcut_manager
= profile_manager
->profile_shortcut_manager();
60 if (!browser
->is_app() && shortcut_manager
&&
61 profile
->GetPrefs()->HasPrefPath(prefs::kProfileIconVersion
)) {
62 const base::FilePath
& profile_path
= profile
->GetPath();
64 // Set relaunch details to use profile.
65 CommandLine
command_line(CommandLine::NO_PROGRAM
);
66 base::FilePath icon_path
;
67 shortcut_manager
->GetShortcutProperties(profile_path
, &command_line
,
68 &pinned_name
, &icon_path
);
69 command_line_string
= command_line
.GetCommandLineString();
70 icon_path_string
= icon_path
.value();
72 ui::win::SetAppDetailsForWindow(
81 scoped_ptr
<BrowserWindowPropertyManager
>
82 BrowserWindowPropertyManager::CreateBrowserWindowPropertyManager(
84 if (base::win::GetVersion() < base::win::VERSION_WIN7
||
85 view
->browser()->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH
) {
86 return scoped_ptr
<BrowserWindowPropertyManager
>();
89 return scoped_ptr
<BrowserWindowPropertyManager
>(
90 new BrowserWindowPropertyManager(view
));
93 void BrowserWindowPropertyManager::OnProfileIconVersionChange() {
94 UpdateWindowProperties(views::HWNDForNativeWindow(view_
->GetNativeWindow()));