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