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#ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_HOST_RESOLVER_MESSAGE_FILTER_H_
6#define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_HOST_RESOLVER_MESSAGE_FILTER_H_
7
8#include <string>
9#include <vector>
10
11#include "base/basictypes.h"
12#include "base/compiler_specific.h"
13#include "content/common/content_export.h"
14#include "content/public/common/process_type.h"
15#include "ppapi/c/pp_instance.h"
16#include "ppapi/host/resource_message_filter.h"
17
18struct PP_HostResolver_Private_Hint;
19struct PP_NetAddress_Private;
20
21namespace net {
22class AddressList;
23}
24
25namespace ppapi {
26struct HostPortPair;
27
28namespace host {
29struct HostMessageContext;
30}
31}
32
33namespace content {
34
35class BrowserPpapiHostImpl;
36class ResourceContext;
37
38class CONTENT_EXPORT PepperHostResolverMessageFilter
39    : public ppapi::host::ResourceMessageFilter {
40 public:
41  PepperHostResolverMessageFilter(BrowserPpapiHostImpl* host,
42                                  PP_Instance instance,
43                                  bool private_api);
44
45 protected:
46  virtual ~PepperHostResolverMessageFilter();
47
48 private:
49  typedef std::vector<PP_NetAddress_Private> NetAddressList;
50
51  // ppapi::host::ResourceMessageFilter overrides.
52  virtual scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage(
53      const IPC::Message& message) OVERRIDE;
54  virtual int32_t OnResourceMessageReceived(
55      const IPC::Message& msg,
56      ppapi::host::HostMessageContext* context) OVERRIDE;
57
58  int32_t OnMsgResolve(const ppapi::host::HostMessageContext* context,
59                       const ppapi::HostPortPair& host_port,
60                       const PP_HostResolver_Private_Hint& hint);
61
62  // Backend for OnMsgResolve(). Delegates host resolution to the
63  // Browser's HostResolver. Must be called on the IO thread.
64  void DoResolve(const ppapi::host::ReplyMessageContext& context,
65                 const ppapi::HostPortPair& host_port,
66                 const PP_HostResolver_Private_Hint& hint,
67                 ResourceContext* resource_context);
68
69  void OnLookupFinished(int net_result,
70                        const net::AddressList& addresses,
71                        const ppapi::host::ReplyMessageContext& bound_info);
72  void SendResolveReply(int32_t result,
73                        const std::string& canonical_name,
74                        const NetAddressList& net_address_list,
75                        const ppapi::host::ReplyMessageContext& context);
76  void SendResolveError(int32_t error,
77                        const ppapi::host::ReplyMessageContext& context);
78
79  bool external_plugin_;
80  bool private_api_;
81  int render_process_id_;
82  int render_frame_id_;
83
84  DISALLOW_COPY_AND_ASSIGN(PepperHostResolverMessageFilter);
85};
86
87}  // namespace content
88
89#endif  // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_HOST_RESOLVER_MESSAGE_FILTER_H_
90