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

Side by Side Diff: chrome/browser/ui/webui/certificate_viewer_webui.cc

Issue 2086763002: Don't use deprecated ListValue::Append(Value*) overload. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
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/certificate_viewer_webui.h" 5 #include "chrome/browser/ui/webui/certificate_viewer_webui.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/i18n/time_formatting.h" 12 #include "base/i18n/time_formatting.h"
13 #include "base/json/json_writer.h" 13 #include "base/json/json_writer.h"
14 #include "base/memory/ptr_util.h"
14 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/browser/certificate_viewer.h" 17 #include "chrome/browser/certificate_viewer.h"
17 #include "chrome/browser/platform_util.h" 18 #include "chrome/browser/platform_util.h"
18 #include "chrome/browser/ui/browser_dialogs.h" 19 #include "chrome/browser/ui/browser_dialogs.h"
19 #include "chrome/browser/ui/certificate_dialogs.h" 20 #include "chrome/browser/ui/certificate_dialogs.h"
20 #include "chrome/browser/ui/webui/certificate_viewer_ui.h" 21 #include "chrome/browser/ui/webui/certificate_viewer_ui.h"
21 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" 22 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
22 #include "chrome/common/net/x509_certificate_model.h" 23 #include "chrome/common/net/x509_certificate_model.h"
23 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 int cert_index = GetCertificateIndex(args); 288 int cert_index = GetCertificateIndex(args);
288 if (cert_index < 0) 289 if (cert_index < 0)
289 return; 290 return;
290 291
291 net::X509Certificate::OSCertHandle cert = cert_chain_[cert_index]; 292 net::X509Certificate::OSCertHandle cert = cert_chain_[cert_index];
292 293
293 base::ListValue root_list; 294 base::ListValue root_list;
294 base::DictionaryValue* node_details; 295 base::DictionaryValue* node_details;
295 base::DictionaryValue* alt_node_details; 296 base::DictionaryValue* alt_node_details;
296 base::ListValue* cert_sub_fields; 297 base::ListValue* cert_sub_fields;
297 root_list.Append(node_details = new base::DictionaryValue()); 298 root_list.Append(
299 base::WrapUnique(node_details = new base::DictionaryValue()));
dcheng 2016/06/21 00:07:58 This is somewhat unsatisfactory, but I'd rather so
Dan Beam 2016/06/21 00:48:06 +flackr
298 node_details->SetString("label", x509_certificate_model::GetTitle(cert)); 300 node_details->SetString("label", x509_certificate_model::GetTitle(cert));
299 301
300 base::ListValue* cert_fields; 302 base::ListValue* cert_fields;
301 node_details->Set("children", cert_fields = new base::ListValue()); 303 node_details->Set("children", cert_fields = new base::ListValue());
302 cert_fields->Append(node_details = new base::DictionaryValue()); 304 cert_fields->Append(
305 base::WrapUnique(node_details = new base::DictionaryValue()));
303 306
304 node_details->SetString("label", 307 node_details->SetString("label",
305 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_CERTIFICATE)); 308 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_CERTIFICATE));
306 node_details->Set("children", cert_fields = new base::ListValue()); 309 node_details->Set("children", cert_fields = new base::ListValue());
307 310
308 // Main certificate fields. 311 // Main certificate fields.
309 cert_fields->Append(node_details = new base::DictionaryValue()); 312 cert_fields->Append(
313 base::WrapUnique(node_details = new base::DictionaryValue()));
310 node_details->SetString("label", 314 node_details->SetString("label",
311 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_VERSION)); 315 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_VERSION));
312 std::string version = x509_certificate_model::GetVersion(cert); 316 std::string version = x509_certificate_model::GetVersion(cert);
313 if (!version.empty()) 317 if (!version.empty())
314 node_details->SetString("payload.val", 318 node_details->SetString("payload.val",
315 l10n_util::GetStringFUTF8(IDS_CERT_DETAILS_VERSION_FORMAT, 319 l10n_util::GetStringFUTF8(IDS_CERT_DETAILS_VERSION_FORMAT,
316 base::UTF8ToUTF16(version))); 320 base::UTF8ToUTF16(version)));
317 321
318 cert_fields->Append(node_details = new base::DictionaryValue()); 322 cert_fields->Append(
323 base::WrapUnique(node_details = new base::DictionaryValue()));
319 node_details->SetString("label", 324 node_details->SetString("label",
320 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_SERIAL_NUMBER)); 325 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_SERIAL_NUMBER));
321 node_details->SetString("payload.val", 326 node_details->SetString("payload.val",
322 x509_certificate_model::GetSerialNumberHexified(cert, 327 x509_certificate_model::GetSerialNumberHexified(cert,
323 l10n_util::GetStringUTF8(IDS_CERT_INFO_FIELD_NOT_PRESENT))); 328 l10n_util::GetStringUTF8(IDS_CERT_INFO_FIELD_NOT_PRESENT)));
324 329
325 cert_fields->Append(node_details = new base::DictionaryValue()); 330 cert_fields->Append(
331 base::WrapUnique(node_details = new base::DictionaryValue()));
326 node_details->SetString("label", 332 node_details->SetString("label",
327 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_CERTIFICATE_SIG_ALG)); 333 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_CERTIFICATE_SIG_ALG));
328 node_details->SetString("payload.val", 334 node_details->SetString("payload.val",
329 x509_certificate_model::ProcessSecAlgorithmSignature(cert)); 335 x509_certificate_model::ProcessSecAlgorithmSignature(cert));
330 336
331 cert_fields->Append(node_details = new base::DictionaryValue()); 337 cert_fields->Append(
338 base::WrapUnique(node_details = new base::DictionaryValue()));
332 node_details->SetString("label", 339 node_details->SetString("label",
333 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_ISSUER)); 340 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_ISSUER));
334 node_details->SetString("payload.val", 341 node_details->SetString("payload.val",
335 x509_certificate_model::GetIssuerName(cert)); 342 x509_certificate_model::GetIssuerName(cert));
336 343
337 // Validity period. 344 // Validity period.
338 cert_fields->Append(node_details = new base::DictionaryValue()); 345 cert_fields->Append(
346 base::WrapUnique(node_details = new base::DictionaryValue()));
339 node_details->SetString("label", 347 node_details->SetString("label",
340 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_VALIDITY)); 348 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_VALIDITY));
341 349
342 node_details->Set("children", cert_sub_fields = new base::ListValue()); 350 node_details->Set("children", cert_sub_fields = new base::ListValue());
343 cert_sub_fields->Append(node_details = new base::DictionaryValue()); 351 cert_sub_fields->Append(
352 base::WrapUnique(node_details = new base::DictionaryValue()));
344 node_details->SetString("label", 353 node_details->SetString("label",
345 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_NOT_BEFORE)); 354 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_NOT_BEFORE));
346 cert_sub_fields->Append(alt_node_details = new base::DictionaryValue()); 355 cert_sub_fields->Append(
356 base::WrapUnique(alt_node_details = new base::DictionaryValue()));
347 alt_node_details->SetString("label", 357 alt_node_details->SetString("label",
348 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_NOT_AFTER)); 358 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_NOT_AFTER));
349 base::Time issued, expires; 359 base::Time issued, expires;
350 if (x509_certificate_model::GetTimes(cert, &issued, &expires)) { 360 if (x509_certificate_model::GetTimes(cert, &issued, &expires)) {
351 node_details->SetString( 361 node_details->SetString(
352 "payload.val", 362 "payload.val",
353 base::UTF16ToUTF8( 363 base::UTF16ToUTF8(
354 base::TimeFormatShortDateAndTimeWithTimeZone(issued))); 364 base::TimeFormatShortDateAndTimeWithTimeZone(issued)));
355 alt_node_details->SetString( 365 alt_node_details->SetString(
356 "payload.val", 366 "payload.val",
357 base::UTF16ToUTF8( 367 base::UTF16ToUTF8(
358 base::TimeFormatShortDateAndTimeWithTimeZone(expires))); 368 base::TimeFormatShortDateAndTimeWithTimeZone(expires)));
359 } 369 }
360 370
361 cert_fields->Append(node_details = new base::DictionaryValue()); 371 cert_fields->Append(
372 base::WrapUnique(node_details = new base::DictionaryValue()));
362 node_details->SetString("label", 373 node_details->SetString("label",
363 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_SUBJECT)); 374 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_SUBJECT));
364 node_details->SetString("payload.val", 375 node_details->SetString("payload.val",
365 x509_certificate_model::GetSubjectName(cert)); 376 x509_certificate_model::GetSubjectName(cert));
366 377
367 // Subject key information. 378 // Subject key information.
368 cert_fields->Append(node_details = new base::DictionaryValue()); 379 cert_fields->Append(
380 base::WrapUnique(node_details = new base::DictionaryValue()));
369 node_details->SetString("label", 381 node_details->SetString("label",
370 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_SUBJECT_KEY_INFO)); 382 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_SUBJECT_KEY_INFO));
371 383
372 node_details->Set("children", cert_sub_fields = new base::ListValue()); 384 node_details->Set("children", cert_sub_fields = new base::ListValue());
373 cert_sub_fields->Append(node_details = new base::DictionaryValue()); 385 cert_sub_fields->Append(
386 base::WrapUnique(node_details = new base::DictionaryValue()));
374 node_details->SetString("label", 387 node_details->SetString("label",
375 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_SUBJECT_KEY_ALG)); 388 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_SUBJECT_KEY_ALG));
376 node_details->SetString("payload.val", 389 node_details->SetString("payload.val",
377 x509_certificate_model::ProcessSecAlgorithmSubjectPublicKey(cert)); 390 x509_certificate_model::ProcessSecAlgorithmSubjectPublicKey(cert));
378 cert_sub_fields->Append(node_details = new base::DictionaryValue()); 391 cert_sub_fields->Append(
392 base::WrapUnique(node_details = new base::DictionaryValue()));
379 node_details->SetString("label", 393 node_details->SetString("label",
380 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_SUBJECT_KEY)); 394 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_SUBJECT_KEY));
381 node_details->SetString("payload.val", 395 node_details->SetString("payload.val",
382 x509_certificate_model::ProcessSubjectPublicKeyInfo(cert)); 396 x509_certificate_model::ProcessSubjectPublicKeyInfo(cert));
383 397
384 // Extensions. 398 // Extensions.
385 x509_certificate_model::Extensions extensions; 399 x509_certificate_model::Extensions extensions;
386 x509_certificate_model::GetExtensions( 400 x509_certificate_model::GetExtensions(
387 l10n_util::GetStringUTF8(IDS_CERT_EXTENSION_CRITICAL), 401 l10n_util::GetStringUTF8(IDS_CERT_EXTENSION_CRITICAL),
388 l10n_util::GetStringUTF8(IDS_CERT_EXTENSION_NON_CRITICAL), 402 l10n_util::GetStringUTF8(IDS_CERT_EXTENSION_NON_CRITICAL),
389 cert, &extensions); 403 cert, &extensions);
390 404
391 if (!extensions.empty()) { 405 if (!extensions.empty()) {
392 cert_fields->Append(node_details = new base::DictionaryValue()); 406 cert_fields->Append(
407 base::WrapUnique(node_details = new base::DictionaryValue()));
393 node_details->SetString("label", 408 node_details->SetString("label",
394 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_EXTENSIONS)); 409 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_EXTENSIONS));
395 410
396 node_details->Set("children", cert_sub_fields = new base::ListValue()); 411 node_details->Set("children", cert_sub_fields = new base::ListValue());
397 for (x509_certificate_model::Extensions::const_iterator i = 412 for (x509_certificate_model::Extensions::const_iterator i =
398 extensions.begin(); i != extensions.end(); ++i) { 413 extensions.begin(); i != extensions.end(); ++i) {
399 cert_sub_fields->Append(node_details = new base::DictionaryValue()); 414 cert_sub_fields->Append(
415 base::WrapUnique(node_details = new base::DictionaryValue()));
400 node_details->SetString("label", i->name); 416 node_details->SetString("label", i->name);
401 node_details->SetString("payload.val", i->value); 417 node_details->SetString("payload.val", i->value);
402 } 418 }
403 } 419 }
404 420
405 cert_fields->Append(node_details = new base::DictionaryValue()); 421 cert_fields->Append(
422 base::WrapUnique(node_details = new base::DictionaryValue()));
406 node_details->SetString("label", 423 node_details->SetString("label",
407 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_CERTIFICATE_SIG_ALG)); 424 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_CERTIFICATE_SIG_ALG));
408 node_details->SetString("payload.val", 425 node_details->SetString("payload.val",
409 x509_certificate_model::ProcessSecAlgorithmSignatureWrap(cert)); 426 x509_certificate_model::ProcessSecAlgorithmSignatureWrap(cert));
410 427
411 cert_fields->Append(node_details = new base::DictionaryValue()); 428 cert_fields->Append(
429 base::WrapUnique(node_details = new base::DictionaryValue()));
412 node_details->SetString("label", 430 node_details->SetString("label",
413 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_CERTIFICATE_SIG_VALUE)); 431 l10n_util::GetStringUTF8(IDS_CERT_DETAILS_CERTIFICATE_SIG_VALUE));
414 node_details->SetString("payload.val", 432 node_details->SetString("payload.val",
415 x509_certificate_model::ProcessRawBitsSignatureWrap(cert)); 433 x509_certificate_model::ProcessRawBitsSignatureWrap(cert));
416 434
417 cert_fields->Append(node_details = new base::DictionaryValue()); 435 cert_fields->Append(
436 base::WrapUnique(node_details = new base::DictionaryValue()));
418 node_details->SetString("label", 437 node_details->SetString("label",
419 l10n_util::GetStringUTF8(IDS_CERT_INFO_FINGERPRINTS_GROUP)); 438 l10n_util::GetStringUTF8(IDS_CERT_INFO_FINGERPRINTS_GROUP));
420 node_details->Set("children", cert_sub_fields = new base::ListValue()); 439 node_details->Set("children", cert_sub_fields = new base::ListValue());
421 440
422 cert_sub_fields->Append(node_details = new base::DictionaryValue()); 441 cert_sub_fields->Append(
442 base::WrapUnique(node_details = new base::DictionaryValue()));
423 node_details->SetString("label", 443 node_details->SetString("label",
424 l10n_util::GetStringUTF8(IDS_CERT_INFO_SHA256_FINGERPRINT_LABEL)); 444 l10n_util::GetStringUTF8(IDS_CERT_INFO_SHA256_FINGERPRINT_LABEL));
425 node_details->SetString("payload.val", 445 node_details->SetString("payload.val",
426 x509_certificate_model::HashCertSHA256(cert)); 446 x509_certificate_model::HashCertSHA256(cert));
427 cert_sub_fields->Append(node_details = new base::DictionaryValue()); 447 cert_sub_fields->Append(
448 base::WrapUnique(node_details = new base::DictionaryValue()));
428 node_details->SetString("label", 449 node_details->SetString("label",
429 l10n_util::GetStringUTF8(IDS_CERT_INFO_SHA1_FINGERPRINT_LABEL)); 450 l10n_util::GetStringUTF8(IDS_CERT_INFO_SHA1_FINGERPRINT_LABEL));
430 node_details->SetString("payload.val", 451 node_details->SetString("payload.val",
431 x509_certificate_model::HashCertSHA1(cert)); 452 x509_certificate_model::HashCertSHA1(cert));
432 453
433 // Send certificate information to javascript. 454 // Send certificate information to javascript.
434 web_ui()->CallJavascriptFunctionUnsafe("cert_viewer.getCertificateFields", 455 web_ui()->CallJavascriptFunctionUnsafe("cert_viewer.getCertificateFields",
435 root_list); 456 root_list);
436 } 457 }
437 458
438 int CertificateViewerDialogHandler::GetCertificateIndex( 459 int CertificateViewerDialogHandler::GetCertificateIndex(
439 const base::ListValue* args) const { 460 const base::ListValue* args) const {
440 int cert_index; 461 int cert_index;
441 double val; 462 double val;
442 if (!(args->GetDouble(0, &val))) 463 if (!(args->GetDouble(0, &val)))
443 return -1; 464 return -1;
444 cert_index = static_cast<int>(val); 465 cert_index = static_cast<int>(val);
445 if (cert_index < 0 || cert_index >= static_cast<int>(cert_chain_.size())) 466 if (cert_index < 0 || cert_index >= static_cast<int>(cert_chain_.size()))
446 return -1; 467 return -1;
447 return cert_index; 468 return cert_index;
448 } 469 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/copresence_ui_handler.cc » ('j') | chrome/browser/ui/webui/identity_internals_ui.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698