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