OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // A BrowserPluginEmbedder has a list of guests it manages. | 5 // A BrowserPluginEmbedder has a list of guests it manages. |
6 // In the beginning when a renderer sees one or more guests (BrowserPlugin | 6 // In the beginning when a renderer sees one or more guests (BrowserPlugin |
7 // instance(s)) and there is a request to navigate to them, the WebContents for | 7 // instance(s)) and there is a request to navigate to them, the WebContents for |
8 // that renderer creates a BrowserPluginEmbedder for itself. The | 8 // that renderer creates a BrowserPluginEmbedder for itself. The |
9 // BrowserPluginEmbedder, in turn, manages a set of BrowserPluginGuests -- one | 9 // BrowserPluginEmbedder, in turn, manages a set of BrowserPluginGuests -- one |
10 // BrowserPluginGuest for each guest in the embedding WebContents. Note that | 10 // BrowserPluginGuest for each guest in the embedding WebContents. Note that |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 // WebContentsObserver implementation. | 73 // WebContentsObserver implementation. |
74 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE; | 74 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE; |
75 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; | 75 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; |
76 | 76 |
77 // NotificationObserver method override. | 77 // NotificationObserver method override. |
78 virtual void Observe(int type, | 78 virtual void Observe(int type, |
79 const NotificationSource& source, | 79 const NotificationSource& source, |
80 const NotificationDetails& details) OVERRIDE; | 80 const NotificationDetails& details) OVERRIDE; |
81 | 81 |
82 // Overrides factory for testing. Default (NULL) value indicates regular | |
83 // (non-test) environment. | |
84 static void set_factory_for_testing(BrowserPluginHostFactory* factory) { | |
85 factory_ = factory; | |
86 } | |
87 | |
88 private: | |
89 friend class BrowserPluginEmbedderHelper; | |
90 friend class TestBrowserPluginEmbedder; | |
91 | |
92 BrowserPluginEmbedder(WebContentsImpl* web_contents, | |
93 RenderViewHost* render_view_host); | |
94 | |
95 // Returns a guest browser plugin delegate by its container ID specified | |
96 // in BrowserPlugin. | |
97 BrowserPluginGuest* GetGuestByInstanceID(int instance_id) const; | |
98 // Adds a new guest web_contents to the embedder (overridable in test). | |
99 virtual void AddGuest(int instance_id, | |
100 WebContents* guest_web_contents, | |
101 int64 frame_id); | |
102 void DestroyGuestByInstanceID(int instance_id); | |
103 void DestroyGuests(); | |
104 | |
105 // Message handlers (direct/indirect via BrowserPluginEmbedderHelper). | 82 // Message handlers (direct/indirect via BrowserPluginEmbedderHelper). |
106 // Routes update rect ack message to the appropriate guest. | 83 // Routes update rect ack message to the appropriate guest. |
107 void UpdateRectACK(int instance_id, int message_id, const gfx::Size& size); | 84 void UpdateRectACK(int instance_id, int message_id, const gfx::Size& size); |
108 void SetFocus(int instance_id, bool focused); | 85 void SetFocus(int instance_id, bool focused); |
109 void ResizeGuest(int instance_id, | 86 void ResizeGuest(int instance_id, |
110 TransportDIB* damage_buffer, | 87 TransportDIB* damage_buffer, |
111 #if defined(OS_WIN) | 88 #if defined(OS_WIN) |
112 int damage_buffer_size, | 89 int damage_buffer_size, |
113 #endif | 90 #endif |
114 int width, | 91 int width, |
115 int height, | 92 int height, |
116 bool resize_pending, | 93 bool resize_pending, |
117 float scale_factor); | 94 float scale_factor); |
118 // Handles input events sent from the BrowserPlugin (embedder's renderer | 95 // Handles input events sent from the BrowserPlugin (embedder's renderer |
119 // process) by passing them to appropriate guest's input handler. | 96 // process) by passing them to appropriate guest's input handler. |
120 void HandleInputEvent(int instance_id, | 97 void HandleInputEvent(int instance_id, |
121 RenderViewHost* render_view_host, | 98 RenderViewHost* render_view_host, |
122 const gfx::Rect& guest_rect, | 99 const gfx::Rect& guest_rect, |
123 const WebKit::WebInputEvent& event, | 100 const WebKit::WebInputEvent& event, |
124 IPC::Message* reply_message); | 101 IPC::Message* reply_message); |
125 void PluginDestroyed(int instance_id); | 102 void PluginDestroyed(int instance_id); |
126 | 103 |
| 104 // Overrides factory for testing. Default (NULL) value indicates regular |
| 105 // (non-test) environment. |
| 106 static void set_factory_for_testing(BrowserPluginHostFactory* factory) { |
| 107 factory_ = factory; |
| 108 } |
| 109 |
| 110 private: |
| 111 friend class TestBrowserPluginEmbedder; |
| 112 |
| 113 BrowserPluginEmbedder(WebContentsImpl* web_contents, |
| 114 RenderViewHost* render_view_host); |
| 115 |
| 116 // Returns a guest browser plugin delegate by its container ID specified |
| 117 // in BrowserPlugin. |
| 118 BrowserPluginGuest* GetGuestByInstanceID(int instance_id) const; |
| 119 // Adds a new guest web_contents to the embedder (overridable in test). |
| 120 virtual void AddGuest(int instance_id, |
| 121 WebContents* guest_web_contents, |
| 122 int64 frame_id); |
| 123 void DestroyGuestByInstanceID(int instance_id); |
| 124 void DestroyGuests(); |
| 125 |
127 // Called when visiblity of web_contents changes, so the embedder will | 126 // Called when visiblity of web_contents changes, so the embedder will |
128 // show/hide its guest. | 127 // show/hide its guest. |
129 void WebContentsVisibilityChanged(bool visible); | 128 void WebContentsVisibilityChanged(bool visible); |
130 | 129 |
131 // Static factory instance (always NULL for non-test). | 130 // Static factory instance (always NULL for non-test). |
132 static BrowserPluginHostFactory* factory_; | 131 static BrowserPluginHostFactory* factory_; |
133 | 132 |
134 // A scoped container for notification registries. | 133 // A scoped container for notification registries. |
135 NotificationRegistrar registrar_; | 134 NotificationRegistrar registrar_; |
136 | 135 |
137 // Contains guests' WebContents, mapping from their instance ids. | 136 // Contains guests' WebContents, mapping from their instance ids. |
138 ContainerInstanceMap guest_web_contents_by_instance_id_; | 137 ContainerInstanceMap guest_web_contents_by_instance_id_; |
139 RenderViewHost* render_view_host_; | 138 RenderViewHost* render_view_host_; |
140 | 139 |
141 DISALLOW_COPY_AND_ASSIGN(BrowserPluginEmbedder); | 140 DISALLOW_COPY_AND_ASSIGN(BrowserPluginEmbedder); |
142 }; | 141 }; |
143 | 142 |
144 } // namespace content | 143 } // namespace content |
145 | 144 |
146 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_ | 145 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_ |
OLD | NEW |