Home | History | Annotate | Download | only in browsing_data
      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 // Defines the Chrome Extensions BrowsingData API functions, which entail
      6 // clearing browsing data, and clearing the browser's cache (which, let's be
      7 // honest, are the same thing), as specified in the extension API JSON.
      8 
      9 #ifndef CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_
     10 #define CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_
     11 
     12 #include <string>
     13 
     14 #include "chrome/browser/browsing_data/browsing_data_remover.h"
     15 #include "chrome/browser/extensions/chrome_extension_function.h"
     16 
     17 class PluginPrefs;
     18 
     19 namespace extension_browsing_data_api_constants {
     20 
     21 // Parameter name keys.
     22 extern const char kDataRemovalPermittedKey[];
     23 extern const char kDataToRemoveKey[];
     24 extern const char kOptionsKey[];
     25 
     26 // Type keys.
     27 extern const char kAppCacheKey[];
     28 extern const char kCacheKey[];
     29 extern const char kCookiesKey[];
     30 extern const char kDownloadsKey[];
     31 extern const char kFileSystemsKey[];
     32 extern const char kFormDataKey[];
     33 extern const char kHistoryKey[];
     34 extern const char kIndexedDBKey[];
     35 extern const char kPluginDataKey[];
     36 extern const char kLocalStorageKey[];
     37 extern const char kPasswordsKey[];
     38 extern const char kServiceWorkersKey[];
     39 extern const char kWebSQLKey[];
     40 
     41 // Option keys.
     42 extern const char kExtensionsKey[];
     43 extern const char kOriginTypesKey[];
     44 extern const char kProtectedWebKey[];
     45 extern const char kSinceKey[];
     46 extern const char kUnprotectedWebKey[];
     47 
     48 // Errors!
     49 extern const char kBadDataTypeDetails[];
     50 extern const char kDeleteProhibitedError[];
     51 extern const char kOneAtATimeError[];
     52 
     53 }  // namespace extension_browsing_data_api_constants
     54 
     55 class BrowsingDataSettingsFunction : public ChromeSyncExtensionFunction {
     56  public:
     57   DECLARE_EXTENSION_FUNCTION("browsingData.settings", BROWSINGDATA_SETTINGS)
     58 
     59   // ExtensionFunction:
     60   virtual bool RunSync() OVERRIDE;
     61 
     62  protected:
     63   virtual ~BrowsingDataSettingsFunction() {}
     64 
     65  private:
     66   // Sets a boolean value in the |selected_dict| with the |data_type| as a key,
     67   // indicating whether the data type is both selected and permitted to be
     68   // removed; and a value in the |permitted_dict| with the |data_type| as a
     69   // key, indicating only whether the data type is permitted to be removed.
     70   void SetDetails(base::DictionaryValue* selected_dict,
     71                   base::DictionaryValue* permitted_dict,
     72                   const char* data_type,
     73                   bool is_selected);
     74 };
     75 
     76 // This serves as a base class from which the browsing data API removal
     77 // functions will inherit. Each needs to be an observer of BrowsingDataRemover
     78 // events, and each will handle those events in the same way (by calling the
     79 // passed-in callback function).
     80 //
     81 // Each child class must implement GetRemovalMask(), which returns the bitmask
     82 // of data types to remove.
     83 class BrowsingDataRemoverFunction : public ChromeAsyncExtensionFunction,
     84                                     public BrowsingDataRemover::Observer {
     85  public:
     86   // BrowsingDataRemover::Observer interface method.
     87   virtual void OnBrowsingDataRemoverDone() OVERRIDE;
     88 
     89   // ExtensionFunction:
     90   virtual bool RunAsync() OVERRIDE;
     91 
     92  protected:
     93   virtual ~BrowsingDataRemoverFunction() {}
     94 
     95   // Children should override this method to provide the proper removal mask
     96   // based on the API call they represent.
     97   virtual int GetRemovalMask() = 0;
     98 
     99  private:
    100   // Updates the removal bitmask according to whether removing plugin data is
    101   // supported or not.
    102   void CheckRemovingPluginDataSupported(
    103       scoped_refptr<PluginPrefs> plugin_prefs);
    104 
    105   // Parse the developer-provided |origin_types| object into an origin_set_mask
    106   // that can be used with the BrowsingDataRemover.
    107   int ParseOriginSetMask(const base::DictionaryValue& options);
    108 
    109   // Called when we're ready to start removing data.
    110   void StartRemoving();
    111 
    112   base::Time remove_since_;
    113   int removal_mask_;
    114   int origin_set_mask_;
    115 };
    116 
    117 class BrowsingDataRemoveAppcacheFunction : public BrowsingDataRemoverFunction {
    118  public:
    119   DECLARE_EXTENSION_FUNCTION("browsingData.removeAppcache",
    120                              BROWSINGDATA_REMOVEAPPCACHE)
    121 
    122  protected:
    123   virtual ~BrowsingDataRemoveAppcacheFunction() {}
    124 
    125   // BrowsingDataRemoverFunction:
    126   virtual int GetRemovalMask() OVERRIDE;
    127 };
    128 
    129 class BrowsingDataRemoveFunction : public BrowsingDataRemoverFunction {
    130  public:
    131   DECLARE_EXTENSION_FUNCTION("browsingData.remove", BROWSINGDATA_REMOVE)
    132 
    133  protected:
    134   virtual ~BrowsingDataRemoveFunction() {}
    135 
    136   // BrowsingDataRemoverFunction:
    137   virtual int GetRemovalMask() OVERRIDE;
    138 };
    139 
    140 class BrowsingDataRemoveCacheFunction : public BrowsingDataRemoverFunction {
    141  public:
    142   DECLARE_EXTENSION_FUNCTION("browsingData.removeCache",
    143                              BROWSINGDATA_REMOVECACHE)
    144 
    145  protected:
    146   virtual ~BrowsingDataRemoveCacheFunction() {}
    147 
    148   // BrowsingDataRemoverFunction:
    149   virtual int GetRemovalMask() OVERRIDE;
    150 };
    151 
    152 class BrowsingDataRemoveCookiesFunction : public BrowsingDataRemoverFunction {
    153  public:
    154   DECLARE_EXTENSION_FUNCTION("browsingData.removeCookies",
    155                              BROWSINGDATA_REMOVECOOKIES)
    156 
    157  protected:
    158   virtual ~BrowsingDataRemoveCookiesFunction() {}
    159 
    160   // BrowsingDataRemoverFunction:
    161   virtual int GetRemovalMask() OVERRIDE;
    162 };
    163 
    164 class BrowsingDataRemoveDownloadsFunction : public BrowsingDataRemoverFunction {
    165  public:
    166   DECLARE_EXTENSION_FUNCTION("browsingData.removeDownloads",
    167                              BROWSINGDATA_REMOVEDOWNLOADS)
    168 
    169  protected:
    170   virtual ~BrowsingDataRemoveDownloadsFunction() {}
    171 
    172   // BrowsingDataRemoverFunction:
    173   virtual int GetRemovalMask() OVERRIDE;
    174 };
    175 
    176 class BrowsingDataRemoveFileSystemsFunction
    177     : public BrowsingDataRemoverFunction {
    178  public:
    179   DECLARE_EXTENSION_FUNCTION("browsingData.removeFileSystems",
    180                              BROWSINGDATA_REMOVEFILESYSTEMS)
    181 
    182  protected:
    183   virtual ~BrowsingDataRemoveFileSystemsFunction() {}
    184 
    185   // BrowsingDataRemoverFunction:
    186   virtual int GetRemovalMask() OVERRIDE;
    187 };
    188 
    189 class BrowsingDataRemoveFormDataFunction : public BrowsingDataRemoverFunction {
    190  public:
    191   DECLARE_EXTENSION_FUNCTION("browsingData.removeFormData",
    192                              BROWSINGDATA_REMOVEFORMDATA)
    193 
    194  protected:
    195   virtual ~BrowsingDataRemoveFormDataFunction() {}
    196 
    197   // BrowsingDataRemoverFunction:
    198   virtual int GetRemovalMask() OVERRIDE;
    199 };
    200 
    201 class BrowsingDataRemoveHistoryFunction : public BrowsingDataRemoverFunction {
    202  public:
    203   DECLARE_EXTENSION_FUNCTION("browsingData.removeHistory",
    204                              BROWSINGDATA_REMOVEHISTORY)
    205 
    206  protected:
    207   virtual ~BrowsingDataRemoveHistoryFunction() {}
    208 
    209   // BrowsingDataRemoverFunction:
    210   virtual int GetRemovalMask() OVERRIDE;
    211 };
    212 
    213 class BrowsingDataRemoveIndexedDBFunction : public BrowsingDataRemoverFunction {
    214  public:
    215   DECLARE_EXTENSION_FUNCTION("browsingData.removeIndexedDB",
    216                              BROWSINGDATA_REMOVEINDEXEDDB)
    217 
    218  protected:
    219   virtual ~BrowsingDataRemoveIndexedDBFunction() {}
    220 
    221   // BrowsingDataRemoverFunction:
    222   virtual int GetRemovalMask() OVERRIDE;
    223 };
    224 
    225 class BrowsingDataRemoveLocalStorageFunction
    226     : public BrowsingDataRemoverFunction {
    227  public:
    228   DECLARE_EXTENSION_FUNCTION("browsingData.removeLocalStorage",
    229                              BROWSINGDATA_REMOVELOCALSTORAGE)
    230 
    231  protected:
    232   virtual ~BrowsingDataRemoveLocalStorageFunction() {}
    233 
    234   // BrowsingDataRemoverFunction:
    235   virtual int GetRemovalMask() OVERRIDE;
    236 };
    237 
    238 class BrowsingDataRemovePluginDataFunction
    239     : public BrowsingDataRemoverFunction {
    240  public:
    241   DECLARE_EXTENSION_FUNCTION("browsingData.removePluginData",
    242                              BROWSINGDATA_REMOVEPLUGINDATA)
    243 
    244  protected:
    245   virtual ~BrowsingDataRemovePluginDataFunction() {}
    246 
    247   // BrowsingDataRemoverFunction:
    248   virtual int GetRemovalMask() OVERRIDE;
    249 };
    250 
    251 class BrowsingDataRemovePasswordsFunction : public BrowsingDataRemoverFunction {
    252  public:
    253   DECLARE_EXTENSION_FUNCTION("browsingData.removePasswords",
    254                              BROWSINGDATA_REMOVEPASSWORDS)
    255 
    256  protected:
    257   virtual ~BrowsingDataRemovePasswordsFunction() {}
    258 
    259   // BrowsingDataRemoverFunction:
    260   virtual int GetRemovalMask() OVERRIDE;
    261 };
    262 
    263 class BrowsingDataRemoveServiceWorkersFunction
    264     : public BrowsingDataRemoverFunction {
    265  public:
    266   DECLARE_EXTENSION_FUNCTION("browsingData.removeServiceWorkers",
    267                              BROWSINGDATA_REMOVESERVICEWORKERS)
    268 
    269  protected:
    270   virtual ~BrowsingDataRemoveServiceWorkersFunction() {}
    271 
    272   // BrowsingDataRemoverFunction:
    273   virtual int GetRemovalMask() OVERRIDE;
    274 };
    275 
    276 class BrowsingDataRemoveWebSQLFunction : public BrowsingDataRemoverFunction {
    277  public:
    278   DECLARE_EXTENSION_FUNCTION("browsingData.removeWebSQL",
    279                              BROWSINGDATA_REMOVEWEBSQL)
    280 
    281  protected:
    282   virtual ~BrowsingDataRemoveWebSQLFunction() {}
    283 
    284   // BrowsingDataRemoverFunction:
    285   virtual int GetRemovalMask() OVERRIDE;
    286 };
    287 
    288 #endif  // CHROME_BROWSER_EXTENSIONS_API_BROWSING_DATA_BROWSING_DATA_API_H_
    289