Home | History | Annotate | Download | only in browser
      1 // Copyright (c) 2011 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_PLUGIN_EXCEPTIONS_TABLE_MODEL_H_
      6 #define CHROME_BROWSER_PLUGIN_EXCEPTIONS_TABLE_MODEL_H_
      7 #pragma once
      8 
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "base/compiler_specific.h"
     13 #include "chrome/browser/content_settings/host_content_settings_map.h"
     14 #include "chrome/browser/remove_rows_table_model.h"
     15 #include "content/common/notification_observer.h"
     16 #include "webkit/plugins/npapi/plugin_list.h"
     17 
     18 struct WebPluginInfo;
     19 
     20 class PluginExceptionsTableModel : public RemoveRowsTableModel,
     21                                    public NotificationObserver {
     22  public:
     23   PluginExceptionsTableModel(HostContentSettingsMap* content_settings_map,
     24                              HostContentSettingsMap* otr_content_settings_map);
     25   virtual ~PluginExceptionsTableModel();
     26 
     27   // Load plugin exceptions from the HostContentSettingsMaps. You should call
     28   // this method after creating a new PluginExceptionsTableModel.
     29   void LoadSettings();
     30 
     31   // RemoveRowsTableModel methods:
     32   virtual bool CanRemoveRows(const Rows& rows) const;
     33   virtual void RemoveRows(const Rows& rows);
     34   virtual void RemoveAll();
     35 
     36   // TableModel methods:
     37   virtual int RowCount() OVERRIDE;
     38   virtual string16 GetText(int row, int column_id) OVERRIDE;
     39   virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE;
     40   virtual bool HasGroups() OVERRIDE;
     41   virtual Groups GetGroups() OVERRIDE;
     42   virtual int GetGroupID(int row) OVERRIDE;
     43 
     44   // NotificationObserver methods:
     45   virtual void Observe(NotificationType type,
     46                        const NotificationSource& source,
     47                        const NotificationDetails& details);
     48 
     49  protected:
     50   // Subclasses can override this method for testing.
     51   virtual void GetPlugins(
     52       std::vector<webkit::npapi::PluginGroup>* plugin_groups);
     53 
     54  private:
     55   friend class PluginExceptionsTableModelTest;
     56 
     57   struct SettingsEntry {
     58     ContentSettingsPattern pattern;
     59     int plugin_id;
     60     ContentSetting setting;
     61     bool is_otr;
     62   };
     63 
     64   void ClearSettings();
     65   void ReloadSettings();
     66 
     67   scoped_refptr<HostContentSettingsMap> map_;
     68   scoped_refptr<HostContentSettingsMap> otr_map_;
     69 
     70   std::vector<SettingsEntry> settings_;
     71   std::vector<int> row_counts_;
     72   std::vector<std::string> resources_;
     73   TableModel::Groups groups_;
     74 
     75   NotificationRegistrar registrar_;
     76   bool updates_disabled_;
     77 
     78   // Weak, can be NULL. Our owner should manage its lifetime, see
     79   // TableModel::SetObserver().
     80   ui::TableModelObserver* observer_;
     81 
     82   DISALLOW_COPY_AND_ASSIGN(PluginExceptionsTableModel);
     83 };
     84 
     85 #endif  // CHROME_BROWSER_PLUGIN_EXCEPTIONS_TABLE_MODEL_H_
     86