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

Unified Diff: content/renderer/browser_plugin/browser_plugin.cc

Issue 11093080: <webview>: First stab at implementing media permission request for guests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments from Fady, fix tests. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 0dbc53fe80a50dc306b41a135f9f866d77bab3ff..c11bb3151aa15f770df1f2993e9fd97ae490788e 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;
@@ -535,6 +537,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) {
+ if (!container())
+ return false;
+
+ // TODO(lazyboy): Fix before submitting: use ancestor list instead similar to
+ // window.open CL, so bubbling is supported.
+ WebKit::WebNode parent = container()->element().parentNode();
+ if (!parent.isNull() && !parent.shadowHost().isNull()) {
+ WebKit::WebElement shadow_host = parent.shadowHost();
+ return shadow_host.hasEventListeners(
+ WebKit::WebString::fromUTF8(event_name));
+ }
+ return false;
+}
+
void BrowserPlugin::OnUpdateRect(
int instance_id,
const BrowserPluginMsg_UpdateRect_Params& params) {
@@ -782,6 +821,52 @@ void BrowserPlugin::TriggerEvent(const std::string& event_name,
container()->element().dispatchEvent(event);
}
+void BrowserPlugin::OnMediaRequestGarbageCollected(int request_id) {
+ // Remove from alive objects.
+ std::map<int, MediaAccessAliveV8RequestItem>::iterator iter =
+ media_access_alive_v8_request_objects_.find(request_id);
+ if (iter != media_access_alive_v8_request_objects_.end()) {
+ DCHECK(iter->second.first == request_id);
+ media_access_alive_v8_request_objects_.erase(iter);
+ }
+
+ // If a decision has not been made for this request yet, deny it.
+ RespondMediaAccessIfPending(request_id, false /* allow */);
+}
+
+void BrowserPlugin::PersistRequestObject(const NPVariant* request, int id) {
+ DCHECK(media_access_alive_v8_request_objects_.find(id) ==
+ media_access_alive_v8_request_objects_.end());
+ if (media_access_alive_v8_request_objects_.find(id) ==
+ media_access_alive_v8_request_objects_.end()) {
+ v8::Persistent<v8::Value> weak_request =
+ v8::Persistent<v8::Value>::New(WebKit::WebBindings::toV8Value(request));
+
+ std::pair<std::map<int, MediaAccessAliveV8RequestItem>::iterator, bool>
+ result = media_access_alive_v8_request_objects_.insert(
+ std::make_pair(id, std::make_pair(id, this)));
+ DCHECK(result.second); // Inserted in the map.
+ if (result.second) {
+ MediaAccessAliveV8RequestItem* request_item = &result.first->second;
+ weak_request.MakeWeak(request_item, WeakCallbackForPersistObject);
+ }
+ }
+}
+
+void BrowserPlugin::WeakCallbackForPersistObject(
Fady Samuel 2013/02/07 21:41:24 It just occurred to me: what happens if BrowserPlu
lazyboy 2013/02/07 22:59:27 Good catch here. Using WeakPtr and allocating map
+ v8::Persistent<v8::Value> object, void* param) {
+ v8::Persistent<v8::Object> persistent_object =
+ v8::Persistent<v8::Object>::Cast(object);
+
+ MediaAccessAliveV8RequestItem* item_ptr =
+ static_cast<MediaAccessAliveV8RequestItem*>(param);
+ int request_id = item_ptr->first;
+ BrowserPlugin* plugin = item_ptr->second;
+ plugin->OnMediaRequestGarbageCollected(request_id);
+
+ persistent_object.Dispose();
+}
+
void BrowserPlugin::Back() {
if (!navigate_src_sent_)
return;
@@ -852,6 +937,26 @@ WebKit::WebPluginContainer* BrowserPlugin::container() const {
return container_;
}
+void BrowserPlugin::RespondMediaAccess(int request_id, bool allow) {
+ browser_plugin_manager()->Send(
+ new BrowserPluginHostMsg_AllowPermissionAccess(
+ render_view_->GetRoutingID(), instance_id_,
+ browser_plugin::kPermissionTypeMedia, request_id, allow));
+}
+
+void BrowserPlugin::RespondMediaAccessIfPending(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);
+}
+
+void BrowserPlugin::OnListenerCallMediaAccess(int request_id, bool allow) {
+ RespondMediaAccessIfPending(request_id, allow);
+}
+
bool BrowserPlugin::initialize(WebPluginContainer* container) {
container_ = container;
container_->setWantsWheelEvents(true);
« no previous file with comments | « content/renderer/browser_plugin/browser_plugin.h ('k') | content/renderer/browser_plugin/browser_plugin_bindings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698