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

Side by Side Diff: content/renderer/pepper/pepper_plugin_delegate_impl.cc

Issue 10854040: Add hooks to content to request permission to connect to the PPAPI broker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 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/pepper/pepper_plugin_delegate_impl.h" 5 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <cstddef> 8 #include <cstddef>
9 #include <map> 9 #include <map>
10 #include <queue> 10 #include <queue>
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 // the raw pointer to the broker. Assumes maximum of one copy of broker exists. 470 // the raw pointer to the broker. Assumes maximum of one copy of broker exists.
471 bool PepperPluginDelegateImpl::StopWaitingForBrokerConnection( 471 bool PepperPluginDelegateImpl::StopWaitingForBrokerConnection(
472 PepperBrokerImpl* broker) { 472 PepperBrokerImpl* broker) {
473 for (BrokerMap::iterator i(&pending_connect_broker_); 473 for (BrokerMap::iterator i(&pending_connect_broker_);
474 !i.IsAtEnd(); i.Advance()) { 474 !i.IsAtEnd(); i.Advance()) {
475 if (i.GetCurrentValue()->get() == broker) { 475 if (i.GetCurrentValue()->get() == broker) {
476 pending_connect_broker_.Remove(i.GetCurrentKey()); 476 pending_connect_broker_.Remove(i.GetCurrentKey());
477 return true; 477 return true;
478 } 478 }
479 } 479 }
480
480 return false; 481 return false;
481 } 482 }
482 483
483 void PepperPluginDelegateImpl::ViewWillInitiatePaint() { 484 void PepperPluginDelegateImpl::ViewWillInitiatePaint() {
484 // Notify all of our instances that we started painting. This is used for 485 // Notify all of our instances that we started painting. This is used for
485 // internal bookkeeping only, so we know that the set can not change under 486 // internal bookkeeping only, so we know that the set can not change under
486 // us. 487 // us.
487 for (std::set<webkit::ppapi::PluginInstance*>::iterator i = 488 for (std::set<webkit::ppapi::PluginInstance*>::iterator i =
488 active_instances_.begin(); 489 active_instances_.begin();
489 i != active_instances_.end(); ++i) 490 i != active_instances_.end(); ++i)
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 AsWeakPtr(), device_id, static_cast<int>(sample_rate), 804 AsWeakPtr(), device_id, static_cast<int>(sample_rate),
804 static_cast<int>(sample_count), client); 805 static_cast<int>(sample_count), client);
805 } 806 }
806 807
807 // If a broker has not already been created for this plugin, creates one. 808 // If a broker has not already been created for this plugin, creates one.
808 webkit::ppapi::PluginDelegate::Broker* 809 webkit::ppapi::PluginDelegate::Broker*
809 PepperPluginDelegateImpl::ConnectToBroker( 810 PepperPluginDelegateImpl::ConnectToBroker(
810 webkit::ppapi::PPB_Broker_Impl* client) { 811 webkit::ppapi::PPB_Broker_Impl* client) {
811 DCHECK(client); 812 DCHECK(client);
812 813
813 // If a broker needs to be created, this will ensure it does not get deleted
814 // before Connect() adds a reference.
815 scoped_refptr<PepperBrokerImpl> broker_impl;
816
817 webkit::ppapi::PluginModule* plugin_module = 814 webkit::ppapi::PluginModule* plugin_module =
818 webkit::ppapi::ResourceHelper::GetPluginModule(client); 815 webkit::ppapi::ResourceHelper::GetPluginModule(client);
819 if (!plugin_module) 816 if (!plugin_module)
820 return NULL; 817 return NULL;
821 818
822 webkit::ppapi::PluginDelegate::Broker* broker = plugin_module->GetBroker(); 819 scoped_refptr<PepperBrokerImpl> broker =
823 if (!broker) { 820 static_cast<PepperBrokerImpl*>(plugin_module->GetBroker());
824 broker_impl = CreateBroker(plugin_module); 821 if (!broker.get()) {
825 if (!broker_impl.get()) 822 broker = CreateBroker(plugin_module);
823 if (!broker.get())
826 return NULL; 824 return NULL;
827 broker = broker_impl;
828 } 825 }
829 826
830 // Adds a reference, ensuring not deleted when broker_impl goes out of scope. 827 int request_id = pending_permission_requests_.Add(
831 broker->Connect(client); 828 new base::WeakPtr<webkit::ppapi::PPB_Broker_Impl>(client->AsWeakPtr()));
829 if (!render_view_->Send(
830 new ViewHostMsg_RequestPpapiBrokerPermission(
831 render_view_->routing_id(),
832 request_id,
833 client->GetDocumentUrl(),
834 plugin_module->path()))) {
835 return NULL;
836 }
837
838 // Adds a reference, ensuring that the broker is not deleted when
839 // |broker| goes out of scope.
840 broker->AddPendingConnect(client);
841
832 return broker; 842 return broker;
833 } 843 }
834 844
845 void PepperPluginDelegateImpl::OnPpapiBrokerPermissionResult(
846 int request_id,
847 bool result) {
848 base::WeakPtr<webkit::ppapi::PPB_Broker_Impl> client =
849 *(pending_permission_requests_.Lookup(request_id));
850 if (client) {
851 webkit::ppapi::PluginModule* plugin_module =
852 webkit::ppapi::ResourceHelper::GetPluginModule(client);
brettw 2012/08/20 05:29:47 You may want to null check this. Could the plugin
Bernhard Bauer 2012/08/20 14:43:20 Done. Presumably the client would have gone away a
853 PepperBrokerImpl* broker =
854 static_cast<PepperBrokerImpl*>(plugin_module->GetBroker());
855 broker->OnBrokerPermissionResult(client, result);
856 }
857
858 pending_permission_requests_.Remove(request_id);
859 }
860
835 bool PepperPluginDelegateImpl::AsyncOpenFile( 861 bool PepperPluginDelegateImpl::AsyncOpenFile(
836 const FilePath& path, 862 const FilePath& path,
837 int flags, 863 int flags,
838 const AsyncOpenFileCallback& callback) { 864 const AsyncOpenFileCallback& callback) {
839 int message_id = pending_async_open_files_.Add( 865 int message_id = pending_async_open_files_.Add(
840 new AsyncOpenFileCallback(callback)); 866 new AsyncOpenFileCallback(callback));
841 IPC::Message* msg = new ViewHostMsg_AsyncOpenFile( 867 IPC::Message* msg = new ViewHostMsg_AsyncOpenFile(
842 render_view_->routing_id(), path, flags, message_id); 868 render_view_->routing_id(), path, flags, message_id);
843 return render_view_->Send(msg); 869 return render_view_->Send(msg);
844 } 870 }
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 else 1825 else
1800 return render_view_->mouse_lock_dispatcher(); 1826 return render_view_->mouse_lock_dispatcher();
1801 } 1827 }
1802 1828
1803 webkit_glue::ClipboardClient* 1829 webkit_glue::ClipboardClient*
1804 PepperPluginDelegateImpl::CreateClipboardClient() const { 1830 PepperPluginDelegateImpl::CreateClipboardClient() const {
1805 return new RendererClipboardClient; 1831 return new RendererClipboardClient;
1806 } 1832 }
1807 1833
1808 } // namespace content 1834 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698