| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/extensions/extension_content_settings_store.h" | 5 #include "chrome/browser/extensions/extension_content_settings_store.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/extension_content_settings_api_constants.h" | 12 #include "chrome/browser/extensions/extension_content_settings_api_constants.h" |
| 13 #include "chrome/browser/extensions/extension_content_settings_helpers.h" | 13 #include "chrome/browser/extensions/extension_content_settings_helpers.h" |
| 14 #include "content/browser/browser_thread.h" | 14 #include "content/browser/browser_thread.h" |
| 15 | 15 |
| 16 namespace helpers = extension_content_settings_helpers; | 16 namespace helpers = extension_content_settings_helpers; |
| 17 namespace keys = extension_content_settings_api_constants; | 17 namespace keys = extension_content_settings_api_constants; |
| 18 | 18 |
| 19 using content_settings::ResourceIdentifier; | 19 using content_settings::ResourceIdentifier; |
| 20 | 20 |
| 21 struct ExtensionContentSettingsStore::ExtensionEntry { | 21 struct ExtensionContentSettingsStore::ExtensionEntry { |
| 22 // Installation time of the extension. | 22 // Installation time of the extension. |
| 23 base::Time install_time; | 23 base::Time install_time; |
| 24 // Whether extension is enabled in the profile. | 24 // Whether extension is enabled in the profile. |
| 25 bool enabled; | 25 bool enabled; |
| 26 // Content settings. | 26 // Content settings. |
| 27 ContentSettingSpecList settings; | 27 ContentSettingSpecList settings; |
| 28 // Incognito content settings. | 28 // Persistent incognito content settings. |
| 29 ContentSettingSpecList incognito_settings; | 29 ContentSettingSpecList incognito_persistent_settings; |
| 30 // Session-only incognito content settings. |
| 31 ContentSettingSpecList incognito_session_only_settings; |
| 30 }; | 32 }; |
| 31 | 33 |
| 32 ExtensionContentSettingsStore::ExtensionContentSettingsStore() { | 34 ExtensionContentSettingsStore::ExtensionContentSettingsStore() { |
| 33 DCHECK(OnCorrectThread()); | 35 DCHECK(OnCorrectThread()); |
| 34 } | 36 } |
| 35 | 37 |
| 36 ExtensionContentSettingsStore::~ExtensionContentSettingsStore() { | 38 ExtensionContentSettingsStore::~ExtensionContentSettingsStore() { |
| 37 DCHECK(OnCorrectThread()); | 39 DCHECK(OnCorrectThread()); |
| 38 NotifyOfDestruction(); | 40 NotifyOfDestruction(); |
| 39 STLDeleteValues(&entries_); | 41 STLDeleteValues(&entries_); |
| 40 } | 42 } |
| 41 | 43 |
| 42 void ExtensionContentSettingsStore::SetExtensionContentSetting( | 44 void ExtensionContentSettingsStore::SetExtensionContentSetting( |
| 43 const std::string& ext_id, | 45 const std::string& ext_id, |
| 44 const ContentSettingsPattern& embedded_pattern, | 46 const ContentSettingsPattern& embedded_pattern, |
| 45 const ContentSettingsPattern& top_level_pattern, | 47 const ContentSettingsPattern& top_level_pattern, |
| 46 ContentSettingsType type, | 48 ContentSettingsType type, |
| 47 const content_settings::ResourceIdentifier& identifier, | 49 const content_settings::ResourceIdentifier& identifier, |
| 48 ContentSetting setting, | 50 ContentSetting setting, |
| 49 bool incognito) { | 51 extension_prefs_scope::Scope scope) { |
| 50 { | 52 { |
| 51 base::AutoLock lock(lock_); | 53 base::AutoLock lock(lock_); |
| 52 ContentSettingSpecList* setting_spec_list = | 54 ContentSettingSpecList* setting_spec_list = |
| 53 GetContentSettingSpecList(ext_id, incognito); | 55 GetContentSettingSpecList(ext_id, scope); |
| 54 | 56 |
| 55 // Find |ContentSettingSpec|. | 57 // Find |ContentSettingSpec|. |
| 56 ContentSettingSpecList::iterator setting_spec = setting_spec_list->begin(); | 58 ContentSettingSpecList::iterator setting_spec = setting_spec_list->begin(); |
| 57 while (setting_spec != setting_spec_list->end()) { | 59 while (setting_spec != setting_spec_list->end()) { |
| 58 if (setting_spec->embedded_pattern == embedded_pattern && | 60 if (setting_spec->embedded_pattern == embedded_pattern && |
| 59 setting_spec->top_level_pattern == top_level_pattern && | 61 setting_spec->top_level_pattern == top_level_pattern && |
| 60 setting_spec->content_type == type && | 62 setting_spec->content_type == type && |
| 61 setting_spec->resource_identifier == identifier) { | 63 setting_spec->resource_identifier == identifier) { |
| 62 break; | 64 break; |
| 63 } | 65 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 78 setting_spec->setting = setting; | 80 setting_spec->setting = setting; |
| 79 } else { | 81 } else { |
| 80 setting_spec_list->erase(setting_spec); | 82 setting_spec_list->erase(setting_spec); |
| 81 } | 83 } |
| 82 } | 84 } |
| 83 | 85 |
| 84 // Send notification that content settings changed. | 86 // Send notification that content settings changed. |
| 85 // TODO(markusheintz): Notifications should only be sent if the set content | 87 // TODO(markusheintz): Notifications should only be sent if the set content |
| 86 // setting is effective and not hidden by another setting of another | 88 // setting is effective and not hidden by another setting of another |
| 87 // extension installed more recently. | 89 // extension installed more recently. |
| 88 NotifyOfContentSettingChanged(ext_id, incognito); | 90 NotifyOfContentSettingChanged(ext_id, |
| 91 scope != extension_prefs_scope::kRegular); |
| 89 } | 92 } |
| 90 | 93 |
| 91 void ExtensionContentSettingsStore::RegisterExtension( | 94 void ExtensionContentSettingsStore::RegisterExtension( |
| 92 const std::string& ext_id, | 95 const std::string& ext_id, |
| 93 const base::Time& install_time, | 96 const base::Time& install_time, |
| 94 bool is_enabled) { | 97 bool is_enabled) { |
| 95 base::AutoLock lock(lock_); | 98 base::AutoLock lock(lock_); |
| 96 ExtensionEntryMap::iterator i = entries_.find(ext_id); | 99 ExtensionEntryMap::iterator i = entries_.find(ext_id); |
| 97 if (i != entries_.end()) | 100 if (i != entries_.end()) |
| 98 delete i->second; | 101 delete i->second; |
| 99 | 102 |
| 100 entries_[ext_id] = new ExtensionEntry; | 103 entries_[ext_id] = new ExtensionEntry; |
| 101 entries_[ext_id]->install_time = install_time; | 104 entries_[ext_id]->install_time = install_time; |
| 102 entries_[ext_id]->enabled = is_enabled; | 105 entries_[ext_id]->enabled = is_enabled; |
| 103 } | 106 } |
| 104 | 107 |
| 105 void ExtensionContentSettingsStore::UnregisterExtension( | 108 void ExtensionContentSettingsStore::UnregisterExtension( |
| 106 const std::string& ext_id) { | 109 const std::string& ext_id) { |
| 107 bool notify = false; | 110 bool notify = false; |
| 108 bool notify_incognito = false; | 111 bool notify_incognito = false; |
| 109 { | 112 { |
| 110 base::AutoLock lock(lock_); | 113 base::AutoLock lock(lock_); |
| 111 ExtensionEntryMap::iterator i = entries_.find(ext_id); | 114 ExtensionEntryMap::iterator i = entries_.find(ext_id); |
| 112 if (i == entries_.end()) | 115 if (i == entries_.end()) |
| 113 return; | 116 return; |
| 114 notify = !i->second->settings.empty(); | 117 notify = !i->second->settings.empty(); |
| 115 notify_incognito = !i->second->incognito_settings.empty(); | 118 notify_incognito = !i->second->incognito_persistent_settings.empty() || |
| 119 !i->second->incognito_session_only_settings.empty(); |
| 116 | 120 |
| 117 delete i->second; | 121 delete i->second; |
| 118 entries_.erase(i); | 122 entries_.erase(i); |
| 119 } | 123 } |
| 120 if (notify) | 124 if (notify) |
| 121 NotifyOfContentSettingChanged(ext_id, false); | 125 NotifyOfContentSettingChanged(ext_id, false); |
| 122 if (notify_incognito) | 126 if (notify_incognito) |
| 123 NotifyOfContentSettingChanged(ext_id, true); | 127 NotifyOfContentSettingChanged(ext_id, true); |
| 124 } | 128 } |
| 125 | 129 |
| 126 void ExtensionContentSettingsStore::SetExtensionState( | 130 void ExtensionContentSettingsStore::SetExtensionState( |
| 127 const std::string& ext_id, bool is_enabled) { | 131 const std::string& ext_id, bool is_enabled) { |
| 128 bool notify = false; | 132 bool notify = false; |
| 129 bool notify_incognito = false; | 133 bool notify_incognito = false; |
| 130 { | 134 { |
| 131 base::AutoLock lock(lock_); | 135 base::AutoLock lock(lock_); |
| 132 ExtensionEntryMap::const_iterator i = entries_.find(ext_id); | 136 ExtensionEntryMap::const_iterator i = entries_.find(ext_id); |
| 133 if (i == entries_.end()) | 137 if (i == entries_.end()) |
| 134 return; | 138 return; |
| 135 notify = !i->second->settings.empty(); | 139 notify = !i->second->settings.empty(); |
| 136 notify_incognito = !i->second->incognito_settings.empty(); | 140 notify_incognito = !i->second->incognito_persistent_settings.empty() || |
| 141 !i->second->incognito_session_only_settings.empty(); |
| 137 | 142 |
| 138 i->second->enabled = is_enabled; | 143 i->second->enabled = is_enabled; |
| 139 } | 144 } |
| 140 if (notify) | 145 if (notify) |
| 141 NotifyOfContentSettingChanged(ext_id, false); | 146 NotifyOfContentSettingChanged(ext_id, false); |
| 142 if (notify_incognito) | 147 if (notify_incognito) |
| 143 NotifyOfContentSettingChanged(ext_id, true); | 148 NotifyOfContentSettingChanged(ext_id, true); |
| 144 } | 149 } |
| 145 | 150 |
| 146 ExtensionContentSettingsStore::ContentSettingSpecList* | 151 ExtensionContentSettingsStore::ContentSettingSpecList* |
| 147 ExtensionContentSettingsStore::GetContentSettingSpecList( | 152 ExtensionContentSettingsStore::GetContentSettingSpecList( |
| 148 const std::string& ext_id, | 153 const std::string& ext_id, |
| 149 bool incognito) { | 154 extension_prefs_scope::Scope scope) { |
| 150 ExtensionEntryMap::const_iterator i = entries_.find(ext_id); | 155 ExtensionEntryMap::const_iterator i = entries_.find(ext_id); |
| 151 DCHECK(i != entries_.end()); | 156 DCHECK(i != entries_.end()); |
| 152 return incognito ? &(i->second->incognito_settings) | 157 switch (scope) { |
| 153 : &(i->second->settings); | 158 case extension_prefs_scope::kRegular: |
| 159 return &(i->second->settings); |
| 160 case extension_prefs_scope::kIncognitoPersistent: |
| 161 return &(i->second->incognito_persistent_settings); |
| 162 case extension_prefs_scope::kIncognitoSessionOnly: |
| 163 return &(i->second->incognito_session_only_settings); |
| 164 } |
| 165 NOTREACHED(); |
| 166 return NULL; |
| 154 } | 167 } |
| 155 | 168 |
| 156 const ExtensionContentSettingsStore::ContentSettingSpecList* | 169 const ExtensionContentSettingsStore::ContentSettingSpecList* |
| 157 ExtensionContentSettingsStore::GetContentSettingSpecList( | 170 ExtensionContentSettingsStore::GetContentSettingSpecList( |
| 158 const std::string& ext_id, | 171 const std::string& ext_id, |
| 159 bool incognito) const { | 172 extension_prefs_scope::Scope scope) const { |
| 160 ExtensionEntryMap::const_iterator i = entries_.find(ext_id); | 173 ExtensionEntryMap::const_iterator i = entries_.find(ext_id); |
| 161 DCHECK(i != entries_.end()); | 174 DCHECK(i != entries_.end()); |
| 162 return incognito ? &(i->second->incognito_settings) | 175 switch (scope) { |
| 163 : &(i->second->settings); | 176 case extension_prefs_scope::kRegular: |
| 177 return &(i->second->settings); |
| 178 case extension_prefs_scope::kIncognitoPersistent: |
| 179 return &(i->second->incognito_persistent_settings); |
| 180 case extension_prefs_scope::kIncognitoSessionOnly: |
| 181 return &(i->second->incognito_session_only_settings); |
| 182 } |
| 183 NOTREACHED(); |
| 184 return NULL; |
| 164 } | 185 } |
| 165 | 186 |
| 166 | |
| 167 ContentSetting ExtensionContentSettingsStore::GetContentSettingFromSpecList( | 187 ContentSetting ExtensionContentSettingsStore::GetContentSettingFromSpecList( |
| 168 const GURL& embedded_url, | 188 const GURL& embedded_url, |
| 169 const GURL& top_level_url, | 189 const GURL& top_level_url, |
| 170 ContentSettingsType type, | 190 ContentSettingsType type, |
| 171 const content_settings::ResourceIdentifier& identifier, | 191 const content_settings::ResourceIdentifier& identifier, |
| 172 const ContentSettingSpecList& setting_spec_list) const { | 192 const ContentSettingSpecList& setting_spec_list) const { |
| 173 ContentSettingSpecList::const_iterator winner_spec = setting_spec_list.end(); | 193 ContentSettingSpecList::const_iterator winner_spec = setting_spec_list.end(); |
| 174 | 194 |
| 175 for (ContentSettingSpecList::const_iterator spec = setting_spec_list.begin(); | 195 for (ContentSettingSpecList::const_iterator spec = setting_spec_list.begin(); |
| 176 spec != setting_spec_list.end(); ++spec) { | 196 spec != setting_spec_list.end(); ++spec) { |
| 177 if (!spec->embedded_pattern.Matches(embedded_url) || | 197 if (!spec->embedded_pattern.Matches(embedded_url) || |
| 178 !spec->top_level_pattern.Matches(top_level_url) || | 198 !spec->top_level_pattern.Matches(top_level_url) || |
| 179 spec->content_type != type || | 199 spec->content_type != type || |
| 180 spec->resource_identifier != identifier) { | 200 spec->resource_identifier != identifier) { |
| 181 continue; | 201 continue; |
| 182 } | 202 } |
| 183 | 203 |
| 184 // TODO(markusheintz): Compare top-level patterns as well? | 204 // TODO(markusheintz): Compare embedded patterns as well? |
| 185 if (winner_spec == setting_spec_list.end() || | 205 if (winner_spec == setting_spec_list.end() || |
| 186 spec->embedded_pattern.Compare(winner_spec->embedded_pattern) == | 206 winner_spec->top_level_pattern.Compare(spec->top_level_pattern) == |
| 187 ContentSettingsPattern::SUCCESSOR) { | 207 ContentSettingsPattern::SUCCESSOR) { |
| 188 winner_spec = spec; | 208 winner_spec = spec; |
| 189 } | 209 } |
| 190 } | 210 } |
| 191 | 211 |
| 192 return (winner_spec != setting_spec_list.end()) ? winner_spec->setting | 212 return (winner_spec != setting_spec_list.end()) ? winner_spec->setting |
| 193 : CONTENT_SETTING_DEFAULT; | 213 : CONTENT_SETTING_DEFAULT; |
| 194 } | 214 } |
| 195 | 215 |
| 196 ContentSetting ExtensionContentSettingsStore::GetEffectiveContentSetting( | 216 ContentSetting ExtensionContentSettingsStore::GetEffectiveContentSetting( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 209 const base::Time& install_time = i->second->install_time; | 229 const base::Time& install_time = i->second->install_time; |
| 210 const bool enabled = i->second->enabled; | 230 const bool enabled = i->second->enabled; |
| 211 | 231 |
| 212 if (!enabled) | 232 if (!enabled) |
| 213 continue; | 233 continue; |
| 214 if (install_time < winners_install_time) | 234 if (install_time < winners_install_time) |
| 215 continue; | 235 continue; |
| 216 | 236 |
| 217 ContentSetting setting = CONTENT_SETTING_DEFAULT; | 237 ContentSetting setting = CONTENT_SETTING_DEFAULT; |
| 218 if (incognito) { | 238 if (incognito) { |
| 219 // Get incognito setting | 239 // Try session-only incognito setting first. |
| 220 setting = GetContentSettingFromSpecList(embedded_url, top_level_url, type, | 240 setting = GetContentSettingFromSpecList( |
| 221 identifier, | 241 embedded_url, top_level_url, type, identifier, |
| 222 i->second->incognito_settings); | 242 i->second->incognito_session_only_settings); |
| 243 if (setting == CONTENT_SETTING_DEFAULT) { |
| 244 // Next, persistent incognito setting. |
| 245 setting = GetContentSettingFromSpecList( |
| 246 embedded_url, top_level_url, type, identifier, |
| 247 i->second->incognito_persistent_settings); |
| 248 } |
| 223 } | 249 } |
| 224 if (setting == CONTENT_SETTING_DEFAULT) { | 250 if (setting == CONTENT_SETTING_DEFAULT) { |
| 225 // Get non incognito setting | 251 // Then, non-incognito setting. |
| 226 setting = GetContentSettingFromSpecList(embedded_url, top_level_url, type, | 252 setting = GetContentSettingFromSpecList(embedded_url, top_level_url, type, |
| 227 identifier, i->second->settings); | 253 identifier, i->second->settings); |
| 228 } | 254 } |
| 229 | 255 |
| 230 if (setting != CONTENT_SETTING_DEFAULT) { | 256 if (setting != CONTENT_SETTING_DEFAULT) { |
| 231 winners_install_time = install_time; | 257 winners_install_time = install_time; |
| 232 winner_setting = setting; | 258 winner_setting = setting; |
| 233 } | 259 } |
| 234 } | 260 } |
| 235 | 261 |
| 236 return winner_setting; | 262 return winner_setting; |
| 237 } | 263 } |
| 238 | 264 |
| 265 void ExtensionContentSettingsStore::ClearContentSettingsForExtension( |
| 266 const std::string& ext_id, |
| 267 extension_prefs_scope::Scope scope) { |
| 268 bool notify = false; |
| 269 { |
| 270 base::AutoLock lock(lock_); |
| 271 ContentSettingSpecList* setting_spec_list = |
| 272 GetContentSettingSpecList(ext_id, scope); |
| 273 notify = !setting_spec_list->empty(); |
| 274 setting_spec_list->clear(); |
| 275 } |
| 276 if (notify) { |
| 277 NotifyOfContentSettingChanged(ext_id, |
| 278 scope != extension_prefs_scope::kRegular); |
| 279 } |
| 280 } |
| 281 |
| 282 // static |
| 283 void ExtensionContentSettingsStore::AddRules( |
| 284 ContentSettingsType type, |
| 285 const content_settings::ResourceIdentifier& identifier, |
| 286 const ContentSettingSpecList* setting_spec_list, |
| 287 content_settings::ProviderInterface::Rules* rules) { |
| 288 ContentSettingSpecList::const_iterator it; |
| 289 for (it = setting_spec_list->begin(); it != setting_spec_list->end(); ++it) { |
| 290 if (it->content_type == type && it->resource_identifier == identifier) { |
| 291 rules->push_back(content_settings::ProviderInterface::Rule( |
| 292 it->embedded_pattern, it->top_level_pattern, it->setting)); |
| 293 } |
| 294 } |
| 295 } |
| 296 |
| 239 void ExtensionContentSettingsStore::GetContentSettingsForContentType( | 297 void ExtensionContentSettingsStore::GetContentSettingsForContentType( |
| 240 ContentSettingsType type, | 298 ContentSettingsType type, |
| 241 const content_settings::ResourceIdentifier& identifier, | 299 const content_settings::ResourceIdentifier& identifier, |
| 242 bool incognito, | 300 bool incognito, |
| 243 content_settings::ProviderInterface::Rules* rules) const { | 301 content_settings::ProviderInterface::Rules* rules) const { |
| 244 base::AutoLock lock(lock_); | 302 base::AutoLock lock(lock_); |
| 245 ExtensionEntryMap::const_iterator ext_it; | 303 ExtensionEntryMap::const_iterator ext_it; |
| 246 for (ext_it = entries_.begin(); ext_it != entries_.end(); ++ext_it) { | 304 for (ext_it = entries_.begin(); ext_it != entries_.end(); ++ext_it) { |
| 247 const ContentSettingSpecList* setting_spec_list = | 305 if (incognito) { |
| 248 GetContentSettingSpecList(ext_it->first, incognito); | 306 AddRules(type, identifier, |
| 249 ContentSettingSpecList::const_iterator it; | 307 GetContentSettingSpecList( |
| 250 for (it = setting_spec_list->begin(); it != setting_spec_list->end(); | 308 ext_it->first, |
| 251 ++it) { | 309 extension_prefs_scope::kIncognitoPersistent), |
| 252 if (it->content_type == type && it->resource_identifier == identifier) { | 310 rules); |
| 253 rules->push_back(content_settings::ProviderInterface::Rule( | 311 AddRules(type, identifier, |
| 254 it->embedded_pattern, it->top_level_pattern, it->setting)); | 312 GetContentSettingSpecList( |
| 255 } | 313 ext_it->first, |
| 314 extension_prefs_scope::kIncognitoSessionOnly), |
| 315 rules); |
| 316 } else { |
| 317 AddRules(type, identifier, |
| 318 GetContentSettingSpecList( |
| 319 ext_it->first, |
| 320 extension_prefs_scope::kRegular), |
| 321 rules); |
| 256 } | 322 } |
| 257 } | 323 } |
| 258 } | 324 } |
| 259 | 325 |
| 260 ListValue* ExtensionContentSettingsStore::GetSettingsForExtension( | 326 ListValue* ExtensionContentSettingsStore::GetSettingsForExtension( |
| 261 const std::string& extension_id) const { | 327 const std::string& extension_id, |
| 328 extension_prefs_scope::Scope scope) const { |
| 262 base::AutoLock lock(lock_); | 329 base::AutoLock lock(lock_); |
| 263 ListValue* settings = new ListValue(); | 330 ListValue* settings = new ListValue(); |
| 264 const ContentSettingSpecList* setting_spec_list = | 331 const ContentSettingSpecList* setting_spec_list = |
| 265 GetContentSettingSpecList(extension_id, false); | 332 GetContentSettingSpecList(extension_id, scope); |
| 266 ContentSettingSpecList::const_iterator it; | 333 ContentSettingSpecList::const_iterator it; |
| 267 for (it = setting_spec_list->begin(); it != setting_spec_list->end(); ++it) { | 334 for (it = setting_spec_list->begin(); it != setting_spec_list->end(); ++it) { |
| 268 DictionaryValue* setting_dict = new DictionaryValue(); | 335 DictionaryValue* setting_dict = new DictionaryValue(); |
| 269 setting_dict->SetString(keys::kEmbeddedPatternKey, | 336 setting_dict->SetString(keys::kEmbeddedPatternKey, |
| 270 it->embedded_pattern.ToString()); | 337 it->embedded_pattern.ToString()); |
| 271 setting_dict->SetString(keys::kTopLevelPatternKey, | 338 setting_dict->SetString(keys::kTopLevelPatternKey, |
| 272 it->top_level_pattern.ToString()); | 339 it->top_level_pattern.ToString()); |
| 273 setting_dict->SetString( | 340 setting_dict->SetString( |
| 274 keys::kContentSettingsTypeKey, | 341 keys::kContentSettingsTypeKey, |
| 275 helpers::ContentSettingsTypeToString(it->content_type)); | 342 helpers::ContentSettingsTypeToString(it->content_type)); |
| 276 setting_dict->SetString(keys::kResourceIdentifierKey, | 343 setting_dict->SetString(keys::kResourceIdentifierKey, |
| 277 it->resource_identifier); | 344 it->resource_identifier); |
| 278 setting_dict->SetString(keys::kContentSettingKey, | 345 setting_dict->SetString(keys::kContentSettingKey, |
| 279 helpers::ContentSettingToString(it->setting)); | 346 helpers::ContentSettingToString(it->setting)); |
| 280 settings->Append(setting_dict); | 347 settings->Append(setting_dict); |
| 281 } | 348 } |
| 282 return settings; | 349 return settings; |
| 283 } | 350 } |
| 284 | 351 |
| 285 void ExtensionContentSettingsStore::SetExtensionContentSettingsFromList( | 352 void ExtensionContentSettingsStore::SetExtensionContentSettingsFromList( |
| 286 const std::string& extension_id, | 353 const std::string& extension_id, |
| 287 const ListValue* list) { | 354 const ListValue* list, |
| 355 extension_prefs_scope::Scope scope) { |
| 288 for (ListValue::const_iterator it = list->begin(); it != list->end(); ++it) { | 356 for (ListValue::const_iterator it = list->begin(); it != list->end(); ++it) { |
| 289 if ((*it)->GetType() != Value::TYPE_DICTIONARY) { | 357 if ((*it)->GetType() != Value::TYPE_DICTIONARY) { |
| 290 NOTREACHED(); | 358 NOTREACHED(); |
| 291 continue; | 359 continue; |
| 292 } | 360 } |
| 293 DictionaryValue* dict = static_cast<DictionaryValue*>(*it); | 361 DictionaryValue* dict = static_cast<DictionaryValue*>(*it); |
| 294 std::string pattern_str; | 362 std::string pattern_str; |
| 295 dict->GetString(keys::kTopLevelPatternKey, &pattern_str); | 363 dict->GetString(keys::kTopLevelPatternKey, &pattern_str); |
| 296 ContentSettingsPattern pattern = | 364 ContentSettingsPattern pattern = |
| 297 ContentSettingsPattern::FromString(pattern_str); | 365 ContentSettingsPattern::FromString(pattern_str); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 318 bool result = | 386 bool result = |
| 319 helpers::StringToContentSetting(content_setting_string, &setting); | 387 helpers::StringToContentSetting(content_setting_string, &setting); |
| 320 DCHECK(result); | 388 DCHECK(result); |
| 321 | 389 |
| 322 SetExtensionContentSetting(extension_id, | 390 SetExtensionContentSetting(extension_id, |
| 323 pattern, | 391 pattern, |
| 324 embedded_pattern, | 392 embedded_pattern, |
| 325 content_settings_type, | 393 content_settings_type, |
| 326 resource_identifier, | 394 resource_identifier, |
| 327 setting, | 395 setting, |
| 328 false); | 396 scope); |
| 329 } | 397 } |
| 330 } | 398 } |
| 331 | 399 |
| 332 void ExtensionContentSettingsStore::AddObserver(Observer* observer) { | 400 void ExtensionContentSettingsStore::AddObserver(Observer* observer) { |
| 333 DCHECK(OnCorrectThread()); | 401 DCHECK(OnCorrectThread()); |
| 334 observers_.AddObserver(observer); | 402 observers_.AddObserver(observer); |
| 335 } | 403 } |
| 336 | 404 |
| 337 void ExtensionContentSettingsStore::RemoveObserver(Observer* observer) { | 405 void ExtensionContentSettingsStore::RemoveObserver(Observer* observer) { |
| 338 DCHECK(OnCorrectThread()); | 406 DCHECK(OnCorrectThread()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 364 ExtensionContentSettingsStore::Observer, | 432 ExtensionContentSettingsStore::Observer, |
| 365 observers_, | 433 observers_, |
| 366 OnContentSettingChanged(extension_id, incognito)); | 434 OnContentSettingChanged(extension_id, incognito)); |
| 367 } | 435 } |
| 368 | 436 |
| 369 bool ExtensionContentSettingsStore::OnCorrectThread() { | 437 bool ExtensionContentSettingsStore::OnCorrectThread() { |
| 370 // If there is no UI thread, we're most likely in a unit test. | 438 // If there is no UI thread, we're most likely in a unit test. |
| 371 return !BrowserThread::IsWellKnownThread(BrowserThread::UI) || | 439 return !BrowserThread::IsWellKnownThread(BrowserThread::UI) || |
| 372 BrowserThread::CurrentlyOn(BrowserThread::UI); | 440 BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 373 } | 441 } |
| OLD | NEW |