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/ui/webui/collected_cookies_ui_delegate.h" | 5 #include "chrome/browser/ui/webui/collected_cookies_ui_delegate.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/content_settings/host_content_settings_map.h" | 12 #include "chrome/browser/content_settings/cookie_settings.h" |
13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
14 #include "chrome/browser/cookies_tree_model.h" | 14 #include "chrome/browser/cookies_tree_model.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
17 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 18 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
18 #include "chrome/browser/ui/webui/constrained_html_ui.h" | 19 #include "chrome/browser/ui/webui/constrained_html_ui.h" |
19 #include "chrome/browser/ui/webui/cookies_tree_model_util.h" | 20 #include "chrome/browser/ui/webui/cookies_tree_model_util.h" |
20 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
21 #include "chrome/common/jstemplate_builder.h" | 22 #include "chrome/common/jstemplate_builder.h" |
| 23 #include "chrome/common/pref_names.h" |
22 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
23 #include "content/browser/tab_contents/tab_contents.h" | 25 #include "content/browser/tab_contents/tab_contents.h" |
24 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.h" |
25 #include "grit/browser_resources.h" | 27 #include "grit/browser_resources.h" |
26 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
27 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
28 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
29 #include "ui/gfx/size.h" | 31 #include "ui/gfx/size.h" |
30 | 32 |
31 namespace { | 33 namespace { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 ConstrainedHtmlUI::CreateConstrainedHtmlDialog(profile, | 151 ConstrainedHtmlUI::CreateConstrainedHtmlDialog(profile, |
150 delegate, | 152 delegate, |
151 wrapper); | 153 wrapper); |
152 } | 154 } |
153 | 155 |
154 CollectedCookiesUIDelegate::CollectedCookiesUIDelegate( | 156 CollectedCookiesUIDelegate::CollectedCookiesUIDelegate( |
155 TabContentsWrapper* wrapper) | 157 TabContentsWrapper* wrapper) |
156 : wrapper_(wrapper), | 158 : wrapper_(wrapper), |
157 closed_(false) { | 159 closed_(false) { |
158 TabSpecificContentSettings* content_settings = wrapper->content_settings(); | 160 TabSpecificContentSettings* content_settings = wrapper->content_settings(); |
159 HostContentSettingsMap* host_content_settings_map = | 161 PrefService* prefs = wrapper->profile()->GetPrefs(); |
160 wrapper->profile()->GetHostContentSettingsMap(); | |
161 | 162 |
162 registrar_.Add(this, chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, | 163 registrar_.Add(this, chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, |
163 content::Source<TabSpecificContentSettings>(content_settings)); | 164 content::Source<TabSpecificContentSettings>(content_settings)); |
164 | 165 |
165 allowed_cookies_tree_model_.reset( | 166 allowed_cookies_tree_model_.reset( |
166 content_settings->GetAllowedCookiesTreeModel()); | 167 content_settings->GetAllowedCookiesTreeModel()); |
167 blocked_cookies_tree_model_.reset( | 168 blocked_cookies_tree_model_.reset( |
168 content_settings->GetBlockedCookiesTreeModel()); | 169 content_settings->GetBlockedCookiesTreeModel()); |
169 | 170 |
170 CollectedCookiesSource* source = new CollectedCookiesSource( | 171 CollectedCookiesSource* source = new CollectedCookiesSource( |
171 host_content_settings_map->BlockThirdPartyCookies()); | 172 prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); |
172 wrapper->profile()->GetChromeURLDataManager()->AddDataSource(source); | 173 wrapper->profile()->GetChromeURLDataManager()->AddDataSource(source); |
173 } | 174 } |
174 | 175 |
175 CollectedCookiesUIDelegate::~CollectedCookiesUIDelegate() { | 176 CollectedCookiesUIDelegate::~CollectedCookiesUIDelegate() { |
176 } | 177 } |
177 | 178 |
178 bool CollectedCookiesUIDelegate::IsDialogModal() const { | 179 bool CollectedCookiesUIDelegate::IsDialogModal() const { |
179 return false; | 180 return false; |
180 } | 181 } |
181 | 182 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 237 |
237 void CollectedCookiesUIDelegate::SetInfobarLabel(const std::string& text) { | 238 void CollectedCookiesUIDelegate::SetInfobarLabel(const std::string& text) { |
238 StringValue string(text); | 239 StringValue string(text); |
239 web_ui_->CallJavascriptFunction("setInfobarLabel", string); | 240 web_ui_->CallJavascriptFunction("setInfobarLabel", string); |
240 } | 241 } |
241 | 242 |
242 void CollectedCookiesUIDelegate::AddContentException( | 243 void CollectedCookiesUIDelegate::AddContentException( |
243 CookieTreeOriginNode* origin_node, ContentSetting setting) { | 244 CookieTreeOriginNode* origin_node, ContentSetting setting) { |
244 if (origin_node->CanCreateContentException()) { | 245 if (origin_node->CanCreateContentException()) { |
245 Profile* profile = wrapper_->profile(); | 246 Profile* profile = wrapper_->profile(); |
246 origin_node->CreateContentException(profile->GetHostContentSettingsMap(), | 247 origin_node->CreateContentException(CookieSettings::GetForProfile(profile), |
247 setting); | 248 setting); |
248 | 249 |
249 SetInfobarLabel(GetInfobarLabel(setting, origin_node->GetTitle())); | 250 SetInfobarLabel(GetInfobarLabel(setting, origin_node->GetTitle())); |
250 } | 251 } |
251 } | 252 } |
252 | 253 |
253 void CollectedCookiesUIDelegate::Observe( | 254 void CollectedCookiesUIDelegate::Observe( |
254 int type, | 255 int type, |
255 const content::NotificationSource& source, | 256 const content::NotificationSource& source, |
256 const content::NotificationDetails& details) { | 257 const content::NotificationDetails& details) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 if (!args->GetString(0, &node_path)) | 297 if (!args->GetString(0, &node_path)) |
297 return; | 298 return; |
298 | 299 |
299 CookieTreeOriginNode* origin_node = GetOriginNode( | 300 CookieTreeOriginNode* origin_node = GetOriginNode( |
300 blocked_cookies_tree_model_.get(), node_path); | 301 blocked_cookies_tree_model_.get(), node_path); |
301 if (!origin_node) | 302 if (!origin_node) |
302 return; | 303 return; |
303 | 304 |
304 AddContentException(origin_node, CONTENT_SETTING_SESSION_ONLY); | 305 AddContentException(origin_node, CONTENT_SETTING_SESSION_ONLY); |
305 } | 306 } |
OLD | NEW |