| 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/content_exceptions_table_model.h" | 5 #include "chrome/browser/content_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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/host_content_settings_map.h" | 10 #include "chrome/browser/host_content_settings_map.h" |
| 11 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
| 12 | 12 |
| 13 ContentExceptionsTableModel::ContentExceptionsTableModel( | 13 ContentExceptionsTableModel::ContentExceptionsTableModel( |
| 14 HostContentSettingsMap* map, | 14 HostContentSettingsMap* map, |
| 15 HostContentSettingsMap* off_the_record_map, | 15 HostContentSettingsMap* off_the_record_map, |
| 16 ContentSettingsType type) | 16 ContentSettingsType type) |
| 17 : map_(map), | 17 : map_(map), |
| 18 off_the_record_map_(off_the_record_map), | 18 off_the_record_map_(off_the_record_map), |
| 19 content_type_(type), | 19 content_type_(type), |
| 20 observer_(NULL) { | 20 observer_(NULL) { |
| 21 // Load the contents. | 21 // Load the contents. |
| 22 map->GetSettingsForOneType(type, &entries_); | 22 map->GetSettingsForOneType(type, "", &entries_); |
| 23 if (off_the_record_map) | 23 if (off_the_record_map) { |
| 24 off_the_record_map->GetSettingsForOneType(type, &off_the_record_entries_); | 24 off_the_record_map->GetSettingsForOneType(type, |
| 25 "", |
| 26 &off_the_record_entries_); |
| 27 } |
| 25 } | 28 } |
| 26 | 29 |
| 27 void ContentExceptionsTableModel::AddException( | 30 void ContentExceptionsTableModel::AddException( |
| 28 const HostContentSettingsMap::Pattern& pattern, | 31 const HostContentSettingsMap::Pattern& pattern, |
| 29 ContentSetting setting, | 32 ContentSetting setting, |
| 30 bool is_off_the_record) { | 33 bool is_off_the_record) { |
| 31 DCHECK(!is_off_the_record || off_the_record_map_); | 34 DCHECK(!is_off_the_record || off_the_record_map_); |
| 32 | 35 |
| 33 int insert_position = | 36 int insert_position = |
| 34 is_off_the_record ? RowCount() : static_cast<int>(entries_.size()); | 37 is_off_the_record ? RowCount() : static_cast<int>(entries_.size()); |
| 35 | 38 |
| 36 entries(is_off_the_record).push_back( | 39 entries(is_off_the_record).push_back( |
| 37 HostContentSettingsMap::PatternSettingPair(pattern, setting)); | 40 HostContentSettingsMap::PatternSettingPair(pattern, setting)); |
| 38 map(is_off_the_record)->SetContentSetting(pattern, content_type_, setting); | 41 map(is_off_the_record)->SetContentSetting(pattern, |
| 42 content_type_, |
| 43 "", |
| 44 setting); |
| 39 if (observer_) | 45 if (observer_) |
| 40 observer_->OnItemsAdded(insert_position, 1); | 46 observer_->OnItemsAdded(insert_position, 1); |
| 41 } | 47 } |
| 42 | 48 |
| 43 void ContentExceptionsTableModel::RemoveException(int row) { | 49 void ContentExceptionsTableModel::RemoveException(int row) { |
| 44 bool is_off_the_record = entry_is_off_the_record(row); | 50 bool is_off_the_record = entry_is_off_the_record(row); |
| 45 int position_to_delete = | 51 int position_to_delete = |
| 46 is_off_the_record ? row - static_cast<int>(entries_.size()) : row; | 52 is_off_the_record ? row - static_cast<int>(entries_.size()) : row; |
| 47 const HostContentSettingsMap::PatternSettingPair& pair = entry_at(row); | 53 const HostContentSettingsMap::PatternSettingPair& pair = entry_at(row); |
| 48 | 54 |
| 49 map(is_off_the_record)->SetContentSetting( | 55 map(is_off_the_record)->SetContentSetting( |
| 50 pair.first, content_type_, CONTENT_SETTING_DEFAULT); | 56 pair.first, content_type_, "", CONTENT_SETTING_DEFAULT); |
| 51 entries(is_off_the_record).erase( | 57 entries(is_off_the_record).erase( |
| 52 entries(is_off_the_record).begin() + position_to_delete); | 58 entries(is_off_the_record).begin() + position_to_delete); |
| 53 if (observer_) | 59 if (observer_) |
| 54 observer_->OnItemsRemoved(row, 1); | 60 observer_->OnItemsRemoved(row, 1); |
| 55 } | 61 } |
| 56 | 62 |
| 57 void ContentExceptionsTableModel::RemoveAll() { | 63 void ContentExceptionsTableModel::RemoveAll() { |
| 58 int old_row_count = RowCount(); | 64 int old_row_count = RowCount(); |
| 59 entries_.clear(); | 65 entries_.clear(); |
| 60 off_the_record_entries_.clear(); | 66 off_the_record_entries_.clear(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 default: | 117 default: |
| 112 NOTREACHED(); | 118 NOTREACHED(); |
| 113 } | 119 } |
| 114 | 120 |
| 115 return std::wstring(); | 121 return std::wstring(); |
| 116 } | 122 } |
| 117 | 123 |
| 118 void ContentExceptionsTableModel::SetObserver(TableModelObserver* observer) { | 124 void ContentExceptionsTableModel::SetObserver(TableModelObserver* observer) { |
| 119 observer_ = observer; | 125 observer_ = observer; |
| 120 } | 126 } |
| OLD | NEW |