Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: chrome/browser/content_exceptions_table_model.cc

Issue 2858032: Display content settings applying to the current otr session only. (Closed)
Patch Set: updates Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 ContentSettingsType type) 16 ContentSettingsType type)
16 : map_(map), 17 : map_(map),
18 off_the_record_map_(off_the_record_map),
17 content_type_(type), 19 content_type_(type),
18 observer_(NULL) { 20 observer_(NULL) {
19 // Load the contents. 21 // Load the contents.
20 map->GetSettingsForOneType(type, &entries_); 22 map->GetSettingsForOneType(type, &entries_);
23 if (off_the_record_map)
24 off_the_record_map->GetSettingsForOneType(type, &off_the_record_entries_);
21 } 25 }
22 26
23 void ContentExceptionsTableModel::AddException( 27 void ContentExceptionsTableModel::AddException(
24 const HostContentSettingsMap::Pattern& pattern, 28 const HostContentSettingsMap::Pattern& pattern,
25 ContentSetting setting) { 29 ContentSetting setting,
26 entries_.push_back( 30 bool is_off_the_record) {
31 DCHECK(!is_off_the_record || off_the_record_map_);
32
33 int insert_position =
34 is_off_the_record ? RowCount() : static_cast<int>(entries_.size());
35
36 entries(is_off_the_record).push_back(
27 HostContentSettingsMap::PatternSettingPair(pattern, setting)); 37 HostContentSettingsMap::PatternSettingPair(pattern, setting));
28 map_->SetContentSetting(pattern, content_type_, setting); 38 map(is_off_the_record)->SetContentSetting(pattern, content_type_, setting);
29 if (observer_) 39 if (observer_)
30 observer_->OnItemsAdded(RowCount() - 1, 1); 40 observer_->OnItemsAdded(insert_position, 1);
31 } 41 }
32 42
33 void ContentExceptionsTableModel::RemoveException(int row) { 43 void ContentExceptionsTableModel::RemoveException(int row) {
34 const HostContentSettingsMap::PatternSettingPair& pair = entries_[row]; 44 bool is_off_the_record = entry_is_off_the_record(row);
35 map_->SetContentSetting(pair.first, content_type_, CONTENT_SETTING_DEFAULT); 45 int position_to_delete =
36 entries_.erase(entries_.begin() + row); 46 is_off_the_record ? row - static_cast<int>(entries_.size()) : row;
47 const HostContentSettingsMap::PatternSettingPair& pair = entry_at(row);
48
49 map(is_off_the_record)->SetContentSetting(
50 pair.first, content_type_, CONTENT_SETTING_DEFAULT);
51 entries(is_off_the_record).erase(
52 entries(is_off_the_record).begin() + position_to_delete);
37 if (observer_) 53 if (observer_)
38 observer_->OnItemsRemoved(row, 1); 54 observer_->OnItemsRemoved(row, 1);
39 } 55 }
40 56
41 void ContentExceptionsTableModel::RemoveAll() { 57 void ContentExceptionsTableModel::RemoveAll() {
42 int old_row_count = RowCount(); 58 int old_row_count = RowCount();
43 entries_.clear(); 59 entries_.clear();
60 off_the_record_entries_.clear();
44 map_->ClearSettingsForOneType(content_type_); 61 map_->ClearSettingsForOneType(content_type_);
62 if (off_the_record_map_)
63 off_the_record_map_->ClearSettingsForOneType(content_type_);
45 if (observer_) 64 if (observer_)
46 observer_->OnItemsRemoved(0, old_row_count); 65 observer_->OnItemsRemoved(0, old_row_count);
47 } 66 }
48 67
49 int ContentExceptionsTableModel::IndexOfExceptionByPattern( 68 int ContentExceptionsTableModel::IndexOfExceptionByPattern(
50 const HostContentSettingsMap::Pattern& pattern) { 69 const HostContentSettingsMap::Pattern& pattern,
70 bool is_off_the_record) {
71 DCHECK(!is_off_the_record || off_the_record_map_);
72
73 int offset =
74 is_off_the_record ? static_cast<int>(entries_.size()) : 0;
75
51 // This is called on every key type in the editor. Move to a map if we end up 76 // This is called on every key type in the editor. Move to a map if we end up
52 // with lots of exceptions. 77 // with lots of exceptions.
53 for (size_t i = 0; i < entries_.size(); ++i) { 78 for (size_t i = 0; i < entries(is_off_the_record).size(); ++i) {
54 if (entries_[i].first == pattern) 79 if (entries(is_off_the_record)[i].first == pattern)
55 return static_cast<int>(i); 80 return offset + static_cast<int>(i);
56 } 81 }
57 return -1; 82 return -1;
58 } 83 }
59 84
60 int ContentExceptionsTableModel::RowCount() { 85 int ContentExceptionsTableModel::RowCount() {
61 return static_cast<int>(entries_.size()); 86 return static_cast<int>(entries_.size() + off_the_record_entries_.size());
62 } 87 }
63 88
64 std::wstring ContentExceptionsTableModel::GetText(int row, int column_id) { 89 std::wstring ContentExceptionsTableModel::GetText(int row, int column_id) {
65 HostContentSettingsMap::PatternSettingPair entry = entries_[row]; 90 HostContentSettingsMap::PatternSettingPair entry = entry_at(row);
66 91
67 switch (column_id) { 92 switch (column_id) {
68 case IDS_EXCEPTIONS_PATTERN_HEADER: 93 case IDS_EXCEPTIONS_PATTERN_HEADER:
69 return UTF8ToWide(entry.first.AsString()); 94 return UTF8ToWide(entry.first.AsString());
70 95
71 case IDS_EXCEPTIONS_ACTION_HEADER: 96 case IDS_EXCEPTIONS_ACTION_HEADER:
72 switch (entry.second) { 97 switch (entry.second) {
73 case CONTENT_SETTING_ALLOW: 98 case CONTENT_SETTING_ALLOW:
74 return l10n_util::GetString(IDS_EXCEPTIONS_ALLOW_BUTTON); 99 return l10n_util::GetString(IDS_EXCEPTIONS_ALLOW_BUTTON);
75 case CONTENT_SETTING_BLOCK: 100 case CONTENT_SETTING_BLOCK:
76 return l10n_util::GetString(IDS_EXCEPTIONS_BLOCK_BUTTON); 101 return l10n_util::GetString(IDS_EXCEPTIONS_BLOCK_BUTTON);
77 case CONTENT_SETTING_ASK: 102 case CONTENT_SETTING_ASK:
78 return l10n_util::GetString(IDS_EXCEPTIONS_ASK_BUTTON); 103 return l10n_util::GetString(IDS_EXCEPTIONS_ASK_BUTTON);
79 default: 104 default:
80 NOTREACHED(); 105 NOTREACHED();
81 } 106 }
82 break; 107 break;
83 108
84 default: 109 default:
85 NOTREACHED(); 110 NOTREACHED();
86 } 111 }
87 112
88 return std::wstring(); 113 return std::wstring();
89 } 114 }
90 115
91 void ContentExceptionsTableModel::SetObserver(TableModelObserver* observer) { 116 void ContentExceptionsTableModel::SetObserver(TableModelObserver* observer) {
92 observer_ = observer; 117 observer_ = observer;
93 } 118 }
OLDNEW
« no previous file with comments | « chrome/browser/content_exceptions_table_model.h ('k') | chrome/browser/gtk/options/content_exception_editor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698