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/callback.h" 12#include "base/sequenced_task_runner_helpers.h" 13#include "content/public/browser/browser_message_filter.h" 14#include "third_party/WebKit/public/web/WebCache.h" 15 16class CookieSettings; 17class GURL; 18class Profile; 19 20namespace chrome_browser_net { 21class Predictor; 22} 23 24namespace extensions { 25class InfoMap; 26} 27 28// This class filters out incoming Chrome-specific IPC messages for the renderer 29// process on the IPC thread. 30class ChromeRenderMessageFilter : public content::BrowserMessageFilter { 31 public: 32 ChromeRenderMessageFilter(int render_process_id, Profile* profile); 33 34 class V8HeapStatsDetails { 35 public: 36 V8HeapStatsDetails(size_t v8_memory_allocated, 37 size_t v8_memory_used) 38 : v8_memory_allocated_(v8_memory_allocated), 39 v8_memory_used_(v8_memory_used) {} 40 size_t v8_memory_allocated() const { return v8_memory_allocated_; } 41 size_t v8_memory_used() const { return v8_memory_used_; } 42 private: 43 size_t v8_memory_allocated_; 44 size_t v8_memory_used_; 45 }; 46 47 // content::BrowserMessageFilter methods: 48 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 49 virtual void OverrideThreadForMessage( 50 const IPC::Message& message, 51 content::BrowserThread::ID* thread) OVERRIDE; 52 53 private: 54 friend class content::BrowserThread; 55 friend class base::DeleteHelper<ChromeRenderMessageFilter>; 56 57 virtual ~ChromeRenderMessageFilter(); 58 59 void OnDnsPrefetch(const std::vector<std::string>& hostnames); 60 void OnPreconnect(const GURL& url); 61 void OnResourceTypeStats(const blink::WebCache::ResourceTypeStats& stats); 62 void OnUpdatedCacheStats(const blink::WebCache::UsageStats& stats); 63 void OnV8HeapStats(int v8_memory_allocated, int v8_memory_used); 64 65 void OnAllowDatabase(int render_frame_id, 66 const GURL& origin_url, 67 const GURL& top_origin_url, 68 const base::string16& name, 69 const base::string16& display_name, 70 bool* allowed); 71 void OnAllowDOMStorage(int render_frame_id, 72 const GURL& origin_url, 73 const GURL& top_origin_url, 74 bool local, 75 bool* allowed); 76 void OnRequestFileSystemAccessSync(int render_frame_id, 77 const GURL& origin_url, 78 const GURL& top_origin_url, 79 IPC::Message* message); 80#if defined(ENABLE_EXTENSIONS) 81 static void FileSystemAccessedSyncOnUIThread( 82 int render_process_id, 83 int render_frame_id, 84 const GURL& url, 85 bool blocked_by_policy, 86 IPC::Message* reply_msg); 87#endif 88 void OnRequestFileSystemAccessAsync(int render_frame_id, 89 int request_id, 90 const GURL& origin_url, 91 const GURL& top_origin_url); 92 void OnRequestFileSystemAccessSyncResponse(IPC::Message* reply_msg, 93 bool allowed); 94 void OnRequestFileSystemAccessAsyncResponse(int render_frame_id, 95 int request_id, 96 bool allowed); 97 void OnRequestFileSystemAccess(int render_frame_id, 98 const GURL& origin_url, 99 const GURL& top_origin_url, 100 base::Callback<void(bool)> callback); 101#if defined(ENABLE_EXTENSIONS) 102 static void FileSystemAccessedOnUIThread(int render_process_id, 103 int render_frame_id, 104 const GURL& url, 105 bool allowed, 106 base::Callback<void(bool)> callback); 107 static void FileSystemAccessedResponse(int render_process_id, 108 int render_frame_id, 109 const GURL& url, 110 base::Callback<void(bool)> callback, 111 bool allowed); 112#endif 113 void OnAllowIndexedDB(int render_frame_id, 114 const GURL& origin_url, 115 const GURL& top_origin_url, 116 const base::string16& name, 117 bool* allowed); 118#if defined(ENABLE_PLUGINS) 119 void OnIsCrashReportingEnabled(bool* enabled); 120#endif 121 122 const int render_process_id_; 123 124 // The Profile associated with our renderer process. This should only be 125 // accessed on the UI thread! 126 Profile* profile_; 127 // The Predictor for the associated Profile. It is stored so that it can be 128 // used on the IO thread. 129 chrome_browser_net::Predictor* predictor_; 130 131 // Used to look up permissions at database creation time. 132 scoped_refptr<CookieSettings> cookie_settings_; 133 134 DISALLOW_COPY_AND_ASSIGN(ChromeRenderMessageFilter); 135}; 136 137#endif // CHROME_BROWSER_RENDERER_HOST_CHROME_RENDER_MESSAGE_FILTER_H_ 138