Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(686)

Unified Diff: content/browser/android/render_widget_host_connector.h

Issue 2792063003: Factor out RenderWidgetHostConnector (Closed)
Patch Set: RenderWidgetHostConnnector Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/android/render_widget_host_connector.h
diff --git a/content/browser/android/render_widget_host_connector.h b/content/browser/android/render_widget_host_connector.h
new file mode 100644
index 0000000000000000000000000000000000000000..42042b5a324fac8ccc8cdbabd99015b561b5c9c2
--- /dev/null
+++ b/content/browser/android/render_widget_host_connector.h
@@ -0,0 +1,75 @@
+// Copyright 2017 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 CONTENT_BROWSER_ANDROID_RENDER_WIDGET_HOST_CONNECTOR_H_
+#define CONTENT_BROWSER_ANDROID_RENDER_WIDGET_HOST_CONNECTOR_H_
+
+#include "base/memory/weak_ptr.h"
+#include "content/public/browser/web_contents_observer.h"
+
+namespace content {
+
+class RenderWidgetHostViewAndroid;
+
+// An base class used to connect an object of the content layer lifecycle
+// to |RenderWidgetHostViewAndroid|. The inherting class needs to
+// override |UpdateRenderProcessConnection| to set itself to the RWHVA
+// brought up foreground, and null out its reference in the RWHVA going
+// away so it won't access the object any more.
+class RenderWidgetHostConnector {
+ public:
+ explicit RenderWidgetHostConnector(WebContents* web_contents);
+ virtual ~RenderWidgetHostConnector();
+
+ // Method to set itself to the |new_rwhva|, and null out the reference
+ // in |old_rwvha|. Example:
+ //
+ // if (old_rwhva)
+ // old_rwhva->set_object(nullptr);
+ // if (new_rwhva)
+ // new_rwhva->set_object(this);
+ virtual void UpdateRenderProcessConnection(
+ RenderWidgetHostViewAndroid* old_rwhva,
+ RenderWidgetHostViewAndroid* new_rhwva) = 0;
+
+ RenderWidgetHostViewAndroid* rwhva() const {
boliu 2017/04/10 18:08:43 I mean this getter is not really needed explicitly
Jinsuk Kim 2017/04/11 01:41:58 Removed rwhva() but let ImeAdapterAndroid keep the
boliu 2017/04/11 01:47:04 Yeah I prefer explicit destroy now. That was a on
Jinsuk Kim 2017/04/11 02:28:09 Done. Could you let me know if there's a reason we
boliu 2017/04/11 02:34:24 It's purely to make this interface simpler. If you
+ return render_widget_observer_.rwhva();
+ }
+
+ private:
+ // Observes RenderWidgetHostViewAndroid updates and keeps the up-to-date
+ // instance through the interface |WebContentsObserver|.
+ class Observer : public WebContentsObserver {
+ public:
+ Observer(WebContents* web_contents, RenderWidgetHostConnector* connector);
+ ~Observer() override;
+
+ // WebContentsObserver implementation.
+ void RenderViewReady() override;
+ void RenderViewHostChanged(RenderViewHost* old_host,
+ RenderViewHost* new_host) override;
+ void DidAttachInterstitialPage() override;
+ void DidDetachInterstitialPage() override;
+ void WebContentsDestroyed() override;
+
+ RenderWidgetHostViewAndroid* rwhva() const { return rwhva_.get(); }
+
+ private:
+ void UpdateRenderWidgetHostView(RenderWidgetHostViewAndroid* rwhva);
+ RenderWidgetHostViewAndroid* GetRenderWidgetHostViewAndroid() const;
+
+ RenderWidgetHostConnector* connector_;
+ base::WeakPtr<RenderWidgetHostViewAndroid> rwhva_;
+
+ DISALLOW_COPY_AND_ASSIGN(Observer);
+ };
+
+ const Observer render_widget_observer_;
+
+ DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostConnector);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_ANDROID_RENDER_WIDGET_HOST_CONNECTOR_H_

Powered by Google App Engine
This is Rietveld 408576698