OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/content_settings/content_setting_bubble_model.h" | 5 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK}, | 156 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK}, |
157 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK}, | 157 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK}, |
158 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK}, | 158 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK}, |
159 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK}, | 159 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK}, |
160 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK}, | 160 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK}, |
161 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_LEARN_MORE}, | 161 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_LEARN_MORE}, |
162 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, IDS_HANDLERS_BUBBLE_MANAGE_LINK}, | 162 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, IDS_HANDLERS_BUBBLE_MANAGE_LINK}, |
163 {CONTENT_SETTINGS_TYPE_MEDIASTREAM, IDS_MEDIASTREAM_BUBBLE_MANAGE_LINK}, | 163 {CONTENT_SETTINGS_TYPE_MEDIASTREAM, IDS_MEDIASTREAM_BUBBLE_MANAGE_LINK}, |
164 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_PPAPI_BROKER_BUBBLE_MANAGE_LINK}, | 164 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_PPAPI_BROKER_BUBBLE_MANAGE_LINK}, |
165 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOADS_LINK}, | 165 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOADS_LINK}, |
| 166 {CONTENT_SETTINGS_TYPE_MIDI_SYSEX, IDS_MIDI_SYSEX_BUBBLE_MANAGE_LINK}, |
166 }; | 167 }; |
167 set_manage_link(l10n_util::GetStringUTF8( | 168 set_manage_link(l10n_util::GetStringUTF8( |
168 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); | 169 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); |
169 } | 170 } |
170 | 171 |
171 void ContentSettingTitleAndLinkModel::OnManageLinkClicked() { | 172 void ContentSettingTitleAndLinkModel::OnManageLinkClicked() { |
172 if (delegate_) | 173 if (delegate_) |
173 delegate_->ShowContentSettingsPage(content_type()); | 174 delegate_->ShowContentSettingsPage(content_type()); |
174 } | 175 } |
175 | 176 |
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 } | 1156 } |
1156 | 1157 |
1157 void ContentSettingRPHBubbleModel::ClearOrSetPreviousHandler() { | 1158 void ContentSettingRPHBubbleModel::ClearOrSetPreviousHandler() { |
1158 if (previous_handler_.IsEmpty()) { | 1159 if (previous_handler_.IsEmpty()) { |
1159 registry_->ClearDefault(pending_handler_.protocol()); | 1160 registry_->ClearDefault(pending_handler_.protocol()); |
1160 } else { | 1161 } else { |
1161 registry_->OnAcceptRegisterProtocolHandler(previous_handler_); | 1162 registry_->OnAcceptRegisterProtocolHandler(previous_handler_); |
1162 } | 1163 } |
1163 } | 1164 } |
1164 | 1165 |
| 1166 // TODO(toyoshim): Should share as many code with geolocation as possible. |
| 1167 class ContentSettingMIDISysExBubbleModel |
| 1168 : public ContentSettingTitleAndLinkModel { |
| 1169 public: |
| 1170 ContentSettingMIDISysExBubbleModel(Delegate* delegate, |
| 1171 WebContents* web_contents, |
| 1172 Profile* profile, |
| 1173 ContentSettingsType content_type); |
| 1174 virtual ~ContentSettingMIDISysExBubbleModel() {} |
| 1175 |
| 1176 private: |
| 1177 void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id); |
| 1178 void SetDomainsAndCustomLink(); |
| 1179 virtual void OnCustomLinkClicked() OVERRIDE; |
| 1180 }; |
| 1181 |
| 1182 ContentSettingMIDISysExBubbleModel::ContentSettingMIDISysExBubbleModel( |
| 1183 Delegate* delegate, |
| 1184 WebContents* web_contents, |
| 1185 Profile* profile, |
| 1186 ContentSettingsType content_type) |
| 1187 : ContentSettingTitleAndLinkModel( |
| 1188 delegate, web_contents, profile, content_type) { |
| 1189 DCHECK_EQ(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, content_type); |
| 1190 SetDomainsAndCustomLink(); |
| 1191 } |
| 1192 |
| 1193 void ContentSettingMIDISysExBubbleModel::MaybeAddDomainList( |
| 1194 const std::set<std::string>& hosts, int title_id) { |
| 1195 if (!hosts.empty()) { |
| 1196 DomainList domain_list; |
| 1197 domain_list.title = l10n_util::GetStringUTF8(title_id); |
| 1198 domain_list.hosts = hosts; |
| 1199 add_domain_list(domain_list); |
| 1200 } |
| 1201 } |
| 1202 |
| 1203 void ContentSettingMIDISysExBubbleModel::SetDomainsAndCustomLink() { |
| 1204 TabSpecificContentSettings* content_settings = |
| 1205 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 1206 const ContentSettingsUsagesState& usages_state = |
| 1207 content_settings->midi_usages_state(); |
| 1208 ContentSettingsUsagesState::FormattedHostsPerState formatted_hosts_per_state; |
| 1209 unsigned int tab_state_flags = 0; |
| 1210 usages_state.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags); |
| 1211 // Divide the tab's current MIDI sysex users into sets according to their |
| 1212 // permission state. |
| 1213 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW], |
| 1214 IDS_MIDI_SYSEX_BUBBLE_ALLOWED); |
| 1215 |
| 1216 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK], |
| 1217 IDS_MIDI_SYSEX_BUBBLE_DENIED); |
| 1218 |
| 1219 if (tab_state_flags & ContentSettingsUsagesState::TABSTATE_HAS_EXCEPTION) { |
| 1220 set_custom_link(l10n_util::GetStringUTF8( |
| 1221 IDS_MIDI_SYSEX_BUBBLE_CLEAR_LINK)); |
| 1222 set_custom_link_enabled(true); |
| 1223 } else if (tab_state_flags & |
| 1224 ContentSettingsUsagesState::TABSTATE_HAS_CHANGED) { |
| 1225 set_custom_link(l10n_util::GetStringUTF8( |
| 1226 IDS_MIDI_SYSEX_BUBBLE_REQUIRE_RELOAD_TO_CLEAR)); |
| 1227 } |
| 1228 } |
| 1229 |
| 1230 void ContentSettingMIDISysExBubbleModel::OnCustomLinkClicked() { |
| 1231 if (!web_contents()) |
| 1232 return; |
| 1233 // Reset this embedder's entry to default for each of the requesting |
| 1234 // origins currently on the page. |
| 1235 TabSpecificContentSettings* content_settings = |
| 1236 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 1237 const ContentSettingsUsagesState::StateMap& state_map = |
| 1238 content_settings->midi_usages_state().state_map(); |
| 1239 HostContentSettingsMap* settings_map = |
| 1240 profile()->GetHostContentSettingsMap(); |
| 1241 |
| 1242 for (ContentSettingsUsagesState::StateMap::const_iterator it = |
| 1243 state_map.begin(); it != state_map.end(); ++it) { |
| 1244 settings_map->SetContentSetting( |
| 1245 ContentSettingsPattern::FromURLNoWildcard(it->first), |
| 1246 ContentSettingsPattern::Wildcard(), |
| 1247 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, |
| 1248 std::string(), |
| 1249 CONTENT_SETTING_DEFAULT); |
| 1250 } |
| 1251 } |
| 1252 |
1165 // static | 1253 // static |
1166 ContentSettingBubbleModel* | 1254 ContentSettingBubbleModel* |
1167 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 1255 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
1168 Delegate* delegate, | 1256 Delegate* delegate, |
1169 WebContents* web_contents, | 1257 WebContents* web_contents, |
1170 Profile* profile, | 1258 Profile* profile, |
1171 ContentSettingsType content_type) { | 1259 ContentSettingsType content_type) { |
1172 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { | 1260 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { |
1173 return new ContentSettingCookiesBubbleModel(delegate, web_contents, profile, | 1261 return new ContentSettingCookiesBubbleModel(delegate, web_contents, profile, |
1174 content_type); | 1262 content_type); |
(...skipping 17 matching lines...) Expand all Loading... |
1192 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { | 1280 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { |
1193 return new ContentSettingMixedScriptBubbleModel(delegate, web_contents, | 1281 return new ContentSettingMixedScriptBubbleModel(delegate, web_contents, |
1194 profile, content_type); | 1282 profile, content_type); |
1195 } | 1283 } |
1196 if (content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { | 1284 if (content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { |
1197 ProtocolHandlerRegistry* registry = | 1285 ProtocolHandlerRegistry* registry = |
1198 ProtocolHandlerRegistryFactory::GetForProfile(profile); | 1286 ProtocolHandlerRegistryFactory::GetForProfile(profile); |
1199 return new ContentSettingRPHBubbleModel(delegate, web_contents, profile, | 1287 return new ContentSettingRPHBubbleModel(delegate, web_contents, profile, |
1200 registry, content_type); | 1288 registry, content_type); |
1201 } | 1289 } |
| 1290 if (content_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { |
| 1291 return new ContentSettingMIDISysExBubbleModel(delegate, web_contents, |
| 1292 profile, content_type); |
| 1293 } |
1202 return new ContentSettingSingleRadioGroup(delegate, web_contents, profile, | 1294 return new ContentSettingSingleRadioGroup(delegate, web_contents, profile, |
1203 content_type); | 1295 content_type); |
1204 } | 1296 } |
1205 | 1297 |
1206 ContentSettingBubbleModel::ContentSettingBubbleModel( | 1298 ContentSettingBubbleModel::ContentSettingBubbleModel( |
1207 WebContents* web_contents, | 1299 WebContents* web_contents, |
1208 Profile* profile, | 1300 Profile* profile, |
1209 ContentSettingsType content_type) | 1301 ContentSettingsType content_type) |
1210 : web_contents_(web_contents), | 1302 : web_contents_(web_contents), |
1211 profile_(profile), | 1303 profile_(profile), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 1339 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
1248 DCHECK_EQ(web_contents_, | 1340 DCHECK_EQ(web_contents_, |
1249 content::Source<WebContents>(source).ptr()); | 1341 content::Source<WebContents>(source).ptr()); |
1250 web_contents_ = NULL; | 1342 web_contents_ = NULL; |
1251 } else { | 1343 } else { |
1252 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 1344 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
1253 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 1345 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
1254 profile_ = NULL; | 1346 profile_ = NULL; |
1255 } | 1347 } |
1256 } | 1348 } |
OLD | NEW |