Add ICU message format support
[chromium-blink-merge.git] / content / browser / renderer_host / pepper / browser_ppapi_host_impl.h
blobd8514347eb606409b9cafd1b41e1209f538edfa1
1 // Copyright (c) 2012 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 CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/containers/scoped_ptr_hash_map.h"
14 #include "base/files/file_path.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/observer_list.h"
18 #include "base/process/process.h"
19 #include "content/browser/renderer_host/pepper/content_browser_pepper_host_factory.h"
20 #include "content/browser/renderer_host/pepper/ssl_context_helper.h"
21 #include "content/common/content_export.h"
22 #include "content/common/pepper_renderer_instance_data.h"
23 #include "content/public/browser/browser_ppapi_host.h"
24 #include "content/public/common/process_type.h"
25 #include "ipc/message_filter.h"
26 #include "ppapi/host/ppapi_host.h"
28 #if !defined(ENABLE_PLUGINS)
29 #error "Plugins should be enabled"
30 #endif
32 namespace content {
34 class CONTENT_EXPORT BrowserPpapiHostImpl : public BrowserPpapiHost {
35 public:
36 class InstanceObserver {
37 public:
38 // Called when the plugin instance is throttled or unthrottled because of
39 // the Plugin Power Saver feature. Invoked on the IO thread.
40 virtual void OnThrottleStateChanged(bool is_throttled) = 0;
42 // Called right before the instance is destroyed.
43 virtual void OnHostDestroyed() = 0;
46 // The creator is responsible for calling set_plugin_process as soon as it is
47 // known (we start the process asynchronously so it won't be known when this
48 // object is created).
49 // |external_plugin| signfies that this is a proxy created for an embedder's
50 // plugin, i.e. using BrowserPpapiHost::CreateExternalPluginProcess.
51 BrowserPpapiHostImpl(IPC::Sender* sender,
52 const ppapi::PpapiPermissions& permissions,
53 const std::string& plugin_name,
54 const base::FilePath& plugin_path,
55 const base::FilePath& profile_data_directory,
56 bool in_process,
57 bool external_plugin);
58 ~BrowserPpapiHostImpl() override;
60 // BrowserPpapiHost.
61 ppapi::host::PpapiHost* GetPpapiHost() override;
62 const base::Process& GetPluginProcess() const override;
63 bool IsValidInstance(PP_Instance instance) const override;
64 bool GetRenderFrameIDsForInstance(PP_Instance instance,
65 int* render_process_id,
66 int* render_frame_id) const override;
67 const std::string& GetPluginName() override;
68 const base::FilePath& GetPluginPath() override;
69 const base::FilePath& GetProfileDataDirectory() override;
70 GURL GetDocumentURLForInstance(PP_Instance instance) override;
71 GURL GetPluginURLForInstance(PP_Instance instance) override;
72 void SetOnKeepaliveCallback(
73 const BrowserPpapiHost::OnKeepaliveCallback& callback) override;
75 // Whether the plugin context is secure. That is, it is served from a secure
76 // origin and it is embedded within a hierarchy of secure frames. This value
77 // comes from the renderer so should not be trusted. It is used for metrics.
78 bool IsPotentiallySecurePluginContext(PP_Instance instance);
80 void set_plugin_process(base::Process process) {
81 plugin_process_ = process.Pass();
84 bool external_plugin() const { return external_plugin_; }
86 // These two functions are notifications that an instance has been created
87 // or destroyed. They allow us to maintain a mapping of PP_Instance to data
88 // associated with the instance including view IDs in the browser process.
89 void AddInstance(PP_Instance instance,
90 const PepperRendererInstanceData& renderer_instance_data);
91 void DeleteInstance(PP_Instance instance);
93 void AddInstanceObserver(PP_Instance instance, InstanceObserver* observer);
94 void RemoveInstanceObserver(PP_Instance instance, InstanceObserver* observer);
96 void OnThrottleStateChanged(PP_Instance instance, bool is_throttled);
97 bool IsThrottled(PP_Instance instance) const;
99 scoped_refptr<IPC::MessageFilter> message_filter() {
100 return message_filter_;
103 const scoped_refptr<SSLContextHelper>& ssl_context_helper() const {
104 return ssl_context_helper_;
107 private:
108 friend class BrowserPpapiHostTest;
110 // Implementing MessageFilter on BrowserPpapiHostImpl makes it ref-counted,
111 // preventing us from returning these to embedders without holding a
112 // reference. To avoid that, define a message filter object.
113 class HostMessageFilter : public IPC::MessageFilter {
114 public:
115 HostMessageFilter(ppapi::host::PpapiHost* ppapi_host,
116 BrowserPpapiHostImpl* browser_ppapi_host_impl);
118 // IPC::MessageFilter.
119 bool OnMessageReceived(const IPC::Message& msg) override;
121 void OnHostDestroyed();
123 private:
124 ~HostMessageFilter() override;
126 void OnKeepalive();
127 void OnHostMsgLogInterfaceUsage(int hash) const;
129 // Non owning pointers cleared in OnHostDestroyed()
130 ppapi::host::PpapiHost* ppapi_host_;
131 BrowserPpapiHostImpl* browser_ppapi_host_impl_;
134 struct InstanceData {
135 InstanceData(const PepperRendererInstanceData& renderer_data);
136 ~InstanceData();
138 PepperRendererInstanceData renderer_data;
139 bool is_throttled;
141 base::ObserverList<InstanceObserver> observer_list;
144 // Reports plugin activity to the callback set with SetOnKeepaliveCallback.
145 void OnKeepalive();
147 scoped_ptr<ppapi::host::PpapiHost> ppapi_host_;
148 base::Process plugin_process_;
149 std::string plugin_name_;
150 base::FilePath plugin_path_;
151 base::FilePath profile_data_directory_;
153 // If true, this refers to a plugin running in the renderer process.
154 bool in_process_;
156 // If true, this is an external plugin, i.e. created by the embedder using
157 // BrowserPpapiHost::CreateExternalPluginProcess.
158 bool external_plugin_;
160 scoped_refptr<SSLContextHelper> ssl_context_helper_;
162 // Tracks all PP_Instances in this plugin and associated data.
163 base::ScopedPtrHashMap<PP_Instance, scoped_ptr<InstanceData>> instance_map_;
165 scoped_refptr<HostMessageFilter> message_filter_;
167 BrowserPpapiHost::OnKeepaliveCallback on_keepalive_callback_;
169 DISALLOW_COPY_AND_ASSIGN(BrowserPpapiHostImpl);
172 } // namespace content
174 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_