Commit 0589d254 authored by James West's avatar James West Committed by Commit Bot

[Chromecast] Dynamic screen access for web applications

Grant screen access to web application and revoke it depending on
whether a web application can be shown on the screen. Only show a web
application when screen access has been granted.

Bug: internal b/112164384
Test: manual
Change-Id: I654f3a69395c1a84e33f38a84d52ba45060d96e2
Reviewed-on: https://chromium-review.googlesource.com/1164641Reviewed-by: default avatarKenneth MacKay <kmackay@chromium.org>
Reviewed-by: default avatarLuke Halliwell <halliwell@chromium.org>
Commit-Queue: James West <jameswest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582975}
parent ea475564
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h" #include "base/android/scoped_java_ref.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "jni/CastContentWindowAndroid_jni.h" #include "jni/CastContentWindowAndroid_jni.h"
...@@ -61,7 +62,6 @@ CastContentWindowAndroid::~CastContentWindowAndroid() { ...@@ -61,7 +62,6 @@ CastContentWindowAndroid::~CastContentWindowAndroid() {
void CastContentWindowAndroid::CreateWindowForWebContents( void CastContentWindowAndroid::CreateWindowForWebContents(
content::WebContents* web_contents, content::WebContents* web_contents,
CastWindowManager* /* window_manager */, CastWindowManager* /* window_manager */,
bool /* is_visible */,
CastWindowManager::WindowId /* z_order */, CastWindowManager::WindowId /* z_order */,
VisibilityPriority visibility_priority) { VisibilityPriority visibility_priority) {
DCHECK(web_contents); DCHECK(web_contents);
...@@ -74,6 +74,14 @@ void CastContentWindowAndroid::CreateWindowForWebContents( ...@@ -74,6 +74,14 @@ void CastContentWindowAndroid::CreateWindowForWebContents(
static_cast<int>(visibility_priority)); static_cast<int>(visibility_priority));
} }
void CastContentWindowAndroid::GrantScreenAccess() {
NOTIMPLEMENTED();
}
void CastContentWindowAndroid::RevokeScreenAccess() {
NOTIMPLEMENTED();
}
void CastContentWindowAndroid::EnableTouchInput(bool enabled) { void CastContentWindowAndroid::EnableTouchInput(bool enabled) {
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
Java_CastContentWindowAndroid_enableTouchInput( Java_CastContentWindowAndroid_enableTouchInput(
......
...@@ -28,9 +28,10 @@ class CastContentWindowAndroid : public CastContentWindow { ...@@ -28,9 +28,10 @@ class CastContentWindowAndroid : public CastContentWindow {
void CreateWindowForWebContents( void CreateWindowForWebContents(
content::WebContents* web_contents, content::WebContents* web_contents,
CastWindowManager* window_manager, CastWindowManager* window_manager,
bool is_visible,
CastWindowManager::WindowId z_order, CastWindowManager::WindowId z_order,
VisibilityPriority visibility_priority) override; VisibilityPriority visibility_priority) override;
void GrantScreenAccess() override;
void RevokeScreenAccess() override;
void EnableTouchInput(bool enabled) override; void EnableTouchInput(bool enabled) override;
void RequestVisibility(VisibilityPriority visibility_priority) override; void RequestVisibility(VisibilityPriority visibility_priority) override;
void NotifyVisibilityChange(VisibilityType visibility_type) override; void NotifyVisibilityChange(VisibilityType visibility_type) override;
......
...@@ -121,8 +121,8 @@ class CastContentWindow { ...@@ -121,8 +121,8 @@ class CastContentWindow {
virtual ~CastContentWindow() {} virtual ~CastContentWindow() {}
// Creates a full-screen window for |web_contents| and displays it if // Creates a full-screen window for |web_contents| and displays it if screen
// |is_visible| is true. // access has been granted.
// |web_contents| should outlive this CastContentWindow. // |web_contents| should outlive this CastContentWindow.
// |window_manager| should outlive this CastContentWindow. // |window_manager| should outlive this CastContentWindow.
// TODO(seantopping): This method probably shouldn't exist; this class should // TODO(seantopping): This method probably shouldn't exist; this class should
...@@ -130,10 +130,17 @@ class CastContentWindow { ...@@ -130,10 +130,17 @@ class CastContentWindow {
virtual void CreateWindowForWebContents( virtual void CreateWindowForWebContents(
content::WebContents* web_contents, content::WebContents* web_contents,
CastWindowManager* window_manager, CastWindowManager* window_manager,
bool is_visible,
CastWindowManager::WindowId z_order, CastWindowManager::WindowId z_order,
VisibilityPriority visibility_priority) = 0; VisibilityPriority visibility_priority) = 0;
// Allows the window to be shown on the screen. The window cannot be shown on
// the screen until this is called.
virtual void GrantScreenAccess() = 0;
// Prevents the window from being shown on the screen until
// GrantScreenAccess() is called.
virtual void RevokeScreenAccess() = 0;
// Enables touch input to be routed to the window's WebContents. // Enables touch input to be routed to the window's WebContents.
virtual void EnableTouchInput(bool enabled) = 0; virtual void EnableTouchInput(bool enabled) = 0;
......
...@@ -79,7 +79,9 @@ CastContentWindowAura::CastContentWindowAura( ...@@ -79,7 +79,9 @@ CastContentWindowAura::CastContentWindowAura(
bool is_touch_enabled) bool is_touch_enabled)
: delegate_(delegate), : delegate_(delegate),
gesture_dispatcher_(std::make_unique<CastGestureDispatcher>(delegate_)), gesture_dispatcher_(std::make_unique<CastGestureDispatcher>(delegate_)),
is_touch_enabled_(is_touch_enabled) { is_touch_enabled_(is_touch_enabled),
window_(nullptr),
has_screen_access_(false) {
DCHECK(delegate_); DCHECK(delegate_);
} }
...@@ -92,23 +94,36 @@ CastContentWindowAura::~CastContentWindowAura() { ...@@ -92,23 +94,36 @@ CastContentWindowAura::~CastContentWindowAura() {
void CastContentWindowAura::CreateWindowForWebContents( void CastContentWindowAura::CreateWindowForWebContents(
content::WebContents* web_contents, content::WebContents* web_contents,
CastWindowManager* window_manager, CastWindowManager* window_manager,
bool is_visible,
CastWindowManager::WindowId z_order, CastWindowManager::WindowId z_order,
VisibilityPriority visibility_priority) { VisibilityPriority visibility_priority) {
DCHECK(web_contents); DCHECK(web_contents);
window_manager_ = window_manager; window_manager_ = window_manager;
DCHECK(window_manager_); DCHECK(window_manager_);
gfx::NativeView window = web_contents->GetNativeView(); window_ = web_contents->GetNativeView();
window_manager_->SetWindowId(window, z_order); window_manager_->SetWindowId(window_, z_order);
window_manager_->AddWindow(window); window_manager_->AddWindow(window_);
window_manager_->AddGestureHandler(this); window_manager_->AddGestureHandler(this);
touch_blocker_ = std::make_unique<TouchBlocker>(window, !is_touch_enabled_); touch_blocker_ = std::make_unique<TouchBlocker>(window_, !is_touch_enabled_);
if (is_visible) { if (has_screen_access_) {
window->Show(); window_->Show();
} else { } else {
window->Hide(); window_->Hide();
}
}
void CastContentWindowAura::GrantScreenAccess() {
has_screen_access_ = true;
if (window_) {
window_->Show();
}
}
void CastContentWindowAura::RevokeScreenAccess() {
has_screen_access_ = false;
if (window_) {
window_->Hide();
} }
} }
......
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
#include "chromecast/browser/cast_gesture_dispatcher.h" #include "chromecast/browser/cast_gesture_dispatcher.h"
#include "chromecast/graphics/cast_gesture_handler.h" #include "chromecast/graphics/cast_gesture_handler.h"
namespace aura {
class Window;
} // namespace aura
namespace content { namespace content {
class WebContents; class WebContents;
} // namespace content } // namespace content
...@@ -28,9 +32,10 @@ class CastContentWindowAura : public CastContentWindow, ...@@ -28,9 +32,10 @@ class CastContentWindowAura : public CastContentWindow,
void CreateWindowForWebContents( void CreateWindowForWebContents(
content::WebContents* web_contents, content::WebContents* web_contents,
CastWindowManager* window_manager, CastWindowManager* window_manager,
bool is_visible,
CastWindowManager::WindowId z_order, CastWindowManager::WindowId z_order,
VisibilityPriority visibility_priority) override; VisibilityPriority visibility_priority) override;
void GrantScreenAccess() override;
void RevokeScreenAccess() override;
void RequestVisibility(VisibilityPriority visibility_priority) override; void RequestVisibility(VisibilityPriority visibility_priority) override;
void NotifyVisibilityChange(VisibilityType visibility_type) override; void NotifyVisibilityChange(VisibilityType visibility_type) override;
void RequestMoveOut() override; void RequestMoveOut() override;
...@@ -63,6 +68,8 @@ class CastContentWindowAura : public CastContentWindow, ...@@ -63,6 +68,8 @@ class CastContentWindowAura : public CastContentWindow,
// TODO(seantopping): Inject in constructor. // TODO(seantopping): Inject in constructor.
CastWindowManager* window_manager_ = nullptr; CastWindowManager* window_manager_ = nullptr;
aura::Window* window_;
bool has_screen_access_;
DISALLOW_COPY_AND_ASSIGN(CastContentWindowAura); DISALLOW_COPY_AND_ASSIGN(CastContentWindowAura);
}; };
......
...@@ -122,10 +122,17 @@ class CastWebView { ...@@ -122,10 +122,17 @@ class CastWebView {
// |is_visible| is true. |z_order| determines how this window is layered in // |is_visible| is true. |z_order| determines how this window is layered in
// relationt other windows (higher value == more foreground). // relationt other windows (higher value == more foreground).
virtual void InitializeWindow(CastWindowManager* window_manager, virtual void InitializeWindow(CastWindowManager* window_manager,
bool is_visible,
CastWindowManager::WindowId z_order, CastWindowManager::WindowId z_order,
VisibilityPriority initial_priority) = 0; VisibilityPriority initial_priority) = 0;
// Allows the page to be shown on the screen. The page cannot be shown on the
// screen until this is called.
virtual void GrantScreenAccess() = 0;
// Prevents the page from being shown on the screen until GrantScreenAccess()
// is called.
virtual void RevokeScreenAccess() = 0;
// Observer interface: // Observer interface:
void AddObserver(Observer* observer); void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer); void RemoveObserver(Observer* observer);
......
...@@ -141,7 +141,6 @@ void CastWebViewDefault::CloseContents(content::WebContents* source) { ...@@ -141,7 +141,6 @@ void CastWebViewDefault::CloseContents(content::WebContents* source) {
} }
void CastWebViewDefault::InitializeWindow(CastWindowManager* window_manager, void CastWebViewDefault::InitializeWindow(CastWindowManager* window_manager,
bool is_visible,
CastWindowManager::WindowId z_order, CastWindowManager::WindowId z_order,
VisibilityPriority initial_priority) { VisibilityPriority initial_priority) {
if (media::CastMediaShlib::ClearVideoPlaneImage) { if (media::CastMediaShlib::ClearVideoPlaneImage) {
...@@ -150,10 +149,18 @@ void CastWebViewDefault::InitializeWindow(CastWindowManager* window_manager, ...@@ -150,10 +149,18 @@ void CastWebViewDefault::InitializeWindow(CastWindowManager* window_manager,
DCHECK(window_manager); DCHECK(window_manager);
window_->CreateWindowForWebContents(web_contents_.get(), window_manager, window_->CreateWindowForWebContents(web_contents_.get(), window_manager,
is_visible, z_order, initial_priority); z_order, initial_priority);
web_contents_->Focus(); web_contents_->Focus();
} }
void CastWebViewDefault::GrantScreenAccess() {
window_->GrantScreenAccess();
}
void CastWebViewDefault::RevokeScreenAccess() {
window_->RevokeScreenAccess();
}
content::WebContents* CastWebViewDefault::OpenURLFromTab( content::WebContents* CastWebViewDefault::OpenURLFromTab(
content::WebContents* source, content::WebContents* source,
const content::OpenURLParams& params) { const content::OpenURLParams& params) {
......
...@@ -50,9 +50,10 @@ class CastWebViewDefault : public CastWebView, ...@@ -50,9 +50,10 @@ class CastWebViewDefault : public CastWebView,
void LoadUrl(GURL url) override; void LoadUrl(GURL url) override;
void ClosePage(const base::TimeDelta& shutdown_delay) override; void ClosePage(const base::TimeDelta& shutdown_delay) override;
void InitializeWindow(CastWindowManager* window_manager, void InitializeWindow(CastWindowManager* window_manager,
bool is_visible,
CastWindowManager::WindowId z_order, CastWindowManager::WindowId z_order,
VisibilityPriority initial_priority) override; VisibilityPriority initial_priority) override;
void GrantScreenAccess() override;
void RevokeScreenAccess() override;
private: private:
// WebContentsObserver implementation: // WebContentsObserver implementation:
......
...@@ -64,14 +64,21 @@ void CastWebViewExtension::ClosePage(const base::TimeDelta& shutdown_delay) {} ...@@ -64,14 +64,21 @@ void CastWebViewExtension::ClosePage(const base::TimeDelta& shutdown_delay) {}
void CastWebViewExtension::InitializeWindow( void CastWebViewExtension::InitializeWindow(
CastWindowManager* window_manager, CastWindowManager* window_manager,
bool is_visible,
CastWindowManager::WindowId z_order, CastWindowManager::WindowId z_order,
VisibilityPriority initial_priority) { VisibilityPriority initial_priority) {
window_->CreateWindowForWebContents(web_contents(), window_manager, window_->CreateWindowForWebContents(web_contents(), window_manager, z_order,
is_visible, z_order, initial_priority); initial_priority);
web_contents()->Focus(); web_contents()->Focus();
} }
void CastWebViewExtension::GrantScreenAccess() {
window_->GrantScreenAccess();
}
void CastWebViewExtension::RevokeScreenAccess() {
window_->RevokeScreenAccess();
}
void CastWebViewExtension::WebContentsDestroyed() { void CastWebViewExtension::WebContentsDestroyed() {
delegate_->OnPageStopped(net::OK); delegate_->OnPageStopped(net::OK);
} }
......
...@@ -50,9 +50,10 @@ class CastWebViewExtension : public CastWebView, content::WebContentsObserver { ...@@ -50,9 +50,10 @@ class CastWebViewExtension : public CastWebView, content::WebContentsObserver {
void LoadUrl(GURL url) override; void LoadUrl(GURL url) override;
void ClosePage(const base::TimeDelta& shutdown_delay) override; void ClosePage(const base::TimeDelta& shutdown_delay) override;
void InitializeWindow(CastWindowManager* window_manager, void InitializeWindow(CastWindowManager* window_manager,
bool is_visible,
CastWindowManager::WindowId z_order, CastWindowManager::WindowId z_order,
VisibilityPriority initial_priority) override; VisibilityPriority initial_priority) override;
void GrantScreenAccess() override;
void RevokeScreenAccess() override;
private: private:
// WebContentsObserver implementation: // WebContentsObserver implementation:
......
...@@ -76,8 +76,9 @@ void CastServiceSimple::StartInternal() { ...@@ -76,8 +76,9 @@ void CastServiceSimple::StartInternal() {
nullptr, /* extension */ nullptr, /* extension */
GURL() /* initial_url */); GURL() /* initial_url */);
cast_web_view_->LoadUrl(startup_url_); cast_web_view_->LoadUrl(startup_url_);
cast_web_view_->GrantScreenAccess();
cast_web_view_->InitializeWindow( cast_web_view_->InitializeWindow(
window_manager_, true /* is_visible */, CastWindowManager::APP, window_manager_, CastWindowManager::APP,
chromecast::shell::VisibilityPriority::STICKY_ACTIVITY); chromecast::shell::VisibilityPriority::STICKY_ACTIVITY);
} }
......
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