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

Side by Side 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: Remove hanging request on garbage collection, yay! 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 container()->requestTouchEventType(accept ? 530 container()->requestTouchEventType(accept ?
529 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : 531 WebKit::WebPluginContainer::TouchEventRequestTypeRaw :
530 WebKit::WebPluginContainer::TouchEventRequestTypeNone); 532 WebKit::WebPluginContainer::TouchEventRequestTypeNone);
531 } 533 }
532 } 534 }
533 535
534 void BrowserPlugin::OnUpdatedName(int instance_id, const std::string& name) { 536 void BrowserPlugin::OnUpdatedName(int instance_id, const std::string& name) {
535 UpdateDOMAttribute(browser_plugin::kAttributeName, name); 537 UpdateDOMAttribute(browser_plugin::kAttributeName, name);
536 } 538 }
537 539
540 void BrowserPlugin::OnRequestMediaAccess(int instance_id,
541 int request_id,
542 const GURL& security_origin) {
543 if (!HasEventListeners(browser_plugin::kEventRequestPermission)) {
544 // Automatically deny the request if there are no event listeners for
545 // permissionrequest.
546 RespondMediaAccess(request_id, false /* allow */);
547 return;
548 }
549 DCHECK(!media_access_pending_request_ids_.count(request_id));
550 media_access_pending_request_ids_.insert(request_id);
551
552 std::map<std::string, base::Value*> props;
553 props[browser_plugin::kPermission] =
554 base::Value::CreateStringValue(browser_plugin::kPermissionTypeMedia);
555 props[browser_plugin::kRequestId] =
556 base::Value::CreateIntegerValue(request_id);
557 props[browser_plugin::kURL] =
558 base::Value::CreateStringValue(security_origin.spec());
559 TriggerEvent(browser_plugin::kEventRequestPermission, &props);
560 }
561
562 bool BrowserPlugin::HasEventListeners(const std::string& event_name) {
563 if (!container())
564 return false;
565
566 // TODO(lazyboy): Fix before submitting: use ancestor list instead similar to
567 // window.open CL, so bubbling is supported.
568 WebKit::WebNode parent = container()->element().parentNode();
569 if (!parent.isNull() && !parent.shadowHost().isNull()) {
570 WebKit::WebElement shadow_host = parent.shadowHost();
571 return shadow_host.hasEventListeners(
572 WebKit::WebString::fromUTF8(event_name));
573 }
574 return false;
575 }
576
538 void BrowserPlugin::OnUpdateRect( 577 void BrowserPlugin::OnUpdateRect(
539 int instance_id, 578 int instance_id,
540 const BrowserPluginMsg_UpdateRect_Params& params) { 579 const BrowserPluginMsg_UpdateRect_Params& params) {
541 bool use_new_damage_buffer = !backing_store_; 580 bool use_new_damage_buffer = !backing_store_;
542 BrowserPluginHostMsg_AutoSize_Params auto_size_params; 581 BrowserPluginHostMsg_AutoSize_Params auto_size_params;
543 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; 582 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params;
544 // If we have a pending damage buffer, and the guest has begun to use the 583 // If we have a pending damage buffer, and the guest has begun to use the
545 // damage buffer then we know the guest will no longer use the current 584 // damage buffer then we know the guest will no longer use the current
546 // damage buffer. At this point, we drop the current damage buffer, and 585 // damage buffer. At this point, we drop the current damage buffer, and
547 // mark the pending damage buffer as the current damage buffer. 586 // mark the pending damage buffer as the current damage buffer.
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 // wrapper/shim (e.g. <webview> tag) should receive these events, and expose a 814 // wrapper/shim (e.g. <webview> tag) should receive these events, and expose a
776 // more appropriate (and stable) event to the consumers as part of the API. 815 // more appropriate (and stable) event to the consumers as part of the API.
777 event.initCustomEvent( 816 event.initCustomEvent(
778 WebKit::WebString::fromUTF8(GetInternalEventName(event_name.c_str())), 817 WebKit::WebString::fromUTF8(GetInternalEventName(event_name.c_str())),
779 false, false, 818 false, false,
780 WebKit::WebSerializedScriptValue::serialize( 819 WebKit::WebSerializedScriptValue::serialize(
781 v8::String::New(json_string.c_str(), json_string.size()))); 820 v8::String::New(json_string.c_str(), json_string.size())));
782 container()->element().dispatchEvent(event); 821 container()->element().dispatchEvent(event);
783 } 822 }
784 823
824 void BrowserPlugin::OnMediaRequestGarbageCollected(int request_id) {
825 // Remove from alive objects.
826 std::map<int, MediaAccessAliveV8RequestItem*>::iterator iter =
827 media_access_alive_v8_request_objects_.find(request_id);
828 if (iter != media_access_alive_v8_request_objects_.end()) {
829 MediaAccessAliveV8RequestItem* item = iter->second;
830 DCHECK(*item->first == request_id);
831 media_access_alive_v8_request_objects_.erase(iter);
832 delete item->first;
833 }
834
835 // If a decision has not been made for this request yet, deny it.
836 RespondMediaAccessIfPending(request_id, false /* allow */);
837 }
838
839 void BrowserPlugin::PersistRequestObject(const NPVariant* request, int id) {
Fady Samuel 2013/02/07 15:40:34 Can we make this more general to allow for window.
lazyboy 2013/02/07 21:24:41 We need a centralized id generation in that case,
840 v8::Persistent<v8::Value> weak_request =
841 v8::Persistent<v8::Value>::New(WebKit::WebBindings::toV8Value(request));
842 int *new_request_id = new int(id);
Fady Samuel 2013/02/07 15:40:34 why are you allocating memory on the heap here? We
lazyboy 2013/02/07 21:24:41 I thought reference to map element is not guarante
843 std::pair<int*, BrowserPlugin*>* req =
844 new std::pair<int*, BrowserPlugin*>(
845 std::make_pair(new_request_id, this));
846 DCHECK(media_access_alive_v8_request_objects_.find(id) ==
847 media_access_alive_v8_request_objects_.end());
848 if (media_access_alive_v8_request_objects_.find(id) ==
849 media_access_alive_v8_request_objects_.end()) {
850 media_access_alive_v8_request_objects_[*new_request_id] = req;
851 weak_request.MakeWeak(req, WeakCallbackForPersistObject);
852 }
853 }
854
855 void BrowserPlugin::WeakCallbackForPersistObject(
856 v8::Persistent<v8::Value> object, void* param) {
857 v8::Persistent<v8::Object> persistent_object =
858 v8::Persistent<v8::Object>::Cast(object);
859
860 MediaAccessAliveV8RequestItem* item_ptr =
861 static_cast<std::pair<int*, BrowserPlugin*>*>(param);
Fady Samuel 2013/02/07 15:40:34 We're leaking memory here. Seem my suggestion abov
lazyboy 2013/02/07 21:24:41 See above, fixed hopefully.
862 int request_id = *(item_ptr->first);
863 BrowserPlugin* plugin = item_ptr->second;
864 plugin->OnMediaRequestGarbageCollected(request_id);
865
866 persistent_object.Dispose();
867 }
868
785 void BrowserPlugin::Back() { 869 void BrowserPlugin::Back() {
786 if (!navigate_src_sent_) 870 if (!navigate_src_sent_)
787 return; 871 return;
788 browser_plugin_manager()->Send( 872 browser_plugin_manager()->Send(
789 new BrowserPluginHostMsg_Go(render_view_routing_id_, 873 new BrowserPluginHostMsg_Go(render_view_routing_id_,
790 instance_id_, -1)); 874 instance_id_, -1));
791 } 875 }
792 876
793 void BrowserPlugin::Forward() { 877 void BrowserPlugin::Forward() {
794 if (!navigate_src_sent_) 878 if (!navigate_src_sent_)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 bool embedder_focused = false; 929 bool embedder_focused = false;
846 if (render_view_) 930 if (render_view_)
847 embedder_focused = render_view_->has_focus(); 931 embedder_focused = render_view_->has_focus();
848 return plugin_focused_ && embedder_focused; 932 return plugin_focused_ && embedder_focused;
849 } 933 }
850 934
851 WebKit::WebPluginContainer* BrowserPlugin::container() const { 935 WebKit::WebPluginContainer* BrowserPlugin::container() const {
852 return container_; 936 return container_;
853 } 937 }
854 938
939 void BrowserPlugin::RespondMediaAccess(int request_id, bool allow) {
940 browser_plugin_manager()->Send(
941 new BrowserPluginHostMsg_AllowMediaAccess(
Fady Samuel 2013/02/07 15:40:34 Given the review overhead for introducing new IPCs
lazyboy 2013/02/07 21:24:41 This part should be straight forward. Done.
942 render_view_->GetRoutingID(), instance_id_, request_id, allow));
943 }
944
945 void BrowserPlugin::RespondMediaAccessIfPending(int request_id, bool allow) {
946 MediaAccessPendingRequestIds::iterator iter =
947 media_access_pending_request_ids_.find(request_id);
948 if (iter == media_access_pending_request_ids_.end())
949 return;
950 media_access_pending_request_ids_.erase(iter);
951 RespondMediaAccess(request_id, allow);
952 }
953
954 void BrowserPlugin::OnListenerCallMediaAccess(int request_id, bool allow) {
955 RespondMediaAccessIfPending(request_id, allow);
956 }
957
855 bool BrowserPlugin::initialize(WebPluginContainer* container) { 958 bool BrowserPlugin::initialize(WebPluginContainer* container) {
856 container_ = container; 959 container_ = container;
857 container_->setWantsWheelEvents(true); 960 container_->setWantsWheelEvents(true);
858 ParseAttributes(); 961 ParseAttributes();
859 return true; 962 return true;
860 } 963 }
861 964
862 void BrowserPlugin::EnableCompositing(bool enable) { 965 void BrowserPlugin::EnableCompositing(bool enable) {
863 if (compositing_enabled_ == enable) 966 if (compositing_enabled_ == enable)
864 return; 967 return;
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 void* notify_data) { 1270 void* notify_data) {
1168 } 1271 }
1169 1272
1170 void BrowserPlugin::didFailLoadingFrameRequest( 1273 void BrowserPlugin::didFailLoadingFrameRequest(
1171 const WebKit::WebURL& url, 1274 const WebKit::WebURL& url,
1172 void* notify_data, 1275 void* notify_data,
1173 const WebKit::WebURLError& error) { 1276 const WebKit::WebURLError& error) {
1174 } 1277 }
1175 1278
1176 } // namespace content 1279 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698