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

Side by Side Diff: content/renderer/browser_plugin/browser_plugin.cc

Issue 11956022: Browser Plugin: Allocate Instance IDs in BrowserPluginEmbedder instead of BrowserPluginManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with ToT Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
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 #include "content/renderer/browser_plugin/browser_plugin.h" 5 #include "content/renderer/browser_plugin/browser_plugin.h"
6 6
7 #include "base/json/json_string_value_serializer.h" 7 #include "base/json/json_string_value_serializer.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 30 matching lines...) Expand all
41 using WebKit::WebPluginParams; 41 using WebKit::WebPluginParams;
42 using WebKit::WebPoint; 42 using WebKit::WebPoint;
43 using WebKit::WebRect; 43 using WebKit::WebRect;
44 using WebKit::WebURL; 44 using WebKit::WebURL;
45 using WebKit::WebVector; 45 using WebKit::WebVector;
46 46
47 namespace content { 47 namespace content {
48 48
49 namespace { 49 namespace {
50 50
51 const int INSTANCE_ID_NONE = 0;
52
51 // Events. 53 // Events.
52 const char kEventExit[] = "exit"; 54 const char kEventExit[] = "exit";
53 const char kEventLoadAbort[] = "loadabort"; 55 const char kEventLoadAbort[] = "loadabort";
54 const char kEventLoadCommit[] = "loadcommit"; 56 const char kEventLoadCommit[] = "loadcommit";
55 const char kEventLoadRedirect[] = "loadredirect"; 57 const char kEventLoadRedirect[] = "loadredirect";
56 const char kEventLoadStart[] = "loadstart"; 58 const char kEventLoadStart[] = "loadstart";
57 const char kEventLoadStop[] = "loadstop"; 59 const char kEventLoadStop[] = "loadstop";
58 const char kEventResponsive[] = "responsive"; 60 const char kEventResponsive[] = "responsive";
59 const char kEventSizeChanged[] = "sizechanged"; 61 const char kEventSizeChanged[] = "sizechanged";
60 const char kEventUnresponsive[] = "unresponsive"; 62 const char kEventUnresponsive[] = "unresponsive";
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 NOTREACHED() << "Unknown Termination Status."; 100 NOTREACHED() << "Unknown Termination Status.";
99 return "unknown"; 101 return "unknown";
100 } 102 }
101 103
102 static std::string GetInternalEventName(const char* event_name) { 104 static std::string GetInternalEventName(const char* event_name) {
103 return base::StringPrintf("-internal-%s", event_name); 105 return base::StringPrintf("-internal-%s", event_name);
104 } 106 }
105 } 107 }
106 108
107 BrowserPlugin::BrowserPlugin( 109 BrowserPlugin::BrowserPlugin(
108 int instance_id,
109 RenderViewImpl* render_view, 110 RenderViewImpl* render_view,
110 WebKit::WebFrame* frame, 111 WebKit::WebFrame* frame,
111 const WebPluginParams& params) 112 const WebPluginParams& params)
112 : instance_id_(instance_id), 113 : instance_id_(INSTANCE_ID_NONE),
113 render_view_(render_view->AsWeakPtr()), 114 render_view_(render_view->AsWeakPtr()),
114 render_view_routing_id_(render_view->GetRoutingID()), 115 render_view_routing_id_(render_view->GetRoutingID()),
115 container_(NULL), 116 container_(NULL),
116 damage_buffer_sequence_id_(0), 117 damage_buffer_sequence_id_(0),
117 resize_ack_received_(true), 118 resize_ack_received_(true),
118 sad_guest_(NULL), 119 sad_guest_(NULL),
119 guest_crashed_(false), 120 guest_crashed_(false),
120 navigate_src_sent_(false), 121 navigate_src_sent_(false),
121 auto_size_(false), 122 auto_size_(false),
122 max_height_(0), 123 max_height_(0),
123 max_width_(0), 124 max_width_(0),
124 min_height_(0), 125 min_height_(0),
125 min_width_(0), 126 min_width_(0),
126 process_id_(-1), 127 process_id_(-1),
127 persist_storage_(false), 128 persist_storage_(false),
128 valid_partition_id_(true), 129 valid_partition_id_(true),
129 content_window_routing_id_(MSG_ROUTING_NONE), 130 content_window_routing_id_(MSG_ROUTING_NONE),
130 plugin_focused_(false), 131 plugin_focused_(false),
131 visible_(true), 132 visible_(true),
132 size_changed_in_flight_(false), 133 size_changed_in_flight_(false),
134 allocate_instance_id_sent_(false),
133 browser_plugin_manager_(render_view->browser_plugin_manager()), 135 browser_plugin_manager_(render_view->browser_plugin_manager()),
134 current_nav_entry_index_(0), 136 current_nav_entry_index_(0),
135 nav_entry_count_(0), 137 nav_entry_count_(0),
136 compositing_enabled_(false) { 138 compositing_enabled_(false) {
137 browser_plugin_manager()->AddBrowserPlugin(instance_id, this);
138 bindings_.reset(new BrowserPluginBindings(this)); 139 bindings_.reset(new BrowserPluginBindings(this));
139 140
140 ParseAttributes(params); 141 ParseAttributes(params);
141 } 142 }
142 143
143 BrowserPlugin::~BrowserPlugin() { 144 BrowserPlugin::~BrowserPlugin() {
145 // If the BrowserPlugin has never navigated then the browser process and
146 // BrowserPluginManager don't know about it and so there is nothing to do
147 // here.
148 if (!navigate_src_sent_)
149 return;
144 browser_plugin_manager()->RemoveBrowserPlugin(instance_id_); 150 browser_plugin_manager()->RemoveBrowserPlugin(instance_id_);
145 browser_plugin_manager()->Send( 151 browser_plugin_manager()->Send(
146 new BrowserPluginHostMsg_PluginDestroyed( 152 new BrowserPluginHostMsg_PluginDestroyed(
147 render_view_routing_id_, 153 render_view_routing_id_,
148 instance_id_)); 154 instance_id_));
149 } 155 }
150 156
151 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { 157 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) {
152 bool handled = true; 158 bool handled = true;
153 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) 159 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 bool BrowserPlugin::SetSrcAttribute(const std::string& src, 218 bool BrowserPlugin::SetSrcAttribute(const std::string& src,
213 std::string* error_message) { 219 std::string* error_message) {
214 if (!valid_partition_id_) { 220 if (!valid_partition_id_) {
215 *error_message = kErrorInvalidPartition; 221 *error_message = kErrorInvalidPartition;
216 return false; 222 return false;
217 } 223 }
218 224
219 if (src.empty() || (src == src_ && !guest_crashed_)) 225 if (src.empty() || (src == src_ && !guest_crashed_))
220 return true; 226 return true;
221 227
228 src_ = src;
229
222 // If we haven't created the guest yet, do so now. We will navigate it right 230 // If we haven't created the guest yet, do so now. We will navigate it right
223 // after creation. If |src| is empty, we can delay the creation until we 231 // after creation. If |src| is empty, we can delay the creation until we
224 // actually need it. 232 // actually need it.
225 if (!navigate_src_sent_) { 233 if (!navigate_src_sent_) {
226 BrowserPluginHostMsg_CreateGuest_Params create_guest_params; 234 // On initial navigation, we request an instance ID from the browser
227 create_guest_params.storage_partition_id = storage_partition_id_; 235 // process. We essentially ignore all subsequent calls to SetSrcAttribute
228 create_guest_params.persist_storage = persist_storage_; 236 // until we receive an instance ID. |allocate_instance_id_sent_|
229 create_guest_params.focused = ShouldGuestBeFocused(); 237 // prevents BrowserPlugin from allocating more than one instance ID.
230 create_guest_params.visible = visible_; 238 // Upon receiving an instance ID from the browser process, we continue
231 create_guest_params.name = name_; 239 // the process of navigation by populating the
232 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, 240 // BrowserPluginHostMsg_CreateGuest_Params with the current state of
233 &create_guest_params.resize_guest_params); 241 // BrowserPlugin and sending a BrowserPluginHostMsg_CreateGuest to the
234 browser_plugin_manager()->Send( 242 // browser process in order to create a new guest.
235 new BrowserPluginHostMsg_CreateGuest( 243 if (!allocate_instance_id_sent_) {
236 render_view_routing_id_, 244 browser_plugin_manager()->AllocateInstanceID(this);
237 instance_id_, 245 allocate_instance_id_sent_ = true;
238 create_guest_params)); 246 }
247 return true;
239 } 248 }
240 249
241 browser_plugin_manager()->Send( 250 browser_plugin_manager()->Send(
242 new BrowserPluginHostMsg_NavigateGuest( 251 new BrowserPluginHostMsg_NavigateGuest(
243 render_view_routing_id_, 252 render_view_routing_id_,
244 instance_id_, 253 instance_id_,
245 src)); 254 src));
246 // Record that we sent a NavigateGuest message to embedder.
247 // Once this instance has navigated, the storage partition cannot be changed,
248 // so this value is used for enforcing this.
249 navigate_src_sent_ = true;
250 src_ = src;
251 return true; 255 return true;
252 } 256 }
253 257
254 void BrowserPlugin::SetAutoSizeAttribute(bool auto_size) { 258 void BrowserPlugin::SetAutoSizeAttribute(bool auto_size) {
255 if (auto_size_ == auto_size) 259 if (auto_size_ == auto_size)
256 return; 260 return;
257 auto_size_ = auto_size; 261 auto_size_ = auto_size;
258 last_view_size_ = plugin_rect_.size(); 262 last_view_size_ = plugin_rect_.size();
259 UpdateGuestAutoSizeState(); 263 UpdateGuestAutoSizeState();
260 } 264 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 return params.damage_buffer_sequence_id != 0; 311 return params.damage_buffer_sequence_id != 0;
308 } 312 }
309 313
310 bool BrowserPlugin::UsesPendingDamageBuffer( 314 bool BrowserPlugin::UsesPendingDamageBuffer(
311 const BrowserPluginMsg_UpdateRect_Params& params) { 315 const BrowserPluginMsg_UpdateRect_Params& params) {
312 if (!pending_damage_buffer_.get()) 316 if (!pending_damage_buffer_.get())
313 return false; 317 return false;
314 return damage_buffer_sequence_id_ == params.damage_buffer_sequence_id; 318 return damage_buffer_sequence_id_ == params.damage_buffer_sequence_id;
315 } 319 }
316 320
321 void BrowserPlugin::SetInstanceID(int instance_id) {
322 CHECK(instance_id != INSTANCE_ID_NONE);
323 instance_id_ = instance_id;
324 browser_plugin_manager()->AddBrowserPlugin(instance_id, this);
325
326 BrowserPluginHostMsg_CreateGuest_Params create_guest_params;
327 create_guest_params.storage_partition_id = storage_partition_id_;
328 create_guest_params.persist_storage = persist_storage_;
329 create_guest_params.focused = ShouldGuestBeFocused();
330 create_guest_params.visible = visible_;
331 create_guest_params.name = name_;
332 create_guest_params.src = src_;
333 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params,
334 &create_guest_params.resize_guest_params);
335 browser_plugin_manager()->Send(
336 new BrowserPluginHostMsg_CreateGuest(
337 render_view_routing_id_,
338 instance_id_,
339 create_guest_params));
340
341 // Record that we sent a navigation request to the browser process.
342 // Once this instance has navigated, the storage partition cannot be changed,
343 // so this value is used for enforcing this.
344 navigate_src_sent_ = true;
345 }
346
317 void BrowserPlugin::OnAdvanceFocus(int instance_id, bool reverse) { 347 void BrowserPlugin::OnAdvanceFocus(int instance_id, bool reverse) {
318 DCHECK(render_view_); 348 DCHECK(render_view_);
319 render_view_->GetWebView()->advanceFocus(reverse); 349 render_view_->GetWebView()->advanceFocus(reverse);
320 } 350 }
321 351
322 void BrowserPlugin::OnBuffersSwapped(int instance_id, 352 void BrowserPlugin::OnBuffersSwapped(int instance_id,
323 const gfx::Size& size, 353 const gfx::Size& size,
324 std::string mailbox_name, 354 std::string mailbox_name,
325 int gpu_route_id, 355 int gpu_route_id,
326 int gpu_host_id) { 356 int gpu_host_id) {
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 void* notify_data) { 1122 void* notify_data) {
1093 } 1123 }
1094 1124
1095 void BrowserPlugin::didFailLoadingFrameRequest( 1125 void BrowserPlugin::didFailLoadingFrameRequest(
1096 const WebKit::WebURL& url, 1126 const WebKit::WebURL& url,
1097 void* notify_data, 1127 void* notify_data,
1098 const WebKit::WebURLError& error) { 1128 const WebKit::WebURLError& error) {
1099 } 1129 }
1100 1130
1101 } // namespace content 1131 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/browser_plugin/browser_plugin.h ('k') | content/renderer/browser_plugin/browser_plugin_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698