| 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" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 static GuestViewBase* From(int embedder_process_id, int instance_id); | 57 static GuestViewBase* From(int embedder_process_id, int instance_id); |
| 58 | 58 |
| 59 static bool IsGuest(content::WebContents* web_contents); | 59 static bool IsGuest(content::WebContents* web_contents); |
| 60 | 60 |
| 61 // By default, JavaScript and images are enabled in guest content. | 61 // By default, JavaScript and images are enabled in guest content. |
| 62 static void GetDefaultContentSettingRules(RendererContentSettingRules* rules, | 62 static void GetDefaultContentSettingRules(RendererContentSettingRules* rules, |
| 63 bool incognito); | 63 bool incognito); |
| 64 | 64 |
| 65 virtual const char* GetViewType() const = 0; | 65 virtual const char* GetViewType() const = 0; |
| 66 | 66 |
| 67 // This method is called after the guest has been attached to an embedder and |
| 68 // suspended resource loads have been resumed. |
| 69 // |
| 70 // This method can be overriden by subclasses. This gives the derived class |
| 71 // an opportunity to perform setup actions after attachment. |
| 72 virtual void DidAttachToEmbedder() {} |
| 73 |
| 67 // This method can be overridden by subclasses. This method is called when | 74 // This method can be overridden by subclasses. This method is called when |
| 68 // the initial set of frames within the page have completed loading. | 75 // the initial set of frames within the page have completed loading. |
| 69 virtual void DidStopLoading() {} | 76 virtual void DidStopLoading() {} |
| 70 | 77 |
| 78 // This method is called immediately before suspended resource loads have been |
| 79 // resumed on attachment to an embedder. |
| 80 // |
| 81 // This method can be overriden by subclasses. This gives the derived class |
| 82 // an opportunity to perform setup actions before attachment. |
| 83 virtual void WillAttachToEmbedder() {} |
| 84 |
| 71 // This method is called when the guest WebContents is about to be destroyed. | 85 // This method is called when the guest WebContents is about to be destroyed. |
| 72 // | 86 // |
| 73 // This method can be overridden by subclasses. This gives the derived class | 87 // This method can be overridden by subclasses. This gives the derived class |
| 74 // an opportunity to perform some cleanup prior to destruction. | 88 // an opportunity to perform some cleanup prior to destruction. |
| 75 virtual void WillDestroy() {} | 89 virtual void WillDestroy() {} |
| 76 | 90 |
| 77 // This method is called when the guest's embedder WebContents has been | 91 // This method is called when the guest's embedder WebContents has been |
| 78 // destroyed and the guest will be destroyed shortly. | 92 // destroyed and the guest will be destroyed shortly. |
| 79 // | 93 // |
| 80 // This method can be overridden by subclasses. This gives the derived class | 94 // This method can be overridden by subclasses. This gives the derived class |
| 81 // an opportunity to perform some cleanup prior to destruction. | 95 // an opportunity to perform some cleanup prior to destruction. |
| 82 virtual void EmbedderDestroyed() {} | 96 virtual void EmbedderDestroyed() {} |
| 83 | 97 |
| 84 // This method is called when the guest WebContents has been destroyed. This | 98 // This method is called when the guest WebContents has been destroyed. This |
| 85 // object will be destroyed after this call returns. | 99 // object will be destroyed after this call returns. |
| 86 // | 100 // |
| 87 // This method can be overridden by subclasses. This gives the derived class | 101 // This method can be overridden by subclasses. This gives the derived class |
| 88 // opportunity to perform some cleanup. | 102 // opportunity to perform some cleanup. |
| 89 virtual void GuestDestroyed() {} | 103 virtual void GuestDestroyed() {} |
| 90 | 104 |
| 91 // This method queries whether drag-and-drop is enabled for this particular | 105 // This method queries whether drag-and-drop is enabled for this particular |
| 92 // view. By default, drag-and-drop is disabled. Derived classes can override | 106 // view. By default, drag-and-drop is disabled. Derived classes can override |
| 93 // this behavior to enable drag-and-drop. | 107 // this behavior to enable drag-and-drop. |
| 94 virtual bool IsDragAndDropEnabled() const; | 108 virtual bool IsDragAndDropEnabled() const; |
| 95 | 109 |
| 110 // Once a guest WebContents is ready, this initiates the association of |this| |
| 111 // GuestView with |guest_web_contents|. |
| 112 void Init(content::WebContents* guest_web_contents, |
| 113 const std::string& embedder_extension_id); |
| 114 |
| 96 bool IsViewType(const char* const view_type) const { | 115 bool IsViewType(const char* const view_type) const { |
| 97 return !strcmp(GetViewType(), view_type); | 116 return !strcmp(GetViewType(), view_type); |
| 98 } | 117 } |
| 99 | 118 |
| 100 base::WeakPtr<GuestViewBase> AsWeakPtr(); | 119 base::WeakPtr<GuestViewBase> AsWeakPtr(); |
| 101 | 120 |
| 102 virtual void Attach(content::WebContents* embedder_web_contents, | |
| 103 const base::DictionaryValue& args); | |
| 104 | |
| 105 content::WebContents* embedder_web_contents() const { | 121 content::WebContents* embedder_web_contents() const { |
| 106 return embedder_web_contents_; | 122 return embedder_web_contents_; |
| 107 } | 123 } |
| 108 | 124 |
| 109 // Returns the guest WebContents. | 125 // Returns the guest WebContents. |
| 110 content::WebContents* guest_web_contents() const { | 126 content::WebContents* guest_web_contents() const { |
| 111 return web_contents(); | 127 return web_contents(); |
| 112 } | 128 } |
| 113 | 129 |
| 114 // Returns the extra parameters associated with this GuestView passed | 130 // Returns the extra parameters associated with this GuestView passed |
| (...skipping 26 matching lines...) Expand all Loading... |
| 141 int embedder_render_process_id() const { return embedder_render_process_id_; } | 157 int embedder_render_process_id() const { return embedder_render_process_id_; } |
| 142 | 158 |
| 143 GuestViewBase* GetOpener() const { | 159 GuestViewBase* GetOpener() const { |
| 144 return opener_.get(); | 160 return opener_.get(); |
| 145 } | 161 } |
| 146 | 162 |
| 147 void SetOpener(GuestViewBase* opener); | 163 void SetOpener(GuestViewBase* opener); |
| 148 | 164 |
| 149 // BrowserPluginGuestDelegate implementation. | 165 // BrowserPluginGuestDelegate implementation. |
| 150 virtual void Destroy() OVERRIDE FINAL; | 166 virtual void Destroy() OVERRIDE FINAL; |
| 167 virtual void DidAttach() OVERRIDE FINAL; |
| 151 virtual void RegisterDestructionCallback( | 168 virtual void RegisterDestructionCallback( |
| 152 const DestructionCallback& callback) OVERRIDE FINAL; | 169 const DestructionCallback& callback) OVERRIDE FINAL; |
| 170 virtual void WillAttach( |
| 171 content::WebContents* embedder_web_contents, |
| 172 const base::DictionaryValue& extra_params) OVERRIDE FINAL; |
| 153 | 173 |
| 154 protected: | 174 protected: |
| 155 GuestViewBase(int guest_instance_id, | 175 explicit GuestViewBase(int guest_instance_id); |
| 156 content::WebContents* guest_web_contents, | 176 |
| 157 const std::string& embedder_extension_id); | |
| 158 virtual ~GuestViewBase(); | 177 virtual ~GuestViewBase(); |
| 159 | 178 |
| 160 // Dispatches an event |event_name| to the embedder with the |event| fields. | 179 // Dispatches an event |event_name| to the embedder with the |event| fields. |
| 161 void DispatchEvent(Event* event); | 180 void DispatchEvent(Event* event); |
| 162 | 181 |
| 163 private: | 182 private: |
| 164 class EmbedderWebContentsObserver; | 183 class EmbedderWebContentsObserver; |
| 165 | 184 |
| 166 void SendQueuedEvents(); | 185 void SendQueuedEvents(); |
| 167 | 186 |
| 168 // WebContentsObserver implementation. | 187 // WebContentsObserver implementation. |
| 169 virtual void DidStopLoading( | 188 virtual void DidStopLoading( |
| 170 content::RenderViewHost* render_view_host) OVERRIDE FINAL; | 189 content::RenderViewHost* render_view_host) OVERRIDE FINAL; |
| 171 virtual void WebContentsDestroyed() OVERRIDE FINAL; | 190 virtual void WebContentsDestroyed() OVERRIDE FINAL; |
| 172 | 191 |
| 173 // WebContentsDelegate implementation. | 192 // WebContentsDelegate implementation. |
| 174 virtual bool ShouldFocusPageAfterCrash() OVERRIDE FINAL; | 193 virtual bool ShouldFocusPageAfterCrash() OVERRIDE FINAL; |
| 175 virtual bool PreHandleGestureEvent( | 194 virtual bool PreHandleGestureEvent( |
| 176 content::WebContents* source, | 195 content::WebContents* source, |
| 177 const blink::WebGestureEvent& event) OVERRIDE FINAL; | 196 const blink::WebGestureEvent& event) OVERRIDE FINAL; |
| 178 | 197 |
| 179 content::WebContents* embedder_web_contents_; | 198 content::WebContents* embedder_web_contents_; |
| 180 const std::string embedder_extension_id_; | 199 std::string embedder_extension_id_; |
| 181 int embedder_render_process_id_; | 200 int embedder_render_process_id_; |
| 182 content::BrowserContext* const browser_context_; | 201 content::BrowserContext* browser_context_; |
| 183 // |guest_instance_id_| is a profile-wide unique identifier for a guest | 202 // |guest_instance_id_| is a profile-wide unique identifier for a guest |
| 184 // WebContents. | 203 // WebContents. |
| 185 const int guest_instance_id_; | 204 const int guest_instance_id_; |
| 186 // |view_instance_id_| is an identifier that's unique within a particular | 205 // |view_instance_id_| is an identifier that's unique within a particular |
| 187 // embedder RenderViewHost for a particular <*view> instance. | 206 // embedder RenderViewHost for a particular <*view> instance. |
| 188 int view_instance_id_; | 207 int view_instance_id_; |
| 189 | 208 |
| 209 bool initialized_; |
| 210 |
| 190 // This is a queue of Events that are destined to be sent to the embedder once | 211 // This is a queue of Events that are destined to be sent to the embedder once |
| 191 // the guest is attached to a particular embedder. | 212 // the guest is attached to a particular embedder. |
| 192 std::deque<linked_ptr<Event> > pending_events_; | 213 std::deque<linked_ptr<Event> > pending_events_; |
| 193 | 214 |
| 194 // The opener guest view. | 215 // The opener guest view. |
| 195 base::WeakPtr<GuestViewBase> opener_; | 216 base::WeakPtr<GuestViewBase> opener_; |
| 196 | 217 |
| 197 DestructionCallback destruction_callback_; | 218 DestructionCallback destruction_callback_; |
| 198 | 219 |
| 199 // The extra parameters associated with this GuestView passed | 220 // The extra parameters associated with this GuestView passed |
| 200 // in from JavaScript. This will typically be the view instance ID, | 221 // in from JavaScript. This will typically be the view instance ID, |
| 201 // the API to use, and view-specific parameters. These parameters | 222 // the API to use, and view-specific parameters. These parameters |
| 202 // are passed along to new guests that are created from this guest. | 223 // are passed along to new guests that are created from this guest. |
| 203 scoped_ptr<base::DictionaryValue> extra_params_; | 224 scoped_ptr<base::DictionaryValue> extra_params_; |
| 204 | 225 |
| 205 scoped_ptr<EmbedderWebContentsObserver> embedder_web_contents_observer_; | 226 scoped_ptr<EmbedderWebContentsObserver> embedder_web_contents_observer_; |
| 206 | 227 |
| 207 // This is used to ensure pending tasks will not fire after this object is | 228 // This is used to ensure pending tasks will not fire after this object is |
| 208 // destroyed. | 229 // destroyed. |
| 209 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; | 230 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; |
| 210 | 231 |
| 211 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); | 232 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); |
| 212 }; | 233 }; |
| 213 | 234 |
| 214 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 235 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
| OLD | NEW |