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

Side by Side Diff: chrome/browser/guest_view/guest_view_base.h

Issue 306003002: Move guest lifetime management to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ 5 #ifndef CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_
6 #define CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ 6 #define CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_
7 7
8 #include <queue> 8 #include <queue>
9 9
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "content/public/browser/browser_plugin_guest_delegate.h" 12 #include "content/public/browser/browser_plugin_guest_delegate.h"
13 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
14 #include "content/public/browser/web_contents_delegate.h" 14 #include "content/public/browser/web_contents_delegate.h"
15 #include "content/public/browser/web_contents_observer.h"
15 16
16 struct RendererContentSettingRules; 17 struct RendererContentSettingRules;
17 18
18 // A GuestViewBase is the base class browser-side API implementation for a 19 // A GuestViewBase is the base class browser-side API implementation for a
19 // <*view> tag. GuestViewBase maintains an association between a guest 20 // <*view> tag. GuestViewBase maintains an association between a guest
20 // WebContents and an embedder WebContents. It receives events issued from 21 // WebContents and an embedder WebContents. It receives events issued from
21 // the guest and relays them to the embedder. 22 // the guest and relays them to the embedder.
lazyboy 2014/05/29 19:13:58 Add comment about this becoming a WCObserver.
Fady Samuel 2014/05/29 21:21:12 This almost seems like an implementation detail. I
22 class GuestViewBase : public content::BrowserPluginGuestDelegate, 23 class GuestViewBase : public content::BrowserPluginGuestDelegate,
23 public content::WebContentsDelegate { 24 public content::WebContentsDelegate,
25 public content::WebContentsObserver {
24 public: 26 public:
25 class Event { 27 class Event {
26 public: 28 public:
27 Event(const std::string& name, scoped_ptr<base::DictionaryValue> args); 29 Event(const std::string& name, scoped_ptr<base::DictionaryValue> args);
28 ~Event(); 30 ~Event();
29 31
30 const std::string& name() const { return name_; } 32 const std::string& name() const { return name_; }
31 33
32 scoped_ptr<base::DictionaryValue> GetArguments(); 34 scoped_ptr<base::DictionaryValue> GetArguments();
33 35
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 std::string* partition_domain, 69 std::string* partition_domain,
68 std::string* partition_name, 70 std::string* partition_name,
69 bool* in_memory); 71 bool* in_memory);
70 72
71 // By default, JavaScript and images are enabled in guest content. 73 // By default, JavaScript and images are enabled in guest content.
72 static void GetDefaultContentSettingRules(RendererContentSettingRules* rules, 74 static void GetDefaultContentSettingRules(RendererContentSettingRules* rules,
73 bool incognito); 75 bool incognito);
74 76
75 virtual const char* GetViewType() const = 0; 77 virtual const char* GetViewType() const = 0;
76 78
79 virtual void EmbedderDestroyed() {}
lazyboy 2014/05/29 19:13:58 Add documentation.
Fady Samuel 2014/05/29 21:21:12 Done.
80
77 bool IsViewType(const char* const view_type) const { 81 bool IsViewType(const char* const view_type) const {
78 return !strcmp(GetViewType(), view_type); 82 return !strcmp(GetViewType(), view_type);
79 } 83 }
80 84
81 base::WeakPtr<GuestViewBase> AsWeakPtr(); 85 base::WeakPtr<GuestViewBase> AsWeakPtr();
82 86
83 virtual void Attach(content::WebContents* embedder_web_contents, 87 virtual void Attach(content::WebContents* embedder_web_contents,
84 const base::DictionaryValue& args); 88 const base::DictionaryValue& args);
85 89
86 content::WebContents* embedder_web_contents() const { 90 content::WebContents* embedder_web_contents() const {
87 return embedder_web_contents_; 91 return embedder_web_contents_;
88 } 92 }
89 93
90 // Returns the guest WebContents. 94 // Returns the guest WebContents.
91 content::WebContents* guest_web_contents() const { 95 content::WebContents* guest_web_contents() const {
92 return guest_web_contents_; 96 return web_contents();
93 } 97 }
94 98
95 // Returns the extra parameters associated with this GuestView passed 99 // Returns the extra parameters associated with this GuestView passed
96 // in from JavaScript. 100 // in from JavaScript.
97 base::DictionaryValue* extra_params() const { 101 base::DictionaryValue* extra_params() const {
98 return extra_params_.get(); 102 return extra_params_.get();
99 } 103 }
100 104
101 // Returns whether this guest has an associated embedder. 105 // Returns whether this guest has an associated embedder.
102 bool attached() const { return !!embedder_web_contents_; } 106 bool attached() const { return !!embedder_web_contents_; }
(...skipping 17 matching lines...) Expand all
120 124
121 // Returns the embedder's process ID. 125 // Returns the embedder's process ID.
122 int embedder_render_process_id() const { return embedder_render_process_id_; } 126 int embedder_render_process_id() const { return embedder_render_process_id_; }
123 127
124 GuestViewBase* GetOpener() const { 128 GuestViewBase* GetOpener() const {
125 return opener_.get(); 129 return opener_.get();
126 } 130 }
127 131
128 void SetOpener(GuestViewBase* opener); 132 void SetOpener(GuestViewBase* opener);
129 133
134 // WebContentsObserver implementation.
135 virtual void WebContentsDestroyed() OVERRIDE;
136
130 // WebContentsDelegate implementation. 137 // WebContentsDelegate implementation.
131 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; 138 virtual bool ShouldFocusPageAfterCrash() OVERRIDE;
132 virtual bool PreHandleGestureEvent( 139 virtual bool PreHandleGestureEvent(
133 content::WebContents* source, 140 content::WebContents* source,
134 const blink::WebGestureEvent& event) OVERRIDE; 141 const blink::WebGestureEvent& event) OVERRIDE;
135 142
136 // BrowserPluginGuestDelegate implementation. 143 // BrowserPluginGuestDelegate implementation.
137 virtual void Destroy() OVERRIDE; 144 virtual void Destroy() OVERRIDE;
138 virtual void RegisterDestructionCallback( 145 virtual void RegisterDestructionCallback(
139 const DestructionCallback& callback) OVERRIDE; 146 const DestructionCallback& callback) OVERRIDE;
140 protected: 147 protected:
141 GuestViewBase(int guest_instance_id, 148 GuestViewBase(int guest_instance_id,
142 content::WebContents* guest_web_contents, 149 content::WebContents* guest_web_contents,
143 const std::string& embedder_extension_id); 150 const std::string& embedder_extension_id);
144 virtual ~GuestViewBase(); 151 virtual ~GuestViewBase();
145 152
146 // Dispatches an event |event_name| to the embedder with the |event| fields. 153 // Dispatches an event |event_name| to the embedder with the |event| fields.
147 void DispatchEvent(Event* event); 154 void DispatchEvent(Event* event);
148 155
149 private: 156 private:
157 class EmbedderWebContentsObserver;
lazyboy 2014/05/29 19:13:58 nit: newline after this line.
Fady Samuel 2014/05/29 21:21:12 Done.
150 void SendQueuedEvents(); 158 void SendQueuedEvents();
151 159
152 content::WebContents* const guest_web_contents_;
153 content::WebContents* embedder_web_contents_; 160 content::WebContents* embedder_web_contents_;
154 const std::string embedder_extension_id_; 161 const std::string embedder_extension_id_;
155 int embedder_render_process_id_; 162 int embedder_render_process_id_;
156 content::BrowserContext* const browser_context_; 163 content::BrowserContext* const browser_context_;
157 // |guest_instance_id_| is a profile-wide unique identifier for a guest 164 // |guest_instance_id_| is a profile-wide unique identifier for a guest
158 // WebContents. 165 // WebContents.
159 const int guest_instance_id_; 166 const int guest_instance_id_;
160 // |view_instance_id_| is an identifier that's unique within a particular 167 // |view_instance_id_| is an identifier that's unique within a particular
161 // embedder RenderViewHost for a particular <*view> instance. 168 // embedder RenderViewHost for a particular <*view> instance.
162 int view_instance_id_; 169 int view_instance_id_;
163 170
164 // This is a queue of Events that are destined to be sent to the embedder once 171 // This is a queue of Events that are destined to be sent to the embedder once
165 // the guest is attached to a particular embedder. 172 // the guest is attached to a particular embedder.
166 std::deque<linked_ptr<Event> > pending_events_; 173 std::deque<linked_ptr<Event> > pending_events_;
167 174
168 // The opener guest view. 175 // The opener guest view.
169 base::WeakPtr<GuestViewBase> opener_; 176 base::WeakPtr<GuestViewBase> opener_;
170 177
171 DestructionCallback destruction_callback_; 178 DestructionCallback destruction_callback_;
172 179
173 // The extra parameters associated with this GuestView passed 180 // The extra parameters associated with this GuestView passed
174 // in from JavaScript. This will typically be the view instance ID, 181 // in from JavaScript. This will typically be the view instance ID,
175 // the API to use, and view-specific parameters. These parameters 182 // the API to use, and view-specific parameters. These parameters
176 // are passed along to new guests that are created from this guest. 183 // are passed along to new guests that are created from this guest.
177 scoped_ptr<base::DictionaryValue> extra_params_; 184 scoped_ptr<base::DictionaryValue> extra_params_;
178 185
186 scoped_ptr<EmbedderWebContentsObserver> embedder_web_contents_observer_;
187
179 // This is used to ensure pending tasks will not fire after this object is 188 // This is used to ensure pending tasks will not fire after this object is
180 // destroyed. 189 // destroyed.
181 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; 190 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_;
182 191
183 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); 192 DISALLOW_COPY_AND_ASSIGN(GuestViewBase);
184 }; 193 };
185 194
186 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ 195 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698