summaryrefslogtreecommitdiffstats
path: root/components/proximity_auth
diff options
context:
space:
mode:
authortengs <tengs@chromium.org>2015-08-18 10:59:46 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-18 18:00:17 +0000
commitc62af475160e989969ed29e4b389d31bb1c4e185 (patch)
tree2cd504dbb3f6569d5ced8770f20896e64db911c4 /components/proximity_auth
parent82008bffc32d3adced6917f9b7eac58b7669b5fe (diff)
downloadchromium_src-c62af475160e989969ed29e4b389d31bb1c4e185.zip
chromium_src-c62af475160e989969ed29e4b389d31bb1c4e185.tar.gz
chromium_src-c62af475160e989969ed29e4b389d31bb1c4e185.tar.bz2
Fix crash in chrome://proximity-auth when executing JS with uninitialized page.
This fix initializes members that cause JS to be executed only upon receiving a message from the page inidicating it is initialized. BUG=516625 TEST=manual Review URL: https://codereview.chromium.org/1299453002 Cr-Commit-Position: refs/heads/master@{#343965}
Diffstat (limited to 'components/proximity_auth')
-rw-r--r--components/proximity_auth/webui/proximity_auth_webui_handler.cc25
-rw-r--r--components/proximity_auth/webui/proximity_auth_webui_handler.h1
-rw-r--r--components/proximity_auth/webui/resources/cryptauth_interface.js5
3 files changed, 21 insertions, 10 deletions
diff --git a/components/proximity_auth/webui/proximity_auth_webui_handler.cc b/components/proximity_auth/webui/proximity_auth_webui_handler.cc
index da5f19b..228cb94 100644
--- a/components/proximity_auth/webui/proximity_auth_webui_handler.cc
+++ b/components/proximity_auth/webui/proximity_auth_webui_handler.cc
@@ -131,6 +131,11 @@ ProximityAuthWebUIHandler::~ProximityAuthWebUIHandler() {
void ProximityAuthWebUIHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
+ "onWebContentsInitialized",
+ base::Bind(&ProximityAuthWebUIHandler::OnWebContentsInitialized,
+ base::Unretained(this)));
+
+ web_ui()->RegisterMessageCallback(
"clearLogBuffer", base::Bind(&ProximityAuthWebUIHandler::ClearLogBuffer,
base::Unretained(this)));
@@ -168,16 +173,6 @@ void ProximityAuthWebUIHandler::RegisterMessages() {
"toggleConnection",
base::Bind(&ProximityAuthWebUIHandler::ToggleConnection,
base::Unretained(this)));
-
- InitGCMManager();
- InitEnrollmentManager();
- InitDeviceManager();
-
- // Note: We add the observer for the logs after initializing the managers
- // because when this function is called, the WebUI's underlying WebContents
- // has not been initialized, so calling any JavaScript function will crash
- // Chrome.
- LogBuffer::GetInstance()->AddObserver(this);
}
void ProximityAuthWebUIHandler::OnLogMessageAdded(
@@ -233,6 +228,16 @@ void ProximityAuthWebUIHandler::OnSyncFinished(
}
}
+void ProximityAuthWebUIHandler::OnWebContentsInitialized(
+ const base::ListValue* args) {
+ if (!gcm_manager_ || !enrollment_manager_ || !device_manager_) {
+ InitGCMManager();
+ InitEnrollmentManager();
+ InitDeviceManager();
+ LogBuffer::GetInstance()->AddObserver(this);
+ }
+}
+
void ProximityAuthWebUIHandler::GetLogMessages(const base::ListValue* args) {
base::ListValue json_logs;
for (const auto& log : *LogBuffer::GetInstance()->logs()) {
diff --git a/components/proximity_auth/webui/proximity_auth_webui_handler.h b/components/proximity_auth/webui/proximity_auth_webui_handler.h
index 1f87687..a6667b0 100644
--- a/components/proximity_auth/webui/proximity_auth_webui_handler.h
+++ b/components/proximity_auth/webui/proximity_auth_webui_handler.h
@@ -70,6 +70,7 @@ class ProximityAuthWebUIHandler : public content::WebUIMessageHandler,
CryptAuthDeviceManager::DeviceChangeResult device_change_result) override;
// Message handler callbacks.
+ void OnWebContentsInitialized(const base::ListValue* args);
void GetLogMessages(const base::ListValue* args);
void ClearLogBuffer(const base::ListValue* args);
void ToggleUnlockKey(const base::ListValue* args);
diff --git a/components/proximity_auth/webui/resources/cryptauth_interface.js b/components/proximity_auth/webui/resources/cryptauth_interface.js
index 4e22c38..a7dbdb7 100644
--- a/components/proximity_auth/webui/resources/cryptauth_interface.js
+++ b/components/proximity_auth/webui/resources/cryptauth_interface.js
@@ -98,3 +98,8 @@ CryptAuthInterface = {
});
},
};
+
+// This message tells the native WebUI handler that the WebContents backing the
+// WebUI has been iniitalized. This signal allows the native handler to execute
+// JavaScript inside the page.
+chrome.send('onWebContentsInitialized');