OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/proxy/host_resolver_resource_base.h" | 5 #include "ppapi/proxy/host_resolver_resource_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/proxy/error_conversion.h" |
9 #include "ppapi/proxy/net_address_resource.h" | 10 #include "ppapi/proxy/net_address_resource.h" |
10 #include "ppapi/proxy/ppapi_messages.h" | 11 #include "ppapi/proxy/ppapi_messages.h" |
11 #include "ppapi/shared_impl/tracked_callback.h" | 12 #include "ppapi/shared_impl/tracked_callback.h" |
12 #include "ppapi/shared_impl/var.h" | 13 #include "ppapi/shared_impl/var.h" |
13 | 14 |
14 namespace ppapi { | 15 namespace ppapi { |
15 namespace proxy { | 16 namespace proxy { |
16 | 17 |
17 namespace { | |
18 | |
19 int32_t ConvertPPError(int32_t pp_error, bool private_api) { | |
20 // The private API doesn't return network-specific error codes or | |
21 // PP_ERROR_NOACCESS. In order to preserve the behavior, we convert those to | |
22 // PP_ERROR_FAILED. | |
23 // TODO(yzshen): Consider defining ranges for different kinds of PP_Error | |
24 // codes, so that we can detect network-specific error codes in a better way. | |
25 if (private_api && | |
26 (pp_error <= PP_ERROR_CONNECTION_CLOSED || | |
27 pp_error == PP_ERROR_NOACCESS)) { | |
28 return PP_ERROR_FAILED; | |
29 } | |
30 | |
31 return pp_error; | |
32 } | |
33 | |
34 } // namespace | |
35 | |
36 HostResolverResourceBase::HostResolverResourceBase(Connection connection, | 18 HostResolverResourceBase::HostResolverResourceBase(Connection connection, |
37 PP_Instance instance, | 19 PP_Instance instance, |
38 bool private_api) | 20 bool private_api) |
39 : PluginResource(connection, instance), | 21 : PluginResource(connection, instance), |
40 private_api_(private_api), | 22 private_api_(private_api), |
41 allow_get_results_(false) { | 23 allow_get_results_(false) { |
42 if (private_api) | 24 if (private_api) |
43 SendCreate(BROWSER, PpapiHostMsg_HostResolver_CreatePrivate()); | 25 SendCreate(BROWSER, PpapiHostMsg_HostResolver_CreatePrivate()); |
44 else | 26 else |
45 SendCreate(BROWSER, PpapiHostMsg_HostResolver_Create()); | 27 SendCreate(BROWSER, PpapiHostMsg_HostResolver_Create()); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 net_address_list.begin(); | 85 net_address_list.begin(); |
104 iter != net_address_list.end(); | 86 iter != net_address_list.end(); |
105 ++iter) { | 87 ++iter) { |
106 net_address_list_.push_back( | 88 net_address_list_.push_back( |
107 new NetAddressResource(connection(), pp_instance(), *iter)); | 89 new NetAddressResource(connection(), pp_instance(), *iter)); |
108 } | 90 } |
109 } else { | 91 } else { |
110 canonical_name_.clear(); | 92 canonical_name_.clear(); |
111 net_address_list_.clear(); | 93 net_address_list_.clear(); |
112 } | 94 } |
113 resolve_callback_->Run(ConvertPPError(params.result(), private_api_)); | 95 resolve_callback_->Run(ConvertNetworkAPIErrorForCompatibility(params.result(), |
| 96 private_api_)); |
114 } | 97 } |
115 | 98 |
116 void HostResolverResourceBase::SendResolve( | 99 void HostResolverResourceBase::SendResolve( |
117 const HostPortPair& host_port, | 100 const HostPortPair& host_port, |
118 const PP_HostResolver_Private_Hint* hint) { | 101 const PP_HostResolver_Private_Hint* hint) { |
119 PpapiHostMsg_HostResolver_Resolve msg(host_port, *hint); | 102 PpapiHostMsg_HostResolver_Resolve msg(host_port, *hint); |
120 Call<PpapiPluginMsg_HostResolver_ResolveReply>( | 103 Call<PpapiPluginMsg_HostResolver_ResolveReply>( |
121 BROWSER, | 104 BROWSER, |
122 msg, | 105 msg, |
123 base::Bind(&HostResolverResourceBase::OnPluginMsgResolveReply, | 106 base::Bind(&HostResolverResourceBase::OnPluginMsgResolveReply, |
124 base::Unretained(this))); | 107 base::Unretained(this))); |
125 } | 108 } |
126 | 109 |
127 bool HostResolverResourceBase::ResolveInProgress() const { | 110 bool HostResolverResourceBase::ResolveInProgress() const { |
128 return TrackedCallback::IsPending(resolve_callback_); | 111 return TrackedCallback::IsPending(resolve_callback_); |
129 } | 112 } |
130 | 113 |
131 } // namespace proxy | 114 } // namespace proxy |
132 } // namespace ppapi | 115 } // namespace ppapi |
OLD | NEW |