Chromium Code Reviews| 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/about_ui.h" | 5 #include "chrome/browser/ui/webui/about_ui.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 512 return WrapWithTR(row); | 512 return WrapWithTR(row); |
| 513 } | 513 } |
| 514 | 514 |
| 515 std::string AddStringRow(const std::string& name, const std::string& value) { | 515 std::string AddStringRow(const std::string& name, const std::string& value) { |
| 516 std::string row; | 516 std::string row; |
| 517 row.append(WrapWithTD(name)); | 517 row.append(WrapWithTD(name)); |
| 518 row.append(WrapWithTD(value)); | 518 row.append(WrapWithTD(value)); |
| 519 return WrapWithTR(row); | 519 return WrapWithTR(row); |
| 520 } | 520 } |
| 521 | 521 |
| 522 void FinishCryptohomeDataRequestInternal( | 522 class CryptohomeDataRequest : public base::RefCounted<CryptohomeDataRequest> { |
| 523 scoped_refptr<AboutUIHTMLSource> source, | 523 public: |
| 524 int refresh, | 524 CryptohomeDataRequest(scoped_refptr<AboutUIHTMLSource> source, |
| 525 int request_id, | 525 const std::string& query, |
| 526 chromeos::DBusMethodCallStatus call_status, | 526 int request_id) |
| 527 bool is_tpm_token_ready) { | 527 : source_(source), |
| 528 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) | 528 query_(query), |
| 529 is_tpm_token_ready = false; | 529 request_id_(request_id), |
| 530 num_pending_values_(0), | |
| 531 is_mounted_(false), | |
| 532 tpm_is_ready_(false), | |
| 533 tpm_is_enabled_(false), | |
| 534 tpm_is_owned_(false), | |
| 535 tpm_is_being_owned_(false), | |
| 536 is_tpm_token_ready_(false) { | |
| 537 } | |
| 530 | 538 |
| 531 chromeos::CryptohomeLibrary* cryptohome = | 539 // Starts asynchronous value fetching to finish data request. |
| 532 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary(); | 540 void Start() { |
| 533 std::string output; | 541 // Request bool values asynchronously. |
| 534 AppendHeader(&output, refresh, "About Cryptohome"); | 542 RequestBoolProperty(&chromeos::CryptohomeClient::TpmIsReady, |
| 535 AppendBody(&output); | 543 &tpm_is_ready_); |
| 536 AppendRefresh(&output, refresh, "cryptohome"); | 544 RequestBoolProperty(&chromeos::CryptohomeClient::Pkcs11IsTpmTokenReady, |
| 545 &is_tpm_token_ready_); | |
| 537 | 546 |
| 538 output.append("<h3>CryptohomeLibrary:</h3>"); | 547 // TODO(hashimoto): Get these values asynchronously. crbug.com/126674 |
| 539 output.append("<table>"); | 548 chromeos::CryptohomeLibrary* cryptohome_library = |
| 540 output.append(AddBoolRow("IsMounted", cryptohome->IsMounted())); | 549 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary(); |
| 541 output.append(AddBoolRow("TpmIsReady", cryptohome->TpmIsReady())); | 550 is_mounted_ = cryptohome_library->IsMounted(); |
| 542 output.append(AddBoolRow("TpmIsEnabled", cryptohome->TpmIsEnabled())); | 551 tpm_is_enabled_ = cryptohome_library->TpmIsEnabled(); |
| 543 output.append(AddBoolRow("TpmIsOwned", cryptohome->TpmIsOwned())); | 552 tpm_is_owned_ = cryptohome_library->TpmIsOwned(); |
| 544 output.append(AddBoolRow("TpmIsBeingOwned", cryptohome->TpmIsBeingOwned())); | 553 tpm_is_being_owned_ = cryptohome_library->TpmIsBeingOwned(); |
| 545 output.append(AddBoolRow("Pkcs11IsTpmTokenReady", is_tpm_token_ready)); | 554 } |
| 546 output.append("</table>"); | |
| 547 | 555 |
| 548 output.append("<h3>crypto:</h3>"); | 556 private: |
| 549 output.append("<table>"); | 557 // Member function pointer to CryptohomeClient's bool value getter. |
| 550 output.append(AddBoolRow("IsTPMTokenReady", crypto::IsTPMTokenReady())); | 558 typedef void (chromeos::CryptohomeClient::*CryptohomeBoolGetterMethod)( |
| 551 std::string token_name, user_pin; | 559 const chromeos::CryptohomeClient::BoolMethodCallback&); |
| 552 if (crypto::IsTPMTokenReady()) | |
| 553 crypto::GetTPMTokenInfo(&token_name, &user_pin); | |
| 554 output.append(AddStringRow("token_name", token_name)); | |
| 555 output.append(AddStringRow("user_pin", std::string(user_pin.length(), '*'))); | |
| 556 output.append("</table>"); | |
| 557 AppendFooter(&output); | |
| 558 | 560 |
| 559 source->FinishDataRequest(output, request_id); | 561 ~CryptohomeDataRequest() {} |
| 560 } | |
| 561 | 562 |
| 562 void FinishCryptohomeDataRequest(scoped_refptr<AboutUIHTMLSource> source, | 563 // Requests Cryptohome's bool property. OnBoolValueReceived will be called. |
| 563 const std::string& query, | 564 void RequestBoolProperty(CryptohomeBoolGetterMethod getter, |
| 564 int request_id) { | 565 bool* destination) { |
| 565 int refresh; | 566 ++num_pending_values_; |
| 566 base::StringToInt(query, &refresh); | 567 (chromeos::DBusThreadManager::Get()->GetCryptohomeClient()->*getter)( |
| 568 base::Bind(&CryptohomeDataRequest::OnBoolValueReceived, | |
| 569 this, | |
| 570 destination)); | |
| 571 } | |
| 567 | 572 |
| 568 chromeos::DBusThreadManager::Get()->GetCryptohomeClient()-> | 573 // Called when a bool property is received. This method finishes data request |
| 569 Pkcs11IsTpmTokenReady(base::Bind(&FinishCryptohomeDataRequestInternal, | 574 // when there is no pending values to be received. |
| 570 source, | 575 void OnBoolValueReceived(bool* destination, |
| 571 refresh, | 576 chromeos::DBusMethodCallStatus call_status, |
| 572 request_id)); | 577 bool value) { |
| 573 } | 578 if (call_status == chromeos::DBUS_METHOD_CALL_SUCCESS) |
| 579 *destination = value; | |
| 580 if (--num_pending_values_ == 0) | |
| 581 Finish(); | |
| 582 } | |
| 583 | |
| 584 // Finishes data request. | |
| 585 void Finish() { | |
| 586 int refresh = 0; | |
| 587 base::StringToInt(query_, &refresh); | |
| 588 | |
| 589 std::string output; | |
| 590 AppendHeader(&output, refresh, "About Cryptohome"); | |
| 591 AppendBody(&output); | |
| 592 AppendRefresh(&output, refresh, "cryptohome"); | |
| 593 | |
| 594 output.append("<h3>CryptohomeLibrary:</h3>"); | |
| 595 output.append("<table>"); | |
| 596 output.append(AddBoolRow("IsMounted", is_mounted_)); | |
| 597 output.append(AddBoolRow("TpmIsReady", tpm_is_ready_)); | |
| 598 output.append(AddBoolRow("TpmIsEnabled", tpm_is_enabled_)); | |
| 599 output.append(AddBoolRow("TpmIsOwned", tpm_is_owned_)); | |
| 600 output.append(AddBoolRow("TpmIsBeingOwned", tpm_is_being_owned_)); | |
| 601 output.append(AddBoolRow("Pkcs11IsTpmTokenReady", is_tpm_token_ready_)); | |
| 602 output.append("</table>"); | |
| 603 | |
| 604 output.append("<h3>crypto:</h3>"); | |
| 605 output.append("<table>"); | |
| 606 output.append(AddBoolRow("IsTPMTokenReady", crypto::IsTPMTokenReady())); | |
| 607 std::string token_name, user_pin; | |
| 608 if (crypto::IsTPMTokenReady()) | |
| 609 crypto::GetTPMTokenInfo(&token_name, &user_pin); | |
| 610 output.append(AddStringRow("token_name", token_name)); | |
| 611 output.append( | |
| 612 AddStringRow("user_pin", std::string(user_pin.length(), '*'))); | |
| 613 output.append("</table>"); | |
| 614 AppendFooter(&output); | |
| 615 | |
| 616 source_->FinishDataRequest(output, request_id_); | |
| 617 } | |
| 618 | |
| 619 // Data request parameters. | |
| 620 scoped_refptr<AboutUIHTMLSource> source_; | |
| 621 std::string query_; | |
| 622 int request_id_; | |
| 623 | |
| 624 // Number of pending values to be received. | |
| 625 int num_pending_values_; | |
| 626 | |
| 627 // Bool values to be appended to the output. | |
| 628 bool is_mounted_; | |
| 629 bool tpm_is_ready_; | |
| 630 bool tpm_is_enabled_; | |
| 631 bool tpm_is_owned_; | |
| 632 bool tpm_is_being_owned_; | |
| 633 bool is_tpm_token_ready_; | |
| 634 | |
| 635 friend class base::RefCounted<CryptohomeDataRequest>; | |
| 636 }; | |
| 574 | 637 |
| 575 std::string AboutDiscardsRun() { | 638 std::string AboutDiscardsRun() { |
| 576 std::string output; | 639 std::string output; |
| 577 AppendHeader(&output, 0, "About discards"); | 640 AppendHeader(&output, 0, "About discards"); |
| 578 output.append(StringPrintf("<meta http-equiv=\"refresh\" content=\"2;%s\">", | 641 output.append(StringPrintf("<meta http-equiv=\"refresh\" content=\"2;%s\">", |
| 579 chrome::kChromeUIDiscardsURL)); | 642 chrome::kChromeUIDiscardsURL)); |
| 580 output.append(WrapWithTag("p", "Discarding a tab...")); | 643 output.append(WrapWithTag("p", "Discarding a tab...")); |
| 581 g_browser_process->oom_priority_manager()->LogMemoryAndDiscardTab(); | 644 g_browser_process->oom_priority_manager()->LogMemoryAndDiscardTab(); |
| 582 AppendFooter(&output); | 645 AppendFooter(&output); |
| 583 return output; | 646 return output; |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1330 source_->FinishDataRequest(AboutVersionStrings( | 1393 source_->FinishDataRequest(AboutVersionStrings( |
| 1331 &localized_strings, source_->profile()), request_id_); | 1394 &localized_strings, source_->profile()), request_id_); |
| 1332 | 1395 |
| 1333 // CancelableRequestProvider isn't happy when it's deleted and servicing a | 1396 // CancelableRequestProvider isn't happy when it's deleted and servicing a |
| 1334 // task, so we delay the deletion. | 1397 // task, so we delay the deletion. |
| 1335 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1398 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 1336 } | 1399 } |
| 1337 | 1400 |
| 1338 #endif | 1401 #endif |
| 1339 | 1402 |
| 1340 } // namespace | 1403 } // namespace |
|
Evan Stade
2012/07/13 05:58:46
wow. 1400 line unnamed namespace? html in C++ in s
hashimoto
2012/07/18 09:34:21
Now chrome://cryptohome (and about:cryptohome) is
| |
| 1341 | 1404 |
| 1342 // AboutUIHTMLSource ---------------------------------------------------------- | 1405 // AboutUIHTMLSource ---------------------------------------------------------- |
| 1343 | 1406 |
| 1344 AboutUIHTMLSource::AboutUIHTMLSource(const std::string& source_name, | 1407 AboutUIHTMLSource::AboutUIHTMLSource(const std::string& source_name, |
| 1345 Profile* profile) | 1408 Profile* profile) |
| 1346 : DataSource(source_name, MessageLoop::current()), | 1409 : DataSource(source_name, MessageLoop::current()), |
| 1347 profile_(profile) { | 1410 profile_(profile) { |
| 1348 } | 1411 } |
| 1349 | 1412 |
| 1350 AboutUIHTMLSource::~AboutUIHTMLSource() { | 1413 AboutUIHTMLSource::~AboutUIHTMLSource() { |
| 1351 } | 1414 } |
| 1352 | 1415 |
| 1353 void AboutUIHTMLSource::StartDataRequest(const std::string& path, | 1416 void AboutUIHTMLSource::StartDataRequest(const std::string& path, |
| 1354 bool is_incognito, | 1417 bool is_incognito, |
| 1355 int request_id) { | 1418 int request_id) { |
| 1356 std::string response; | 1419 std::string response; |
| 1357 std::string host = source_name(); | 1420 std::string host = source_name(); |
| 1358 // Add your data source here, in alphabetical order. | 1421 // Add your data source here, in alphabetical order. |
| 1359 if (host == chrome::kChromeUIChromeURLsHost) { | 1422 if (host == chrome::kChromeUIChromeURLsHost) { |
| 1360 response = ChromeURLs(); | 1423 response = ChromeURLs(); |
| 1361 } else if (host == chrome::kChromeUICreditsHost) { | 1424 } else if (host == chrome::kChromeUICreditsHost) { |
| 1362 int idr = (path == kCreditsJsPath) ? IDR_CREDITS_JS : IDR_CREDITS_HTML; | 1425 int idr = (path == kCreditsJsPath) ? IDR_CREDITS_JS : IDR_CREDITS_HTML; |
| 1363 response = ResourceBundle::GetSharedInstance().GetRawDataResource( | 1426 response = ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 1364 idr, ui::SCALE_FACTOR_NONE).as_string(); | 1427 idr, ui::SCALE_FACTOR_NONE).as_string(); |
| 1365 #if defined(OS_CHROMEOS) | 1428 #if defined(OS_CHROMEOS) |
| 1366 } else if (host == chrome::kChromeUICryptohomeHost) { | 1429 } else if (host == chrome::kChromeUICryptohomeHost) { |
| 1367 FinishCryptohomeDataRequest(this, path, request_id); | 1430 scoped_refptr<CryptohomeDataRequest> request( |
| 1431 new CryptohomeDataRequest(this, path, request_id)); | |
| 1432 request->Start(); | |
| 1368 return; | 1433 return; |
| 1369 } else if (host == chrome::kChromeUIDiscardsHost) { | 1434 } else if (host == chrome::kChromeUIDiscardsHost) { |
| 1370 response = AboutDiscards(path); | 1435 response = AboutDiscards(path); |
| 1371 #endif | 1436 #endif |
| 1372 #if defined(USE_ASH) | 1437 #if defined(USE_ASH) |
| 1373 } else if (host == chrome::kChromeUITransparencyHost) { | 1438 } else if (host == chrome::kChromeUITransparencyHost) { |
| 1374 response = AboutTransparency(path); | 1439 response = AboutTransparency(path); |
| 1375 #endif | 1440 #endif |
| 1376 } else if (host == chrome::kChromeUIDNSHost) { | 1441 } else if (host == chrome::kChromeUIDNSHost) { |
| 1377 AboutDnsHandler::Start(this, request_id); | 1442 AboutDnsHandler::Start(this, request_id); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1440 | 1505 |
| 1441 AboutUI::AboutUI(content::WebUI* web_ui, const std::string& name) | 1506 AboutUI::AboutUI(content::WebUI* web_ui, const std::string& name) |
| 1442 : WebUIController(web_ui) { | 1507 : WebUIController(web_ui) { |
| 1443 Profile* profile = Profile::FromWebUI(web_ui); | 1508 Profile* profile = Profile::FromWebUI(web_ui); |
| 1444 ChromeURLDataManager::DataSource* source = | 1509 ChromeURLDataManager::DataSource* source = |
| 1445 new AboutUIHTMLSource(name, profile); | 1510 new AboutUIHTMLSource(name, profile); |
| 1446 if (source) { | 1511 if (source) { |
| 1447 ChromeURLDataManager::AddDataSource(profile, source); | 1512 ChromeURLDataManager::AddDataSource(profile, source); |
| 1448 } | 1513 } |
| 1449 } | 1514 } |
| OLD | NEW |