Chromium Code Reviews| 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 "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/blocked_content_container.h" | 10 #include "chrome/browser/blocked_content_container.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) { | 127 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) { |
| 128 SetInfoLink(); | 128 SetInfoLink(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 private: | 131 private: |
| 132 void SetInfoLink() { | 132 void SetInfoLink() { |
| 133 static const int kInfoIDs[] = { | 133 static const int kInfoIDs[] = { |
| 134 IDS_BLOCKED_COOKIES_INFO, | 134 IDS_BLOCKED_COOKIES_INFO, |
| 135 0, // Images do not have an info link. | 135 0, // Images do not have an info link. |
| 136 0, // Javascript doesn't have an info link. | 136 0, // Javascript doesn't have an info link. |
| 137 0, // Plugins do not have an info link. | 137 IDS_BLOCKED_PLUGINS_LOAD_ALL, |
| 138 0, // Popups do not have an info link. | 138 0, // Popups do not have an info link. |
| 139 0, // Geolocation does not have an info link. | 139 0, // Geolocation links are set within that class. |
| 140 0, // Notifications do not have a bubble. | 140 0, // Notifications do not have a bubble. |
| 141 }; | 141 }; |
| 142 COMPILE_ASSERT(arraysize(kInfoIDs) == CONTENT_SETTINGS_NUM_TYPES, | 142 COMPILE_ASSERT(arraysize(kInfoIDs) == CONTENT_SETTINGS_NUM_TYPES, |
| 143 Need_a_setting_for_every_content_settings_type); | 143 Need_a_setting_for_every_content_settings_type); |
| 144 if (kInfoIDs[content_type()]) | 144 if (kInfoIDs[content_type()]) |
| 145 set_info_link(l10n_util::GetStringUTF8(kInfoIDs[content_type()])); | 145 set_info_link(l10n_util::GetStringUTF8(kInfoIDs[content_type()])); |
| 146 } | 146 } |
| 147 | 147 |
| 148 virtual void OnInfoLinkClicked() { | 148 virtual void OnInfoLinkClicked() { |
| 149 DCHECK(content_type() == CONTENT_SETTINGS_TYPE_COOKIES); | 149 DCHECK(content_type() == CONTENT_SETTINGS_TYPE_COOKIES); |
|
Peter Kasting
2010/12/07 17:53:00
Nit: Now that we've combined all these, it seems w
| |
| 150 if (tab_contents()) { | 150 if (tab_contents()) { |
| 151 NotificationService::current()->Notify( | 151 NotificationService::current()->Notify( |
| 152 NotificationType::COLLECTED_COOKIES_SHOWN, | 152 NotificationType::COLLECTED_COOKIES_SHOWN, |
| 153 Source<TabSpecificContentSettings>( | 153 Source<TabSpecificContentSettings>( |
| 154 tab_contents()->GetTabSpecificContentSettings()), | 154 tab_contents()->GetTabSpecificContentSettings()), |
| 155 NotificationService::NoDetails()); | 155 NotificationService::NoDetails()); |
| 156 tab_contents()->delegate()->ShowCollectedCookiesDialog(tab_contents()); | 156 tab_contents()->delegate()->ShowCollectedCookiesDialog(tab_contents()); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 }; | 159 }; |
| 160 | 160 |
| 161 | 161 |
| 162 class ContentSettingSingleRadioGroup : public ContentSettingTitleAndLinkModel { | 162 class ContentSettingSingleRadioGroup |
| 163 : public ContentSettingTitleLinkAndInfoModel { | |
| 163 public: | 164 public: |
| 164 ContentSettingSingleRadioGroup(TabContents* tab_contents, Profile* profile, | 165 ContentSettingSingleRadioGroup(TabContents* tab_contents, Profile* profile, |
| 165 ContentSettingsType content_type) | 166 ContentSettingsType content_type) |
| 166 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type), | 167 : ContentSettingTitleLinkAndInfoModel(tab_contents, |
| 168 profile, | |
| 169 content_type), | |
| 167 block_setting_(CONTENT_SETTING_BLOCK) { | 170 block_setting_(CONTENT_SETTING_BLOCK) { |
| 168 SetRadioGroup(); | 171 SetRadioGroup(); |
| 169 } | 172 } |
| 170 | 173 |
| 171 private: | 174 private: |
| 172 ContentSetting block_setting_; | 175 ContentSetting block_setting_; |
| 173 | 176 |
| 174 // Initialize the radio group by setting the appropriate labels for the | 177 // Initialize the radio group by setting the appropriate labels for the |
| 175 // content type and setting the default value based on the content setting. | 178 // content type and setting the default value based on the content setting. |
| 176 void SetRadioGroup() { | 179 void SetRadioGroup() { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 } | 288 } |
| 286 } | 289 } |
| 287 }; | 290 }; |
| 288 | 291 |
| 289 class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup { | 292 class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup { |
| 290 public: | 293 public: |
| 291 ContentSettingPluginBubbleModel(TabContents* tab_contents, Profile* profile, | 294 ContentSettingPluginBubbleModel(TabContents* tab_contents, Profile* profile, |
| 292 ContentSettingsType content_type) | 295 ContentSettingsType content_type) |
| 293 : ContentSettingSingleRadioGroup(tab_contents, profile, content_type) { | 296 : ContentSettingSingleRadioGroup(tab_contents, profile, content_type) { |
| 294 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS); | 297 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS); |
| 295 SetLoadPluginsLinkTitle(); | |
| 296 } | 298 } |
| 297 | 299 |
| 298 private: | 300 private: |
| 299 void SetLoadPluginsLinkTitle() { | 301 virtual void OnInfoLinkClicked() OVERRIDE { |
| 300 set_load_plugins_link_title( | |
| 301 l10n_util::GetStringUTF8(IDS_BLOCKED_PLUGINS_LOAD_ALL)); | |
| 302 } | |
| 303 | |
| 304 virtual void OnLoadPluginsLinkClicked() { | |
| 305 UserMetrics::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble")); | 302 UserMetrics::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble")); |
| 306 if (tab_contents()) { | 303 if (tab_contents()) { |
| 307 tab_contents()->render_view_host()->LoadBlockedPlugins(); | 304 tab_contents()->render_view_host()->LoadBlockedPlugins(); |
| 308 } | 305 } |
| 309 set_load_plugins_link_enabled(false); | 306 set_info_link_enabled(false); |
| 310 TabSpecificContentSettings* settings = | 307 TabSpecificContentSettings* settings = |
| 311 tab_contents()->GetTabSpecificContentSettings(); | 308 tab_contents()->GetTabSpecificContentSettings(); |
| 312 settings->set_load_plugins_link_enabled(false); | 309 settings->set_load_plugins_link_enabled(false); |
|
msw
2010/12/07 03:28:58
If we want, I can rename TabSpecificContentSetting
Peter Kasting
2010/12/07 17:53:00
No, I think that'd be wrong. From that class' per
| |
| 313 } | 310 } |
| 314 }; | 311 }; |
| 315 | 312 |
| 316 class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup { | 313 class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup { |
| 317 public: | 314 public: |
| 318 ContentSettingPopupBubbleModel(TabContents* tab_contents, Profile* profile, | 315 ContentSettingPopupBubbleModel(TabContents* tab_contents, Profile* profile, |
| 319 ContentSettingsType content_type) | 316 ContentSettingsType content_type) |
| 320 : ContentSettingSingleRadioGroup(tab_contents, profile, content_type) { | 317 : ContentSettingSingleRadioGroup(tab_contents, profile, content_type) { |
| 321 SetPopups(); | 318 SetPopups(); |
| 322 } | 319 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 343 add_popup(popup_item); | 340 add_popup(popup_item); |
| 344 } | 341 } |
| 345 } | 342 } |
| 346 | 343 |
| 347 virtual void OnPopupClicked(int index) { | 344 virtual void OnPopupClicked(int index) { |
| 348 if (tab_contents() && tab_contents()->blocked_content_container()) { | 345 if (tab_contents() && tab_contents()->blocked_content_container()) { |
| 349 tab_contents()->blocked_content_container()->LaunchForContents( | 346 tab_contents()->blocked_content_container()->LaunchForContents( |
| 350 bubble_content().popup_items[index].tab_contents); | 347 bubble_content().popup_items[index].tab_contents); |
| 351 } | 348 } |
| 352 } | 349 } |
| 350 virtual void OnInfoLinkClicked() OVERRIDE {} | |
| 353 }; | 351 }; |
| 354 | 352 |
| 355 class ContentSettingDomainListBubbleModel | 353 class ContentSettingDomainListBubbleModel |
| 356 : public ContentSettingTitleAndLinkModel { | 354 : public ContentSettingTitleAndLinkModel { |
| 357 public: | 355 public: |
| 358 ContentSettingDomainListBubbleModel(TabContents* tab_contents, | 356 ContentSettingDomainListBubbleModel(TabContents* tab_contents, |
| 359 Profile* profile, | 357 Profile* profile, |
| 360 ContentSettingsType content_type) | 358 ContentSettingsType content_type) |
| 361 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) { | 359 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) { |
| 362 DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) << | 360 DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) << |
| 363 "SetDomains currently only supports geolocation content type"; | 361 "SetDomains currently only supports geolocation content type"; |
| 364 SetDomainsAndClearLink(); | 362 SetDomainsAndInfoLink(); |
| 365 } | 363 } |
| 366 | 364 |
| 367 private: | 365 private: |
| 368 void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id) { | 366 void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id) { |
| 369 if (!hosts.empty()) { | 367 if (!hosts.empty()) { |
| 370 DomainList domain_list; | 368 DomainList domain_list; |
| 371 domain_list.title = l10n_util::GetStringUTF8(title_id); | 369 domain_list.title = l10n_util::GetStringUTF8(title_id); |
| 372 domain_list.hosts = hosts; | 370 domain_list.hosts = hosts; |
| 373 add_domain_list(domain_list); | 371 add_domain_list(domain_list); |
| 374 } | 372 } |
| 375 } | 373 } |
| 376 void SetDomainsAndClearLink() { | 374 void SetDomainsAndInfoLink() { |
| 377 TabSpecificContentSettings* content_settings = | 375 TabSpecificContentSettings* content_settings = |
| 378 tab_contents()->GetTabSpecificContentSettings(); | 376 tab_contents()->GetTabSpecificContentSettings(); |
| 379 const GeolocationSettingsState& settings = | 377 const GeolocationSettingsState& settings = |
| 380 content_settings->geolocation_settings_state(); | 378 content_settings->geolocation_settings_state(); |
| 381 GeolocationSettingsState::FormattedHostsPerState formatted_hosts_per_state; | 379 GeolocationSettingsState::FormattedHostsPerState formatted_hosts_per_state; |
| 382 unsigned int tab_state_flags = 0; | 380 unsigned int tab_state_flags = 0; |
| 383 settings.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags); | 381 settings.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags); |
| 384 // Divide the tab's current geolocation users into sets according to their | 382 // Divide the tab's current geolocation users into sets according to their |
| 385 // permission state. | 383 // permission state. |
| 386 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW], | 384 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW], |
| 387 IDS_GEOLOCATION_BUBBLE_SECTION_ALLOWED); | 385 IDS_GEOLOCATION_BUBBLE_SECTION_ALLOWED); |
| 388 | 386 |
| 389 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK], | 387 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK], |
| 390 IDS_GEOLOCATION_BUBBLE_SECTION_DENIED); | 388 IDS_GEOLOCATION_BUBBLE_SECTION_DENIED); |
| 391 | 389 |
| 392 if (tab_state_flags & GeolocationSettingsState::TABSTATE_HAS_EXCEPTION) { | 390 if (tab_state_flags & GeolocationSettingsState::TABSTATE_HAS_EXCEPTION) { |
| 393 set_clear_link( | 391 set_info_link(l10n_util::GetStringUTF8( |
| 394 l10n_util::GetStringUTF8(IDS_GEOLOCATION_BUBBLE_CLEAR_LINK)); | 392 IDS_GEOLOCATION_BUBBLE_CLEAR_LINK)); |
| 393 set_info_link_enabled(true); | |
| 395 } else if (tab_state_flags & | 394 } else if (tab_state_flags & |
| 396 GeolocationSettingsState::TABSTATE_HAS_CHANGED) { | 395 GeolocationSettingsState::TABSTATE_HAS_CHANGED) { |
| 397 // It is a slight abuse of the domain list field to use it for the reload | 396 set_info_link(l10n_util::GetStringUTF8( |
| 398 // hint, but works fine for now. TODO(joth): If we need to style it | 397 IDS_GEOLOCATION_BUBBLE_REQUIRE_RELOAD_TO_CLEAR)); |
| 399 // differently, consider adding an explicit field, or generalize the | 398 set_info_link_enabled(false); |
| 400 // domain list to be a flat list of style formatted lines. | 399 } else { |
| 401 DomainList reload_section; | 400 set_info_link(std::string()); |
| 402 reload_section.title = l10n_util::GetStringUTF8( | 401 set_info_link_enabled(false); |
| 403 IDS_GEOLOCATION_BUBBLE_REQUIRE_RELOAD_TO_CLEAR); | |
| 404 add_domain_list(reload_section); | |
| 405 } | 402 } |
| 406 } | 403 } |
| 407 virtual void OnClearLinkClicked() { | 404 virtual void OnInfoLinkClicked() OVERRIDE { |
| 408 if (!tab_contents()) | 405 if (!tab_contents()) |
| 409 return; | 406 return; |
| 410 // Reset this embedder's entry to default for each of the requesting | 407 // Reset this embedder's entry to default for each of the requesting |
| 411 // origins currently on the page. | 408 // origins currently on the page. |
| 412 const GURL& embedder_url = tab_contents()->GetURL(); | 409 const GURL& embedder_url = tab_contents()->GetURL(); |
| 413 TabSpecificContentSettings* content_settings = | 410 TabSpecificContentSettings* content_settings = |
| 414 tab_contents()->GetTabSpecificContentSettings(); | 411 tab_contents()->GetTabSpecificContentSettings(); |
| 415 const GeolocationSettingsState::StateMap& state_map = | 412 const GeolocationSettingsState::StateMap& state_map = |
| 416 content_settings->geolocation_settings_state().state_map(); | 413 content_settings->geolocation_settings_state().state_map(); |
| 417 GeolocationContentSettingsMap* settings_map = | 414 GeolocationContentSettingsMap* settings_map = |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 } | 448 } |
| 452 | 449 |
| 453 ContentSettingBubbleModel::ContentSettingBubbleModel( | 450 ContentSettingBubbleModel::ContentSettingBubbleModel( |
| 454 TabContents* tab_contents, Profile* profile, | 451 TabContents* tab_contents, Profile* profile, |
| 455 ContentSettingsType content_type) | 452 ContentSettingsType content_type) |
| 456 : tab_contents_(tab_contents), profile_(profile), | 453 : tab_contents_(tab_contents), profile_(profile), |
| 457 content_type_(content_type) { | 454 content_type_(content_type) { |
| 458 if (tab_contents) { | 455 if (tab_contents) { |
| 459 TabSpecificContentSettings* settings = | 456 TabSpecificContentSettings* settings = |
| 460 tab_contents->GetTabSpecificContentSettings(); | 457 tab_contents->GetTabSpecificContentSettings(); |
| 461 set_load_plugins_link_enabled(settings->load_plugins_link_enabled()); | 458 set_info_link_enabled(settings->load_plugins_link_enabled()); |
| 462 } else { | 459 } else { |
| 463 set_load_plugins_link_enabled(true); | 460 set_info_link_enabled(true); |
| 464 } | 461 } |
| 465 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, | 462 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, |
| 466 Source<TabContents>(tab_contents)); | 463 Source<TabContents>(tab_contents)); |
| 467 } | 464 } |
| 468 | 465 |
| 469 ContentSettingBubbleModel::~ContentSettingBubbleModel() { | 466 ContentSettingBubbleModel::~ContentSettingBubbleModel() { |
| 470 } | 467 } |
| 471 | 468 |
| 472 ContentSettingBubbleModel::RadioGroup::RadioGroup() : default_item(0) {} | 469 ContentSettingBubbleModel::RadioGroup::RadioGroup() : default_item(0) {} |
| 473 | 470 |
| 474 ContentSettingBubbleModel::RadioGroup::~RadioGroup() {} | 471 ContentSettingBubbleModel::RadioGroup::~RadioGroup() {} |
| 475 | 472 |
| 476 ContentSettingBubbleModel::DomainList::DomainList() {} | 473 ContentSettingBubbleModel::DomainList::DomainList() {} |
| 477 | 474 |
| 478 ContentSettingBubbleModel::DomainList::~DomainList() {} | 475 ContentSettingBubbleModel::DomainList::~DomainList() {} |
| 479 | 476 |
| 480 ContentSettingBubbleModel::BubbleContent::BubbleContent() | 477 ContentSettingBubbleModel::BubbleContent::BubbleContent() |
| 481 : load_plugins_link_enabled(false) { | 478 : info_link_enabled(false) { |
| 482 } | 479 } |
| 483 | 480 |
| 484 ContentSettingBubbleModel::BubbleContent::~BubbleContent() {} | 481 ContentSettingBubbleModel::BubbleContent::~BubbleContent() {} |
| 485 | 482 |
| 486 | 483 |
| 487 void ContentSettingBubbleModel::AddBlockedResource( | 484 void ContentSettingBubbleModel::AddBlockedResource( |
| 488 const std::string& resource_identifier) { | 485 const std::string& resource_identifier) { |
| 489 bubble_content_.resource_identifiers.insert(resource_identifier); | 486 bubble_content_.resource_identifiers.insert(resource_identifier); |
| 490 } | 487 } |
| 491 | 488 |
| 492 void ContentSettingBubbleModel::Observe(NotificationType type, | 489 void ContentSettingBubbleModel::Observe(NotificationType type, |
| 493 const NotificationSource& source, | 490 const NotificationSource& source, |
| 494 const NotificationDetails& details) { | 491 const NotificationDetails& details) { |
| 495 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); | 492 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); |
| 496 DCHECK(source == Source<TabContents>(tab_contents_)); | 493 DCHECK(source == Source<TabContents>(tab_contents_)); |
| 497 tab_contents_ = NULL; | 494 tab_contents_ = NULL; |
| 498 } | 495 } |
| OLD | NEW |