Chromium Code Reviews| 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..69c23c5a1bd55d356c9901225e3d8be589eb9e79 |
| --- /dev/null |
| +++ b/content/browser/android/render_widget_host_connector.h |
| @@ -0,0 +1,78 @@ |
| +// 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/browser/renderer_host/render_widget_host_view_android.h" |
| +#include "content/public/browser/web_contents_observer.h" |
| + |
| +namespace content { |
| + |
| +// 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. |
|
boliu
2017/04/13 21:26:59
definitely should mention this object "owns itself
Jinsuk Kim
2017/04/13 23:00:43
Done.
|
| +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_for_testing() const { |
| + return render_widget_observer_->rwhva(); |
| + } |
| + |
| + private: |
| + // Observes RenderWidgetHostViewAndroid to keep the instance up to date. |
| + class Observer : public WebContentsObserver, |
| + public RenderWidgetHostViewAndroid::DestructionObserver { |
| + public: |
| + Observer(WebContents* web_contents, RenderWidgetHostConnector* connector); |
| + ~Observer() override; |
| + |
| + // WebContentsObserver implementation. |
| + void RenderViewHostChanged(RenderViewHost* old_host, |
| + RenderViewHost* new_host) override; |
| + void DidAttachInterstitialPage() override; |
| + void DidDetachInterstitialPage() override; |
| + void WebContentsDestroyed() override; |
| + |
| + // RenderWidgetHostViewAndroid::DestructionObserver implementation. |
| + void RenderWidgetHostViewDestroyed( |
| + RenderWidgetHostViewAndroid* rwhva) override; |
| + |
| + RenderWidgetHostViewAndroid* rwhva() const { return rwhva_; } |
| + |
| + private: |
| + void UpdateRenderWidgetHostView(RenderWidgetHostViewAndroid* old_rwhva, |
| + RenderWidgetHostViewAndroid* new_rwhva); |
| + RenderWidgetHostViewAndroid* GetRenderWidgetHostViewAndroid() const; |
| + |
| + RenderWidgetHostConnector* const connector_; |
| + RenderWidgetHostViewAndroid* rwhva_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Observer); |
| + }; |
| + |
| + std::unique_ptr<Observer> render_widget_observer_; |
|
boliu
2017/04/13 21:26:59
oh this is unique_ptr now, then you can move the e
Jinsuk Kim
2017/04/13 23:00:43
Connector::rwhva_for_testing() uses Observer::rwhv
boliu
2017/04/13 23:03:32
Yes. rwhva_for_testing shouldn't be inlined anyway
Jinsuk Kim
2017/04/13 23:31:10
Done. Renamed the class to be more descriptive as
boliu
2017/04/13 23:33:38
Hmm? It can stay an private inner class. You can f
Jinsuk Kim
2017/04/13 23:45:14
Haven't done that before... Thanks. Done.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostConnector); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_ANDROID_RENDER_WIDGET_HOST_CONNECTOR_H_ |