| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/plugin_exceptions_table_model.h" | 5 #include "chrome/browser/plugin_exceptions_table_model.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/table_model_observer.h" | 8 #include "app/table_model_observer.h" |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 bool PluginExceptionsTableModel::CanRemoveRows(const Rows& rows) const { | 27 bool PluginExceptionsTableModel::CanRemoveRows(const Rows& rows) const { |
| 28 return !rows.empty(); | 28 return !rows.empty(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void PluginExceptionsTableModel::RemoveRows(const Rows& rows) { | 31 void PluginExceptionsTableModel::RemoveRows(const Rows& rows) { |
| 32 AutoReset<bool> tmp(&updates_disabled_, true); | 32 AutoReset<bool> tmp(&updates_disabled_, true); |
| 33 bool reload_all = false; | 33 bool reload_all = false; |
| 34 // Iterate in reverse over the rows to get the indexes right. | 34 // Iterate in reverse over the rows to get the indexes right. |
| 35 for (Rows::const_reverse_iterator it = rows.rbegin(); | 35 for (Rows::const_reverse_iterator it = rows.rbegin(); |
| 36 it != rows.rend(); ++it) { | 36 it != rows.rend(); ++it) { |
| 37 DCHECK_LT(*it, settings_.size()); |
| 37 SettingsEntry& entry = settings_[*it]; | 38 SettingsEntry& entry = settings_[*it]; |
| 38 HostContentSettingsMap* map = entry.is_otr ? otr_map_ : map_; | 39 HostContentSettingsMap* map = entry.is_otr ? otr_map_ : map_; |
| 39 map->SetContentSetting(entry.pattern, | 40 map->SetContentSetting(entry.pattern, |
| 40 CONTENT_SETTINGS_TYPE_PLUGINS, | 41 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 41 resources_[entry.plugin_id], | 42 resources_[entry.plugin_id], |
| 42 CONTENT_SETTING_DEFAULT); | 43 CONTENT_SETTING_DEFAULT); |
| 43 row_counts_[entry.plugin_id]--; | 44 row_counts_[entry.plugin_id]--; |
| 44 // If we remove the last exception for a plugin, recreate all groups to get | 45 // If we remove the last exception for a plugin, recreate all groups to get |
| 45 // correct IDs. | 46 // correct IDs. |
| 46 if (row_counts_[entry.plugin_id] == 0) | 47 if (row_counts_[entry.plugin_id] == 0) |
| 47 reload_all = true; | 48 reload_all = true; |
| 48 settings_.erase(settings_.begin() + *it); | 49 settings_.erase(settings_.begin() + *it); |
| 49 } | 50 } |
| 50 if (reload_all) { | 51 if (reload_all) { |
| 51 // This also notifies the observer. | 52 // This also notifies the observer. |
| 52 ReloadSettings(); | 53 ReloadSettings(); |
| 53 } else if (observer_) { | 54 } else if (observer_) { |
| 54 for (Rows::const_reverse_iterator it = rows.rbegin(); | 55 for (Rows::const_reverse_iterator it = rows.rbegin(); |
| 55 it != rows.rend(); ++it) { | 56 it != rows.rend(); ++it) { |
| 56 observer_->OnItemsRemoved(*it, 1); | 57 observer_->OnItemsRemoved(*it, 1); |
| 57 } | 58 } |
| 58 } | 59 } |
| 59 } | 60 } |
| 60 | 61 |
| 61 void PluginExceptionsTableModel::RemoveAll() { | 62 void PluginExceptionsTableModel::RemoveAll() { |
| 62 int old_row_count = RowCount(); | 63 AutoReset<bool> tmp(&updates_disabled_, true); |
| 63 { | 64 map_->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS); |
| 64 AutoReset<bool> tmp(&updates_disabled_, true); | 65 if (otr_map_) |
| 65 map_->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS); | 66 otr_map_->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS); |
| 66 if (otr_map_) | 67 |
| 67 otr_map_->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS); | |
| 68 } | |
| 69 ClearSettings(); | 68 ClearSettings(); |
| 70 if (observer_) | 69 if (observer_) |
| 71 observer_->OnItemsRemoved(0, old_row_count); | 70 observer_->OnModelChanged(); |
| 72 } | 71 } |
| 73 | 72 |
| 74 int PluginExceptionsTableModel::RowCount() { | 73 int PluginExceptionsTableModel::RowCount() { |
| 75 return settings_.size(); | 74 return settings_.size(); |
| 76 } | 75 } |
| 77 | 76 |
| 78 std::wstring PluginExceptionsTableModel::GetText(int row, int column_id) { | 77 std::wstring PluginExceptionsTableModel::GetText(int row, int column_id) { |
| 79 DCHECK_GE(row, 0); | 78 DCHECK_GE(row, 0); |
| 80 DCHECK_LT(row, static_cast<int>(settings_.size())); | 79 DCHECK_LT(row, static_cast<int>(settings_.size())); |
| 81 SettingsEntry& entry = settings_[row]; | 80 SettingsEntry& entry = settings_[row]; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 } | 187 } |
| 189 | 188 |
| 190 void PluginExceptionsTableModel::ReloadSettings() { | 189 void PluginExceptionsTableModel::ReloadSettings() { |
| 191 ClearSettings(); | 190 ClearSettings(); |
| 192 LoadSettings(); | 191 LoadSettings(); |
| 193 | 192 |
| 194 if (observer_) | 193 if (observer_) |
| 195 observer_->OnModelChanged(); | 194 observer_->OnModelChanged(); |
| 196 } | 195 } |
| 197 | 196 |
| OLD | NEW |