Home | History | Annotate | Download | only in renderer_host
      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 
     19 class CookieSettings;
     20 struct ExtensionHostMsg_APIActionOrEvent_Params;
     21 struct ExtensionHostMsg_DOMAction_Params;
     22 struct ExtensionHostMsg_Request_Params;
     23 struct ExtensionMsg_ExternalConnectionInfo;
     24 class ExtensionInfoMap;
     25 class GURL;
     26 
     27 namespace net {
     28 class HostResolver;
     29 class URLRequestContextGetter;
     30 }
     31 
     32 // This class filters out incoming Chrome-specific IPC messages for the renderer
     33 // process on the IPC thread.
     34 class ChromeRenderMessageFilter : public content::BrowserMessageFilter {
     35  public:
     36   ChromeRenderMessageFilter(int render_process_id,
     37                             Profile* profile,
     38                             net::URLRequestContextGetter* request_context);
     39 
     40   // Notification detail classes.
     41   class FPSDetails {
     42    public:
     43     FPSDetails(int routing_id, float fps)
     44         : routing_id_(routing_id),
     45           fps_(fps) {}
     46     int routing_id() const { return routing_id_; }
     47     float fps() const { return fps_; }
     48    private:
     49     int routing_id_;
     50     float fps_;
     51   };
     52 
     53   class V8HeapStatsDetails {
     54    public:
     55     V8HeapStatsDetails(size_t v8_memory_allocated,
     56                        size_t v8_memory_used)
     57         : v8_memory_allocated_(v8_memory_allocated),
     58           v8_memory_used_(v8_memory_used) {}
     59     size_t v8_memory_allocated() const { return v8_memory_allocated_; }
     60     size_t v8_memory_used() const { return v8_memory_used_; }
     61    private:
     62     size_t v8_memory_allocated_;
     63     size_t v8_memory_used_;
     64   };
     65 
     66   // content::BrowserMessageFilter methods:
     67   virtual bool OnMessageReceived(const IPC::Message& message,
     68                                  bool* message_was_ok) OVERRIDE;
     69   virtual void OverrideThreadForMessage(
     70       const IPC::Message& message,
     71       content::BrowserThread::ID* thread) OVERRIDE;
     72 
     73   int render_process_id() { return render_process_id_; }
     74   bool off_the_record() { return off_the_record_; }
     75   net::HostResolver* GetHostResolver();
     76 
     77  private:
     78   friend class content::BrowserThread;
     79   friend class base::DeleteHelper<ChromeRenderMessageFilter>;
     80 
     81   virtual ~ChromeRenderMessageFilter();
     82 
     83   void OnDnsPrefetch(const std::vector<std::string>& hostnames);
     84   void OnPreconnect(const GURL& url);
     85   void OnResourceTypeStats(const WebKit::WebCache::ResourceTypeStats& stats);
     86   void OnUpdatedCacheStats(const WebKit::WebCache::UsageStats& stats);
     87   void OnFPS(int routing_id, float fps);
     88   void OnV8HeapStats(int v8_memory_allocated, int v8_memory_used);
     89   void OnOpenChannelToExtension(int routing_id,
     90                                 const ExtensionMsg_ExternalConnectionInfo& info,
     91                                 const std::string& channel_name, int* port_id);
     92   void OpenChannelToExtensionOnUIThread(
     93       int source_process_id,
     94       int source_routing_id,
     95       int receiver_port_id,
     96       const ExtensionMsg_ExternalConnectionInfo& info,
     97       const std::string& channel_name);
     98   void OnOpenChannelToNativeApp(int routing_id,
     99                                 const std::string& source_extension_id,
    100                                 const std::string& native_app_name,
    101                                 int* port_id);
    102   void OpenChannelToNativeAppOnUIThread(int source_routing_id,
    103                                         int receiver_port_id,
    104                                         const std::string& source_extension_id,
    105                                         const std::string& native_app_name);
    106   void OnOpenChannelToTab(int routing_id, int tab_id,
    107                           const std::string& extension_id,
    108                           const std::string& channel_name, int* port_id);
    109   void OpenChannelToTabOnUIThread(int source_process_id, int source_routing_id,
    110                                   int receiver_port_id,
    111                                   int tab_id, const std::string& extension_id,
    112                                   const std::string& channel_name);
    113   void OnGetExtensionMessageBundle(const std::string& extension_id,
    114                                    IPC::Message* reply_msg);
    115   void OnGetExtensionMessageBundleOnFileThread(
    116       const base::FilePath& extension_path,
    117       const std::string& extension_id,
    118       const std::string& default_locale,
    119       IPC::Message* reply_msg);
    120   void OnExtensionAddListener(const std::string& extension_id,
    121                               const std::string& event_name);
    122   void OnExtensionRemoveListener(const std::string& extension_id,
    123                                  const std::string& event_name);
    124   void OnExtensionAddLazyListener(const std::string& extension_id,
    125                                   const std::string& event_name);
    126   void OnExtensionRemoveLazyListener(const std::string& extension_id,
    127                                      const std::string& event_name);
    128   void OnExtensionAddFilteredListener(const std::string& extension_id,
    129                                       const std::string& event_name,
    130                                       const base::DictionaryValue& filter,
    131                                       bool lazy);
    132   void OnExtensionRemoveFilteredListener(const std::string& extension_id,
    133                                          const std::string& event_name,
    134                                          const base::DictionaryValue& filter,
    135                                          bool lazy);
    136   void OnExtensionCloseChannel(int port_id, const std::string& error_message);
    137   void OnExtensionRequestForIOThread(
    138       int routing_id,
    139       const ExtensionHostMsg_Request_Params& params);
    140   void OnExtensionShouldSuspendAck(const std::string& extension_id,
    141                                    int sequence_id);
    142   void OnExtensionSuspendAck(const std::string& extension_id);
    143   void OnExtensionGenerateUniqueID(int* unique_id);
    144   void OnExtensionResumeRequests(int route_id);
    145   void OnAddAPIActionToExtensionActivityLog(
    146       const std::string& extension_id,
    147       const ExtensionHostMsg_APIActionOrEvent_Params& params);
    148   void OnAddBlockedCallToExtensionActivityLog(
    149       const std::string& extension_id,
    150       const std::string& function_name);
    151   void OnAddDOMActionToExtensionActivityLog(
    152       const std::string& extension_id,
    153       const ExtensionHostMsg_DOMAction_Params& params);
    154   void OnAddEventToExtensionActivityLog(
    155       const std::string& extension_id,
    156       const ExtensionHostMsg_APIActionOrEvent_Params& params);
    157   void OnAllowDatabase(int render_view_id,
    158                        const GURL& origin_url,
    159                        const GURL& top_origin_url,
    160                        const string16& name,
    161                        const string16& display_name,
    162                        bool* allowed);
    163   void OnAllowDOMStorage(int render_view_id,
    164                          const GURL& origin_url,
    165                          const GURL& top_origin_url,
    166                          bool local,
    167                          bool* allowed);
    168   void OnAllowFileSystem(int render_view_id,
    169                          const GURL& origin_url,
    170                          const GURL& top_origin_url,
    171                          bool* allowed);
    172   void OnAllowIndexedDB(int render_view_id,
    173                         const GURL& origin_url,
    174                         const GURL& top_origin_url,
    175                         const string16& name,
    176                         bool* allowed);
    177   void OnCanTriggerClipboardRead(const GURL& origin, bool* allowed);
    178   void OnCanTriggerClipboardWrite(const GURL& origin, bool* allowed);
    179   void OnGetCookies(const GURL& url,
    180                     const GURL& first_party_for_cookies,
    181                     IPC::Message* reply_msg);
    182   void OnSetCookie(const IPC::Message& message,
    183                    const GURL& url,
    184                    const GURL& first_party_for_cookies,
    185                    const std::string& cookie);
    186 
    187   int render_process_id_;
    188 
    189   // The Profile associated with our renderer process.  This should only be
    190   // accessed on the UI thread!
    191   Profile* profile_;
    192   // Copied from the profile so that it can be read on the IO thread.
    193   bool off_the_record_;
    194   scoped_refptr<net::URLRequestContextGetter> request_context_;
    195   scoped_refptr<ExtensionInfoMap> extension_info_map_;
    196   // Used to look up permissions at database creation time.
    197   scoped_refptr<CookieSettings> cookie_settings_;
    198 
    199   base::WeakPtrFactory<ChromeRenderMessageFilter> weak_ptr_factory_;
    200 
    201   DISALLOW_COPY_AND_ASSIGN(ChromeRenderMessageFilter);
    202 };
    203 
    204 #endif  // CHROME_BROWSER_RENDERER_HOST_CHROME_RENDER_MESSAGE_FILTER_H_
    205