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

Side by Side Diff: chrome/browser/extensions/extension_content_settings_api.cc

Issue 7713034: HostContentSettingsMap refactoring. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Code review comments. Threading fixes. Mac + win fixes. Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
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_api.h" 5 #include "chrome/browser/extensions/extension_content_settings_api.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/content_settings/cookie_settings.h"
12 #include "chrome/browser/content_settings/host_content_settings_map.h" 13 #include "chrome/browser/content_settings/host_content_settings_map.h"
13 #include "chrome/browser/extensions/extension_content_settings_api_constants.h" 14 #include "chrome/browser/extensions/extension_content_settings_api_constants.h"
14 #include "chrome/browser/extensions/extension_content_settings_helpers.h" 15 #include "chrome/browser/extensions/extension_content_settings_helpers.h"
15 #include "chrome/browser/extensions/extension_content_settings_store.h" 16 #include "chrome/browser/extensions/extension_content_settings_store.h"
16 #include "chrome/browser/extensions/extension_preference_api_constants.h" 17 #include "chrome/browser/extensions/extension_preference_api_constants.h"
17 #include "chrome/browser/extensions/extension_preference_helpers.h" 18 #include "chrome/browser/extensions/extension_preference_helpers.h"
18 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/extensions/extension_error_utils.h" 22 #include "chrome/common/extensions/extension_error_utils.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 if (details->HasKey(pref_keys::kIncognitoKey)) { 122 if (details->HasKey(pref_keys::kIncognitoKey)) {
122 EXTENSION_FUNCTION_VALIDATE( 123 EXTENSION_FUNCTION_VALIDATE(
123 details->GetBoolean(pref_keys::kIncognitoKey, &incognito)); 124 details->GetBoolean(pref_keys::kIncognitoKey, &incognito));
124 } 125 }
125 if (incognito && !include_incognito()) { 126 if (incognito && !include_incognito()) {
126 error_ = pref_keys::kIncognitoErrorMessage; 127 error_ = pref_keys::kIncognitoErrorMessage;
127 return false; 128 return false;
128 } 129 }
129 130
130 HostContentSettingsMap* map; 131 HostContentSettingsMap* map;
132 CookieSettings* cookie_settings;
131 if (incognito) { 133 if (incognito) {
132 if (!profile()->HasOffTheRecordProfile()) { 134 if (!profile()->HasOffTheRecordProfile()) {
133 // TODO(bauerb): Allow reading incognito content settings 135 // TODO(bauerb): Allow reading incognito content settings
134 // outside of an incognito session. 136 // outside of an incognito session.
135 error_ = keys::kIncognitoSessionOnlyError; 137 error_ = keys::kIncognitoSessionOnlyError;
136 return false; 138 return false;
137 } 139 }
138 map = profile()->GetOffTheRecordProfile()->GetHostContentSettingsMap(); 140 map = profile()->GetOffTheRecordProfile()->GetHostContentSettingsMap();
141 cookie_settings = CookieSettings::GetForProfile(
142 profile()->GetOffTheRecordProfile());
139 } else { 143 } else {
140 map = profile()->GetHostContentSettingsMap(); 144 map = profile()->GetHostContentSettingsMap();
145 cookie_settings = CookieSettings::GetForProfile(profile());
141 } 146 }
147 DCHECK(cookie_settings != NULL);
142 148
143 ContentSetting setting; 149 ContentSetting setting;
144 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { 150 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) {
145 // TODO(jochen): Do we return the value for setting or for reading cookies? 151 // TODO(jochen): Do we return the value for setting or for reading cookies?
146 bool setting_cookie = false; 152 if (cookie_settings->IsReadingCookieAllowed(primary_url, secondary_url)) {
147 setting = map->GetCookieContentSetting(primary_url, secondary_url, 153 if (cookie_settings->IsCookieSessionOnly(primary_url))
148 setting_cookie); 154 setting = CONTENT_SETTING_SESSION_ONLY;
155 else
156 setting = CONTENT_SETTING_ALLOW;
157 } else {
158 setting = CONTENT_SETTING_BLOCK;
159 }
149 } else { 160 } else {
150 setting = map->GetContentSetting(primary_url, secondary_url, content_type, 161 setting = map->GetContentSetting(primary_url, secondary_url, content_type,
151 resource_identifier); 162 resource_identifier);
152 } 163 }
153 164
154 DictionaryValue* result = new DictionaryValue(); 165 DictionaryValue* result = new DictionaryValue();
155 result->SetString(keys::kContentSettingKey, 166 result->SetString(keys::kContentSettingKey,
156 helpers::ContentSettingToString(setting)); 167 helpers::ContentSettingToString(setting));
157 168
158 result_.reset(result); 169 result_.reset(result);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 BrowserThread::PostTask( 309 BrowserThread::PostTask(
299 BrowserThread::UI, FROM_HERE, base::Bind( 310 BrowserThread::UI, FROM_HERE, base::Bind(
300 &GetResourceIdentifiersFunction::SendResponse, this, true)); 311 &GetResourceIdentifiersFunction::SendResponse, this, true));
301 } 312 }
302 313
303 // static 314 // static
304 void GetResourceIdentifiersFunction::SetPluginListForTesting( 315 void GetResourceIdentifiersFunction::SetPluginListForTesting(
305 webkit::npapi::PluginList* plugin_list) { 316 webkit::npapi::PluginList* plugin_list) {
306 g_plugin_list = plugin_list; 317 g_plugin_list = plugin_list;
307 } 318 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698