Commit 9dd7bb4a authored by Jiawei Li's avatar Jiawei Li Committed by Chromium LUCI CQ

[chromecast] Add CastWindowEmbedder and CastContentWindowEmbedded

Those interfaces are used for organizing Cast native windows to work
with an external window manager via the interface CastWindowEmbedder
primarily through pre-defined events and requests.

The unittest is not exhaustive and more test cases will be added in
follow-up CLs.

Bug: Internal b/173251340
Test: cast_content_window_embedded_unittest
Change-Id: I9385cfb0bd2af64cc364f74f5c1b86b88d4432ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2539668Reviewed-by: default avatarShawn Gallea <sagallea@google.com>
Reviewed-by: default avatarSean Topping <seantopping@chromium.org>
Commit-Queue: Jiawei Li <lijiawei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843204}
parent 2d9577e0
......@@ -465,6 +465,10 @@ cast_source_set("browser_base") {
"webview/cast_app_controller.h",
"webview/cast_app_rpc_instance.cc",
"webview/cast_app_rpc_instance.h",
"webview/cast_content_window_embedded.cc",
"webview/cast_content_window_embedded.h",
"webview/cast_window_embedder.cc",
"webview/cast_window_embedder.h",
"webview/js_channel_service.cc",
"webview/js_channel_service.h",
"webview/platform_views_grpc_service.cc",
......@@ -489,6 +493,7 @@ cast_source_set("browser_base") {
deps += [
":web_contents_provider",
"//chromecast/browser/webview/proto",
"//chromecast/ui:back_gesture_router",
"//components/exo",
"//components/exo/wayland",
"//content/public/browser",
......@@ -664,6 +669,10 @@ cast_source_set("unittests") {
"//ui/events:test_support",
]
}
if ((is_linux || is_chromeos) && use_ozone) {
deps += [ "//chromecast/browser/webview:unittests" ]
}
}
if (is_android) {
......
# Copyright 2020 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.
import("//chromecast/chromecast.gni")
import("//testing/test.gni")
cast_source_set("unittests") {
testonly = true
sources = [ "cast_content_window_embedded_unittest.cc" ]
deps = [
"//base",
"//base/test:test_support",
"//chromecast/browser",
"//chromecast/browser:public",
"//chromecast/browser:test_support",
"//content/public/common",
]
}
This diff is collapsed.
// Copyright 2020 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.
#ifndef CHROMECAST_BROWSER_WEBVIEW_CAST_CONTENT_WINDOW_EMBEDDED_H_
#define CHROMECAST_BROWSER_WEBVIEW_CAST_CONTENT_WINDOW_EMBEDDED_H_
#include <string>
#include "base/macros.h"
#include "chromecast/browser/cast_content_window.h"
#include "chromecast/browser/webview/cast_window_embedder.h"
#include "chromecast/ui/back_gesture_router.h"
#include "content/public/browser/web_contents_observer.h"
#include "ui/aura/window_observer.h"
namespace aura {
class Window;
} // namespace aura
namespace content {
class WebContents;
} // namespace content
namespace chromecast {
class CastWebContents;
// Embedded Cast window implementation to work with webview window
// management system. This class will receive embedder's window events
// and reports its Cast window specific request to embedder.
// An instance of this object is created for each CastWebContents instance. Its
// web contents may be destroyed before |this| is destroyed, so
// WebContentsObserver is used to observe the web contents to prevent garbage
// from being returned in GetWebContents.
class CastContentWindowEmbedded
: public CastContentWindow,
public aura::WindowObserver,
public content::WebContentsObserver,
public chromecast::BackGestureRouter::Delegate,
public CastWindowEmbedder::EmbeddedWindow {
public:
// |cast_window_embedder|: The corresponding embedder that this window
// listens on incoming window events. Must outlive |this|.
// |force_720p_resolution|: Whether 720p resolution is enabled/forced for
// this window's hosted web page (i.e. a CastWebView).
explicit CastContentWindowEmbedded(
const CastContentWindow::CreateParams& params,
CastWindowEmbedder* cast_window_embedder,
bool force_720p_resolution);
~CastContentWindowEmbedded() override;
CastContentWindowEmbedded(const CastContentWindowEmbedded&) = delete;
CastContentWindowEmbedded& operator=(const CastContentWindowEmbedded&) =
delete;
// CastContentWindow implementation:
void CreateWindowForWebContents(
CastWebContents* cast_web_contents,
::chromecast::mojom::ZOrder z_order,
VisibilityPriority visibility_priority) override;
void GrantScreenAccess() override;
void RevokeScreenAccess() override;
void RequestVisibility(VisibilityPriority visibility_priority) override;
void SetActivityContext(base::Value activity_context) override;
void SetHostContext(base::Value host_context) override;
void NotifyVisibilityChange(VisibilityType visibility_type) override;
void RequestMoveOut() override;
void EnableTouchInput(bool enabled) override;
// aura::WindowObserver implementation:
void OnWindowDestroyed(aura::Window* window) override;
// CastWindowEmbedder::EmbeddedWindow implementation:
int GetWindowId() override;
std::string GetAppId() override;
void OnEmbedderWindowEvent(
const CastWindowEmbedder::EmbedderWindowEvent& request) override;
content::WebContents* GetWebContents() override;
CastWebContents* GetCastWebContents() override;
void DispatchState() override;
void SendAppContext(const std::string& context) override;
void Stop() override;
// chromecast::GestureRouter::Delegate
void SetCanGoBack(bool can_go_back) override;
void RegisterBackGestureRouter(
::chromecast::BackGestureRouter* back_gesture_router) override;
private:
// Sending a window request to the embedder to handle.
// |request_type| specifies the type of the request, e.g. creation of new
// window, request of focus, and so forth.
void SendWindowRequest(CastWindowEmbedder::WindowRequestType request_type);
// Collects and generates a |CastWindowProperties| to represent the current
// state of this window, in terms of the embedder needs to know about.
CastWindowEmbedder::CastWindowProperties PopulateCastWindowProperties();
void ReleaseFocus();
void RequestFocus();
// Sends open window request only when this window has gained screen access
// and has not reported the creation/open of this window to the embedder yet.
void MaybeSendOpenWindowRequest();
// Sends the current CastWindowProperties to |cast_window_embedder_|.
void SendCastWindowProperties();
void SendOpenWindowRequest();
void ConsumeGestureCompleted(bool handled);
// content::WebContentsObserver
void DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) override;
void DidFirstVisuallyNonEmptyPaint() override;
void WebContentsDestroyed() override;
// Once set, those window properties are fixed during lifetime of |this|.
std::string app_id_;
std::string session_id_;
int window_id_ = -1;
bool is_remote_control_ = false;
const bool is_touch_enabled_ = false;
CastWindowEmbedder* cast_window_embedder_ = nullptr;
const bool force_720p_resolution_ = false;
// States might change during lifetime of |this|.
bool open_window_sent_ = false;
bool can_go_back_ = false;
bool has_screen_access_ = false;
VisibilityPriority visibility_priority_ = VisibilityPriority::DEFAULT;
aura::Window* window_ = nullptr;
CastWebContents* cast_web_contents_ = nullptr;
base::Value activity_context_;
// A free-form custom data field for communicating with the window embedder.
base::Value host_context_;
};
} // namespace chromecast
#endif // CHROMECAST_BROWSER_WEBVIEW_CAST_CONTENT_WINDOW_EMBEDDED_H_
// Copyright 2020 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/webview/cast_window_embedder.h"
namespace chromecast {
CastWindowEmbedder::EmbedderWindowEvent::EmbedderWindowEvent() = default;
CastWindowEmbedder::EmbedderWindowEvent::~EmbedderWindowEvent() = default;
CastWindowEmbedder::CastWindowProperties::CastWindowProperties() = default;
CastWindowEmbedder::CastWindowProperties::~CastWindowProperties() = default;
CastWindowEmbedder::CastWindowProperties::CastWindowProperties(
CastWindowProperties&& other) = default;
} // namespace chromecast
// Copyright 2020 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.
#ifndef CHROMECAST_BROWSER_WEBVIEW_CAST_WINDOW_EMBEDDER_H_
#define CHROMECAST_BROWSER_WEBVIEW_CAST_WINDOW_EMBEDDER_H_
#include <string>
#include "base/optional.h"
#include "chromecast/browser/cast_content_window.h"
namespace content {
class WebContents;
} // namespace content
namespace chromecast {
class CastWebContents;
// An interface to route messages and requests between a window manager
// other than CastShell and the embedded Cast window (i.e. subclass of
// CastContentWindow).
class CastWindowEmbedder {
public:
// Describes change of the visibility state of the embedded window.
enum class VisibilityChange {
// Unknown visibility state.
UNKNOWN = 0,
// The window is not visible to the user.
NOT_VISIBLE = 1,
// The window is active and shown fullscreen to the user.
FULL_SCREEN = 2,
// The window it is covered by other activities.
OBSCURED = 3,
// The window is interrupting another activity, and shown as a side
// interruption.
INTERRUPTION = 4,
// The cast window is interrupted by another activity, and only partially
// visible.
INTERRUPTED = 5,
};
enum class NavigationType {
// Unknown nagvigation type.
UNKNOWN = 0,
// Navigate back.
GO_BACK = 1,
};
struct BackGestureProgressEvent {
// The x-coordinate of the finger during the swipe.
double x = -1;
// The y-coordinate of the finger during the swipe.
double y = -1;
};
// Event sent from the embedder to instruct corresponding Cast window
// to respond.
// Four event types are supported:
// - Visibility change
// - Navigation
// - Back gesture progress update
// - Cancellation of back gesture
// Note that a |WindowEvent| must and must only convey one type
// of event at a time.
struct EmbedderWindowEvent {
EmbedderWindowEvent();
~EmbedderWindowEvent();
// Unique window ID assigned by the embedder.
int window_id = -1;
base::Optional<VisibilityChange> visibility_changed;
base::Optional<NavigationType> navigation;
base::Optional<BackGestureProgressEvent> back_gesture_progress_event;
base::Optional<bool> back_gesture_cancel_event;
};
// Interface for the embedded Cast window to implement for
// working with the embedder environment.
class EmbeddedWindow {
public:
virtual ~EmbeddedWindow() = default;
// Returns the unique window ID assigned by the embedder.
virtual int GetWindowId() = 0;
// Returns the ID of the hosted app.
virtual std::string GetAppId() = 0;
// Handles window change requested by the embedder.
virtual void OnEmbedderWindowEvent(const EmbedderWindowEvent& request) = 0;
// Returns the WebContents associsated with this Cast window.
virtual content::WebContents* GetWebContents() = 0;
// Returns the CastWebContents associsated with this Cast window.
virtual CastWebContents* GetCastWebContents() = 0;
// Populates and reports current window properties to the
// |CastWindowEmbedder|.
virtual void DispatchState() = 0;
// Sends |context| along with current |CastWindowProperties| to
// the embedder window manager.
virtual void SendAppContext(const std::string& context) = 0;
// Stops the Cast window and its assiciated |CastWebContents|.
virtual void Stop() = 0;
};
// Info that are needed by the embedder to orchectrate the embedded window
// with other activities' window.
struct CastWindowProperties {
CastWindowProperties();
~CastWindowProperties();
CastWindowProperties(CastWindowProperties&& other);
CastWindowProperties(const CastWindowProperties&) = delete;
CastWindowProperties& operator=(const CastWindowProperties&) = delete;
// Unique ID for the embedded Cast window. This must be set for each
// CastWindowProperties.
int window_id = -1;
// A Cast specific ID for identifying the type of content hosted by the
// Cast window.
std::string app_id;
// A unique Id to identify the hosted content.
std::string session_id;
// Whether the window is a system setup window for OOBE or error screens.
bool is_system_setup_window = false;
// Whether the hosted content supports handling touch event.
bool is_touch_enabled = false;
// Whether the hosted content is in remote control mode.
bool is_remote_control = false;
// Whether the content is enabled/forced to display in 720P resolution.
bool force_720p_resolution = false;
// Whether the window support navigate back inside.
bool supports_go_back_inside = false;
// Represents requested activity windowing mode.
VisibilityPriority visibility_priority = VisibilityPriority::DEFAULT;
// Application-related metadata associated with the Cast window.
base::Optional<std::string> app_context;
// Custom data for the Cast window. The embedder and whoever set the
// value need to have agreement on the schema of |host_context|.
base::Optional<base::Value> host_context;
};
// The embedded Cast window will use this to communicate with the embedder
// about its current status, including focus change, creation/close of the
// window, and so forth.
enum class WindowRequestType {
// The embedded window requests to report its current set of window
// properties to the embedder.
SET_PROPERTIES,
// Requests the embedder to handle the creation of a new Cast window.
// This could be called when the embedder is restarted and requests all
// alive managed Cast window to report its existence.
OPEN_WINDOW,
// Informs the embedder that the embedded window is being closed.
CLOSE_WINDOW,
// Requests that this window is brought into the focus of user's attention,
// instructed by its visibility priority setting which is included in
// |CastWindowProperties|. It generally means window wants to be shown.
REQUEST_FOCUS,
// Requests to release the focus of this window, e.g. when the window is
// hidden and screen access is revoked.
RELEASE_FOCUS,
// CastShell has handled GO_BACK navigation request.
NAVIGATION_HANDLE_RESULT,
};
virtual ~CastWindowEmbedder() = default;
// Generates a new window ID to be used for identifying a unique
// embedded CastContentWindow.
virtual int GenerateWindowId() = 0;
// Add managed |embedded_window| to listen on events that are sent
// by the embedder.
virtual void AddEmbeddedWindow(EmbeddedWindow* embedded_window) = 0;
// Remove |embedded_window| from the list of managed windows.
virtual void RemoveEmbeddedWindow(EmbeddedWindow* embedded_window) = 0;
// The embedded window report its updated window properties to the embedder
// via this function.
virtual void OnWindowRequest(
const WindowRequestType& type,
const CastWindowProperties& window_properties) = 0;
virtual void GenerateAndSendNavigationHandleResult(
const int window_id,
const std::string session_id,
const bool handled,
NavigationType navigation_type) = 0;
};
} // namespace chromecast
#endif // CHROMECAST_BROWSER_WEBVIEW_CAST_WINDOW_EMBEDDER_H_
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