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/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/content_settings/host_content_settings_map.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 IDR_COLLECTED_COOKIES_HTML)); | 123 IDR_COLLECTED_COOKIES_HTML)); |
124 std::string response = jstemplate_builder::GetI18nTemplateHtml( | 124 std::string response = jstemplate_builder::GetI18nTemplateHtml( |
125 html, &localized_strings); | 125 html, &localized_strings); |
126 | 126 |
127 SendResponse(request_id, base::RefCountedString::TakeString(&response)); | 127 SendResponse(request_id, base::RefCountedString::TakeString(&response)); |
128 } | 128 } |
129 | 129 |
130 } // namespace | 130 } // namespace |
131 | 131 |
132 // static | 132 // static |
133 void CollectedCookiesUIDelegate::Show(TabContents* tab_contents) { | 133 void CollectedCookiesUIDelegate::Show(TabContentsWrapper* wrapper) { |
134 CollectedCookiesUIDelegate* delegate = | 134 CollectedCookiesUIDelegate* delegate = |
135 new CollectedCookiesUIDelegate(tab_contents); | 135 new CollectedCookiesUIDelegate(wrapper); |
136 Profile* profile = | 136 Profile* profile = wrapper->profile(); |
137 Profile::FromBrowserContext(tab_contents->browser_context()); | |
138 ConstrainedHtmlUI::CreateConstrainedHtmlDialog(profile, | 137 ConstrainedHtmlUI::CreateConstrainedHtmlDialog(profile, |
139 delegate, | 138 delegate, |
140 tab_contents); | 139 wrapper->tab_contents()); |
141 } | 140 } |
142 | 141 |
143 CollectedCookiesUIDelegate::CollectedCookiesUIDelegate( | 142 CollectedCookiesUIDelegate::CollectedCookiesUIDelegate( |
144 TabContents* tab_contents) | 143 TabContentsWrapper* wrapper) |
145 : tab_contents_(tab_contents), | 144 : wrapper_(wrapper), |
146 closed_(false) { | 145 closed_(false) { |
147 TabContentsWrapper* wrapper = | |
148 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); | |
149 TabSpecificContentSettings* content_settings = wrapper->content_settings(); | 146 TabSpecificContentSettings* content_settings = wrapper->content_settings(); |
150 HostContentSettingsMap* host_content_settings_map = | 147 HostContentSettingsMap* host_content_settings_map = |
151 wrapper->profile()->GetHostContentSettingsMap(); | 148 wrapper->profile()->GetHostContentSettingsMap(); |
152 | 149 |
153 registrar_.Add(this, chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, | 150 registrar_.Add(this, chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, |
154 Source<TabSpecificContentSettings>(content_settings)); | 151 Source<TabSpecificContentSettings>(content_settings)); |
155 | 152 |
156 allowed_cookies_tree_model_.reset( | 153 allowed_cookies_tree_model_.reset( |
157 content_settings->GetAllowedCookiesTreeModel()); | 154 content_settings->GetAllowedCookiesTreeModel()); |
158 blocked_cookies_tree_model_.reset( | 155 blocked_cookies_tree_model_.reset( |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 219 } |
223 | 220 |
224 void CollectedCookiesUIDelegate::SetInfobarLabel(const std::string& text) { | 221 void CollectedCookiesUIDelegate::SetInfobarLabel(const std::string& text) { |
225 StringValue string(text); | 222 StringValue string(text); |
226 web_ui_->CallJavascriptFunction("setInfobarLabel", string); | 223 web_ui_->CallJavascriptFunction("setInfobarLabel", string); |
227 } | 224 } |
228 | 225 |
229 void CollectedCookiesUIDelegate::AddContentException( | 226 void CollectedCookiesUIDelegate::AddContentException( |
230 CookieTreeOriginNode* origin_node, ContentSetting setting) { | 227 CookieTreeOriginNode* origin_node, ContentSetting setting) { |
231 if (origin_node->CanCreateContentException()) { | 228 if (origin_node->CanCreateContentException()) { |
232 Profile* profile = | 229 Profile* profile = wrapper_->profile(); |
233 Profile::FromBrowserContext(tab_contents_->browser_context()); | |
234 origin_node->CreateContentException(profile->GetHostContentSettingsMap(), | 230 origin_node->CreateContentException(profile->GetHostContentSettingsMap(), |
235 setting); | 231 setting); |
236 | 232 |
237 SetInfobarLabel(GetInfobarLabel(setting, origin_node->GetTitle())); | 233 SetInfobarLabel(GetInfobarLabel(setting, origin_node->GetTitle())); |
238 } | 234 } |
239 } | 235 } |
240 | 236 |
241 void CollectedCookiesUIDelegate::Observe(int type, | 237 void CollectedCookiesUIDelegate::Observe(int type, |
242 const NotificationSource& source, | 238 const NotificationSource& source, |
243 const NotificationDetails& details) { | 239 const NotificationDetails& details) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 if (!args->GetString(0, &node_path)) | 279 if (!args->GetString(0, &node_path)) |
284 return; | 280 return; |
285 | 281 |
286 CookieTreeOriginNode* origin_node = GetOriginNode( | 282 CookieTreeOriginNode* origin_node = GetOriginNode( |
287 blocked_cookies_tree_model_.get(), node_path); | 283 blocked_cookies_tree_model_.get(), node_path); |
288 if (!origin_node) | 284 if (!origin_node) |
289 return; | 285 return; |
290 | 286 |
291 AddContentException(origin_node, CONTENT_SETTING_SESSION_ONLY); | 287 AddContentException(origin_node, CONTENT_SETTING_SESSION_ONLY); |
292 } | 288 } |
OLD | NEW |