chrome_render_message_filter.h revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
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.
4
5#ifndef CHROME_BROWSER_RENDERER_HOST_CHROME_RENDER_MESSAGE_FILTER_H_
6#define CHROME_BROWSER_RENDERER_HOST_CHROME_RENDER_MESSAGE_FILTER_H_
7
8#include <string>
9#include <vector>
10
11#include "base/files/file_path.h"
12#include "base/memory/weak_ptr.h"
13#include "base/sequenced_task_runner_helpers.h"
14#include "chrome/browser/profiles/profile.h"
15#include "chrome/common/content_settings.h"
16#include "content/public/browser/browser_message_filter.h"
17#include "third_party/WebKit/public/web/WebCache.h"
18
19class CookieSettings;
20struct ExtensionHostMsg_APIActionOrEvent_Params;
21struct ExtensionHostMsg_DOMAction_Params;
22struct ExtensionHostMsg_Request_Params;
23struct ExtensionMsg_ExternalConnectionInfo;
24class ExtensionInfoMap;
25class GURL;
26
27namespace net {
28class HostResolver;
29class URLRequestContextGetter;
30}
31
32// This class filters out incoming Chrome-specific IPC messages for the renderer
33// process on the IPC thread.
34class ChromeRenderMessageFilter : public content::BrowserMessageFilter {
35 public:
36  ChromeRenderMessageFilter(int render_process_id,
37                            Profile* profile,
38                            net::URLRequestContextGetter* request_context);
39
40  // Notification detail classes.
41  class FPSDetails {
42   public:
43    FPSDetails(int routing_id, float fps)
44        : routing_id_(routing_id),
45          fps_(fps) {}
46    int routing_id() const { return routing_id_; }
47    float fps() const { return fps_; }
48   private:
49    int routing_id_;
50    float fps_;
51  };
52
53  class V8HeapStatsDetails {
54   public:
55    V8HeapStatsDetails(size_t v8_memory_allocated,
56                       size_t v8_memory_used)
57        : v8_memory_allocated_(v8_memory_allocated),
58          v8_memory_used_(v8_memory_used) {}
59    size_t v8_memory_allocated() const { return v8_memory_allocated_; }
60    size_t v8_memory_used() const { return v8_memory_used_; }
61   private:
62    size_t v8_memory_allocated_;
63    size_t v8_memory_used_;
64  };
65
66  // content::BrowserMessageFilter methods:
67  virtual bool OnMessageReceived(const IPC::Message& message,
68                                 bool* message_was_ok) OVERRIDE;
69  virtual void OverrideThreadForMessage(
70      const IPC::Message& message,
71      content::BrowserThread::ID* thread) OVERRIDE;
72
73  int render_process_id() { return render_process_id_; }
74  bool off_the_record() { return off_the_record_; }
75  net::HostResolver* GetHostResolver();
76
77 private:
78  friend class content::BrowserThread;
79  friend class base::DeleteHelper<ChromeRenderMessageFilter>;
80
81  virtual ~ChromeRenderMessageFilter();
82
83  void OnDnsPrefetch(const std::vector<std::string>& hostnames);
84  void OnPreconnect(const GURL& url);
85  void OnResourceTypeStats(const WebKit::WebCache::ResourceTypeStats& stats);
86  void OnUpdatedCacheStats(const WebKit::WebCache::UsageStats& stats);
87  void OnFPS(int routing_id, float fps);
88  void OnV8HeapStats(int v8_memory_allocated, int v8_memory_used);
89  void OnOpenChannelToExtension(int routing_id,
90                                const ExtensionMsg_ExternalConnectionInfo& info,
91                                const std::string& channel_name,
92                                bool include_tls_channel_id,
93                                int* port_id);
94  void OpenChannelToExtensionOnUIThread(
95      int source_process_id,
96      int source_routing_id,
97      int receiver_port_id,
98      const ExtensionMsg_ExternalConnectionInfo& info,
99      const std::string& channel_name,
100      bool include_tls_channel_id);
101  void OnOpenChannelToNativeApp(int routing_id,
102                                const std::string& source_extension_id,
103                                const std::string& native_app_name,
104                                int* port_id);
105  void OpenChannelToNativeAppOnUIThread(int source_routing_id,
106                                        int receiver_port_id,
107                                        const std::string& source_extension_id,
108                                        const std::string& native_app_name);
109  void OnOpenChannelToTab(int routing_id, int tab_id,
110                          const std::string& extension_id,
111                          const std::string& channel_name, int* port_id);
112  void OpenChannelToTabOnUIThread(int source_process_id, int source_routing_id,
113                                  int receiver_port_id,
114                                  int tab_id, const std::string& extension_id,
115                                  const std::string& channel_name);
116  void OnGetExtensionMessageBundle(const std::string& extension_id,
117                                   IPC::Message* reply_msg);
118  void OnGetExtensionMessageBundleOnFileThread(
119      const base::FilePath& extension_path,
120      const std::string& extension_id,
121      const std::string& default_locale,
122      IPC::Message* reply_msg);
123  void OnExtensionAddListener(const std::string& extension_id,
124                              const std::string& event_name);
125  void OnExtensionRemoveListener(const std::string& extension_id,
126                                 const std::string& event_name);
127  void OnExtensionAddLazyListener(const std::string& extension_id,
128                                  const std::string& event_name);
129  void OnExtensionRemoveLazyListener(const std::string& extension_id,
130                                     const std::string& event_name);
131  void OnExtensionAddFilteredListener(const std::string& extension_id,
132                                      const std::string& event_name,
133                                      const base::DictionaryValue& filter,
134                                      bool lazy);
135  void OnExtensionRemoveFilteredListener(const std::string& extension_id,
136                                         const std::string& event_name,
137                                         const base::DictionaryValue& filter,
138                                         bool lazy);
139  void OnExtensionCloseChannel(int port_id, const std::string& error_message);
140  void OnExtensionRequestForIOThread(
141      int routing_id,
142      const ExtensionHostMsg_Request_Params& params);
143  void OnExtensionShouldSuspendAck(const std::string& extension_id,
144                                   int sequence_id);
145  void OnExtensionSuspendAck(const std::string& extension_id);
146  void OnExtensionGenerateUniqueID(int* unique_id);
147  void OnExtensionResumeRequests(int route_id);
148  void OnAddAPIActionToExtensionActivityLog(
149      const std::string& extension_id,
150      const ExtensionHostMsg_APIActionOrEvent_Params& params);
151  void OnAddBlockedCallToExtensionActivityLog(
152      const std::string& extension_id,
153      const std::string& function_name);
154  void OnAddDOMActionToExtensionActivityLog(
155      const std::string& extension_id,
156      const ExtensionHostMsg_DOMAction_Params& params);
157  void OnAddEventToExtensionActivityLog(
158      const std::string& extension_id,
159      const ExtensionHostMsg_APIActionOrEvent_Params& params);
160  void OnAllowDatabase(int render_view_id,
161                       const GURL& origin_url,
162                       const GURL& top_origin_url,
163                       const string16& name,
164                       const string16& display_name,
165                       bool* allowed);
166  void OnAllowDOMStorage(int render_view_id,
167                         const GURL& origin_url,
168                         const GURL& top_origin_url,
169                         bool local,
170                         bool* allowed);
171  void OnAllowFileSystem(int render_view_id,
172                         const GURL& origin_url,
173                         const GURL& top_origin_url,
174                         bool* allowed);
175  void OnAllowIndexedDB(int render_view_id,
176                        const GURL& origin_url,
177                        const GURL& top_origin_url,
178                        const string16& name,
179                        bool* allowed);
180  void OnCanTriggerClipboardRead(const GURL& origin, bool* allowed);
181  void OnCanTriggerClipboardWrite(const GURL& origin, bool* allowed);
182  void OnGetCookies(const GURL& url,
183                    const GURL& first_party_for_cookies,
184                    IPC::Message* reply_msg);
185  void OnSetCookie(const IPC::Message& message,
186                   const GURL& url,
187                   const GURL& first_party_for_cookies,
188                   const std::string& cookie);
189
190  int render_process_id_;
191
192  // The Profile associated with our renderer process.  This should only be
193  // accessed on the UI thread!
194  Profile* profile_;
195  // Copied from the profile so that it can be read on the IO thread.
196  bool off_the_record_;
197  scoped_refptr<net::URLRequestContextGetter> request_context_;
198  scoped_refptr<ExtensionInfoMap> extension_info_map_;
199  // Used to look up permissions at database creation time.
200  scoped_refptr<CookieSettings> cookie_settings_;
201
202  base::WeakPtrFactory<ChromeRenderMessageFilter> weak_ptr_factory_;
203
204  DISALLOW_COPY_AND_ASSIGN(ChromeRenderMessageFilter);
205};
206
207#endif  // CHROME_BROWSER_RENDERER_HOST_CHROME_RENDER_MESSAGE_FILTER_H_
208