chrome_render_message_filter.h revision cedac228d2dd51db4b79ea1e72c7f249408ee061
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/sequenced_task_runner_helpers.h" 13#include "chrome/browser/profiles/profile.h" 14#include "chrome/common/content_settings.h" 15#include "content/public/browser/browser_message_filter.h" 16#include "third_party/WebKit/public/web/WebCache.h" 17 18class CookieSettings; 19struct ExtensionHostMsg_APIActionOrEvent_Params; 20struct ExtensionHostMsg_DOMAction_Params; 21struct ExtensionMsg_ExternalConnectionInfo; 22class GURL; 23 24namespace extensions { 25class InfoMap; 26} 27 28namespace net { 29class HostResolver; 30class URLRequestContextGetter; 31} 32 33// This class filters out incoming Chrome-specific IPC messages for the renderer 34// process on the IPC thread. 35class ChromeRenderMessageFilter : public content::BrowserMessageFilter { 36 public: 37 ChromeRenderMessageFilter(int render_process_id, 38 Profile* profile, 39 net::URLRequestContextGetter* request_context); 40 41 class V8HeapStatsDetails { 42 public: 43 V8HeapStatsDetails(size_t v8_memory_allocated, 44 size_t v8_memory_used) 45 : v8_memory_allocated_(v8_memory_allocated), 46 v8_memory_used_(v8_memory_used) {} 47 size_t v8_memory_allocated() const { return v8_memory_allocated_; } 48 size_t v8_memory_used() const { return v8_memory_used_; } 49 private: 50 size_t v8_memory_allocated_; 51 size_t v8_memory_used_; 52 }; 53 54 // content::BrowserMessageFilter methods: 55 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 56 virtual void OverrideThreadForMessage( 57 const IPC::Message& message, 58 content::BrowserThread::ID* thread) OVERRIDE; 59 60 int render_process_id() { return render_process_id_; } 61 bool off_the_record() { return off_the_record_; } 62 net::HostResolver* GetHostResolver(); 63 64 private: 65 friend class content::BrowserThread; 66 friend class base::DeleteHelper<ChromeRenderMessageFilter>; 67 68 virtual ~ChromeRenderMessageFilter(); 69 70 void OnDnsPrefetch(const std::vector<std::string>& hostnames); 71 void OnPreconnect(const GURL& url); 72 void OnResourceTypeStats(const blink::WebCache::ResourceTypeStats& stats); 73 void OnUpdatedCacheStats(const blink::WebCache::UsageStats& stats); 74 void OnFPS(int routing_id, float fps); 75 void OnV8HeapStats(int v8_memory_allocated, int v8_memory_used); 76 77#if defined(ENABLE_EXTENSIONS) 78 // TODO(jamescook): Move these functions into the extensions module. Ideally 79 // this would be in extensions::ExtensionMessageFilter but that will require 80 // resolving the MessageService and ActivityLog dependencies on src/chrome. 81 // http://crbug.com/339637 82 void OnOpenChannelToExtension(int routing_id, 83 const ExtensionMsg_ExternalConnectionInfo& info, 84 const std::string& channel_name, 85 bool include_tls_channel_id, 86 int* port_id); 87 void OpenChannelToExtensionOnUIThread( 88 int source_process_id, 89 int source_routing_id, 90 int receiver_port_id, 91 const ExtensionMsg_ExternalConnectionInfo& info, 92 const std::string& channel_name, 93 bool include_tls_channel_id); 94 void OnOpenChannelToNativeApp(int routing_id, 95 const std::string& source_extension_id, 96 const std::string& native_app_name, 97 int* port_id); 98 void OpenChannelToNativeAppOnUIThread(int source_routing_id, 99 int receiver_port_id, 100 const std::string& source_extension_id, 101 const std::string& native_app_name); 102 void OnOpenChannelToTab(int routing_id, int tab_id, 103 const std::string& extension_id, 104 const std::string& channel_name, int* port_id); 105 void OpenChannelToTabOnUIThread(int source_process_id, int source_routing_id, 106 int receiver_port_id, 107 int tab_id, const std::string& extension_id, 108 const std::string& channel_name); 109 void OnGetExtensionMessageBundle(const std::string& extension_id, 110 IPC::Message* reply_msg); 111 void OnGetExtensionMessageBundleOnFileThread( 112 const base::FilePath& extension_path, 113 const std::string& extension_id, 114 const std::string& default_locale, 115 IPC::Message* reply_msg); 116 void OnExtensionCloseChannel(int port_id, const std::string& error_message); 117 void OnAddAPIActionToExtensionActivityLog( 118 const std::string& extension_id, 119 const ExtensionHostMsg_APIActionOrEvent_Params& params); 120 void OnAddBlockedCallToExtensionActivityLog( 121 const std::string& extension_id, 122 const std::string& function_name); 123 void OnAddDOMActionToExtensionActivityLog( 124 const std::string& extension_id, 125 const ExtensionHostMsg_DOMAction_Params& params); 126 void OnAddEventToExtensionActivityLog( 127 const std::string& extension_id, 128 const ExtensionHostMsg_APIActionOrEvent_Params& params); 129#endif // defined(ENABLE_EXTENSIONS) 130 void OnAllowDatabase(int render_frame_id, 131 const GURL& origin_url, 132 const GURL& top_origin_url, 133 const base::string16& name, 134 const base::string16& display_name, 135 bool* allowed); 136 void OnAllowDOMStorage(int render_frame_id, 137 const GURL& origin_url, 138 const GURL& top_origin_url, 139 bool local, 140 bool* allowed); 141 void OnRequestFileSystemAccessSync(int render_frame_id, 142 const GURL& origin_url, 143 const GURL& top_origin_url, 144 bool* allowed); 145 void OnRequestFileSystemAccessAsync(int render_frame_id, 146 int request_id, 147 const GURL& origin_url, 148 const GURL& top_origin_url); 149 void OnAllowIndexedDB(int render_frame_id, 150 const GURL& origin_url, 151 const GURL& top_origin_url, 152 const base::string16& name, 153 bool* allowed); 154#if defined(ENABLE_EXTENSIONS) 155 void OnCanTriggerClipboardRead(const GURL& origin, bool* allowed); 156 void OnCanTriggerClipboardWrite(const GURL& origin, bool* allowed); 157#endif 158#if defined(ENABLE_PLUGINS) 159 void OnIsCrashReportingEnabled(bool* enabled); 160#endif 161 162 const int render_process_id_; 163 164 // The Profile associated with our renderer process. This should only be 165 // accessed on the UI thread! 166 Profile* profile_; 167 // Copied from the profile so that it can be read on the IO thread. 168 const bool off_the_record_; 169 // The Predictor for the associated Profile. It is stored so that it can be 170 // used on the IO thread. 171 chrome_browser_net::Predictor* predictor_; 172 scoped_refptr<net::URLRequestContextGetter> request_context_; 173 174#if defined(ENABLE_EXTENSIONS) 175 scoped_refptr<extensions::InfoMap> extension_info_map_; 176#endif 177 178 // Used to look up permissions at database creation time. 179 scoped_refptr<CookieSettings> cookie_settings_; 180 181 DISALLOW_COPY_AND_ASSIGN(ChromeRenderMessageFilter); 182}; 183 184#endif // CHROME_BROWSER_RENDERER_HOST_CHROME_RENDER_MESSAGE_FILTER_H_ 185