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