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

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: Fix android build 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..43d2a2f9566000ac0775912f41c66432a4a98209 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,16 @@ void StartPageService::AppListHidden() {
}
void StartPageService::ToggleSpeechRecognition() {
+ DCHECK(contents_);
speech_button_toggled_manually_ = true;
- contents_->GetWebUI()->CallJavascriptFunction(
- "appList.startPage.toggleSpeechRecognition");
+ if (webui_finished_loading_) {
+ contents_->GetWebUI()->CallJavascriptFunction(
+ "appList.startPage.toggleSpeechRecognition");
+ } else {
+ pending_webui_callbacks_.push_back(
+ base::Bind(&StartPageService::ToggleSpeechRecognition,
+ base::Unretained(this)));
+ }
}
bool StartPageService::HotwordEnabled() {
@@ -228,6 +237,18 @@ 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_)
+ 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
« no previous file with comments | « chrome/browser/ui/app_list/start_page_service.h ('k') | chrome/browser/ui/webui/app_list/start_page_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698