chrome_render_message_filter.h revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
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 OnV8HeapStats(int v8_memory_allocated, int v8_memory_used);
63
64  void OnAllowDatabase(int render_frame_id,
65                       const GURL& origin_url,
66                       const GURL& top_origin_url,
67                       const base::string16& name,
68                       const base::string16& display_name,
69                       bool* allowed);
70  void OnAllowDOMStorage(int render_frame_id,
71                         const GURL& origin_url,
72                         const GURL& top_origin_url,
73                         bool local,
74                         bool* allowed);
75  void OnRequestFileSystemAccessSync(int render_frame_id,
76                                     const GURL& origin_url,
77                                     const GURL& top_origin_url,
78                                     IPC::Message* message);
79  void OnRequestFileSystemAccessAsync(int render_frame_id,
80                                      int request_id,
81                                      const GURL& origin_url,
82                                      const GURL& top_origin_url);
83  void OnAllowIndexedDB(int render_frame_id,
84                        const GURL& origin_url,
85                        const GURL& top_origin_url,
86                        const base::string16& name,
87                        bool* allowed);
88#if defined(ENABLE_PLUGINS)
89  void OnIsCrashReportingEnabled(bool* enabled);
90#endif
91
92  const int render_process_id_;
93
94  // The Profile associated with our renderer process.  This should only be
95  // accessed on the UI thread!
96  Profile* profile_;
97  // The Predictor for the associated Profile. It is stored so that it can be
98  // used on the IO thread.
99  chrome_browser_net::Predictor* predictor_;
100
101  // Used to look up permissions at database creation time.
102  scoped_refptr<CookieSettings> cookie_settings_;
103
104  DISALLOW_COPY_AND_ASSIGN(ChromeRenderMessageFilter);
105};
106
107#endif  // CHROME_BROWSER_RENDERER_HOST_CHROME_RENDER_MESSAGE_FILTER_H_
108