Commit a64a082b authored by Jiawei Li's avatar Jiawei Li Committed by Commit Bot

[chromecast] Handle WebSQL database and mixer audio via CastWebContents

- Adds a CastWebContents::FromWebContents() method to retrieve
corresponding CastWebContents that wrapped the content::CastWebContents.
- Adds flags into CastWebContents::InitParams to determine whether
enabling WebSQL database and mixer audio.

Merge-With: eureka-internal/342751

Bug: internal b/144316145
Test: CQ
Change-Id: I7768e9b2d903ea79dbb3e49ca82ffe389f98d19e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1954447Reviewed-by: default avatarSean Topping <seantopping@chromium.org>
Reviewed-by: default avatarYuchen Liu <yucliu@chromium.org>
Commit-Queue: Jiawei Li <lijiawei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722614}
parent bb0adca4
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "chromecast/browser/cast_overlay_manifests.h" #include "chromecast/browser/cast_overlay_manifests.h"
#include "chromecast/browser/cast_quota_permission_context.h" #include "chromecast/browser/cast_quota_permission_context.h"
#include "chromecast/browser/cast_session_id_map.h" #include "chromecast/browser/cast_session_id_map.h"
#include "chromecast/browser/cast_web_contents.h"
#include "chromecast/browser/default_navigation_throttle.h" #include "chromecast/browser/default_navigation_throttle.h"
#include "chromecast/browser/devtools/cast_devtools_manager_delegate.h" #include "chromecast/browser/devtools/cast_devtools_manager_delegate.h"
#include "chromecast/browser/general_audience_browsing_navigation_throttle.h" #include "chromecast/browser/general_audience_browsing_navigation_throttle.h"
...@@ -107,12 +108,12 @@ ...@@ -107,12 +108,12 @@
#endif // defined(USE_ALSA) #endif // defined(USE_ALSA)
#if BUILDFLAG(ENABLE_CHROMECAST_EXTENSIONS) #if BUILDFLAG(ENABLE_CHROMECAST_EXTENSIONS)
#include "chromecast/browser/cast_extension_message_filter.h" // nogncheck #include "chromecast/browser/cast_extension_message_filter.h" // nogncheck
#include "chromecast/browser/cast_extension_url_loader_factory.h" // nogncheck #include "chromecast/browser/cast_extension_url_loader_factory.h" // nogncheck
#include "extensions/browser/extension_message_filter.h" // nogncheck #include "extensions/browser/extension_message_filter.h" // nogncheck
#include "extensions/browser/extension_protocols.h" // nogncheck #include "extensions/browser/extension_protocols.h" // nogncheck
#include "extensions/browser/extension_registry.h" // nogncheck #include "extensions/browser/extension_registry.h" // nogncheck
#include "extensions/browser/extension_system.h" // nogncheck #include "extensions/browser/extension_system.h" // nogncheck
#include "extensions/browser/guest_view/extensions_guest_view_message_filter.h" // nogncheck #include "extensions/browser/guest_view/extensions_guest_view_message_filter.h" // nogncheck
#include "extensions/browser/guest_view/web_view/web_view_guest.h" // nogncheck #include "extensions/browser/guest_view/web_view/web_view_guest.h" // nogncheck
#include "extensions/browser/info_map.h" // nogncheck #include "extensions/browser/info_map.h" // nogncheck
...@@ -444,15 +445,16 @@ void CastContentBrowserClient::AppendExtraCommandLineSwitches( ...@@ -444,15 +445,16 @@ void CastContentBrowserClient::AppendExtraCommandLineSwitches(
} }
} else if (process_type == switches::kGpuProcess) { } else if (process_type == switches::kGpuProcess) {
#if defined(OS_LINUX) #if defined(OS_LINUX)
// Necessary for accelerated 2d canvas. By default on Linux, Chromium assumes // Necessary for accelerated 2d canvas. By default on Linux, Chromium
// GLES2 contexts can be lost to a power-save mode, which breaks GPU canvas // assumes GLES2 contexts can be lost to a power-save mode, which breaks GPU
// apps. // canvas apps.
command_line->AppendSwitch(switches::kGpuNoContextLost); command_line->AppendSwitch(switches::kGpuNoContextLost);
#endif #endif
#if defined(USE_AURA) #if defined(USE_AURA)
static const char* const kForwardSwitches[] = { static const char* const kForwardSwitches[] = {
switches::kCastInitialScreenHeight, switches::kCastInitialScreenWidth, switches::kCastInitialScreenHeight,
switches::kCastInitialScreenWidth,
switches::kVSyncInterval, switches::kVSyncInterval,
}; };
command_line->CopySwitchesFrom(*browser_command_line, kForwardSwitches, command_line->CopySwitchesFrom(*browser_command_line, kForwardSwitches,
...@@ -516,6 +518,18 @@ void CastContentBrowserClient::OverrideWebkitPrefs( ...@@ -516,6 +518,18 @@ void CastContentBrowserClient::OverrideWebkitPrefs(
DCHECK(prefs->viewport_meta_enabled); DCHECK(prefs->viewport_meta_enabled);
prefs->viewport_style = content::ViewportStyle::TELEVISION; prefs->viewport_style = content::ViewportStyle::TELEVISION;
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
// Disable WebSQL databases by default.
prefs->databases_enabled = false;
content::WebContents* web_contents =
content::WebContents::FromRenderViewHost(render_view_host);
if (web_contents) {
chromecast::CastWebContents* cast_web_contents =
chromecast::CastWebContents::FromWebContents(web_contents);
if (cast_web_contents && cast_web_contents->is_websql_enabled()) {
prefs->databases_enabled = true;
}
}
} }
std::string CastContentBrowserClient::GetApplicationLocale() { std::string CastContentBrowserClient::GetApplicationLocale() {
...@@ -644,8 +658,16 @@ void CastContentBrowserClient::GetApplicationMediaInfo( ...@@ -644,8 +658,16 @@ void CastContentBrowserClient::GetApplicationMediaInfo(
std::string* application_session_id, std::string* application_session_id,
bool* mixer_audio_enabled, bool* mixer_audio_enabled,
content::RenderFrameHost* render_frame_host) { content::RenderFrameHost* render_frame_host) {
*application_session_id = ""; content::WebContents* web_contents =
*mixer_audio_enabled = true; content::WebContents::FromRenderFrameHost(render_frame_host);
if (web_contents) {
*application_session_id =
CastNavigationUIData::GetSessionIdForWebContents(web_contents);
chromecast::CastWebContents* cast_web_contents =
chromecast::CastWebContents::FromWebContents(web_contents);
*mixer_audio_enabled =
(cast_web_contents && cast_web_contents->is_mixer_audio_enabled());
}
} }
base::Optional<service_manager::Manifest> base::Optional<service_manager::Manifest>
......
...@@ -275,11 +275,9 @@ class CastContentBrowserClient ...@@ -275,11 +275,9 @@ class CastContentBrowserClient
void BindMediaRenderer( void BindMediaRenderer(
mojo::PendingReceiver<::media::mojom::Renderer> receiver); mojo::PendingReceiver<::media::mojom::Renderer> receiver);
// Internal implementation overwrites this function to inject real values. void GetApplicationMediaInfo(std::string* application_session_id,
virtual void GetApplicationMediaInfo( bool* mixer_audio_enabled,
std::string* application_session_id, content::RenderFrameHost* render_frame_host);
bool* mixer_audio_enabled,
content::RenderFrameHost* render_frame_host);
private: private:
// Create device cert/key // Create device cert/key
......
...@@ -188,7 +188,7 @@ class CastWebContents { ...@@ -188,7 +188,7 @@ class CastWebContents {
// is destroyed before CastWebContents, the WeakPtr will be invalidated on // is destroyed before CastWebContents, the WeakPtr will be invalidated on
// the main UI thread. // the main UI thread.
base::WeakPtr<Delegate> delegate = nullptr; base::WeakPtr<Delegate> delegate = nullptr;
// Enable development mode for this CastWebCastWebContents. Whitelists // Enable development mode for this CastWebContents. Whitelists
// certain functionality for the WebContents, like remote debugging and // certain functionality for the WebContents, like remote debugging and
// debugging interfaces. // debugging interfaces.
bool enabled_for_dev = false; bool enabled_for_dev = false;
...@@ -206,6 +206,10 @@ class CastWebContents { ...@@ -206,6 +206,10 @@ class CastWebContents {
// Background color for the WebContents view. If not provided, the color // Background color for the WebContents view. If not provided, the color
// will fall back to the platform default. // will fall back to the platform default.
BackgroundColor background_color = BackgroundColor::NONE; BackgroundColor background_color = BackgroundColor::NONE;
// Enable WebSQL database for this CastWebContents.
bool enable_websql = false;
// Enable mixer audio support for this CastWebContents.
bool enable_mixer_audio = false;
InitParams(); InitParams();
InitParams(const InitParams& other); InitParams(const InitParams& other);
...@@ -224,6 +228,10 @@ class CastWebContents { ...@@ -224,6 +228,10 @@ class CastWebContents {
static std::vector<CastWebContents*>& GetAll(); static std::vector<CastWebContents*>& GetAll();
// Returns the CastWebContents that wraps the content::WebContents, or nullptr
// if the CastWebContents does not exist.
static CastWebContents* FromWebContents(content::WebContents* web_contents);
CastWebContents() = default; CastWebContents() = default;
virtual ~CastWebContents() = default; virtual ~CastWebContents() = default;
...@@ -341,6 +349,13 @@ class CastWebContents { ...@@ -341,6 +349,13 @@ class CastWebContents {
const InterfaceSet& interface_set, const InterfaceSet& interface_set,
service_manager::InterfaceProvider* interface_provider) = 0; service_manager::InterfaceProvider* interface_provider) = 0;
// Returns true if WebSQL database is configured enabled for this
// CastWebContents.
virtual bool is_websql_enabled() = 0;
// Returns true if mixer audio is enabled.
virtual bool is_mixer_audio_enabled() = 0;
private: private:
DISALLOW_COPY_AND_ASSIGN(CastWebContents); DISALLOW_COPY_AND_ASSIGN(CastWebContents);
}; };
......
...@@ -84,6 +84,21 @@ std::vector<CastWebContents*>& CastWebContents::GetAll() { ...@@ -84,6 +84,21 @@ std::vector<CastWebContents*>& CastWebContents::GetAll() {
return *instance; return *instance;
} }
// static
CastWebContents* CastWebContents::FromWebContents(
content::WebContents* web_contents) {
auto& all_cast_web_contents = CastWebContents::GetAll();
auto it =
std::find_if(all_cast_web_contents.begin(), all_cast_web_contents.end(),
[&web_contents](const auto* cast_web_contents) {
return cast_web_contents->web_contents() == web_contents;
});
if (it == all_cast_web_contents.end()) {
return nullptr;
}
return *it;
}
CastWebContentsImpl::CastWebContentsImpl(content::WebContents* web_contents, CastWebContentsImpl::CastWebContentsImpl(content::WebContents* web_contents,
const InitParams& init_params) const InitParams& init_params)
: web_contents_(web_contents), : web_contents_(web_contents),
...@@ -100,6 +115,8 @@ CastWebContentsImpl::CastWebContentsImpl(content::WebContents* web_contents, ...@@ -100,6 +115,8 @@ CastWebContentsImpl::CastWebContentsImpl(content::WebContents* web_contents,
? std::make_unique<CastMediaBlocker>(web_contents_) ? std::make_unique<CastMediaBlocker>(web_contents_)
: nullptr), : nullptr),
tab_id_(init_params.is_root_window ? 0 : next_tab_id++), tab_id_(init_params.is_root_window ? 0 : next_tab_id++),
is_websql_enabled_(init_params.enable_websql),
is_mixer_audio_enabled_(init_params.enable_mixer_audio),
main_frame_loaded_(false), main_frame_loaded_(false),
closing_(false), closing_(false),
stopped_(false), stopped_(false),
...@@ -335,6 +352,14 @@ void CastWebContentsImpl::RegisterInterfaceProvider( ...@@ -335,6 +352,14 @@ void CastWebContentsImpl::RegisterInterfaceProvider(
interface_providers_map_.emplace(interface_set, interface_provider); interface_providers_map_.emplace(interface_set, interface_provider);
} }
bool CastWebContentsImpl::is_websql_enabled() {
return is_websql_enabled_;
}
bool CastWebContentsImpl::is_mixer_audio_enabled() {
return is_mixer_audio_enabled_;
}
void CastWebContentsImpl::OnClosePageTimeout() { void CastWebContentsImpl::OnClosePageTimeout() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!closing_ || stopped_) { if (!closing_ || stopped_) {
......
...@@ -68,6 +68,8 @@ class CastWebContentsImpl : public CastWebContents, ...@@ -68,6 +68,8 @@ class CastWebContentsImpl : public CastWebContents,
std::vector<mojo::ScopedMessagePipeHandle> channels) override; std::vector<mojo::ScopedMessagePipeHandle> channels) override;
void AddObserver(Observer* observer) override; void AddObserver(Observer* observer) override;
void RemoveObserver(Observer* observer) override; void RemoveObserver(Observer* observer) override;
bool is_websql_enabled() override;
bool is_mixer_audio_enabled() override;
// content::WebContentsObserver implementation: // content::WebContentsObserver implementation:
void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
...@@ -152,6 +154,8 @@ class CastWebContentsImpl : public CastWebContents, ...@@ -152,6 +154,8 @@ class CastWebContentsImpl : public CastWebContents,
std::vector<RendererFeature> renderer_features_; std::vector<RendererFeature> renderer_features_;
const int tab_id_; const int tab_id_;
bool is_websql_enabled_;
bool is_mixer_audio_enabled_;
base::TimeTicks start_loading_ticks_; base::TimeTicks start_loading_ticks_;
bool main_frame_loaded_; bool main_frame_loaded_;
bool closing_; bool closing_;
......
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