Commit b5f35752 authored by evliu's avatar evliu Committed by Commit Bot

Add Live Caption Blocklist

This CL blocklists a hardcoded list of websites from the using the Live
Caption feature because those frequently visited websites contain their
own captions. This blocklist is temporary and is  intended to reduce the
usage of the feature while it is implemented using the Open Speech API
behind a flag. The blocklist will be removed when the feature is
officially launched with the Speech On-Device API.

Bug: 1090862
Change-Id: Icc064a7dfd459a930afb5dadd5a52d488495094d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2229149
Commit-Queue: Evan Liu <evliu@google.com>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#776615}
parent 9f11da1a
...@@ -6,13 +6,28 @@ ...@@ -6,13 +6,28 @@
#include <utility> #include <utility>
#include "base/metrics/field_trial_params.h"
#include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_frame.h"
#include "media/base/channel_mixer.h" #include "media/base/channel_mixer.h"
#include "media/base/media_switches.h"
#include "media/mojo/mojom/media_types.mojom.h" #include "media/mojo/mojom/media_types.mojom.h"
#include "third_party/blink/public/common/browser_interface_broker_proxy.h" #include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/web/web_frame.h"
#include "third_party/blink/public/web/web_local_frame.h"
// Get the list of blocked URLs defined by the Finch experiment parameter. These
// websites provide captions by default and thus do not require the live caption
// feature.
std::vector<std::string> GetBlockedURLs() {
return base::SplitString(base::GetFieldTrialParamValueByFeature(
media::kLiveCaption, "blocked_websites"),
",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
}
ChromeSpeechRecognitionClient::ChromeSpeechRecognitionClient( ChromeSpeechRecognitionClient::ChromeSpeechRecognitionClient(
content::RenderFrame* render_frame) { content::RenderFrame* render_frame)
: blocked_urls_(GetBlockedURLs()) {
mojo::PendingReceiver<media::mojom::SpeechRecognitionContext> mojo::PendingReceiver<media::mojom::SpeechRecognitionContext>
speech_recognition_context_receiver = speech_recognition_context_receiver =
speech_recognition_context_.BindNewPipeAndPassReceiver(); speech_recognition_context_.BindNewPipeAndPassReceiver();
...@@ -25,6 +40,8 @@ ChromeSpeechRecognitionClient::ChromeSpeechRecognitionClient( ...@@ -25,6 +40,8 @@ ChromeSpeechRecognitionClient::ChromeSpeechRecognitionClient(
std::move(speech_recognition_context_receiver)); std::move(speech_recognition_context_receiver));
render_frame->GetBrowserInterfaceBroker()->GetInterface( render_frame->GetBrowserInterfaceBroker()->GetInterface(
caption_host_.BindNewPipeAndPassReceiver()); caption_host_.BindNewPipeAndPassReceiver());
is_website_blocked_ = IsUrlBlocked(
render_frame->GetWebFrame()->GetSecurityOrigin().ToString().Utf8());
} }
void ChromeSpeechRecognitionClient::OnRecognizerBound( void ChromeSpeechRecognitionClient::OnRecognizerBound(
...@@ -44,7 +61,7 @@ void ChromeSpeechRecognitionClient::AddAudio( ...@@ -44,7 +61,7 @@ void ChromeSpeechRecognitionClient::AddAudio(
} }
bool ChromeSpeechRecognitionClient::IsSpeechRecognitionAvailable() { bool ChromeSpeechRecognitionClient::IsSpeechRecognitionAvailable() {
return is_browser_requesting_transcription_ && return !is_website_blocked_ && is_browser_requesting_transcription_ &&
speech_recognition_recognizer_.is_bound() && speech_recognition_recognizer_.is_bound() &&
speech_recognition_recognizer_.is_connected(); speech_recognition_recognizer_.is_connected();
} }
...@@ -134,3 +151,7 @@ ChromeSpeechRecognitionClient::ConvertToAudioDataS16( ...@@ -134,3 +151,7 @@ ChromeSpeechRecognitionClient::ConvertToAudioDataS16(
return signed_buffer; return signed_buffer;
} }
bool ChromeSpeechRecognitionClient::IsUrlBlocked(const std::string& url) const {
return blocked_urls_.find(url) != blocked_urls_.end();
}
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "base/containers/flat_set.h"
#include "chrome/common/caption.mojom.h" #include "chrome/common/caption.mojom.h"
#include "media/base/audio_buffer.h" #include "media/base/audio_buffer.h"
#include "media/base/speech_recognition_client.h" #include "media/base/speech_recognition_client.h"
...@@ -58,6 +59,7 @@ class ChromeSpeechRecognitionClient ...@@ -58,6 +59,7 @@ class ChromeSpeechRecognitionClient
// Resets the temporary monaural audio bus and the channel mixer used to // Resets the temporary monaural audio bus and the channel mixer used to
// combine multiple audio channels. // combine multiple audio channels.
void ResetChannelMixer(const media::AudioBuffer& buffer); void ResetChannelMixer(const media::AudioBuffer& buffer);
bool IsUrlBlocked(const std::string& url) const;
mojo::Remote<media::mojom::SpeechRecognitionContext> mojo::Remote<media::mojom::SpeechRecognitionContext>
speech_recognition_context_; speech_recognition_context_;
...@@ -67,6 +69,9 @@ class ChromeSpeechRecognitionClient ...@@ -67,6 +69,9 @@ class ChromeSpeechRecognitionClient
speech_recognition_client_receiver_{this}; speech_recognition_client_receiver_{this};
mojo::Remote<chrome::mojom::CaptionHost> caption_host_; mojo::Remote<chrome::mojom::CaptionHost> caption_host_;
bool is_website_blocked_ = false;
const base::flat_set<std::string> blocked_urls_;
// The temporary audio bus used to convert the raw audio to the appropriate // The temporary audio bus used to convert the raw audio to the appropriate
// format. // format.
std::unique_ptr<media::AudioBus> temp_audio_bus_; std::unique_ptr<media::AudioBus> temp_audio_bus_;
......
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