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 #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_
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"
21 struct ExtensionHostMsg_Request_Params;
28 class BrowserPpapiHost;
33 class PepperExtensionsCommonMessageFilter
34 : public ppapi::host::ResourceMessageFilter {
36 static PepperExtensionsCommonMessageFilter* Create(
37 content::BrowserPpapiHost* host,
38 PP_Instance instance);
41 PepperExtensionsCommonMessageFilter(int render_process_id,
43 const base::FilePath& profile_directory,
44 const GURL& document_url);
45 virtual ~PepperExtensionsCommonMessageFilter();
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;
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;
62 int32_t OnPost(ppapi::host::HostMessageContext* context,
63 const std::string& request_name,
64 base::ListValue& args);
66 int32_t OnCall(ppapi::host::HostMessageContext* context,
67 const std::string& request_name,
68 base::ListValue& args);
70 // Returns true if |dispatcher_owner_| is non-null.
71 bool EnsureDispatcherOwnerInitialized();
72 // Resets |dispatcher_owner_| to NULL.
73 void DetachDispatcherOwner();
75 void PopulateParams(const std::string& request_name,
76 base::ListValue* args,
78 ExtensionHostMsg_Request_Params* params);
80 void OnCallCompleted(ppapi::host::ReplyMessageContext reply_context,
81 ExtensionFunction::ResponseType type,
82 const base::ListValue& results,
83 const std::string& error);
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_;
89 base::FilePath profile_directory_;
92 // Not-owning pointer. It will be set to NULL when it goes away.
93 DispatcherOwner* dispatcher_owner_;
94 bool dispatcher_owner_initialized_;
96 DISALLOW_COPY_AND_ASSIGN(PepperExtensionsCommonMessageFilter);
101 #endif // CHROME_BROWSER_RENDERER_HOST_PEPPER_PEPPER_EXTENSIONS_COMMON_MESSAGE_FILTER_H_