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/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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 // the raw pointer to the broker. Assumes maximum of one copy of broker exists. | 469 // the raw pointer to the broker. Assumes maximum of one copy of broker exists. |
470 bool PepperPluginDelegateImpl::StopWaitingForBrokerConnection( | 470 bool PepperPluginDelegateImpl::StopWaitingForBrokerConnection( |
471 PepperBrokerImpl* broker) { | 471 PepperBrokerImpl* broker) { |
472 for (BrokerMap::iterator i(&pending_connect_broker_); | 472 for (BrokerMap::iterator i(&pending_connect_broker_); |
473 !i.IsAtEnd(); i.Advance()) { | 473 !i.IsAtEnd(); i.Advance()) { |
474 if (i.GetCurrentValue()->get() == broker) { | 474 if (i.GetCurrentValue()->get() == broker) { |
475 pending_connect_broker_.Remove(i.GetCurrentKey()); | 475 pending_connect_broker_.Remove(i.GetCurrentKey()); |
476 return true; | 476 return true; |
477 } | 477 } |
478 } | 478 } |
| 479 |
479 return false; | 480 return false; |
480 } | 481 } |
481 | 482 |
482 void PepperPluginDelegateImpl::ViewWillInitiatePaint() { | 483 void PepperPluginDelegateImpl::ViewWillInitiatePaint() { |
483 // Notify all of our instances that we started painting. This is used for | 484 // Notify all of our instances that we started painting. This is used for |
484 // internal bookkeeping only, so we know that the set can not change under | 485 // internal bookkeeping only, so we know that the set can not change under |
485 // us. | 486 // us. |
486 for (std::set<webkit::ppapi::PluginInstance*>::iterator i = | 487 for (std::set<webkit::ppapi::PluginInstance*>::iterator i = |
487 active_instances_.begin(); | 488 active_instances_.begin(); |
488 i != active_instances_.end(); ++i) | 489 i != active_instances_.end(); ++i) |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 AsWeakPtr(), device_id, static_cast<int>(sample_rate), | 803 AsWeakPtr(), device_id, static_cast<int>(sample_rate), |
803 static_cast<int>(sample_count), client); | 804 static_cast<int>(sample_count), client); |
804 } | 805 } |
805 | 806 |
806 // If a broker has not already been created for this plugin, creates one. | 807 // If a broker has not already been created for this plugin, creates one. |
807 webkit::ppapi::PluginDelegate::Broker* | 808 webkit::ppapi::PluginDelegate::Broker* |
808 PepperPluginDelegateImpl::ConnectToBroker( | 809 PepperPluginDelegateImpl::ConnectToBroker( |
809 webkit::ppapi::PPB_Broker_Impl* client) { | 810 webkit::ppapi::PPB_Broker_Impl* client) { |
810 DCHECK(client); | 811 DCHECK(client); |
811 | 812 |
812 // If a broker needs to be created, this will ensure it does not get deleted | |
813 // before Connect() adds a reference. | |
814 scoped_refptr<PepperBrokerImpl> broker_impl; | |
815 | |
816 webkit::ppapi::PluginModule* plugin_module = | 813 webkit::ppapi::PluginModule* plugin_module = |
817 webkit::ppapi::ResourceHelper::GetPluginModule(client); | 814 webkit::ppapi::ResourceHelper::GetPluginModule(client); |
818 if (!plugin_module) | 815 if (!plugin_module) |
819 return NULL; | 816 return NULL; |
820 | 817 |
821 webkit::ppapi::PluginDelegate::Broker* broker = plugin_module->GetBroker(); | 818 scoped_refptr<PepperBrokerImpl> broker = |
822 if (!broker) { | 819 static_cast<PepperBrokerImpl*>(plugin_module->GetBroker()); |
823 broker_impl = CreateBroker(plugin_module); | 820 if (!broker.get()) { |
824 if (!broker_impl.get()) | 821 broker = CreateBroker(plugin_module); |
| 822 if (!broker.get()) |
825 return NULL; | 823 return NULL; |
826 broker = broker_impl; | |
827 } | 824 } |
828 | 825 |
829 // Adds a reference, ensuring not deleted when broker_impl goes out of scope. | 826 int request_id = pending_permission_requests_.Add( |
830 broker->Connect(client); | 827 new base::WeakPtr<webkit::ppapi::PPB_Broker_Impl>(client->AsWeakPtr())); |
| 828 if (!render_view_->Send( |
| 829 new ViewHostMsg_RequestPpapiBrokerPermission( |
| 830 render_view_->routing_id(), |
| 831 request_id, |
| 832 client->GetDocumentUrl(), |
| 833 plugin_module->path()))) { |
| 834 return NULL; |
| 835 } |
| 836 |
| 837 // Adds a reference, ensuring that the broker is not deleted when |
| 838 // |broker| goes out of scope. |
| 839 broker->AddPendingConnect(client); |
| 840 |
831 return broker; | 841 return broker; |
832 } | 842 } |
833 | 843 |
| 844 void PepperPluginDelegateImpl::OnPpapiBrokerPermissionResult( |
| 845 int request_id, |
| 846 bool result) { |
| 847 scoped_ptr<base::WeakPtr<webkit::ppapi::PPB_Broker_Impl> > client_ptr( |
| 848 pending_permission_requests_.Lookup(request_id)); |
| 849 DCHECK(client_ptr.get()); |
| 850 pending_permission_requests_.Remove(request_id); |
| 851 base::WeakPtr<webkit::ppapi::PPB_Broker_Impl> client = *client_ptr; |
| 852 if (!client) |
| 853 return; |
| 854 |
| 855 webkit::ppapi::PluginModule* plugin_module = |
| 856 webkit::ppapi::ResourceHelper::GetPluginModule(client); |
| 857 if (!plugin_module) |
| 858 return; |
| 859 |
| 860 PepperBrokerImpl* broker = |
| 861 static_cast<PepperBrokerImpl*>(plugin_module->GetBroker()); |
| 862 broker->OnBrokerPermissionResult(client, result); |
| 863 } |
| 864 |
834 bool PepperPluginDelegateImpl::AsyncOpenFile( | 865 bool PepperPluginDelegateImpl::AsyncOpenFile( |
835 const FilePath& path, | 866 const FilePath& path, |
836 int flags, | 867 int flags, |
837 const AsyncOpenFileCallback& callback) { | 868 const AsyncOpenFileCallback& callback) { |
838 int message_id = pending_async_open_files_.Add( | 869 int message_id = pending_async_open_files_.Add( |
839 new AsyncOpenFileCallback(callback)); | 870 new AsyncOpenFileCallback(callback)); |
840 IPC::Message* msg = new ViewHostMsg_AsyncOpenFile( | 871 IPC::Message* msg = new ViewHostMsg_AsyncOpenFile( |
841 render_view_->routing_id(), path, flags, message_id); | 872 render_view_->routing_id(), path, flags, message_id); |
842 return render_view_->Send(msg); | 873 return render_view_->Send(msg); |
843 } | 874 } |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1788 else | 1819 else |
1789 return render_view_->mouse_lock_dispatcher(); | 1820 return render_view_->mouse_lock_dispatcher(); |
1790 } | 1821 } |
1791 | 1822 |
1792 webkit_glue::ClipboardClient* | 1823 webkit_glue::ClipboardClient* |
1793 PepperPluginDelegateImpl::CreateClipboardClient() const { | 1824 PepperPluginDelegateImpl::CreateClipboardClient() const { |
1794 return new RendererClipboardClient; | 1825 return new RendererClipboardClient; |
1795 } | 1826 } |
1796 | 1827 |
1797 } // namespace content | 1828 } // namespace content |
OLD | NEW |