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

Side by Side Diff: content/browser/android/render_widget_host_connector.h

Issue 2792063003: Factor out RenderWidgetHostConnector (Closed)
Patch Set: test 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 unified diff | Download patch
OLDNEW
(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/public/browser/web_contents_observer.h"
10
11 namespace content {
12
13 class RenderWidgetHostViewAndroid;
14
15 // An base class used to connect an object of the content layer lifecycle
16 // to |RenderWidgetHostViewAndroid|. The inherting class needs to
17 // override |UpdateRenderProcessConnection| to set itself to the RWHVA
18 // brought up foreground, and null out its reference in the RWHVA going
19 // away so it won't access the object any more.
20 class RenderWidgetHostConnector {
21 public:
22 explicit RenderWidgetHostConnector(WebContents* web_contents);
23 virtual ~RenderWidgetHostConnector();
24
25 // Called when the rwhva is being destroyed. Helps avoid further referencing
26 // such instance.
27 void ResetRenderWidgetHostView(RenderWidgetHostViewAndroid* deleted_rwhva);
28
29 // Method to set itself to the |new_rwhva|, and null out the reference
30 // in |old_rwvha|. Example:
31 //
32 // if (old_rwhva)
33 // old_rwhva->set_object(nullptr);
34 // if (new_rwhva)
35 // new_rwhva->set_object(this);
36 virtual void UpdateRenderProcessConnection(
37 RenderWidgetHostViewAndroid* old_rwhva,
38 RenderWidgetHostViewAndroid* new_rhwva) = 0;
39
40 RenderWidgetHostViewAndroid* rwhva_for_testing() const {
41 return render_widget_observer_->rwhva();
42 }
43
44 private:
45 // Observes RenderWidgetHostViewAndroid updates and keeps the up-to-date
46 // instance through the interface |WebContentsObserver|.
47 class Observer : public WebContentsObserver {
48 public:
49 Observer(WebContents* web_contents, RenderWidgetHostConnector* connector);
50 ~Observer() override;
51
52 // WebContentsObserver implementation.
53 void RenderViewReady() override;
54 void RenderViewHostChanged(RenderViewHost* old_host,
55 RenderViewHost* new_host) override;
56 void DidAttachInterstitialPage() override;
57 void DidDetachInterstitialPage() override;
58 void WebContentsDestroyed() override;
59
60 void ResetRenderWidgetHostView(RenderWidgetHostViewAndroid* deleted_rwhva);
61 RenderWidgetHostViewAndroid* rwhva() const { return rwhva_; }
62
63 private:
64 void UpdateRenderWidgetHostView(RenderWidgetHostViewAndroid* rwhva);
65 RenderWidgetHostViewAndroid* GetRenderWidgetHostViewAndroid() const;
66
67 RenderWidgetHostConnector* const connector_;
68 RenderWidgetHostViewAndroid* rwhva_;
69
70 DISALLOW_COPY_AND_ASSIGN(Observer);
71 };
72
73 std::unique_ptr<Observer> render_widget_observer_;
74
75 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostConnector);
76 };
77
78 } // namespace content
79
80 #endif // CONTENT_BROWSER_ANDROID_RENDER_WIDGET_HOST_CONNECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698