chrome_render_message_filter.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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 OnResourceTypeStats(const WebKit::WebCache::ResourceTypeStats& stats); 100 void OnUpdatedCacheStats(const WebKit::WebCache::UsageStats& stats); 101 void OnFPS(int routing_id, float fps); 102 void OnV8HeapStats(int v8_memory_allocated, int v8_memory_used); 103 void OnOpenChannelToExtension(int routing_id, 104 const ExtensionMsg_ExternalConnectionInfo& info, 105 const std::string& channel_name, int* port_id); 106 void OpenChannelToExtensionOnUIThread( 107 int source_process_id, 108 int source_routing_id, 109 int receiver_port_id, 110 const ExtensionMsg_ExternalConnectionInfo& info, 111 const std::string& channel_name); 112 void OnOpenChannelToNativeApp(int routing_id, 113 const std::string& source_extension_id, 114 const std::string& native_app_name, 115 int* port_id); 116 void OpenChannelToNativeAppOnUIThread(int source_routing_id, 117 int receiver_port_id, 118 const std::string& source_extension_id, 119 const std::string& native_app_name); 120 void OnOpenChannelToTab(int routing_id, int tab_id, 121 const std::string& extension_id, 122 const std::string& channel_name, int* port_id); 123 void OpenChannelToTabOnUIThread(int source_process_id, int source_routing_id, 124 int receiver_port_id, 125 int tab_id, const std::string& extension_id, 126 const std::string& channel_name); 127 void OnGetExtensionMessageBundle(const std::string& extension_id, 128 IPC::Message* reply_msg); 129 void OnGetExtensionMessageBundleOnFileThread( 130 const base::FilePath& extension_path, 131 const std::string& extension_id, 132 const std::string& default_locale, 133 IPC::Message* reply_msg); 134 void OnExtensionAddListener(const std::string& extension_id, 135 const std::string& event_name); 136 void OnExtensionRemoveListener(const std::string& extension_id, 137 const std::string& event_name); 138 void OnExtensionAddLazyListener(const std::string& extension_id, 139 const std::string& event_name); 140 void OnExtensionRemoveLazyListener(const std::string& extension_id, 141 const std::string& event_name); 142 void OnExtensionAddFilteredListener(const std::string& extension_id, 143 const std::string& event_name, 144 const base::DictionaryValue& filter, 145 bool lazy); 146 void OnExtensionRemoveFilteredListener(const std::string& extension_id, 147 const std::string& event_name, 148 const base::DictionaryValue& filter, 149 bool lazy); 150 void OnExtensionCloseChannel(int port_id, const std::string& error_message); 151 void OnExtensionRequestForIOThread( 152 int routing_id, 153 const ExtensionHostMsg_Request_Params& params); 154 void OnExtensionShouldSuspendAck(const std::string& extension_id, 155 int sequence_id); 156 void OnExtensionSuspendAck(const std::string& extension_id); 157 void OnExtensionGenerateUniqueID(int* unique_id); 158 void OnExtensionResumeRequests(int route_id); 159 void OnAddAPIActionToExtensionActivityLog( 160 const std::string& extension_id, 161 const ExtensionHostMsg_APIActionOrEvent_Params& params); 162 void OnAddDOMActionToExtensionActivityLog( 163 const std::string& extension_id, 164 const ExtensionHostMsg_DOMAction_Params& params); 165 void OnAddEventToExtensionActivityLog( 166 const std::string& extension_id, 167 const ExtensionHostMsg_APIActionOrEvent_Params& params); 168 void OnAllowDatabase(int render_view_id, 169 const GURL& origin_url, 170 const GURL& top_origin_url, 171 const string16& name, 172 const string16& display_name, 173 bool* allowed); 174 void OnAllowDOMStorage(int render_view_id, 175 const GURL& origin_url, 176 const GURL& top_origin_url, 177 bool local, 178 bool* allowed); 179 void OnAllowFileSystem(int render_view_id, 180 const GURL& origin_url, 181 const GURL& top_origin_url, 182 bool* allowed); 183 void OnAllowIndexedDB(int render_view_id, 184 const GURL& origin_url, 185 const GURL& top_origin_url, 186 const string16& name, 187 bool* allowed); 188 void OnCanTriggerClipboardRead(const GURL& origin, bool* allowed); 189 void OnCanTriggerClipboardWrite(const GURL& origin, bool* allowed); 190 void OnGetCookies(const GURL& url, 191 const GURL& first_party_for_cookies, 192 IPC::Message* reply_msg); 193 void OnSetCookie(const IPC::Message& message, 194 const GURL& url, 195 const GURL& first_party_for_cookies, 196 const std::string& cookie); 197 198 int render_process_id_; 199 200 // The Profile associated with our renderer process. This should only be 201 // accessed on the UI thread! 202 Profile* profile_; 203 // Copied from the profile so that it can be read on the IO thread. 204 bool off_the_record_; 205 scoped_refptr<net::URLRequestContextGetter> request_context_; 206 scoped_refptr<ExtensionInfoMap> extension_info_map_; 207 // Used to look up permissions at database creation time. 208 scoped_refptr<CookieSettings> cookie_settings_; 209 210 base::WeakPtrFactory<ChromeRenderMessageFilter> weak_ptr_factory_; 211 212 DISALLOW_COPY_AND_ASSIGN(ChromeRenderMessageFilter); 213}; 214 215#endif // CHROME_BROWSER_RENDERER_HOST_CHROME_RENDER_MESSAGE_FILTER_H_ 216