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

Unified Diff: chrome/browser/ui/app_list/start_page_service.cc

Issue 631913004: Open the launcher when hotword is triggered in always-on mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hotword-google-com-ntp
Patch Set: Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698