Commit b7a80f27 authored by Michael Nye's avatar Michael Nye Committed by Commit Bot

Add observer interface for CastContentWindow.

Bug: b/80441180
Change-Id: I66bd3265c724229c818d54289479c6262a2e28a9
Test: Ran on device
Reviewed-on: https://chromium-review.googlesource.com/1148803Reviewed-by: default avatarLuke Halliwell <halliwell@chromium.org>
Commit-Queue: Michael Nye <michaelnye@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592136}
parent 355a3311
...@@ -334,6 +334,7 @@ cast_source_set("browser") { ...@@ -334,6 +334,7 @@ cast_source_set("browser") {
# This target should only include interfaces which are required for unit tests. # This target should only include interfaces which are required for unit tests.
cast_source_set("public") { cast_source_set("public") {
sources = [ sources = [
"cast_content_window.cc",
"cast_content_window.h", "cast_content_window.h",
"cast_web_view.cc", "cast_web_view.cc",
"cast_web_view.h", "cast_web_view.h",
......
...@@ -114,6 +114,9 @@ void CastContentWindowAndroid::RequestVisibility( ...@@ -114,6 +114,9 @@ void CastContentWindowAndroid::RequestVisibility(
void CastContentWindowAndroid::NotifyVisibilityChange( void CastContentWindowAndroid::NotifyVisibilityChange(
VisibilityType visibility_type) { VisibilityType visibility_type) {
delegate_->OnVisibilityChange(visibility_type); delegate_->OnVisibilityChange(visibility_type);
for (auto& observer : observer_list_) {
observer.OnVisibilityChange(visibility_type);
}
} }
void CastContentWindowAndroid::RequestMoveOut() { void CastContentWindowAndroid::RequestMoveOut() {
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromecast/browser/cast_content_window.h"
namespace chromecast {
namespace shell {
CastContentWindow::CastContentWindow() = default;
CastContentWindow::~CastContentWindow() = default;
void CastContentWindow::AddObserver(Observer* observer) {
observer_list_.AddObserver(observer);
}
void CastContentWindow::RemoveObserver(Observer* observer) {
observer_list_.RemoveObserver(observer);
}
} // namespace shell
} // namespace chromecast
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "chromecast/graphics/cast_window_manager.h" #include "chromecast/graphics/cast_window_manager.h"
#include "chromecast/graphics/gestures/cast_gesture_handler.h" #include "chromecast/graphics/gestures/cast_gesture_handler.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -143,11 +145,21 @@ class CastContentWindow { ...@@ -143,11 +145,21 @@ class CastContentWindow {
CreateParams() = default; CreateParams() = default;
}; };
class Observer : public base::CheckedObserver {
public:
// Notify visibility change for this window.
virtual void OnVisibilityChange(VisibilityType visibility_type) {}
protected:
~Observer() override {}
};
// Creates the platform specific CastContentWindow. |delegate| should outlive // Creates the platform specific CastContentWindow. |delegate| should outlive
// the created CastContentWindow. // the created CastContentWindow.
static std::unique_ptr<CastContentWindow> Create(const CreateParams& params); static std::unique_ptr<CastContentWindow> Create(const CreateParams& params);
virtual ~CastContentWindow() {} CastContentWindow();
virtual ~CastContentWindow();
// Creates a full-screen window for |web_contents| and displays it if screen // Creates a full-screen window for |web_contents| and displays it if screen
// access has been granted. // access has been granted.
...@@ -184,6 +196,13 @@ class CastContentWindow { ...@@ -184,6 +196,13 @@ class CastContentWindow {
// Cast activity or application calls it to request for moving out of the // Cast activity or application calls it to request for moving out of the
// screen. // screen.
virtual void RequestMoveOut() = 0; virtual void RequestMoveOut() = 0;
// Observer interface:
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
protected:
base::ObserverList<Observer> observer_list_;
}; };
} // namespace shell } // namespace shell
......
...@@ -143,6 +143,9 @@ void CastContentWindowAura::RequestVisibility( ...@@ -143,6 +143,9 @@ void CastContentWindowAura::RequestVisibility(
void CastContentWindowAura::NotifyVisibilityChange( void CastContentWindowAura::NotifyVisibilityChange(
VisibilityType visibility_type) { VisibilityType visibility_type) {
delegate_->OnVisibilityChange(visibility_type); delegate_->OnVisibilityChange(visibility_type);
for (auto& observer : observer_list_) {
observer.OnVisibilityChange(visibility_type);
}
} }
void CastContentWindowAura::RequestMoveOut(){}; void CastContentWindowAura::RequestMoveOut(){};
......
...@@ -21,6 +21,9 @@ CastWebViewFactory::CastWebViewFactory(content::BrowserContext* browser_context) ...@@ -21,6 +21,9 @@ CastWebViewFactory::CastWebViewFactory(content::BrowserContext* browser_context)
CastWebViewFactory::~CastWebViewFactory() = default; CastWebViewFactory::~CastWebViewFactory() = default;
void CastWebViewFactory::OnPageDestroyed(CastWebView* web_view) { void CastWebViewFactory::OnPageDestroyed(CastWebView* web_view) {
for (auto& observer : observer_list_) {
observer.OnCastWebViewDestroyed(web_view);
}
web_view->RemoveObserver(this); web_view->RemoveObserver(this);
active_webviews_.erase(std::find_if( active_webviews_.erase(std::find_if(
active_webviews_.begin(), active_webviews_.end(), active_webviews_.begin(), active_webviews_.end(),
...@@ -47,7 +50,18 @@ std::unique_ptr<CastWebView> CastWebViewFactory::CreateWebView( ...@@ -47,7 +50,18 @@ std::unique_ptr<CastWebView> CastWebViewFactory::CreateWebView(
active_webviews_.push_back({webview.get(), next_id_++}); active_webviews_.push_back({webview.get(), next_id_++});
webview->AddObserver(this); webview->AddObserver(this);
} }
for (auto& observer : observer_list_) {
observer.OnCastWebViewCreated(webview.get());
}
return webview; return webview;
} }
void CastWebViewFactory::AddObserver(Observer* observer) {
observer_list_.AddObserver(observer);
}
void CastWebViewFactory::RemoveObserver(Observer* observer) {
observer_list_.RemoveObserver(observer);
}
} // namespace chromecast } // namespace chromecast
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "chromecast/browser/cast_web_view.h" #include "chromecast/browser/cast_web_view.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -34,6 +36,15 @@ struct ActiveWebview { ...@@ -34,6 +36,15 @@ struct ActiveWebview {
class CastWebViewFactory : public CastWebView::Observer { class CastWebViewFactory : public CastWebView::Observer {
public: public:
class Observer : public base::CheckedObserver {
public:
virtual void OnCastWebViewCreated(CastWebView* web_view) {}
virtual void OnCastWebViewDestroyed(CastWebView* web_view) {}
protected:
~Observer() override {}
};
explicit CastWebViewFactory(content::BrowserContext* browser_context); explicit CastWebViewFactory(content::BrowserContext* browser_context);
~CastWebViewFactory() override; ~CastWebViewFactory() override;
...@@ -44,6 +55,9 @@ class CastWebViewFactory : public CastWebView::Observer { ...@@ -44,6 +55,9 @@ class CastWebViewFactory : public CastWebView::Observer {
const extensions::Extension* extension, const extensions::Extension* extension,
const GURL& initial_url); const GURL& initial_url);
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
const std::vector<ActiveWebview>& active_webviews() const { const std::vector<ActiveWebview>& active_webviews() const {
return active_webviews_; return active_webviews_;
} }
...@@ -55,6 +69,7 @@ class CastWebViewFactory : public CastWebView::Observer { ...@@ -55,6 +69,7 @@ class CastWebViewFactory : public CastWebView::Observer {
content::BrowserContext* const browser_context_; content::BrowserContext* const browser_context_;
base::RepeatingCallback<void(CastWebView*, int)> register_callback_; base::RepeatingCallback<void(CastWebView*, int)> register_callback_;
base::ObserverList<Observer> observer_list_;
std::vector<ActiveWebview> active_webviews_; std::vector<ActiveWebview> active_webviews_;
int next_id_ = 1; int next_id_ = 1;
......
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