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