Commit 0d8be1e4 authored by Katie D's avatar Katie D Committed by Commit Bot

Adds links to Text-to-Speech extensions settings pages from tts settings.

Any extension that supports the Text-to-Speech callbacks will be able to
be linked from the Text-to-Speech settings page.

Bug: 823359
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I2f2ae0d9008e48faccd8c3929b902cb925afb877
Reviewed-on: https://chromium-review.googlesource.com/1030755Reviewed-by: default avatarHector Carmona <hcarmona@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Commit-Queue: Katie Dektar <katie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554947}
parent f7b2214a
...@@ -28,3 +28,8 @@ Window.prototype.SpeechSynthesisUtterance = function() {}; ...@@ -28,3 +28,8 @@ Window.prototype.SpeechSynthesisUtterance = function() {};
* extensionId: string, id: string}} * extensionId: string, id: string}}
*/ */
let TtsHandlerVoice; let TtsHandlerVoice;
/**
* @typedef {{name: string, extensionId: string, optionsPage: string}}
*/
let TtsHandlerExtension;
...@@ -86,7 +86,19 @@ ...@@ -86,7 +86,19 @@
</paper-button> </paper-button>
</div> </div>
<h2>$i18n{textToSpeechEngines}</h2> <h2>$i18n{textToSpeechEngines}</h2>
<div class="settings-box block first"> <template is="dom-repeat" items="[[extensions]]" as="extension">
<div class="settings-box continuation">
<div id="extension_name_[[index]]" class="start">
[[extension.name]]
</div>
<paper-button on-click="onManageTtsEngineSettingsClick_"
aria-describedby="extension_name_[[index]]"
hidden="[[!extension.options_page]]">
$i18n{settings}
</paper-button>
</div>
</template>
<div class="settings-box block continuation">
<a href="">$i18n{textToSpeechInstallEngines}</a> <a href="">$i18n{textToSpeechInstallEngines}</a>
</div> </div>
</template> </template>
......
...@@ -36,6 +36,9 @@ Polymer({ ...@@ -36,6 +36,9 @@ Polymer({
this.addWebUIListener( this.addWebUIListener(
'all-voice-data-updated', this.populateVoiceList_.bind(this)); 'all-voice-data-updated', this.populateVoiceList_.bind(this));
chrome.send('getAllTtsVoiceData'); chrome.send('getAllTtsVoiceData');
this.addWebUIListener(
'tts-extensions-updated', this.populateExtensionList_.bind(this));
chrome.send('getTtsExtensions');
}, },
/** /**
...@@ -64,6 +67,15 @@ Polymer({ ...@@ -64,6 +67,15 @@ Polymer({
this.set('languagesToVoices', Object.values(result)); this.set('languagesToVoices', Object.values(result));
}, },
/**
* Sets the list of Text-to-Speech extensions for the UI.
* @param {Array<TtsHandlerExtension>} extensions
* @private
*/
populateExtensionList_: function(extensions) {
this.extensions = extensions;
},
/** /**
* A function used for sorting languages alphabetically. * A function used for sorting languages alphabetically.
* @param {Object} first A languageToVoices array item. * @param {Object} first A languageToVoices array item.
...@@ -98,6 +110,14 @@ Polymer({ ...@@ -98,6 +110,14 @@ Polymer({
}); });
}, },
/**
* Function to navigate to the options page for an extension.
* @param {TtsHandlerExtension} engine
* @private */
onManageTtsEngineSettingsClick_: function(engine) {
window.open(engine.optionsPage, '_blank');
},
/** @private */ /** @private */
onPreviewTtsClick_: function() { onPreviewTtsClick_: function() {
let utter = new window.SpeechSynthesisUtterance(); let utter = new window.SpeechSynthesisUtterance();
......
...@@ -89,6 +89,10 @@ bool TtsEngineExtensionObserver::SawExtensionLoad( ...@@ -89,6 +89,10 @@ bool TtsEngineExtensionObserver::SawExtensionLoad(
return previously_loaded; return previously_loaded;
} }
const std::set<std::string> TtsEngineExtensionObserver::GetTtsExtensions() {
return engine_extension_ids_;
}
const std::vector<extensions::TtsVoice>* const std::vector<extensions::TtsVoice>*
TtsEngineExtensionObserver::GetRuntimeVoices(const std::string extension_id) { TtsEngineExtensionObserver::GetRuntimeVoices(const std::string extension_id) {
auto it = extension_id_to_runtime_voices_.find(extension_id); auto it = extension_id_to_runtime_voices_.find(extension_id);
......
...@@ -32,6 +32,9 @@ class TtsEngineExtensionObserver ...@@ -32,6 +32,9 @@ class TtsEngineExtensionObserver
// as loaded immediately if |update| is set to true. // as loaded immediately if |update| is set to true.
bool SawExtensionLoad(const std::string& extension_id, bool update); bool SawExtensionLoad(const std::string& extension_id, bool update);
// Gets the currently loaded TTS extension ids.
const std::set<std::string> GetTtsExtensions();
// Gets voices for |extension_id| updated through TtsEngine.updateVoices. // Gets voices for |extension_id| updated through TtsEngine.updateVoices.
const std::vector<extensions::TtsVoice>* GetRuntimeVoices( const std::vector<extensions::TtsVoice>* GetRuntimeVoices(
const std::string extension_id); const std::string extension_id);
......
...@@ -8,9 +8,16 @@ ...@@ -8,9 +8,16 @@
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
#include "chrome/browser/speech/extension_api/tts_engine_extension_observer.h"
#include "chrome/browser/speech/tts_controller_impl.h" #include "chrome/browser/speech/tts_controller_impl.h"
#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_constants.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/manifest_handlers/options_page_info.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
namespace settings { namespace settings {
...@@ -19,6 +26,35 @@ void TtsHandler::HandleGetAllTtsVoiceData(const base::ListValue* args) { ...@@ -19,6 +26,35 @@ void TtsHandler::HandleGetAllTtsVoiceData(const base::ListValue* args) {
OnVoicesChanged(); OnVoicesChanged();
} }
void TtsHandler::HandleGetTtsExtensions(const base::ListValue* args) {
base::ListValue responses;
Profile* profile = Profile::FromWebUI(web_ui());
extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(profile);
const std::set<std::string> extensions =
TtsEngineExtensionObserver::GetInstance(profile)->GetTtsExtensions();
std::set<std::string>::const_iterator iter;
for (iter = extensions.begin(); iter != extensions.end(); ++iter) {
const std::string extension_id = *iter;
const extensions::Extension* extension =
registry->GetInstalledExtension(extension_id);
base::DictionaryValue response;
response.SetPath({"name"}, base::Value(extension->name()));
response.SetPath({"extensionId"}, base::Value(extension_id));
if (extensions::OptionsPageInfo::HasOptionsPage(extension)) {
response.SetPath(
{"optionsPage"},
base::Value(
extensions::OptionsPageInfo::GetOptionsPage(extension).spec()));
}
responses.GetList().push_back(std::move(response));
}
CallJavascriptFunction("cr.webUIListenerCallback",
base::Value("tts-extensions-updated"), responses);
}
void TtsHandler::OnVoicesChanged() { void TtsHandler::OnVoicesChanged() {
TtsControllerImpl* impl = TtsControllerImpl::GetInstance(); TtsControllerImpl* impl = TtsControllerImpl::GetInstance();
std::vector<VoiceData> voices; std::vector<VoiceData> voices;
...@@ -39,6 +75,9 @@ void TtsHandler::OnVoicesChanged() { ...@@ -39,6 +75,9 @@ void TtsHandler::OnVoicesChanged() {
AllowJavascript(); AllowJavascript();
CallJavascriptFunction("cr.webUIListenerCallback", CallJavascriptFunction("cr.webUIListenerCallback",
base::Value("all-voice-data-updated"), responses); base::Value("all-voice-data-updated"), responses);
// Also refresh the TTS extensions in case they have changed.
HandleGetTtsExtensions(nullptr);
} }
void TtsHandler::RegisterMessages() { void TtsHandler::RegisterMessages() {
...@@ -46,6 +85,10 @@ void TtsHandler::RegisterMessages() { ...@@ -46,6 +85,10 @@ void TtsHandler::RegisterMessages() {
"getAllTtsVoiceData", "getAllTtsVoiceData",
base::BindRepeating(&TtsHandler::HandleGetAllTtsVoiceData, base::BindRepeating(&TtsHandler::HandleGetAllTtsVoiceData,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"getTtsExtensions",
base::BindRepeating(&TtsHandler::HandleGetTtsExtensions,
base::Unretained(this)));
} }
} // namespace settings } // namespace settings
...@@ -17,6 +17,7 @@ class TtsHandler : public SettingsPageUIHandler, public VoicesChangedDelegate { ...@@ -17,6 +17,7 @@ class TtsHandler : public SettingsPageUIHandler, public VoicesChangedDelegate {
~TtsHandler() override = default; ~TtsHandler() override = default;
void HandleGetAllTtsVoiceData(const base::ListValue* args); void HandleGetAllTtsVoiceData(const base::ListValue* args);
void HandleGetTtsExtensions(const base::ListValue* args);
// SettingsPageUIHandler implementation. // SettingsPageUIHandler implementation.
void RegisterMessages() override; void RegisterMessages() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment