chrome_render_message_filter.h revision 46d4c2bc3267f3f028f39e7e311b0f89aba2e4fd
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/sequenced_task_runner_helpers.h"
12#include "content/public/browser/browser_message_filter.h"
13#include "third_party/WebKit/public/web/WebCache.h"
14
15class CookieSettings;
16class GURL;
17class Profile;
18
19namespace chrome_browser_net {
20class Predictor;
21}
22
23namespace extensions {
24class InfoMap;
25}
26
27// This class filters out incoming Chrome-specific IPC messages for the renderer
28// process on the IPC thread.
29class ChromeRenderMessageFilter : public content::BrowserMessageFilter {
30 public:
31  ChromeRenderMessageFilter(int render_process_id, Profile* profile);
32
33  class V8HeapStatsDetails {
34   public:
35    V8HeapStatsDetails(size_t v8_memory_allocated,
36                       size_t v8_memory_used)
37        : v8_memory_allocated_(v8_memory_allocated),
38          v8_memory_used_(v8_memory_used) {}
39    size_t v8_memory_allocated() const { return v8_memory_allocated_; }
40    size_t v8_memory_used() const { return v8_memory_used_; }
41   private:
42    size_t v8_memory_allocated_;
43    size_t v8_memory_used_;
44  };
45
46  // content::BrowserMessageFilter methods:
47  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
48  virtual void OverrideThreadForMessage(
49      const IPC::Message& message,
50      content::BrowserThread::ID* thread) OVERRIDE;
51
52 private:
53  friend class content::BrowserThread;
54  friend class base::DeleteHelper<ChromeRenderMessageFilter>;
55
56  virtual ~ChromeRenderMessageFilter();
57
58  void OnDnsPrefetch(const std::vector<std::string>& hostnames);
59  void OnPreconnect(const GURL& url);
60  void OnResourceTypeStats(const blink::WebCache::ResourceTypeStats& stats);
61  void OnUpdatedCacheStats(const blink::WebCache::UsageStats& stats);
62  void OnFPS(int routing_id, float fps);
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                                     bool* allowed);
80  void OnRequestFileSystemAccessAsync(int render_frame_id,
81                                      int request_id,
82                                      const GURL& origin_url,
83                                      const GURL& top_origin_url);
84  void OnAllowIndexedDB(int render_frame_id,
85                        const GURL& origin_url,
86                        const GURL& top_origin_url,
87                        const base::string16& name,
88                        bool* allowed);
89#if defined(ENABLE_PLUGINS)
90  void OnIsCrashReportingEnabled(bool* enabled);
91#endif
92
93  const int render_process_id_;
94
95  // The Profile associated with our renderer process.  This should only be
96  // accessed on the UI thread!
97  Profile* profile_;
98  // The Predictor for the associated Profile. It is stored so that it can be
99  // used on the IO thread.
100  chrome_browser_net::Predictor* predictor_;
101
102  // Used to look up permissions at database creation time.
103  scoped_refptr<CookieSettings> cookie_settings_;
104
105  DISALLOW_COPY_AND_ASSIGN(ChromeRenderMessageFilter);
106};
107
108#endif  // CHROME_BROWSER_RENDERER_HOST_CHROME_RENDER_MESSAGE_FILTER_H_
109