summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkgr@chromium.org <kgr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-12 22:08:13 +0000
committerkgr@chromium.org <kgr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-12 22:08:13 +0000
commit18b3bab80e64f82e50c46fb4d8ce0b68cb130aa7 (patch)
tree429a5aa69a242474a1f3257f400193b7d9fb0601
parentddb1b3a81fe038aca0421a4b3bb1e8eb74f91bf1 (diff)
downloadchromium_src-18b3bab80e64f82e50c46fb4d8ce0b68cb130aa7.zip
chromium_src-18b3bab80e64f82e50c46fb4d8ce0b68cb130aa7.tar.gz
chromium_src-18b3bab80e64f82e50c46fb4d8ce0b68cb130aa7.tar.bz2
Shorten startup time for WebUI Certificate Viewer.
Two approaches were taken: 1. Data necessary for the first tab is now provided with GetDialogArgs() so that the dialog already has the data when needed rather than having to issue and wait for a requrest to the C++ side. 2. Data required for the second tab, which isn't shown on startup, is deferred until a little after startup. BUG=114371 TEST=see ticket for details Review URL: http://codereview.chromium.org/9963110 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132069 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/resources/certificate_viewer.js28
-rw-r--r--chrome/browser/ui/webui/certificate_viewer_webui.cc111
-rw-r--r--chrome/browser/ui/webui/certificate_viewer_webui.h4
3 files changed, 75 insertions, 68 deletions
diff --git a/chrome/browser/resources/certificate_viewer.js b/chrome/browser/resources/certificate_viewer.js
index 95a5d82..417f560 100644
--- a/chrome/browser/resources/certificate_viewer.js
+++ b/chrome/browser/resources/certificate_viewer.js
@@ -10,15 +10,29 @@ cr.define('cert_viewer', function() {
* substituting in translated strings and requesting certificate details.
*/
function initialize() {
- $('export').onclick = exportCertificate;
cr.ui.decorate('tabbox', cr.ui.TabBox);
- initializeTree($('hierarchy'), showCertificateFields);
- initializeTree($('cert-fields'), showCertificateFieldValue);
-
i18nTemplate.process(document, templateData);
+
+ var args = JSON.parse(chrome.dialogArguments);
+ getCertificateInfo(args);
+
+ // The second tab's contents aren't visible on startup, so we can
+ // shorten startup by not populating those controls until after we
+ // have had a chance to draw the visible controls the first time.
+ // The value of 200ms is quick enough that the user couldn't open the
+ // tab in that time but long enough to allow the first tab to draw on
+ // even the slowest machine.
+ setTimeout(function() {
+ initializeTree($('hierarchy'), showCertificateFields);
+ initializeTree($('cert-fields'), showCertificateFieldValue);
+ createCertificateHierarchy(args.hierarchy);
+ }, 200);
+
stripGtkAccessorKeys();
- chrome.send('requestCertificateInfo');
+
+ $('export').onclick = exportCertificate;
+
// TODO(kochi): ESC key should be handled in the views window side.
document.addEventListener('keydown', function(e) {
if (e.keyCode == 27) // ESC
@@ -72,7 +86,6 @@ cr.define('cert_viewer', function() {
for (var key in certInfo.general) {
$(key).textContent = certInfo.general[key];
}
- createCertificateHierarchy(certInfo.hierarchy);
}
/**
@@ -147,7 +160,7 @@ cr.define('cert_viewer', function() {
treeItem.add(treeItem.detail.children['root'] =
constructTree(certFields[0]));
revealTree(treeItem);
- // Ensure the list is scrolled to the top by selecting the first item.
+ // Ensure the list is scrolled to the top by selecting the first item.
treeItem.children[0].selected = true;
}
@@ -173,7 +186,6 @@ cr.define('cert_viewer', function() {
return {
initialize: initialize,
- getCertificateInfo: getCertificateInfo,
getCertificateFields: getCertificateFields,
};
});
diff --git a/chrome/browser/ui/webui/certificate_viewer_webui.cc b/chrome/browser/ui/webui/certificate_viewer_webui.cc
index ac94d3d..af09b6f 100644
--- a/chrome/browser/ui/webui/certificate_viewer_webui.cc
+++ b/chrome/browser/ui/webui/certificate_viewer_webui.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/i18n/time_formatting.h"
+#include "base/json/json_writer.h"
#include "base/utf_string_conversions.h"
#include "base/string_number_conversions.h"
#include "chrome/browser/certificate_viewer.h"
@@ -101,61 +102,8 @@ void CertificateViewerDialog::GetDialogSize(gfx::Size* size) const {
}
std::string CertificateViewerDialog::GetDialogArgs() const {
- return std::string();
-}
-
-void CertificateViewerDialog::OnDialogClosed(const std::string& json_retval) {
- delete this;
-}
-
-void CertificateViewerDialog::OnCloseContents(WebContents* source,
- bool* out_close_dialog) {
- if (out_close_dialog)
- *out_close_dialog = true;
-}
-
-bool CertificateViewerDialog::ShouldShowDialogTitle() const {
- return true;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// CertificateViewerDialogHandler
-
-CertificateViewerDialogHandler::CertificateViewerDialogHandler(
- gfx::NativeWindow window,
- net::X509Certificate* cert) : cert_(cert), window_(window) {
- x509_certificate_model::GetCertChainFromCert(cert_->os_cert_handle(),
- &cert_chain_);
-}
+ std::string data;
-CertificateViewerDialogHandler::~CertificateViewerDialogHandler() {
-}
-
-void CertificateViewerDialogHandler::RegisterMessages() {
- web_ui()->RegisterMessageCallback("exportCertificate",
- base::Bind(&CertificateViewerDialogHandler::ExportCertificate,
- base::Unretained(this)));
- web_ui()->RegisterMessageCallback("requestCertificateInfo",
- base::Bind(&CertificateViewerDialogHandler::RequestCertificateInfo,
- base::Unretained(this)));
- web_ui()->RegisterMessageCallback("requestCertificateFields",
- base::Bind(&CertificateViewerDialogHandler::RequestCertificateFields,
- base::Unretained(this)));
-}
-
-void CertificateViewerDialogHandler::ExportCertificate(
- const base::ListValue* args) {
- int cert_index = GetCertificateIndex(args);
- if (cert_index < 0)
- return;
-
- ShowCertExportDialog(web_ui()->GetWebContents(),
- window_,
- cert_chain_[cert_index]);
-}
-
-void CertificateViewerDialogHandler::RequestCertificateInfo(
- const base::ListValue* args) {
// Certificate information. The keys in this dictionary's general key
// correspond to the IDs in the Html page.
DictionaryValue cert_info;
@@ -245,8 +193,59 @@ void CertificateViewerDialogHandler::RequestCertificateInfo(
// Set the last node as the top of the certificate hierarchy.
cert_info.Set("hierarchy", children);
- // Send certificate information to javascript.
- web_ui()->CallJavascriptFunction("cert_viewer.getCertificateInfo", cert_info);
+ base::JSONWriter::WriteWithOptions(
+ &cert_info,
+ base::JSONWriter::OPTIONS_DO_NOT_ESCAPE,
+ &data);
+
+ return data;
+}
+
+void CertificateViewerDialog::OnDialogClosed(const std::string& json_retval) {
+ delete this;
+}
+
+void CertificateViewerDialog::OnCloseContents(WebContents* source,
+ bool* out_close_dialog) {
+ if (out_close_dialog)
+ *out_close_dialog = true;
+}
+
+bool CertificateViewerDialog::ShouldShowDialogTitle() const {
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// CertificateViewerDialogHandler
+
+CertificateViewerDialogHandler::CertificateViewerDialogHandler(
+ gfx::NativeWindow window,
+ net::X509Certificate* cert) : cert_(cert), window_(window) {
+ x509_certificate_model::GetCertChainFromCert(cert_->os_cert_handle(),
+ &cert_chain_);
+}
+
+CertificateViewerDialogHandler::~CertificateViewerDialogHandler() {
+}
+
+void CertificateViewerDialogHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback("exportCertificate",
+ base::Bind(&CertificateViewerDialogHandler::ExportCertificate,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback("requestCertificateFields",
+ base::Bind(&CertificateViewerDialogHandler::RequestCertificateFields,
+ base::Unretained(this)));
+}
+
+void CertificateViewerDialogHandler::ExportCertificate(
+ const base::ListValue* args) {
+ int cert_index = GetCertificateIndex(args);
+ if (cert_index < 0)
+ return;
+
+ ShowCertExportDialog(web_ui()->GetWebContents(),
+ window_,
+ cert_chain_[cert_index]);
}
void CertificateViewerDialogHandler::RequestCertificateFields(
diff --git a/chrome/browser/ui/webui/certificate_viewer_webui.h b/chrome/browser/ui/webui/certificate_viewer_webui.h
index a1553d1..f6f6e4e 100644
--- a/chrome/browser/ui/webui/certificate_viewer_webui.h
+++ b/chrome/browser/ui/webui/certificate_viewer_webui.h
@@ -91,10 +91,6 @@ class CertificateViewerDialogHandler : public content::WebUIMessageHandler {
// The input is an integer index to the certificate in the chain to view.
void RequestCertificateFields(const base::ListValue* args);
- // Extracts the certificate details and returns them to the javascript
- // function cert_viewer.getCertificateInfo in a dictionary structure.
- void RequestCertificateInfo(const base::ListValue* args);
-
// Helper function to get the certificate index from |args|. Returns -1 if
// the index is out of range.
int GetCertificateIndex(const base::ListValue* args) const;