diff options
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'); |