| 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 #include "content/renderer/browser_plugin/browser_plugin.h" | 5 #include "content/renderer/browser_plugin/browser_plugin.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #if defined (OS_WIN) | 9 #if defined (OS_WIN) |
| 10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 const WebPluginParams& params) | 83 const WebPluginParams& params) |
| 84 : instance_id_(instance_id), | 84 : instance_id_(instance_id), |
| 85 render_view_(render_view->AsWeakPtr()), | 85 render_view_(render_view->AsWeakPtr()), |
| 86 render_view_routing_id_(render_view->GetRoutingID()), | 86 render_view_routing_id_(render_view->GetRoutingID()), |
| 87 container_(NULL), | 87 container_(NULL), |
| 88 damage_buffer_(NULL), | 88 damage_buffer_(NULL), |
| 89 sad_guest_(NULL), | 89 sad_guest_(NULL), |
| 90 guest_crashed_(false), | 90 guest_crashed_(false), |
| 91 resize_pending_(false), | 91 resize_pending_(false), |
| 92 navigate_src_sent_(false), | 92 navigate_src_sent_(false), |
| 93 auto_size_(false), |
| 94 max_height_(0), |
| 95 max_width_(0), |
| 96 min_height_(0), |
| 97 min_width_(0), |
| 93 process_id_(-1), | 98 process_id_(-1), |
| 94 persist_storage_(false), | 99 persist_storage_(false), |
| 95 content_window_routing_id_(MSG_ROUTING_NONE), | 100 content_window_routing_id_(MSG_ROUTING_NONE), |
| 96 focused_(false), | 101 focused_(false), |
| 97 visible_(true), | 102 visible_(true), |
| 98 current_nav_entry_index_(0), | 103 current_nav_entry_index_(0), |
| 99 nav_entry_count_(0) { | 104 nav_entry_count_(0) { |
| 100 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); | 105 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); |
| 101 bindings_.reset(new BrowserPluginBindings(this)); | 106 bindings_.reset(new BrowserPluginBindings(this)); |
| 102 | 107 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 114 new BrowserPluginHostMsg_PluginDestroyed( | 119 new BrowserPluginHostMsg_PluginDestroyed( |
| 115 render_view_routing_id_, | 120 render_view_routing_id_, |
| 116 instance_id_)); | 121 instance_id_)); |
| 117 } | 122 } |
| 118 | 123 |
| 119 void BrowserPlugin::Cleanup() { | 124 void BrowserPlugin::Cleanup() { |
| 120 if (damage_buffer_) | 125 if (damage_buffer_) |
| 121 FreeDamageBuffer(); | 126 FreeDamageBuffer(); |
| 122 } | 127 } |
| 123 | 128 |
| 124 std::string BrowserPlugin::GetSrcAttribute() const { | |
| 125 return src_; | |
| 126 } | |
| 127 | |
| 128 void BrowserPlugin::SetSrcAttribute(const std::string& src) { | 129 void BrowserPlugin::SetSrcAttribute(const std::string& src) { |
| 129 if (src.empty() || (src == src_ && !guest_crashed_)) | 130 if (src.empty() || (src == src_ && !guest_crashed_)) |
| 130 return; | 131 return; |
| 131 | 132 |
| 132 // If we haven't created the guest yet, do so now. We will navigate it right | 133 // If we haven't created the guest yet, do so now. We will navigate it right |
| 133 // after creation. If |src| is empty, we can delay the creation until we | 134 // after creation. If |src| is empty, we can delay the creation until we |
| 134 // acutally need it. | 135 // acutally need it. |
| 135 if (!navigate_src_sent_) { | 136 if (!navigate_src_sent_) { |
| 137 BrowserPluginHostMsg_CreateGuest_Params params; |
| 138 params.storage_partition_id = storage_partition_id_; |
| 139 params.persist_storage = persist_storage_; |
| 140 params.focused = focused_; |
| 141 params.visible = visible_; |
| 142 PopulateAutoSizeParameters(¶ms.auto_size); |
| 136 BrowserPluginManager::Get()->Send( | 143 BrowserPluginManager::Get()->Send( |
| 137 new BrowserPluginHostMsg_CreateGuest( | 144 new BrowserPluginHostMsg_CreateGuest( |
| 138 render_view_routing_id_, | 145 render_view_routing_id_, |
| 139 instance_id_, | 146 instance_id_, |
| 140 storage_partition_id_, | 147 params)); |
| 141 persist_storage_, | |
| 142 focused_, | |
| 143 visible_)); | |
| 144 } | 148 } |
| 145 | 149 |
| 146 scoped_ptr<BrowserPluginHostMsg_ResizeGuest_Params> params( | 150 scoped_ptr<BrowserPluginHostMsg_ResizeGuest_Params> params( |
| 147 GetPendingResizeParams()); | 151 GetPendingResizeParams()); |
| 148 DCHECK(!params->resize_pending); | 152 DCHECK(!params->resize_pending); |
| 149 | 153 |
| 150 BrowserPluginManager::Get()->Send( | 154 BrowserPluginManager::Get()->Send( |
| 151 new BrowserPluginHostMsg_NavigateGuest( | 155 new BrowserPluginHostMsg_NavigateGuest( |
| 152 render_view_routing_id_, | 156 render_view_routing_id_, |
| 153 instance_id_, | 157 instance_id_, |
| 154 src, | 158 src, |
| 155 *params)); | 159 *params)); |
| 156 // Record that we sent a NavigateGuest message to embedder. | 160 // Record that we sent a NavigateGuest message to embedder. |
| 157 // Once this instance has navigated, the storage partition cannot be changed, | 161 // Once this instance has navigated, the storage partition cannot be changed, |
| 158 // so this value is used for enforcing this. | 162 // so this value is used for enforcing this. |
| 159 navigate_src_sent_ = true; | 163 navigate_src_sent_ = true; |
| 160 src_ = src; | 164 src_ = src; |
| 161 } | 165 } |
| 162 | 166 |
| 167 void BrowserPlugin::SetAutoSizeAttribute(bool auto_size) { |
| 168 if (auto_size_ == auto_size) |
| 169 return; |
| 170 auto_size_ = auto_size; |
| 171 UpdateGuestAutoSizeState(); |
| 172 } |
| 173 |
| 174 void BrowserPlugin::PopulateAutoSizeParameters( |
| 175 BrowserPluginHostMsg_AutoSize_Params* params) const { |
| 176 params->enable = auto_size_; |
| 177 params->max_height = max_height_; |
| 178 params->max_width = max_width_; |
| 179 params->min_height = min_height_; |
| 180 params->min_width = min_width_; |
| 181 } |
| 182 |
| 183 void BrowserPlugin::UpdateGuestAutoSizeState() const { |
| 184 if (!navigate_src_sent_) |
| 185 return; |
| 186 BrowserPluginHostMsg_AutoSize_Params params; |
| 187 PopulateAutoSizeParameters(¶ms); |
| 188 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_SetAutoSize( |
| 189 render_view_routing_id_, |
| 190 instance_id_, |
| 191 params)); |
| 192 } |
| 193 |
| 194 void BrowserPlugin::SetMaxHeightAttribute(int max_height) { |
| 195 if (max_height_ == max_height) |
| 196 return; |
| 197 max_height_ = max_height; |
| 198 if (!auto_size_) |
| 199 return; |
| 200 UpdateGuestAutoSizeState(); |
| 201 } |
| 202 |
| 203 void BrowserPlugin::SetMaxWidthAttribute(int max_width) { |
| 204 if (max_width_ == max_width) |
| 205 return; |
| 206 max_width_ = max_width; |
| 207 if (!auto_size_) |
| 208 return; |
| 209 UpdateGuestAutoSizeState(); |
| 210 } |
| 211 |
| 212 void BrowserPlugin::SetMinHeightAttribute(int min_height) { |
| 213 if (min_height_ == min_height) |
| 214 return; |
| 215 min_height_ = min_height; |
| 216 if (!auto_size_) |
| 217 return; |
| 218 UpdateGuestAutoSizeState(); |
| 219 } |
| 220 |
| 221 void BrowserPlugin::SetMinWidthAttribute(int min_width) { |
| 222 if (min_width_ == min_width) |
| 223 return; |
| 224 min_width_ = min_width; |
| 225 if (!auto_size_) |
| 226 return; |
| 227 UpdateGuestAutoSizeState(); |
| 228 } |
| 229 |
| 163 NPObject* BrowserPlugin::GetContentWindow() const { | 230 NPObject* BrowserPlugin::GetContentWindow() const { |
| 164 if (content_window_routing_id_ == MSG_ROUTING_NONE) | 231 if (content_window_routing_id_ == MSG_ROUTING_NONE) |
| 165 return NULL; | 232 return NULL; |
| 166 RenderViewImpl* guest_render_view = static_cast<RenderViewImpl*>( | 233 RenderViewImpl* guest_render_view = static_cast<RenderViewImpl*>( |
| 167 ChildThread::current()->ResolveRoute(content_window_routing_id_)); | 234 ChildThread::current()->ResolveRoute(content_window_routing_id_)); |
| 168 if (!guest_render_view) | 235 if (!guest_render_view) |
| 169 return NULL; | 236 return NULL; |
| 170 WebKit::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); | 237 WebKit::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); |
| 171 return guest_frame->windowObject(); | 238 return guest_frame->windowObject(); |
| 172 } | 239 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 338 } |
| 272 | 339 |
| 273 bool BrowserPlugin::IsValidEvent(const std::string& event_name) { | 340 bool BrowserPlugin::IsValidEvent(const std::string& event_name) { |
| 274 return event_listener_map_.find(event_name) != event_listener_map_.end(); | 341 return event_listener_map_.find(event_name) != event_listener_map_.end(); |
| 275 } | 342 } |
| 276 | 343 |
| 277 void BrowserPlugin::TriggerEvent(const std::string& event_name, | 344 void BrowserPlugin::TriggerEvent(const std::string& event_name, |
| 278 v8::Local<v8::Object>* event) { | 345 v8::Local<v8::Object>* event) { |
| 279 WebKit::WebElement plugin = container()->element(); | 346 WebKit::WebElement plugin = container()->element(); |
| 280 | 347 |
| 281 // TODO(fsamuel): Copying the event listeners is insufficent because | |
| 282 // new persistent handles are not created when the copy constructor is | |
| 283 // called. See http://crbug.com/155044. | |
| 284 const EventListeners& listeners = event_listener_map_[event_name.c_str()]; | 348 const EventListeners& listeners = event_listener_map_[event_name.c_str()]; |
| 285 // A v8::Local copy of the listeners is created from the v8::Persistent | 349 // A v8::Local copy of the listeners is created from the v8::Persistent |
| 286 // listeners before firing them. This is to ensure that if one of these | 350 // listeners before firing them. This is to ensure that if one of these |
| 287 // listeners mutate the list of listeners (by calling | 351 // listeners mutate the list of listeners (by calling |
| 288 // addEventListener/removeEventListener), this local copy is not affected. | 352 // addEventListener/removeEventListener), this local copy is not affected. |
| 289 // This means if you mutate the list of listeners for an event X while event X | 353 // This means if you mutate the list of listeners for an event X while event X |
| 290 // is firing, the mutation is deferred until all current listeners for X have | 354 // is firing, the mutation is deferred until all current listeners for X have |
| 291 // fired. | 355 // fired. |
| 292 EventListenersLocal listeners_local; | 356 EventListenersLocal listeners_local; |
| 293 listeners_local.reserve(listeners.size()); | 357 listeners_local.reserve(listeners.size()); |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 } | 745 } |
| 682 | 746 |
| 683 void BrowserPlugin::updateGeometry( | 747 void BrowserPlugin::updateGeometry( |
| 684 const WebRect& window_rect, | 748 const WebRect& window_rect, |
| 685 const WebRect& clip_rect, | 749 const WebRect& clip_rect, |
| 686 const WebVector<WebRect>& cut_outs_rects, | 750 const WebVector<WebRect>& cut_outs_rects, |
| 687 bool is_visible) { | 751 bool is_visible) { |
| 688 int old_width = width(); | 752 int old_width = width(); |
| 689 int old_height = height(); | 753 int old_height = height(); |
| 690 plugin_rect_ = window_rect; | 754 plugin_rect_ = window_rect; |
| 691 if (old_width == window_rect.width && | 755 if (auto_size_ || (old_width == window_rect.width && |
| 692 old_height == window_rect.height) { | 756 old_height == window_rect.height)) { |
| 693 return; | 757 return; |
| 694 } | 758 } |
| 695 | 759 |
| 696 const size_t stride = skia::PlatformCanvas::StrideForWidth(window_rect.width); | 760 const size_t stride = skia::PlatformCanvas::StrideForWidth(window_rect.width); |
| 697 // Make sure the size of the damage buffer is at least four bytes so that we | 761 // Make sure the size of the damage buffer is at least four bytes so that we |
| 698 // can fit in a magic word to verify that the memory is shared correctly. | 762 // can fit in a magic word to verify that the memory is shared correctly. |
| 699 size_t size = | 763 size_t size = |
| 700 std::max(sizeof(unsigned int), | 764 std::max(sizeof(unsigned int), |
| 701 static_cast<size_t>(window_rect.height * | 765 static_cast<size_t>(window_rect.height * |
| 702 stride * | 766 stride * |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 void* notify_data) { | 954 void* notify_data) { |
| 891 } | 955 } |
| 892 | 956 |
| 893 void BrowserPlugin::didFailLoadingFrameRequest( | 957 void BrowserPlugin::didFailLoadingFrameRequest( |
| 894 const WebKit::WebURL& url, | 958 const WebKit::WebURL& url, |
| 895 void* notify_data, | 959 void* notify_data, |
| 896 const WebKit::WebURLError& error) { | 960 const WebKit::WebURLError& error) { |
| 897 } | 961 } |
| 898 | 962 |
| 899 } // namespace content | 963 } // namespace content |
| OLD | NEW |