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
3 * found in the LICENSE file.
4 */
5
6/**
7 * This file defines the <code>PPB_HostResolver</code> interface.
8 */
9
10[generate_thunk]
11
12label Chrome {
13  M29 = 1.0
14};
15
16/**
17 * <code>PP_HostResolver_Flag</code> is an enumeration of flags which can be
18 * OR-ed and passed to the host resolver. Currently there is only one flag
19 * defined.
20 */
21[assert_size(4)]
22enum PP_HostResolver_Flag {
23  /**
24   * Hint to request the canonical name of the host, which can be retrieved by
25   * <code>GetCanonicalName()</code>.
26   */
27  PP_HOSTRESOLVER_FLAG_CANONNAME = 1 << 0
28};
29
30/**
31 * <code>PP_HostResolver_Hint</code> represents hints for host resolution.
32 */
33[assert_size(8)]
34struct PP_HostResolver_Hint {
35  /**
36   * Network address family.
37   */
38  PP_NetAddress_Family family;
39  /**
40   * Combination of flags from <code>PP_HostResolver_Flag</code>.
41   */
42  int32_t flags;
43};
44
45/**
46 * The <code>PPB_HostResolver</code> interface supports host name
47 * resolution.
48 *
49 * Permissions: In order to run <code>Resolve()</code>, apps permission
50 * <code>socket</code> with subrule <code>resolve-host</code> is required.
51 * For more details about network communication permissions, please see:
52 * http://developer.chrome.com/apps/app_network.html
53 */
54interface PPB_HostResolver {
55  /**
56   * Creates a host resolver resource.
57   *
58   * @param[in] instance A <code>PP_Instance</code> identifying one instance of
59   * a module.
60   *
61   * @return A <code>PP_Resource</code> corresponding to a host reslover or 0
62   * on failure.
63   */
64  PP_Resource Create([in] PP_Instance instance);
65
66  /**
67   * Determines if a given resource is a host resolver.
68   *
69   * @param[in] resource A <code>PP_Resource</code> to check.
70   *
71   * @return <code>PP_TRUE</code> if the input is a
72   * <code>PPB_HostResolver</code> resource; <code>PP_FALSE</code> otherwise.
73   */
74  PP_Bool IsHostResolver([in] PP_Resource resource);
75
76  /**
77   * Requests resolution of a host name. If the call completes successfully, the
78   * results can be retrieved by <code>GetCanonicalName()</code>,
79   * <code>GetNetAddressCount()</code> and <code>GetNetAddress()</code>.
80   *
81   * @param[in] host_resolver A <code>PP_Resource</code> corresponding to a host
82   * resolver.
83   * @param[in] host The host name (or IP address literal) to resolve.
84   * @param[in] port The port number to be set in the resulting network
85   * addresses.
86   * @param[in] hint A <code>PP_HostResolver_Hint</code> structure providing
87   * hints for host resolution.
88   * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
89   * completion.
90   *
91   * @return An int32_t containing an error code from <code>pp_errors.h</code>.
92   * <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have
93   * required permissions. <code>PP_ERROR_NAME_NOT_RESOLVED</code> will be
94   * returned if the host name couldn't be resolved.
95   */
96  int32_t Resolve([in] PP_Resource host_resolver,
97                  [in] str_t host,
98                  [in] uint16_t port,
99                  [in] PP_HostResolver_Hint hint,
100                  [in] PP_CompletionCallback callback);
101
102  /**
103   * Gets the canonical name of the host.
104   *
105   * @param[in] host_resolver A <code>PP_Resource</code> corresponding to a host
106   * resolver.
107   *
108   * @return A string <code>PP_Var</code> on success, which is an empty string
109   * if <code>PP_HOSTRESOLVER_FLAG_CANONNAME</code> is not set in the hint flags
110   * when calling <code>Resolve()</code>; an undefined <code>PP_Var</code> if
111   * there is a pending <code>Resolve()</code> call or the previous
112   * <code>Resolve()</code> call failed.
113   */
114  PP_Var GetCanonicalName([in] PP_Resource host_resolver);
115
116  /**
117   * Gets the number of network addresses.
118   *
119   * @param[in] host_resolver A <code>PP_Resource</code> corresponding to a host
120   * resolver.
121   *
122   * @return The number of available network addresses on success; 0 if there is
123   * a pending <code>Resolve()</code> call or the previous
124   * <code>Resolve()</code> call failed.
125   */
126  uint32_t GetNetAddressCount([in] PP_Resource host_resolver);
127
128  /**
129   * Gets a network address.
130   *
131   * @param[in] host_resolver A <code>PP_Resource</code> corresponding to a host
132   * resolver.
133   * @param[in] index An index indicating which address to return.
134   *
135   * @return A <code>PPB_NetAddress</code> resource on success; 0 if there is a
136   * pending <code>Resolve()</code> call or the previous <code>Resolve()</code>
137   * call failed, or the specified index is out of range.
138   */
139  PP_Resource GetNetAddress([in] PP_Resource host_resolver,
140                            [in] uint32_t index);
141};
142