| 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 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 } | 1124 } |
| 1125 | 1125 |
| 1126 void ContentSettingRPHBubbleModel::ClearOrSetPreviousHandler() { | 1126 void ContentSettingRPHBubbleModel::ClearOrSetPreviousHandler() { |
| 1127 if (previous_handler_.IsEmpty()) { | 1127 if (previous_handler_.IsEmpty()) { |
| 1128 registry_->ClearDefault(pending_handler_.protocol()); | 1128 registry_->ClearDefault(pending_handler_.protocol()); |
| 1129 } else { | 1129 } else { |
| 1130 registry_->OnAcceptRegisterProtocolHandler(previous_handler_); | 1130 registry_->OnAcceptRegisterProtocolHandler(previous_handler_); |
| 1131 } | 1131 } |
| 1132 } | 1132 } |
| 1133 | 1133 |
| 1134 // TODO(toyoshim): Should share as many code with geolocation as possible. | 1134 class ContentSettingMidiSysExBubbleModel |
| 1135 class ContentSettingMIDISysExBubbleModel | |
| 1136 : public ContentSettingTitleAndLinkModel { | 1135 : public ContentSettingTitleAndLinkModel { |
| 1137 public: | 1136 public: |
| 1138 ContentSettingMIDISysExBubbleModel(Delegate* delegate, | 1137 ContentSettingMidiSysExBubbleModel(Delegate* delegate, |
| 1139 WebContents* web_contents, | 1138 WebContents* web_contents, |
| 1140 Profile* profile, | 1139 Profile* profile, |
| 1141 ContentSettingsType content_type); | 1140 ContentSettingsType content_type); |
| 1142 virtual ~ContentSettingMIDISysExBubbleModel() {} | 1141 virtual ~ContentSettingMidiSysExBubbleModel() {} |
| 1143 | 1142 |
| 1144 private: | 1143 private: |
| 1145 void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id); | 1144 void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id); |
| 1146 void SetDomainsAndCustomLink(); | 1145 void SetDomainsAndCustomLink(); |
| 1147 virtual void OnCustomLinkClicked() OVERRIDE; | 1146 virtual void OnCustomLinkClicked() OVERRIDE; |
| 1148 }; | 1147 }; |
| 1149 | 1148 |
| 1150 ContentSettingMIDISysExBubbleModel::ContentSettingMIDISysExBubbleModel( | 1149 ContentSettingMidiSysExBubbleModel::ContentSettingMidiSysExBubbleModel( |
| 1151 Delegate* delegate, | 1150 Delegate* delegate, |
| 1152 WebContents* web_contents, | 1151 WebContents* web_contents, |
| 1153 Profile* profile, | 1152 Profile* profile, |
| 1154 ContentSettingsType content_type) | 1153 ContentSettingsType content_type) |
| 1155 : ContentSettingTitleAndLinkModel( | 1154 : ContentSettingTitleAndLinkModel( |
| 1156 delegate, web_contents, profile, content_type) { | 1155 delegate, web_contents, profile, content_type) { |
| 1157 DCHECK_EQ(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, content_type); | 1156 DCHECK_EQ(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, content_type); |
| 1158 SetDomainsAndCustomLink(); | 1157 SetDomainsAndCustomLink(); |
| 1159 } | 1158 } |
| 1160 | 1159 |
| 1161 void ContentSettingMIDISysExBubbleModel::MaybeAddDomainList( | 1160 void ContentSettingMidiSysExBubbleModel::MaybeAddDomainList( |
| 1162 const std::set<std::string>& hosts, int title_id) { | 1161 const std::set<std::string>& hosts, int title_id) { |
| 1163 if (!hosts.empty()) { | 1162 if (!hosts.empty()) { |
| 1164 DomainList domain_list; | 1163 DomainList domain_list; |
| 1165 domain_list.title = l10n_util::GetStringUTF8(title_id); | 1164 domain_list.title = l10n_util::GetStringUTF8(title_id); |
| 1166 domain_list.hosts = hosts; | 1165 domain_list.hosts = hosts; |
| 1167 add_domain_list(domain_list); | 1166 add_domain_list(domain_list); |
| 1168 } | 1167 } |
| 1169 } | 1168 } |
| 1170 | 1169 |
| 1171 void ContentSettingMIDISysExBubbleModel::SetDomainsAndCustomLink() { | 1170 void ContentSettingMidiSysExBubbleModel::SetDomainsAndCustomLink() { |
| 1172 TabSpecificContentSettings* content_settings = | 1171 TabSpecificContentSettings* content_settings = |
| 1173 TabSpecificContentSettings::FromWebContents(web_contents()); | 1172 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 1174 const ContentSettingsUsagesState& usages_state = | 1173 const ContentSettingsUsagesState& usages_state = |
| 1175 content_settings->midi_usages_state(); | 1174 content_settings->midi_usages_state(); |
| 1176 ContentSettingsUsagesState::FormattedHostsPerState formatted_hosts_per_state; | 1175 ContentSettingsUsagesState::FormattedHostsPerState formatted_hosts_per_state; |
| 1177 unsigned int tab_state_flags = 0; | 1176 unsigned int tab_state_flags = 0; |
| 1178 usages_state.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags); | 1177 usages_state.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags); |
| 1179 // Divide the tab's current MIDI sysex users into sets according to their | 1178 // Divide the tab's current MIDI sysex users into sets according to their |
| 1180 // permission state. | 1179 // permission state. |
| 1181 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW], | 1180 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW], |
| 1182 IDS_MIDI_SYSEX_BUBBLE_ALLOWED); | 1181 IDS_MIDI_SYSEX_BUBBLE_ALLOWED); |
| 1183 | 1182 |
| 1184 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK], | 1183 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK], |
| 1185 IDS_MIDI_SYSEX_BUBBLE_DENIED); | 1184 IDS_MIDI_SYSEX_BUBBLE_DENIED); |
| 1186 | 1185 |
| 1187 if (tab_state_flags & ContentSettingsUsagesState::TABSTATE_HAS_EXCEPTION) { | 1186 if (tab_state_flags & ContentSettingsUsagesState::TABSTATE_HAS_EXCEPTION) { |
| 1188 set_custom_link(l10n_util::GetStringUTF8( | 1187 set_custom_link(l10n_util::GetStringUTF8( |
| 1189 IDS_MIDI_SYSEX_BUBBLE_CLEAR_LINK)); | 1188 IDS_MIDI_SYSEX_BUBBLE_CLEAR_LINK)); |
| 1190 set_custom_link_enabled(true); | 1189 set_custom_link_enabled(true); |
| 1191 } else if (tab_state_flags & | 1190 } else if (tab_state_flags & |
| 1192 ContentSettingsUsagesState::TABSTATE_HAS_CHANGED) { | 1191 ContentSettingsUsagesState::TABSTATE_HAS_CHANGED) { |
| 1193 set_custom_link(l10n_util::GetStringUTF8( | 1192 set_custom_link(l10n_util::GetStringUTF8( |
| 1194 IDS_MIDI_SYSEX_BUBBLE_REQUIRE_RELOAD_TO_CLEAR)); | 1193 IDS_MIDI_SYSEX_BUBBLE_REQUIRE_RELOAD_TO_CLEAR)); |
| 1195 } | 1194 } |
| 1196 } | 1195 } |
| 1197 | 1196 |
| 1198 void ContentSettingMIDISysExBubbleModel::OnCustomLinkClicked() { | 1197 void ContentSettingMidiSysExBubbleModel::OnCustomLinkClicked() { |
| 1199 if (!web_contents()) | 1198 if (!web_contents()) |
| 1200 return; | 1199 return; |
| 1201 // Reset this embedder's entry to default for each of the requesting | 1200 // Reset this embedder's entry to default for each of the requesting |
| 1202 // origins currently on the page. | 1201 // origins currently on the page. |
| 1203 TabSpecificContentSettings* content_settings = | 1202 TabSpecificContentSettings* content_settings = |
| 1204 TabSpecificContentSettings::FromWebContents(web_contents()); | 1203 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 1205 const ContentSettingsUsagesState::StateMap& state_map = | 1204 const ContentSettingsUsagesState::StateMap& state_map = |
| 1206 content_settings->midi_usages_state().state_map(); | 1205 content_settings->midi_usages_state().state_map(); |
| 1207 HostContentSettingsMap* settings_map = | 1206 HostContentSettingsMap* settings_map = |
| 1208 profile()->GetHostContentSettingsMap(); | 1207 profile()->GetHostContentSettingsMap(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1249 return new ContentSettingMixedScriptBubbleModel(delegate, web_contents, | 1248 return new ContentSettingMixedScriptBubbleModel(delegate, web_contents, |
| 1250 profile, content_type); | 1249 profile, content_type); |
| 1251 } | 1250 } |
| 1252 if (content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { | 1251 if (content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { |
| 1253 ProtocolHandlerRegistry* registry = | 1252 ProtocolHandlerRegistry* registry = |
| 1254 ProtocolHandlerRegistryFactory::GetForProfile(profile); | 1253 ProtocolHandlerRegistryFactory::GetForProfile(profile); |
| 1255 return new ContentSettingRPHBubbleModel(delegate, web_contents, profile, | 1254 return new ContentSettingRPHBubbleModel(delegate, web_contents, profile, |
| 1256 registry, content_type); | 1255 registry, content_type); |
| 1257 } | 1256 } |
| 1258 if (content_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { | 1257 if (content_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { |
| 1259 return new ContentSettingMIDISysExBubbleModel(delegate, web_contents, | 1258 return new ContentSettingMidiSysExBubbleModel(delegate, web_contents, |
| 1260 profile, content_type); | 1259 profile, content_type); |
| 1261 } | 1260 } |
| 1262 return new ContentSettingSingleRadioGroup(delegate, web_contents, profile, | 1261 return new ContentSettingSingleRadioGroup(delegate, web_contents, profile, |
| 1263 content_type); | 1262 content_type); |
| 1264 } | 1263 } |
| 1265 | 1264 |
| 1266 ContentSettingBubbleModel::ContentSettingBubbleModel( | 1265 ContentSettingBubbleModel::ContentSettingBubbleModel( |
| 1267 WebContents* web_contents, | 1266 WebContents* web_contents, |
| 1268 Profile* profile, | 1267 Profile* profile, |
| 1269 ContentSettingsType content_type) | 1268 ContentSettingsType content_type) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1306 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 1305 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
| 1307 DCHECK_EQ(web_contents_, | 1306 DCHECK_EQ(web_contents_, |
| 1308 content::Source<WebContents>(source).ptr()); | 1307 content::Source<WebContents>(source).ptr()); |
| 1309 web_contents_ = NULL; | 1308 web_contents_ = NULL; |
| 1310 } else { | 1309 } else { |
| 1311 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 1310 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
| 1312 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 1311 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
| 1313 profile_ = NULL; | 1312 profile_ = NULL; |
| 1314 } | 1313 } |
| 1315 } | 1314 } |
| OLD | NEW |