Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/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/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/blocked_content_container.h" | |
| 10 #include "chrome/browser/content_settings/host_content_settings_map.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 11 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | 10 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
| 12 #include "chrome/browser/metrics/user_metrics.h" | 11 #include "chrome/browser/metrics/user_metrics.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/tab_contents/tab_specific_content_settings.h" | 14 #include "chrome/browser/tab_contents/tab_specific_content_settings.h" |
| 15 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | |
| 16 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate. h" | |
| 16 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" | 17 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" |
| 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
| 17 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 18 #include "content/browser/renderer_host/render_view_host.h" | 20 #include "content/browser/renderer_host/render_view_host.h" |
| 19 #include "content/browser/tab_contents/tab_contents.h" | 21 #include "content/browser/tab_contents/tab_contents.h" |
| 20 #include "content/browser/tab_contents/tab_contents_delegate.h" | 22 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 21 #include "content/common/notification_service.h" | 23 #include "content/common/notification_service.h" |
| 22 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 23 #include "net/base/net_util.h" | 25 #include "net/base/net_util.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 25 | 27 |
| 26 class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel { | 28 class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel { |
| 27 public: | 29 public: |
| 28 ContentSettingTitleAndLinkModel(TabContents* tab_contents, | 30 ContentSettingTitleAndLinkModel(TabContentsWrapper* tab_contents, |
|
stevenjb
2011/04/21 19:03:00
nit: tab_contents_wrapper
| |
| 29 Profile* profile, | 31 Profile* profile, |
| 30 ContentSettingsType content_type) | 32 ContentSettingsType content_type) |
| 31 : ContentSettingBubbleModel(tab_contents, profile, content_type) { | 33 : ContentSettingBubbleModel(tab_contents, profile, content_type) { |
| 32 // Notifications do not have a bubble. | 34 // Notifications do not have a bubble. |
| 33 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 35 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 34 SetBlockedResources(); | 36 SetBlockedResources(); |
| 35 SetTitle(); | 37 SetTitle(); |
| 36 SetManageLink(); | 38 SetManageLink(); |
| 37 } | 39 } |
| 38 | 40 |
| 39 virtual ~ContentSettingTitleAndLinkModel() {} | 41 virtual ~ContentSettingTitleAndLinkModel() {} |
| 40 | 42 |
| 41 private: | 43 private: |
| 42 void SetBlockedResources() { | 44 void SetBlockedResources() { |
| 43 TabSpecificContentSettings* settings = | 45 TabSpecificContentSettings* settings = tab_contents()-> |
| 44 tab_contents()->GetTabSpecificContentSettings(); | 46 tab_contents()->GetTabSpecificContentSettings(); |
| 45 const std::set<std::string>& resources = settings->BlockedResourcesForType( | 47 const std::set<std::string>& resources = settings->BlockedResourcesForType( |
| 46 content_type()); | 48 content_type()); |
| 47 for (std::set<std::string>::const_iterator it = resources.begin(); | 49 for (std::set<std::string>::const_iterator it = resources.begin(); |
| 48 it != resources.end(); ++it) { | 50 it != resources.end(); ++it) { |
| 49 AddBlockedResource(*it); | 51 AddBlockedResource(*it); |
| 50 } | 52 } |
| 51 } | 53 } |
| 52 | 54 |
| 53 void SetTitle() { | 55 void SetTitle() { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 84 }; | 86 }; |
| 85 COMPILE_ASSERT(arraysize(kAccessedTitleIDs) == CONTENT_SETTINGS_NUM_TYPES, | 87 COMPILE_ASSERT(arraysize(kAccessedTitleIDs) == CONTENT_SETTINGS_NUM_TYPES, |
| 86 Need_a_setting_for_every_content_settings_type); | 88 Need_a_setting_for_every_content_settings_type); |
| 87 COMPILE_ASSERT(arraysize(kBlockedTitleIDs) == CONTENT_SETTINGS_NUM_TYPES, | 89 COMPILE_ASSERT(arraysize(kBlockedTitleIDs) == CONTENT_SETTINGS_NUM_TYPES, |
| 88 Need_a_setting_for_every_content_settings_type); | 90 Need_a_setting_for_every_content_settings_type); |
| 89 COMPILE_ASSERT(arraysize(kResourceSpecificBlockedTitleIDs) == | 91 COMPILE_ASSERT(arraysize(kResourceSpecificBlockedTitleIDs) == |
| 90 CONTENT_SETTINGS_NUM_TYPES, | 92 CONTENT_SETTINGS_NUM_TYPES, |
| 91 Need_a_setting_for_every_content_settings_type); | 93 Need_a_setting_for_every_content_settings_type); |
| 92 const int *title_ids = kBlockedTitleIDs; | 94 const int *title_ids = kBlockedTitleIDs; |
| 93 if (tab_contents() && | 95 if (tab_contents() && |
| 94 tab_contents()->GetTabSpecificContentSettings()->IsContentAccessed( | 96 tab_contents()->tab_contents()->GetTabSpecificContentSettings()-> |
| 95 content_type()) && | 97 IsContentAccessed(content_type()) && |
| 96 !tab_contents()->GetTabSpecificContentSettings()->IsContentBlocked( | 98 !tab_contents()->tab_contents()->GetTabSpecificContentSettings()-> |
| 97 content_type())) { | 99 IsContentBlocked(content_type())) { |
| 98 title_ids = kAccessedTitleIDs; | 100 title_ids = kAccessedTitleIDs; |
| 99 } else if (!bubble_content().resource_identifiers.empty()) { | 101 } else if (!bubble_content().resource_identifiers.empty()) { |
| 100 title_ids = kResourceSpecificBlockedTitleIDs; | 102 title_ids = kResourceSpecificBlockedTitleIDs; |
| 101 } | 103 } |
| 102 if (title_ids[content_type()]) | 104 if (title_ids[content_type()]) |
| 103 set_title(l10n_util::GetStringUTF8(title_ids[content_type()])); | 105 set_title(l10n_util::GetStringUTF8(title_ids[content_type()])); |
| 104 } | 106 } |
| 105 | 107 |
| 106 void SetManageLink() { | 108 void SetManageLink() { |
| 107 static const int kLinkIDs[] = { | 109 static const int kLinkIDs[] = { |
| 108 IDS_BLOCKED_COOKIES_LINK, | 110 IDS_BLOCKED_COOKIES_LINK, |
| 109 IDS_BLOCKED_IMAGES_LINK, | 111 IDS_BLOCKED_IMAGES_LINK, |
| 110 IDS_BLOCKED_JAVASCRIPT_LINK, | 112 IDS_BLOCKED_JAVASCRIPT_LINK, |
| 111 IDS_BLOCKED_PLUGINS_LINK, | 113 IDS_BLOCKED_PLUGINS_LINK, |
| 112 IDS_BLOCKED_POPUPS_LINK, | 114 IDS_BLOCKED_POPUPS_LINK, |
| 113 IDS_GEOLOCATION_BUBBLE_MANAGE_LINK, | 115 IDS_GEOLOCATION_BUBBLE_MANAGE_LINK, |
| 114 0, // Notifications do not have a bubble. | 116 0, // Notifications do not have a bubble. |
| 115 0, // Prerender does not have a bubble. | 117 0, // Prerender does not have a bubble. |
| 116 }; | 118 }; |
| 117 COMPILE_ASSERT(arraysize(kLinkIDs) == CONTENT_SETTINGS_NUM_TYPES, | 119 COMPILE_ASSERT(arraysize(kLinkIDs) == CONTENT_SETTINGS_NUM_TYPES, |
| 118 Need_a_setting_for_every_content_settings_type); | 120 Need_a_setting_for_every_content_settings_type); |
| 119 set_manage_link(l10n_util::GetStringUTF8(kLinkIDs[content_type()])); | 121 set_manage_link(l10n_util::GetStringUTF8(kLinkIDs[content_type()])); |
| 120 } | 122 } |
| 121 | 123 |
| 122 virtual void OnManageLinkClicked() { | 124 virtual void OnManageLinkClicked() { |
| 123 if (tab_contents()) | 125 if (tab_contents()) { |
| 124 tab_contents()->delegate()->ShowContentSettingsPage(content_type()); | 126 tab_contents()->tab_contents()->delegate()-> |
| 127 ShowContentSettingsPage(content_type()); | |
| 128 } | |
| 125 } | 129 } |
| 126 }; | 130 }; |
| 127 | 131 |
| 128 class ContentSettingTitleLinkAndCustomModel | 132 class ContentSettingTitleLinkAndCustomModel |
| 129 : public ContentSettingTitleAndLinkModel { | 133 : public ContentSettingTitleAndLinkModel { |
| 130 public: | 134 public: |
| 131 ContentSettingTitleLinkAndCustomModel(TabContents* tab_contents, | 135 ContentSettingTitleLinkAndCustomModel(TabContentsWrapper* tab_contents, |
|
stevenjb
2011/04/21 19:03:00
nit: tab_contents_wrapper
| |
| 132 Profile* profile, | 136 Profile* profile, |
| 133 ContentSettingsType content_type) | 137 ContentSettingsType content_type) |
| 134 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) { | 138 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) { |
| 135 SetCustomLink(); | 139 SetCustomLink(); |
| 136 } | 140 } |
| 137 | 141 |
| 138 virtual ~ContentSettingTitleLinkAndCustomModel() {} | 142 virtual ~ContentSettingTitleLinkAndCustomModel() {} |
| 139 | 143 |
| 140 private: | 144 private: |
| 141 void SetCustomLink() { | 145 void SetCustomLink() { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 155 set_custom_link(l10n_util::GetStringUTF8(kCustomIDs[content_type()])); | 159 set_custom_link(l10n_util::GetStringUTF8(kCustomIDs[content_type()])); |
| 156 } | 160 } |
| 157 | 161 |
| 158 virtual void OnCustomLinkClicked() {} | 162 virtual void OnCustomLinkClicked() {} |
| 159 }; | 163 }; |
| 160 | 164 |
| 161 | 165 |
| 162 class ContentSettingSingleRadioGroup | 166 class ContentSettingSingleRadioGroup |
| 163 : public ContentSettingTitleLinkAndCustomModel { | 167 : public ContentSettingTitleLinkAndCustomModel { |
| 164 public: | 168 public: |
| 165 ContentSettingSingleRadioGroup(TabContents* tab_contents, | 169 ContentSettingSingleRadioGroup(TabContentsWrapper* tab_contents, |
|
stevenjb
2011/04/21 19:03:00
nit: tab_contents_wrapper
| |
| 166 Profile* profile, | 170 Profile* profile, |
| 167 ContentSettingsType content_type) | 171 ContentSettingsType content_type) |
| 168 : ContentSettingTitleLinkAndCustomModel(tab_contents, profile, | 172 : ContentSettingTitleLinkAndCustomModel(tab_contents, profile, |
| 169 content_type), | 173 content_type), |
| 170 block_setting_(CONTENT_SETTING_BLOCK), | 174 block_setting_(CONTENT_SETTING_BLOCK), |
| 171 selected_item_(0) { | 175 selected_item_(0) { |
| 172 SetRadioGroup(); | 176 SetRadioGroup(); |
| 173 } | 177 } |
| 174 | 178 |
| 175 virtual ~ContentSettingSingleRadioGroup() { | 179 virtual ~ContentSettingSingleRadioGroup() { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 194 return selected_item_ != bubble_content().radio_group.default_item; | 198 return selected_item_ != bubble_content().radio_group.default_item; |
| 195 } | 199 } |
| 196 | 200 |
| 197 private: | 201 private: |
| 198 ContentSetting block_setting_; | 202 ContentSetting block_setting_; |
| 199 int selected_item_; | 203 int selected_item_; |
| 200 | 204 |
| 201 // Initialize the radio group by setting the appropriate labels for the | 205 // Initialize the radio group by setting the appropriate labels for the |
| 202 // content type and setting the default value based on the content setting. | 206 // content type and setting the default value based on the content setting. |
| 203 void SetRadioGroup() { | 207 void SetRadioGroup() { |
| 204 GURL url = tab_contents()->GetURL(); | 208 GURL url = tab_contents()->tab_contents()->GetURL(); |
| 205 std::wstring display_host_wide; | 209 std::wstring display_host_wide; |
| 206 net::AppendFormattedHost(url, | 210 net::AppendFormattedHost(url, |
| 207 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages)), | 211 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages)), |
| 208 &display_host_wide, NULL, NULL); | 212 &display_host_wide, NULL, NULL); |
| 209 std::string display_host(WideToUTF8(display_host_wide)); | 213 std::string display_host(WideToUTF8(display_host_wide)); |
| 210 | 214 |
| 211 if (display_host.empty()) | 215 if (display_host.empty()) |
| 212 display_host = url.spec(); | 216 display_host = url.spec(); |
| 213 | 217 |
| 214 const std::set<std::string>& resources = | 218 const std::set<std::string>& resources = |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 setting); | 308 setting); |
| 305 } | 309 } |
| 306 | 310 |
| 307 virtual void OnRadioClicked(int radio_index) { | 311 virtual void OnRadioClicked(int radio_index) { |
| 308 selected_item_ = radio_index; | 312 selected_item_ = radio_index; |
| 309 } | 313 } |
| 310 }; | 314 }; |
| 311 | 315 |
| 312 class ContentSettingCookiesBubbleModel : public ContentSettingSingleRadioGroup { | 316 class ContentSettingCookiesBubbleModel : public ContentSettingSingleRadioGroup { |
| 313 public: | 317 public: |
| 314 ContentSettingCookiesBubbleModel(TabContents* tab_contents, | 318 ContentSettingCookiesBubbleModel(TabContentsWrapper* tab_contents, |
|
stevenjb
2011/04/21 19:03:00
nit: tab_contents_wrapper
| |
| 315 Profile* profile, | 319 Profile* profile, |
| 316 ContentSettingsType content_type) | 320 ContentSettingsType content_type) |
| 317 : ContentSettingSingleRadioGroup(tab_contents, profile, content_type) { | 321 : ContentSettingSingleRadioGroup(tab_contents, profile, content_type) { |
| 318 DCHECK_EQ(CONTENT_SETTINGS_TYPE_COOKIES, content_type); | 322 DCHECK_EQ(CONTENT_SETTINGS_TYPE_COOKIES, content_type); |
| 319 set_custom_link_enabled(true); | 323 set_custom_link_enabled(true); |
| 320 } | 324 } |
| 321 | 325 |
| 322 virtual ~ContentSettingCookiesBubbleModel() { | 326 virtual ~ContentSettingCookiesBubbleModel() { |
| 323 if (settings_changed()) { | 327 if (settings_changed()) { |
| 324 tab_contents()->AddInfoBar( | 328 tab_contents()->tab_contents()->AddInfoBar( |
| 325 new CollectedCookiesInfoBarDelegate(tab_contents())); | 329 new CollectedCookiesInfoBarDelegate(tab_contents()->tab_contents())); |
| 326 } | 330 } |
| 327 } | 331 } |
| 328 | 332 |
| 329 private: | 333 private: |
| 330 virtual void OnCustomLinkClicked() OVERRIDE { | 334 virtual void OnCustomLinkClicked() OVERRIDE { |
| 331 if (tab_contents()) { | 335 if (tab_contents()) { |
| 332 NotificationService::current()->Notify( | 336 NotificationService::current()->Notify( |
| 333 NotificationType::COLLECTED_COOKIES_SHOWN, | 337 NotificationType::COLLECTED_COOKIES_SHOWN, |
| 334 Source<TabSpecificContentSettings>( | 338 Source<TabSpecificContentSettings>( |
| 335 tab_contents()->GetTabSpecificContentSettings()), | 339 tab_contents()->tab_contents()->GetTabSpecificContentSettings()), |
| 336 NotificationService::NoDetails()); | 340 NotificationService::NoDetails()); |
| 337 tab_contents()->delegate()->ShowCollectedCookiesDialog(tab_contents()); | 341 tab_contents()->tab_contents()->delegate()-> |
| 342 ShowCollectedCookiesDialog(tab_contents()->tab_contents()); | |
| 338 } | 343 } |
| 339 } | 344 } |
| 340 }; | 345 }; |
| 341 | 346 |
| 342 class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup { | 347 class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup { |
| 343 public: | 348 public: |
| 344 ContentSettingPluginBubbleModel(TabContents* tab_contents, | 349 ContentSettingPluginBubbleModel(TabContentsWrapper* tab_contents, |
|
stevenjb
2011/04/21 19:03:00
nit: tab_contents_wrapper
| |
| 345 Profile* profile, | 350 Profile* profile, |
| 346 ContentSettingsType content_type) | 351 ContentSettingsType content_type) |
| 347 : ContentSettingSingleRadioGroup(tab_contents, profile, content_type) { | 352 : ContentSettingSingleRadioGroup(tab_contents, profile, content_type) { |
| 348 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS); | 353 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS); |
| 349 set_custom_link_enabled(tab_contents && tab_contents-> | 354 set_custom_link_enabled(tab_contents && tab_contents->tab_contents()-> |
| 350 GetTabSpecificContentSettings()->load_plugins_link_enabled()); | 355 GetTabSpecificContentSettings()->load_plugins_link_enabled()); |
| 351 } | 356 } |
| 352 | 357 |
| 353 virtual ~ContentSettingPluginBubbleModel() {} | 358 virtual ~ContentSettingPluginBubbleModel() {} |
| 354 | 359 |
| 355 private: | 360 private: |
| 356 virtual void OnCustomLinkClicked() OVERRIDE { | 361 virtual void OnCustomLinkClicked() OVERRIDE { |
| 357 UserMetrics::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble")); | 362 UserMetrics::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble")); |
| 358 DCHECK(tab_contents()); | 363 DCHECK(tab_contents()); |
| 359 tab_contents()->render_view_host()->LoadBlockedPlugins(); | 364 tab_contents()->render_view_host()->LoadBlockedPlugins(); |
| 360 set_custom_link_enabled(false); | 365 set_custom_link_enabled(false); |
| 361 tab_contents()->GetTabSpecificContentSettings()-> | 366 tab_contents()->tab_contents()->GetTabSpecificContentSettings()-> |
| 362 set_load_plugins_link_enabled(false); | 367 set_load_plugins_link_enabled(false); |
| 363 } | 368 } |
| 364 }; | 369 }; |
| 365 | 370 |
| 366 class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup { | 371 class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup { |
| 367 public: | 372 public: |
| 368 ContentSettingPopupBubbleModel(TabContents* tab_contents, | 373 ContentSettingPopupBubbleModel(TabContentsWrapper* tab_contents, |
|
stevenjb
2011/04/21 19:03:00
nit: tab_contents_wrapper
| |
| 369 Profile* profile, | 374 Profile* profile, |
| 370 ContentSettingsType content_type) | 375 ContentSettingsType content_type) |
| 371 : ContentSettingSingleRadioGroup(tab_contents, profile, content_type) { | 376 : ContentSettingSingleRadioGroup(tab_contents, profile, content_type) { |
| 372 SetPopups(); | 377 SetPopups(); |
| 373 } | 378 } |
| 374 | 379 |
| 375 virtual ~ContentSettingPopupBubbleModel() {} | 380 virtual ~ContentSettingPopupBubbleModel() {} |
| 376 | 381 |
| 377 private: | 382 private: |
| 378 void SetPopups() { | 383 void SetPopups() { |
| 379 // check for crbug.com/53176 | 384 std::vector<TabContentsWrapper*> blocked_contents; |
| 380 if (!tab_contents()->blocked_content_container()) | 385 tab_contents()->blocked_content_tab_helper()-> |
| 381 return; | 386 GetBlockedContents(&blocked_contents); |
| 382 std::vector<TabContents*> blocked_contents; | 387 for (std::vector<TabContentsWrapper*>::const_iterator |
| 383 tab_contents()->blocked_content_container()->GetBlockedContents( | 388 i = blocked_contents.begin(); i != blocked_contents.end(); ++i) { |
| 384 &blocked_contents); | 389 std::string title(UTF16ToUTF8((*i)->tab_contents()->GetTitle())); |
| 385 for (std::vector<TabContents*>::const_iterator | |
| 386 i(blocked_contents.begin()); i != blocked_contents.end(); ++i) { | |
| 387 std::string title(UTF16ToUTF8((*i)->GetTitle())); | |
| 388 // The popup may not have committed a load yet, in which case it won't | 390 // The popup may not have committed a load yet, in which case it won't |
| 389 // have a URL or title. | 391 // have a URL or title. |
| 390 if (title.empty()) | 392 if (title.empty()) |
| 391 title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE); | 393 title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE); |
| 392 PopupItem popup_item; | 394 PopupItem popup_item; |
| 393 popup_item.title = title; | 395 popup_item.title = title; |
| 394 popup_item.bitmap = (*i)->GetFavicon(); | 396 popup_item.bitmap = (*i)->tab_contents()->GetFavicon(); |
| 395 popup_item.tab_contents = (*i); | 397 popup_item.tab_contents = (*i); |
| 396 add_popup(popup_item); | 398 add_popup(popup_item); |
| 397 } | 399 } |
| 398 } | 400 } |
| 399 | 401 |
| 400 virtual void OnPopupClicked(int index) { | 402 virtual void OnPopupClicked(int index) { |
| 401 if (tab_contents() && tab_contents()->blocked_content_container()) { | 403 if (tab_contents()) { |
| 402 tab_contents()->blocked_content_container()->LaunchForContents( | 404 tab_contents()->blocked_content_tab_helper()-> |
| 403 bubble_content().popup_items[index].tab_contents); | 405 LaunchForContents(bubble_content().popup_items[index].tab_contents); |
| 404 } | 406 } |
| 405 } | 407 } |
| 406 }; | 408 }; |
| 407 | 409 |
| 408 class ContentSettingDomainListBubbleModel | 410 class ContentSettingDomainListBubbleModel |
| 409 : public ContentSettingTitleAndLinkModel { | 411 : public ContentSettingTitleAndLinkModel { |
| 410 public: | 412 public: |
| 411 ContentSettingDomainListBubbleModel(TabContents* tab_contents, | 413 ContentSettingDomainListBubbleModel(TabContentsWrapper* tab_contents, |
|
stevenjb
2011/04/21 19:03:00
nit: tab_contents_wrapper
| |
| 412 Profile* profile, | 414 Profile* profile, |
| 413 ContentSettingsType content_type) | 415 ContentSettingsType content_type) |
| 414 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) { | 416 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) { |
| 415 DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) << | 417 DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) << |
| 416 "SetDomains currently only supports geolocation content type"; | 418 "SetDomains currently only supports geolocation content type"; |
| 417 SetDomainsAndCustomLink(); | 419 SetDomainsAndCustomLink(); |
| 418 } | 420 } |
| 419 | 421 |
| 420 virtual ~ContentSettingDomainListBubbleModel() {} | 422 virtual ~ContentSettingDomainListBubbleModel() {} |
| 421 | 423 |
| 422 private: | 424 private: |
| 423 void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id) { | 425 void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id) { |
| 424 if (!hosts.empty()) { | 426 if (!hosts.empty()) { |
| 425 DomainList domain_list; | 427 DomainList domain_list; |
| 426 domain_list.title = l10n_util::GetStringUTF8(title_id); | 428 domain_list.title = l10n_util::GetStringUTF8(title_id); |
| 427 domain_list.hosts = hosts; | 429 domain_list.hosts = hosts; |
| 428 add_domain_list(domain_list); | 430 add_domain_list(domain_list); |
| 429 } | 431 } |
| 430 } | 432 } |
| 431 void SetDomainsAndCustomLink() { | 433 void SetDomainsAndCustomLink() { |
| 432 TabSpecificContentSettings* content_settings = | 434 TabSpecificContentSettings* content_settings = |
| 433 tab_contents()->GetTabSpecificContentSettings(); | 435 tab_contents()->tab_contents()->GetTabSpecificContentSettings(); |
| 434 const GeolocationSettingsState& settings = | 436 const GeolocationSettingsState& settings = |
| 435 content_settings->geolocation_settings_state(); | 437 content_settings->geolocation_settings_state(); |
| 436 GeolocationSettingsState::FormattedHostsPerState formatted_hosts_per_state; | 438 GeolocationSettingsState::FormattedHostsPerState formatted_hosts_per_state; |
| 437 unsigned int tab_state_flags = 0; | 439 unsigned int tab_state_flags = 0; |
| 438 settings.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags); | 440 settings.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags); |
| 439 // Divide the tab's current geolocation users into sets according to their | 441 // Divide the tab's current geolocation users into sets according to their |
| 440 // permission state. | 442 // permission state. |
| 441 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW], | 443 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW], |
| 442 IDS_GEOLOCATION_BUBBLE_SECTION_ALLOWED); | 444 IDS_GEOLOCATION_BUBBLE_SECTION_ALLOWED); |
| 443 | 445 |
| 444 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK], | 446 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK], |
| 445 IDS_GEOLOCATION_BUBBLE_SECTION_DENIED); | 447 IDS_GEOLOCATION_BUBBLE_SECTION_DENIED); |
| 446 | 448 |
| 447 if (tab_state_flags & GeolocationSettingsState::TABSTATE_HAS_EXCEPTION) { | 449 if (tab_state_flags & GeolocationSettingsState::TABSTATE_HAS_EXCEPTION) { |
| 448 set_custom_link(l10n_util::GetStringUTF8( | 450 set_custom_link(l10n_util::GetStringUTF8( |
| 449 IDS_GEOLOCATION_BUBBLE_CLEAR_LINK)); | 451 IDS_GEOLOCATION_BUBBLE_CLEAR_LINK)); |
| 450 set_custom_link_enabled(true); | 452 set_custom_link_enabled(true); |
| 451 } else if (tab_state_flags & | 453 } else if (tab_state_flags & |
| 452 GeolocationSettingsState::TABSTATE_HAS_CHANGED) { | 454 GeolocationSettingsState::TABSTATE_HAS_CHANGED) { |
| 453 set_custom_link(l10n_util::GetStringUTF8( | 455 set_custom_link(l10n_util::GetStringUTF8( |
| 454 IDS_GEOLOCATION_BUBBLE_REQUIRE_RELOAD_TO_CLEAR)); | 456 IDS_GEOLOCATION_BUBBLE_REQUIRE_RELOAD_TO_CLEAR)); |
| 455 } | 457 } |
| 456 } | 458 } |
| 457 virtual void OnCustomLinkClicked() OVERRIDE { | 459 virtual void OnCustomLinkClicked() OVERRIDE { |
| 458 if (!tab_contents()) | 460 if (!tab_contents()) |
| 459 return; | 461 return; |
| 460 // Reset this embedder's entry to default for each of the requesting | 462 // Reset this embedder's entry to default for each of the requesting |
| 461 // origins currently on the page. | 463 // origins currently on the page. |
| 462 const GURL& embedder_url = tab_contents()->GetURL(); | 464 const GURL& embedder_url = tab_contents()->tab_contents()->GetURL(); |
| 463 TabSpecificContentSettings* content_settings = | 465 TabSpecificContentSettings* content_settings = |
| 464 tab_contents()->GetTabSpecificContentSettings(); | 466 tab_contents()->tab_contents()->GetTabSpecificContentSettings(); |
| 465 const GeolocationSettingsState::StateMap& state_map = | 467 const GeolocationSettingsState::StateMap& state_map = |
| 466 content_settings->geolocation_settings_state().state_map(); | 468 content_settings->geolocation_settings_state().state_map(); |
| 467 GeolocationContentSettingsMap* settings_map = | 469 GeolocationContentSettingsMap* settings_map = |
| 468 profile()->GetGeolocationContentSettingsMap(); | 470 profile()->GetGeolocationContentSettingsMap(); |
| 469 for (GeolocationSettingsState::StateMap::const_iterator it = | 471 for (GeolocationSettingsState::StateMap::const_iterator it = |
| 470 state_map.begin(); it != state_map.end(); ++it) { | 472 state_map.begin(); it != state_map.end(); ++it) { |
| 471 settings_map->SetContentSetting(it->first, embedder_url, | 473 settings_map->SetContentSetting(it->first, embedder_url, |
| 472 CONTENT_SETTING_DEFAULT); | 474 CONTENT_SETTING_DEFAULT); |
| 473 } | 475 } |
| 474 } | 476 } |
| 475 }; | 477 }; |
| 476 | 478 |
| 477 // static | 479 // static |
| 478 ContentSettingBubbleModel* | 480 ContentSettingBubbleModel* |
| 479 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 481 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 480 TabContents* tab_contents, | 482 TabContentsWrapper* tab_contents, |
|
stevenjb
2011/04/21 19:03:00
nit: tab_contents_wrapper
| |
| 481 Profile* profile, | 483 Profile* profile, |
| 482 ContentSettingsType content_type) { | 484 ContentSettingsType content_type) { |
| 483 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { | 485 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { |
| 484 return new ContentSettingCookiesBubbleModel(tab_contents, profile, | 486 return new ContentSettingCookiesBubbleModel(tab_contents, profile, |
| 485 content_type); | 487 content_type); |
| 486 } | 488 } |
| 487 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { | 489 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { |
| 488 return new ContentSettingPopupBubbleModel(tab_contents, profile, | 490 return new ContentSettingPopupBubbleModel(tab_contents, profile, |
| 489 content_type); | 491 content_type); |
| 490 } | 492 } |
| 491 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 493 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| 492 return new ContentSettingDomainListBubbleModel(tab_contents, profile, | 494 return new ContentSettingDomainListBubbleModel(tab_contents, profile, |
| 493 content_type); | 495 content_type); |
| 494 } | 496 } |
| 495 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { | 497 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
| 496 return new ContentSettingPluginBubbleModel(tab_contents, profile, | 498 return new ContentSettingPluginBubbleModel(tab_contents, profile, |
| 497 content_type); | 499 content_type); |
| 498 } | 500 } |
| 499 return new ContentSettingSingleRadioGroup(tab_contents, profile, | 501 return new ContentSettingSingleRadioGroup(tab_contents, profile, |
| 500 content_type); | 502 content_type); |
| 501 } | 503 } |
| 502 | 504 |
| 503 ContentSettingBubbleModel::ContentSettingBubbleModel( | 505 ContentSettingBubbleModel::ContentSettingBubbleModel( |
| 504 TabContents* tab_contents, | 506 TabContentsWrapper* tab_contents, |
|
stevenjb
2011/04/21 19:03:00
nit: tab_contents_wrapper
| |
| 505 Profile* profile, | 507 Profile* profile, |
| 506 ContentSettingsType content_type) | 508 ContentSettingsType content_type) |
| 507 : tab_contents_(tab_contents), | 509 : tab_contents_(tab_contents), |
| 508 profile_(profile), | 510 profile_(profile), |
| 509 content_type_(content_type) { | 511 content_type_(content_type) { |
| 510 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, | 512 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, |
| 511 Source<TabContents>(tab_contents)); | 513 Source<TabContents>(tab_contents->tab_contents())); |
| 512 } | 514 } |
| 513 | 515 |
| 514 ContentSettingBubbleModel::~ContentSettingBubbleModel() { | 516 ContentSettingBubbleModel::~ContentSettingBubbleModel() { |
| 515 } | 517 } |
| 516 | 518 |
| 517 ContentSettingBubbleModel::RadioGroup::RadioGroup() : default_item(0) {} | 519 ContentSettingBubbleModel::RadioGroup::RadioGroup() : default_item(0) {} |
| 518 | 520 |
| 519 ContentSettingBubbleModel::RadioGroup::~RadioGroup() {} | 521 ContentSettingBubbleModel::RadioGroup::~RadioGroup() {} |
| 520 | 522 |
| 521 ContentSettingBubbleModel::DomainList::DomainList() {} | 523 ContentSettingBubbleModel::DomainList::DomainList() {} |
| 522 | 524 |
| 523 ContentSettingBubbleModel::DomainList::~DomainList() {} | 525 ContentSettingBubbleModel::DomainList::~DomainList() {} |
| 524 | 526 |
| 525 ContentSettingBubbleModel::BubbleContent::BubbleContent() | 527 ContentSettingBubbleModel::BubbleContent::BubbleContent() |
| 526 : custom_link_enabled(false) { | 528 : custom_link_enabled(false) { |
| 527 } | 529 } |
| 528 | 530 |
| 529 ContentSettingBubbleModel::BubbleContent::~BubbleContent() {} | 531 ContentSettingBubbleModel::BubbleContent::~BubbleContent() {} |
| 530 | 532 |
| 531 | 533 |
| 532 void ContentSettingBubbleModel::AddBlockedResource( | 534 void ContentSettingBubbleModel::AddBlockedResource( |
| 533 const std::string& resource_identifier) { | 535 const std::string& resource_identifier) { |
| 534 bubble_content_.resource_identifiers.insert(resource_identifier); | 536 bubble_content_.resource_identifiers.insert(resource_identifier); |
| 535 } | 537 } |
| 536 | 538 |
| 537 void ContentSettingBubbleModel::Observe(NotificationType type, | 539 void ContentSettingBubbleModel::Observe(NotificationType type, |
| 538 const NotificationSource& source, | 540 const NotificationSource& source, |
| 539 const NotificationDetails& details) { | 541 const NotificationDetails& details) { |
| 540 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); | 542 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); |
| 541 DCHECK(source == Source<TabContents>(tab_contents_)); | 543 DCHECK(source == Source<TabContents>(tab_contents_->tab_contents())); |
| 542 tab_contents_ = NULL; | 544 tab_contents_ = NULL; |
| 543 } | 545 } |
| OLD | NEW |