Commit ce4e5a10 authored by Shawn Gallea's avatar Shawn Gallea Committed by Commit Bot

Add WebContentController

Split WebviewController into a generic base class that only
deals with mutating the WebContents. The split allows implementing
a Webview and CastApp controller differently while retaining common
functionality in the base class.


Bug: b/136460199
Test: Compile
Change-Id: I4267e3c6ac4e3904160e7ee34e35d2b220777cad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1867189Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Commit-Queue: Shawn Gallea <sagallea@google.com>
Cr-Commit-Position: refs/heads/master@{#707487}
parent 0e80dc08
...@@ -382,6 +382,8 @@ cast_source_set("browser") { ...@@ -382,6 +382,8 @@ cast_source_set("browser") {
"exo/cast_wm_helper.h", "exo/cast_wm_helper.h",
"exo/wayland_server_controller.cc", "exo/wayland_server_controller.cc",
"exo/wayland_server_controller.h", "exo/wayland_server_controller.h",
"webview/web_content_controller.cc",
"webview/web_content_controller.h",
"webview/webview_controller.cc", "webview/webview_controller.cc",
"webview/webview_controller.h", "webview/webview_controller.h",
"webview/webview_grpc_service.cc", "webview/webview_grpc_service.cc",
......
This diff is collapsed.
// Copyright 2019 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_WEB_CONTENT_CONTROLLER_H_
#define CHROMECAST_BROWSER_WEBVIEW_WEB_CONTENT_CONTROLLER_H_
#include <memory>
#include <string>
#include "chromecast/browser/webview/proto/webview.pb.h"
#include "components/exo/surface.h"
#include "components/exo/surface_observer.h"
#include "ui/events/gestures/gesture_recognizer_impl.h"
namespace aura {
class Window;
} // namespace aura
namespace content {
class WebContents;
} // namespace content
namespace chromecast {
// Processes proto commands to control WebContents
class WebContentController : public exo::SurfaceObserver {
public:
class Client {
public:
virtual ~Client() {}
virtual void EnqueueSend(
std::unique_ptr<webview::WebviewResponse> response) = 0;
virtual void OnError(const std::string& error_message) = 0;
};
WebContentController(Client* client);
~WebContentController() override;
virtual void Destroy() = 0;
virtual void ProcessRequest(const webview::WebviewRequest& request);
// Attach this web contents to an aura window as a child.
void AttachTo(aura::Window* window, int window_id);
protected:
virtual content::WebContents* GetWebContents() = 0;
Client* client_; // Not owned.
bool has_navigation_delegate_ = false;
private:
void ProcessInputEvent(const webview::InputEvent& ev);
void JavascriptCallback(int64_t id, base::Value result);
void HandleEvaluateJavascript(
int64_t id,
const webview::EvaluateJavascriptRequest& request);
void HandleAddJavascriptChannels(
const webview::AddJavascriptChannelsRequest& request);
void HandleRemoveJavascriptChannels(
const webview::RemoveJavascriptChannelsRequest& request);
void HandleGetCurrentUrl(int64_t id);
void HandleCanGoBack(int64_t id);
void HandleCanGoForward(int64_t id);
void HandleClearCache();
void HandleGetTitle(int64_t id);
void HandleUpdateSettings(const webview::UpdateSettingsRequest& request);
void HandleSetAutoMediaPlaybackPolicy(
const webview::SetAutoMediaPlaybackPolicyRequest& request);
viz::SurfaceId GetSurfaceId();
// exo::SurfaceObserver
void OnSurfaceDestroying(exo::Surface* surface) override;
ui::GestureRecognizerImpl gesture_recognizer_;
exo::Surface* surface_ = nullptr;
base::WeakPtrFactory<WebContentController> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(WebContentController);
};
} // namespace chromecast
#endif // CHROMECAST_BROWSER_WEBVIEW_WEB_CONTENT_CONTROLLER_H_
...@@ -11,15 +11,9 @@ ...@@ -11,15 +11,9 @@
#include "base/supports_user_data.h" #include "base/supports_user_data.h"
#include "chromecast/browser/cast_web_contents.h" #include "chromecast/browser/cast_web_contents.h"
#include "chromecast/browser/webview/proto/webview.pb.h" #include "chromecast/browser/webview/proto/webview.pb.h"
#include "components/exo/surface.h" #include "chromecast/browser/webview/web_content_controller.h"
#include "components/exo/surface_observer.h"
#include "ui/events/gestures/gesture_recognizer_impl.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace aura {
class Window;
} // namespace aura
namespace chromecast { namespace chromecast {
class CastWebContents; class CastWebContents;
} // namespace chromecast } // namespace chromecast
...@@ -39,15 +33,8 @@ class WebviewNavigationThrottle; ...@@ -39,15 +33,8 @@ class WebviewNavigationThrottle;
// to allow the web contents to be controlled and embedded. // to allow the web contents to be controlled and embedded.
class WebviewController : public CastWebContents::Delegate, class WebviewController : public CastWebContents::Delegate,
public CastWebContents::Observer, public CastWebContents::Observer,
public exo::SurfaceObserver { public WebContentController {
public: public:
class Client {
public:
virtual ~Client() {}
virtual void EnqueueSend(
std::unique_ptr<webview::WebviewResponse> response) = 0;
virtual void OnError(const std::string& error_message) = 0;
};
WebviewController(content::BrowserContext* browser_context, Client* client); WebviewController(content::BrowserContext* browser_context, Client* client);
~WebviewController() override; ~WebviewController() override;
...@@ -59,44 +46,23 @@ class WebviewController : public CastWebContents::Delegate, ...@@ -59,44 +46,23 @@ class WebviewController : public CastWebContents::Delegate,
// Cause the controller to be destroyed after giving the webpage a chance to // Cause the controller to be destroyed after giving the webpage a chance to
// run unload events. This unsets the client so no more messages will be // run unload events. This unsets the client so no more messages will be
// sent. // sent.
void Destroy(); void Destroy() override;
void ProcessRequest(const webview::WebviewRequest& request) override;
// Close the page. This will cause a stopped response to eventually be sent. // Close the page. This will cause a stopped response to eventually be sent.
void ClosePage(); void ClosePage();
void ProcessRequest(const webview::WebviewRequest& request);
// Attach this web contents to an aura window as a child.
void AttachTo(aura::Window* window, int window_id);
void SendNavigationEvent(WebviewNavigationThrottle* throttle, void SendNavigationEvent(WebviewNavigationThrottle* throttle,
const GURL& url, const GURL& url,
bool is_in_main_frame); bool is_in_main_frame);
protected:
content::WebContents* GetWebContents() override;
private: private:
webview::AsyncPageEvent_State current_state(); webview::AsyncPageEvent_State current_state();
void ProcessInputEvent(const webview::InputEvent& ev);
void JavascriptCallback(int64_t id, base::Value result);
void HandleEvaluateJavascript(
int64_t id,
const webview::EvaluateJavascriptRequest& request);
void HandleAddJavascriptChannels(
const webview::AddJavascriptChannelsRequest& request);
void HandleRemoveJavascriptChannels(
const webview::RemoveJavascriptChannelsRequest& request);
void HandleGetCurrentUrl(int64_t id);
void HandleCanGoBack(int64_t id);
void HandleCanGoForward(int64_t id);
void HandleClearCache();
void HandleGetTitle(int64_t id);
void HandleUpdateSettings(const webview::UpdateSettingsRequest& request);
void HandleSetAutoMediaPlaybackPolicy(
const webview::SetAutoMediaPlaybackPolicyRequest& request);
viz::SurfaceId GetSurfaceId();
bool Check(bool condition, const char* error);
// CastWebContents::Delegate // CastWebContents::Delegate
void OnPageStateChanged(CastWebContents* cast_web_contents) override; void OnPageStateChanged(CastWebContents* cast_web_contents) override;
void OnPageStopped(CastWebContents* cast_web_contents, void OnPageStopped(CastWebContents* cast_web_contents,
...@@ -105,20 +71,10 @@ class WebviewController : public CastWebContents::Delegate, ...@@ -105,20 +71,10 @@ class WebviewController : public CastWebContents::Delegate,
// CastWebContents::Observer // CastWebContents::Observer
void ResourceLoadFailed(CastWebContents* cast_web_contents) override; void ResourceLoadFailed(CastWebContents* cast_web_contents) override;
// exo::SurfaceObserver
void OnSurfaceDestroying(exo::Surface* surface) override;
Client* client_; // Not owned.
std::unique_ptr<content::WebContents> contents_; std::unique_ptr<content::WebContents> contents_;
std::unique_ptr<CastWebContents> cast_web_contents_; std::unique_ptr<CastWebContents> cast_web_contents_;
bool stopped_ = false; bool stopped_ = false;
bool has_navigation_delegate_ = false;
ui::GestureRecognizerImpl gesture_recognizer_;
exo::Surface* surface_ = nullptr;
// The navigation throttle for the current navigation event, if any. // The navigation throttle for the current navigation event, if any.
// Is set only: // Is set only:
// When has_navigation_delegate is true, and // When has_navigation_delegate is true, and
......
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