Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/webui/voicesearch_ui.h" | 5 #include "chrome/browser/ui/webui/voicesearch_ui.h" |
|
Evan Stade
2015/01/05 19:13:38
the files should be called voice_search_ui.*
Anand Mistry (off Chromium)
2015/01/05 23:33:01
That seems orthogonal to this change, and renaming
Evan Stade
2015/01/06 01:07:19
git is smart, especially if you use --follow. I th
Anand Mistry (off Chromium)
2015/01/06 01:53:33
Done.
| |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_enumerator.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 10 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
| 11 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 12 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 17 #include "chrome/browser/plugins/plugin_prefs.h" | 19 #include "chrome/browser/plugins/plugin_prefs.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/search/hotword_service.h" | 21 #include "chrome/browser/search/hotword_service.h" |
| 20 #include "chrome/browser/search/hotword_service_factory.h" | 22 #include "chrome/browser/search/hotword_service_factory.h" |
| 21 #include "chrome/browser/ui/app_list/start_page_service.h" | 23 #include "chrome/browser/ui/app_list/start_page_service.h" |
| 22 #include "chrome/browser/ui/webui/version_handler.h" | 24 #include "chrome/browser/ui/webui/version_handler.h" |
| 23 #include "chrome/common/chrome_content_client.h" | 25 #include "chrome/common/chrome_content_client.h" |
| 24 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
| 25 #include "chrome/common/chrome_version_info.h" | 27 #include "chrome/common/chrome_version_info.h" |
| 26 #include "chrome/common/extensions/extension_constants.h" | 28 #include "chrome/common/extensions/extension_constants.h" |
| 27 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 29 #include "chrome/grit/chromium_strings.h" | 31 #include "chrome/grit/chromium_strings.h" |
| 30 #include "chrome/grit/generated_resources.h" | 32 #include "chrome/grit/generated_resources.h" |
| 31 #include "chrome/grit/google_chrome_strings.h" | 33 #include "chrome/grit/google_chrome_strings.h" |
| 34 #include "content/public/browser/browser_thread.h" | |
| 32 #include "content/public/browser/plugin_service.h" | 35 #include "content/public/browser/plugin_service.h" |
| 33 #include "content/public/browser/url_data_source.h" | 36 #include "content/public/browser/url_data_source.h" |
| 34 #include "content/public/browser/web_ui.h" | 37 #include "content/public/browser/web_ui.h" |
| 35 #include "content/public/browser/web_ui_data_source.h" | 38 #include "content/public/browser/web_ui_data_source.h" |
| 36 #include "content/public/browser/web_ui_message_handler.h" | 39 #include "content/public/browser/web_ui_message_handler.h" |
| 37 #include "content/public/common/user_agent.h" | 40 #include "content/public/common/user_agent.h" |
| 38 #include "extensions/browser/extension_prefs.h" | 41 #include "extensions/browser/extension_prefs.h" |
| 39 #include "extensions/browser/extension_system.h" | 42 #include "extensions/browser/extension_system.h" |
| 40 #include "extensions/common/extension.h" | 43 #include "extensions/common/extension.h" |
| 41 #include "grit/browser_resources.h" | 44 #include "grit/browser_resources.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 const base::StringPiece& key, | 85 const base::StringPiece& key, |
| 83 const base::StringPiece& value) { | 86 const base::StringPiece& value) { |
| 84 AddPair16(list, UTF8ToUTF16(key), UTF8ToUTF16(value)); | 87 AddPair16(list, UTF8ToUTF16(key), UTF8ToUTF16(value)); |
| 85 } | 88 } |
| 86 | 89 |
| 87 // Generate an empty data-pair which acts as a line break. | 90 // Generate an empty data-pair which acts as a line break. |
| 88 void AddLineBreak(base::ListValue* list) { | 91 void AddLineBreak(base::ListValue* list) { |
| 89 AddPair(list, "", ""); | 92 AddPair(list, "", ""); |
| 90 } | 93 } |
| 91 | 94 |
| 95 void AddSharedModulePlatformsOnFileThread(base::ListValue* list, | |
| 96 const base::FilePath& path, | |
| 97 base::Closure callback) { | |
| 98 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | |
| 99 | |
| 100 if (!path.empty()) { | |
| 101 // Display available platforms for shared module. | |
| 102 base::FilePath platforms_path = path.AppendASCII("_platform_specific"); | |
| 103 base::FileEnumerator enumerator( | |
| 104 platforms_path, false, base::FileEnumerator::DIRECTORIES); | |
| 105 base::string16 files; | |
| 106 for (base::FilePath name = enumerator.Next(); | |
| 107 !name.empty(); | |
| 108 name = enumerator.Next()) { | |
| 109 files += name.BaseName().LossyDisplayName() + ASCIIToUTF16(" "); | |
| 110 } | |
| 111 AddPair16(list, | |
| 112 ASCIIToUTF16("Shared Module Platforms"), | |
| 113 files.empty() ? ASCIIToUTF16("undefined") : files); | |
| 114 AddLineBreak(list); | |
| 115 } | |
| 116 | |
| 117 content::BrowserThread::PostTask(content::BrowserThread::UI, | |
| 118 FROM_HERE, | |
| 119 callback); | |
| 120 } | |
| 121 | |
| 92 //////////////////////////////////////////////////////////////////////////////// | 122 //////////////////////////////////////////////////////////////////////////////// |
| 93 // | 123 // |
| 94 // VoiceSearchDomHandler | 124 // VoiceSearchDomHandler |
| 95 // | 125 // |
| 96 //////////////////////////////////////////////////////////////////////////////// | 126 //////////////////////////////////////////////////////////////////////////////// |
| 97 | 127 |
| 98 // The handler for Javascript messages for the about:flags page. | 128 // The handler for Javascript messages for the about:flags page. |
| 99 class VoiceSearchDomHandler : public WebUIMessageHandler { | 129 class VoiceSearchDomHandler : public WebUIMessageHandler { |
| 100 public: | 130 public: |
| 101 explicit VoiceSearchDomHandler(Profile* profile) : profile_(profile) {} | 131 explicit VoiceSearchDomHandler(Profile* profile) |
| 132 : profile_(profile), | |
| 133 weak_factory_(this) {} | |
| 102 | 134 |
| 103 ~VoiceSearchDomHandler() override {} | 135 ~VoiceSearchDomHandler() override {} |
| 104 | 136 |
| 105 // WebUIMessageHandler implementation. | 137 // WebUIMessageHandler implementation. |
| 106 void RegisterMessages() override { | 138 void RegisterMessages() override { |
| 107 web_ui()->RegisterMessageCallback( | 139 web_ui()->RegisterMessageCallback( |
| 108 "requestVoiceSearchInfo", | 140 "requestVoiceSearchInfo", |
| 109 base::Bind(&VoiceSearchDomHandler::HandleRequestVoiceSearchInfo, | 141 base::Bind(&VoiceSearchDomHandler::HandleRequestVoiceSearchInfo, |
| 110 base::Unretained(this))); | 142 base::Unretained(this))); |
| 111 } | 143 } |
| 112 | 144 |
| 113 private: | 145 private: |
| 114 // Callback for the "requestVoiceSearchInfo" message. No arguments. | 146 // Callback for the "requestVoiceSearchInfo" message. No arguments. |
| 115 void HandleRequestVoiceSearchInfo(const base::ListValue* args) { | 147 void HandleRequestVoiceSearchInfo(const base::ListValue* args) { |
| 148 PopulatePageInformation(); | |
| 149 } | |
| 150 | |
| 151 void ReturnVoiceSearchInfo(scoped_ptr<base::ListValue> info) { | |
| 152 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 153 DCHECK(info); | |
| 116 base::DictionaryValue voiceSearchInfo; | 154 base::DictionaryValue voiceSearchInfo; |
| 117 PopulatePageInformation(&voiceSearchInfo); | 155 // voiceSearchInfo will take ownership of |info|, and clean it up on |
|
Evan Stade
2015/01/05 19:13:38
nit: remove this comment
Anand Mistry (off Chromium)
2015/01/05 23:33:01
Done.
| |
| 118 web_ui()->CallJavascriptFunction("returnVoiceSearchInfo", | 156 // destruction. |
| 119 voiceSearchInfo); | 157 voiceSearchInfo.Set("voiceSearchInfo", info.release()); |
| 158 web_ui()->CallJavascriptFunction("returnVoiceSearchInfo", voiceSearchInfo); | |
| 120 } | 159 } |
| 121 | 160 |
| 122 // Fill in the data to be displayed on the page. | 161 // Fill in the data to be displayed on the page. |
| 123 void PopulatePageInformation(base::DictionaryValue* voiceSearchInfo) { | 162 void PopulatePageInformation() { |
| 124 // Store Key-Value pairs of about-information. | 163 // Store Key-Value pairs of about-information. |
| 125 scoped_ptr<base::ListValue> list(new base::ListValue()); | 164 scoped_ptr<base::ListValue> list(new base::ListValue()); |
| 126 | 165 |
| 127 // Populate information. | 166 // Populate information. |
| 128 AddOperatingSystemInfo(list.get()); | 167 AddOperatingSystemInfo(list.get()); |
| 129 AddAudioInfo(list.get()); | 168 AddAudioInfo(list.get()); |
| 130 AddLanguageInfo(list.get()); | 169 AddLanguageInfo(list.get()); |
| 131 AddHotwordInfo(list.get()); | 170 AddHotwordInfo(list.get()); |
| 171 AddAppListInfo(list.get()); | |
| 132 | 172 |
| 133 std::string extension_id = extension_misc::kHotwordExtensionId; | 173 std::string extension_id = extension_misc::kHotwordExtensionId; |
| 134 HotwordService* hotword_service = | 174 HotwordService* hotword_service = |
| 135 HotwordServiceFactory::GetForProfile(profile_); | 175 HotwordServiceFactory::GetForProfile(profile_); |
| 136 if (hotword_service && hotword_service->IsExperimentalHotwordingEnabled()) | 176 if (hotword_service && hotword_service->IsExperimentalHotwordingEnabled()) |
| 137 extension_id = extension_misc::kHotwordNewExtensionId; | 177 extension_id = extension_misc::kHotwordNewExtensionId; |
| 138 AddExtensionInfo(extension_id, "Extension", list.get()); | 178 AddExtensionInfo(extension_id, "Extension", list.get()); |
| 139 | 179 |
| 140 AddExtensionInfo(extension_misc::kHotwordSharedModuleId, | 180 AddExtensionInfo(extension_misc::kHotwordSharedModuleId, |
| 141 "Shared Module", | 181 "Shared Module", |
| 142 list.get()); | 182 list.get()); |
| 143 AddAppListInfo(list.get()); | |
| 144 | 183 |
| 145 // voiceSearchInfo will take ownership of list, and clean it up on | 184 base::FilePath path; |
| 146 // destruction. | 185 extensions::ExtensionSystem* extension_system = |
| 147 voiceSearchInfo->Set("voiceSearchInfo", list.release()); | 186 extensions::ExtensionSystem::Get(profile_); |
| 187 if (extension_system) { | |
| 188 ExtensionService* extension_service = | |
| 189 extension_system->extension_service(); | |
| 190 const extensions::Extension* extension = | |
| 191 extension_service->GetExtensionById( | |
| 192 extension_misc::kHotwordSharedModuleId, true); | |
| 193 if (extension) { | |
|
Evan Stade
2015/01/05 19:13:38
nit: no curlies
Anand Mistry (off Chromium)
2015/01/05 23:33:01
Done.
| |
| 194 path = extension->path(); | |
| 195 } | |
| 196 } | |
| 197 // Temporary, unowned ptr to |list| to pass into | |
| 198 // AddSharedModulePlatformsOnFileThread. | |
|
Evan Stade
2015/01/05 19:13:38
nit: remove comment
Anand Mistry (off Chromium)
2015/01/05 23:33:01
Done.
| |
| 199 base::ListValue* raw_list = list.get(); | |
| 200 content::BrowserThread::PostTask( | |
| 201 content::BrowserThread::FILE, | |
| 202 FROM_HERE, | |
| 203 base::Bind( | |
| 204 &AddSharedModulePlatformsOnFileThread, | |
| 205 raw_list, | |
| 206 path, | |
| 207 base::Bind(&VoiceSearchDomHandler::ReturnVoiceSearchInfo, | |
| 208 weak_factory_.GetWeakPtr(), | |
| 209 base::Passed(&list)))); | |
|
Evan Stade
2015/01/05 19:13:38
optional nit: I think list.Pass() is more self-doc
Anand Mistry (off Chromium)
2015/01/05 23:33:01
It fails to compile:
../../base/bind_internal.h:1
Evan Stade
2015/01/06 01:07:19
base::Passed(list.Pass());
Anand Mistry (off Chromium)
2015/01/06 01:53:33
Done.
| |
| 148 } | 210 } |
| 149 | 211 |
| 150 // Adds information regarding the system and chrome version info to list. | 212 // Adds information regarding the system and chrome version info to list. |
| 151 void AddOperatingSystemInfo(base::ListValue* list) { | 213 void AddOperatingSystemInfo(base::ListValue* list) { |
| 152 // Obtain the Chrome version info. | 214 // Obtain the Chrome version info. |
| 153 chrome::VersionInfo version_info; | 215 chrome::VersionInfo version_info; |
| 154 AddPair(list, | 216 AddPair(list, |
| 155 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME), | 217 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME), |
| 156 version_info.Version() + " (" + | 218 version_info.Version() + " (" + |
| 157 chrome::VersionInfo::GetVersionStringModifier() + ")"); | 219 chrome::VersionInfo::GetVersionStringModifier() + ")"); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 state = "SPEECH_RECOGNITION_STOPPING"; | 421 state = "SPEECH_RECOGNITION_STOPPING"; |
| 360 break; | 422 break; |
| 361 case app_list::SPEECH_RECOGNITION_NETWORK_ERROR: | 423 case app_list::SPEECH_RECOGNITION_NETWORK_ERROR: |
| 362 state = "SPEECH_RECOGNITION_NETWORK_ERROR"; | 424 state = "SPEECH_RECOGNITION_NETWORK_ERROR"; |
| 363 break; | 425 break; |
| 364 default: | 426 default: |
| 365 state = "undefined"; | 427 state = "undefined"; |
| 366 } | 428 } |
| 367 } | 429 } |
| 368 AddPair(list, "Start Page State", state); | 430 AddPair(list, "Start Page State", state); |
| 431 AddLineBreak(list); | |
| 369 #endif | 432 #endif |
| 370 } | 433 } |
| 371 | 434 |
| 372 Profile* profile_; | 435 Profile* profile_; |
| 436 base::WeakPtrFactory<VoiceSearchDomHandler> weak_factory_; | |
| 373 | 437 |
| 374 DISALLOW_COPY_AND_ASSIGN(VoiceSearchDomHandler); | 438 DISALLOW_COPY_AND_ASSIGN(VoiceSearchDomHandler); |
| 375 }; | 439 }; |
| 376 | 440 |
| 377 } // namespace | 441 } // namespace |
| 378 | 442 |
| 379 /////////////////////////////////////////////////////////////////////////////// | 443 /////////////////////////////////////////////////////////////////////////////// |
| 380 // | 444 // |
| 381 // VoiceSearchUI | 445 // VoiceSearchUI |
| 382 // | 446 // |
| 383 /////////////////////////////////////////////////////////////////////////////// | 447 /////////////////////////////////////////////////////////////////////////////// |
| 384 | 448 |
| 385 VoiceSearchUI::VoiceSearchUI(content::WebUI* web_ui) | 449 VoiceSearchUI::VoiceSearchUI(content::WebUI* web_ui) |
| 386 : content::WebUIController(web_ui) { | 450 : content::WebUIController(web_ui) { |
| 387 Profile* profile = Profile::FromWebUI(web_ui); | 451 Profile* profile = Profile::FromWebUI(web_ui); |
| 388 web_ui->AddMessageHandler(new VoiceSearchDomHandler(profile)); | 452 web_ui->AddMessageHandler(new VoiceSearchDomHandler(profile)); |
| 389 | 453 |
| 390 // Set up the about:voicesearch source. | 454 // Set up the about:voicesearch source. |
| 391 content::WebUIDataSource::Add(profile, CreateVoiceSearchUiHtmlSource()); | 455 content::WebUIDataSource::Add(profile, CreateVoiceSearchUiHtmlSource()); |
| 392 } | 456 } |
| 393 | 457 |
| 394 VoiceSearchUI::~VoiceSearchUI() {} | 458 VoiceSearchUI::~VoiceSearchUI() {} |
| OLD | NEW |