Index: chrome/browser/ui/app_list/start_page_service.cc |
diff --git a/chrome/browser/ui/app_list/start_page_service.cc b/chrome/browser/ui/app_list/start_page_service.cc |
index 92a0fa5f52737dcae4438b19e478a36521af1f27..d60e4c2c9ec09d88361ae733049506687fce8ccf 100644 |
--- a/chrome/browser/ui/app_list/start_page_service.cc |
+++ b/chrome/browser/ui/app_list/start_page_service.cc |
@@ -6,6 +6,7 @@ |
#include <string> |
+#include "base/bind.h" |
#include "base/command_line.h" |
#include "base/memory/singleton.h" |
#include "base/metrics/user_metrics.h" |
@@ -111,7 +112,8 @@ StartPageService::StartPageService(Profile* profile) |
recommended_apps_(new RecommendedApps(profile)), |
state_(app_list::SPEECH_RECOGNITION_OFF), |
speech_button_toggled_manually_(false), |
- speech_result_obtained_(false) { |
+ speech_result_obtained_(false), |
+ webui_finished_loading_(false) { |
// If experimental hotwording is enabled, then we're always "ready". |
// Transitioning into the "hotword recognizing" state is handled by the |
// hotword extension. |
@@ -154,9 +156,15 @@ void StartPageService::AppListHidden() { |
} |
void StartPageService::ToggleSpeechRecognition() { |
+ DCHECK(contents_); |
speech_button_toggled_manually_ = true; |
- contents_->GetWebUI()->CallJavascriptFunction( |
- "appList.startPage.toggleSpeechRecognition"); |
+ if (webui_finished_loading_) |
tapted
2014/10/09 03:37:00
nit: needs curlies
Anand Mistry (off Chromium)
2014/10/13 21:52:00
Done.
|
+ contents_->GetWebUI()->CallJavascriptFunction( |
+ "appList.startPage.toggleSpeechRecognition"); |
+ else |
+ pending_webui_callbacks_.push_back( |
+ base::Bind(&StartPageService::ToggleSpeechRecognition, |
+ base::Unretained(this))); |
} |
bool StartPageService::HotwordEnabled() { |
@@ -228,6 +236,19 @@ void StartPageService::Shutdown() { |
UnloadContents(); |
} |
+void StartPageService::WebUILoaded() { |
+ // There's a race condition between the WebUI loading, and calling its JS |
+ // functions. Specifically, calling LoadContents() doesn't mean that the page |
+ // has loaded, but several code paths make this assumption. This function |
+ // allows us to defer calling JS functions until after the page has finished |
+ // loading. |
+ webui_finished_loading_ = true; |
+ for (const auto& cb : pending_webui_callbacks_) { |
Matt Giuca
2014/10/09 18:07:11
Nit: no curlies.
Anand Mistry (off Chromium)
2014/10/13 21:52:00
Done.
|
+ cb.Run(); |
+ } |
+ pending_webui_callbacks_.clear(); |
+} |
+ |
void StartPageService::LoadContents() { |
contents_.reset(content::WebContents::Create( |
content::WebContents::CreateParams(profile_))); |
@@ -250,6 +271,7 @@ void StartPageService::LoadContents() { |
void StartPageService::UnloadContents() { |
contents_.reset(); |
+ webui_finished_loading_ = false; |
} |
} // namespace app_list |