OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/notifications/message_center_settings_controller.h" | 5 #include "chrome/browser/notifications/message_center_settings_controller.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/extensions/app_icon_loader_impl.h" | 8 #include "chrome/browser/extensions/app_icon_loader_impl.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/favicon/favicon_service.h" | 10 #include "chrome/browser/favicon/favicon_service.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 UTF8ToUTF16(extension->name()), | 54 UTF8ToUTF16(extension->name()), |
55 notification_service->IsExtensionEnabled(extension->id()))); | 55 notification_service->IsExtensionEnabled(extension->id()))); |
56 app_icon_loader_->FetchImage(extension->id()); | 56 app_icon_loader_->FetchImage(extension->id()); |
57 } | 57 } |
58 | 58 |
59 ContentSettingsForOneType settings; | 59 ContentSettingsForOneType settings; |
60 notification_service->GetNotificationsSettings(&settings); | 60 notification_service->GetNotificationsSettings(&settings); |
61 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 61 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
62 profile, Profile::EXPLICIT_ACCESS); | 62 profile, Profile::EXPLICIT_ACCESS); |
63 favicon_tracker_.reset(new CancelableTaskTracker()); | 63 favicon_tracker_.reset(new CancelableTaskTracker()); |
| 64 patterns_.clear(); |
64 for (ContentSettingsForOneType::const_iterator iter = settings.begin(); | 65 for (ContentSettingsForOneType::const_iterator iter = settings.begin(); |
65 iter != settings.end(); ++iter) { | 66 iter != settings.end(); ++iter) { |
66 if (iter->primary_pattern == ContentSettingsPattern::Wildcard() && | 67 if (iter->primary_pattern == ContentSettingsPattern::Wildcard() && |
67 iter->secondary_pattern == ContentSettingsPattern::Wildcard() && | 68 iter->secondary_pattern == ContentSettingsPattern::Wildcard() && |
68 iter->source != "preference") { | 69 iter->source != "preference") { |
69 continue; | 70 continue; |
70 } | 71 } |
71 | 72 |
72 std::string url_pattern = iter->primary_pattern.ToString(); | 73 std::string url_pattern = iter->primary_pattern.ToString(); |
| 74 string16 name = UTF8ToUTF16(url_pattern); |
73 GURL url(url_pattern); | 75 GURL url(url_pattern); |
74 notifiers->push_back(new message_center::Notifier( | 76 notifiers->push_back(new message_center::Notifier( |
75 url, | 77 url, |
76 UTF8ToUTF16(url_pattern), | 78 name, |
77 notification_service->GetContentSetting(url) == CONTENT_SETTING_ALLOW)); | 79 notification_service->GetContentSetting(url) == CONTENT_SETTING_ALLOW)); |
| 80 patterns_[name] = iter->primary_pattern; |
78 FaviconService::FaviconForURLParams favicon_params( | 81 FaviconService::FaviconForURLParams favicon_params( |
79 profile, url, history::FAVICON | history::TOUCH_ICON, | 82 profile, url, history::FAVICON | history::TOUCH_ICON, |
80 message_center::kSettingsIconSize); | 83 message_center::kSettingsIconSize); |
81 // Note that favicon service obtains the favicon from history. This means | 84 // Note that favicon service obtains the favicon from history. This means |
82 // that it will fail to obtain the image if there are no history data for | 85 // that it will fail to obtain the image if there are no history data for |
83 // that URL. | 86 // that URL. |
84 favicon_service->GetFaviconImageForURL( | 87 favicon_service->GetFaviconImageForURL( |
85 favicon_params, | 88 favicon_params, |
86 base::Bind(&MessageCenterSettingsController::OnFaviconLoaded, | 89 base::Bind(&MessageCenterSettingsController::OnFaviconLoaded, |
87 base::Unretained(this), url), | 90 base::Unretained(this), url), |
(...skipping 23 matching lines...) Expand all Loading... |
111 (!enabled && default_setting == CONTENT_SETTING_ALLOW)) { | 114 (!enabled && default_setting == CONTENT_SETTING_ALLOW)) { |
112 if (notifier.url.is_valid()) { | 115 if (notifier.url.is_valid()) { |
113 if (enabled) | 116 if (enabled) |
114 notification_service->GrantPermission(notifier.url); | 117 notification_service->GrantPermission(notifier.url); |
115 else | 118 else |
116 notification_service->DenyPermission(notifier.url); | 119 notification_service->DenyPermission(notifier.url); |
117 } else { | 120 } else { |
118 LOG(ERROR) << "Invalid url pattern: " << notifier.url.spec(); | 121 LOG(ERROR) << "Invalid url pattern: " << notifier.url.spec(); |
119 } | 122 } |
120 } else { | 123 } else { |
121 ContentSettingsPattern pattern = | 124 std::map<string16, ContentSettingsPattern>::const_iterator iter = |
122 ContentSettingsPattern::FromURL(notifier.url); | 125 patterns_.find(notifier.name); |
123 if (pattern.IsValid()) | 126 if (iter != patterns_.end()) { |
124 notification_service->ClearSetting(pattern); | 127 notification_service->ClearSetting(iter->second); |
125 else | 128 } else { |
126 LOG(ERROR) << "Invalid url pattern: " << notifier.url.spec(); | 129 LOG(ERROR) << "Invalid url pattern: " << notifier.url.spec(); |
| 130 } |
127 } | 131 } |
128 break; | 132 break; |
129 } | 133 } |
130 } | 134 } |
131 } | 135 } |
132 | 136 |
133 void MessageCenterSettingsController::OnNotifierSettingsClosing() { | 137 void MessageCenterSettingsController::OnNotifierSettingsClosing() { |
134 delegate_ = NULL; | 138 delegate_ = NULL; |
135 DCHECK(favicon_tracker_.get()); | 139 DCHECK(favicon_tracker_.get()); |
136 favicon_tracker_->TryCancelAll(); | 140 favicon_tracker_->TryCancelAll(); |
| 141 patterns_.clear(); |
137 } | 142 } |
138 | 143 |
139 void MessageCenterSettingsController::OnFaviconLoaded( | 144 void MessageCenterSettingsController::OnFaviconLoaded( |
140 const GURL& url, | 145 const GURL& url, |
141 const history::FaviconImageResult& favicon_result) { | 146 const history::FaviconImageResult& favicon_result) { |
142 if (!delegate_) | 147 if (!delegate_) |
143 return; | 148 return; |
144 delegate_->UpdateFavicon(url, favicon_result.image); | 149 delegate_->UpdateFavicon(url, favicon_result.image); |
145 } | 150 } |
146 | 151 |
147 | 152 |
148 void MessageCenterSettingsController::SetAppImage(const std::string& id, | 153 void MessageCenterSettingsController::SetAppImage(const std::string& id, |
149 const gfx::ImageSkia& image) { | 154 const gfx::ImageSkia& image) { |
150 if (!delegate_) | 155 if (!delegate_) |
151 return; | 156 return; |
152 delegate_->UpdateIconImage(id, gfx::Image(image) ); | 157 delegate_->UpdateIconImage(id, gfx::Image(image) ); |
153 } | 158 } |
OLD | NEW |