Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(628)

Side by Side Diff: chrome/browser/ui/webui/settings/about_handler.cc

Issue 1971483002: MD Settings: About page, porting C++ handler and adding browser proxy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding include Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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/webui/settings/about_handler.h"
6
7 #include <stddef.h>
8
9 #include <string>
10
11 #include "ash/system/chromeos/devicetype_utils.h"
12 #include "base/bind.h"
13 #include "base/bind_helpers.h"
14 #include "base/command_line.h"
15 #include "base/files/file_path.h"
16 #include "base/files/file_util.h"
17 #include "base/location.h"
18 #include "base/macros.h"
19 #include "base/strings/string16.h"
20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_util.h"
22 #include "base/strings/utf_string_conversions.h"
23 #include "base/task_runner_util.h"
24 #include "base/values.h"
25 #include "build/build_config.h"
26 #include "chrome/browser/browser_process.h"
27 #include "chrome/browser/chrome_notification_types.h"
28 #include "chrome/browser/obsolete_system/obsolete_system.h"
29 #include "chrome/browser/ui/browser.h"
30 #include "chrome/browser/ui/browser_commands.h"
31 #include "chrome/browser/ui/browser_finder.h"
32 #include "chrome/browser/ui/chrome_pages.h"
33 #include "chrome/common/channel_info.h"
34 #include "chrome/common/chrome_content_client.h"
35 #include "chrome/common/pref_names.h"
36 #include "chrome/common/url_constants.h"
37 #include "chrome/grit/chromium_strings.h"
38 #include "chrome/grit/generated_resources.h"
39 #include "components/google/core/browser/google_util.h"
40 #include "components/policy/core/common/policy_namespace.h"
41 #include "components/version_info/version_info.h"
42 #include "content/public/browser/browser_thread.h"
43 #include "content/public/browser/notification_service.h"
44 #include "content/public/browser/web_contents.h"
45 #include "content/public/browser/web_ui.h"
46 #include "content/public/browser/web_ui_data_source.h"
47 #include "content/public/common/user_agent.h"
48 #include "grit/components_chromium_strings.h"
49 #include "grit/components_google_chrome_strings.h"
50 #include "grit/components_strings.h"
51 #include "grit/generated_resources.h"
52 #include "policy/policy_constants.h"
53 #include "ui/base/l10n/l10n_util.h"
54 #include "v8/include/v8.h"
55
56 #if defined(OS_CHROMEOS)
57 #include "base/files/file_util_proxy.h"
58 #include "base/i18n/time_formatting.h"
59 #include "base/sys_info.h"
60 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
61 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
62 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
63 #include "chrome/browser/chromeos/profiles/profile_helper.h"
64 #include "chrome/browser/chromeos/settings/cros_settings.h"
65 #include "chrome/browser/profiles/profile.h"
66 #include "chrome/browser/ui/webui/chromeos/image_source.h"
67 #include "chrome/browser/ui/webui/help/help_utils_chromeos.h"
68 #include "chrome/browser/ui/webui/help/version_updater_chromeos.h"
69 #include "chromeos/chromeos_switches.h"
70 #include "chromeos/dbus/power_manager_client.h"
71 #include "chromeos/system/statistics_provider.h"
72 #include "components/user_manager/user_manager.h"
73 #endif
74
75 using base::ListValue;
76 using content::BrowserThread;
77
78 namespace {
79
80 #if defined(OS_CHROMEOS)
81
82 // Directory containing the regulatory labels for supported regions.
83 const char kRegulatoryLabelsDirectory[] = "regulatory_labels";
84
85 // File names of the image file and the file containing alt text for the label.
86 const char kRegulatoryLabelImageFilename[] = "label.png";
87 const char kRegulatoryLabelTextFilename[] = "label.txt";
88
89 // Default region code to use if there's no label for the VPD region code.
90 const char kDefaultRegionCode[] = "us";
91
92 struct RegulatoryLabel {
93 const std::string label_text;
94 const std::string image_url;
95 };
96
97 // Returns message that informs user that for update it's better to
98 // connect to a network of one of the allowed types.
99 base::string16 GetAllowedConnectionTypesMessage() {
100 if (help_utils_chromeos::IsUpdateOverCellularAllowed()) {
101 return l10n_util::GetStringUTF16(IDS_UPGRADE_NETWORK_LIST_CELLULAR_ALLOWED);
102 } else {
103 return l10n_util::GetStringUTF16(
104 IDS_UPGRADE_NETWORK_LIST_CELLULAR_DISALLOWED);
105 }
106 }
107
108 // Returns true if the device is enterprise managed, false otherwise.
109 bool IsEnterpriseManaged() {
110 policy::BrowserPolicyConnectorChromeOS* connector =
111 g_browser_process->platform_part()->browser_policy_connector_chromeos();
112 return connector->IsEnterpriseManaged();
113 }
114
115 // Returns true if current user can change channel, false otherwise.
116 bool CanChangeChannel(Profile* profile) {
117 bool value = false;
118 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kReleaseChannelDelegated,
119 &value);
120
121 // On a managed machine we delegate this setting to the users of the same
122 // domain only if the policy value is "domain".
123 if (IsEnterpriseManaged()) {
124 if (!value)
125 return false;
126 // Get the currently logged in user and strip the domain part only.
127 std::string domain = "";
128 const user_manager::User* user =
129 profile ? chromeos::ProfileHelper::Get()->GetUserByProfile(profile)
130 : nullptr;
131 std::string email = user ? user->email() : std::string();
132 size_t at_pos = email.find('@');
133 if (at_pos != std::string::npos && at_pos + 1 < email.length())
134 domain = email.substr(email.find('@') + 1);
135 policy::BrowserPolicyConnectorChromeOS* connector =
136 g_browser_process->platform_part()->browser_policy_connector_chromeos();
137 return domain == connector->GetEnterpriseDomain();
138 } else {
139 chromeos::OwnerSettingsServiceChromeOS* service =
140 chromeos::OwnerSettingsServiceChromeOSFactory::GetInstance()
141 ->GetForBrowserContext(profile);
142 // On non managed machines we have local owner who is the only one to change
143 // anything. Ensure that ReleaseChannelDelegated is false.
144 if (service && service->IsOwner())
145 return !value;
146 }
147 return false;
148 }
149
150 // Returns the path of the regulatory labels directory for a given region, if
151 // found. Must be called from the blocking pool.
152 base::FilePath GetRegulatoryLabelDirForRegion(const std::string& region) {
153 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
154
155 // Generate the path under the asset dir or URL host to the regulatory files
156 // for the region, e.g., "regulatory_labels/us/".
157 const base::FilePath region_path =
158 base::FilePath(kRegulatoryLabelsDirectory).AppendASCII(region);
159
160 // Check for file existence starting in /usr/share/chromeos-assets/, e.g.,
161 // "/usr/share/chromeos-assets/regulatory_labels/us/label.png".
162 const base::FilePath asset_dir(chrome::kChromeOSAssetPath);
163 if (base::PathExists(asset_dir.Append(region_path)
164 .AppendASCII(kRegulatoryLabelImageFilename))) {
165 return region_path;
166 }
167
168 return base::FilePath();
169 }
170
171 // Finds the directory for the regulatory label, using the VPD region code.
172 // Also tries "us" as a fallback region. Must be called from the blocking pool.
173 base::FilePath FindRegulatoryLabelDir() {
174 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
175
176 std::string region;
177 base::FilePath region_path;
178 // Use the VPD region code to find the label dir.
179 if (chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic(
180 "region", &region) &&
181 !region.empty()) {
182 region_path = GetRegulatoryLabelDirForRegion(region);
183 }
184
185 // Try the fallback region code if no directory was found.
186 if (region_path.empty() && region != kDefaultRegionCode)
187 region_path = GetRegulatoryLabelDirForRegion(kDefaultRegionCode);
188
189 return region_path;
190 }
191
192 // Reads the file containing the regulatory label text, if found, relative to
193 // the asset directory. Must be called from the blocking pool.
194 std::string ReadRegulatoryLabelText(const base::FilePath& path) {
195 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
196 base::FilePath text_path(chrome::kChromeOSAssetPath);
197 text_path = text_path.Append(path);
198 text_path = text_path.AppendASCII(kRegulatoryLabelTextFilename);
199
200 std::string contents;
201 if (base::ReadFileToString(text_path, &contents))
202 return contents;
203 return std::string();
204 }
205
206 std::unique_ptr<base::DictionaryValue> GetVersionInfo() {
207 std::unique_ptr<base::DictionaryValue> version_info(
208 new base::DictionaryValue);
209
210 version_info->SetString("osVersion",
211 chromeos::version_loader::GetVersion(
212 chromeos::version_loader::VERSION_FULL));
213 version_info->SetString("arcVersion",
214 chromeos::version_loader::GetARCVersion());
215 version_info->SetString("osFirmware",
216 chromeos::version_loader::GetFirmware());
217
218 return version_info;
219 }
220
221 #endif // defined(OS_CHROMEOS)
222
223 std::string UpdateStatusToString(VersionUpdater::Status status) {
224 std::string status_str;
225 switch (status) {
226 case VersionUpdater::CHECKING:
227 status_str = "checking";
228 break;
229 case VersionUpdater::UPDATING:
230 status_str = "updating";
231 break;
232 case VersionUpdater::NEARLY_UPDATED:
233 status_str = "nearly_updated";
234 break;
235 case VersionUpdater::UPDATED:
236 status_str = "updated";
237 break;
238 case VersionUpdater::FAILED:
239 case VersionUpdater::FAILED_OFFLINE:
240 case VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED:
241 status_str = "failed";
242 break;
243 case VersionUpdater::DISABLED:
244 status_str = "disabled";
245 break;
246 case VersionUpdater::DISABLED_BY_ADMIN:
247 status_str = "disabled_by_admin";
248 break;
249 }
250
251 return status_str;
252 }
253
254 } // namespace
255
256 namespace settings {
257
258 AboutHandler::AboutHandler() : weak_factory_(this) {}
259
260 AboutHandler::~AboutHandler() {}
261
262 AboutHandler* AboutHandler::Create(content::WebUIDataSource* html_source,
263 Profile* profile) {
264 html_source->AddString(
265 "aboutBrowserVersion",
266 l10n_util::GetStringFUTF16(IDS_ABOUT_PRODUCT_VERSION,
267 BuildBrowserVersionString()));
268
269 base::Time::Exploded exploded_time;
270 base::Time::Now().LocalExplode(&exploded_time);
271 html_source->AddString(
272 "aboutProductCopyright",
273 l10n_util::GetStringFUTF16(IDS_ABOUT_VERSION_COPYRIGHT,
274 base::IntToString16(exploded_time.year)));
275
276 base::string16 license = l10n_util::GetStringFUTF16(
277 IDS_VERSION_UI_LICENSE, base::ASCIIToUTF16(chrome::kChromiumProjectURL),
278 base::ASCIIToUTF16(chrome::kChromeUICreditsURL));
279 html_source->AddString("aboutProductLicense", license);
280
281 html_source->AddBoolean("aboutObsolteNowOrSoon",
282 ObsoleteSystem::IsObsoleteNowOrSoon());
283 html_source->AddBoolean("aboutObsolteEndOfTheLine",
284 ObsoleteSystem::IsObsoleteNowOrSoon() &&
285 ObsoleteSystem::IsEndOfTheLine());
286
287 #if defined(OS_CHROMEOS)
288 base::string16 os_license = l10n_util::GetStringFUTF16(
289 IDS_ABOUT_CROS_VERSION_LICENSE,
290 base::ASCIIToUTF16(chrome::kChromeUIOSCreditsURL));
291 html_source->AddString("aboutProductOsLicense", os_license);
292
293 html_source->AddBoolean("aboutCanChangeChannel", CanChangeChannel(profile));
294 html_source->AddBoolean("aboutEnterpriseManaged", IsEnterpriseManaged());
295
296 base::Time build_time = base::SysInfo::GetLsbReleaseTime();
297 base::string16 build_date = base::TimeFormatFriendlyDate(build_time);
298 html_source->AddString("aboutBuildDate", build_date);
299 #endif
300
301 return new AboutHandler();
302 }
303
304 void AboutHandler::RegisterMessages() {
305 web_ui()->RegisterMessageCallback(
306 "refreshUpdateStatus",
307 base::Bind(&AboutHandler::HandleRefreshUpdateStatus,
308 base::Unretained(this)));
309 web_ui()->RegisterMessageCallback(
310 "relaunchNow",
311 base::Bind(&AboutHandler::HandleRelaunchNow, base::Unretained(this)));
312 web_ui()->RegisterMessageCallback(
313 "openFeedbackDialog", base::Bind(&AboutHandler::HandleOpenFeedbackDialog,
314 base::Unretained(this)));
315 web_ui()->RegisterMessageCallback(
316 "openHelpPage",
317 base::Bind(&AboutHandler::HandleOpenHelpPage, base::Unretained(this)));
318 #if defined(OS_CHROMEOS)
319 web_ui()->RegisterMessageCallback(
320 "setChannel",
321 base::Bind(&AboutHandler::HandleSetChannel, base::Unretained(this)));
322 web_ui()->RegisterMessageCallback(
323 "requestUpdate",
324 base::Bind(&AboutHandler::HandleRequestUpdate, base::Unretained(this)));
325
326 web_ui()->RegisterMessageCallback(
327 "getVersionInfo",
328 base::Bind(&AboutHandler::HandleGetVersionInfo, base::Unretained(this)));
329 web_ui()->RegisterMessageCallback(
330 "getRegulatoryInfo", base::Bind(&AboutHandler::HandleGetRegulatoryInfo,
331 base::Unretained(this)));
332 web_ui()->RegisterMessageCallback(
333 "getCurrentChannel", base::Bind(&AboutHandler::HandleGetCurrentChannel,
334 base::Unretained(this)));
335 web_ui()->RegisterMessageCallback(
336 "getTargetChannel", base::Bind(&AboutHandler::HandleGetTargetChannel,
337 base::Unretained(this)));
338 #endif
339 #if defined(OS_MACOSX)
340 web_ui()->RegisterMessageCallback(
341 "promoteUpdater",
342 base::Bind(&AboutHandler::PromoteUpdater, base::Unretained(this)));
343 #endif
344
345 #if defined(OS_CHROMEOS)
346 // Handler for the product label image, which will be shown if available.
347 content::URLDataSource::Add(Profile::FromWebUI(web_ui()),
348 new chromeos::ImageSource());
349 #endif
350 }
351
352 void AboutHandler::OnJavascriptAllowed() {
353 version_updater_.reset(VersionUpdater::Create(web_ui()->GetWebContents()));
354 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
355 content::NotificationService::AllSources());
356 policy_registrar_.reset(new policy::PolicyChangeRegistrar(
357 g_browser_process->policy_service(),
358 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())));
359 policy_registrar_->Observe(
360 policy::key::kDeviceAutoUpdateDisabled,
361 base::Bind(&AboutHandler::OnDeviceAutoUpdatePolicyChanged,
362 base::Unretained(this)));
363 }
364
365 void AboutHandler::OnJavascriptDisallowed() {
366 version_updater_.reset();
367 policy_registrar_.reset();
368 registrar_.Remove(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
369 content::NotificationService::AllSources());
370 }
371
372 void AboutHandler::Observe(int type,
373 const content::NotificationSource& source,
374 const content::NotificationDetails& details) {
375 switch (type) {
376 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
377 // A version update is installed and ready to go. Refresh the UI so the
378 // correct state will be shown.
379 RequestUpdate();
380 break;
381 }
382 default:
383 NOTREACHED();
384 }
385 }
386
387 // static
388 base::string16 AboutHandler::BuildBrowserVersionString() {
389 std::string version = version_info::GetVersionNumber();
390
391 std::string modifier = chrome::GetChannelString();
392 if (!modifier.empty())
393 version += " " + modifier;
394
395 #if defined(ARCH_CPU_64_BITS)
396 version += " (64-bit)";
397 #endif
398
399 return base::UTF8ToUTF16(version);
400 }
401
402 void AboutHandler::OnDeviceAutoUpdatePolicyChanged(
403 const base::Value* previous_policy,
404 const base::Value* current_policy) {
405 bool previous_auto_update_disabled = false;
406 if (previous_policy)
407 CHECK(previous_policy->GetAsBoolean(&previous_auto_update_disabled));
408
409 bool current_auto_update_disabled = false;
410 if (current_policy)
411 CHECK(current_policy->GetAsBoolean(&current_auto_update_disabled));
412
413 if (current_auto_update_disabled != previous_auto_update_disabled) {
414 // Refresh the update status to refresh the status of the UI.
415 RefreshUpdateStatus();
416 }
417 }
418
419 void AboutHandler::HandleRefreshUpdateStatus(const base::ListValue* args) {
420 AllowJavascript();
421 RefreshUpdateStatus();
422 }
423
424 void AboutHandler::RefreshUpdateStatus() {
425 // On Chrome OS, do not check for an update automatically.
426 #if defined(OS_CHROMEOS)
427 static_cast<VersionUpdaterCros*>(version_updater_.get())
428 ->GetUpdateStatus(
429 base::Bind(&AboutHandler::SetUpdateStatus, base::Unretained(this)));
430 #else
431 RequestUpdate();
432 #endif
433 }
434
435 #if defined(OS_MACOSX)
436 void AboutHandler::PromoteUpdater(const base::ListValue* args) {
437 version_updater_->PromoteUpdater();
438 }
439 #endif
440
441 void AboutHandler::HandleRelaunchNow(const base::ListValue* args) {
442 DCHECK(args->empty());
443 version_updater_->RelaunchBrowser();
444 }
445
446 void AboutHandler::HandleOpenFeedbackDialog(const base::ListValue* args) {
447 DCHECK(args->empty());
448 Browser* browser =
449 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents());
450 chrome::OpenFeedbackDialog(browser);
451 }
452
453 void AboutHandler::HandleOpenHelpPage(const base::ListValue* args) {
454 DCHECK(args->empty());
455 Browser* browser =
456 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents());
457 chrome::ShowHelp(browser, chrome::HELP_SOURCE_WEBUI);
458 }
459
460 #if defined(OS_CHROMEOS)
461
462 void AboutHandler::HandleSetChannel(const base::ListValue* args) {
463 DCHECK(args->GetSize() == 2);
464
465 if (!CanChangeChannel(Profile::FromWebUI(web_ui()))) {
466 LOG(WARNING) << "Non-owner tried to change release track.";
467 return;
468 }
469
470 base::string16 channel;
471 bool is_powerwash_allowed;
472 if (!args->GetString(0, &channel) ||
473 !args->GetBoolean(1, &is_powerwash_allowed)) {
474 LOG(ERROR) << "Can't parse SetChannel() args";
475 return;
476 }
477
478 version_updater_->SetChannel(base::UTF16ToUTF8(channel),
479 is_powerwash_allowed);
480 if (user_manager::UserManager::Get()->IsCurrentUserOwner()) {
481 // Check for update after switching release channel.
482 version_updater_->CheckForUpdate(
483 base::Bind(&AboutHandler::SetUpdateStatus, base::Unretained(this)),
484 VersionUpdater::PromoteCallback());
485 }
486 }
487
488 void AboutHandler::HandleGetVersionInfo(const base::ListValue* args) {
489 CHECK_EQ(1U, args->GetSize());
490 std::string callback_id;
491 CHECK(args->GetString(0, &callback_id));
492
493 base::PostTaskAndReplyWithResult(
494 content::BrowserThread::GetBlockingPool(), FROM_HERE,
495 base::Bind(&GetVersionInfo),
496 base::Bind(&AboutHandler::OnGetVersionInfoReady,
497 weak_factory_.GetWeakPtr(), callback_id));
498 }
499
500 void AboutHandler::OnGetVersionInfoReady(
501 std::string callback_id,
502 std::unique_ptr<base::DictionaryValue> version_info) {
503 ResolveJavascriptCallback(base::StringValue(callback_id), *version_info);
504 }
505
506 void AboutHandler::HandleGetRegulatoryInfo(const base::ListValue* args) {
507 CHECK_EQ(1U, args->GetSize());
508 std::string callback_id;
509 CHECK(args->GetString(0, &callback_id));
510
511 base::PostTaskAndReplyWithResult(
512 content::BrowserThread::GetBlockingPool(), FROM_HERE,
513 base::Bind(&FindRegulatoryLabelDir),
514 base::Bind(&AboutHandler::OnRegulatoryLabelDirFound,
515 weak_factory_.GetWeakPtr(), callback_id));
516 }
517
518 void AboutHandler::HandleGetCurrentChannel(const base::ListValue* args) {
519 CHECK_EQ(1U, args->GetSize());
520 std::string callback_id;
521 CHECK(args->GetString(0, &callback_id));
522 // First argument to GetChannel() is a flag that indicates whether
523 // current channel should be returned (if true) or target channel
524 // (otherwise).
525 version_updater_->GetChannel(
526 true, base::Bind(&AboutHandler::OnGetChannelReady,
527 weak_factory_.GetWeakPtr(), callback_id));
528 }
529
530 void AboutHandler::HandleGetTargetChannel(const base::ListValue* args) {
531 CHECK_EQ(1U, args->GetSize());
532 std::string callback_id;
533 CHECK(args->GetString(0, &callback_id));
534 version_updater_->GetChannel(
535 false, base::Bind(&AboutHandler::OnGetChannelReady,
536 weak_factory_.GetWeakPtr(), callback_id));
537 }
538
539 void AboutHandler::OnGetChannelReady(std::string callback_id,
540 const std::string& channel) {
541 ResolveJavascriptCallback(base::StringValue(callback_id),
542 base::StringValue(channel));
543 }
544
545 void AboutHandler::HandleRequestUpdate(const base::ListValue* args) {
546 RequestUpdate();
547 }
548
549 #endif // defined(OS_CHROMEOS)
550
551 void AboutHandler::RequestUpdate() {
552 version_updater_->CheckForUpdate(
553 base::Bind(&AboutHandler::SetUpdateStatus, base::Unretained(this)),
554 #if defined(OS_MACOSX)
555 base::Bind(&AboutHandler::SetPromotionState, base::Unretained(this)));
556 #else
557 VersionUpdater::PromoteCallback());
558 #endif // OS_MACOSX
559 }
560
561 void AboutHandler::SetUpdateStatus(VersionUpdater::Status status,
562 int progress,
563 const base::string16& message) {
564 // Only UPDATING state should have progress set.
565 DCHECK(status == VersionUpdater::UPDATING || progress == 0);
566
567 std::unique_ptr<base::DictionaryValue> event(new base::DictionaryValue);
568 event->SetString("status", UpdateStatusToString(status));
569 event->SetString("message", message);
570 event->SetInteger("progress", progress);
571
572 #if defined(OS_CHROMEOS)
573 if (status == VersionUpdater::FAILED_OFFLINE ||
574 status == VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED) {
575 base::string16 types_msg = GetAllowedConnectionTypesMessage();
576 if (!types_msg.empty())
577 event->SetString("connectionTypes", types_msg);
578 else
579 event->Set("connectionTypes", base::Value::CreateNullValue());
580 } else {
581 event->Set("connectionTypes", base::Value::CreateNullValue());
582 }
583 #endif // defined(OS_CHROMEOS)
584
585 CallJavascriptFunction("cr.webUIListenerCallback",
586 base::StringValue("update-status-changed"), *event);
587 }
588
589 #if defined(OS_MACOSX)
590 void AboutHandler::SetPromotionState(VersionUpdater::PromotionState state) {
591 std::string state_str;
592 switch (state) {
593 case VersionUpdater::PROMOTE_HIDDEN:
594 state_str = "hidden";
595 break;
596 case VersionUpdater::PROMOTE_ENABLED:
597 state_str = "enabled";
598 break;
599 case VersionUpdater::PROMOTE_DISABLED:
600 state_str = "disabled";
601 break;
602 }
603
604 CallJavascriptFunction("cr.webUIListenerCallback",
605 base::StringValue("promotion-state-changed"),
606 base::StringValue(state_str));
607 }
608 #endif // defined(OS_MACOSX)
609
610 #if defined(OS_CHROMEOS)
611 void AboutHandler::OnRegulatoryLabelDirFound(std::string callback_id,
612 const base::FilePath& path) {
613 if (path.empty()) {
614 ResolveJavascriptCallback(base::StringValue(callback_id),
615 *base::Value::CreateNullValue());
616 return;
617 }
618
619 base::PostTaskAndReplyWithResult(
620 content::BrowserThread::GetBlockingPool(), FROM_HERE,
621 base::Bind(&ReadRegulatoryLabelText, path),
622 base::Bind(&AboutHandler::OnRegulatoryLabelTextRead,
623 weak_factory_.GetWeakPtr(), callback_id, path));
624 }
625
626 void AboutHandler::OnRegulatoryLabelTextRead(std::string callback_id,
627 const base::FilePath& path,
628 const std::string& text) {
629 std::unique_ptr<base::DictionaryValue> regulatory_info(
630 new base::DictionaryValue);
631 // Remove unnecessary whitespace.
632 regulatory_info->SetString("text", base::CollapseWhitespaceASCII(text, true));
633 std::string url = std::string("chrome://") + chrome::kChromeOSAssetHost +
634 "/" + path.MaybeAsASCII();
635 regulatory_info->SetString("url", url);
636
637 ResolveJavascriptCallback(base::StringValue(callback_id), *regulatory_info);
638 }
639
640 #endif // defined(OS_CHROMEOS)
641
642 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/about_handler.h ('k') | chrome/browser/ui/webui/settings/md_settings_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698