1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/proxy/network_proxy_resource.h"
8 #include "ppapi/proxy/dispatch_reply_message.h"
9 #include "ppapi/proxy/ppapi_messages.h"
10 #include "ppapi/shared_impl/tracked_callback.h"
11 #include "ppapi/shared_impl/var.h"
16 NetworkProxyResource::NetworkProxyResource(Connection connection
,
18 : PluginResource(connection
, instance
) {
19 SendCreate(BROWSER
, PpapiHostMsg_NetworkProxy_Create());
22 NetworkProxyResource::~NetworkProxyResource() {
25 thunk::PPB_NetworkProxy_API
* NetworkProxyResource::AsPPB_NetworkProxy_API() {
29 int32_t NetworkProxyResource::GetProxyForURL(
30 PP_Instance
/* instance */,
33 scoped_refptr
<TrackedCallback
> callback
) {
34 StringVar
* string_url
= StringVar::FromPPVar(url
);
36 return PP_ERROR_BADARGUMENT
;
37 Call
<PpapiPluginMsg_NetworkProxy_GetProxyForURLReply
>(
39 PpapiHostMsg_NetworkProxy_GetProxyForURL(string_url
->value()),
40 base::Bind(&NetworkProxyResource::OnPluginMsgGetProxyForURLReply
,
41 base::Unretained(this),
42 base::Unretained(proxy_string
),
44 return PP_OK_COMPLETIONPENDING
;
47 void NetworkProxyResource::OnPluginMsgGetProxyForURLReply(
48 PP_Var
* proxy_string_out_param
,
49 scoped_refptr
<TrackedCallback
> callback
,
50 const ResourceMessageReplyParams
& params
,
51 const std::string
& proxy_string
) {
52 if (!TrackedCallback::IsPending(callback
)) {
53 // The callback should not have already been run. If this resource is
54 // deleted, LastPluginRefWasReleased in PluginResource should abort the
55 // callback and should not run this callback.
59 if (params
.result() == PP_OK
) {
60 *proxy_string_out_param
= (new StringVar(proxy_string
))->GetPPVar();
62 callback
->Run(params
.result());