Chromium Code Reviews| Index: content/renderer/browser_plugin/browser_plugin.cc |
| diff --git a/content/renderer/browser_plugin/browser_plugin.cc b/content/renderer/browser_plugin/browser_plugin.cc |
| index 6798d96c6cee94b01e6b72980f587b1d6d03b5d8..ba9b252579d2d14f67b24fc9fe37e3efc963975a 100644 |
| --- a/content/renderer/browser_plugin/browser_plugin.cc |
| +++ b/content/renderer/browser_plugin/browser_plugin.cc |
| @@ -134,6 +134,8 @@ bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { |
| OnShouldAcceptTouchEvents) |
| IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdatedName, OnUpdatedName) |
| IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect) |
| + IPC_MESSAGE_HANDLER(BrowserPluginMsg_RequestMediaAccess, |
| + OnRequestMediaAccess) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| return handled; |
| @@ -517,6 +519,43 @@ void BrowserPlugin::OnUpdatedName(int instance_id, const std::string& name) { |
| UpdateDOMAttribute(browser_plugin::kAttributeName, name); |
| } |
| +void BrowserPlugin::OnRequestMediaAccess(int instance_id, |
| + int request_id, |
| + const GURL& security_origin) { |
| + if (!HasEventListeners(browser_plugin::kEventRequestPermission)) { |
| + // Automatically deny the request if there are no event listeners for |
| + // permissionrequest. |
| + RespondMediaAccess(request_id, false /* allow */); |
| + return; |
| + } |
| + DCHECK(!media_access_pending_request_ids_.count(request_id)); |
| + media_access_pending_request_ids_.insert(request_id); |
| + |
| + std::map<std::string, base::Value*> props; |
| + props[browser_plugin::kPermission] = |
| + base::Value::CreateStringValue(browser_plugin::kPermissionTypeMedia); |
| + props[browser_plugin::kRequestId] = |
| + base::Value::CreateIntegerValue(request_id); |
| + props[browser_plugin::kURL] = |
| + base::Value::CreateStringValue(security_origin.spec()); |
| + TriggerEvent(browser_plugin::kEventRequestPermission, &props); |
| +} |
| + |
| +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
|
| + if (!container()) |
| + return false; |
| + |
| + WebKit::WebNode parent = container()->element().parentNode(); |
| + if (!parent.isNull() && parent.isShadowRoot()) { |
| + WebKit::WebElement shadow_host = parent.shadowHost(); |
| + if (!shadow_host.isNull()) { |
| + return shadow_host.hasEventListeners( |
| + WebKit::WebString::fromUTF8(event_name)); |
| + } |
| + } |
| + return false; |
| +} |
| + |
| void BrowserPlugin::OnUpdateRect( |
| int instance_id, |
| const BrowserPluginMsg_UpdateRect_Params& params) { |
| @@ -828,6 +867,23 @@ WebKit::WebPluginContainer* BrowserPlugin::container() const { |
| return container_; |
| } |
| +void BrowserPlugin::RespondMediaAccess(int request_id, bool allow) { |
| + browser_plugin_manager()->Send( |
| + new BrowserPluginHostMsg_AllowMediaAccess(render_view_->GetRoutingID(), |
| + instance_id_, |
| + request_id, |
| + allow)); |
| +} |
| + |
| +void BrowserPlugin::OnListenerCallMediaAccess(int request_id, bool allow) { |
| + MediaAccessPendingRequestIds::iterator iter = |
| + media_access_pending_request_ids_.find(request_id); |
| + if (iter == media_access_pending_request_ids_.end()) |
| + return; |
| + media_access_pending_request_ids_.erase(iter); |
| + RespondMediaAccess(request_id, allow); |
| +} |
| + |
| bool BrowserPlugin::initialize(WebPluginContainer* container) { |
| container_ = container; |
| container_->setWantsWheelEvents(true); |