172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// Copyright (c) 2011 The Chromium Authors. All rights reserved.
221d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen// Use of this source code is governed by a BSD-style license that can be
321d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen// found in the LICENSE file.
421d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen
521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen// Interface for objects providing content setting rules.
621d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen
721d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen#ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PROVIDER_H_
821d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen#define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PROVIDER_H_
921d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen#pragma once
1021d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen
11ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#define NO_RESOURCE_IDENTIFIER ""
12ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
1372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#include <string>
1472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#include <vector>
1572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
1672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#include "chrome/browser/content_settings/content_settings_pattern.h"
1721d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen#include "chrome/common/content_settings.h"
1821d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen
1972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenclass GURL;
2021d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen
2172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsennamespace content_settings {
2272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
2372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenclass DefaultProviderInterface {
2472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen public:
2572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual ~DefaultProviderInterface() {}
2621d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen
2721d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  // Returns the default content setting this provider has for the given
2821d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  // |content_type|, or CONTENT_SETTING_DEFAULT if nothing be provided for this
2921d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  // type.
3021d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  virtual ContentSetting ProvideDefaultSetting(
3121d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen      ContentSettingsType content_type) const = 0;
3221d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen
3321d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  // Notifies the provider that the host content settings map would like to
3421d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  // update the default setting for the given |content_type|. The provider may
3521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  // ignore this.
3621d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  virtual void UpdateDefaultSetting(ContentSettingsType content_type,
3721d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen                                    ContentSetting setting) = 0;
3821d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen
3921d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  // Resets the state of the provider to the default.
4021d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  virtual void ResetToDefaults() = 0;
4121d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen
4221d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  // True if the default setting for the |content_type| is policy managed, i.e.,
4321d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  // there shouldn't be any UI shown to modify this setting.
4421d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  virtual bool DefaultSettingIsManaged(
4521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen      ContentSettingsType content_type) const = 0;
4621d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen};
4721d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen
4872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenclass ProviderInterface {
4972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen public:
5072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  typedef std::string ResourceIdentifier;
5172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
5272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  struct Rule {
5372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    Rule() {}
5472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    Rule(const ContentSettingsPattern& requesting_pattern,
5572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen         const ContentSettingsPattern& embedding_pattern,
5672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen         ContentSetting setting)
5772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      : requesting_url_pattern(requesting_pattern),
5872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen        embedding_url_pattern(embedding_pattern),
5972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen        content_setting(setting) {}
6072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
6172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    ContentSettingsPattern requesting_url_pattern;
6272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    ContentSettingsPattern embedding_url_pattern;
6372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    ContentSetting content_setting;
6472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  };
6572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
6672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  typedef std::vector<Rule> Rules;
6772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
6872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual ~ProviderInterface() {}
6972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
70dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // Returns true whether the content settings provider manages the
71dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // |content_type|.
72dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  virtual bool ContentSettingsTypeIsManaged(
73dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen      ContentSettingsType content_type) = 0;
74dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen
7572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Returns a single ContentSetting which applies to a given |requesting_url|,
7672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // |embedding_url| pair or CONTENT_SETTING_DEFAULT, if no rule applies. For
7772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // ContentSettingsTypes that require a resource identifier to be specified,
7872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // the |resource_identifier| must be non-empty.
7972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //
8072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // This may be called on any thread.
8172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual ContentSetting GetContentSetting(
8272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      const GURL& requesting_url,
8372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      const GURL& embedding_url,
8472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      ContentSettingsType content_type,
8572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      const ResourceIdentifier& resource_identifier) const = 0;
8672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
8772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Sets the content setting for a particular |requesting_pattern|,
8872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // |embedding_pattern|, |content_type| tuple. For ContentSettingsTypes that
8972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // require a resource identifier to be specified, the |resource_identifier|
9072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // must be non-empty.
9172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //
9272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // This should only be called on the UI thread.
9372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual void SetContentSetting(
9472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      const ContentSettingsPattern& requesting_url_pattern,
9572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      const ContentSettingsPattern& embedding_url_pattern,
9672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      ContentSettingsType content_type,
9772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      const ResourceIdentifier& resource_identifier,
9872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      ContentSetting content_setting) = 0;
9972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
10072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // For a given content type, returns all content setting rules with a
10172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // non-default setting, mapped to their actual settings.
10272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // |content_settings_rules| must be non-NULL. If this provider was created for
103ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // the incognito profile, it will only return those settings differing
10472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // from the corresponding regular provider. For ContentSettingsTypes that
10572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // require a resource identifier to be specified, the |resource_identifier|
10672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // must be non-empty.
10772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //
10872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // This may be called on any thread.
10972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual void GetAllContentSettingsRules(
11072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      ContentSettingsType content_type,
11172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      const ResourceIdentifier& resource_identifier,
11272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      Rules* content_setting_rules) const = 0;
11372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
11472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Resets all content settings for the given |content_type| to
11572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // CONTENT_SETTING_DEFAULT. For content types that require a resource
11672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // identifier all content settings for any resource identifieres of the given
11772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // |content_type| will be reset to CONTENT_SETTING_DEFAULT.
11872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //
11972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // This should only be called on the UI thread.
12072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual void ClearAllContentSettingsRules(
12172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      ContentSettingsType content_type) = 0;
12272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
12372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Resets all content settings to CONTENT_SETTINGS_DEFAULT.
12472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //
12572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // This should only be called on the UI thread.
12672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual void ResetToDefaults() = 0;
12772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen};
12872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
12972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen}  // namespace content_settings
13072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
13121d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen#endif  // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PROVIDER_H_
132