Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / renderer_host / pepper / pepper_extensions_common_message_filter.h
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.
4
5 #ifndef CHROME_BROWSER_RENDERER_HOST_PEPPER_PEPPER_EXTENSIONS_COMMON_MESSAGE_FILTER_H_
6 #define CHROME_BROWSER_RENDERER_HOST_PEPPER_PEPPER_EXTENSIONS_COMMON_MESSAGE_FILTER_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/string16.h"
15 #include "extensions/browser/extension_function.h"
16 #include "ppapi/c/pp_instance.h"
17 #include "ppapi/host/host_message_context.h"
18 #include "ppapi/host/resource_message_filter.h"
19 #include "url/gurl.h"
20
21 struct ExtensionHostMsg_Request_Params;
22
23 namespace base {
24 class ListValue;
25 }
26
27 namespace content {
28 class BrowserPpapiHost;
29 }
30
31 namespace chrome {
32
33 class PepperExtensionsCommonMessageFilter
34     : public ppapi::host::ResourceMessageFilter {
35  public:
36   static PepperExtensionsCommonMessageFilter* Create(
37       content::BrowserPpapiHost* host,
38       PP_Instance instance);
39
40  protected:
41   PepperExtensionsCommonMessageFilter(int render_process_id,
42                                       int render_frame_id,
43                                       const base::FilePath& profile_directory,
44                                       const GURL& document_url);
45   virtual ~PepperExtensionsCommonMessageFilter();
46
47   // ppapi::host::ResourceMessageFilter overrides.
48   virtual scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage(
49       const IPC::Message& msg) OVERRIDE;
50   virtual int32_t OnResourceMessageReceived(
51       const IPC::Message& msg,
52       ppapi::host::HostMessageContext* context) OVERRIDE;
53
54  private:
55   // DispatcherOwner holds an ExtensionFunctionDispatcher instance and acts as
56   // its delegate. It is designed to meet the lifespan requirements of
57   // ExtensionFunctionDispatcher and its delegate. (Please see the comment of
58   // ExtensionFunctionDispatcher constructor in
59   // extension_function_dispatcher.h.)
60   class DispatcherOwner;
61
62   int32_t OnPost(ppapi::host::HostMessageContext* context,
63                  const std::string& request_name,
64                  base::ListValue& args);
65
66   int32_t OnCall(ppapi::host::HostMessageContext* context,
67                  const std::string& request_name,
68                  base::ListValue& args);
69
70   // Returns true if |dispatcher_owner_| is non-null.
71   bool EnsureDispatcherOwnerInitialized();
72   // Resets |dispatcher_owner_| to NULL.
73   void DetachDispatcherOwner();
74
75   void PopulateParams(const std::string& request_name,
76                       base::ListValue* args,
77                       bool has_callback,
78                       ExtensionHostMsg_Request_Params* params);
79
80   void OnCallCompleted(ppapi::host::ReplyMessageContext reply_context,
81                        ExtensionFunction::ResponseType type,
82                        const base::ListValue& results,
83                        const std::string& error);
84
85   // All the members are initialized on the IO thread when the object is
86   // constructed, and accessed only on the UI thread afterwards.
87   int render_process_id_;
88   int render_frame_id_;
89   base::FilePath profile_directory_;
90   GURL document_url_;
91
92   // Not-owning pointer. It will be set to NULL when it goes away.
93   DispatcherOwner* dispatcher_owner_;
94   bool dispatcher_owner_initialized_;
95
96   DISALLOW_COPY_AND_ASSIGN(PepperExtensionsCommonMessageFilter);
97 };
98
99 }  // namespace chrome
100
101 #endif  // CHROME_BROWSER_RENDERER_HOST_PEPPER_PEPPER_EXTENSIONS_COMMON_MESSAGE_FILTER_H_