OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/help/help_handler.h" | 5 #include "chrome/browser/ui/webui/help/help_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "chrome/common/chrome_content_client.h" | 26 #include "chrome/common/chrome_content_client.h" |
27 #include "chrome/common/chrome_version_info.h" | 27 #include "chrome/common/chrome_version_info.h" |
28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
29 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
30 #include "chrome/grit/chromium_strings.h" | 30 #include "chrome/grit/chromium_strings.h" |
31 #include "chrome/grit/generated_resources.h" | 31 #include "chrome/grit/generated_resources.h" |
32 #include "chrome/grit/google_chrome_strings.h" | 32 #include "chrome/grit/google_chrome_strings.h" |
33 #include "components/google/core/browser/google_util.h" | 33 #include "components/google/core/browser/google_util.h" |
34 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
35 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 36 #include "content/public/browser/web_contents.h" |
36 #include "content/public/browser/web_ui.h" | 37 #include "content/public/browser/web_ui.h" |
37 #include "content/public/common/user_agent.h" | 38 #include "content/public/common/user_agent.h" |
38 #include "grit/components_strings.h" | 39 #include "grit/components_strings.h" |
39 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
40 #include "v8/include/v8.h" | 41 #include "v8/include/v8.h" |
41 | 42 |
42 #if defined(OS_MACOSX) | 43 #if defined(OS_MACOSX) |
43 #include "chrome/browser/mac/obsolete_system.h" | 44 #include "chrome/browser/mac/obsolete_system.h" |
44 #endif | 45 #endif |
45 | 46 |
46 #if defined(OS_CHROMEOS) | 47 #if defined(OS_CHROMEOS) |
47 #include "base/files/file_util_proxy.h" | 48 #include "base/files/file_util_proxy.h" |
48 #include "base/i18n/time_formatting.h" | 49 #include "base/i18n/time_formatting.h" |
49 #include "base/prefs/pref_service.h" | 50 #include "base/prefs/pref_service.h" |
50 #include "base/sys_info.h" | 51 #include "base/sys_info.h" |
51 #include "base/task_runner_util.h" | 52 #include "base/task_runner_util.h" |
| 53 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
| 54 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact
ory.h" |
52 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 55 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 56 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
53 #include "chrome/browser/chromeos/settings/cros_settings.h" | 57 #include "chrome/browser/chromeos/settings/cros_settings.h" |
54 #include "chrome/browser/profiles/profile.h" | 58 #include "chrome/browser/profiles/profile.h" |
55 #include "chrome/browser/ui/webui/chromeos/image_source.h" | 59 #include "chrome/browser/ui/webui/chromeos/image_source.h" |
56 #include "chrome/browser/ui/webui/help/help_utils_chromeos.h" | 60 #include "chrome/browser/ui/webui/help/help_utils_chromeos.h" |
57 #include "chrome/browser/ui/webui/help/version_updater_chromeos.h" | 61 #include "chrome/browser/ui/webui/help/version_updater_chromeos.h" |
58 #include "chromeos/chromeos_switches.h" | 62 #include "chromeos/chromeos_switches.h" |
59 #include "chromeos/dbus/dbus_thread_manager.h" | 63 #include "chromeos/dbus/dbus_thread_manager.h" |
60 #include "chromeos/dbus/power_manager_client.h" | 64 #include "chromeos/dbus/power_manager_client.h" |
61 #include "components/user_manager/user_manager.h" | 65 #include "components/user_manager/user_manager.h" |
62 #endif | 66 #endif |
(...skipping 19 matching lines...) Expand all Loading... |
82 } | 86 } |
83 | 87 |
84 // Returns true if the device is enterprise managed, false otherwise. | 88 // Returns true if the device is enterprise managed, false otherwise. |
85 bool IsEnterpriseManaged() { | 89 bool IsEnterpriseManaged() { |
86 policy::BrowserPolicyConnectorChromeOS* connector = | 90 policy::BrowserPolicyConnectorChromeOS* connector = |
87 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 91 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
88 return connector->IsEnterpriseManaged(); | 92 return connector->IsEnterpriseManaged(); |
89 } | 93 } |
90 | 94 |
91 // Returns true if current user can change channel, false otherwise. | 95 // Returns true if current user can change channel, false otherwise. |
92 bool CanChangeChannel() { | 96 bool CanChangeChannel(Profile* profile) { |
93 bool value = false; | 97 bool value = false; |
94 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kReleaseChannelDelegated, | 98 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kReleaseChannelDelegated, |
95 &value); | 99 &value); |
96 | 100 |
97 // On a managed machine we delegate this setting to the users of the same | 101 // On a managed machine we delegate this setting to the users of the same |
98 // domain only if the policy value is "domain". | 102 // domain only if the policy value is "domain". |
99 if (IsEnterpriseManaged()) { | 103 if (IsEnterpriseManaged()) { |
100 if (!value) | 104 if (!value) |
101 return false; | 105 return false; |
102 // Get the currently logged in user and strip the domain part only. | 106 // Get the currently logged in user and strip the domain part only. |
103 std::string domain = ""; | 107 std::string domain = ""; |
104 std::string user = | 108 const user_manager::User* user = |
105 user_manager::UserManager::Get()->GetLoggedInUser()->email(); | 109 profile ? chromeos::ProfileHelper::Get()->GetUserByProfile(profile) |
106 size_t at_pos = user.find('@'); | 110 : nullptr; |
107 if (at_pos != std::string::npos && at_pos + 1 < user.length()) | 111 std::string email = user ? user->email() : std::string(); |
108 domain = user.substr(user.find('@') + 1); | 112 size_t at_pos = email.find('@'); |
| 113 if (at_pos != std::string::npos && at_pos + 1 < email.length()) |
| 114 domain = email.substr(email.find('@') + 1); |
109 policy::BrowserPolicyConnectorChromeOS* connector = | 115 policy::BrowserPolicyConnectorChromeOS* connector = |
110 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 116 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
111 return domain == connector->GetEnterpriseDomain(); | 117 return domain == connector->GetEnterpriseDomain(); |
112 } else if (user_manager::UserManager::Get()->IsCurrentUserOwner()) { | 118 } else { |
| 119 chromeos::OwnerSettingsServiceChromeOS* service = |
| 120 chromeos::OwnerSettingsServiceChromeOSFactory::GetInstance() |
| 121 ->GetForBrowserContext(profile); |
113 // On non managed machines we have local owner who is the only one to change | 122 // On non managed machines we have local owner who is the only one to change |
114 // anything. Ensure that ReleaseChannelDelegated is false. | 123 // anything. Ensure that ReleaseChannelDelegated is false. |
115 return !value; | 124 if (service && service->IsOwner()) |
| 125 return !value; |
116 } | 126 } |
117 return false; | 127 return false; |
118 } | 128 } |
119 | 129 |
120 // Reads the file containing the FCC label text, if found. Must be called from | 130 // Reads the file containing the FCC label text, if found. Must be called from |
121 // the blocking pool. | 131 // the blocking pool. |
122 std::string ReadFCCLabelText() { | 132 std::string ReadFCCLabelText() { |
123 const base::FilePath asset_dir(FILE_PATH_LITERAL(chrome::kChromeOSAssetPath)); | 133 const base::FilePath asset_dir(FILE_PATH_LITERAL(chrome::kChromeOSAssetPath)); |
124 const base::FilePath label_file_path = | 134 const base::FilePath label_file_path = |
125 asset_dir.AppendASCII(kFCCLabelTextPath); | 135 asset_dir.AppendASCII(kFCCLabelTextPath); |
126 | 136 |
127 std::string contents; | 137 std::string contents; |
128 if (base::ReadFileToString(label_file_path, &contents)) | 138 if (base::ReadFileToString(label_file_path, &contents)) |
129 return contents; | 139 return contents; |
130 return std::string(); | 140 return std::string(); |
131 } | 141 } |
132 | 142 |
133 #endif // defined(OS_CHROMEOS) | 143 #endif // defined(OS_CHROMEOS) |
134 | 144 |
135 } // namespace | 145 } // namespace |
136 | 146 |
137 HelpHandler::HelpHandler() | 147 HelpHandler::HelpHandler() |
138 : version_updater_(VersionUpdater::Create()), | 148 : version_updater_(VersionUpdater::Create(nullptr)), weak_factory_(this) { |
139 weak_factory_(this) { | |
140 } | 149 } |
141 | 150 |
142 HelpHandler::~HelpHandler() { | 151 HelpHandler::~HelpHandler() { |
143 } | 152 } |
144 | 153 |
145 void HelpHandler::GetLocalizedValues(base::DictionaryValue* localized_strings) { | 154 void HelpHandler::GetLocalizedValues(base::DictionaryValue* localized_strings) { |
146 struct L10nResources { | 155 struct L10nResources { |
147 const char* name; | 156 const char* name; |
148 int ids; | 157 int ids; |
149 }; | 158 }; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 localized_strings->SetString("jsEngineVersion", v8::V8::GetVersion()); | 292 localized_strings->SetString("jsEngineVersion", v8::V8::GetVersion()); |
284 | 293 |
285 localized_strings->SetString("userAgentInfo", GetUserAgent()); | 294 localized_strings->SetString("userAgentInfo", GetUserAgent()); |
286 | 295 |
287 CommandLine::StringType command_line = | 296 CommandLine::StringType command_line = |
288 CommandLine::ForCurrentProcess()->GetCommandLineString(); | 297 CommandLine::ForCurrentProcess()->GetCommandLineString(); |
289 localized_strings->SetString("commandLineInfo", command_line); | 298 localized_strings->SetString("commandLineInfo", command_line); |
290 } | 299 } |
291 | 300 |
292 void HelpHandler::RegisterMessages() { | 301 void HelpHandler::RegisterMessages() { |
| 302 #if defined(OS_CHROMEOS) |
| 303 version_updater_.reset( |
| 304 VersionUpdater::Create(web_ui()->GetWebContents()->GetBrowserContext())); |
| 305 #endif |
293 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 306 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
294 content::NotificationService::AllSources()); | 307 content::NotificationService::AllSources()); |
295 | 308 |
296 web_ui()->RegisterMessageCallback("onPageLoaded", | 309 web_ui()->RegisterMessageCallback("onPageLoaded", |
297 base::Bind(&HelpHandler::OnPageLoaded, base::Unretained(this))); | 310 base::Bind(&HelpHandler::OnPageLoaded, base::Unretained(this))); |
298 web_ui()->RegisterMessageCallback("relaunchNow", | 311 web_ui()->RegisterMessageCallback("relaunchNow", |
299 base::Bind(&HelpHandler::RelaunchNow, base::Unretained(this))); | 312 base::Bind(&HelpHandler::RelaunchNow, base::Unretained(this))); |
300 web_ui()->RegisterMessageCallback("openFeedbackDialog", | 313 web_ui()->RegisterMessageCallback("openFeedbackDialog", |
301 base::Bind(&HelpHandler::OpenFeedbackDialog, base::Unretained(this))); | 314 base::Bind(&HelpHandler::OpenFeedbackDialog, base::Unretained(this))); |
302 web_ui()->RegisterMessageCallback("openHelpPage", | 315 web_ui()->RegisterMessageCallback("openHelpPage", |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 loader_.GetVersion( | 371 loader_.GetVersion( |
359 chromeos::VersionLoader::VERSION_FULL, | 372 chromeos::VersionLoader::VERSION_FULL, |
360 base::Bind(&HelpHandler::OnOSVersion, base::Unretained(this)), | 373 base::Bind(&HelpHandler::OnOSVersion, base::Unretained(this)), |
361 &tracker_); | 374 &tracker_); |
362 loader_.GetFirmware( | 375 loader_.GetFirmware( |
363 base::Bind(&HelpHandler::OnOSFirmware, base::Unretained(this)), | 376 base::Bind(&HelpHandler::OnOSFirmware, base::Unretained(this)), |
364 &tracker_); | 377 &tracker_); |
365 | 378 |
366 web_ui()->CallJavascriptFunction( | 379 web_ui()->CallJavascriptFunction( |
367 "help.HelpPage.updateEnableReleaseChannel", | 380 "help.HelpPage.updateEnableReleaseChannel", |
368 base::FundamentalValue(CanChangeChannel())); | 381 base::FundamentalValue(CanChangeChannel(Profile::FromWebUI(web_ui())))); |
369 | 382 |
370 base::Time build_time = base::SysInfo::GetLsbReleaseTime(); | 383 base::Time build_time = base::SysInfo::GetLsbReleaseTime(); |
371 base::string16 build_date = base::TimeFormatFriendlyDate(build_time); | 384 base::string16 build_date = base::TimeFormatFriendlyDate(build_time); |
372 web_ui()->CallJavascriptFunction("help.HelpPage.setBuildDate", | 385 web_ui()->CallJavascriptFunction("help.HelpPage.setBuildDate", |
373 base::StringValue(build_date)); | 386 base::StringValue(build_date)); |
374 #endif // defined(OS_CHROMEOS) | 387 #endif // defined(OS_CHROMEOS) |
375 | 388 |
376 // On Chrome OS, do not check for an update automatically. | 389 // On Chrome OS, do not check for an update automatically. |
377 #if defined(OS_CHROMEOS) | 390 #if defined(OS_CHROMEOS) |
378 static_cast<VersionUpdaterCros*>(version_updater_.get())->GetUpdateStatus( | 391 static_cast<VersionUpdaterCros*>(version_updater_.get())->GetUpdateStatus( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 Browser* browser = chrome::FindBrowserWithWebContents( | 449 Browser* browser = chrome::FindBrowserWithWebContents( |
437 web_ui()->GetWebContents()); | 450 web_ui()->GetWebContents()); |
438 chrome::ShowHelp(browser, chrome::HELP_SOURCE_WEBUI); | 451 chrome::ShowHelp(browser, chrome::HELP_SOURCE_WEBUI); |
439 } | 452 } |
440 | 453 |
441 #if defined(OS_CHROMEOS) | 454 #if defined(OS_CHROMEOS) |
442 | 455 |
443 void HelpHandler::SetChannel(const base::ListValue* args) { | 456 void HelpHandler::SetChannel(const base::ListValue* args) { |
444 DCHECK(args->GetSize() == 2); | 457 DCHECK(args->GetSize() == 2); |
445 | 458 |
446 if (!CanChangeChannel()) { | 459 if (!CanChangeChannel(Profile::FromWebUI(web_ui()))) { |
447 LOG(WARNING) << "Non-owner tried to change release track."; | 460 LOG(WARNING) << "Non-owner tried to change release track."; |
448 return; | 461 return; |
449 } | 462 } |
450 | 463 |
451 base::string16 channel; | 464 base::string16 channel; |
452 bool is_powerwash_allowed; | 465 bool is_powerwash_allowed; |
453 if (!args->GetString(0, &channel) || | 466 if (!args->GetString(0, &channel) || |
454 !args->GetBoolean(1, &is_powerwash_allowed)) { | 467 !args->GetBoolean(1, &is_powerwash_allowed)) { |
455 LOG(ERROR) << "Can't parse SetChannel() args"; | 468 LOG(ERROR) << "Can't parse SetChannel() args"; |
456 return; | 469 return; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 } | 605 } |
593 | 606 |
594 void HelpHandler::OnFCCLabelTextRead(const std::string& text) { | 607 void HelpHandler::OnFCCLabelTextRead(const std::string& text) { |
595 // Remove unnecessary whitespace. | 608 // Remove unnecessary whitespace. |
596 web_ui()->CallJavascriptFunction( | 609 web_ui()->CallJavascriptFunction( |
597 "help.HelpPage.setProductLabelText", | 610 "help.HelpPage.setProductLabelText", |
598 base::StringValue(base::CollapseWhitespaceASCII(text, true))); | 611 base::StringValue(base::CollapseWhitespaceASCII(text, true))); |
599 } | 612 } |
600 | 613 |
601 #endif // defined(OS_CHROMEOS) | 614 #endif // defined(OS_CHROMEOS) |
OLD | NEW |