Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / chrome / browser / content_settings / tab_specific_content_settings.h
blob1ab21f8428cce554420101b4fd45dfbff4461d67
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.
5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_TAB_SPECIFIC_CONTENT_SETTINGS_H_
6 #define CHROME_BROWSER_CONTENT_SETTINGS_TAB_SPECIFIC_CONTENT_SETTINGS_H_
8 #include <set>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h"
15 #include "chrome/browser/content_settings/local_shared_objects_container.h"
16 #include "chrome/browser/geolocation/geolocation_settings_state.h"
17 #include "chrome/common/content_settings.h"
18 #include "chrome/common/content_settings_types.h"
19 #include "chrome/common/custom_handlers/protocol_handler.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/web_contents_observer.h"
23 #include "content/public/browser/web_contents_user_data.h"
24 #include "net/cookies/canonical_cookie.h"
26 class CookiesTreeModel;
27 class Profile;
29 namespace content {
30 class RenderViewHost;
33 namespace net {
34 class CookieOptions;
37 // This class manages state about permissions, content settings, cookies and
38 // site data for a specific WebContents. It tracks which content was accessed
39 // and which content was blocked. Based on this it provides information about
40 // which types of content were accessed and blocked.
41 class TabSpecificContentSettings
42 : public content::WebContentsObserver,
43 public content::NotificationObserver,
44 public content::WebContentsUserData<TabSpecificContentSettings> {
45 public:
46 // Classes that want to be notified about site data events must implement
47 // this abstract class and add themselves as observer to the
48 // |TabSpecificContentSettings|.
49 class SiteDataObserver {
50 public:
51 explicit SiteDataObserver(
52 TabSpecificContentSettings* tab_specific_content_settings);
53 virtual ~SiteDataObserver();
55 // Called whenever site data is accessed.
56 virtual void OnSiteDataAccessed() = 0;
58 TabSpecificContentSettings* tab_specific_content_settings() {
59 return tab_specific_content_settings_;
62 // Called when the TabSpecificContentSettings is destroyed; nulls out
63 // the local reference.
64 void ContentSettingsDestroyed();
66 private:
67 TabSpecificContentSettings* tab_specific_content_settings_;
69 DISALLOW_COPY_AND_ASSIGN(SiteDataObserver);
72 virtual ~TabSpecificContentSettings();
74 // Returns the object given a render view's id.
75 static TabSpecificContentSettings* Get(int render_process_id,
76 int render_view_id);
78 // Static methods called on the UI threads.
79 // Called when cookies for the given URL were read either from within the
80 // current page or while loading it. |blocked_by_policy| should be true, if
81 // reading cookies was blocked due to the user's content settings. In that
82 // case, this function should invoke OnContentBlocked.
83 static void CookiesRead(int render_process_id,
84 int render_view_id,
85 const GURL& url,
86 const GURL& first_party_url,
87 const net::CookieList& cookie_list,
88 bool blocked_by_policy);
90 // Called when a specific cookie in the current page was changed.
91 // |blocked_by_policy| should be true, if the cookie was blocked due to the
92 // user's content settings. In that case, this function should invoke
93 // OnContentBlocked.
94 static void CookieChanged(int render_process_id,
95 int render_view_id,
96 const GURL& url,
97 const GURL& first_party_url,
98 const std::string& cookie_line,
99 const net::CookieOptions& options,
100 bool blocked_by_policy);
102 // Called when a specific Web database in the current page was accessed. If
103 // access was blocked due to the user's content settings,
104 // |blocked_by_policy| should be true, and this function should invoke
105 // OnContentBlocked.
106 static void WebDatabaseAccessed(int render_process_id,
107 int render_view_id,
108 const GURL& url,
109 const string16& name,
110 const string16& display_name,
111 bool blocked_by_policy);
113 // Called when a specific DOM storage area in the current page was
114 // accessed. If access was blocked due to the user's content settings,
115 // |blocked_by_policy| should be true, and this function should invoke
116 // OnContentBlocked.
117 static void DOMStorageAccessed(int render_process_id,
118 int render_view_id,
119 const GURL& url,
120 bool local,
121 bool blocked_by_policy);
123 // Called when a specific indexed db factory in the current page was
124 // accessed. If access was blocked due to the user's content settings,
125 // |blocked_by_policy| should be true, and this function should invoke
126 // OnContentBlocked.
127 static void IndexedDBAccessed(int render_process_id,
128 int render_view_id,
129 const GURL& url,
130 const string16& description,
131 bool blocked_by_policy);
133 // Called when a specific file system in the current page was accessed.
134 // If access was blocked due to the user's content settings,
135 // |blocked_by_policy| should be true, and this function should invoke
136 // OnContentBlocked.
137 static void FileSystemAccessed(int render_process_id,
138 int render_view_id,
139 const GURL& url,
140 bool blocked_by_policy);
142 // Resets the |content_blocked_| and |content_accessed_| arrays, except for
143 // CONTENT_SETTINGS_TYPE_COOKIES related information.
144 void ClearBlockedContentSettingsExceptForCookies();
146 // Resets all cookies related information.
147 void ClearCookieSpecificContentSettings();
149 // Clears the Geolocation settings.
150 void ClearGeolocationContentSettings();
152 // Changes the |content_blocked_| entry for popups.
153 void SetPopupsBlocked(bool blocked);
155 // Updates Geolocation settings on navigation.
156 void GeolocationDidNavigate(
157 const content::LoadCommittedDetails& details);
159 // Returns whether a particular kind of content has been blocked for this
160 // page.
161 bool IsContentBlocked(ContentSettingsType content_type) const;
163 // Returns true if content blockage was indicated to the user.
164 bool IsBlockageIndicated(ContentSettingsType content_type) const;
166 void SetBlockageHasBeenIndicated(ContentSettingsType content_type);
168 // Returns whether a particular kind of content has been accessed. Currently
169 // only tracks cookies.
170 bool IsContentAccessed(ContentSettingsType content_type) const;
172 const std::set<std::string>& BlockedResourcesForType(
173 ContentSettingsType content_type) const;
175 // Returns the GeolocationSettingsState that controls the
176 // geolocation API usage on this page.
177 const GeolocationSettingsState& geolocation_settings_state() const {
178 return geolocation_settings_state_;
181 // Call to indicate that there is a protocol handler pending user approval.
182 void set_pending_protocol_handler(const ProtocolHandler& handler) {
183 pending_protocol_handler_ = handler;
186 const ProtocolHandler& pending_protocol_handler() const {
187 return pending_protocol_handler_;
190 void ClearPendingProtocolHandler() {
191 pending_protocol_handler_ = ProtocolHandler::EmptyProtocolHandler();
195 // Sets the previous protocol handler which will be replaced by the
196 // pending protocol handler.
197 void set_previous_protocol_handler(const ProtocolHandler& handler) {
198 previous_protocol_handler_ = handler;
201 const ProtocolHandler& previous_protocol_handler() const {
202 return previous_protocol_handler_;
205 // Set whether the setting for the pending handler is DEFAULT (ignore),
206 // ALLOW, or DENY.
207 void set_pending_protocol_handler_setting(ContentSetting setting) {
208 pending_protocol_handler_setting_ = setting;
211 ContentSetting pending_protocol_handler_setting() const {
212 return pending_protocol_handler_setting_;
216 // Returns a pointer to the |LocalSharedObjectsContainer| that contains all
217 // allowed local shared objects like cookies, local storage, ... .
218 const LocalSharedObjectsContainer& allowed_local_shared_objects() const {
219 return allowed_local_shared_objects_;
222 // Returns a pointer to the |LocalSharedObjectsContainer| that contains all
223 // blocked local shared objects like cookies, local storage, ... .
224 const LocalSharedObjectsContainer& blocked_local_shared_objects() const {
225 return blocked_local_shared_objects_;
228 bool load_plugins_link_enabled() { return load_plugins_link_enabled_; }
229 void set_load_plugins_link_enabled(bool enabled) {
230 load_plugins_link_enabled_ = enabled;
233 // content::WebContentsObserver overrides.
234 virtual void RenderViewForInterstitialPageCreated(
235 content::RenderViewHost* render_view_host) OVERRIDE;
236 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
237 virtual void DidNavigateMainFrame(
238 const content::LoadCommittedDetails& details,
239 const content::FrameNavigateParams& params) OVERRIDE;
240 virtual void DidStartProvisionalLoadForFrame(
241 int64 frame_id,
242 int64 parent_frame_id,
243 bool is_main_frame,
244 const GURL& validated_url,
245 bool is_error_page,
246 content::RenderViewHost* render_view_host) OVERRIDE;
247 virtual void AppCacheAccessed(const GURL& manifest_url,
248 bool blocked_by_policy) OVERRIDE;
250 // Message handlers. Public for testing.
251 void OnContentBlocked(ContentSettingsType type,
252 const std::string& resource_identifier);
254 // These methods are invoked on the UI thread by the static functions above.
255 // Public for testing.
256 void OnCookiesRead(const GURL& url,
257 const GURL& first_party_url,
258 const net::CookieList& cookie_list,
259 bool blocked_by_policy);
260 void OnCookieChanged(const GURL& url,
261 const GURL& first_party_url,
262 const std::string& cookie_line,
263 const net::CookieOptions& options,
264 bool blocked_by_policy);
265 void OnFileSystemAccessed(const GURL& url,
266 bool blocked_by_policy);
267 void OnIndexedDBAccessed(const GURL& url,
268 const string16& description,
269 bool blocked_by_policy);
270 void OnLocalStorageAccessed(const GURL& url,
271 bool local,
272 bool blocked_by_policy);
273 void OnWebDatabaseAccessed(const GURL& url,
274 const string16& name,
275 const string16& display_name,
276 bool blocked_by_policy);
277 void OnGeolocationPermissionSet(const GURL& requesting_frame,
278 bool allowed);
280 // Adds the given |SiteDataObserver|. The |observer| is notified when a
281 // locale shared object, like for example a cookie, is accessed.
282 void AddSiteDataObserver(SiteDataObserver* observer);
284 // Removes the given |SiteDataObserver|.
285 void RemoveSiteDataObserver(SiteDataObserver* observer);
287 private:
288 explicit TabSpecificContentSettings(content::WebContents* tab);
289 friend class content::WebContentsUserData<TabSpecificContentSettings>;
291 void AddBlockedResource(ContentSettingsType content_type,
292 const std::string& resource_identifier);
294 void OnContentAccessed(ContentSettingsType type);
296 // content::NotificationObserver implementation.
297 virtual void Observe(int type,
298 const content::NotificationSource& source,
299 const content::NotificationDetails& details) OVERRIDE;
301 // Notifies all registered |SiteDataObserver|s.
302 void NotifySiteDataObservers();
304 // All currently registered |SiteDataObserver|s.
305 ObserverList<SiteDataObserver> observer_list_;
307 // Stores which content setting types actually have blocked content.
308 bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES];
310 // Stores if the blocked content was messaged to the user.
311 bool content_blockage_indicated_to_user_[CONTENT_SETTINGS_NUM_TYPES];
313 // Stores which content setting types actually were accessed.
314 bool content_accessed_[CONTENT_SETTINGS_NUM_TYPES];
316 // Stores the blocked resources for each content type.
317 // Currently only used for plugins.
318 scoped_ptr<std::set<std::string> >
319 blocked_resources_[CONTENT_SETTINGS_NUM_TYPES];
321 // The profile of the tab.
322 Profile* profile_;
324 // Stores the blocked/allowed cookies.
325 LocalSharedObjectsContainer allowed_local_shared_objects_;
326 LocalSharedObjectsContainer blocked_local_shared_objects_;
328 // Manages information about Geolocation API usage in this page.
329 GeolocationSettingsState geolocation_settings_state_;
331 // The pending protocol handler, if any. This can be set if
332 // registerProtocolHandler was invoked without user gesture.
333 // The |IsEmpty| method will be true if no protocol handler is
334 // pending registration.
335 ProtocolHandler pending_protocol_handler_;
337 // The previous protocol handler to be replaced by
338 // the pending_protocol_handler_, if there is one. Empty if
339 // there is no handler which would be replaced.
340 ProtocolHandler previous_protocol_handler_;
342 // The setting on the pending protocol handler registration. Persisted in case
343 // the user opens the bubble and makes changes multiple times.
344 ContentSetting pending_protocol_handler_setting_;
346 // Stores whether the user can load blocked plugins on this page.
347 bool load_plugins_link_enabled_;
349 content::NotificationRegistrar registrar_;
351 DISALLOW_COPY_AND_ASSIGN(TabSpecificContentSettings);
354 #endif // CHROME_BROWSER_CONTENT_SETTINGS_TAB_SPECIFIC_CONTENT_SETTINGS_H_