• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2010 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_TAB_CONTENTS_TAB_SPECIFIC_CONTENT_SETTINGS_H_
6 #define CHROME_BROWSER_TAB_CONTENTS_TAB_SPECIFIC_CONTENT_SETTINGS_H_
7 #pragma once
8 
9 #include "base/basictypes.h"
10 #include "chrome/browser/geolocation/geolocation_settings_state.h"
11 #include "chrome/common/content_settings.h"
12 #include "chrome/common/content_settings_types.h"
13 #include "content/browser/renderer_host/render_view_host_delegate.h"
14 #include "content/browser/tab_contents/navigation_controller.h"
15 
16 class CannedBrowsingDataAppCacheHelper;
17 class CannedBrowsingDataDatabaseHelper;
18 class CannedBrowsingDataIndexedDBHelper;
19 class CannedBrowsingDataLocalStorageHelper;
20 class CookiesTreeModel;
21 class Profile;
22 
23 namespace net {
24 class CookieMonster;
25 }
26 
27 class TabSpecificContentSettings
28     : public RenderViewHostDelegate::ContentSettings {
29  public:
30   class Delegate {
31    public:
32     // Invoked when content settings for resources in the tab contents
33     // associated with this TabSpecificContentSettings object were accessed.
34     // |content_was_blocked| is true, if a content settings type was blocked
35     // (as opposed to just accessed). Currently, this parameter is checked in
36     // unit tests only.
37     virtual void OnContentSettingsAccessed(bool content_was_blocked) = 0;
38 
~Delegate()39     virtual ~Delegate() {}
40   };
41 
42   TabSpecificContentSettings(Delegate* delegate, Profile* profile);
43 
~TabSpecificContentSettings()44   virtual ~TabSpecificContentSettings() {}
45 
46   // Resets the |content_blocked_| and |content_accessed_| arrays, except for
47   // CONTENT_SETTINGS_TYPE_COOKIES related information.
48   void ClearBlockedContentSettingsExceptForCookies();
49 
50   // Resets all cookies related information.
51   void ClearCookieSpecificContentSettings();
52 
53   // Clears the Geolocation settings.
54   void ClearGeolocationContentSettings();
55 
56   // Changes the |content_blocked_| entry for popups.
57   void SetPopupsBlocked(bool blocked);
58 
59   // Updates Geolocation settings on navigation.
60   void GeolocationDidNavigate(
61       const NavigationController::LoadCommittedDetails& details);
62 
63   // Returns whether a particular kind of content has been blocked for this
64   // page.
65   bool IsContentBlocked(ContentSettingsType content_type) const;
66 
67   // Returns true if content blockage was indicated to the user.
68   bool IsBlockageIndicated(ContentSettingsType content_type) const;
69 
70   void SetBlockageHasBeenIndicated(ContentSettingsType content_type);
71 
72   // Returns whether a particular kind of content has been accessed. Currently
73   // only tracks cookies.
74   bool IsContentAccessed(ContentSettingsType content_type) const;
75 
76   const std::set<std::string>& BlockedResourcesForType(
77       ContentSettingsType content_type) const;
78 
79   // Returns the GeolocationSettingsState that controls the
80   // geolocation API usage on this page.
geolocation_settings_state()81   const GeolocationSettingsState& geolocation_settings_state() const {
82     return geolocation_settings_state_;
83   }
84 
85   // Returns a CookiesTreeModel object for the recoreded allowed cookies.
86   CookiesTreeModel* GetAllowedCookiesTreeModel();
87 
88   // Returns a CookiesTreeModel object for the recoreded blocked cookies.
89   CookiesTreeModel* GetBlockedCookiesTreeModel();
90 
load_plugins_link_enabled()91   bool load_plugins_link_enabled() { return load_plugins_link_enabled_; }
set_load_plugins_link_enabled(bool enabled)92   void set_load_plugins_link_enabled(bool enabled) {
93     load_plugins_link_enabled_ = enabled;
94   }
95 
96   // RenderViewHostDelegate::ContentSettings implementation.
97   virtual void OnContentBlocked(ContentSettingsType type,
98                                 const std::string& resource_identifier);
99   virtual void OnCookiesRead(const GURL& url,
100                              const net::CookieList& cookie_list,
101                              bool blocked_by_policy);
102   virtual void OnCookieChanged(const GURL& url,
103                                const std::string& cookie_line,
104                                const net::CookieOptions& options,
105                                bool blocked_by_policy);
106   virtual void OnIndexedDBAccessed(const GURL& url,
107                                    const string16& description,
108                                    bool blocked_by_policy);
109   virtual void OnLocalStorageAccessed(const GURL& url,
110                                       DOMStorageType storage_type,
111                                       bool blocked_by_policy);
112   virtual void OnWebDatabaseAccessed(const GURL& url,
113                                      const string16& name,
114                                      const string16& display_name,
115                                      unsigned long estimated_size,
116                                      bool blocked_by_policy);
117   virtual void OnAppCacheAccessed(const GURL& manifest_url,
118                                   bool blocked_by_policy);
119   virtual void OnGeolocationPermissionSet(const GURL& requesting_frame,
120                                           bool allowed);
121 
122  private:
123   class LocalSharedObjectsContainer {
124    public:
125     explicit LocalSharedObjectsContainer(Profile* profile);
126     ~LocalSharedObjectsContainer();
127 
128     // Empties the container.
129     void Reset();
130 
cookies()131     net::CookieMonster* cookies() const { return cookies_; }
appcaches()132     CannedBrowsingDataAppCacheHelper* appcaches() const {
133       return appcaches_;
134     }
databases()135     CannedBrowsingDataDatabaseHelper* databases() const {
136       return databases_;
137     }
indexed_dbs()138     CannedBrowsingDataIndexedDBHelper* indexed_dbs() const {
139       return indexed_dbs_;
140     }
local_storages()141     CannedBrowsingDataLocalStorageHelper* local_storages() const {
142       return local_storages_;
143     }
session_storages()144     CannedBrowsingDataLocalStorageHelper* session_storages() const {
145       return session_storages_;
146     }
147 
148     CookiesTreeModel* GetCookiesTreeModel();
149 
150     bool empty() const;
151 
152    private:
153     DISALLOW_COPY_AND_ASSIGN(LocalSharedObjectsContainer);
154 
155     scoped_refptr<net::CookieMonster> cookies_;
156     scoped_refptr<CannedBrowsingDataAppCacheHelper> appcaches_;
157     scoped_refptr<CannedBrowsingDataDatabaseHelper> databases_;
158     scoped_refptr<CannedBrowsingDataIndexedDBHelper> indexed_dbs_;
159     scoped_refptr<CannedBrowsingDataLocalStorageHelper> local_storages_;
160     scoped_refptr<CannedBrowsingDataLocalStorageHelper> session_storages_;
161   };
162 
163   void AddBlockedResource(ContentSettingsType content_type,
164                           const std::string& resource_identifier);
165 
166   void OnContentAccessed(ContentSettingsType type);
167 
168   // Stores which content setting types actually have blocked content.
169   bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES];
170 
171   // Stores if the blocked content was messaged to the user.
172   bool content_blockage_indicated_to_user_[CONTENT_SETTINGS_NUM_TYPES];
173 
174   // Stores which content setting types actually were accessed.
175   bool content_accessed_[CONTENT_SETTINGS_NUM_TYPES];
176 
177   // Stores the blocked resources for each content type.
178   // Currently only used for plugins.
179   scoped_ptr<std::set<std::string> >
180       blocked_resources_[CONTENT_SETTINGS_NUM_TYPES];
181 
182   // Stores the blocked/allowed cookies.
183   LocalSharedObjectsContainer allowed_local_shared_objects_;
184   LocalSharedObjectsContainer blocked_local_shared_objects_;
185 
186   // Manages information about Geolocation API usage in this page.
187   GeolocationSettingsState geolocation_settings_state_;
188 
189   // Stores whether the user can load blocked plugins on this page.
190   bool load_plugins_link_enabled_;
191 
192   Delegate* delegate_;
193 
194   DISALLOW_COPY_AND_ASSIGN(TabSpecificContentSettings);
195 };
196 
197 #endif  // CHROME_BROWSER_TAB_CONTENTS_TAB_SPECIFIC_CONTENT_SETTINGS_H_
198