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