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 | 14 |
15 class AdViewGuest; | |
16 class WebViewGuest; | |
17 struct RendererContentSettingRules; | 15 struct RendererContentSettingRules; |
18 | 16 |
19 // A GuestViewBase is the base class browser-side API implementation for a | 17 // A GuestViewBase is the base class browser-side API implementation for a |
20 // <*view> tag. GuestViewBase maintains an association between a guest | 18 // <*view> tag. GuestViewBase maintains an association between a guest |
21 // WebContents and an embedder WebContents. It receives events issued from | 19 // WebContents and an embedder WebContents. It receives events issued from |
22 // the guest and relays them to the embedder. | 20 // the guest and relays them to the embedder. |
23 class GuestViewBase : public content::BrowserPluginGuestDelegate { | 21 class GuestViewBase : public content::BrowserPluginGuestDelegate { |
24 public: | 22 public: |
25 class Event { | 23 class Event { |
26 public: | 24 public: |
(...skipping 13 matching lines...) Expand all Loading... | |
40 template <typename T> | 38 template <typename T> |
41 T* As() { | 39 T* As() { |
42 if (IsViewType(T::Type)) | 40 if (IsViewType(T::Type)) |
43 return static_cast<T*>(this); | 41 return static_cast<T*>(this); |
44 | 42 |
45 return NULL; | 43 return NULL; |
46 } | 44 } |
47 | 45 |
48 static GuestViewBase* Create(content::WebContents* guest_web_contents, | 46 static GuestViewBase* Create(content::WebContents* guest_web_contents, |
49 const std::string& embedder_extension_id, | 47 const std::string& embedder_extension_id, |
50 const std::string& view_type, | 48 const std::string& view_type); |
51 const base::WeakPtr<GuestViewBase>& opener); | |
52 | 49 |
53 static GuestViewBase* FromWebContents(content::WebContents* web_contents); | 50 static GuestViewBase* FromWebContents(content::WebContents* web_contents); |
54 | 51 |
55 static GuestViewBase* From(int embedder_process_id, int instance_id); | 52 static GuestViewBase* From(int embedder_process_id, int instance_id); |
56 | 53 |
57 // For GuestViewBases, we create special guest processes, which host the | 54 // For GuestViewBases, we create special guest processes, which host the |
58 // tag content separately from the main application that embeds the tag. | 55 // tag content separately from the main application that embeds the tag. |
59 // A GuestViewBase can specify both the partition name and whether the storage | 56 // A GuestViewBase can specify both the partition name and whether the storage |
60 // for that partition should be persisted. Each tag gets a SiteInstance with | 57 // for that partition should be persisted. Each tag gets a SiteInstance with |
61 // a specially formatted URL, based on the application it is hosted by and | 58 // a specially formatted URL, based on the application it is hosted by and |
(...skipping 21 matching lines...) Expand all Loading... | |
83 | 80 |
84 content::WebContents* embedder_web_contents() const { | 81 content::WebContents* embedder_web_contents() const { |
85 return embedder_web_contents_; | 82 return embedder_web_contents_; |
86 } | 83 } |
87 | 84 |
88 // Returns the guest WebContents. | 85 // Returns the guest WebContents. |
89 content::WebContents* guest_web_contents() const { | 86 content::WebContents* guest_web_contents() const { |
90 return guest_web_contents_; | 87 return guest_web_contents_; |
91 } | 88 } |
92 | 89 |
90 // Returns the extra parameters associated with this GuestView passed | |
91 // in from JavaScript. | |
92 base::DictionaryValue* extra_params() const { | |
93 return extra_params_.get(); | |
94 } | |
95 | |
93 // Returns whether this guest has an associated embedder. | 96 // Returns whether this guest has an associated embedder. |
94 bool attached() const { return !!embedder_web_contents_; } | 97 bool attached() const { return !!embedder_web_contents_; } |
95 | 98 |
96 // Returns the instance ID of the <*view> element. | 99 // Returns the instance ID of the <*view> element. |
97 int view_instance_id() const { return view_instance_id_; } | 100 int view_instance_id() const { return view_instance_id_; } |
98 | 101 |
99 // Returns the instance ID of the guest WebContents. | 102 // Returns the instance ID of the guest WebContents. |
100 int guest_instance_id() const { return guest_instance_id_; } | 103 int guest_instance_id() const { return guest_instance_id_; } |
101 | 104 |
102 // Returns the extension ID of the embedder. | 105 // Returns the extension ID of the embedder. |
103 const std::string& embedder_extension_id() const { | 106 const std::string& embedder_extension_id() const { |
104 return embedder_extension_id_; | 107 return embedder_extension_id_; |
105 } | 108 } |
106 | 109 |
107 // Returns whether this GuestView is embedded in an extension/app. | 110 // Returns whether this GuestView is embedded in an extension/app. |
108 bool in_extension() const { return !embedder_extension_id_.empty(); } | 111 bool in_extension() const { return !embedder_extension_id_.empty(); } |
109 | 112 |
110 // Returns the user browser context of the embedder. | 113 // Returns the user browser context of the embedder. |
111 content::BrowserContext* browser_context() const { return browser_context_; } | 114 content::BrowserContext* browser_context() const { return browser_context_; } |
112 | 115 |
113 // Returns the embedder's process ID. | 116 // Returns the embedder's process ID. |
114 int embedder_render_process_id() const { return embedder_render_process_id_; } | 117 int embedder_render_process_id() const { return embedder_render_process_id_; } |
115 | 118 |
119 GuestViewBase* GetOpener() const { | |
120 return opener_.get(); | |
121 } | |
122 | |
123 void SetOpener(GuestViewBase* opener); | |
124 | |
116 // BrowserPluginGuestDelegate implementation. | 125 // BrowserPluginGuestDelegate implementation. |
117 virtual content::WebContents* GetOpener() const OVERRIDE; | 126 virtual void Destroy() OVERRIDE; |
118 virtual void SetOpener(content::WebContents* opener) OVERRIDE; | 127 virtual void RegisterDestructionCallback( |
128 const DestructionCallback& callback) OVERRIDE; | |
119 | 129 |
120 protected: | 130 protected: |
121 GuestViewBase(content::WebContents* guest_web_contents, | 131 GuestViewBase(content::WebContents* guest_web_contents, |
122 const std::string& embedder_extension_id, | 132 const std::string& embedder_extension_id); |
123 const base::WeakPtr<GuestViewBase>& opener); | |
124 virtual ~GuestViewBase(); | 133 virtual ~GuestViewBase(); |
125 | 134 |
126 // Dispatches an event |event_name| to the embedder with the |event| fields. | 135 // Dispatches an event |event_name| to the embedder with the |event| fields. |
127 void DispatchEvent(Event* event); | 136 void DispatchEvent(Event* event); |
128 | 137 |
129 private: | 138 private: |
130 void SendQueuedEvents(); | 139 void SendQueuedEvents(); |
131 | 140 |
132 content::WebContents* const guest_web_contents_; | 141 content::WebContents* const guest_web_contents_; |
133 content::WebContents* embedder_web_contents_; | 142 content::WebContents* embedder_web_contents_; |
134 const std::string embedder_extension_id_; | 143 const std::string embedder_extension_id_; |
135 int embedder_render_process_id_; | 144 int embedder_render_process_id_; |
136 content::BrowserContext* const browser_context_; | 145 content::BrowserContext* const browser_context_; |
137 // |guest_instance_id_| is a profile-wide unique identifier for a guest | 146 // |guest_instance_id_| is a profile-wide unique identifier for a guest |
138 // WebContents. | 147 // WebContents. |
139 const int guest_instance_id_; | 148 const int guest_instance_id_; |
140 // |view_instance_id_| is an identifier that's unique within a particular | 149 // |view_instance_id_| is an identifier that's unique within a particular |
141 // embedder RenderViewHost for a particular <*view> instance. | 150 // embedder RenderViewHost for a particular <*view> instance. |
142 int view_instance_id_; | 151 int view_instance_id_; |
143 | 152 |
144 // This is a queue of Events that are destined to be sent to the embedder once | 153 // This is a queue of Events that are destined to be sent to the embedder once |
145 // the guest is attached to a particular embedder. | 154 // the guest is attached to a particular embedder. |
146 std::deque<linked_ptr<Event> > pending_events_; | 155 std::deque<linked_ptr<Event> > pending_events_; |
147 | 156 |
148 // The opener guest view. | 157 // The opener guest view. |
149 base::WeakPtr<GuestViewBase> opener_; | 158 base::WeakPtr<GuestViewBase> opener_; |
150 | 159 |
160 DestructionCallback destruction_callback_; | |
161 | |
162 scoped_ptr<base::DictionaryValue> extra_params_; | |
lazyboy
2014/05/12 23:00:20
A bit of desc + a typical example of what this dic
Fady Samuel
2014/05/13 18:59:02
Done.
| |
163 | |
151 // This is used to ensure pending tasks will not fire after this object is | 164 // This is used to ensure pending tasks will not fire after this object is |
152 // destroyed. | 165 // destroyed. |
153 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; | 166 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; |
154 | 167 |
155 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); | 168 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); |
156 }; | 169 }; |
157 | 170 |
158 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 171 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
OLD | NEW |