forked from sanyaade-mobiledev/chromium.src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 Review URL: https://chromiumcodereview.appspot.com/23819033 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223494 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
sergeyu@chromium.org
committed
Sep 17, 2013
1 parent
6ab4a44
commit 2ff98b5
Showing
28 changed files
with
509 additions
and
611 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
content/browser/renderer_host/pepper/pepper_network_monitor_host.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// 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 |
Oops, something went wrong.