chrome_render_message_filter.h revision effb81e5f8246d0db0270817048dc992db66e9fb
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 93 // TODO(jamescook): Move these functions into the extensions module. Ideally 94 // this would be in extensions::ExtensionMessageFilter but that will require 95 // resolving the MessageService and ActivityLog dependencies on src/chrome. 96 // http://crbug.com/339637 97 void OnOpenChannelToExtension(int routing_id, 98 const ExtensionMsg_ExternalConnectionInfo& info, 99 const std::string& channel_name, 100 bool include_tls_channel_id, 101 int* port_id); 102 void OpenChannelToExtensionOnUIThread( 103 int source_process_id, 104 int source_routing_id, 105 int receiver_port_id, 106 const ExtensionMsg_ExternalConnectionInfo& info, 107 const std::string& channel_name, 108 bool include_tls_channel_id); 109 void OnOpenChannelToNativeApp(int routing_id, 110 const std::string& source_extension_id, 111 const std::string& native_app_name, 112 int* port_id); 113 void OpenChannelToNativeAppOnUIThread(int source_routing_id, 114 int receiver_port_id, 115 const std::string& source_extension_id, 116 const std::string& native_app_name); 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 base::FilePath& extension_path, 128 const std::string& extension_id, 129 const std::string& default_locale, 130 IPC::Message* reply_msg); 131 void OnExtensionCloseChannel(int port_id, const std::string& error_message); 132 void OnExtensionRequestForIOThread( 133 int routing_id, 134 const ExtensionHostMsg_Request_Params& params); 135 void OnAddAPIActionToExtensionActivityLog( 136 const std::string& extension_id, 137 const ExtensionHostMsg_APIActionOrEvent_Params& params); 138 void OnAddBlockedCallToExtensionActivityLog( 139 const std::string& extension_id, 140 const std::string& function_name); 141 void OnAddDOMActionToExtensionActivityLog( 142 const std::string& extension_id, 143 const ExtensionHostMsg_DOMAction_Params& params); 144 void OnAddEventToExtensionActivityLog( 145 const std::string& extension_id, 146 const ExtensionHostMsg_APIActionOrEvent_Params& params); 147 void OnAllowDatabase(int render_frame_id, 148 const GURL& origin_url, 149 const GURL& top_origin_url, 150 const base::string16& name, 151 const base::string16& display_name, 152 bool* allowed); 153 void OnAllowDOMStorage(int render_frame_id, 154 const GURL& origin_url, 155 const GURL& top_origin_url, 156 bool local, 157 bool* allowed); 158 void OnAllowFileSystem(int render_frame_id, 159 const GURL& origin_url, 160 const GURL& top_origin_url, 161 bool* allowed); 162 void OnAllowIndexedDB(int render_frame_id, 163 const GURL& origin_url, 164 const GURL& top_origin_url, 165 const base::string16& name, 166 bool* allowed); 167 void OnCanTriggerClipboardRead(const GURL& origin, bool* allowed); 168 void OnCanTriggerClipboardWrite(const GURL& origin, bool* allowed); 169 void OnIsCrashReportingEnabled(bool* enabled); 170 171 int render_process_id_; 172 173 // The Profile associated with our renderer process. This should only be 174 // accessed on the UI thread! 175 Profile* profile_; 176 // Copied from the profile so that it can be read on the IO thread. 177 bool off_the_record_; 178 // The Predictor for the associated Profile. It is stored so that it can be 179 // used on the IO thread. 180 chrome_browser_net::Predictor* predictor_; 181 scoped_refptr<net::URLRequestContextGetter> request_context_; 182 scoped_refptr<extensions::InfoMap> extension_info_map_; 183 // Used to look up permissions at database creation time. 184 scoped_refptr<CookieSettings> cookie_settings_; 185 186 base::WeakPtrFactory<ChromeRenderMessageFilter> weak_ptr_factory_; 187 188 DISALLOW_COPY_AND_ASSIGN(ChromeRenderMessageFilter); 189}; 190 191#endif // CHROME_BROWSER_RENDERER_HOST_CHROME_RENDER_MESSAGE_FILTER_H_ 192