Commit 2fe094a1 authored by Zhaoxin's avatar Zhaoxin Committed by Commit Bot

[CastWebService] Move RenderProcessHostObserver into CastWebContentsImpl

Move RenderProcessHostObserver methods into CastWebContentsImpl. Remove
CastBluetoothChooser with corresponding CastWebView::Delegate method.

Merge-with: eureka-internal/361134

Bug: b/148898885
Test: CQ
Change-Id: I2adce89c9b3baba5780211e58d5a3be48ff63171
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2051024Reviewed-by: default avatarSean Topping <seantopping@chromium.org>
Commit-Queue: Zhaoxin Liang <zxliang@google.com>
Cr-Commit-Position: refs/heads/master@{#740463}
parent 49838e67
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/containers/flat_set.h" #include "base/containers/flat_set.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/process/process.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/string_piece_forward.h" #include "base/strings/string_piece_forward.h"
#include "chromecast/common/mojom/feature_manager.mojom.h" #include "chromecast/common/mojom/feature_manager.mojom.h"
...@@ -164,6 +165,10 @@ class CastWebContents { ...@@ -164,6 +165,10 @@ class CastWebContents {
// Notifies that a resource for the main frame failed to load. // Notifies that a resource for the main frame failed to load.
virtual void ResourceLoadFailed(CastWebContents* cast_web_contents) {} virtual void ResourceLoadFailed(CastWebContents* cast_web_contents) {}
// Propagates the process information via observer, in particular to
// the underlying OnRendererProcessStarted() method.
virtual void OnRenderProcessReady(const base::Process& process) {}
// Adds |this| to the ObserverList in the implementation of // Adds |this| to the ObserverList in the implementation of
// |cast_web_contents|. // |cast_web_contents|.
void Observe(CastWebContents* cast_web_contents); void Observe(CastWebContents* cast_web_contents);
......
...@@ -103,6 +103,32 @@ CastWebContents* CastWebContents::FromWebContents( ...@@ -103,6 +103,32 @@ CastWebContents* CastWebContents::FromWebContents(
return *it; return *it;
} }
void CastWebContentsImpl::RenderProcessReady(
content::RenderProcessHost* host) {
DCHECK(host->IsReady());
const base::Process& process = host->GetProcess();
for (auto& observer : observer_list_) {
observer.OnRenderProcessReady(process);
}
}
void CastWebContentsImpl::RenderProcessExited(
content::RenderProcessHost* host,
const content::ChildProcessTerminationInfo& info) {
RemoveRenderProcessHostObserver();
}
void CastWebContentsImpl::RenderProcessHostDestroyed(
content::RenderProcessHost* host) {
RemoveRenderProcessHostObserver();
}
void CastWebContentsImpl::RemoveRenderProcessHostObserver() {
if (main_process_host_)
main_process_host_->RemoveObserver(this);
main_process_host_ = nullptr;
}
CastWebContentsImpl::CastWebContentsImpl(content::WebContents* web_contents, CastWebContentsImpl::CastWebContentsImpl(content::WebContents* web_contents,
const InitParams& init_params) const InitParams& init_params)
: web_contents_(web_contents), : web_contents_(web_contents),
...@@ -118,6 +144,7 @@ CastWebContentsImpl::CastWebContentsImpl(content::WebContents* web_contents, ...@@ -118,6 +144,7 @@ CastWebContentsImpl::CastWebContentsImpl(content::WebContents* web_contents,
media_blocker_(init_params.use_media_blocker media_blocker_(init_params.use_media_blocker
? std::make_unique<CastMediaBlocker>(web_contents_) ? std::make_unique<CastMediaBlocker>(web_contents_)
: nullptr), : nullptr),
main_process_host_(nullptr),
tab_id_(init_params.is_root_window ? 0 : next_tab_id++), tab_id_(init_params.is_root_window ? 0 : next_tab_id++),
is_websql_enabled_(init_params.enable_websql), is_websql_enabled_(init_params.enable_websql),
is_mixer_audio_enabled_(init_params.enable_mixer_audio), is_mixer_audio_enabled_(init_params.enable_mixer_audio),
...@@ -132,6 +159,12 @@ CastWebContentsImpl::CastWebContentsImpl(content::WebContents* web_contents, ...@@ -132,6 +159,12 @@ CastWebContentsImpl::CastWebContentsImpl(content::WebContents* web_contents,
DCHECK(web_contents_); DCHECK(web_contents_);
DCHECK(web_contents_->GetController().IsInitialNavigation()); DCHECK(web_contents_->GetController().IsInitialNavigation());
DCHECK(!web_contents_->IsLoading()); DCHECK(!web_contents_->IsLoading());
DCHECK(web_contents_->GetMainFrame());
main_process_host_ = web_contents_->GetMainFrame()->GetProcess();
DCHECK(main_process_host_);
main_process_host_->AddObserver(this);
CastWebContents::GetAll().push_back(this); CastWebContents::GetAll().push_back(this);
content::WebContentsObserver::Observe(web_contents_); content::WebContentsObserver::Observe(web_contents_);
if (enabled_for_dev_) { if (enabled_for_dev_) {
...@@ -156,7 +189,7 @@ CastWebContentsImpl::~CastWebContentsImpl() { ...@@ -156,7 +189,7 @@ CastWebContentsImpl::~CastWebContentsImpl() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!notifying_) << "Do not destroy CastWebContents during observer " DCHECK(!notifying_) << "Do not destroy CastWebContents during observer "
"notification!"; "notification!";
RemoveRenderProcessHostObserver();
DisableDebugging(); DisableDebugging();
for (auto& observer : observer_list_) { for (auto& observer : observer_list_) {
observer.ResetCastWebContents(); observer.ResetCastWebContents();
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "chromecast/browser/cast_media_blocker.h" #include "chromecast/browser/cast_media_blocker.h"
#include "chromecast/browser/cast_web_contents.h" #include "chromecast/browser/cast_web_contents.h"
#include "content/public/browser/render_process_host_observer.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "services/service_manager/public/cpp/binder_registry.h" #include "services/service_manager/public/cpp/binder_registry.h"
...@@ -36,6 +37,7 @@ class RemoteDebuggingServer; ...@@ -36,6 +37,7 @@ class RemoteDebuggingServer;
} // namespace shell } // namespace shell
class CastWebContentsImpl : public CastWebContents, class CastWebContentsImpl : public CastWebContents,
public content::RenderProcessHostObserver,
public content::WebContentsObserver { public content::WebContentsObserver {
public: public:
CastWebContentsImpl(content::WebContents* web_contents, CastWebContentsImpl(content::WebContents* web_contents,
...@@ -82,6 +84,13 @@ class CastWebContentsImpl : public CastWebContents, ...@@ -82,6 +84,13 @@ class CastWebContentsImpl : public CastWebContents,
bool is_websql_enabled() override; bool is_websql_enabled() override;
bool is_mixer_audio_enabled() override; bool is_mixer_audio_enabled() override;
// content::RenderProcessHostObserver implementation:
void RenderProcessReady(content::RenderProcessHost* host) override;
void RenderProcessExited(
content::RenderProcessHost* host,
const content::ChildProcessTerminationInfo& info) override;
void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
// content::WebContentsObserver implementation: // content::WebContentsObserver implementation:
void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
void RenderFrameHostChanged(content::RenderFrameHost* old_host, void RenderFrameHostChanged(content::RenderFrameHost* old_host,
...@@ -147,6 +156,7 @@ class CastWebContentsImpl : public CastWebContents, ...@@ -147,6 +156,7 @@ class CastWebContentsImpl : public CastWebContents,
void TracePageLoadEnd(const GURL& url); void TracePageLoadEnd(const GURL& url);
void DisableDebugging(); void DisableDebugging();
void OnClosePageTimeout(); void OnClosePageTimeout();
void RemoveRenderProcessHostObserver();
std::vector<chromecast::shell::mojom::FeaturePtr> GetRendererFeatures(); std::vector<chromecast::shell::mojom::FeaturePtr> GetRendererFeatures();
content::WebContents* web_contents_; content::WebContents* web_contents_;
...@@ -160,6 +170,9 @@ class CastWebContentsImpl : public CastWebContents, ...@@ -160,6 +170,9 @@ class CastWebContentsImpl : public CastWebContents,
shell::RemoteDebuggingServer* const remote_debugging_server_; shell::RemoteDebuggingServer* const remote_debugging_server_;
std::unique_ptr<CastMediaBlocker> media_blocker_; std::unique_ptr<CastMediaBlocker> media_blocker_;
// Retained so that this observer can be removed before being destroyed:
content::RenderProcessHost* main_process_host_;
base::flat_set<std::unique_ptr<CastWebContents>> inner_contents_; base::flat_set<std::unique_ptr<CastWebContents>> inner_contents_;
std::vector<RendererFeature> renderer_features_; std::vector<RendererFeature> renderer_features_;
......
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