OLD | NEW |
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. |
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 Loading... |
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 // This method can be overridden by subclasses. It indicates that this guest's |
| 80 // embedder has been destroyed and the guest will be destroyed shortly. This |
| 81 // method gives derived classes the opportunity to perform some cleanup. |
| 82 virtual void EmbedderDestroyed() {} |
| 83 |
77 bool IsViewType(const char* const view_type) const { | 84 bool IsViewType(const char* const view_type) const { |
78 return !strcmp(GetViewType(), view_type); | 85 return !strcmp(GetViewType(), view_type); |
79 } | 86 } |
80 | 87 |
81 base::WeakPtr<GuestViewBase> AsWeakPtr(); | 88 base::WeakPtr<GuestViewBase> AsWeakPtr(); |
82 | 89 |
83 virtual void Attach(content::WebContents* embedder_web_contents, | 90 virtual void Attach(content::WebContents* embedder_web_contents, |
84 const base::DictionaryValue& args); | 91 const base::DictionaryValue& args); |
85 | 92 |
86 content::WebContents* embedder_web_contents() const { | 93 content::WebContents* embedder_web_contents() const { |
87 return embedder_web_contents_; | 94 return embedder_web_contents_; |
88 } | 95 } |
89 | 96 |
90 // Returns the guest WebContents. | 97 // Returns the guest WebContents. |
91 content::WebContents* guest_web_contents() const { | 98 content::WebContents* guest_web_contents() const { |
92 return guest_web_contents_; | 99 return web_contents(); |
93 } | 100 } |
94 | 101 |
95 // Returns the extra parameters associated with this GuestView passed | 102 // Returns the extra parameters associated with this GuestView passed |
96 // in from JavaScript. | 103 // in from JavaScript. |
97 base::DictionaryValue* extra_params() const { | 104 base::DictionaryValue* extra_params() const { |
98 return extra_params_.get(); | 105 return extra_params_.get(); |
99 } | 106 } |
100 | 107 |
101 // Returns whether this guest has an associated embedder. | 108 // Returns whether this guest has an associated embedder. |
102 bool attached() const { return !!embedder_web_contents_; } | 109 bool attached() const { return !!embedder_web_contents_; } |
(...skipping 17 matching lines...) Expand all Loading... |
120 | 127 |
121 // Returns the embedder's process ID. | 128 // Returns the embedder's process ID. |
122 int embedder_render_process_id() const { return embedder_render_process_id_; } | 129 int embedder_render_process_id() const { return embedder_render_process_id_; } |
123 | 130 |
124 GuestViewBase* GetOpener() const { | 131 GuestViewBase* GetOpener() const { |
125 return opener_.get(); | 132 return opener_.get(); |
126 } | 133 } |
127 | 134 |
128 void SetOpener(GuestViewBase* opener); | 135 void SetOpener(GuestViewBase* opener); |
129 | 136 |
| 137 // WebContentsObserver implementation. |
| 138 virtual void WebContentsDestroyed() OVERRIDE; |
| 139 |
130 // WebContentsDelegate implementation. | 140 // WebContentsDelegate implementation. |
131 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; | 141 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; |
132 virtual bool PreHandleGestureEvent( | 142 virtual bool PreHandleGestureEvent( |
133 content::WebContents* source, | 143 content::WebContents* source, |
134 const blink::WebGestureEvent& event) OVERRIDE; | 144 const blink::WebGestureEvent& event) OVERRIDE; |
135 | 145 |
136 // BrowserPluginGuestDelegate implementation. | 146 // BrowserPluginGuestDelegate implementation. |
137 virtual void Destroy() OVERRIDE; | 147 virtual void Destroy() OVERRIDE; |
138 virtual void RegisterDestructionCallback( | 148 virtual void RegisterDestructionCallback( |
139 const DestructionCallback& callback) OVERRIDE; | 149 const DestructionCallback& callback) OVERRIDE; |
140 protected: | 150 protected: |
141 GuestViewBase(int guest_instance_id, | 151 GuestViewBase(int guest_instance_id, |
142 content::WebContents* guest_web_contents, | 152 content::WebContents* guest_web_contents, |
143 const std::string& embedder_extension_id); | 153 const std::string& embedder_extension_id); |
144 virtual ~GuestViewBase(); | 154 virtual ~GuestViewBase(); |
145 | 155 |
146 // Dispatches an event |event_name| to the embedder with the |event| fields. | 156 // Dispatches an event |event_name| to the embedder with the |event| fields. |
147 void DispatchEvent(Event* event); | 157 void DispatchEvent(Event* event); |
148 | 158 |
149 private: | 159 private: |
| 160 class EmbedderWebContentsObserver; |
| 161 |
150 void SendQueuedEvents(); | 162 void SendQueuedEvents(); |
151 | 163 |
152 content::WebContents* const guest_web_contents_; | |
153 content::WebContents* embedder_web_contents_; | 164 content::WebContents* embedder_web_contents_; |
154 const std::string embedder_extension_id_; | 165 const std::string embedder_extension_id_; |
155 int embedder_render_process_id_; | 166 int embedder_render_process_id_; |
156 content::BrowserContext* const browser_context_; | 167 content::BrowserContext* const browser_context_; |
157 // |guest_instance_id_| is a profile-wide unique identifier for a guest | 168 // |guest_instance_id_| is a profile-wide unique identifier for a guest |
158 // WebContents. | 169 // WebContents. |
159 const int guest_instance_id_; | 170 const int guest_instance_id_; |
160 // |view_instance_id_| is an identifier that's unique within a particular | 171 // |view_instance_id_| is an identifier that's unique within a particular |
161 // embedder RenderViewHost for a particular <*view> instance. | 172 // embedder RenderViewHost for a particular <*view> instance. |
162 int view_instance_id_; | 173 int view_instance_id_; |
163 | 174 |
164 // This is a queue of Events that are destined to be sent to the embedder once | 175 // 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. | 176 // the guest is attached to a particular embedder. |
166 std::deque<linked_ptr<Event> > pending_events_; | 177 std::deque<linked_ptr<Event> > pending_events_; |
167 | 178 |
168 // The opener guest view. | 179 // The opener guest view. |
169 base::WeakPtr<GuestViewBase> opener_; | 180 base::WeakPtr<GuestViewBase> opener_; |
170 | 181 |
171 DestructionCallback destruction_callback_; | 182 DestructionCallback destruction_callback_; |
172 | 183 |
173 // The extra parameters associated with this GuestView passed | 184 // The extra parameters associated with this GuestView passed |
174 // in from JavaScript. This will typically be the view instance ID, | 185 // in from JavaScript. This will typically be the view instance ID, |
175 // the API to use, and view-specific parameters. These parameters | 186 // the API to use, and view-specific parameters. These parameters |
176 // are passed along to new guests that are created from this guest. | 187 // are passed along to new guests that are created from this guest. |
177 scoped_ptr<base::DictionaryValue> extra_params_; | 188 scoped_ptr<base::DictionaryValue> extra_params_; |
178 | 189 |
| 190 scoped_ptr<EmbedderWebContentsObserver> embedder_web_contents_observer_; |
| 191 |
179 // This is used to ensure pending tasks will not fire after this object is | 192 // This is used to ensure pending tasks will not fire after this object is |
180 // destroyed. | 193 // destroyed. |
181 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; | 194 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; |
182 | 195 |
183 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); | 196 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); |
184 }; | 197 }; |
185 | 198 |
186 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 199 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
OLD | NEW |