diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-17 04:15:10 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-17 04:15:10 +0000 |
commit | 07d0a6bf3c7b947e76ac2d05649fb5e8ebce6f6e (patch) | |
tree | e4489dcaa64a9a09a7d3aff67c0f9c5c4743fa36 | |
parent | f27ebb8c25f88e5caea6ff3bc184b6ec47d369bc (diff) | |
download | chromium_src-07d0a6bf3c7b947e76ac2d05649fb5e8ebce6f6e.zip chromium_src-07d0a6bf3c7b947e76ac2d05649fb5e8ebce6f6e.tar.gz chromium_src-07d0a6bf3c7b947e76ac2d05649fb5e8ebce6f6e.tar.bz2 |
Simplify PPB_NetworkMonitor proxy.
The new proxy is based on ppapi::proxy::PluginResource and
ppapi::host::ResourceHost which simplifies code significantly. Also
the permission check is consistent with socket APIs now.
BUG=281781
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=223482
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=223494
R=brettw@chromium.org, yzshen@chromium.org
Review URL: https://codereview.chromium.org/23819033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223535 0039d316-1c4b-4281-b951-d872f2087c98
28 files changed, 511 insertions, 611 deletions
diff --git a/content/browser/ppapi_plugin_process_host.cc b/content/browser/ppapi_plugin_process_host.cc index 3183a84..ecbbfd6 100644 --- a/content/browser/ppapi_plugin_process_host.cc +++ b/content/browser/ppapi_plugin_process_host.cc @@ -217,7 +217,7 @@ PpapiPluginProcessHost::PpapiPluginProcessHost( info.path, profile_data_directory, false)); - filter_ = new PepperMessageFilter(permissions_); + filter_ = new PepperMessageFilter(); process_->GetHost()->AddFilter(filter_.get()); process_->GetHost()->AddFilter(host_impl_->message_filter().get()); diff --git a/content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc b/content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc index 7368932..db3f8ef 100644 --- a/content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc +++ b/content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc @@ -29,7 +29,7 @@ BrowserPpapiHost* BrowserPpapiHost::CreateExternalPluginProcess( browser_ppapi_host->set_plugin_process_handle(plugin_child_process); scoped_refptr<PepperMessageFilter> pepper_message_filter( - new PepperMessageFilter(permissions)); + new PepperMessageFilter()); channel->AddFilter(pepper_message_filter); channel->AddFilter(browser_ppapi_host->message_filter().get()); channel->AddFilter(new TraceMessageFilter()); diff --git a/content/browser/renderer_host/pepper/content_browser_pepper_host_factory.cc b/content/browser/renderer_host/pepper/content_browser_pepper_host_factory.cc index 97e3173..46e8c13 100644 --- a/content/browser/renderer_host/pepper/content_browser_pepper_host_factory.cc +++ b/content/browser/renderer_host/pepper/content_browser_pepper_host_factory.cc @@ -11,6 +11,7 @@ #include "content/browser/renderer_host/pepper/pepper_flash_file_message_filter.h" #include "content/browser/renderer_host/pepper/pepper_gamepad_host.h" #include "content/browser/renderer_host/pepper/pepper_host_resolver_message_filter.h" +#include "content/browser/renderer_host/pepper/pepper_network_monitor_host.h" #include "content/browser/renderer_host/pepper/pepper_network_proxy_host.h" #include "content/browser/renderer_host/pepper/pepper_print_settings_manager.h" #include "content/browser/renderer_host/pepper/pepper_printing_host.h" @@ -198,6 +199,10 @@ scoped_ptr<ResourceHost> ContentBrowserPepperHostFactory::CreateResourceHost( return scoped_ptr<ResourceHost>(); } } + if (message.type() == PpapiHostMsg_NetworkMonitor_Create::ID) { + return scoped_ptr<ResourceHost>( + new PepperNetworkMonitorHost(host_, instance, params.pp_resource())); + } // Flash interfaces. if (GetPermissions().HasPermission(ppapi::PERMISSION_FLASH)) { diff --git a/content/browser/renderer_host/pepper/pepper_message_filter.cc b/content/browser/renderer_host/pepper/pepper_message_filter.cc index 197a303..6434729 100644 --- a/content/browser/renderer_host/pepper/pepper_message_filter.cc +++ b/content/browser/renderer_host/pepper/pepper_message_filter.cc @@ -4,32 +4,20 @@ #include "content/browser/renderer_host/pepper/pepper_message_filter.h" -#include "base/bind.h" -#include "base/bind_helpers.h" #include "base/logging.h" #include "content/browser/renderer_host/pepper/pepper_socket_utils.h" -#include "content/browser/renderer_host/render_process_host_impl.h" -#include "content/public/browser/browser_thread.h" #include "content/public/common/content_client.h" -#include "ppapi/c/private/ppb_network_list_private.h" #include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/shared_impl/api_id.h" -#include "ppapi/shared_impl/private/net_address_private_impl.h" - -using ppapi::NetAddressPrivateImpl; namespace content { +PepperMessageFilter::PepperMessageFilter() {} +PepperMessageFilter::~PepperMessageFilter() {} + bool PepperMessageFilter::OnMessageReceived(const IPC::Message& msg, bool* message_was_ok) { bool handled = true; IPC_BEGIN_MESSAGE_MAP_EX(PepperMessageFilter, msg, *message_was_ok) - // NetworkMonitor messages. - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBNetworkMonitor_Start, - OnNetworkMonitorStart) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBNetworkMonitor_Stop, - OnNetworkMonitorStop) - // X509 certificate messages. IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBX509Certificate_ParseDER, OnX509CertificateParseDER); @@ -39,41 +27,6 @@ bool PepperMessageFilter::OnMessageReceived(const IPC::Message& msg, return handled; } -void PepperMessageFilter::OnIPAddressChanged() { - GetAndSendNetworkList(); -} - -PepperMessageFilter::PepperMessageFilter( - const ppapi::PpapiPermissions& permissions) - : permissions_(permissions) { -} - -PepperMessageFilter::~PepperMessageFilter() { - if (!network_monitor_ids_.empty()) - net::NetworkChangeNotifier::RemoveIPAddressObserver(this); -} - -void PepperMessageFilter::OnNetworkMonitorStart(uint32 plugin_dispatcher_id) { - // Support all in-process plugins, and ones with "private" permissions. - if (!permissions_.HasPermission(ppapi::PERMISSION_PRIVATE)) - return; - - if (network_monitor_ids_.empty()) - net::NetworkChangeNotifier::AddIPAddressObserver(this); - - network_monitor_ids_.insert(plugin_dispatcher_id); - GetAndSendNetworkList(); -} - -void PepperMessageFilter::OnNetworkMonitorStop(uint32 plugin_dispatcher_id) { - if (!permissions_.HasPermission(ppapi::PERMISSION_PRIVATE)) - return; - - network_monitor_ids_.erase(plugin_dispatcher_id); - if (network_monitor_ids_.empty()) - net::NetworkChangeNotifier::RemoveIPAddressObserver(this); -} - void PepperMessageFilter::OnX509CertificateParseDER( const std::vector<char>& der, bool* succeeded, @@ -84,51 +37,4 @@ void PepperMessageFilter::OnX509CertificateParseDER( pepper_socket_utils::GetCertificateFields(&der[0], der.size(), result); } -void PepperMessageFilter::GetAndSendNetworkList() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - BrowserThread::PostBlockingPoolTask( - FROM_HERE, base::Bind(&PepperMessageFilter::DoGetNetworkList, this)); -} - -void PepperMessageFilter::DoGetNetworkList() { - scoped_ptr<net::NetworkInterfaceList> list(new net::NetworkInterfaceList()); - net::GetNetworkList(list.get()); - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&PepperMessageFilter::SendNetworkList, - this, base::Passed(&list))); -} - -void PepperMessageFilter::SendNetworkList( - scoped_ptr<net::NetworkInterfaceList> list) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - scoped_ptr< ::ppapi::NetworkList> list_copy( - new ::ppapi::NetworkList(list->size())); - for (size_t i = 0; i < list->size(); ++i) { - const net::NetworkInterface& network = list->at(i); - ::ppapi::NetworkInfo& network_copy = list_copy->at(i); - network_copy.name = network.name; - - network_copy.addresses.resize(1, NetAddressPrivateImpl::kInvalidNetAddress); - bool result = NetAddressPrivateImpl::IPEndPointToNetAddress( - network.address, 0, &(network_copy.addresses[0])); - DCHECK(result); - - // TODO(sergeyu): Currently net::NetworkInterfaceList provides - // only name and one IP address. Add all other fields and copy - // them here. - network_copy.type = PP_NETWORKLIST_UNKNOWN; - network_copy.state = PP_NETWORKLIST_UP; - network_copy.display_name = network.name; - network_copy.mtu = 0; - } - for (NetworkMonitorIdSet::iterator it = network_monitor_ids_.begin(); - it != network_monitor_ids_.end(); ++it) { - Send(new PpapiMsg_PPBNetworkMonitor_NetworkList( - ppapi::API_ID_PPB_NETWORKMANAGER_PRIVATE, *it, *list_copy)); - } -} - } // namespace content diff --git a/content/browser/renderer_host/pepper/pepper_message_filter.h b/content/browser/renderer_host/pepper/pepper_message_filter.h index a2aa226..3f5010e 100644 --- a/content/browser/renderer_host/pepper/pepper_message_filter.h +++ b/content/browser/renderer_host/pepper/pepper_message_filter.h @@ -5,17 +5,12 @@ #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_MESSAGE_FILTER_H_ #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_MESSAGE_FILTER_H_ -#include <set> #include <vector> #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "base/files/file_path.h" #include "base/memory/scoped_ptr.h" #include "content/public/browser/browser_message_filter.h" -#include "net/base/net_util.h" -#include "net/base/network_change_notifier.h" -#include "ppapi/shared_impl/ppapi_permissions.h" namespace ppapi { class PPB_X509Certificate_Fields; @@ -23,48 +18,23 @@ class PPB_X509Certificate_Fields; namespace content { -// Message filter that handles IPC for PPB_NetworkMonitor_Private and -// PPB_X509Certificate_Private. -class PepperMessageFilter - : public BrowserMessageFilter, - public net::NetworkChangeNotifier::IPAddressObserver { +// Message filter that handles IPC for PPB_X509Certificate_Private. +class PepperMessageFilter : public BrowserMessageFilter { public: - explicit PepperMessageFilter(const ppapi::PpapiPermissions& permissions); + PepperMessageFilter(); // BrowserMessageFilter methods. virtual bool OnMessageReceived(const IPC::Message& message, bool* message_was_ok) OVERRIDE; - // net::NetworkChangeNotifier::IPAddressObserver interface. - virtual void OnIPAddressChanged() OVERRIDE; - protected: virtual ~PepperMessageFilter(); private: - // Set of disptachers ID's that have subscribed for NetworkMonitor - // notifications. - typedef std::set<uint32> NetworkMonitorIdSet; - - void OnNetworkMonitorStart(uint32 plugin_dispatcher_id); - void OnNetworkMonitorStop(uint32 plugin_dispatcher_id); - void OnX509CertificateParseDER(const std::vector<char>& der, bool* succeeded, ppapi::PPB_X509Certificate_Fields* result); - void GetAndSendNetworkList(); - void DoGetNetworkList(); - void SendNetworkList(scoped_ptr<net::NetworkInterfaceList> list); - - // When attached to an out-of-process plugin (be it native or NaCl) this - // will have the Pepper permissions for the plugin. When attached to the - // renderer channel, this will have no permissions listed (since there may - // be many plugins sharing this channel). - ppapi::PpapiPermissions permissions_; - - NetworkMonitorIdSet network_monitor_ids_; - DISALLOW_COPY_AND_ASSIGN(PepperMessageFilter); }; diff --git a/content/browser/renderer_host/pepper/pepper_network_monitor_host.cc b/content/browser/renderer_host/pepper/pepper_network_monitor_host.cc new file mode 100644 index 0000000..32d8a8a --- /dev/null +++ b/content/browser/renderer_host/pepper/pepper_network_monitor_host.cc @@ -0,0 +1,120 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/renderer_host/pepper/pepper_network_monitor_host.h" + +#include "base/task_runner_util.h" +#include "base/threading/sequenced_worker_pool.h" +#include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h" +#include "content/browser/renderer_host/pepper/pepper_socket_utils.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/common/socket_permission_request.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/private/net_address_private_impl.h" + +namespace content { + +namespace { + +bool CanUseNetworkMonitor(bool external_plugin, + int render_process_id, + int render_view_id) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + SocketPermissionRequest request = SocketPermissionRequest( + SocketPermissionRequest::NETWORK_STATE, std::string(), 0); + return pepper_socket_utils::CanUseSocketAPIs( + external_plugin, true /* private_api */, request, render_process_id, + render_view_id); +} + +scoped_ptr<net::NetworkInterfaceList> GetNetworkList() { + scoped_ptr<net::NetworkInterfaceList> list(new net::NetworkInterfaceList()); + net::GetNetworkList(list.get()); + return list.Pass(); +} + +} // namespace + +PepperNetworkMonitorHost::PepperNetworkMonitorHost( + BrowserPpapiHostImpl* host, + PP_Instance instance, + PP_Resource resource) + : ResourceHost(host->GetPpapiHost(), instance, resource), + weak_factory_(this) { + int render_process_id; + int render_view_id; + host->GetRenderViewIDsForInstance(instance, + &render_process_id, + &render_view_id); + + BrowserThread::PostTaskAndReplyWithResult( + BrowserThread::UI, FROM_HERE, + base::Bind(&CanUseNetworkMonitor, host->external_plugin(), + render_process_id, render_view_id), + base::Bind(&PepperNetworkMonitorHost::OnPermissionCheckResult, + weak_factory_.GetWeakPtr())); +} + +PepperNetworkMonitorHost::~PepperNetworkMonitorHost() { + net::NetworkChangeNotifier::RemoveIPAddressObserver(this); +} + +void PepperNetworkMonitorHost::OnIPAddressChanged() { + GetAndSendNetworkList(); +} + +void PepperNetworkMonitorHost::OnPermissionCheckResult( + bool can_use_network_monitor) { + if (!can_use_network_monitor) { + host()->SendUnsolicitedReply(pp_resource(), + PpapiPluginMsg_NetworkMonitor_Forbidden()); + return; + } + + net::NetworkChangeNotifier::AddIPAddressObserver(this); + GetAndSendNetworkList(); +} + +void PepperNetworkMonitorHost::GetAndSendNetworkList() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + // Call GetNetworkList() on a thread that allows blocking IO. + base::PostTaskAndReplyWithResult( + BrowserThread::GetBlockingPool(), FROM_HERE, + base::Bind(&GetNetworkList), + base::Bind(&PepperNetworkMonitorHost::SendNetworkList, + weak_factory_.GetWeakPtr())); +} + +void PepperNetworkMonitorHost::SendNetworkList( + scoped_ptr<net::NetworkInterfaceList> list) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + scoped_ptr<ppapi::proxy::SerializedNetworkList> list_copy( + new ppapi::proxy::SerializedNetworkList(list->size())); + for (size_t i = 0; i < list->size(); ++i) { + const net::NetworkInterface& network = list->at(i); + ppapi::proxy::SerializedNetworkInfo& network_copy = list_copy->at(i); + network_copy.name = network.name; + + network_copy.addresses.resize( + 1, ppapi::NetAddressPrivateImpl::kInvalidNetAddress); + bool result = ppapi::NetAddressPrivateImpl::IPEndPointToNetAddress( + network.address, 0, &(network_copy.addresses[0])); + DCHECK(result); + + // TODO(sergeyu): Currently net::NetworkInterfaceList provides + // only name and one IP address. Add all other fields and copy + // them here. + network_copy.type = PP_NETWORKLIST_UNKNOWN; + network_copy.state = PP_NETWORKLIST_UP; + network_copy.display_name = network.name; + network_copy.mtu = 0; + } + host()->SendUnsolicitedReply( + pp_resource(), PpapiPluginMsg_NetworkMonitor_NetworkList(*list_copy)); +} + +} // namespace content diff --git a/content/browser/renderer_host/pepper/pepper_network_monitor_host.h b/content/browser/renderer_host/pepper/pepper_network_monitor_host.h new file mode 100644 index 0000000..e27f8a2 --- /dev/null +++ b/content/browser/renderer_host/pepper/pepper_network_monitor_host.h @@ -0,0 +1,50 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_NETWORK_MONITOR_HOST_H_ +#define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_NETWORK_MONITOR_HOST_H_ + +#include "base/compiler_specific.h" +#include "base/memory/weak_ptr.h" +#include "content/common/content_export.h" +#include "net/base/net_util.h" +#include "net/base/network_change_notifier.h" +#include "ppapi/host/host_message_context.h" +#include "ppapi/host/resource_host.h" + +namespace content { + +class BrowserPpapiHostImpl; + +// The host for PPB_NetworkMonitor. This class lives on the IO thread. +class CONTENT_EXPORT PepperNetworkMonitorHost + : public ppapi::host::ResourceHost, + public net::NetworkChangeNotifier::IPAddressObserver { + public: + PepperNetworkMonitorHost( + BrowserPpapiHostImpl* host, + PP_Instance instance, + PP_Resource resource); + + virtual ~PepperNetworkMonitorHost(); + + // net::NetworkChangeNotifier::IPAddressObserver interface. + virtual void OnIPAddressChanged() OVERRIDE; + + private: + void OnPermissionCheckResult(bool can_use_network_monitor); + + void GetAndSendNetworkList(); + void SendNetworkList(scoped_ptr<net::NetworkInterfaceList> list); + + ppapi::host::ReplyMessageContext reply_context_; + + base::WeakPtrFactory<PepperNetworkMonitorHost> weak_factory_; + + DISALLOW_COPY_AND_ASSIGN(PepperNetworkMonitorHost); +}; + +} // namespace content + +#endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_NETWORK_MONITOR_HOST_H_ diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 74927bf..1b4ed2d 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -945,6 +945,8 @@ 'browser/renderer_host/pepper/pepper_lookup_request.h', 'browser/renderer_host/pepper/pepper_message_filter.cc', 'browser/renderer_host/pepper/pepper_message_filter.h', + 'browser/renderer_host/pepper/pepper_network_monitor_host.cc', + 'browser/renderer_host/pepper/pepper_network_monitor_host.h', 'browser/renderer_host/pepper/pepper_network_proxy_host.cc', 'browser/renderer_host/pepper/pepper_network_proxy_host.h', 'browser/renderer_host/pepper/pepper_print_settings_manager.cc', diff --git a/content/ppapi_plugin/ppapi_thread.cc b/content/ppapi_plugin/ppapi_thread.cc index c4021cb..2d46807 100644 --- a/content/ppapi_plugin/ppapi_thread.cc +++ b/content/ppapi_plugin/ppapi_thread.cc @@ -103,8 +103,6 @@ PpapiThread::PpapiThread(const CommandLine& command_line, bool is_broker) // note that only those InterfaceProxy-based ones require registration. AddRoute(ppapi::API_ID_PPB_HOSTRESOLVER_PRIVATE, &dispatcher_message_listener_); - AddRoute(ppapi::API_ID_PPB_NETWORKMANAGER_PRIVATE, - &dispatcher_message_listener_); } PpapiThread::~PpapiThread() { diff --git a/content/public/common/socket_permission_request.h b/content/public/common/socket_permission_request.h index 278880e..13b9ed1 100644 --- a/content/public/common/socket_permission_request.h +++ b/content/public/common/socket_permission_request.h @@ -20,7 +20,8 @@ struct SocketPermissionRequest { UDP_SEND_TO, UDP_MULTICAST_MEMBERSHIP, RESOLVE_HOST, - RESOLVE_PROXY + RESOLVE_PROXY, + NETWORK_STATE }; SocketPermissionRequest(OperationType type, diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi index 52b97e9..d0bbe65 100644 --- a/ppapi/ppapi_proxy.gypi +++ b/ppapi/ppapi_proxy.gypi @@ -82,6 +82,10 @@ 'proxy/locking_resource_releaser.h', 'proxy/net_address_resource.cc', 'proxy/net_address_resource.h', + 'proxy/network_list_resource.cc', + 'proxy/network_list_resource.h', + 'proxy/network_monitor_resource.cc', + 'proxy/network_monitor_resource.h', 'proxy/network_proxy_resource.cc', 'proxy/network_proxy_resource.h', 'proxy/pdf_resource.cc', @@ -127,8 +131,6 @@ 'proxy/ppb_instance_proxy.h', 'proxy/ppb_message_loop_proxy.cc', 'proxy/ppb_message_loop_proxy.h', - 'proxy/ppb_network_monitor_private_proxy.cc', - 'proxy/ppb_network_monitor_private_proxy.h', 'proxy/ppb_testing_proxy.cc', 'proxy/ppb_testing_proxy.h', 'proxy/ppb_var_deprecated_proxy.cc', diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index e638498..8c9b658 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -68,8 +68,6 @@ 'shared_impl/ppb_memory_shared.cc', 'shared_impl/ppb_message_loop_shared.cc', 'shared_impl/ppb_message_loop_shared.h', - 'shared_impl/ppb_network_list_private_shared.cc', - 'shared_impl/ppb_network_list_private_shared.h', 'shared_impl/ppb_opengles2_shared.cc', 'shared_impl/ppb_opengles2_shared.h', 'shared_impl/ppb_resource_array_shared.cc', diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc index 115516f..409f12f 100644 --- a/ppapi/proxy/interface_list.cc +++ b/ppapi/proxy/interface_list.cc @@ -107,7 +107,6 @@ #include "ppapi/proxy/ppb_image_data_proxy.h" #include "ppapi/proxy/ppb_instance_proxy.h" #include "ppapi/proxy/ppb_message_loop_proxy.h" -#include "ppapi/proxy/ppb_network_monitor_private_proxy.h" #include "ppapi/proxy/ppb_testing_proxy.h" #include "ppapi/proxy/ppb_var_deprecated_proxy.h" #include "ppapi/proxy/ppb_video_decoder_proxy.h" diff --git a/ppapi/proxy/network_list_resource.cc b/ppapi/proxy/network_list_resource.cc new file mode 100644 index 0000000..62a342c --- /dev/null +++ b/ppapi/proxy/network_list_resource.cc @@ -0,0 +1,89 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/proxy/network_list_resource.h" + +#include <algorithm> + +#include "base/logging.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/shared_impl/array_writer.h" +#include "ppapi/shared_impl/var.h" +#include "ppapi/thunk/enter.h" + +namespace ppapi { +namespace proxy { + +NetworkListResource::NetworkListResource(PP_Instance instance, + const SerializedNetworkList& list) + : Resource(OBJECT_IS_PROXY, instance), + list_(list) { +} + +NetworkListResource::~NetworkListResource() {} + +thunk::PPB_NetworkList_API* NetworkListResource::AsPPB_NetworkList_API() { + return this; +} + +uint32_t NetworkListResource::GetCount() { + return static_cast<uint32_t>(list_.size()); +} + +PP_Var NetworkListResource::GetName(uint32_t index) { + if (index >= list_.size()) + return PP_MakeUndefined(); + return StringVar::StringToPPVar(list_.at(index).name); +} + +PP_NetworkListType_Private NetworkListResource::GetType(uint32_t index) { + if (index >= list_.size()) + return PP_NETWORKLIST_UNKNOWN; + return list_.at(index).type; +} + +PP_NetworkListState_Private NetworkListResource::GetState(uint32_t index) { + if (index >= list_.size()) + return PP_NETWORKLIST_DOWN; + return list_.at(index).state; +} + +int32_t NetworkListResource::GetIpAddresses(uint32_t index, + const PP_ArrayOutput& output) { + ArrayWriter writer(output); + if (index >= list_.size() || !writer.is_valid()) + return PP_ERROR_BADARGUMENT; + + thunk::EnterResourceCreationNoLock enter(pp_instance()); + if (enter.failed()) + return PP_ERROR_FAILED; + + const std::vector<PP_NetAddress_Private>& addresses = + list_.at(index).addresses; + std::vector<PP_Resource> addr_resources; + for (size_t i = 0; i < addresses.size(); ++i) { + addr_resources.push_back( + enter.functions()->CreateNetAddressFromNetAddressPrivate( + pp_instance(), addresses[i])); + } + if (!writer.StoreResourceVector(addr_resources)) + return PP_ERROR_FAILED; + + return PP_OK; +} + +PP_Var NetworkListResource::GetDisplayName(uint32_t index) { + if (index >= list_.size()) + return PP_MakeUndefined(); + return StringVar::StringToPPVar(list_.at(index).display_name); +} + +uint32_t NetworkListResource::GetMTU(uint32_t index) { + if (index >= list_.size()) + return 0; + return list_.at(index).mtu; +} + +} // namespace proxy +} // namespace thunk diff --git a/ppapi/proxy/network_list_resource.h b/ppapi/proxy/network_list_resource.h new file mode 100644 index 0000000..9c078669 --- /dev/null +++ b/ppapi/proxy/network_list_resource.h @@ -0,0 +1,52 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_PROXY_NETWORK_LIST_RESOURCE_H_ +#define PPAPI_PROXY_NETWORK_LIST_RESOURCE_H_ + +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "base/memory/ref_counted.h" +#include "ppapi/c/private/ppb_net_address_private.h" +#include "ppapi/proxy/ppapi_proxy_export.h" +#include "ppapi/proxy/serialized_structs.h" +#include "ppapi/shared_impl/resource.h" +#include "ppapi/thunk/ppb_network_list_api.h" + +namespace ppapi { +namespace proxy { + +class NetworkListResource + : public Resource, + public thunk::PPB_NetworkList_API { + public: + NetworkListResource(PP_Instance instance, + const SerializedNetworkList& list); + virtual ~NetworkListResource(); + + // Resource override. + virtual thunk::PPB_NetworkList_API* AsPPB_NetworkList_API() OVERRIDE; + + // PPB_NetworkList_API implementation. + virtual uint32_t GetCount() OVERRIDE; + virtual PP_Var GetName(uint32_t index) OVERRIDE; + virtual PP_NetworkListType_Private GetType(uint32_t index) OVERRIDE; + virtual PP_NetworkListState_Private GetState(uint32_t index) OVERRIDE; + virtual int32_t GetIpAddresses(uint32_t index, + const PP_ArrayOutput& output) OVERRIDE; + virtual PP_Var GetDisplayName(uint32_t index) OVERRIDE; + virtual uint32_t GetMTU(uint32_t index) OVERRIDE; + + private: + SerializedNetworkList list_; + + DISALLOW_COPY_AND_ASSIGN(NetworkListResource); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_NETWORK_LIST_RESOURCE_H_ diff --git a/ppapi/proxy/network_monitor_resource.cc b/ppapi/proxy/network_monitor_resource.cc new file mode 100644 index 0000000..0dfb0b4 --- /dev/null +++ b/ppapi/proxy/network_monitor_resource.cc @@ -0,0 +1,85 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/proxy/network_monitor_resource.h" + +#include "ppapi/proxy/dispatch_reply_message.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_network_monitor_api.h" + +namespace ppapi { +namespace proxy { + +NetworkMonitorResource::NetworkMonitorResource(Connection connection, + PP_Instance instance) + : PluginResource(connection, instance), + current_list_(0), + forbidden_(false), + network_list_(NULL) { + SendCreate(BROWSER, PpapiHostMsg_NetworkMonitor_Create()); +} + +NetworkMonitorResource::~NetworkMonitorResource() {} + +ppapi::thunk::PPB_NetworkMonitor_API* +NetworkMonitorResource::AsPPB_NetworkMonitor_API() { + return this; +} + +void NetworkMonitorResource::OnReplyReceived( + const ResourceMessageReplyParams& params, + const IPC::Message& msg) { + IPC_BEGIN_MESSAGE_MAP(NetworkMonitorResource, msg) + PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL( + PpapiPluginMsg_NetworkMonitor_NetworkList, OnPluginMsgNetworkList) + PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_0( + PpapiPluginMsg_NetworkMonitor_Forbidden, OnPluginMsgForbidden) + PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED( + PluginResource::OnReplyReceived(params, msg)) + IPC_END_MESSAGE_MAP() +} + +int32_t NetworkMonitorResource::UpdateNetworkList( + PP_Resource* network_list, + scoped_refptr<TrackedCallback> callback) { + if (!network_list) + return PP_ERROR_BADARGUMENT; + if (TrackedCallback::IsPending(update_callback_)) + return PP_ERROR_INPROGRESS; + if (forbidden_) + return PP_ERROR_NOACCESS; + + if (current_list_.get()) { + *network_list = current_list_.Release(); + return PP_OK; + } + + network_list_ = network_list; + update_callback_ = callback; + return PP_OK_COMPLETIONPENDING; +} + +void NetworkMonitorResource::OnPluginMsgNetworkList( + const ResourceMessageReplyParams& params, + const SerializedNetworkList& list) { + current_list_ = ScopedPPResource( + new NetworkListResource(pp_instance(), list)); + + if (TrackedCallback::IsPending(update_callback_)) { + *network_list_ = current_list_.Release(); + update_callback_->Run(PP_OK); + } +} + +void NetworkMonitorResource::OnPluginMsgForbidden( + const ResourceMessageReplyParams& params) { + forbidden_ = true; + + if (TrackedCallback::IsPending(update_callback_)) + update_callback_->Run(PP_ERROR_NOACCESS); +} + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/network_monitor_resource.h b/ppapi/proxy/network_monitor_resource.h new file mode 100644 index 0000000..d227934 --- /dev/null +++ b/ppapi/proxy/network_monitor_resource.h @@ -0,0 +1,58 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_PROXY_NETWORK_MONITOR_RESOURCE_H_ +#define PPAPI_PROXY_NETWORK_MONITOR_RESOURCE_H_ + +#include <list> + +#include "ppapi/proxy/network_list_resource.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/shared_impl/scoped_pp_resource.h" +#include "ppapi/thunk/ppb_network_monitor_api.h" + +namespace base { +class MessageLoopProxy; +} // namespace base + +namespace ppapi { +namespace proxy { + +class NetworkMonitorResource : public PluginResource, + public thunk::PPB_NetworkMonitor_API { + public: + explicit NetworkMonitorResource(Connection connection, + PP_Instance instance); + virtual ~NetworkMonitorResource(); + + // PluginResource overrides. + ppapi::thunk::PPB_NetworkMonitor_API* AsPPB_NetworkMonitor_API() OVERRIDE; + virtual void OnReplyReceived(const ResourceMessageReplyParams& params, + const IPC::Message& msg) OVERRIDE; + + // thunk::PPB_NetworkMonitor_API interface + virtual int32_t UpdateNetworkList( + PP_Resource* network_list, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + + private: + // IPC message handlers for the messages received from the browser. + void OnPluginMsgNetworkList(const ResourceMessageReplyParams& params, + const SerializedNetworkList& list); + void OnPluginMsgForbidden(const ResourceMessageReplyParams& params); + + ScopedPPResource current_list_; + bool forbidden_; + + // Parameters passed to UpdateNetworkList(). + PP_Resource* network_list_; + scoped_refptr<TrackedCallback> update_callback_; + + DISALLOW_COPY_AND_ASSIGN(NetworkMonitorResource); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_NETWORK_MONITOR_RESOURCE_H_ diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index b970d36..9108ea1e 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -47,6 +47,7 @@ #include "ppapi/c/private/ppb_talk_private.h" #include "ppapi/c/private/ppp_flash_browser_operations.h" #include "ppapi/proxy/host_resolver_private_resource.h" +#include "ppapi/proxy/network_list_resource.h" #include "ppapi/proxy/ppapi_param_traits.h" #include "ppapi/proxy/ppapi_proxy_export.h" #include "ppapi/proxy/resource_message_params.h" @@ -61,7 +62,6 @@ #include "ppapi/shared_impl/ppapi_preferences.h" #include "ppapi/shared_impl/ppb_device_ref_shared.h" #include "ppapi/shared_impl/ppb_input_event_shared.h" -#include "ppapi/shared_impl/ppb_network_list_private_shared.h" #include "ppapi/shared_impl/ppb_view_shared.h" #include "ppapi/shared_impl/ppp_flash_browser_operations_shared.h" #include "ppapi/shared_impl/private/ppb_x509_certificate_private_shared.h" @@ -315,7 +315,7 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::URLResponseInfoData) IPC_STRUCT_TRAITS_MEMBER(body_as_file_ref) IPC_STRUCT_TRAITS_END() -IPC_STRUCT_TRAITS_BEGIN(ppapi::NetworkInfo) +IPC_STRUCT_TRAITS_BEGIN(ppapi::proxy::SerializedNetworkInfo) IPC_STRUCT_TRAITS_MEMBER(name) IPC_STRUCT_TRAITS_MEMBER(type) IPC_STRUCT_TRAITS_MEMBER(state) @@ -625,11 +625,6 @@ IPC_MESSAGE_ROUTED2(PpapiMsg_PPPMessaging_HandleMessage, IPC_MESSAGE_ROUTED1(PpapiMsg_PPPMouseLock_MouseLockLost, PP_Instance /* instance */) -// PPB_NetworkMonitor_Private. -IPC_MESSAGE_ROUTED2(PpapiMsg_PPBNetworkMonitor_NetworkList, - uint32 /* plugin_dispatcher_id */, - ppapi::NetworkList /* network_list */) - // PPP_Printing IPC_SYNC_MESSAGE_ROUTED1_1(PpapiMsg_PPPPrinting_QuerySupportedFormats, PP_Instance /* instance */, @@ -1082,12 +1077,6 @@ IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBInstance_DeliverSamples, std::string /* serialized_block_info */) #endif // !defined(OS_NACL) && !defined(NACL_WIN64) -// PPB_NetworkMonitor_Private. -IPC_MESSAGE_CONTROL1(PpapiHostMsg_PPBNetworkMonitor_Start, - uint32 /* plugin_dispatcher_id */) -IPC_MESSAGE_CONTROL1(PpapiHostMsg_PPBNetworkMonitor_Stop, - uint32 /* plugin_dispatcher_id */) - // PPB_Testing. IPC_SYNC_MESSAGE_ROUTED3_1( PpapiHostMsg_PPBTesting_ReadImageData, @@ -1441,6 +1430,13 @@ IPC_MESSAGE_CONTROL2(PpapiHostMsg_Graphics2D_ReadImageData, PP_Point /* top_left */) IPC_MESSAGE_CONTROL0(PpapiPluginMsg_Graphics2D_ReadImageDataAck) +// NetworkMonitor. +IPC_MESSAGE_CONTROL0(PpapiHostMsg_NetworkMonitor_Create) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_NetworkMonitor_NetworkList, + ppapi::proxy::SerializedNetworkList /* network_list */) +IPC_MESSAGE_CONTROL0(PpapiPluginMsg_NetworkMonitor_Forbidden) + + // NetworkProxy ---------------------------------------------------------------- IPC_MESSAGE_CONTROL0(PpapiHostMsg_NetworkProxy_Create) diff --git a/ppapi/proxy/ppb_network_monitor_private_proxy.cc b/ppapi/proxy/ppb_network_monitor_private_proxy.cc deleted file mode 100644 index 26bad03..0000000 --- a/ppapi/proxy/ppb_network_monitor_private_proxy.cc +++ /dev/null @@ -1,174 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ppapi/proxy/ppb_network_monitor_private_proxy.h" - -#include "ppapi/proxy/enter_proxy.h" -#include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/shared_impl/proxy_lock.h" -#include "ppapi/thunk/ppb_network_monitor_api.h" - -namespace ppapi { -namespace proxy { - -class PPB_NetworkMonitor_Private_Proxy::NetworkMonitor - : public Resource, - public thunk::PPB_NetworkMonitor_API, - public base::SupportsWeakPtr< - PPB_NetworkMonitor_Private_Proxy::NetworkMonitor> { - public: - NetworkMonitor(PP_Instance instance, - PPB_NetworkMonitor_Private_Proxy* proxy) - : Resource(OBJECT_IS_PROXY, instance), - proxy_(proxy), - initial_list_sent_(false), - network_list_(NULL) { - } - - virtual ~NetworkMonitor() { - if (TrackedCallback::IsPending(update_callback_)) - update_callback_->PostAbort(); - proxy_->OnNetworkMonitorDeleted(this, pp_instance()); - } - - // thunk::PPB_NetworkMonitor_API interface. - virtual int32_t UpdateNetworkList( - PP_Resource* network_list, - scoped_refptr<TrackedCallback> callback) OVERRIDE { - if (!network_list) - return PP_ERROR_BADARGUMENT; - if (TrackedCallback::IsPending(update_callback_)) - return PP_ERROR_INPROGRESS; - - if (current_list_ && !initial_list_sent_) { - initial_list_sent_ = true; - thunk::EnterResourceCreationNoLock enter(pp_instance()); - *network_list = PPB_NetworkList_Private_Shared::Create( - OBJECT_IS_PROXY, pp_instance(), current_list_); - return PP_OK; - } - - network_list_ = network_list; - update_callback_ = callback; - return PP_OK_COMPLETIONPENDING; - } - - // Resource overrides. - virtual ppapi::thunk::PPB_NetworkMonitor_API* - AsPPB_NetworkMonitor_API() OVERRIDE { - return this; - } - - // This is invoked when a network list is received for this monitor (either - // initially or on a change). - void OnNetworkListReceived(const scoped_refptr<NetworkListStorage>& list) { - current_list_ = list; - - if (TrackedCallback::IsPending(update_callback_)) { - initial_list_sent_ = true; - { - thunk::EnterResourceCreationNoLock enter(pp_instance()); - *network_list_ = PPB_NetworkList_Private_Shared::Create( - OBJECT_IS_PROXY, pp_instance(), list); - network_list_ = NULL; - } - update_callback_->Run(PP_OK); - } - } - - private: - PPB_NetworkMonitor_Private_Proxy* proxy_; - scoped_refptr<NetworkListStorage> current_list_; - bool initial_list_sent_; - - // Parameters passed to UpdateNetworkList(); - PP_Resource* network_list_; - scoped_refptr<TrackedCallback> update_callback_; - - DISALLOW_COPY_AND_ASSIGN(NetworkMonitor); -}; - -PPB_NetworkMonitor_Private_Proxy::PPB_NetworkMonitor_Private_Proxy( - Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - monitors_(ObserverList<NetworkMonitor>::NOTIFY_EXISTING_ONLY) { -} - -PPB_NetworkMonitor_Private_Proxy::~PPB_NetworkMonitor_Private_Proxy() { - DCHECK(!monitors_.might_have_observers()); -} - -// static -PP_Resource PPB_NetworkMonitor_Private_Proxy::CreateProxyResource( - PP_Instance instance) { - // TODO(dmichael): Check that this thread has a valid message loop associated - // with it. - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); - if (!dispatcher) - return 0; - PPB_NetworkMonitor_Private_Proxy* proxy = - static_cast<PPB_NetworkMonitor_Private_Proxy*>( - dispatcher->GetInterfaceProxy(kApiID)); - if (!proxy) - return 0; - - scoped_refptr<NetworkMonitor> result(new NetworkMonitor(instance, proxy)); - - bool first_network_monitor = !proxy->monitors_.might_have_observers(); - proxy->monitors_.AddObserver(result.get()); - if (first_network_monitor) { - // If that is the first network monitor then send Start message. - PluginGlobals::Get()->GetBrowserSender()->Send( - new PpapiHostMsg_PPBNetworkMonitor_Start( - dispatcher->plugin_dispatcher_id())); - - // We could have received network list message after sending the - // previous Stop message. This list is stale now, so reset it - // here. - proxy->current_list_ = NULL; - } else if (proxy->current_list_.get()) { - result->OnNetworkListReceived(proxy->current_list_); - } - - return result->GetReference(); -} - -bool PPB_NetworkMonitor_Private_Proxy::OnMessageReceived( - const IPC::Message& msg) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(PPB_NetworkMonitor_Private_Proxy, msg) - IPC_MESSAGE_HANDLER(PpapiMsg_PPBNetworkMonitor_NetworkList, - OnPluginMsgNetworkList) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -void PPB_NetworkMonitor_Private_Proxy::OnPluginMsgNetworkList( - uint32 plugin_dispatcher_id, - const ppapi::NetworkList& list) { - scoped_refptr<NetworkListStorage> list_storage(new NetworkListStorage(list)); - current_list_ = list_storage; - FOR_EACH_OBSERVER(NetworkMonitor, monitors_, - OnNetworkListReceived(list_storage)); -} - -void PPB_NetworkMonitor_Private_Proxy::OnNetworkMonitorDeleted( - NetworkMonitor* monitor, - PP_Instance instance) { - monitors_.RemoveObserver(monitor); - if (!monitors_.might_have_observers()) { - // Send Stop message if that was the last NetworkMonitor. - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); - if (dispatcher) { - PluginGlobals::Get()->GetBrowserSender()->Send( - new PpapiHostMsg_PPBNetworkMonitor_Stop( - dispatcher->plugin_dispatcher_id())); - } - current_list_ = NULL; - } -} - -} // namespace proxy -} // namespace ppapi diff --git a/ppapi/proxy/ppb_network_monitor_private_proxy.h b/ppapi/proxy/ppb_network_monitor_private_proxy.h deleted file mode 100644 index 7dbcbd6..0000000 --- a/ppapi/proxy/ppb_network_monitor_private_proxy.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef PPAPI_PROXY_PPB_NETWORK_MONITOR_PRIVATE_PROXY_H_ -#define PPAPI_PROXY_PPB_NETWORK_MONITOR_PRIVATE_PROXY_H_ - -#include <list> - -#include "base/observer_list.h" -#include "ppapi/proxy/interface_proxy.h" -#include "ppapi/shared_impl/ppb_network_list_private_shared.h" -#include "ppapi/shared_impl/scoped_pp_resource.h" -#include "ppapi/thunk/ppb_network_monitor_api.h" - -namespace base { -class MessageLoopProxy; -} // namespace base - -namespace ppapi { -namespace proxy { - -class PPB_NetworkMonitor_Private_Proxy : public InterfaceProxy { - public: - explicit PPB_NetworkMonitor_Private_Proxy(Dispatcher* dispatcher); - virtual ~PPB_NetworkMonitor_Private_Proxy(); - - // Creates n NetworkManager object in the plugin process. - static PP_Resource CreateProxyResource(PP_Instance instance); - - // InterfaceProxy implementation. - virtual bool OnMessageReceived(const IPC::Message& msg); - - static const ApiID kApiID = API_ID_PPB_NETWORKMANAGER_PRIVATE; - - private: - class NetworkMonitor; - friend class NetworkMonitor; - - // IPC message handler for the messages received from the browser. - void OnPluginMsgNetworkList(uint32 plugin_dispatcher_id, - const ppapi::NetworkList& list); - - // Called by NetworkMonitor destructor. - void OnNetworkMonitorDeleted(NetworkMonitor* monitor, - PP_Instance instance); - - ObserverList<NetworkMonitor> monitors_; - - scoped_refptr<NetworkListStorage> current_list_; - - DISALLOW_COPY_AND_ASSIGN(PPB_NetworkMonitor_Private_Proxy); -}; - -} // namespace proxy -} // namespace ppapi - -#endif // PPAPI_PROXY_PPB_NETWORK_MONITOR_PRIVATE_PROXY_H_ diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index 3bb1140..a3ce05e 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -19,6 +19,7 @@ #include "ppapi/proxy/host_resolver_private_resource.h" #include "ppapi/proxy/host_resolver_resource.h" #include "ppapi/proxy/net_address_resource.h" +#include "ppapi/proxy/network_monitor_resource.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_globals.h" #include "ppapi/proxy/plugin_resource_tracker.h" @@ -30,7 +31,6 @@ #include "ppapi/proxy/ppb_flash_message_loop_proxy.h" #include "ppapi/proxy/ppb_graphics_3d_proxy.h" #include "ppapi/proxy/ppb_image_data_proxy.h" -#include "ppapi/proxy/ppb_network_monitor_private_proxy.h" #include "ppapi/proxy/ppb_video_decoder_proxy.h" #include "ppapi/proxy/ppb_x509_certificate_private_proxy.h" #include "ppapi/proxy/printing_resource.h" @@ -313,7 +313,8 @@ PP_Resource ResourceCreationProxy::CreateNetAddressFromNetAddressPrivate( PP_Resource ResourceCreationProxy::CreateNetworkMonitorPrivate( PP_Instance instance) { - return PPB_NetworkMonitor_Private_Proxy::CreateProxyResource(instance); + return (new NetworkMonitorResource(GetConnection(), instance))-> + GetReference(); } PP_Resource ResourceCreationProxy::CreatePrinting(PP_Instance instance) { diff --git a/ppapi/proxy/serialized_structs.cc b/ppapi/proxy/serialized_structs.cc index 8c984d5..d645dd8 100644 --- a/ppapi/proxy/serialized_structs.cc +++ b/ppapi/proxy/serialized_structs.cc @@ -80,6 +80,14 @@ void SerializedFontDescription::SetToPPBrowserFontDescription( desc->word_spacing = word_spacing; } +SerializedNetworkInfo::SerializedNetworkInfo() + : type(PP_NETWORKLIST_UNKNOWN), + state(PP_NETWORKLIST_DOWN), + mtu(0) { +} + +SerializedNetworkInfo::~SerializedNetworkInfo() {} + SerializedTrueTypeFontDesc::SerializedTrueTypeFontDesc() : family(), generic_family(), diff --git a/ppapi/proxy/serialized_structs.h b/ppapi/proxy/serialized_structs.h index 1f89ae2..74525f3 100644 --- a/ppapi/proxy/serialized_structs.h +++ b/ppapi/proxy/serialized_structs.h @@ -16,6 +16,8 @@ #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_point.h" #include "ppapi/c/pp_rect.h" +#include "ppapi/c/private/ppb_net_address_private.h" +#include "ppapi/c/private/ppb_network_list_private.h" #include "ppapi/proxy/ppapi_proxy_export.h" #include "ppapi/shared_impl/host_resource.h" @@ -57,6 +59,19 @@ struct PPAPI_PROXY_EXPORT SerializedFontDescription { int32_t word_spacing; }; +struct PPAPI_PROXY_EXPORT SerializedNetworkInfo { + SerializedNetworkInfo(); + ~SerializedNetworkInfo(); + + std::string name; + PP_NetworkListType_Private type; + PP_NetworkListState_Private state; + std::vector<PP_NetAddress_Private> addresses; + std::string display_name; + int mtu; +}; +typedef std::vector<SerializedNetworkInfo> SerializedNetworkList; + struct PPAPI_PROXY_EXPORT SerializedTrueTypeFontDesc { SerializedTrueTypeFontDesc(); ~SerializedTrueTypeFontDesc(); diff --git a/ppapi/shared_impl/api_id.h b/ppapi/shared_impl/api_id.h index 49e0dcb..c482a02 100644 --- a/ppapi/shared_impl/api_id.h +++ b/ppapi/shared_impl/api_id.h @@ -35,7 +35,6 @@ enum ApiID { API_ID_PPB_IMAGE_DATA, API_ID_PPB_INSTANCE, API_ID_PPB_INSTANCE_PRIVATE, - API_ID_PPB_NETWORKMANAGER_PRIVATE, API_ID_PPB_OPENGLES2, API_ID_PPB_PDF, API_ID_PPB_SURFACE_3D, diff --git a/ppapi/shared_impl/ppb_network_list_private_shared.cc b/ppapi/shared_impl/ppb_network_list_private_shared.cc deleted file mode 100644 index d299c06..0000000 --- a/ppapi/shared_impl/ppb_network_list_private_shared.cc +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <algorithm> - -#include "base/logging.h" -#include "ppapi/c/pp_errors.h" -#include "ppapi/shared_impl/array_writer.h" -#include "ppapi/shared_impl/ppb_network_list_private_shared.h" -#include "ppapi/shared_impl/var.h" -#include "ppapi/thunk/enter.h" - -namespace ppapi { - -NetworkInfo::NetworkInfo() - : type(PP_NETWORKLIST_UNKNOWN), - state(PP_NETWORKLIST_DOWN), - mtu(0) { -} - -NetworkInfo::~NetworkInfo() { -} - -NetworkListStorage::NetworkListStorage(const NetworkList& list) - : list_(list) { -} - -NetworkListStorage::~NetworkListStorage() { -} - -PPB_NetworkList_Private_Shared::PPB_NetworkList_Private_Shared( - ResourceObjectType type, - PP_Instance instance, - const scoped_refptr<NetworkListStorage>& list) - : Resource(type, instance), - list_(list) { -} - -PPB_NetworkList_Private_Shared::~PPB_NetworkList_Private_Shared() { -} - -// static -PP_Resource PPB_NetworkList_Private_Shared::Create( - ResourceObjectType type, - PP_Instance instance, - const scoped_refptr<NetworkListStorage>& list) { - scoped_refptr<PPB_NetworkList_Private_Shared> object( - new PPB_NetworkList_Private_Shared(type, instance, list)); - return object->GetReference(); -} - -::ppapi::thunk::PPB_NetworkList_API* -PPB_NetworkList_Private_Shared::AsPPB_NetworkList_API() { - return this; -} - -const NetworkList& PPB_NetworkList_Private_Shared::GetNetworkListData() const { - return list_->list(); -} - -uint32_t PPB_NetworkList_Private_Shared::GetCount() { - return static_cast<uint32_t>(list_->list().size()); -} - -PP_Var PPB_NetworkList_Private_Shared::GetName(uint32_t index) { - if (index >= list_->list().size()) - return PP_MakeUndefined(); - return StringVar::StringToPPVar(list_->list().at(index).name); -} - -PP_NetworkListType_Private PPB_NetworkList_Private_Shared::GetType( - uint32_t index) { - if (index >= list_->list().size()) - return PP_NETWORKLIST_UNKNOWN; - return list_->list().at(index).type; -} - -PP_NetworkListState_Private PPB_NetworkList_Private_Shared::GetState( - uint32_t index) { - if (index >= list_->list().size()) - return PP_NETWORKLIST_DOWN; - return list_->list().at(index).state; -} - -int32_t PPB_NetworkList_Private_Shared::GetIpAddresses( - uint32_t index, - const PP_ArrayOutput& output) { - ArrayWriter writer(output); - if (index >= list_->list().size() || !writer.is_valid()) - return PP_ERROR_BADARGUMENT; - - thunk::EnterResourceCreationNoLock enter(pp_instance()); - if (enter.failed()) - return PP_ERROR_FAILED; - - const std::vector<PP_NetAddress_Private>& addresses = - list_->list().at(index).addresses; - std::vector<PP_Resource> addr_resources; - for (size_t i = 0; i < addresses.size(); ++i) { - addr_resources.push_back( - enter.functions()->CreateNetAddressFromNetAddressPrivate( - pp_instance(), addresses[i])); - } - if (!writer.StoreResourceVector(addr_resources)) - return PP_ERROR_FAILED; - - return PP_OK; -} - -PP_Var PPB_NetworkList_Private_Shared::GetDisplayName(uint32_t index) { - if (index >= list_->list().size()) - return PP_MakeUndefined(); - return StringVar::StringToPPVar(list_->list().at(index).display_name); -} - -uint32_t PPB_NetworkList_Private_Shared::GetMTU(uint32_t index) { - if (index >= list_->list().size()) - return 0; - return list_->list().at(index).mtu; -} - -} // namespace thunk diff --git a/ppapi/shared_impl/ppb_network_list_private_shared.h b/ppapi/shared_impl/ppb_network_list_private_shared.h deleted file mode 100644 index 8396003..0000000 --- a/ppapi/shared_impl/ppb_network_list_private_shared.h +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef PPAPI_SHARED_IMPL_PPB_NETWORK_LIST_PRIVATE_SHARED_H_ -#define PPAPI_SHARED_IMPL_PPB_NETWORK_LIST_PRIVATE_SHARED_H_ - -#include <string> -#include <vector> - -#include "base/basictypes.h" -#include "base/memory/ref_counted.h" -#include "ppapi/c/private/ppb_net_address_private.h" -#include "ppapi/shared_impl/resource.h" -#include "ppapi/thunk/ppb_network_list_api.h" - -namespace ppapi { - -struct PPAPI_SHARED_EXPORT NetworkInfo { - NetworkInfo(); - ~NetworkInfo(); - - std::string name; - PP_NetworkListType_Private type; - PP_NetworkListState_Private state; - std::vector<PP_NetAddress_Private> addresses; - std::string display_name; - int mtu; -}; -typedef std::vector<NetworkInfo> NetworkList; - -// NetworkListStorage is refcounted container for NetworkList. It -// allows sharing of one NetworkList object between multiple -// NetworkList resources. -class PPAPI_SHARED_EXPORT NetworkListStorage - : public base::RefCountedThreadSafe<NetworkListStorage> { - public: - explicit NetworkListStorage(const NetworkList& list); - - const NetworkList& list() { return list_; } - - private: - friend class base::RefCountedThreadSafe<NetworkListStorage>; - ~NetworkListStorage(); - - NetworkList list_; - - DISALLOW_COPY_AND_ASSIGN(NetworkListStorage); -}; - -class PPAPI_SHARED_EXPORT PPB_NetworkList_Private_Shared - : public ::ppapi::Resource, - public ::ppapi::thunk::PPB_NetworkList_API { - public: - static PP_Resource Create(ResourceObjectType type, - PP_Instance instance, - const scoped_refptr<NetworkListStorage>& list); - - virtual ~PPB_NetworkList_Private_Shared(); - - // Resource override. - virtual ::ppapi::thunk::PPB_NetworkList_API* - AsPPB_NetworkList_API() OVERRIDE; - - // PPB_NetworkList_API implementation. - virtual const NetworkList& GetNetworkListData() const OVERRIDE; - virtual uint32_t GetCount() OVERRIDE; - virtual PP_Var GetName(uint32_t index) OVERRIDE; - virtual PP_NetworkListType_Private GetType(uint32_t index) OVERRIDE; - virtual PP_NetworkListState_Private GetState(uint32_t index) OVERRIDE; - virtual int32_t GetIpAddresses(uint32_t index, - const PP_ArrayOutput& output) OVERRIDE; - virtual PP_Var GetDisplayName(uint32_t index) OVERRIDE; - virtual uint32_t GetMTU(uint32_t index) OVERRIDE; - - private: - PPB_NetworkList_Private_Shared(ResourceObjectType type, - PP_Instance instance, - const scoped_refptr<NetworkListStorage>& list); - - scoped_refptr<NetworkListStorage> list_; - - DISALLOW_COPY_AND_ASSIGN(PPB_NetworkList_Private_Shared); -}; - -} // namespace ppapi - -#endif // PPAPI_SHARED_IMPL_PPB_NETWORK_LIST_PRIVATE_SHARED_H_ diff --git a/ppapi/thunk/interfaces_ppb_private_no_permissions.h b/ppapi/thunk/interfaces_ppb_private_no_permissions.h index 13a60d1..de1faad 100644 --- a/ppapi/thunk/interfaces_ppb_private_no_permissions.h +++ b/ppapi/thunk/interfaces_ppb_private_no_permissions.h @@ -9,8 +9,6 @@ // These interfaces don't require private permissions. However, they only work // for whitelisted origins. -UNPROXIED_API(PPB_NetworkList_Private) -PROXIED_API(PPB_NetworkMonitor_Private) PROXIED_IFACE(NoAPIName, PPB_HOSTRESOLVER_PRIVATE_INTERFACE_0_1, PPB_HostResolver_Private_0_1) @@ -39,8 +37,7 @@ PROXIED_IFACE(NoAPIName, PPB_NETADDRESS_PRIVATE_INTERFACE_1_1, PPB_NetAddress_Private_1_1) PROXIED_IFACE(NoAPIName, PPB_NETWORKLIST_PRIVATE_INTERFACE_0_3, PPB_NetworkList_Private_0_3) -PROXIED_IFACE(PPB_NetworkMonitor_Private, - PPB_NETWORKMONITOR_PRIVATE_INTERFACE_0_3, +PROXIED_IFACE(NoAPIName, PPB_NETWORKMONITOR_PRIVATE_INTERFACE_0_3, PPB_NetworkMonitor_Private_0_3) PROXIED_IFACE(NoAPIName, PPB_EXT_CRXFILESYSTEM_PRIVATE_INTERFACE_0_1, diff --git a/ppapi/thunk/ppb_network_list_api.h b/ppapi/thunk/ppb_network_list_api.h index b8fb9a3..661399a 100644 --- a/ppapi/thunk/ppb_network_list_api.h +++ b/ppapi/thunk/ppb_network_list_api.h @@ -11,20 +11,12 @@ #include "ppapi/thunk/ppapi_thunk_export.h" namespace ppapi { - -struct NetworkInfo; -typedef std::vector<NetworkInfo> NetworkList; - namespace thunk { class PPAPI_THUNK_EXPORT PPB_NetworkList_API { public: virtual ~PPB_NetworkList_API() {} - // This function is not exposed through the C API, but returns the - // internal data for easy proxying. - virtual const NetworkList& GetNetworkListData() const = 0; - // Private API virtual uint32_t GetCount() = 0; virtual PP_Var GetName(uint32_t index) = 0; |