Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / views / frame / browser_window_property_manager_win.cc
blob59996a15d9702f6a49d76513f141158dce55e7e4
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/browser/web_applications/web_app.h"
19 #include "chrome/browser/web_applications/web_app_win.h"
20 #include "chrome/common/pref_names.h"
21 #include "extensions/browser/extension_registry.h"
22 #include "ui/base/win/shell.h"
23 #include "ui/views/win/hwnd_util.h"
25 using extensions::ExtensionRegistry;
27 BrowserWindowPropertyManager::BrowserWindowPropertyManager(BrowserView* view)
28 : view_(view) {
29 DCHECK(view_);
30 profile_pref_registrar_.Init(view_->browser()->profile()->GetPrefs());
32 // Monitor the profile icon version on Windows so that we can set the browser
33 // relaunch icon when the version changes (e.g on initial icon creation).
34 profile_pref_registrar_.Add(
35 prefs::kProfileIconVersion,
36 base::Bind(&BrowserWindowPropertyManager::OnProfileIconVersionChange,
37 base::Unretained(this)));
40 BrowserWindowPropertyManager::~BrowserWindowPropertyManager() {
43 void BrowserWindowPropertyManager::UpdateWindowProperties(HWND hwnd) {
44 DCHECK(hwnd);
45 Browser* browser = view_->browser();
46 Profile* profile = browser->profile();
48 // Set the app user model id for this application to that of the application
49 // name. See http://crbug.com/7028.
50 base::string16 app_id = browser->is_app() ?
51 ShellIntegration::GetAppModelIdForProfile(
52 base::UTF8ToWide(browser->app_name()),
53 profile->GetPath()) :
54 ShellIntegration::GetChromiumModelIdForProfile(profile->GetPath());
55 base::string16 icon_path_string;
56 base::string16 command_line_string;
57 base::string16 pinned_name;
58 ProfileManager* profile_manager = g_browser_process->profile_manager();
59 ProfileShortcutManager* shortcut_manager = nullptr;
61 // Apps set their relaunch details based on app's details.
62 if (browser->is_app()) {
63 ExtensionRegistry* registry = ExtensionRegistry::Get(profile);
64 const extensions::Extension* extension = registry->GetExtensionById(
65 web_app::GetExtensionIdFromApplicationName(browser->app_name()),
66 ExtensionRegistry::EVERYTHING);
67 if (extension) {
68 ui::win::SetAppIdForWindow(app_id, hwnd);
69 web_app::UpdateRelaunchDetailsForApp(profile, extension, hwnd);
70 return;
74 // The profile manager may be null in testing.
75 if (profile_manager)
76 shortcut_manager = profile_manager->profile_shortcut_manager();
78 if (!browser->is_app() && shortcut_manager &&
79 profile->GetPrefs()->HasPrefPath(prefs::kProfileIconVersion)) {
80 const base::FilePath& profile_path = profile->GetPath();
82 // Set relaunch details to use profile.
83 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
84 base::FilePath icon_path;
85 shortcut_manager->GetShortcutProperties(profile_path, &command_line,
86 &pinned_name, &icon_path);
87 command_line_string = command_line.GetCommandLineString();
88 icon_path_string = icon_path.value();
90 ui::win::SetAppDetailsForWindow(
91 app_id,
92 icon_path_string,
93 command_line_string,
94 pinned_name,
95 hwnd);
98 // static
99 scoped_ptr<BrowserWindowPropertyManager>
100 BrowserWindowPropertyManager::CreateBrowserWindowPropertyManager(
101 BrowserView* view) {
102 if (base::win::GetVersion() < base::win::VERSION_WIN7 ||
103 view->browser()->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) {
104 return scoped_ptr<BrowserWindowPropertyManager>();
107 return scoped_ptr<BrowserWindowPropertyManager>(
108 new BrowserWindowPropertyManager(view));
111 void BrowserWindowPropertyManager::OnProfileIconVersionChange() {
112 UpdateWindowProperties(views::HWNDForNativeWindow(view_->GetNativeWindow()));