OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/app_list/start_page_service.h" | 5 #include "chrome/browser/ui/app_list/start_page_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 observers_.AddObserver(observer); | 130 observers_.AddObserver(observer); |
131 } | 131 } |
132 | 132 |
133 void StartPageService::RemoveObserver(StartPageObserver* observer) { | 133 void StartPageService::RemoveObserver(StartPageObserver* observer) { |
134 observers_.RemoveObserver(observer); | 134 observers_.RemoveObserver(observer); |
135 } | 135 } |
136 | 136 |
137 void StartPageService::AppListShown() { | 137 void StartPageService::AppListShown() { |
138 if (!contents_) { | 138 if (!contents_) { |
139 LoadContents(); | 139 LoadContents(); |
140 } else { | 140 } else if (contents_->GetWebUI()) { |
141 // If experimental hotwording is enabled, don't enable hotwording in the | 141 // If experimental hotwording is enabled, don't enable hotwording in the |
142 // start page, since the hotword extension is taking care of this. | 142 // start page, since the hotword extension is taking care of this. |
143 bool hotword_enabled = HotwordEnabled() && | 143 bool hotword_enabled = HotwordEnabled() && |
144 !HotwordService::IsExperimentalHotwordingEnabled(); | 144 !HotwordService::IsExperimentalHotwordingEnabled(); |
145 contents_->GetWebUI()->CallJavascriptFunction( | 145 contents_->GetWebUI()->CallJavascriptFunction( |
146 "appList.startPage.onAppListShown", | 146 "appList.startPage.onAppListShown", |
147 base::FundamentalValue(hotword_enabled)); | 147 base::FundamentalValue(hotword_enabled)); |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 void StartPageService::AppListHidden() { | 151 void StartPageService::AppListHidden() { |
152 contents_->GetWebUI()->CallJavascriptFunction( | 152 if (contents_->GetWebUI()) { |
153 "appList.startPage.onAppListHidden"); | 153 contents_->GetWebUI()->CallJavascriptFunction( |
| 154 "appList.startPage.onAppListHidden"); |
| 155 } |
154 if (!app_list::switches::IsExperimentalAppListEnabled()) | 156 if (!app_list::switches::IsExperimentalAppListEnabled()) |
155 UnloadContents(); | 157 UnloadContents(); |
156 } | 158 } |
157 | 159 |
158 void StartPageService::ToggleSpeechRecognition() { | 160 void StartPageService::ToggleSpeechRecognition() { |
159 DCHECK(contents_); | 161 DCHECK(contents_); |
160 speech_button_toggled_manually_ = true; | 162 speech_button_toggled_manually_ = true; |
| 163 if (!contents_->GetWebUI()) |
| 164 return; |
| 165 |
161 if (webui_finished_loading_) { | 166 if (webui_finished_loading_) { |
162 contents_->GetWebUI()->CallJavascriptFunction( | 167 contents_->GetWebUI()->CallJavascriptFunction( |
163 "appList.startPage.toggleSpeechRecognition"); | 168 "appList.startPage.toggleSpeechRecognition"); |
164 } else { | 169 } else { |
165 pending_webui_callbacks_.push_back( | 170 pending_webui_callbacks_.push_back( |
166 base::Bind(&StartPageService::ToggleSpeechRecognition, | 171 base::Bind(&StartPageService::ToggleSpeechRecognition, |
167 base::Unretained(this))); | 172 base::Unretained(this))); |
168 } | 173 } |
169 } | 174 } |
170 | 175 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 273 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
269 std::string()); | 274 std::string()); |
270 } | 275 } |
271 | 276 |
272 void StartPageService::UnloadContents() { | 277 void StartPageService::UnloadContents() { |
273 contents_.reset(); | 278 contents_.reset(); |
274 webui_finished_loading_ = false; | 279 webui_finished_loading_ = false; |
275 } | 280 } |
276 | 281 |
277 } // namespace app_list | 282 } // namespace app_list |
OLD | NEW |