Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_ANDROID_RENDER_WIDGET_HOST_CONNECTOR_H_ | |
| 6 #define CONTENT_BROWSER_ANDROID_RENDER_WIDGET_HOST_CONNECTOR_H_ | |
| 7 | |
| 8 #include "base/memory/weak_ptr.h" | |
| 9 #include "content/browser/renderer_host/render_widget_host_view_android.h" | |
| 10 #include "content/public/browser/web_contents_observer.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 // An base class used to connect an object of the content layer lifecycle | |
| 15 // to |RenderWidgetHostViewAndroid|. The inherting class needs to | |
| 16 // override |UpdateRenderProcessConnection| to set itself to the RWHVA | |
| 17 // brought up foreground, and null out its reference in the RWHVA going | |
| 18 // 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.
| |
| 19 class RenderWidgetHostConnector { | |
| 20 public: | |
| 21 explicit RenderWidgetHostConnector(WebContents* web_contents); | |
| 22 virtual ~RenderWidgetHostConnector(); | |
| 23 | |
| 24 // Method to set itself to the |new_rwhva|, and null out the reference | |
| 25 // in |old_rwvha|. Example: | |
| 26 // | |
| 27 // if (old_rwhva) | |
| 28 // old_rwhva->set_object(nullptr); | |
| 29 // if (new_rwhva) | |
| 30 // new_rwhva->set_object(this); | |
| 31 virtual void UpdateRenderProcessConnection( | |
| 32 RenderWidgetHostViewAndroid* old_rwhva, | |
| 33 RenderWidgetHostViewAndroid* new_rhwva) = 0; | |
| 34 | |
| 35 RenderWidgetHostViewAndroid* rwhva_for_testing() const { | |
| 36 return render_widget_observer_->rwhva(); | |
| 37 } | |
| 38 | |
| 39 private: | |
| 40 // Observes RenderWidgetHostViewAndroid to keep the instance up to date. | |
| 41 class Observer : public WebContentsObserver, | |
| 42 public RenderWidgetHostViewAndroid::DestructionObserver { | |
| 43 public: | |
| 44 Observer(WebContents* web_contents, RenderWidgetHostConnector* connector); | |
| 45 ~Observer() override; | |
| 46 | |
| 47 // WebContentsObserver implementation. | |
| 48 void RenderViewHostChanged(RenderViewHost* old_host, | |
| 49 RenderViewHost* new_host) override; | |
| 50 void DidAttachInterstitialPage() override; | |
| 51 void DidDetachInterstitialPage() override; | |
| 52 void WebContentsDestroyed() override; | |
| 53 | |
| 54 // RenderWidgetHostViewAndroid::DestructionObserver implementation. | |
| 55 void RenderWidgetHostViewDestroyed( | |
| 56 RenderWidgetHostViewAndroid* rwhva) override; | |
| 57 | |
| 58 RenderWidgetHostViewAndroid* rwhva() const { return rwhva_; } | |
| 59 | |
| 60 private: | |
| 61 void UpdateRenderWidgetHostView(RenderWidgetHostViewAndroid* old_rwhva, | |
| 62 RenderWidgetHostViewAndroid* new_rwhva); | |
| 63 RenderWidgetHostViewAndroid* GetRenderWidgetHostViewAndroid() const; | |
| 64 | |
| 65 RenderWidgetHostConnector* const connector_; | |
| 66 RenderWidgetHostViewAndroid* rwhva_; | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(Observer); | |
| 69 }; | |
| 70 | |
| 71 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.
| |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostConnector); | |
| 74 }; | |
| 75 | |
| 76 } // namespace content | |
| 77 | |
| 78 #endif // CONTENT_BROWSER_ANDROID_RENDER_WIDGET_HOST_CONNECTOR_H_ | |
| OLD | NEW |