Expand CastWebContents delegate and observer interfaces
We want to reduce the internal dependency on
content::WebContentsObserver. Part of this effort requires the
implementation and usage of the delegate and observer interfaces of
CastWebContents.
CastWebContents inherits from WebContentsObserver and will handle nearly
all the implementation of WebContentsObserver that is spread across the
repository. The remaining functionality can be either delegated or
simply passed through to various objects.
feature_manager.mojom has been moved into //chromecast/browser and is
now being used in CastWebContents. This move allows us to shift some of
the implementation of content::WebContentsObserver from WebUiSettingsWeb
into CastWebContents. Additionally, a number of other classes share a
nearly identical implementation that we will be able to move with
minimal effort after this change.
Bug: b/120675407
Change-Id: Ia8f5a308bf45b4d72edfc02c84ba995fbe9cf8ee
Test: CQ tryjobs.
Reviewed-on: https://chromium-review.googlesource.com/c/1405973
Reviewed-by: Yuchen Liu <[email protected]>
Reviewed-by: Will Harris <[email protected]>
Reviewed-by: Sean Topping <[email protected]>
Commit-Queue: Chad Duffin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#621836}
diff --git a/chromecast/browser/cast_web_contents.h b/chromecast/browser/cast_web_contents.h
index 71d946b..db1c817 100644
--- a/chromecast/browser/cast_web_contents.h
+++ b/chromecast/browser/cast_web_contents.h
@@ -5,6 +5,11 @@
#ifndef CHROMECAST_BROWSER_CAST_WEB_CONTENTS_H_
#define CHROMECAST_BROWSER_CAST_WEB_CONTENTS_H_
+#include <string>
+#include <vector>
+
+#include "base/observer_list.h"
+#include "chromecast/common/mojom/feature_manager.mojom.h"
#include "url/gurl.h"
namespace content {
@@ -35,10 +40,42 @@
virtual void OnPageStopped(CastWebContents* cast_web_contents,
int error_code) = 0;
+ // Collects the set of delegate-specific renderer features that needs to be
+ // configured when `CastWebContents::RenderFrameCreated` is invoked.
+ virtual std::vector<chromecast::shell::mojom::FeaturePtr>
+ GetRendererFeatures();
+
protected:
virtual ~Delegate() {}
};
+ class Observer {
+ public:
+ Observer();
+
+ virtual void RenderFrameCreated(int render_process_id,
+ int render_frame_id) {}
+ virtual void OnInterfaceRequestFromFrame(
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle* interface_pipe) {}
+
+ // Adds |this| to the ObserverList in the implementation of
+ // |cast_web_contents|.
+ void Observe(CastWebContents* cast_web_contents);
+
+ // Removes |this| from the ObserverList in the implementation of
+ // |cast_web_contents_|. This is only invoked by CastWebContents and is used
+ // to ensure that once the observed CastWebContents object is destructed the
+ // CastWebContents::Observer does not invoke any additional function calls
+ // on it.
+ void ResetCastWebContents();
+
+ protected:
+ virtual ~Observer();
+
+ CastWebContents* cast_web_contents_;
+ };
+
// Page state for the main frame.
enum class PageState {
IDLE, // Main frame has not started yet.
@@ -72,6 +109,15 @@
// Set the delegate. SetDelegate(nullptr) can be used to stop notifications.
virtual void SetDelegate(Delegate* delegate) = 0;
+ virtual void AllowWebAndMojoWebUiBindings() = 0;
+ virtual void ClearRenderWidgetHostView() = 0;
+
+ // Used to add or remove |observer| to the ObserverList in the implementation.
+ // These functions should only be invoked by CastWebContents::Observer in a
+ // valid sequence, enforced via SequenceChecker.
+ virtual void AddObserver(Observer* observer) = 0;
+ virtual void RemoveObserver(Observer* observer) = 0;
+
private:
DISALLOW_COPY_AND_ASSIGN(CastWebContents);
};