| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/content_setting_bubble_model.h" | 5 #include "chrome/browser/content_setting_bubble_model.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "chrome/browser/blocked_popup_container.h" | 8 #include "chrome/browser/blocked_popup_container.h" |
| 9 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | |
| 10 #include "chrome/browser/host_content_settings_map.h" | 9 #include "chrome/browser/host_content_settings_map.h" |
| 11 #include "chrome/browser/pref_service.h" | 10 #include "chrome/browser/pref_service.h" |
| 12 #include "chrome/browser/profile.h" | 11 #include "chrome/browser/profile.h" |
| 13 #include "chrome/browser/tab_contents/tab_contents.h" | 12 #include "chrome/browser/tab_contents/tab_contents.h" |
| 14 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 13 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
| 15 #include "chrome/common/notification_service.h" | 14 #include "chrome/common/notification_service.h" |
| 16 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 17 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 18 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
| 19 | 18 |
| 20 class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel { | 19 class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel { |
| 21 public: | 20 public: |
| 22 ContentSettingTitleAndLinkModel(TabContents* tab_contents, Profile* profile, | 21 ContentSettingTitleAndLinkModel(TabContents* tab_contents, Profile* profile, |
| 23 ContentSettingsType content_type) | 22 ContentSettingsType content_type) |
| 24 : ContentSettingBubbleModel(tab_contents, profile, content_type) { | 23 : ContentSettingBubbleModel(tab_contents, profile, content_type) { |
| 25 SetTitle(); | 24 SetTitle(); |
| 26 SetManageLink(); | 25 SetManageLink(); |
| 27 } | 26 } |
| 28 | 27 |
| 29 private: | 28 private: |
| 30 void SetTitle() { | 29 void SetTitle() { |
| 31 static const int kTitleIDs[CONTENT_SETTINGS_NUM_TYPES] = { | 30 static const int kTitleIDs[CONTENT_SETTINGS_NUM_TYPES] = { |
| 32 IDS_BLOCKED_COOKIES_TITLE, | 31 IDS_BLOCKED_COOKIES_TITLE, |
| 33 IDS_BLOCKED_IMAGES_TITLE, | 32 IDS_BLOCKED_IMAGES_TITLE, |
| 34 IDS_BLOCKED_JAVASCRIPT_TITLE, | 33 IDS_BLOCKED_JAVASCRIPT_TITLE, |
| 35 IDS_BLOCKED_PLUGINS_TITLE, | 34 IDS_BLOCKED_PLUGINS_TITLE, |
| 36 IDS_BLOCKED_POPUPS_TITLE, | 35 IDS_BLOCKED_POPUPS_TITLE, |
| 37 0, // Geolocation does not have an overall title. | |
| 38 }; | 36 }; |
| 39 if (kTitleIDs[content_type()]) | 37 set_title(l10n_util::GetStringUTF8(kTitleIDs[content_type()])); |
| 40 set_title(l10n_util::GetStringUTF8(kTitleIDs[content_type()])); | |
| 41 } | 38 } |
| 42 | 39 |
| 43 void SetManageLink() { | 40 void SetManageLink() { |
| 44 static const int kLinkIDs[CONTENT_SETTINGS_NUM_TYPES] = { | 41 static const int kLinkIDs[CONTENT_SETTINGS_NUM_TYPES] = { |
| 45 IDS_BLOCKED_COOKIES_LINK, | 42 IDS_BLOCKED_COOKIES_LINK, |
| 46 IDS_BLOCKED_IMAGES_LINK, | 43 IDS_BLOCKED_IMAGES_LINK, |
| 47 IDS_BLOCKED_JAVASCRIPT_LINK, | 44 IDS_BLOCKED_JAVASCRIPT_LINK, |
| 48 IDS_BLOCKED_PLUGINS_LINK, | 45 IDS_BLOCKED_PLUGINS_LINK, |
| 49 IDS_BLOCKED_POPUPS_LINK, | 46 IDS_BLOCKED_POPUPS_LINK, |
| 50 IDS_GEOLOCATION_BUBBLE_MANAGE_LINK, | |
| 51 }; | 47 }; |
| 52 set_manage_link(l10n_util::GetStringUTF8(kLinkIDs[content_type()])); | 48 set_manage_link(l10n_util::GetStringUTF8(kLinkIDs[content_type()])); |
| 53 } | 49 } |
| 54 | 50 |
| 55 virtual void OnManageLinkClicked() { | 51 virtual void OnManageLinkClicked() { |
| 56 if (tab_contents()) | 52 if (tab_contents()) |
| 57 tab_contents()->delegate()->ShowContentSettingsWindow(content_type()); | 53 tab_contents()->delegate()->ShowContentSettingsWindow(content_type()); |
| 58 } | 54 } |
| 59 }; | 55 }; |
| 60 | 56 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 77 | 73 |
| 78 RadioGroup radio_group; | 74 RadioGroup radio_group; |
| 79 radio_group.host = url.host(); | 75 radio_group.host = url.host(); |
| 80 | 76 |
| 81 static const int kAllowIDs[CONTENT_SETTINGS_NUM_TYPES] = { | 77 static const int kAllowIDs[CONTENT_SETTINGS_NUM_TYPES] = { |
| 82 0, // We don't manage cookies here. | 78 0, // We don't manage cookies here. |
| 83 IDS_BLOCKED_IMAGES_UNBLOCK, | 79 IDS_BLOCKED_IMAGES_UNBLOCK, |
| 84 IDS_BLOCKED_JAVASCRIPT_UNBLOCK, | 80 IDS_BLOCKED_JAVASCRIPT_UNBLOCK, |
| 85 IDS_BLOCKED_PLUGINS_UNBLOCK, | 81 IDS_BLOCKED_PLUGINS_UNBLOCK, |
| 86 IDS_BLOCKED_POPUPS_UNBLOCK, | 82 IDS_BLOCKED_POPUPS_UNBLOCK, |
| 87 0, // We don't manage geolocation here. | |
| 88 }; | 83 }; |
| 89 std::string radio_allow_label; | 84 std::string radio_allow_label; |
| 90 radio_allow_label = l10n_util::GetStringFUTF8( | 85 radio_allow_label = l10n_util::GetStringFUTF8( |
| 91 kAllowIDs[content_type()], UTF8ToUTF16(display_host)); | 86 kAllowIDs[content_type()], UTF8ToUTF16(display_host)); |
| 92 | 87 |
| 93 static const int kBlockIDs[CONTENT_SETTINGS_NUM_TYPES] = { | 88 static const int kBlockIDs[CONTENT_SETTINGS_NUM_TYPES] = { |
| 94 0, // We don't manage cookies here. | 89 0, // We don't manage cookies here. |
| 95 IDS_BLOCKED_IMAGES_NO_ACTION, | 90 IDS_BLOCKED_IMAGES_NO_ACTION, |
| 96 IDS_BLOCKED_JAVASCRIPT_NO_ACTION, | 91 IDS_BLOCKED_JAVASCRIPT_NO_ACTION, |
| 97 IDS_BLOCKED_PLUGINS_NO_ACTION, | 92 IDS_BLOCKED_PLUGINS_NO_ACTION, |
| 98 IDS_BLOCKED_POPUPS_NO_ACTION, | 93 IDS_BLOCKED_POPUPS_NO_ACTION, |
| 99 0, // We don't manage geolocation here. | |
| 100 }; | 94 }; |
| 101 std::string radio_block_label; | 95 std::string radio_block_label; |
| 102 radio_block_label = l10n_util::GetStringFUTF8( | 96 radio_block_label = l10n_util::GetStringFUTF8( |
| 103 kBlockIDs[content_type()], UTF8ToUTF16(display_host)); | 97 kBlockIDs[content_type()], UTF8ToUTF16(display_host)); |
| 104 | 98 |
| 105 radio_group.radio_items.push_back(radio_allow_label); | 99 radio_group.radio_items.push_back(radio_allow_label); |
| 106 radio_group.radio_items.push_back(radio_block_label); | 100 radio_group.radio_items.push_back(radio_block_label); |
| 107 radio_group.default_item = | 101 radio_group.default_item = |
| 108 profile()->GetHostContentSettingsMap()->GetContentSetting(url, | 102 profile()->GetHostContentSettingsMap()->GetContentSetting(url, |
| 109 content_type()) == CONTENT_SETTING_ALLOW ? 0 : 1; | 103 content_type()) == CONTENT_SETTING_ALLOW ? 0 : 1; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } | 142 } |
| 149 | 143 |
| 150 virtual void OnPopupClicked(int index) { | 144 virtual void OnPopupClicked(int index) { |
| 151 if (tab_contents() && tab_contents()->blocked_popup_container()) { | 145 if (tab_contents() && tab_contents()->blocked_popup_container()) { |
| 152 tab_contents()->blocked_popup_container()->LaunchPopupForContents( | 146 tab_contents()->blocked_popup_container()->LaunchPopupForContents( |
| 153 bubble_content().popup_items[index].tab_contents); | 147 bubble_content().popup_items[index].tab_contents); |
| 154 } | 148 } |
| 155 } | 149 } |
| 156 }; | 150 }; |
| 157 | 151 |
| 158 class ContentSettingDomainListBubbleModel | |
| 159 : public ContentSettingTitleAndLinkModel { | |
| 160 public: | |
| 161 ContentSettingDomainListBubbleModel(TabContents* tab_contents, | |
| 162 Profile* profile, | |
| 163 ContentSettingsType content_type) | |
| 164 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) { | |
| 165 DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) << | |
| 166 "SetDomains currently only supports geolocation content type"; | |
| 167 SetDomains(); | |
| 168 SetClearLink(); | |
| 169 } | |
| 170 | |
| 171 private: | |
| 172 void MaybeAddDomainList(DomainList* domain_list, int title_id) { | |
| 173 if (!domain_list->hosts.empty()) { | |
| 174 domain_list->title = l10n_util::GetStringUTF8(title_id); | |
| 175 add_domain_list(*domain_list); | |
| 176 } | |
| 177 } | |
| 178 void SetDomains() { | |
| 179 const TabContents::GeolocationContentSettings& settings = | |
| 180 tab_contents()->geolocation_content_settings(); | |
| 181 | |
| 182 // Divide the tab's current geolocation users into sets according to their | |
| 183 // permission state. | |
| 184 DomainList domain_lists[CONTENT_SETTING_NUM_SETTINGS]; | |
| 185 for (TabContents::GeolocationContentSettings::const_iterator it = | |
| 186 settings.begin(); it != settings.end(); ++it) { | |
| 187 domain_lists[it->second].hosts.push_back(it->first); | |
| 188 } | |
| 189 MaybeAddDomainList(&domain_lists[CONTENT_SETTING_ALLOW], | |
| 190 IDS_GEOLOCATION_BUBBLE_SECTION_ALLOWED); | |
| 191 MaybeAddDomainList(&domain_lists[CONTENT_SETTING_BLOCK], | |
| 192 IDS_GEOLOCATION_BUBBLE_SECTION_DENIED); | |
| 193 } | |
| 194 void SetClearLink() { | |
| 195 set_clear_link(l10n_util::GetStringUTF8(IDS_GEOLOCATION_BUBBLE_CLEAR_LINK)); | |
| 196 } | |
| 197 virtual void OnClearLinkClicked() { | |
| 198 if (!tab_contents()) | |
| 199 return; | |
| 200 // Reset this embedder's entry to default for each of the requesting | |
| 201 // origins currently on the page. | |
| 202 const GURL& embedder_url = tab_contents()->GetURL(); | |
| 203 const TabContents::GeolocationContentSettings& settings = | |
| 204 tab_contents()->geolocation_content_settings(); | |
| 205 GeolocationContentSettingsMap* settings_map = | |
| 206 profile()->GetGeolocationContentSettingsMap(); | |
| 207 for (TabContents::GeolocationContentSettings::const_iterator it = | |
| 208 settings.begin(); it != settings.end(); ++it) { | |
| 209 settings_map->SetContentSetting(it->first, embedder_url, | |
| 210 CONTENT_SETTING_DEFAULT); | |
| 211 } | |
| 212 } | |
| 213 }; | |
| 214 | |
| 215 // static | 152 // static |
| 216 ContentSettingBubbleModel* | 153 ContentSettingBubbleModel* |
| 217 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 154 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 218 TabContents* tab_contents, | 155 TabContents* tab_contents, |
| 219 Profile* profile, | 156 Profile* profile, |
| 220 ContentSettingsType content_type) { | 157 ContentSettingsType content_type) { |
| 221 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { | 158 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { |
| 222 return new ContentSettingTitleAndLinkModel(tab_contents, profile, | 159 return new ContentSettingTitleAndLinkModel(tab_contents, profile, |
| 223 content_type); | 160 content_type); |
| 224 } | 161 } |
| 225 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { | 162 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { |
| 226 return new ContentSettingPopupBubbleModel(tab_contents, profile, | 163 return new ContentSettingPopupBubbleModel(tab_contents, profile, |
| 227 content_type); | 164 content_type); |
| 228 } | 165 } |
| 229 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | |
| 230 return new ContentSettingDomainListBubbleModel(tab_contents, profile, | |
| 231 content_type); | |
| 232 } | |
| 233 return new ContentSettingSingleRadioGroup(tab_contents, profile, | 166 return new ContentSettingSingleRadioGroup(tab_contents, profile, |
| 234 content_type); | 167 content_type); |
| 235 } | 168 } |
| 236 | 169 |
| 237 ContentSettingBubbleModel::ContentSettingBubbleModel( | 170 ContentSettingBubbleModel::ContentSettingBubbleModel( |
| 238 TabContents* tab_contents, Profile* profile, | 171 TabContents* tab_contents, Profile* profile, |
| 239 ContentSettingsType content_type) | 172 ContentSettingsType content_type) |
| 240 : tab_contents_(tab_contents), profile_(profile), | 173 : tab_contents_(tab_contents), profile_(profile), |
| 241 content_type_(content_type) { | 174 content_type_(content_type) { |
| 242 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, | 175 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, |
| 243 Source<TabContents>(tab_contents)); | 176 Source<TabContents>(tab_contents)); |
| 244 } | 177 } |
| 245 | 178 |
| 246 ContentSettingBubbleModel::~ContentSettingBubbleModel() { | 179 ContentSettingBubbleModel::~ContentSettingBubbleModel() { |
| 247 } | 180 } |
| 248 | 181 |
| 249 void ContentSettingBubbleModel::Observe(NotificationType type, | 182 void ContentSettingBubbleModel::Observe(NotificationType type, |
| 250 const NotificationSource& source, | 183 const NotificationSource& source, |
| 251 const NotificationDetails& details) { | 184 const NotificationDetails& details) { |
| 252 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); | 185 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); |
| 253 DCHECK(source == Source<TabContents>(tab_contents_)); | 186 DCHECK(source == Source<TabContents>(tab_contents_)); |
| 254 tab_contents_ = NULL; | 187 tab_contents_ = NULL; |
| 255 } | 188 } |
| OLD | NEW |