| 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_impl.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" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "content/common/browser_plugin_messages.h" | 12 #include "content/common/browser_plugin_messages.h" |
| 13 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
| 14 #include "content/public/common/content_client.h" | 14 #include "content/public/common/content_client.h" |
| 15 #include "content/public/renderer/browser_plugin/browser_plugin_observer.h" |
| 15 #include "content/public/renderer/content_renderer_client.h" | 16 #include "content/public/renderer/content_renderer_client.h" |
| 16 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" | 17 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" |
| 17 #include "content/renderer/browser_plugin/browser_plugin_compositing_helper.h" | 18 #include "content/renderer/browser_plugin/browser_plugin_compositing_helper.h" |
| 18 #include "content/renderer/browser_plugin/browser_plugin_constants.h" | 19 #include "content/renderer/browser_plugin/browser_plugin_constants.h" |
| 19 #include "content/renderer/browser_plugin/browser_plugin_manager.h" | 20 #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
| 20 #include "content/renderer/render_process_impl.h" | 21 #include "content/renderer/render_process_impl.h" |
| 21 #include "content/renderer/render_thread_impl.h" | 22 #include "content/renderer/render_thread_impl.h" |
| 22 #include "content/renderer/v8_value_converter_impl.h" | 23 #include "content/renderer/v8_value_converter_impl.h" |
| 23 #include "skia/ext/platform_canvas.h" | 24 #include "skia/ext/platform_canvas.h" |
| 24 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" | 25 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 66 } |
| 66 NOTREACHED() << "Unknown Termination Status."; | 67 NOTREACHED() << "Unknown Termination Status."; |
| 67 return "unknown"; | 68 return "unknown"; |
| 68 } | 69 } |
| 69 | 70 |
| 70 static std::string GetInternalEventName(const char* event_name) { | 71 static std::string GetInternalEventName(const char* event_name) { |
| 71 return base::StringPrintf("-internal-%s", event_name); | 72 return base::StringPrintf("-internal-%s", event_name); |
| 72 } | 73 } |
| 73 } // namespace | 74 } // namespace |
| 74 | 75 |
| 75 BrowserPlugin::BrowserPlugin( | 76 BrowserPluginImpl::BrowserPluginImpl( |
| 76 RenderViewImpl* render_view, | 77 RenderViewImpl* render_view, |
| 77 WebKit::WebFrame* frame, | 78 WebKit::WebFrame* frame, |
| 78 const WebPluginParams& params) | 79 const WebPluginParams& params) |
| 79 : instance_id_(browser_plugin::kInstanceIDNone), | 80 : instance_id_(browser_plugin::kInstanceIDNone), |
| 80 render_view_(render_view->AsWeakPtr()), | 81 render_view_(render_view->AsWeakPtr()), |
| 81 render_view_routing_id_(render_view->GetRoutingID()), | 82 render_view_routing_id_(render_view->GetRoutingID()), |
| 82 container_(NULL), | 83 container_(NULL), |
| 83 damage_buffer_sequence_id_(0), | 84 damage_buffer_sequence_id_(0), |
| 84 resize_ack_received_(true), | 85 resize_ack_received_(true), |
| 85 sad_guest_(NULL), | 86 sad_guest_(NULL), |
| 86 guest_crashed_(false), | 87 guest_crashed_(false), |
| 87 navigate_src_sent_(false), | 88 navigate_src_sent_(false), |
| 88 auto_size_ack_pending_(false), | 89 auto_size_ack_pending_(false), |
| 89 guest_process_id_(-1), | 90 guest_process_id_(-1), |
| 90 guest_route_id_(-1), | 91 guest_route_id_(-1), |
| 91 persist_storage_(false), | 92 persist_storage_(false), |
| 92 valid_partition_id_(true), | 93 valid_partition_id_(true), |
| 93 content_window_routing_id_(MSG_ROUTING_NONE), | 94 content_window_routing_id_(MSG_ROUTING_NONE), |
| 94 plugin_focused_(false), | 95 plugin_focused_(false), |
| 95 visible_(true), | 96 visible_(true), |
| 96 size_changed_in_flight_(false), | 97 size_changed_in_flight_(false), |
| 97 allocate_instance_id_sent_(false), | 98 allocate_instance_id_sent_(false), |
| 98 browser_plugin_manager_(render_view->browser_plugin_manager()), | 99 browser_plugin_manager_(render_view->browser_plugin_manager()), |
| 99 current_nav_entry_index_(0), | 100 current_nav_entry_index_(0), |
| 100 nav_entry_count_(0), | 101 nav_entry_count_(0), |
| 101 compositing_enabled_(false) { | 102 compositing_enabled_(false) { |
| 102 bindings_.reset(new BrowserPluginBindings(this)); | 103 bindings_.reset(new BrowserPluginBindings(this)); |
| 104 GetContentClient()->renderer()->BrowserPluginCreated(this); |
| 103 } | 105 } |
| 104 | 106 |
| 105 BrowserPlugin::~BrowserPlugin() { | 107 BrowserPluginImpl::~BrowserPluginImpl() { |
| 106 // If the BrowserPlugin has never navigated then the browser process and | 108 // If the BrowserPlugin has never navigated then the browser process and |
| 107 // BrowserPluginManager don't know about it and so there is nothing to do | 109 // BrowserPluginManager don't know about it and so there is nothing to do |
| 108 // here. | 110 // here. |
| 109 if (!navigate_src_sent_) | 111 if (!navigate_src_sent_) |
| 110 return; | 112 return; |
| 111 browser_plugin_manager()->RemoveBrowserPlugin(instance_id_); | 113 browser_plugin_manager()->RemoveBrowserPlugin(instance_id_); |
| 112 browser_plugin_manager()->Send( | 114 browser_plugin_manager()->Send( |
| 113 new BrowserPluginHostMsg_PluginDestroyed(render_view_routing_id_, | 115 new BrowserPluginHostMsg_PluginDestroyed(render_view_routing_id_, |
| 114 instance_id_)); | 116 instance_id_)); |
| 115 } | 117 } |
| 116 | 118 |
| 117 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { | 119 void BrowserPluginImpl::AddObserver(BrowserPluginObserver* observer) { |
| 120 observers_.AddObserver(observer); |
| 121 } |
| 122 |
| 123 void BrowserPluginImpl::RemoveObserver(BrowserPluginObserver* observer) { |
| 124 observers_.RemoveObserver(observer); |
| 125 } |
| 126 |
| 127 bool BrowserPluginImpl::OnMessageReceived(const IPC::Message& message) { |
| 118 bool handled = true; | 128 bool handled = true; |
| 119 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) | 129 IPC_BEGIN_MESSAGE_MAP(BrowserPluginImpl, message) |
| 120 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) | 130 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) |
| 121 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) | 131 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) |
| 132 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ForwardMessage, OnForwardMessage) |
| 122 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, | 133 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, |
| 123 OnGuestContentWindowReady) | 134 OnGuestContentWindowReady) |
| 124 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) | 135 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) |
| 125 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestResponsive, OnGuestResponsive) | 136 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestResponsive, OnGuestResponsive) |
| 126 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestUnresponsive, OnGuestUnresponsive) | 137 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestUnresponsive, OnGuestUnresponsive) |
| 127 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadAbort, OnLoadAbort) | 138 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadAbort, OnLoadAbort) |
| 128 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadCommit, OnLoadCommit) | 139 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadCommit, OnLoadCommit) |
| 129 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadRedirect, OnLoadRedirect) | 140 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadRedirect, OnLoadRedirect) |
| 130 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStart, OnLoadStart) | 141 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStart, OnLoadStart) |
| 131 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStop, OnLoadStop) | 142 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStop, OnLoadStop) |
| 132 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) | 143 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) |
| 133 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, | 144 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, |
| 134 OnShouldAcceptTouchEvents) | 145 OnShouldAcceptTouchEvents) |
| 135 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdatedName, OnUpdatedName) | 146 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdatedName, OnUpdatedName) |
| 136 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect) | 147 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect) |
| 137 IPC_MESSAGE_UNHANDLED(handled = false) | 148 IPC_MESSAGE_UNHANDLED(handled = false) |
| 138 IPC_END_MESSAGE_MAP() | 149 IPC_END_MESSAGE_MAP() |
| 139 return handled; | 150 return handled; |
| 140 } | 151 } |
| 141 | 152 |
| 142 void BrowserPlugin::UpdateDOMAttribute(const std::string& attribute_name, | 153 std::string BrowserPluginImpl::GetNameAttribute() const { |
| 143 const std::string& attribute_value) { | |
| 144 if (!container()) | |
| 145 return; | |
| 146 | |
| 147 WebKit::WebElement element = container()->element(); | |
| 148 WebKit::WebString web_attribute_name = | |
| 149 WebKit::WebString::fromUTF8(attribute_name); | |
| 150 if (!HasDOMAttribute(attribute_name) || | |
| 151 (std::string(element.getAttribute(web_attribute_name).utf8()) != | |
| 152 attribute_value)) { | |
| 153 element.setAttribute(web_attribute_name, | |
| 154 WebKit::WebString::fromUTF8(attribute_value)); | |
| 155 } | |
| 156 } | |
| 157 | |
| 158 void BrowserPlugin::RemoveDOMAttribute(const std::string& attribute_name) { | |
| 159 if (!container()) | |
| 160 return; | |
| 161 | |
| 162 container()->element().removeAttribute( | |
| 163 WebKit::WebString::fromUTF8(attribute_name)); | |
| 164 } | |
| 165 | |
| 166 std::string BrowserPlugin::GetDOMAttributeValue( | |
| 167 const std::string& attribute_name) const { | |
| 168 if (!container()) | |
| 169 return ""; | |
| 170 | |
| 171 return container()->element().getAttribute( | |
| 172 WebKit::WebString::fromUTF8(attribute_name)).utf8(); | |
| 173 } | |
| 174 | |
| 175 bool BrowserPlugin::HasDOMAttribute(const std::string& attribute_name) const { | |
| 176 if (!container()) | |
| 177 return false; | |
| 178 | |
| 179 return container()->element().hasAttribute( | |
| 180 WebKit::WebString::fromUTF8(attribute_name)); | |
| 181 } | |
| 182 | |
| 183 std::string BrowserPlugin::GetNameAttribute() const { | |
| 184 return GetDOMAttributeValue(browser_plugin::kAttributeName); | 154 return GetDOMAttributeValue(browser_plugin::kAttributeName); |
| 185 } | 155 } |
| 186 | 156 |
| 187 std::string BrowserPlugin::GetSrcAttribute() const { | 157 std::string BrowserPluginImpl::GetSrcAttribute() const { |
| 188 return GetDOMAttributeValue(browser_plugin::kAttributeSrc); | 158 return GetDOMAttributeValue(browser_plugin::kAttributeSrc); |
| 189 } | 159 } |
| 190 | 160 |
| 191 bool BrowserPlugin::GetAutoSizeAttribute() const { | 161 bool BrowserPluginImpl::GetAutoSizeAttribute() const { |
| 192 return HasDOMAttribute(browser_plugin::kAttributeAutoSize); | 162 return HasDOMAttribute(browser_plugin::kAttributeAutoSize); |
| 193 } | 163 } |
| 194 | 164 |
| 195 int BrowserPlugin::GetMaxHeightAttribute() const { | 165 int BrowserPluginImpl::GetMaxHeightAttribute() const { |
| 196 int max_height; | 166 int max_height; |
| 197 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMaxHeight), | 167 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMaxHeight), |
| 198 &max_height); | 168 &max_height); |
| 199 return max_height; | 169 return max_height; |
| 200 } | 170 } |
| 201 | 171 |
| 202 int BrowserPlugin::GetMaxWidthAttribute() const { | 172 int BrowserPluginImpl::GetMaxWidthAttribute() const { |
| 203 int max_width; | 173 int max_width; |
| 204 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMaxWidth), | 174 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMaxWidth), |
| 205 &max_width); | 175 &max_width); |
| 206 return max_width; | 176 return max_width; |
| 207 } | 177 } |
| 208 | 178 |
| 209 int BrowserPlugin::GetMinHeightAttribute() const { | 179 int BrowserPluginImpl::GetMinHeightAttribute() const { |
| 210 int min_height; | 180 int min_height; |
| 211 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMinHeight), | 181 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMinHeight), |
| 212 &min_height); | 182 &min_height); |
| 213 return min_height; | 183 return min_height; |
| 214 } | 184 } |
| 215 | 185 |
| 216 int BrowserPlugin::GetMinWidthAttribute() const { | 186 int BrowserPluginImpl::GetMinWidthAttribute() const { |
| 217 int min_width; | 187 int min_width; |
| 218 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMinWidth), | 188 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMinWidth), |
| 219 &min_width); | 189 &min_width); |
| 220 return min_width; | 190 return min_width; |
| 221 } | 191 } |
| 222 | 192 |
| 223 int BrowserPlugin::GetAdjustedMaxHeight() const { | 193 int BrowserPluginImpl::GetAdjustedMaxHeight() const { |
| 224 int max_height = GetMaxHeightAttribute(); | 194 int max_height = GetMaxHeightAttribute(); |
| 225 return max_height ? max_height : height(); | 195 return max_height ? max_height : height(); |
| 226 } | 196 } |
| 227 | 197 |
| 228 int BrowserPlugin::GetAdjustedMaxWidth() const { | 198 int BrowserPluginImpl::GetAdjustedMaxWidth() const { |
| 229 int max_width = GetMaxWidthAttribute(); | 199 int max_width = GetMaxWidthAttribute(); |
| 230 return max_width ? max_width : width(); | 200 return max_width ? max_width : width(); |
| 231 } | 201 } |
| 232 | 202 |
| 233 int BrowserPlugin::GetAdjustedMinHeight() const { | 203 int BrowserPluginImpl::GetAdjustedMinHeight() const { |
| 234 int min_height = GetMinHeightAttribute(); | 204 int min_height = GetMinHeightAttribute(); |
| 235 // FrameView.cpp does not allow this value to be <= 0, so when the value is | 205 // FrameView.cpp does not allow this value to be <= 0, so when the value is |
| 236 // unset (or set to 0), we set it to the container size. | 206 // unset (or set to 0), we set it to the container size. |
| 237 min_height = min_height ? min_height : height(); | 207 min_height = min_height ? min_height : height(); |
| 238 // For autosize, minHeight should not be bigger than maxHeight. | 208 // For autosize, minHeight should not be bigger than maxHeight. |
| 239 return std::min(min_height, GetAdjustedMaxHeight()); | 209 return std::min(min_height, GetAdjustedMaxHeight()); |
| 240 } | 210 } |
| 241 | 211 |
| 242 int BrowserPlugin::GetAdjustedMinWidth() const { | 212 int BrowserPluginImpl::GetAdjustedMinWidth() const { |
| 243 int min_width = GetMinWidthAttribute(); | 213 int min_width = GetMinWidthAttribute(); |
| 244 // FrameView.cpp does not allow this value to be <= 0, so when the value is | 214 // FrameView.cpp does not allow this value to be <= 0, so when the value is |
| 245 // unset (or set to 0), we set it to the container size. | 215 // unset (or set to 0), we set it to the container size. |
| 246 min_width = min_width ? min_width : width(); | 216 min_width = min_width ? min_width : width(); |
| 247 // For autosize, minWidth should not be bigger than maxWidth. | 217 // For autosize, minWidth should not be bigger than maxWidth. |
| 248 return std::min(min_width, GetAdjustedMaxWidth()); | 218 return std::min(min_width, GetAdjustedMaxWidth()); |
| 249 } | 219 } |
| 250 | 220 |
| 251 std::string BrowserPlugin::GetPartitionAttribute() const { | 221 std::string BrowserPluginImpl::GetPartitionAttribute() const { |
| 252 return GetDOMAttributeValue(browser_plugin::kAttributePartition); | 222 return GetDOMAttributeValue(browser_plugin::kAttributePartition); |
| 253 } | 223 } |
| 254 | 224 |
| 255 void BrowserPlugin::ParseNameAttribute() { | 225 void BrowserPluginImpl::ParseNameAttribute() { |
| 256 if (!navigate_src_sent_) | 226 if (!navigate_src_sent_) |
| 257 return; | 227 return; |
| 258 browser_plugin_manager()->Send( | 228 browser_plugin_manager()->Send( |
| 259 new BrowserPluginHostMsg_SetName(render_view_routing_id_, | 229 new BrowserPluginHostMsg_SetName(render_view_routing_id_, |
| 260 instance_id_, | 230 instance_id_, |
| 261 GetNameAttribute())); | 231 GetNameAttribute())); |
| 262 } | 232 } |
| 263 | 233 |
| 264 bool BrowserPlugin::ParseSrcAttribute(std::string* error_message) { | 234 bool BrowserPluginImpl::ParseSrcAttribute(std::string* error_message) { |
| 265 if (!valid_partition_id_) { | 235 if (!valid_partition_id_) { |
| 266 *error_message = browser_plugin::kErrorInvalidPartition; | 236 *error_message = browser_plugin::kErrorInvalidPartition; |
| 267 return false; | 237 return false; |
| 268 } | 238 } |
| 269 std::string src = GetSrcAttribute(); | 239 std::string src = GetSrcAttribute(); |
| 270 if (src.empty()) | 240 if (src.empty()) |
| 271 return true; | 241 return true; |
| 272 | 242 |
| 273 // If we haven't created the guest yet, do so now. We will navigate it right | 243 // If we haven't created the guest yet, do so now. We will navigate it right |
| 274 // after creation. If |src| is empty, we can delay the creation until we | 244 // after creation. If |src| is empty, we can delay the creation until we |
| (...skipping 15 matching lines...) Expand all Loading... |
| 290 return true; | 260 return true; |
| 291 } | 261 } |
| 292 | 262 |
| 293 browser_plugin_manager()->Send( | 263 browser_plugin_manager()->Send( |
| 294 new BrowserPluginHostMsg_NavigateGuest(render_view_routing_id_, | 264 new BrowserPluginHostMsg_NavigateGuest(render_view_routing_id_, |
| 295 instance_id_, | 265 instance_id_, |
| 296 src)); | 266 src)); |
| 297 return true; | 267 return true; |
| 298 } | 268 } |
| 299 | 269 |
| 300 void BrowserPlugin::ParseAutoSizeAttribute() { | 270 void BrowserPluginImpl::ParseAutoSizeAttribute() { |
| 301 auto_size_ack_pending_ = true; | 271 auto_size_ack_pending_ = true; |
| 302 last_view_size_ = plugin_rect_.size(); | 272 last_view_size_ = plugin_rect_.size(); |
| 303 UpdateGuestAutoSizeState(GetAutoSizeAttribute()); | 273 UpdateGuestAutoSizeState(GetAutoSizeAttribute()); |
| 304 } | 274 } |
| 305 | 275 |
| 306 void BrowserPlugin::PopulateAutoSizeParameters( | 276 void BrowserPluginImpl::PopulateAutoSizeParameters( |
| 307 BrowserPluginHostMsg_AutoSize_Params* params, bool current_auto_size) { | 277 BrowserPluginHostMsg_AutoSize_Params* params, bool current_auto_size) { |
| 308 params->enable = current_auto_size; | 278 params->enable = current_auto_size; |
| 309 // No need to populate the params if autosize is off. | 279 // No need to populate the params if autosize is off. |
| 310 if (current_auto_size) { | 280 if (current_auto_size) { |
| 311 params->max_size = gfx::Size(GetAdjustedMaxWidth(), GetAdjustedMaxHeight()); | 281 params->max_size = gfx::Size(GetAdjustedMaxWidth(), GetAdjustedMaxHeight()); |
| 312 params->min_size = gfx::Size(GetAdjustedMinWidth(), GetAdjustedMinHeight()); | 282 params->min_size = gfx::Size(GetAdjustedMinWidth(), GetAdjustedMinHeight()); |
| 313 } | 283 } |
| 314 } | 284 } |
| 315 | 285 |
| 316 void BrowserPlugin::UpdateGuestAutoSizeState(bool current_auto_size) { | 286 void BrowserPluginImpl::UpdateGuestAutoSizeState(bool current_auto_size) { |
| 317 // If we haven't yet heard back from the guest about the last resize request, | 287 // If we haven't yet heard back from the guest about the last resize request, |
| 318 // then we don't issue another request until we do in | 288 // then we don't issue another request until we do in |
| 319 // BrowserPlugin::UpdateRect. | 289 // BrowserPluginImpl::UpdateRect. |
| 320 if (!navigate_src_sent_ || !resize_ack_received_) | 290 if (!navigate_src_sent_ || !resize_ack_received_) |
| 321 return; | 291 return; |
| 322 BrowserPluginHostMsg_AutoSize_Params auto_size_params; | 292 BrowserPluginHostMsg_AutoSize_Params auto_size_params; |
| 323 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; | 293 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; |
| 324 if (current_auto_size) { | 294 if (current_auto_size) { |
| 325 GetDamageBufferWithSizeParams(&auto_size_params, &resize_guest_params); | 295 GetDamageBufferWithSizeParams(&auto_size_params, &resize_guest_params); |
| 326 } else { | 296 } else { |
| 327 GetDamageBufferWithSizeParams(NULL, &resize_guest_params); | 297 GetDamageBufferWithSizeParams(NULL, &resize_guest_params); |
| 328 } | 298 } |
| 329 resize_ack_received_ = false; | 299 resize_ack_received_ = false; |
| 330 browser_plugin_manager()->Send( | 300 browser_plugin_manager()->Send( |
| 331 new BrowserPluginHostMsg_SetAutoSize(render_view_routing_id_, | 301 new BrowserPluginHostMsg_SetAutoSize(render_view_routing_id_, |
| 332 instance_id_, | 302 instance_id_, |
| 333 auto_size_params, | 303 auto_size_params, |
| 334 resize_guest_params)); | 304 resize_guest_params)); |
| 335 } | 305 } |
| 336 | 306 |
| 337 void BrowserPlugin::SizeChangedDueToAutoSize(const gfx::Size& old_view_size) { | 307 void BrowserPluginImpl::SizeChangedDueToAutoSize( |
| 308 const gfx::Size& old_view_size) { |
| 338 size_changed_in_flight_ = false; | 309 size_changed_in_flight_ = false; |
| 339 | 310 |
| 340 std::map<std::string, base::Value*> props; | 311 std::map<std::string, base::Value*> props; |
| 341 props[browser_plugin::kOldHeight] = | 312 props[browser_plugin::kOldHeight] = |
| 342 new base::FundamentalValue(old_view_size.height()); | 313 new base::FundamentalValue(old_view_size.height()); |
| 343 props[browser_plugin::kOldWidth] = | 314 props[browser_plugin::kOldWidth] = |
| 344 new base::FundamentalValue(old_view_size.width()); | 315 new base::FundamentalValue(old_view_size.width()); |
| 345 props[browser_plugin::kNewHeight] = | 316 props[browser_plugin::kNewHeight] = |
| 346 new base::FundamentalValue(last_view_size_.height()); | 317 new base::FundamentalValue(last_view_size_.height()); |
| 347 props[browser_plugin::kNewWidth] = | 318 props[browser_plugin::kNewWidth] = |
| 348 new base::FundamentalValue(last_view_size_.width()); | 319 new base::FundamentalValue(last_view_size_.width()); |
| 349 TriggerEvent(browser_plugin::kEventSizeChanged, &props); | 320 TriggerEvent(browser_plugin::kEventSizeChanged, &props); |
| 350 } | 321 } |
| 351 | 322 |
| 352 // static | 323 // static |
| 353 bool BrowserPlugin::UsesDamageBuffer( | 324 bool BrowserPluginImpl::UsesDamageBuffer( |
| 354 const BrowserPluginMsg_UpdateRect_Params& params) { | 325 const BrowserPluginMsg_UpdateRect_Params& params) { |
| 355 return params.damage_buffer_sequence_id != 0 || params.needs_ack; | 326 return params.damage_buffer_sequence_id != 0 || params.needs_ack; |
| 356 } | 327 } |
| 357 | 328 |
| 358 bool BrowserPlugin::UsesPendingDamageBuffer( | 329 bool BrowserPluginImpl::UsesPendingDamageBuffer( |
| 359 const BrowserPluginMsg_UpdateRect_Params& params) { | 330 const BrowserPluginMsg_UpdateRect_Params& params) { |
| 360 if (!pending_damage_buffer_.get()) | 331 if (!pending_damage_buffer_.get()) |
| 361 return false; | 332 return false; |
| 362 return damage_buffer_sequence_id_ == params.damage_buffer_sequence_id; | 333 return damage_buffer_sequence_id_ == params.damage_buffer_sequence_id; |
| 363 } | 334 } |
| 364 | 335 |
| 365 void BrowserPlugin::SetInstanceID(int instance_id) { | 336 void BrowserPluginImpl::SetInstanceID(int instance_id) { |
| 366 CHECK(instance_id != browser_plugin::kInstanceIDNone); | 337 CHECK(instance_id != browser_plugin::kInstanceIDNone); |
| 367 instance_id_ = instance_id; | 338 instance_id_ = instance_id; |
| 368 browser_plugin_manager()->AddBrowserPlugin(instance_id, this); | 339 browser_plugin_manager()->AddBrowserPlugin(instance_id, this); |
| 369 | 340 |
| 370 BrowserPluginHostMsg_CreateGuest_Params create_guest_params; | 341 BrowserPluginHostMsg_CreateGuest_Params create_guest_params; |
| 371 create_guest_params.storage_partition_id = storage_partition_id_; | 342 create_guest_params.storage_partition_id = storage_partition_id_; |
| 372 create_guest_params.persist_storage = persist_storage_; | 343 create_guest_params.persist_storage = persist_storage_; |
| 373 create_guest_params.focused = ShouldGuestBeFocused(); | 344 create_guest_params.focused = ShouldGuestBeFocused(); |
| 374 create_guest_params.visible = visible_; | 345 create_guest_params.visible = visible_; |
| 375 create_guest_params.name = GetNameAttribute(); | 346 create_guest_params.name = GetNameAttribute(); |
| 376 create_guest_params.src = GetSrcAttribute(); | 347 create_guest_params.src = GetSrcAttribute(); |
| 377 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, | 348 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, |
| 378 &create_guest_params.resize_guest_params); | 349 &create_guest_params.resize_guest_params); |
| 379 browser_plugin_manager()->Send( | 350 browser_plugin_manager()->Send( |
| 380 new BrowserPluginHostMsg_CreateGuest(render_view_routing_id_, | 351 new BrowserPluginHostMsg_CreateGuest(render_view_routing_id_, |
| 381 instance_id_, | 352 instance_id_, |
| 382 create_guest_params)); | 353 create_guest_params)); |
| 383 | 354 |
| 384 // Record that we sent a navigation request to the browser process. | 355 // Record that we sent a navigation request to the browser process. |
| 385 // Once this instance has navigated, the storage partition cannot be changed, | 356 // Once this instance has navigated, the storage partition cannot be changed, |
| 386 // so this value is used for enforcing this. | 357 // so this value is used for enforcing this. |
| 387 navigate_src_sent_ = true; | 358 navigate_src_sent_ = true; |
| 388 } | 359 } |
| 389 | 360 |
| 390 void BrowserPlugin::OnAdvanceFocus(int instance_id, bool reverse) { | 361 void BrowserPluginImpl::OnAdvanceFocus(int instance_id, bool reverse) { |
| 391 DCHECK(render_view_); | 362 DCHECK(render_view_); |
| 392 render_view_->GetWebView()->advanceFocus(reverse); | 363 render_view_->GetWebView()->advanceFocus(reverse); |
| 393 } | 364 } |
| 394 | 365 |
| 395 void BrowserPlugin::OnBuffersSwapped(int instance_id, | 366 void BrowserPluginImpl::OnBuffersSwapped(int instance_id, |
| 396 const gfx::Size& size, | 367 const gfx::Size& size, |
| 397 std::string mailbox_name, | 368 std::string mailbox_name, |
| 398 int gpu_route_id, | 369 int gpu_route_id, |
| 399 int gpu_host_id) { | 370 int gpu_host_id) { |
| 400 DCHECK(instance_id == instance_id_); | 371 DCHECK(instance_id == instance_id_); |
| 401 EnableCompositing(true); | 372 EnableCompositing(true); |
| 402 | 373 |
| 403 compositing_helper_->OnBuffersSwapped(size, | 374 compositing_helper_->OnBuffersSwapped(size, |
| 404 mailbox_name, | 375 mailbox_name, |
| 405 gpu_route_id, | 376 gpu_route_id, |
| 406 gpu_host_id); | 377 gpu_host_id); |
| 407 } | 378 } |
| 408 | 379 |
| 409 void BrowserPlugin::OnGuestContentWindowReady(int instance_id, | 380 void BrowserPluginImpl::OnForwardMessage(int instance_id, |
| 410 int content_window_routing_id) { | 381 const IPC::Message& msg) { |
| 382 if (!observers_.might_have_observers()) |
| 383 return; |
| 384 ObserverListBase<BrowserPluginObserver>::Iterator it(observers_); |
| 385 BrowserPluginObserver* observer; |
| 386 while ((observer = it.GetNext()) != NULL) { |
| 387 if (observer->OnMessageReceived(msg)) |
| 388 return; |
| 389 } |
| 390 } |
| 391 |
| 392 void BrowserPluginImpl::OnGuestContentWindowReady( |
| 393 int instance_id, |
| 394 int content_window_routing_id) { |
| 411 DCHECK(content_window_routing_id != MSG_ROUTING_NONE); | 395 DCHECK(content_window_routing_id != MSG_ROUTING_NONE); |
| 412 content_window_routing_id_ = content_window_routing_id; | 396 content_window_routing_id_ = content_window_routing_id; |
| 413 } | 397 } |
| 414 | 398 |
| 415 void BrowserPlugin::OnGuestGone(int instance_id, int process_id, int status) { | 399 void BrowserPluginImpl::OnGuestGone(int instance_id, |
| 400 int process_id, |
| 401 int status) { |
| 416 // Set the BrowserPlugin in a crashed state before firing event listeners so | 402 // Set the BrowserPlugin in a crashed state before firing event listeners so |
| 417 // that operations on the BrowserPlugin within listeners are aware that | 403 // that operations on the BrowserPlugin within listeners are aware that |
| 418 // BrowserPlugin is in a crashed state. | 404 // BrowserPlugin is in a crashed state. |
| 419 guest_crashed_ = true; | 405 guest_crashed_ = true; |
| 420 | 406 |
| 421 // We fire the event listeners before painting the sad graphic to give the | 407 // We fire the event listeners before painting the sad graphic to give the |
| 422 // developer an opportunity to display an alternative overlay image on crash. | 408 // developer an opportunity to display an alternative overlay image on crash. |
| 423 std::string termination_status = TerminationStatusToString( | 409 std::string termination_status = TerminationStatusToString( |
| 424 static_cast<base::TerminationStatus>(status)); | 410 static_cast<base::TerminationStatus>(status)); |
| 425 std::map<std::string, base::Value*> props; | 411 std::map<std::string, base::Value*> props; |
| 426 props[browser_plugin::kProcessId] = new base::FundamentalValue(process_id); | 412 props[browser_plugin::kProcessId] = new base::FundamentalValue(process_id); |
| 427 props[browser_plugin::kReason] = new base::StringValue(termination_status); | 413 props[browser_plugin::kReason] = new base::StringValue(termination_status); |
| 428 | 414 |
| 429 // Event listeners may remove the BrowserPlugin from the document. If that | 415 // Event listeners may remove the BrowserPlugin from the document. If that |
| 430 // happens, the BrowserPlugin will be scheduled for later deletion (see | 416 // happens, the BrowserPlugin will be scheduled for later deletion (see |
| 431 // BrowserPlugin::destroy()). That will clear the container_ reference, | 417 // BrowserPluginImpl::destroy()). That will clear the container_ reference, |
| 432 // but leave other member variables valid below. | 418 // but leave other member variables valid below. |
| 433 TriggerEvent(browser_plugin::kEventExit, &props); | 419 TriggerEvent(browser_plugin::kEventExit, &props); |
| 434 | 420 |
| 435 // We won't paint the contents of the current backing store again so we might | 421 // We won't paint the contents of the current backing store again so we might |
| 436 // as well toss it out and save memory. | 422 // as well toss it out and save memory. |
| 437 backing_store_.reset(); | 423 backing_store_.reset(); |
| 438 // If the BrowserPlugin is scheduled to be deleted, then container_ will be | 424 // If the BrowserPlugin is scheduled to be deleted, then container_ will be |
| 439 // NULL so we shouldn't attempt to access it. | 425 // NULL so we shouldn't attempt to access it. |
| 440 if (container_) | 426 if (container_) |
| 441 container_->invalidate(); | 427 container_->invalidate(); |
| 442 // Turn off compositing so we can display the sad graphic. | 428 // Turn off compositing so we can display the sad graphic. |
| 443 EnableCompositing(false); | 429 EnableCompositing(false); |
| 444 } | 430 } |
| 445 | 431 |
| 446 void BrowserPlugin::OnGuestResponsive(int instance_id, int process_id) { | 432 void BrowserPluginImpl::OnGuestResponsive(int instance_id, int process_id) { |
| 447 std::map<std::string, base::Value*> props; | 433 std::map<std::string, base::Value*> props; |
| 448 props[browser_plugin::kProcessId] = new base::FundamentalValue(process_id); | 434 props[browser_plugin::kProcessId] = new base::FundamentalValue(process_id); |
| 449 TriggerEvent(browser_plugin::kEventResponsive, &props); | 435 TriggerEvent(browser_plugin::kEventResponsive, &props); |
| 450 } | 436 } |
| 451 | 437 |
| 452 void BrowserPlugin::OnGuestUnresponsive(int instance_id, int process_id) { | 438 void BrowserPluginImpl::OnGuestUnresponsive(int instance_id, int process_id) { |
| 453 std::map<std::string, base::Value*> props; | 439 std::map<std::string, base::Value*> props; |
| 454 props[browser_plugin::kProcessId] = new base::FundamentalValue(process_id); | 440 props[browser_plugin::kProcessId] = new base::FundamentalValue(process_id); |
| 455 TriggerEvent(browser_plugin::kEventUnresponsive, &props); | 441 TriggerEvent(browser_plugin::kEventUnresponsive, &props); |
| 456 } | 442 } |
| 457 | 443 |
| 458 void BrowserPlugin::OnLoadAbort(int instance_id, | 444 void BrowserPluginImpl::OnLoadAbort(int instance_id, |
| 459 const GURL& url, | 445 const GURL& url, |
| 460 bool is_top_level, | 446 bool is_top_level, |
| 461 const std::string& type) { | 447 const std::string& type) { |
| 462 std::map<std::string, base::Value*> props; | 448 std::map<std::string, base::Value*> props; |
| 463 props[browser_plugin::kURL] = new base::StringValue(url.spec()); | 449 props[browser_plugin::kURL] = new base::StringValue(url.spec()); |
| 464 props[browser_plugin::kIsTopLevel] = new base::FundamentalValue(is_top_level); | 450 props[browser_plugin::kIsTopLevel] = new base::FundamentalValue(is_top_level); |
| 465 props[browser_plugin::kReason] = new base::StringValue(type); | 451 props[browser_plugin::kReason] = new base::StringValue(type); |
| 466 TriggerEvent(browser_plugin::kEventLoadAbort, &props); | 452 TriggerEvent(browser_plugin::kEventLoadAbort, &props); |
| 467 } | 453 } |
| 468 | 454 |
| 469 void BrowserPlugin::OnLoadCommit( | 455 void BrowserPluginImpl::OnLoadCommit( |
| 470 int instance_id, | 456 int instance_id, |
| 471 const BrowserPluginMsg_LoadCommit_Params& params) { | 457 const BrowserPluginMsg_LoadCommit_Params& params) { |
| 472 // If the guest has just committed a new navigation then it is no longer | 458 // If the guest has just committed a new navigation then it is no longer |
| 473 // crashed. | 459 // crashed. |
| 474 guest_crashed_ = false; | 460 guest_crashed_ = false; |
| 475 if (params.is_top_level) | 461 if (params.is_top_level) |
| 476 UpdateDOMAttribute(browser_plugin::kAttributeSrc, params.url.spec()); | 462 UpdateDOMAttribute(browser_plugin::kAttributeSrc, params.url.spec()); |
| 477 | 463 |
| 478 guest_process_id_ = params.process_id; | 464 guest_process_id_ = params.process_id; |
| 479 guest_route_id_ = params.route_id; | 465 guest_route_id_ = params.route_id; |
| 480 current_nav_entry_index_ = params.current_entry_index; | 466 current_nav_entry_index_ = params.current_entry_index; |
| 481 nav_entry_count_ = params.entry_count; | 467 nav_entry_count_ = params.entry_count; |
| 482 | 468 |
| 483 std::map<std::string, base::Value*> props; | 469 std::map<std::string, base::Value*> props; |
| 484 props[browser_plugin::kURL] = new base::StringValue(params.url.spec()); | 470 props[browser_plugin::kURL] = new base::StringValue(params.url.spec()); |
| 485 props[browser_plugin::kIsTopLevel] = | 471 props[browser_plugin::kIsTopLevel] = |
| 486 new base::FundamentalValue(params.is_top_level); | 472 new base::FundamentalValue(params.is_top_level); |
| 487 TriggerEvent(browser_plugin::kEventLoadCommit, &props); | 473 TriggerEvent(browser_plugin::kEventLoadCommit, &props); |
| 488 } | 474 } |
| 489 | 475 |
| 490 void BrowserPlugin::OnLoadRedirect(int instance_id, | 476 void BrowserPluginImpl::OnLoadRedirect(int instance_id, |
| 491 const GURL& old_url, | 477 const GURL& old_url, |
| 492 const GURL& new_url, | 478 const GURL& new_url, |
| 493 bool is_top_level) { | 479 bool is_top_level) { |
| 494 std::map<std::string, base::Value*> props; | 480 std::map<std::string, base::Value*> props; |
| 495 props[browser_plugin::kOldURL] = new base::StringValue(old_url.spec()); | 481 props[browser_plugin::kOldURL] = new base::StringValue(old_url.spec()); |
| 496 props[browser_plugin::kNewURL] = new base::StringValue(new_url.spec()); | 482 props[browser_plugin::kNewURL] = new base::StringValue(new_url.spec()); |
| 497 props[browser_plugin::kIsTopLevel] = new base::FundamentalValue(is_top_level); | 483 props[browser_plugin::kIsTopLevel] = new base::FundamentalValue(is_top_level); |
| 498 TriggerEvent(browser_plugin::kEventLoadRedirect, &props); | 484 TriggerEvent(browser_plugin::kEventLoadRedirect, &props); |
| 499 } | 485 } |
| 500 | 486 |
| 501 void BrowserPlugin::OnLoadStart(int instance_id, | 487 void BrowserPluginImpl::OnLoadStart(int instance_id, |
| 502 const GURL& url, | 488 const GURL& url, |
| 503 bool is_top_level) { | 489 bool is_top_level) { |
| 504 std::map<std::string, base::Value*> props; | 490 std::map<std::string, base::Value*> props; |
| 505 props[browser_plugin::kURL] = new base::StringValue(url.spec()); | 491 props[browser_plugin::kURL] = new base::StringValue(url.spec()); |
| 506 props[browser_plugin::kIsTopLevel] = new base::FundamentalValue(is_top_level); | 492 props[browser_plugin::kIsTopLevel] = new base::FundamentalValue(is_top_level); |
| 507 | 493 |
| 508 TriggerEvent(browser_plugin::kEventLoadStart, &props); | 494 TriggerEvent(browser_plugin::kEventLoadStart, &props); |
| 509 } | 495 } |
| 510 | 496 |
| 511 void BrowserPlugin::OnLoadStop(int instance_id) { | 497 void BrowserPluginImpl::OnLoadStop(int instance_id) { |
| 512 TriggerEvent(browser_plugin::kEventLoadStop, NULL); | 498 TriggerEvent(browser_plugin::kEventLoadStop, NULL); |
| 513 } | 499 } |
| 514 | 500 |
| 515 void BrowserPlugin::OnSetCursor(int instance_id, const WebCursor& cursor) { | 501 void BrowserPluginImpl::OnSetCursor(int instance_id, const WebCursor& cursor) { |
| 516 cursor_ = cursor; | 502 cursor_ = cursor; |
| 517 } | 503 } |
| 518 | 504 |
| 519 void BrowserPlugin::OnShouldAcceptTouchEvents(int instance_id, bool accept) { | 505 void BrowserPluginImpl::OnShouldAcceptTouchEvents(int instance_id, |
| 506 bool accept) { |
| 520 if (container()) { | 507 if (container()) { |
| 521 container()->requestTouchEventType(accept ? | 508 container()->requestTouchEventType(accept ? |
| 522 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : | 509 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : |
| 523 WebKit::WebPluginContainer::TouchEventRequestTypeNone); | 510 WebKit::WebPluginContainer::TouchEventRequestTypeNone); |
| 524 } | 511 } |
| 525 } | 512 } |
| 526 | 513 |
| 527 void BrowserPlugin::OnUpdatedName(int instance_id, const std::string& name) { | 514 void BrowserPluginImpl::OnUpdatedName(int instance_id, |
| 515 const std::string& name) { |
| 528 UpdateDOMAttribute(browser_plugin::kAttributeName, name); | 516 UpdateDOMAttribute(browser_plugin::kAttributeName, name); |
| 529 } | 517 } |
| 530 | 518 |
| 531 void BrowserPlugin::OnUpdateRect( | 519 void BrowserPluginImpl::OnUpdateRect( |
| 532 int instance_id, | 520 int instance_id, |
| 533 const BrowserPluginMsg_UpdateRect_Params& params) { | 521 const BrowserPluginMsg_UpdateRect_Params& params) { |
| 534 bool use_new_damage_buffer = !backing_store_; | 522 bool use_new_damage_buffer = !backing_store_; |
| 535 BrowserPluginHostMsg_AutoSize_Params auto_size_params; | 523 BrowserPluginHostMsg_AutoSize_Params auto_size_params; |
| 536 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; | 524 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; |
| 537 // If we have a pending damage buffer, and the guest has begun to use the | 525 // If we have a pending damage buffer, and the guest has begun to use the |
| 538 // damage buffer then we know the guest will no longer use the current | 526 // damage buffer then we know the guest will no longer use the current |
| 539 // damage buffer. At this point, we drop the current damage buffer, and | 527 // damage buffer. At this point, we drop the current damage buffer, and |
| 540 // mark the pending damage buffer as the current damage buffer. | 528 // mark the pending damage buffer as the current damage buffer. |
| 541 if (UsesPendingDamageBuffer(params)) { | 529 if (UsesPendingDamageBuffer(params)) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 // resize to avoid flicker. |size_changed_in_flight_| acts as a form of | 586 // resize to avoid flicker. |size_changed_in_flight_| acts as a form of |
| 599 // flow control for SizeChanged events. If the guest's view size is changing | 587 // flow control for SizeChanged events. If the guest's view size is changing |
| 600 // rapidly before a SizeChanged event fires, then we avoid scheduling | 588 // rapidly before a SizeChanged event fires, then we avoid scheduling |
| 601 // another SizeChanged event. SizeChanged reads the new size from | 589 // another SizeChanged event. SizeChanged reads the new size from |
| 602 // |last_view_size_| so we can be sure that it always fires an event | 590 // |last_view_size_| so we can be sure that it always fires an event |
| 603 // with the last seen view size. | 591 // with the last seen view size. |
| 604 if (container_ && !size_changed_in_flight_) { | 592 if (container_ && !size_changed_in_flight_) { |
| 605 size_changed_in_flight_ = true; | 593 size_changed_in_flight_ = true; |
| 606 MessageLoop::current()->PostTask( | 594 MessageLoop::current()->PostTask( |
| 607 FROM_HERE, | 595 FROM_HERE, |
| 608 base::Bind(&BrowserPlugin::SizeChangedDueToAutoSize, | 596 base::Bind(&BrowserPluginImpl::SizeChangedDueToAutoSize, |
| 609 base::Unretained(this), | 597 base::Unretained(this), |
| 610 old_view_size)); | 598 old_view_size)); |
| 611 } | 599 } |
| 612 } | 600 } |
| 613 | 601 |
| 614 // No more work to do since the guest is no longer using a damage buffer. | 602 // No more work to do since the guest is no longer using a damage buffer. |
| 615 if (!UsesDamageBuffer(params)) | 603 if (!UsesDamageBuffer(params)) |
| 616 return; | 604 return; |
| 617 | 605 |
| 618 // If we are seeing damage buffers, HW compositing should be turned off. | 606 // If we are seeing damage buffers, HW compositing should be turned off. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 649 container_->invalidate(); | 637 container_->invalidate(); |
| 650 if (auto_size) | 638 if (auto_size) |
| 651 PopulateAutoSizeParameters(&auto_size_params, auto_size); | 639 PopulateAutoSizeParameters(&auto_size_params, auto_size); |
| 652 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( | 640 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( |
| 653 render_view_routing_id_, | 641 render_view_routing_id_, |
| 654 instance_id_, | 642 instance_id_, |
| 655 auto_size_params, | 643 auto_size_params, |
| 656 resize_guest_params)); | 644 resize_guest_params)); |
| 657 } | 645 } |
| 658 | 646 |
| 659 void BrowserPlugin::ParseSizeContraintsChanged() { | 647 void BrowserPluginImpl::ParseSizeContraintsChanged() { |
| 660 bool auto_size = GetAutoSizeAttribute(); | 648 bool auto_size = GetAutoSizeAttribute(); |
| 661 if (auto_size) | 649 if (auto_size) |
| 662 UpdateGuestAutoSizeState(true); | 650 UpdateGuestAutoSizeState(true); |
| 663 } | 651 } |
| 664 | 652 |
| 665 bool BrowserPlugin::InAutoSizeBounds(const gfx::Size& size) const { | 653 bool BrowserPluginImpl::InAutoSizeBounds(const gfx::Size& size) const { |
| 666 return size.width() <= GetAdjustedMaxWidth() && | 654 return size.width() <= GetAdjustedMaxWidth() && |
| 667 size.height() <= GetAdjustedMaxHeight(); | 655 size.height() <= GetAdjustedMaxHeight(); |
| 668 } | 656 } |
| 669 | 657 |
| 670 NPObject* BrowserPlugin::GetContentWindow() const { | 658 NPObject* BrowserPluginImpl::GetContentWindow() const { |
| 671 if (content_window_routing_id_ == MSG_ROUTING_NONE) | 659 if (content_window_routing_id_ == MSG_ROUTING_NONE) |
| 672 return NULL; | 660 return NULL; |
| 673 RenderViewImpl* guest_render_view = static_cast<RenderViewImpl*>( | 661 RenderViewImpl* guest_render_view = static_cast<RenderViewImpl*>( |
| 674 ChildThread::current()->ResolveRoute(content_window_routing_id_)); | 662 ChildThread::current()->ResolveRoute(content_window_routing_id_)); |
| 675 if (!guest_render_view) | 663 if (!guest_render_view) |
| 676 return NULL; | 664 return NULL; |
| 677 WebKit::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); | 665 WebKit::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); |
| 678 return guest_frame->windowObject(); | 666 return guest_frame->windowObject(); |
| 679 } | 667 } |
| 680 | 668 |
| 681 bool BrowserPlugin::CanGoBack() const { | 669 bool BrowserPluginImpl::CanGoBack() const { |
| 682 return nav_entry_count_ > 1 && current_nav_entry_index_ > 0; | 670 return nav_entry_count_ > 1 && current_nav_entry_index_ > 0; |
| 683 } | 671 } |
| 684 | 672 |
| 685 bool BrowserPlugin::CanGoForward() const { | 673 bool BrowserPluginImpl::CanGoForward() const { |
| 686 return current_nav_entry_index_ >= 0 && | 674 return current_nav_entry_index_ >= 0 && |
| 687 current_nav_entry_index_ < (nav_entry_count_ - 1); | 675 current_nav_entry_index_ < (nav_entry_count_ - 1); |
| 688 } | 676 } |
| 689 | 677 |
| 690 bool BrowserPlugin::ParsePartitionAttribute(std::string* error_message) { | 678 bool BrowserPluginImpl::ParsePartitionAttribute(std::string* error_message) { |
| 691 if (allocate_instance_id_sent_) { | 679 if (allocate_instance_id_sent_) { |
| 692 *error_message = browser_plugin::kErrorAlreadyNavigated; | 680 *error_message = browser_plugin::kErrorAlreadyNavigated; |
| 693 return false; | 681 return false; |
| 694 } | 682 } |
| 695 | 683 |
| 696 std::string input = GetPartitionAttribute(); | 684 std::string input = GetPartitionAttribute(); |
| 697 | 685 |
| 698 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on | 686 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on |
| 699 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely | 687 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely |
| 700 // remove the prefix without splicing in the middle of a multi-byte codepoint. | 688 // remove the prefix without splicing in the middle of a multi-byte codepoint. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 712 persist_storage_ = true; | 700 persist_storage_ = true; |
| 713 } else { | 701 } else { |
| 714 persist_storage_ = false; | 702 persist_storage_ = false; |
| 715 } | 703 } |
| 716 | 704 |
| 717 valid_partition_id_ = true; | 705 valid_partition_id_ = true; |
| 718 storage_partition_id_ = input; | 706 storage_partition_id_ = input; |
| 719 return true; | 707 return true; |
| 720 } | 708 } |
| 721 | 709 |
| 722 bool BrowserPlugin::CanRemovePartitionAttribute(std::string* error_message) { | 710 bool BrowserPluginImpl::CanRemovePartitionAttribute( |
| 711 std::string* error_message) { |
| 723 if (navigate_src_sent_) | 712 if (navigate_src_sent_) |
| 724 *error_message = browser_plugin::kErrorCannotRemovePartition; | 713 *error_message = browser_plugin::kErrorCannotRemovePartition; |
| 725 return !navigate_src_sent_; | 714 return !navigate_src_sent_; |
| 726 } | 715 } |
| 727 | 716 |
| 728 void BrowserPlugin::ParseAttributes() { | 717 void BrowserPluginImpl::ParseAttributes() { |
| 729 // TODO(mthiesse): Handle errors here? | 718 // TODO(mthiesse): Handle errors here? |
| 730 std::string error; | 719 std::string error; |
| 731 ParsePartitionAttribute(&error); | 720 ParsePartitionAttribute(&error); |
| 732 | 721 |
| 733 // Parse the 'src' attribute last, as it will set the has_navigated_ flag to | 722 // Parse the 'src' attribute last, as it will set the has_navigated_ flag to |
| 734 // true, which prevents changing the 'partition' attribute. | 723 // true, which prevents changing the 'partition' attribute. |
| 735 ParseSrcAttribute(&error); | 724 ParseSrcAttribute(&error); |
| 736 } | 725 } |
| 737 | 726 |
| 738 float BrowserPlugin::GetDeviceScaleFactor() const { | 727 float BrowserPluginImpl::GetDeviceScaleFactor() const { |
| 739 if (!render_view_) | 728 if (!render_view_) |
| 740 return 1.0f; | 729 return 1.0f; |
| 741 return render_view_->GetWebView()->deviceScaleFactor(); | 730 return render_view_->GetWebView()->deviceScaleFactor(); |
| 742 } | 731 } |
| 743 | 732 |
| 744 void BrowserPlugin::TriggerEvent(const std::string& event_name, | 733 void BrowserPluginImpl::Back() { |
| 745 std::map<std::string, base::Value*>* props) { | |
| 746 if (!container() || !container()->element().document().frame()) | |
| 747 return; | |
| 748 v8::HandleScope handle_scope; | |
| 749 std::string json_string; | |
| 750 if (props) { | |
| 751 base::DictionaryValue dict; | |
| 752 for (std::map<std::string, base::Value*>::iterator iter = props->begin(), | |
| 753 end = props->end(); iter != end; ++iter) { | |
| 754 dict.Set(iter->first, iter->second); | |
| 755 } | |
| 756 | |
| 757 JSONStringValueSerializer serializer(&json_string); | |
| 758 if (!serializer.Serialize(dict)) | |
| 759 return; | |
| 760 } | |
| 761 | |
| 762 WebKit::WebFrame* frame = container()->element().document().frame(); | |
| 763 WebKit::WebDOMEvent dom_event = frame->document().createEvent("CustomEvent"); | |
| 764 WebKit::WebDOMCustomEvent event = dom_event.to<WebKit::WebDOMCustomEvent>(); | |
| 765 | |
| 766 // The events triggered directly from the plugin <object> are internal events | |
| 767 // whose implementation details can (and likely will) change over time. The | |
| 768 // wrapper/shim (e.g. <webview> tag) should receive these events, and expose a | |
| 769 // more appropriate (and stable) event to the consumers as part of the API. | |
| 770 event.initCustomEvent( | |
| 771 WebKit::WebString::fromUTF8(GetInternalEventName(event_name.c_str())), | |
| 772 false, false, | |
| 773 WebKit::WebSerializedScriptValue::serialize( | |
| 774 v8::String::New(json_string.c_str(), json_string.size()))); | |
| 775 container()->element().dispatchEvent(event); | |
| 776 } | |
| 777 | |
| 778 void BrowserPlugin::Back() { | |
| 779 if (!navigate_src_sent_) | 734 if (!navigate_src_sent_) |
| 780 return; | 735 return; |
| 781 browser_plugin_manager()->Send( | 736 browser_plugin_manager()->Send( |
| 782 new BrowserPluginHostMsg_Go(render_view_routing_id_, | 737 new BrowserPluginHostMsg_Go(render_view_routing_id_, |
| 783 instance_id_, -1)); | 738 instance_id_, -1)); |
| 784 } | 739 } |
| 785 | 740 |
| 786 void BrowserPlugin::Forward() { | 741 void BrowserPluginImpl::Forward() { |
| 787 if (!navigate_src_sent_) | 742 if (!navigate_src_sent_) |
| 788 return; | 743 return; |
| 789 browser_plugin_manager()->Send( | 744 browser_plugin_manager()->Send( |
| 790 new BrowserPluginHostMsg_Go(render_view_routing_id_, | 745 new BrowserPluginHostMsg_Go(render_view_routing_id_, |
| 791 instance_id_, 1)); | 746 instance_id_, 1)); |
| 792 } | 747 } |
| 793 | 748 |
| 794 void BrowserPlugin::Go(int relative_index) { | 749 void BrowserPluginImpl::Go(int relative_index) { |
| 795 if (!navigate_src_sent_) | 750 if (!navigate_src_sent_) |
| 796 return; | 751 return; |
| 797 browser_plugin_manager()->Send( | 752 browser_plugin_manager()->Send( |
| 798 new BrowserPluginHostMsg_Go(render_view_routing_id_, | 753 new BrowserPluginHostMsg_Go(render_view_routing_id_, |
| 799 instance_id_, | 754 instance_id_, |
| 800 relative_index)); | 755 relative_index)); |
| 801 } | 756 } |
| 802 | 757 |
| 803 void BrowserPlugin::TerminateGuest() { | 758 void BrowserPluginImpl::TerminateGuest() { |
| 804 if (!navigate_src_sent_ || guest_crashed_) | 759 if (!navigate_src_sent_ || guest_crashed_) |
| 805 return; | 760 return; |
| 806 browser_plugin_manager()->Send( | 761 browser_plugin_manager()->Send( |
| 807 new BrowserPluginHostMsg_TerminateGuest(render_view_routing_id_, | 762 new BrowserPluginHostMsg_TerminateGuest(render_view_routing_id_, |
| 808 instance_id_)); | 763 instance_id_)); |
| 809 } | 764 } |
| 810 | 765 |
| 811 void BrowserPlugin::Stop() { | 766 void BrowserPluginImpl::Stop() { |
| 812 if (!navigate_src_sent_) | 767 if (!navigate_src_sent_) |
| 813 return; | 768 return; |
| 814 browser_plugin_manager()->Send( | 769 browser_plugin_manager()->Send( |
| 815 new BrowserPluginHostMsg_Stop(render_view_routing_id_, | 770 new BrowserPluginHostMsg_Stop(render_view_routing_id_, |
| 816 instance_id_)); | 771 instance_id_)); |
| 817 } | 772 } |
| 818 | 773 |
| 819 void BrowserPlugin::Reload() { | 774 void BrowserPluginImpl::Reload() { |
| 820 if (!navigate_src_sent_) | 775 if (!navigate_src_sent_) |
| 821 return; | 776 return; |
| 822 browser_plugin_manager()->Send( | 777 browser_plugin_manager()->Send( |
| 823 new BrowserPluginHostMsg_Reload(render_view_routing_id_, | 778 new BrowserPluginHostMsg_Reload(render_view_routing_id_, |
| 824 instance_id_)); | 779 instance_id_)); |
| 825 } | 780 } |
| 826 | 781 |
| 827 void BrowserPlugin::UpdateGuestFocusState() { | 782 void BrowserPluginImpl::UpdateGuestFocusState() { |
| 828 if (!navigate_src_sent_) | 783 if (!navigate_src_sent_) |
| 829 return; | 784 return; |
| 830 bool should_be_focused = ShouldGuestBeFocused(); | 785 bool should_be_focused = ShouldGuestBeFocused(); |
| 831 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus( | 786 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus( |
| 832 render_view_routing_id_, | 787 render_view_routing_id_, |
| 833 instance_id_, | 788 instance_id_, |
| 834 should_be_focused)); | 789 should_be_focused)); |
| 835 } | 790 } |
| 836 | 791 |
| 837 bool BrowserPlugin::ShouldGuestBeFocused() const { | 792 bool BrowserPluginImpl::ShouldGuestBeFocused() const { |
| 838 bool embedder_focused = false; | 793 bool embedder_focused = false; |
| 839 if (render_view_) | 794 if (render_view_) |
| 840 embedder_focused = render_view_->has_focus(); | 795 embedder_focused = render_view_->has_focus(); |
| 841 return plugin_focused_ && embedder_focused; | 796 return plugin_focused_ && embedder_focused; |
| 842 } | 797 } |
| 843 | 798 |
| 844 WebKit::WebPluginContainer* BrowserPlugin::container() const { | 799 WebKit::WebPluginContainer* BrowserPluginImpl::container() const { |
| 845 return container_; | 800 return container_; |
| 846 } | 801 } |
| 847 | 802 |
| 848 bool BrowserPlugin::initialize(WebPluginContainer* container) { | 803 bool BrowserPluginImpl::initialize(WebPluginContainer* container) { |
| 849 container_ = container; | 804 container_ = container; |
| 850 container_->setWantsWheelEvents(true); | 805 container_->setWantsWheelEvents(true); |
| 851 ParseAttributes(); | 806 ParseAttributes(); |
| 852 return true; | 807 return true; |
| 853 } | 808 } |
| 854 | 809 |
| 855 void BrowserPlugin::EnableCompositing(bool enable) { | 810 void BrowserPluginImpl::EnableCompositing(bool enable) { |
| 856 if (compositing_enabled_ == enable) | 811 if (compositing_enabled_ == enable) |
| 857 return; | 812 return; |
| 858 | 813 |
| 859 compositing_enabled_ = enable; | 814 compositing_enabled_ = enable; |
| 860 if (enable) { | 815 if (enable) { |
| 861 // No need to keep the backing store and damage buffer around if we're now | 816 // No need to keep the backing store and damage buffer around if we're now |
| 862 // compositing. | 817 // compositing. |
| 863 backing_store_.reset(); | 818 backing_store_.reset(); |
| 864 current_damage_buffer_.reset(); | 819 current_damage_buffer_.reset(); |
| 865 if (!compositing_helper_) { | 820 if (!compositing_helper_) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 879 params.repaint = true; | 834 params.repaint = true; |
| 880 resize_ack_received_ = false; | 835 resize_ack_received_ = false; |
| 881 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | 836 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( |
| 882 render_view_routing_id_, | 837 render_view_routing_id_, |
| 883 instance_id_, | 838 instance_id_, |
| 884 params)); | 839 params)); |
| 885 } | 840 } |
| 886 compositing_helper_->EnableCompositing(enable); | 841 compositing_helper_->EnableCompositing(enable); |
| 887 } | 842 } |
| 888 | 843 |
| 889 void BrowserPlugin::destroy() { | 844 void BrowserPluginImpl::destroy() { |
| 890 // The BrowserPlugin's WebPluginContainer is deleted immediately after this | 845 // The BrowserPlugin's WebPluginContainer is deleted immediately after this |
| 891 // call returns, so let's not keep a reference to it around. | 846 // call returns, so let's not keep a reference to it around. |
| 892 container_ = NULL; | 847 container_ = NULL; |
| 848 // BrowserPluginObservers might create additional bindings. These bindings |
| 849 // might refer back to the observers that created them. In order to ensure |
| 850 // that bindings can always refer to valid observers, we get rid of bindings |
| 851 // prior to cleaning up observers. |
| 852 bindings_.reset(); |
| 853 FOR_EACH_OBSERVER(BrowserPluginObserver, observers_, BrowserPluginGone()); |
| 854 FOR_EACH_OBSERVER(BrowserPluginObserver, observers_, OnDestruct()); |
| 893 if (compositing_helper_) | 855 if (compositing_helper_) |
| 894 compositing_helper_->OnContainerDestroy(); | 856 compositing_helper_->OnContainerDestroy(); |
| 895 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 857 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 896 } | 858 } |
| 897 | 859 |
| 898 NPObject* BrowserPlugin::scriptableObject() { | 860 NPObject* BrowserPluginImpl::scriptableObject() { |
| 899 NPObject* browser_plugin_np_object(bindings_->np_object()); | 861 NPObject* browser_plugin_np_object(bindings_->np_object()); |
| 900 // The object is expected to be retained before it is returned. | 862 // The object is expected to be retained before it is returned. |
| 901 WebKit::WebBindings::retainObject(browser_plugin_np_object); | 863 WebKit::WebBindings::retainObject(browser_plugin_np_object); |
| 902 return browser_plugin_np_object; | 864 return browser_plugin_np_object; |
| 903 } | 865 } |
| 904 | 866 |
| 905 bool BrowserPlugin::supportsKeyboardFocus() const { | 867 bool BrowserPluginImpl::supportsKeyboardFocus() const { |
| 906 return true; | 868 return true; |
| 907 } | 869 } |
| 908 | 870 |
| 909 bool BrowserPlugin::canProcessDrag() const { | 871 bool BrowserPluginImpl::canProcessDrag() const { |
| 910 return true; | 872 return true; |
| 911 } | 873 } |
| 912 | 874 |
| 913 void BrowserPlugin::paint(WebCanvas* canvas, const WebRect& rect) { | 875 void BrowserPluginImpl::paint(WebCanvas* canvas, const WebRect& rect) { |
| 914 if (guest_crashed_) { | 876 if (guest_crashed_) { |
| 915 if (!sad_guest_) // Lazily initialize bitmap. | 877 if (!sad_guest_) // Lazily initialize bitmap. |
| 916 sad_guest_ = content::GetContentClient()->renderer()-> | 878 sad_guest_ = GetContentClient()->renderer()->GetSadWebViewBitmap(); |
| 917 GetSadWebViewBitmap(); | |
| 918 // content_shell does not have the sad plugin bitmap, so we'll paint black | 879 // content_shell does not have the sad plugin bitmap, so we'll paint black |
| 919 // instead to make it clear that something went wrong. | 880 // instead to make it clear that something went wrong. |
| 920 if (sad_guest_) { | 881 if (sad_guest_) { |
| 921 webkit::PaintSadPlugin(canvas, plugin_rect_, *sad_guest_); | 882 webkit::PaintSadPlugin(canvas, plugin_rect_, *sad_guest_); |
| 922 return; | 883 return; |
| 923 } | 884 } |
| 924 } | 885 } |
| 925 SkAutoCanvasRestore auto_restore(canvas, true); | 886 SkAutoCanvasRestore auto_restore(canvas, true); |
| 926 canvas->translate(plugin_rect_.x(), plugin_rect_.y()); | 887 canvas->translate(plugin_rect_.x(), plugin_rect_.y()); |
| 927 SkRect image_data_rect = SkRect::MakeXYWH( | 888 SkRect image_data_rect = SkRect::MakeXYWH( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 938 canvas->drawRect(image_data_rect, paint); | 899 canvas->drawRect(image_data_rect, paint); |
| 939 // Stay a solid color if we have never set a non-empty src, or we don't have a | 900 // Stay a solid color if we have never set a non-empty src, or we don't have a |
| 940 // backing store. | 901 // backing store. |
| 941 if (!backing_store_.get() || !navigate_src_sent_) | 902 if (!backing_store_.get() || !navigate_src_sent_) |
| 942 return; | 903 return; |
| 943 float inverse_scale_factor = 1.0f / backing_store_->GetScaleFactor(); | 904 float inverse_scale_factor = 1.0f / backing_store_->GetScaleFactor(); |
| 944 canvas->scale(inverse_scale_factor, inverse_scale_factor); | 905 canvas->scale(inverse_scale_factor, inverse_scale_factor); |
| 945 canvas->drawBitmap(backing_store_->GetBitmap(), 0, 0); | 906 canvas->drawBitmap(backing_store_->GetBitmap(), 0, 0); |
| 946 } | 907 } |
| 947 | 908 |
| 948 bool BrowserPlugin::InBounds(const gfx::Point& position) const { | 909 bool BrowserPluginImpl::InBounds(const gfx::Point& position) const { |
| 949 // Note that even for plugins that are rotated using rotate transformations, | 910 // Note that even for plugins that are rotated using rotate transformations, |
| 950 // we use the the |plugin_rect_| provided by updateGeometry, which means we | 911 // we use the the |plugin_rect_| provided by updateGeometry, which means we |
| 951 // will be off if |position| is within the plugin rect but does not fall | 912 // will be off if |position| is within the plugin rect but does not fall |
| 952 // within the actual plugin boundary. Not supporting such edge case is OK | 913 // within the actual plugin boundary. Not supporting such edge case is OK |
| 953 // since this function should not be used for making security-sensitive | 914 // since this function should not be used for making security-sensitive |
| 954 // decisions. | 915 // decisions. |
| 955 // This also does not take overlapping plugins into account. | 916 // This also does not take overlapping plugins into account. |
| 956 bool result = position.x() >= plugin_rect_.x() && | 917 bool result = position.x() >= plugin_rect_.x() && |
| 957 position.x() < plugin_rect_.x() + plugin_rect_.width() && | 918 position.x() < plugin_rect_.x() + plugin_rect_.width() && |
| 958 position.y() >= plugin_rect_.y() && | 919 position.y() >= plugin_rect_.y() && |
| 959 position.y() < plugin_rect_.y() + plugin_rect_.height(); | 920 position.y() < plugin_rect_.y() + plugin_rect_.height(); |
| 960 return result; | 921 return result; |
| 961 } | 922 } |
| 962 | 923 |
| 963 gfx::Point BrowserPlugin::ToLocalCoordinates(const gfx::Point& point) const { | 924 void BrowserPluginImpl::AddMethodBinding( |
| 925 BrowserPluginMethodBinding* method_binding) { |
| 926 bindings_->AddMethodBinding(method_binding); |
| 927 } |
| 928 |
| 929 void BrowserPluginImpl::AddPropertyBinding( |
| 930 BrowserPluginPropertyBinding* method_binding) { |
| 931 bindings_->AddPropertyBinding(method_binding); |
| 932 } |
| 933 |
| 934 RenderView* BrowserPluginImpl::GetRenderView() const { |
| 935 return render_view_.get(); |
| 936 } |
| 937 |
| 938 WebKit::WebPluginContainer* BrowserPluginImpl::GetContainer() const { |
| 939 return container(); |
| 940 } |
| 941 |
| 942 void BrowserPluginImpl::TriggerEvent( |
| 943 const std::string& event_name, |
| 944 std::map<std::string, base::Value*>* props) { |
| 945 if (!container() || !container()->element().document().frame()) |
| 946 return; |
| 947 v8::HandleScope handle_scope; |
| 948 std::string json_string; |
| 949 if (props) { |
| 950 base::DictionaryValue dict; |
| 951 for (std::map<std::string, base::Value*>::iterator iter = props->begin(), |
| 952 end = props->end(); iter != end; ++iter) { |
| 953 dict.Set(iter->first, iter->second); |
| 954 } |
| 955 |
| 956 JSONStringValueSerializer serializer(&json_string); |
| 957 if (!serializer.Serialize(dict)) |
| 958 return; |
| 959 } |
| 960 |
| 961 WebKit::WebFrame* frame = container()->element().document().frame(); |
| 962 WebKit::WebDOMEvent dom_event = frame->document().createEvent("CustomEvent"); |
| 963 WebKit::WebDOMCustomEvent event = dom_event.to<WebKit::WebDOMCustomEvent>(); |
| 964 |
| 965 // The events triggered directly from the plugin <object> are internal events |
| 966 // whose implementation details can (and likely will) change over time. The |
| 967 // wrapper/shim (e.g. <webview> tag) should receive these events, and expose a |
| 968 // more appropriate (and stable) event to the consumers as part of the API. |
| 969 event.initCustomEvent( |
| 970 WebKit::WebString::fromUTF8(GetInternalEventName(event_name.c_str())), |
| 971 false, false, |
| 972 WebKit::WebSerializedScriptValue::serialize( |
| 973 v8::String::New(json_string.c_str(), json_string.size()))); |
| 974 container()->element().dispatchEvent(event); |
| 975 } |
| 976 |
| 977 void BrowserPluginImpl::UpdateDOMAttribute(const std::string& attribute_name, |
| 978 const std::string& attribute_value) { |
| 979 if (!container()) |
| 980 return; |
| 981 |
| 982 WebKit::WebElement element = container()->element(); |
| 983 WebKit::WebString web_attribute_name = |
| 984 WebKit::WebString::fromUTF8(attribute_name); |
| 985 if (!HasDOMAttribute(attribute_name) || |
| 986 (std::string(element.getAttribute(web_attribute_name).utf8()) != |
| 987 attribute_value)) { |
| 988 element.setAttribute(web_attribute_name, |
| 989 WebKit::WebString::fromUTF8(attribute_value)); |
| 990 } |
| 991 } |
| 992 void BrowserPluginImpl::RemoveDOMAttribute(const std::string& attribute_name) { |
| 993 if (!container()) |
| 994 return; |
| 995 |
| 996 container()->element().removeAttribute( |
| 997 WebKit::WebString::fromUTF8(attribute_name)); |
| 998 } |
| 999 |
| 1000 std::string BrowserPluginImpl::GetDOMAttributeValue( |
| 1001 const std::string& attribute_name) const { |
| 1002 if (!container()) |
| 1003 return ""; |
| 1004 |
| 1005 return container()->element().getAttribute( |
| 1006 WebKit::WebString::fromUTF8(attribute_name)).utf8(); |
| 1007 } |
| 1008 |
| 1009 bool BrowserPluginImpl::HasDOMAttribute( |
| 1010 const std::string& attribute_name) const { |
| 1011 if (!container()) |
| 1012 return false; |
| 1013 |
| 1014 return container()->element().hasAttribute( |
| 1015 WebKit::WebString::fromUTF8(attribute_name)); |
| 1016 } |
| 1017 |
| 1018 bool BrowserPluginImpl::HasNavigated() const { |
| 1019 return navigate_src_sent_; |
| 1020 } |
| 1021 |
| 1022 bool BrowserPluginImpl::Send(IPC::Message* message) { |
| 1023 IPC::Message* wrapper_msg = |
| 1024 new BrowserPluginHostMsg_ForwardMessage( |
| 1025 render_view_routing_id_, instance_id_, *message); |
| 1026 delete message; |
| 1027 return browser_plugin_manager()->Send(wrapper_msg); |
| 1028 } |
| 1029 |
| 1030 gfx::Point BrowserPluginImpl::ToLocalCoordinates( |
| 1031 const gfx::Point& point) const { |
| 964 if (container_) | 1032 if (container_) |
| 965 return container_->windowToLocalPoint(WebKit::WebPoint(point)); | 1033 return container_->windowToLocalPoint(WebKit::WebPoint(point)); |
| 966 return gfx::Point(point.x() - plugin_rect_.x(), point.y() - plugin_rect_.y()); | 1034 return gfx::Point(point.x() - plugin_rect_.x(), point.y() - plugin_rect_.y()); |
| 967 } | 1035 } |
| 968 | 1036 |
| 969 void BrowserPlugin::updateGeometry( | 1037 void BrowserPluginImpl::updateGeometry( |
| 970 const WebRect& window_rect, | 1038 const WebRect& window_rect, |
| 971 const WebRect& clip_rect, | 1039 const WebRect& clip_rect, |
| 972 const WebVector<WebRect>& cut_outs_rects, | 1040 const WebVector<WebRect>& cut_outs_rects, |
| 973 bool is_visible) { | 1041 bool is_visible) { |
| 974 int old_width = width(); | 1042 int old_width = width(); |
| 975 int old_height = height(); | 1043 int old_height = height(); |
| 976 plugin_rect_ = window_rect; | 1044 plugin_rect_ = window_rect; |
| 977 // In AutoSize mode, guests don't care when the BrowserPlugin container is | 1045 // In AutoSize mode, guests don't care when the BrowserPlugin container is |
| 978 // resized. If |!resize_ack_received_|, then we are still waiting on a | 1046 // resized. If |!resize_ack_received_|, then we are still waiting on a |
| 979 // previous resize to be ACK'ed and so we don't issue additional resizes | 1047 // previous resize to be ACK'ed and so we don't issue additional resizes |
| 980 // until the previous one is ACK'ed. | 1048 // until the previous one is ACK'ed. |
| 981 // TODO(mthiesse): Assess the performance of calling GetAutoSizeAttribute() on | 1049 // TODO(mthiesse): Assess the performance of calling GetAutoSizeAttribute() on |
| 982 // resize. | 1050 // resize. |
| 983 if (!navigate_src_sent_ || | 1051 if (!navigate_src_sent_ || |
| 984 !resize_ack_received_ || | 1052 !resize_ack_received_ || |
| 985 (old_width == window_rect.width && old_height == window_rect.height) || | 1053 (old_width == window_rect.width && old_height == window_rect.height) || |
| 986 GetAutoSizeAttribute()) { | 1054 GetAutoSizeAttribute()) { |
| 987 return; | 1055 return; |
| 988 } | 1056 } |
| 989 | 1057 |
| 990 BrowserPluginHostMsg_ResizeGuest_Params params; | 1058 BrowserPluginHostMsg_ResizeGuest_Params params; |
| 991 PopulateResizeGuestParameters(¶ms, gfx::Size(width(), height())); | 1059 PopulateResizeGuestParameters(¶ms, gfx::Size(width(), height())); |
| 992 resize_ack_received_ = false; | 1060 resize_ack_received_ = false; |
| 993 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | 1061 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( |
| 994 render_view_routing_id_, | 1062 render_view_routing_id_, |
| 995 instance_id_, | 1063 instance_id_, |
| 996 params)); | 1064 params)); |
| 997 } | 1065 } |
| 998 | 1066 |
| 999 void BrowserPlugin::SwapDamageBuffers() { | 1067 void BrowserPluginImpl::SwapDamageBuffers() { |
| 1000 current_damage_buffer_.reset(pending_damage_buffer_.release()); | 1068 current_damage_buffer_.reset(pending_damage_buffer_.release()); |
| 1001 resize_ack_received_ = true; | 1069 resize_ack_received_ = true; |
| 1002 } | 1070 } |
| 1003 | 1071 |
| 1004 void BrowserPlugin::PopulateResizeGuestParameters( | 1072 void BrowserPluginImpl::PopulateResizeGuestParameters( |
| 1005 BrowserPluginHostMsg_ResizeGuest_Params* params, | 1073 BrowserPluginHostMsg_ResizeGuest_Params* params, |
| 1006 const gfx::Size& view_size) { | 1074 const gfx::Size& view_size) { |
| 1007 params->view_size = view_size; | 1075 params->view_size = view_size; |
| 1008 params->scale_factor = GetDeviceScaleFactor(); | 1076 params->scale_factor = GetDeviceScaleFactor(); |
| 1009 | 1077 |
| 1010 // In HW compositing mode, we do not need a damage buffer. | 1078 // In HW compositing mode, we do not need a damage buffer. |
| 1011 if (compositing_enabled_) | 1079 if (compositing_enabled_) |
| 1012 return; | 1080 return; |
| 1013 | 1081 |
| 1014 const size_t stride = skia::PlatformCanvasStrideForWidth(view_size.width()); | 1082 const size_t stride = skia::PlatformCanvasStrideForWidth(view_size.width()); |
| 1015 // Make sure the size of the damage buffer is at least four bytes so that we | 1083 // Make sure the size of the damage buffer is at least four bytes so that we |
| 1016 // can fit in a magic word to verify that the memory is shared correctly. | 1084 // can fit in a magic word to verify that the memory is shared correctly. |
| 1017 size_t size = | 1085 size_t size = |
| 1018 std::max(sizeof(unsigned int), | 1086 std::max(sizeof(unsigned int), |
| 1019 static_cast<size_t>(view_size.height() * | 1087 static_cast<size_t>(view_size.height() * |
| 1020 stride * | 1088 stride * |
| 1021 GetDeviceScaleFactor() * | 1089 GetDeviceScaleFactor() * |
| 1022 GetDeviceScaleFactor())); | 1090 GetDeviceScaleFactor())); |
| 1023 | 1091 |
| 1024 params->damage_buffer_size = size; | 1092 params->damage_buffer_size = size; |
| 1025 pending_damage_buffer_.reset( | 1093 pending_damage_buffer_.reset( |
| 1026 CreateDamageBuffer(size, ¶ms->damage_buffer_handle)); | 1094 CreateDamageBuffer(size, ¶ms->damage_buffer_handle)); |
| 1027 if (!pending_damage_buffer_.get()) | 1095 if (!pending_damage_buffer_.get()) |
| 1028 NOTREACHED(); | 1096 NOTREACHED(); |
| 1029 params->damage_buffer_sequence_id = ++damage_buffer_sequence_id_; | 1097 params->damage_buffer_sequence_id = ++damage_buffer_sequence_id_; |
| 1030 } | 1098 } |
| 1031 | 1099 |
| 1032 void BrowserPlugin::GetDamageBufferWithSizeParams( | 1100 void BrowserPluginImpl::GetDamageBufferWithSizeParams( |
| 1033 BrowserPluginHostMsg_AutoSize_Params* auto_size_params, | 1101 BrowserPluginHostMsg_AutoSize_Params* auto_size_params, |
| 1034 BrowserPluginHostMsg_ResizeGuest_Params* resize_guest_params) { | 1102 BrowserPluginHostMsg_ResizeGuest_Params* resize_guest_params) { |
| 1035 if (auto_size_params) | 1103 if (auto_size_params) |
| 1036 PopulateAutoSizeParameters(auto_size_params, GetAutoSizeAttribute()); | 1104 PopulateAutoSizeParameters(auto_size_params, GetAutoSizeAttribute()); |
| 1037 gfx::Size view_size = (auto_size_params && auto_size_params->enable) ? | 1105 gfx::Size view_size = (auto_size_params && auto_size_params->enable) ? |
| 1038 auto_size_params->max_size : gfx::Size(width(), height()); | 1106 auto_size_params->max_size : gfx::Size(width(), height()); |
| 1039 if (view_size.IsEmpty()) | 1107 if (view_size.IsEmpty()) |
| 1040 return; | 1108 return; |
| 1041 resize_ack_received_ = false; | 1109 resize_ack_received_ = false; |
| 1042 PopulateResizeGuestParameters(resize_guest_params, view_size); | 1110 PopulateResizeGuestParameters(resize_guest_params, view_size); |
| 1043 } | 1111 } |
| 1044 | 1112 |
| 1045 #if defined(OS_POSIX) | 1113 #if defined(OS_POSIX) |
| 1046 base::SharedMemory* BrowserPlugin::CreateDamageBuffer( | 1114 base::SharedMemory* BrowserPluginImpl::CreateDamageBuffer( |
| 1047 const size_t size, | 1115 const size_t size, |
| 1048 base::SharedMemoryHandle* damage_buffer_handle) { | 1116 base::SharedMemoryHandle* damage_buffer_handle) { |
| 1049 scoped_ptr<base::SharedMemory> shared_buf( | 1117 scoped_ptr<base::SharedMemory> shared_buf( |
| 1050 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer( | 1118 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer( |
| 1051 size).release()); | 1119 size).release()); |
| 1052 | 1120 |
| 1053 if (shared_buf.get()) { | 1121 if (shared_buf.get()) { |
| 1054 if (shared_buf->Map(size)) { | 1122 if (shared_buf->Map(size)) { |
| 1055 // Insert the magic word. | 1123 // Insert the magic word. |
| 1056 *static_cast<unsigned int*>(shared_buf->memory()) = 0xdeadbeef; | 1124 *static_cast<unsigned int*>(shared_buf->memory()) = 0xdeadbeef; |
| 1057 shared_buf->ShareToProcess(base::GetCurrentProcessHandle(), | 1125 shared_buf->ShareToProcess(base::GetCurrentProcessHandle(), |
| 1058 damage_buffer_handle); | 1126 damage_buffer_handle); |
| 1059 return shared_buf.release(); | 1127 return shared_buf.release(); |
| 1060 } | 1128 } |
| 1061 } | 1129 } |
| 1062 NOTREACHED(); | 1130 NOTREACHED(); |
| 1063 return NULL; | 1131 return NULL; |
| 1064 } | 1132 } |
| 1065 #elif defined(OS_WIN) | 1133 #elif defined(OS_WIN) |
| 1066 base::SharedMemory* BrowserPlugin::CreateDamageBuffer( | 1134 base::SharedMemory* BrowserPluginImpl::CreateDamageBuffer( |
| 1067 const size_t size, | 1135 const size_t size, |
| 1068 base::SharedMemoryHandle* damage_buffer_handle) { | 1136 base::SharedMemoryHandle* damage_buffer_handle) { |
| 1069 scoped_ptr<base::SharedMemory> shared_buf(new base::SharedMemory()); | 1137 scoped_ptr<base::SharedMemory> shared_buf(new base::SharedMemory()); |
| 1070 | 1138 |
| 1071 if (!shared_buf->CreateAndMapAnonymous(size)) { | 1139 if (!shared_buf->CreateAndMapAnonymous(size)) { |
| 1072 NOTREACHED() << "Buffer allocation failed"; | 1140 NOTREACHED() << "Buffer allocation failed"; |
| 1073 return NULL; | 1141 return NULL; |
| 1074 } | 1142 } |
| 1075 | |
| 1076 // Insert the magic word. | 1143 // Insert the magic word. |
| 1077 *static_cast<unsigned int*>(shared_buf->memory()) = 0xdeadbeef; | 1144 *static_cast<unsigned int*>(shared_buf->memory()) = 0xdeadbeef; |
| 1078 if (shared_buf->ShareToProcess(base::GetCurrentProcessHandle(), | 1145 if (shared_buf->ShareToProcess(base::GetCurrentProcessHandle(), |
| 1079 damage_buffer_handle)) | 1146 damage_buffer_handle)) |
| 1080 return shared_buf.release(); | 1147 return shared_buf.release(); |
| 1081 NOTREACHED(); | 1148 NOTREACHED(); |
| 1082 return NULL; | 1149 return NULL; |
| 1083 } | 1150 } |
| 1084 #endif | 1151 #endif |
| 1085 | 1152 |
| 1086 void BrowserPlugin::updateFocus(bool focused) { | 1153 void BrowserPluginImpl::updateFocus(bool focused) { |
| 1087 if (plugin_focused_ == focused) | 1154 if (plugin_focused_ == focused) |
| 1088 return; | 1155 return; |
| 1089 | 1156 |
| 1090 bool old_guest_focus_state = ShouldGuestBeFocused(); | 1157 bool old_guest_focus_state = ShouldGuestBeFocused(); |
| 1091 plugin_focused_ = focused; | 1158 plugin_focused_ = focused; |
| 1092 | 1159 |
| 1093 if (ShouldGuestBeFocused() != old_guest_focus_state) | 1160 if (ShouldGuestBeFocused() != old_guest_focus_state) |
| 1094 UpdateGuestFocusState(); | 1161 UpdateGuestFocusState(); |
| 1095 } | 1162 } |
| 1096 | 1163 |
| 1097 void BrowserPlugin::updateVisibility(bool visible) { | 1164 void BrowserPluginImpl::updateVisibility(bool visible) { |
| 1098 if (visible_ == visible) | 1165 if (visible_ == visible) |
| 1099 return; | 1166 return; |
| 1100 | 1167 |
| 1101 visible_ = visible; | 1168 visible_ = visible; |
| 1102 if (!navigate_src_sent_) | 1169 if (!navigate_src_sent_) |
| 1103 return; | 1170 return; |
| 1104 | 1171 |
| 1105 if (compositing_helper_) | 1172 if (compositing_helper_) |
| 1106 compositing_helper_->UpdateVisibility(visible); | 1173 compositing_helper_->UpdateVisibility(visible); |
| 1107 | 1174 |
| 1108 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetVisibility( | 1175 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetVisibility( |
| 1109 render_view_routing_id_, | 1176 render_view_routing_id_, |
| 1110 instance_id_, | 1177 instance_id_, |
| 1111 visible)); | 1178 visible)); |
| 1112 } | 1179 } |
| 1113 | 1180 |
| 1114 bool BrowserPlugin::acceptsInputEvents() { | 1181 bool BrowserPluginImpl::acceptsInputEvents() { |
| 1115 return true; | 1182 return true; |
| 1116 } | 1183 } |
| 1117 | 1184 |
| 1118 bool BrowserPlugin::handleInputEvent(const WebKit::WebInputEvent& event, | 1185 bool BrowserPluginImpl::handleInputEvent(const WebKit::WebInputEvent& event, |
| 1119 WebKit::WebCursorInfo& cursor_info) { | 1186 WebKit::WebCursorInfo& cursor_info) { |
| 1120 if (guest_crashed_ || !navigate_src_sent_ || | 1187 if (guest_crashed_ || !navigate_src_sent_ || |
| 1121 event.type == WebKit::WebInputEvent::ContextMenu) | 1188 event.type == WebKit::WebInputEvent::ContextMenu) |
| 1122 return false; | 1189 return false; |
| 1123 browser_plugin_manager()->Send( | 1190 browser_plugin_manager()->Send( |
| 1124 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 1191 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
| 1125 instance_id_, | 1192 instance_id_, |
| 1126 plugin_rect_, | 1193 plugin_rect_, |
| 1127 &event)); | 1194 &event)); |
| 1128 cursor_.GetCursorInfo(&cursor_info); | 1195 cursor_.GetCursorInfo(&cursor_info); |
| 1129 return true; | 1196 return true; |
| 1130 } | 1197 } |
| 1131 | 1198 |
| 1132 bool BrowserPlugin::handleDragStatusUpdate(WebKit::WebDragStatus drag_status, | 1199 bool BrowserPluginImpl::handleDragStatusUpdate( |
| 1133 const WebKit::WebDragData& drag_data, | 1200 WebKit::WebDragStatus drag_status, |
| 1134 WebKit::WebDragOperationsMask mask, | 1201 const WebKit::WebDragData& drag_data, |
| 1135 const WebKit::WebPoint& position, | 1202 WebKit::WebDragOperationsMask mask, |
| 1136 const WebKit::WebPoint& screen) { | 1203 const WebKit::WebPoint& position, |
| 1204 const WebKit::WebPoint& screen) { |
| 1137 if (guest_crashed_ || !navigate_src_sent_) | 1205 if (guest_crashed_ || !navigate_src_sent_) |
| 1138 return false; | 1206 return false; |
| 1139 browser_plugin_manager()->Send( | 1207 browser_plugin_manager()->Send(new BrowserPluginHostMsg_DragStatusUpdate( |
| 1140 new BrowserPluginHostMsg_DragStatusUpdate( | 1208 render_view_routing_id_, |
| 1141 render_view_routing_id_, | 1209 instance_id_, |
| 1142 instance_id_, | 1210 drag_status, |
| 1143 drag_status, | 1211 WebDropData(drag_data), |
| 1144 WebDropData(drag_data), | 1212 mask, |
| 1145 mask, | 1213 position)); |
| 1146 position)); | |
| 1147 return false; | 1214 return false; |
| 1148 } | 1215 } |
| 1149 | 1216 |
| 1150 void BrowserPlugin::didReceiveResponse( | 1217 void BrowserPluginImpl::didReceiveResponse( |
| 1151 const WebKit::WebURLResponse& response) { | 1218 const WebKit::WebURLResponse& response) { |
| 1152 } | 1219 } |
| 1153 | 1220 |
| 1154 void BrowserPlugin::didReceiveData(const char* data, int data_length) { | 1221 void BrowserPluginImpl::didReceiveData(const char* data, int data_length) { |
| 1155 } | 1222 } |
| 1156 | 1223 |
| 1157 void BrowserPlugin::didFinishLoading() { | 1224 void BrowserPluginImpl::didFinishLoading() { |
| 1158 } | 1225 } |
| 1159 | 1226 |
| 1160 void BrowserPlugin::didFailLoading(const WebKit::WebURLError& error) { | 1227 void BrowserPluginImpl::didFailLoading(const WebKit::WebURLError& error) { |
| 1161 } | 1228 } |
| 1162 | 1229 |
| 1163 void BrowserPlugin::didFinishLoadingFrameRequest(const WebKit::WebURL& url, | 1230 void BrowserPluginImpl::didFinishLoadingFrameRequest(const WebKit::WebURL& url, |
| 1164 void* notify_data) { | 1231 void* notify_data) { |
| 1165 } | 1232 } |
| 1166 | 1233 |
| 1167 void BrowserPlugin::didFailLoadingFrameRequest( | 1234 void BrowserPluginImpl::didFailLoadingFrameRequest( |
| 1168 const WebKit::WebURL& url, | 1235 const WebKit::WebURL& url, |
| 1169 void* notify_data, | 1236 void* notify_data, |
| 1170 const WebKit::WebURLError& error) { | 1237 const WebKit::WebURLError& error) { |
| 1171 } | 1238 } |
| 1172 | 1239 |
| 1173 } // namespace content | 1240 } // namespace content |
| OLD | NEW |