Chromium Code Reviews| 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/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadAbort, OnLoadAbort) | 127 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadAbort, OnLoadAbort) |
| 128 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadCommit, OnLoadCommit) | 128 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadCommit, OnLoadCommit) |
| 129 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadRedirect, OnLoadRedirect) | 129 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadRedirect, OnLoadRedirect) |
| 130 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStart, OnLoadStart) | 130 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStart, OnLoadStart) |
| 131 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStop, OnLoadStop) | 131 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStop, OnLoadStop) |
| 132 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) | 132 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) |
| 133 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, | 133 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, |
| 134 OnShouldAcceptTouchEvents) | 134 OnShouldAcceptTouchEvents) |
| 135 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdatedName, OnUpdatedName) | 135 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdatedName, OnUpdatedName) |
| 136 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect) | 136 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect) |
| 137 IPC_MESSAGE_HANDLER(BrowserPluginMsg_RequestMediaAccess, | |
| 138 OnRequestMediaAccess) | |
| 137 IPC_MESSAGE_UNHANDLED(handled = false) | 139 IPC_MESSAGE_UNHANDLED(handled = false) |
| 138 IPC_END_MESSAGE_MAP() | 140 IPC_END_MESSAGE_MAP() |
| 139 return handled; | 141 return handled; |
| 140 } | 142 } |
| 141 | 143 |
| 142 void BrowserPlugin::UpdateDOMAttribute(const std::string& attribute_name, | 144 void BrowserPlugin::UpdateDOMAttribute(const std::string& attribute_name, |
| 143 const std::string& attribute_value) { | 145 const std::string& attribute_value) { |
| 144 if (!container()) | 146 if (!container()) |
| 145 return; | 147 return; |
| 146 | 148 |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 container()->requestTouchEventType(accept ? | 512 container()->requestTouchEventType(accept ? |
| 511 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : | 513 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : |
| 512 WebKit::WebPluginContainer::TouchEventRequestTypeNone); | 514 WebKit::WebPluginContainer::TouchEventRequestTypeNone); |
| 513 } | 515 } |
| 514 } | 516 } |
| 515 | 517 |
| 516 void BrowserPlugin::OnUpdatedName(int instance_id, const std::string& name) { | 518 void BrowserPlugin::OnUpdatedName(int instance_id, const std::string& name) { |
| 517 UpdateDOMAttribute(browser_plugin::kAttributeName, name); | 519 UpdateDOMAttribute(browser_plugin::kAttributeName, name); |
| 518 } | 520 } |
| 519 | 521 |
| 522 void BrowserPlugin::OnRequestMediaAccess(int instance_id, | |
| 523 int request_id, | |
| 524 const GURL& security_origin) { | |
| 525 if (!HasEventListeners(browser_plugin::kEventRequestPermission)) { | |
| 526 // Automatically deny the request if there are no event listeners for | |
| 527 // permissionrequest. | |
| 528 RespondMediaAccess(request_id, false /* allow */); | |
| 529 return; | |
| 530 } | |
| 531 DCHECK(!media_access_pending_request_ids_.count(request_id)); | |
| 532 media_access_pending_request_ids_.insert(request_id); | |
| 533 | |
| 534 std::map<std::string, base::Value*> props; | |
| 535 props[browser_plugin::kPermission] = | |
| 536 base::Value::CreateStringValue(browser_plugin::kPermissionTypeMedia); | |
| 537 props[browser_plugin::kRequestId] = | |
| 538 base::Value::CreateIntegerValue(request_id); | |
| 539 props[browser_plugin::kURL] = | |
| 540 base::Value::CreateStringValue(security_origin.spec()); | |
| 541 TriggerEvent(browser_plugin::kEventRequestPermission, &props); | |
| 542 } | |
| 543 | |
| 544 bool BrowserPlugin::HasEventListeners(const std::string& event_name) { | |
|
Fady Samuel
2013/02/05 17:53:27
I think you'd need the ancestor list here too, as
lazyboy
2013/02/07 04:38:42
Deferring it for now, added todo, I'll fix once we
| |
| 545 if (!container()) | |
| 546 return false; | |
| 547 | |
| 548 WebKit::WebNode parent = container()->element().parentNode(); | |
| 549 if (!parent.isNull() && parent.isShadowRoot()) { | |
| 550 WebKit::WebElement shadow_host = parent.shadowHost(); | |
| 551 if (!shadow_host.isNull()) { | |
| 552 return shadow_host.hasEventListeners( | |
| 553 WebKit::WebString::fromUTF8(event_name)); | |
| 554 } | |
| 555 } | |
| 556 return false; | |
| 557 } | |
| 558 | |
| 520 void BrowserPlugin::OnUpdateRect( | 559 void BrowserPlugin::OnUpdateRect( |
| 521 int instance_id, | 560 int instance_id, |
| 522 const BrowserPluginMsg_UpdateRect_Params& params) { | 561 const BrowserPluginMsg_UpdateRect_Params& params) { |
| 523 bool use_new_damage_buffer = !backing_store_; | 562 bool use_new_damage_buffer = !backing_store_; |
| 524 BrowserPluginHostMsg_AutoSize_Params auto_size_params; | 563 BrowserPluginHostMsg_AutoSize_Params auto_size_params; |
| 525 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; | 564 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; |
| 526 // If we have a pending damage buffer, and the guest has begun to use the | 565 // If we have a pending damage buffer, and the guest has begun to use the |
| 527 // damage buffer then we know the guest will no longer use the current | 566 // damage buffer then we know the guest will no longer use the current |
| 528 // damage buffer. At this point, we drop the current damage buffer, and | 567 // damage buffer. At this point, we drop the current damage buffer, and |
| 529 // mark the pending damage buffer as the current damage buffer. | 568 // mark the pending damage buffer as the current damage buffer. |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 821 bool embedder_focused = false; | 860 bool embedder_focused = false; |
| 822 if (render_view_) | 861 if (render_view_) |
| 823 embedder_focused = render_view_->has_focus(); | 862 embedder_focused = render_view_->has_focus(); |
| 824 return plugin_focused_ && embedder_focused; | 863 return plugin_focused_ && embedder_focused; |
| 825 } | 864 } |
| 826 | 865 |
| 827 WebKit::WebPluginContainer* BrowserPlugin::container() const { | 866 WebKit::WebPluginContainer* BrowserPlugin::container() const { |
| 828 return container_; | 867 return container_; |
| 829 } | 868 } |
| 830 | 869 |
| 870 void BrowserPlugin::RespondMediaAccess(int request_id, bool allow) { | |
| 871 browser_plugin_manager()->Send( | |
| 872 new BrowserPluginHostMsg_AllowMediaAccess(render_view_->GetRoutingID(), | |
| 873 instance_id_, | |
| 874 request_id, | |
| 875 allow)); | |
| 876 } | |
| 877 | |
| 878 void BrowserPlugin::OnListenerCallMediaAccess(int request_id, bool allow) { | |
| 879 MediaAccessPendingRequestIds::iterator iter = | |
| 880 media_access_pending_request_ids_.find(request_id); | |
| 881 if (iter == media_access_pending_request_ids_.end()) | |
| 882 return; | |
| 883 media_access_pending_request_ids_.erase(iter); | |
| 884 RespondMediaAccess(request_id, allow); | |
| 885 } | |
| 886 | |
| 831 bool BrowserPlugin::initialize(WebPluginContainer* container) { | 887 bool BrowserPlugin::initialize(WebPluginContainer* container) { |
| 832 container_ = container; | 888 container_ = container; |
| 833 container_->setWantsWheelEvents(true); | 889 container_->setWantsWheelEvents(true); |
| 834 ParseAttributes(); | 890 ParseAttributes(); |
| 835 return true; | 891 return true; |
| 836 } | 892 } |
| 837 | 893 |
| 838 void BrowserPlugin::EnableCompositing(bool enable) { | 894 void BrowserPlugin::EnableCompositing(bool enable) { |
| 839 if (compositing_enabled_ == enable) | 895 if (compositing_enabled_ == enable) |
| 840 return; | 896 return; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1143 void* notify_data) { | 1199 void* notify_data) { |
| 1144 } | 1200 } |
| 1145 | 1201 |
| 1146 void BrowserPlugin::didFailLoadingFrameRequest( | 1202 void BrowserPlugin::didFailLoadingFrameRequest( |
| 1147 const WebKit::WebURL& url, | 1203 const WebKit::WebURL& url, |
| 1148 void* notify_data, | 1204 void* notify_data, |
| 1149 const WebKit::WebURLError& error) { | 1205 const WebKit::WebURLError& error) { |
| 1150 } | 1206 } |
| 1151 | 1207 |
| 1152 } // namespace content | 1208 } // namespace content |
| OLD | NEW |