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