summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorikarienator@chromium.org <ikarienator@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-17 00:19:10 +0000
committerikarienator@chromium.org <ikarienator@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-17 00:19:10 +0000
commitea4d18bcd417746286f009a0cadf51ebe408f3de (patch)
tree364d037655b6f89300be744ec51bda692eb5c498
parent50106bf5210c384f90a45cad94992ed22f931cac (diff)
downloadchromium_src-ea4d18bcd417746286f009a0cadf51ebe408f3de.zip
chromium_src-ea4d18bcd417746286f009a0cadf51ebe408f3de.tar.gz
chromium_src-ea4d18bcd417746286f009a0cadf51ebe408f3de.tar.bz2
Revert 223482 "Simplify PPB_NetworkMonitor proxy."
> 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 > > Review URL: https://chromiumcodereview.appspot.com/23819033 TBR=sergeyu@chromium.org Review URL: https://codereview.chromium.org/23463037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223484 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/ppapi_plugin_process_host.cc2
-rw-r--r--content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc2
-rw-r--r--content/browser/renderer_host/pepper/content_browser_pepper_host_factory.cc5
-rw-r--r--content/browser/renderer_host/pepper/pepper_message_filter.cc100
-rw-r--r--content/browser/renderer_host/pepper/pepper_message_filter.h36
-rw-r--r--content/browser/renderer_host/pepper/pepper_network_monitor_host.cc118
-rw-r--r--content/browser/renderer_host/pepper/pepper_network_monitor_host.h50
-rw-r--r--content/content_browser.gypi2
-rw-r--r--content/ppapi_plugin/ppapi_thread.cc2
-rw-r--r--content/public/common/socket_permission_request.h3
-rw-r--r--ppapi/ppapi_proxy.gypi6
-rw-r--r--ppapi/ppapi_shared.gypi2
-rw-r--r--ppapi/proxy/interface_list.cc1
-rw-r--r--ppapi/proxy/network_list_resource.cc89
-rw-r--r--ppapi/proxy/network_list_resource.h52
-rw-r--r--ppapi/proxy/network_monitor_resource.cc85
-rw-r--r--ppapi/proxy/network_monitor_resource.h58
-rw-r--r--ppapi/proxy/ppapi_messages.h22
-rw-r--r--ppapi/proxy/ppb_network_monitor_private_proxy.cc174
-rw-r--r--ppapi/proxy/ppb_network_monitor_private_proxy.h58
-rw-r--r--ppapi/proxy/resource_creation_proxy.cc5
-rw-r--r--ppapi/proxy/serialized_structs.cc8
-rw-r--r--ppapi/proxy/serialized_structs.h15
-rw-r--r--ppapi/shared_impl/api_id.h1
-rw-r--r--ppapi/shared_impl/ppb_network_list_private_shared.cc123
-rw-r--r--ppapi/shared_impl/ppb_network_list_private_shared.h88
-rw-r--r--ppapi/thunk/interfaces_ppb_private_no_permissions.h5
-rw-r--r--ppapi/thunk/ppb_network_list_api.h8
28 files changed, 611 insertions, 509 deletions
diff --git a/content/browser/ppapi_plugin_process_host.cc b/content/browser/ppapi_plugin_process_host.cc
index ecbbfd6..3183a84 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();
+ filter_ = new PepperMessageFilter(permissions_);
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 db3f8ef..7368932 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());
+ new PepperMessageFilter(permissions));
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 46e8c13..97e3173 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,7 +11,6 @@
#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"
@@ -199,10 +198,6 @@ 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 6434729..197a303 100644
--- a/content/browser/renderer_host/pepper/pepper_message_filter.cc
+++ b/content/browser/renderer_host/pepper/pepper_message_filter.cc
@@ -4,20 +4,32 @@
#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"
-namespace content {
+using ppapi::NetAddressPrivateImpl;
-PepperMessageFilter::PepperMessageFilter() {}
-PepperMessageFilter::~PepperMessageFilter() {}
+namespace content {
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);
@@ -27,6 +39,41 @@ 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,
@@ -37,4 +84,51 @@ 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 3f5010e..a2aa226 100644
--- a/content/browser/renderer_host/pepper/pepper_message_filter.h
+++ b/content/browser/renderer_host/pepper/pepper_message_filter.h
@@ -5,12 +5,17 @@
#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;
@@ -18,23 +23,48 @@ class PPB_X509Certificate_Fields;
namespace content {
-// Message filter that handles IPC for PPB_X509Certificate_Private.
-class PepperMessageFilter : public BrowserMessageFilter {
+// Message filter that handles IPC for PPB_NetworkMonitor_Private and
+// PPB_X509Certificate_Private.
+class PepperMessageFilter
+ : public BrowserMessageFilter,
+ public net::NetworkChangeNotifier::IPAddressObserver {
public:
- PepperMessageFilter();
+ explicit PepperMessageFilter(const ppapi::PpapiPermissions& permissions);
// 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
deleted file mode 100644
index 15993f6..0000000
--- a/content/browser/renderer_host/pepper/pepper_network_monitor_host.cc
+++ /dev/null
@@ -1,118 +0,0 @@
-// 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 "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
deleted file mode 100644
index e27f8a2..0000000
--- a/content/browser/renderer_host/pepper/pepper_network_monitor_host.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// 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 09b16c8..49bd34d 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -945,8 +945,6 @@
'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 2d46807..c4021cb 100644
--- a/content/ppapi_plugin/ppapi_thread.cc
+++ b/content/ppapi_plugin/ppapi_thread.cc
@@ -103,6 +103,8 @@ 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 13b9ed1..278880e 100644
--- a/content/public/common/socket_permission_request.h
+++ b/content/public/common/socket_permission_request.h
@@ -20,8 +20,7 @@ struct SocketPermissionRequest {
UDP_SEND_TO,
UDP_MULTICAST_MEMBERSHIP,
RESOLVE_HOST,
- RESOLVE_PROXY,
- NETWORK_STATE
+ RESOLVE_PROXY
};
SocketPermissionRequest(OperationType type,
diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi
index d0bbe65..52b97e9 100644
--- a/ppapi/ppapi_proxy.gypi
+++ b/ppapi/ppapi_proxy.gypi
@@ -82,10 +82,6 @@
'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',
@@ -131,6 +127,8 @@
'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 8c9b658..e638498 100644
--- a/ppapi/ppapi_shared.gypi
+++ b/ppapi/ppapi_shared.gypi
@@ -68,6 +68,8 @@
'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 409f12f..115516f 100644
--- a/ppapi/proxy/interface_list.cc
+++ b/ppapi/proxy/interface_list.cc
@@ -107,6 +107,7 @@
#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
deleted file mode 100644
index 789e4f2..0000000
--- a/ppapi/proxy/network_list_resource.cc
+++ /dev/null
@@ -1,89 +0,0 @@
-// 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_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
deleted file mode 100644
index 618ba02..0000000
--- a/ppapi/proxy/network_list_resource.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// 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_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
deleted file mode 100644
index 0dfb0b4..0000000
--- a/ppapi/proxy/network_monitor_resource.cc
+++ /dev/null
@@ -1,85 +0,0 @@
-// 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
deleted file mode 100644
index d227934..0000000
--- a/ppapi/proxy/network_monitor_resource.h
+++ /dev/null
@@ -1,58 +0,0 @@
-// 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 9108ea1e..b970d36 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -47,7 +47,6 @@
#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"
@@ -62,6 +61,7 @@
#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::proxy::SerializedNetworkInfo)
+IPC_STRUCT_TRAITS_BEGIN(ppapi::NetworkInfo)
IPC_STRUCT_TRAITS_MEMBER(name)
IPC_STRUCT_TRAITS_MEMBER(type)
IPC_STRUCT_TRAITS_MEMBER(state)
@@ -625,6 +625,11 @@ 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 */,
@@ -1077,6 +1082,12 @@ 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,
@@ -1430,13 +1441,6 @@ 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
new file mode 100644
index 0000000..26bad03
--- /dev/null
+++ b/ppapi/proxy/ppb_network_monitor_private_proxy.cc
@@ -0,0 +1,174 @@
+// 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
new file mode 100644
index 0000000..7dbcbd6
--- /dev/null
+++ b/ppapi/proxy/ppb_network_monitor_private_proxy.h
@@ -0,0 +1,58 @@
+// 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 a3ce05e..3bb1140 100644
--- a/ppapi/proxy/resource_creation_proxy.cc
+++ b/ppapi/proxy/resource_creation_proxy.cc
@@ -19,7 +19,6 @@
#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"
@@ -31,6 +30,7 @@
#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,8 +313,7 @@ PP_Resource ResourceCreationProxy::CreateNetAddressFromNetAddressPrivate(
PP_Resource ResourceCreationProxy::CreateNetworkMonitorPrivate(
PP_Instance instance) {
- return (new NetworkMonitorResource(GetConnection(), instance))->
- GetReference();
+ return PPB_NetworkMonitor_Private_Proxy::CreateProxyResource(instance);
}
PP_Resource ResourceCreationProxy::CreatePrinting(PP_Instance instance) {
diff --git a/ppapi/proxy/serialized_structs.cc b/ppapi/proxy/serialized_structs.cc
index d645dd8..8c984d5 100644
--- a/ppapi/proxy/serialized_structs.cc
+++ b/ppapi/proxy/serialized_structs.cc
@@ -80,14 +80,6 @@ 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 74525f3..1f89ae2 100644
--- a/ppapi/proxy/serialized_structs.h
+++ b/ppapi/proxy/serialized_structs.h
@@ -16,8 +16,6 @@
#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"
@@ -59,19 +57,6 @@ 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 c482a02..49e0dcb 100644
--- a/ppapi/shared_impl/api_id.h
+++ b/ppapi/shared_impl/api_id.h
@@ -35,6 +35,7 @@ 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
new file mode 100644
index 0000000..d299c06
--- /dev/null
+++ b/ppapi/shared_impl/ppb_network_list_private_shared.cc
@@ -0,0 +1,123 @@
+// 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
new file mode 100644
index 0000000..8396003
--- /dev/null
+++ b/ppapi/shared_impl/ppb_network_list_private_shared.h
@@ -0,0 +1,88 @@
+// 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 de1faad..13a60d1 100644
--- a/ppapi/thunk/interfaces_ppb_private_no_permissions.h
+++ b/ppapi/thunk/interfaces_ppb_private_no_permissions.h
@@ -9,6 +9,8 @@
// 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)
@@ -37,7 +39,8 @@ 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(NoAPIName, PPB_NETWORKMONITOR_PRIVATE_INTERFACE_0_3,
+PROXIED_IFACE(PPB_NetworkMonitor_Private,
+ 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 661399a..b8fb9a3 100644
--- a/ppapi/thunk/ppb_network_list_api.h
+++ b/ppapi/thunk/ppb_network_list_api.h
@@ -11,12 +11,20 @@
#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;