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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 SetManageText(); | 118 SetManageText(); |
119 SetCustomLink(); | 119 SetCustomLink(); |
120 } | 120 } |
121 | 121 |
122 ContentSettingSimpleBubbleModel* | 122 ContentSettingSimpleBubbleModel* |
123 ContentSettingSimpleBubbleModel::AsSimpleBubbleModel() { | 123 ContentSettingSimpleBubbleModel::AsSimpleBubbleModel() { |
124 return this; | 124 return this; |
125 } | 125 } |
126 | 126 |
127 void ContentSettingSimpleBubbleModel::SetTitle() { | 127 void ContentSettingSimpleBubbleModel::SetTitle() { |
128 TabSpecificContentSettings* content_settings = NULL; | 128 TabSpecificContentSettings* content_settings = |
129 if (web_contents()) { | 129 web_contents() |
130 content_settings = | 130 ? TabSpecificContentSettings::FromWebContents(web_contents()) |
131 TabSpecificContentSettings::FromWebContents(web_contents()); | 131 : nullptr; |
132 } | |
133 | 132 |
134 static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = { | 133 static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = { |
135 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, | 134 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, |
136 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, | 135 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, |
137 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE}, | 136 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE}, |
138 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_TITLE}, | 137 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_TITLE}, |
139 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE}, | 138 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE}, |
140 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, | 139 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, |
141 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT}, | 140 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT}, |
142 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | 141 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, |
143 IDS_BLOCKED_PPAPI_BROKER_TITLE}, | 142 IDS_BLOCKED_PPAPI_BROKER_TITLE}, |
144 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_TITLE}, | 143 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_TITLE}, |
145 }; | 144 }; |
146 // Fields as for kBlockedTitleIDs, above. | 145 // Fields as for kBlockedTitleIDs, above. |
147 static const ContentSettingsTypeIdEntry kAccessedTitleIDs[] = { | 146 static const ContentSettingsTypeIdEntry kAccessedTitleIDs[] = { |
148 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE}, | 147 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE}, |
149 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_TITLE}, | 148 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_TITLE}, |
150 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_TITLE}, | 149 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_TITLE}, |
151 }; | 150 }; |
152 const ContentSettingsTypeIdEntry *title_ids = kBlockedTitleIDs; | 151 const ContentSettingsTypeIdEntry* title_ids = kBlockedTitleIDs; |
153 size_t num_title_ids = arraysize(kBlockedTitleIDs); | 152 size_t num_title_ids = arraysize(kBlockedTitleIDs); |
154 if (content_settings && content_settings->IsContentAllowed(content_type()) && | 153 if (content_settings && content_settings->IsContentAllowed(content_type()) && |
155 !content_settings->IsContentBlocked(content_type())) { | 154 !content_settings->IsContentBlocked(content_type())) { |
156 title_ids = kAccessedTitleIDs; | 155 title_ids = kAccessedTitleIDs; |
157 num_title_ids = arraysize(kAccessedTitleIDs); | 156 num_title_ids = arraysize(kAccessedTitleIDs); |
158 } | 157 } |
159 int title_id = | 158 int title_id = GetIdForContentType(title_ids, num_title_ids, content_type()); |
160 GetIdForContentType(title_ids, num_title_ids, content_type()); | |
161 if (title_id) | 159 if (title_id) |
162 set_title(l10n_util::GetStringUTF16(title_id)); | 160 set_title(l10n_util::GetStringUTF16(title_id)); |
163 } | 161 } |
164 | 162 |
165 void ContentSettingSimpleBubbleModel::SetManageText() { | 163 void ContentSettingSimpleBubbleModel::SetManageText() { |
166 static const ContentSettingsTypeIdEntry kLinkIDs[] = { | 164 static const ContentSettingsTypeIdEntry kLinkIDs[] = { |
167 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK}, | 165 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK}, |
168 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK}, | 166 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK}, |
169 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK}, | 167 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK}, |
170 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK}, | 168 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK}, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 bool settings_changed() const; | 217 bool settings_changed() const; |
220 int selected_item() const { return selected_item_; } | 218 int selected_item() const { return selected_item_; } |
221 | 219 |
222 private: | 220 private: |
223 void SetRadioGroup(); | 221 void SetRadioGroup(); |
224 void SetNarrowestContentSetting(ContentSetting setting); | 222 void SetNarrowestContentSetting(ContentSetting setting); |
225 void OnRadioClicked(int radio_index) override; | 223 void OnRadioClicked(int radio_index) override; |
226 | 224 |
227 ContentSetting block_setting_; | 225 ContentSetting block_setting_; |
228 int selected_item_; | 226 int selected_item_; |
| 227 |
| 228 DISALLOW_COPY_AND_ASSIGN(ContentSettingSingleRadioGroup); |
229 }; | 229 }; |
230 | 230 |
231 ContentSettingSingleRadioGroup::ContentSettingSingleRadioGroup( | 231 ContentSettingSingleRadioGroup::ContentSettingSingleRadioGroup( |
232 Delegate* delegate, | 232 Delegate* delegate, |
233 WebContents* web_contents, | 233 WebContents* web_contents, |
234 Profile* profile, | 234 Profile* profile, |
235 ContentSettingsType content_type) | 235 ContentSettingsType content_type) |
236 : ContentSettingSimpleBubbleModel(delegate, | 236 : ContentSettingSimpleBubbleModel(delegate, |
237 web_contents, | 237 web_contents, |
238 profile, | 238 profile, |
(...skipping 21 matching lines...) Expand all Loading... |
260 // content type and setting the default value based on the content setting. | 260 // content type and setting the default value based on the content setting. |
261 void ContentSettingSingleRadioGroup::SetRadioGroup() { | 261 void ContentSettingSingleRadioGroup::SetRadioGroup() { |
262 GURL url = web_contents()->GetURL(); | 262 GURL url = web_contents()->GetURL(); |
263 base::string16 display_host = | 263 base::string16 display_host = |
264 url_formatter::FormatUrlForSecurityDisplay(url); | 264 url_formatter::FormatUrlForSecurityDisplay(url); |
265 if (display_host.empty()) | 265 if (display_host.empty()) |
266 display_host = base::ASCIIToUTF16(url.spec()); | 266 display_host = base::ASCIIToUTF16(url.spec()); |
267 | 267 |
268 TabSpecificContentSettings* content_settings = | 268 TabSpecificContentSettings* content_settings = |
269 TabSpecificContentSettings::FromWebContents(web_contents()); | 269 TabSpecificContentSettings::FromWebContents(web_contents()); |
270 bool allowed = | 270 bool allowed = !content_settings->IsContentBlocked(content_type()); |
271 !content_settings->IsContentBlocked(content_type()); | 271 DCHECK(!allowed || content_settings->IsContentAllowed(content_type())); |
272 DCHECK(!allowed || | |
273 content_settings->IsContentAllowed(content_type())); | |
274 | 272 |
275 RadioGroup radio_group; | 273 RadioGroup radio_group; |
276 radio_group.url = url; | 274 radio_group.url = url; |
277 | 275 |
278 static const ContentSettingsTypeIdEntry kBlockedAllowIDs[] = { | 276 static const ContentSettingsTypeIdEntry kBlockedAllowIDs[] = { |
279 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK}, | 277 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK}, |
280 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_UNBLOCK}, | 278 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_UNBLOCK}, |
281 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_UNBLOCK}, | 279 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_UNBLOCK}, |
282 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK_ALL}, | 280 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK_ALL}, |
283 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_UNBLOCK}, | 281 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_UNBLOCK}, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 } else if (setting == CONTENT_SETTING_ALLOW) { | 363 } else if (setting == CONTENT_SETTING_ALLOW) { |
366 radio_group.default_item = kAllowButtonIndex; | 364 radio_group.default_item = kAllowButtonIndex; |
367 // |block_setting_| is already set to |CONTENT_SETTING_BLOCK|. | 365 // |block_setting_| is already set to |CONTENT_SETTING_BLOCK|. |
368 } else { | 366 } else { |
369 radio_group.default_item = 1; | 367 radio_group.default_item = 1; |
370 block_setting_ = setting; | 368 block_setting_ = setting; |
371 } | 369 } |
372 | 370 |
373 set_setting_is_managed(setting_source != SETTING_SOURCE_USER && | 371 set_setting_is_managed(setting_source != SETTING_SOURCE_USER && |
374 setting != CONTENT_SETTING_ASK); | 372 setting != CONTENT_SETTING_ASK); |
375 if (setting_source != SETTING_SOURCE_USER) { | 373 set_radio_group_enabled(setting_source == SETTING_SOURCE_USER); |
376 set_radio_group_enabled(false); | |
377 } else { | |
378 set_radio_group_enabled(true); | |
379 } | |
380 selected_item_ = radio_group.default_item; | 374 selected_item_ = radio_group.default_item; |
381 set_radio_group(radio_group); | 375 set_radio_group(radio_group); |
382 } | 376 } |
383 | 377 |
384 void ContentSettingSingleRadioGroup::SetNarrowestContentSetting( | 378 void ContentSettingSingleRadioGroup::SetNarrowestContentSetting( |
385 ContentSetting setting) { | 379 ContentSetting setting) { |
386 if (profile()) { | 380 if (!profile()) |
387 HostContentSettingsMapFactory::GetForProfile(profile()) | 381 return; |
388 ->SetNarrowestContentSetting(bubble_content().radio_group.url, | 382 |
389 bubble_content().radio_group.url, | 383 auto* map = HostContentSettingsMapFactory::GetForProfile(profile()); |
390 content_type(), setting); | 384 map->SetNarrowestContentSetting(bubble_content().radio_group.url, |
391 } | 385 bubble_content().radio_group.url, |
| 386 content_type(), setting); |
392 } | 387 } |
393 | 388 |
394 void ContentSettingSingleRadioGroup::OnRadioClicked(int radio_index) { | 389 void ContentSettingSingleRadioGroup::OnRadioClicked(int radio_index) { |
395 selected_item_ = radio_index; | 390 selected_item_ = radio_index; |
396 } | 391 } |
397 | 392 |
398 // ContentSettingCookiesBubbleModel -------------------------------------------- | 393 // ContentSettingCookiesBubbleModel -------------------------------------------- |
399 | 394 |
400 class ContentSettingCookiesBubbleModel : public ContentSettingSingleRadioGroup { | 395 class ContentSettingCookiesBubbleModel : public ContentSettingSingleRadioGroup { |
401 public: | 396 public: |
402 ContentSettingCookiesBubbleModel(Delegate* delegate, | 397 ContentSettingCookiesBubbleModel(Delegate* delegate, |
403 WebContents* web_contents, | 398 WebContents* web_contents, |
404 Profile* profile); | 399 Profile* profile); |
405 | |
406 ~ContentSettingCookiesBubbleModel() override; | 400 ~ContentSettingCookiesBubbleModel() override; |
407 | 401 |
408 private: | 402 private: |
409 void OnCustomLinkClicked() override; | 403 void OnCustomLinkClicked() override; |
| 404 |
| 405 DISALLOW_COPY_AND_ASSIGN(ContentSettingCookiesBubbleModel); |
410 }; | 406 }; |
411 | 407 |
412 ContentSettingCookiesBubbleModel::ContentSettingCookiesBubbleModel( | 408 ContentSettingCookiesBubbleModel::ContentSettingCookiesBubbleModel( |
413 Delegate* delegate, | 409 Delegate* delegate, |
414 WebContents* web_contents, | 410 WebContents* web_contents, |
415 Profile* profile) | 411 Profile* profile) |
416 : ContentSettingSingleRadioGroup(delegate, | 412 : ContentSettingSingleRadioGroup(delegate, |
417 web_contents, | 413 web_contents, |
418 profile, | 414 profile, |
419 CONTENT_SETTINGS_TYPE_COOKIES) { | 415 CONTENT_SETTINGS_TYPE_COOKIES) { |
(...skipping 28 matching lines...) Expand all Loading... |
448 WebContents* web_contents, | 444 WebContents* web_contents, |
449 Profile* profile); | 445 Profile* profile); |
450 | 446 |
451 ~ContentSettingPluginBubbleModel() override; | 447 ~ContentSettingPluginBubbleModel() override; |
452 | 448 |
453 private: | 449 private: |
454 void OnLearnMoreLinkClicked() override; | 450 void OnLearnMoreLinkClicked() override; |
455 void OnCustomLinkClicked() override; | 451 void OnCustomLinkClicked() override; |
456 | 452 |
457 void RunPluginsOnPage(); | 453 void RunPluginsOnPage(); |
| 454 |
| 455 DISALLOW_COPY_AND_ASSIGN(ContentSettingPluginBubbleModel); |
458 }; | 456 }; |
459 | 457 |
460 ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel( | 458 ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel( |
461 Delegate* delegate, | 459 Delegate* delegate, |
462 WebContents* web_contents, | 460 WebContents* web_contents, |
463 Profile* profile) | 461 Profile* profile) |
464 : ContentSettingSingleRadioGroup(delegate, | 462 : ContentSettingSingleRadioGroup(delegate, |
465 web_contents, | 463 web_contents, |
466 profile, | 464 profile, |
467 CONTENT_SETTINGS_TYPE_PLUGINS) { | 465 CONTENT_SETTINGS_TYPE_PLUGINS) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 WebContents* web_contents, | 545 WebContents* web_contents, |
548 Profile* profile); | 546 Profile* profile); |
549 ~ContentSettingPopupBubbleModel() override {} | 547 ~ContentSettingPopupBubbleModel() override {} |
550 | 548 |
551 private: | 549 private: |
552 void OnListItemClicked(int index) override; | 550 void OnListItemClicked(int index) override; |
553 | 551 |
554 int32_t item_id_from_item_index(int index) const { | 552 int32_t item_id_from_item_index(int index) const { |
555 return bubble_content().list_items[index].item_id; | 553 return bubble_content().list_items[index].item_id; |
556 } | 554 } |
| 555 |
| 556 DISALLOW_COPY_AND_ASSIGN(ContentSettingPopupBubbleModel); |
557 }; | 557 }; |
558 | 558 |
559 ContentSettingPopupBubbleModel::ContentSettingPopupBubbleModel( | 559 ContentSettingPopupBubbleModel::ContentSettingPopupBubbleModel( |
560 Delegate* delegate, | 560 Delegate* delegate, |
561 WebContents* web_contents, | 561 WebContents* web_contents, |
562 Profile* profile) | 562 Profile* profile) |
563 : ContentSettingSingleRadioGroup(delegate, | 563 : ContentSettingSingleRadioGroup(delegate, |
564 web_contents, | 564 web_contents, |
565 profile, | 565 profile, |
566 CONTENT_SETTINGS_TYPE_POPUPS) { | 566 CONTENT_SETTINGS_TYPE_POPUPS) { |
567 if (web_contents) { | 567 if (!web_contents) |
568 // Build blocked popup list. | 568 return; |
569 std::map<int32_t, GURL> blocked_popups = | 569 |
570 PopupBlockerTabHelper::FromWebContents(web_contents) | 570 // Build blocked popup list. |
571 ->GetBlockedPopupRequests(); | 571 auto* helper = PopupBlockerTabHelper::FromWebContents(web_contents); |
572 for (const std::pair<int32_t, GURL>& blocked_popup : blocked_popups) { | 572 std::map<int32_t, GURL> blocked_popups = helper->GetBlockedPopupRequests(); |
573 std::string title(blocked_popup.second.spec()); | 573 for (const std::pair<int32_t, GURL>& blocked_popup : blocked_popups) { |
574 // The pop-up may not have a valid URL. | 574 std::string title(blocked_popup.second.spec()); |
575 if (title.empty()) | 575 // The pop-up may not have a valid URL. |
576 title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE); | 576 if (title.empty()) |
577 ListItem popup_item(ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 577 title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE); |
578 IDR_DEFAULT_FAVICON), | 578 ListItem popup_item(ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
579 title, true, blocked_popup.first); | 579 IDR_DEFAULT_FAVICON), |
580 add_list_item(popup_item); | 580 title, true, blocked_popup.first); |
581 } | 581 add_list_item(popup_item); |
582 } | 582 } |
583 } | 583 } |
584 | 584 |
585 void ContentSettingPopupBubbleModel::OnListItemClicked(int index) { | 585 void ContentSettingPopupBubbleModel::OnListItemClicked(int index) { |
586 if (web_contents()) { | 586 if (web_contents()) { |
587 PopupBlockerTabHelper::FromWebContents(web_contents()) | 587 auto* helper = PopupBlockerTabHelper::FromWebContents(web_contents()); |
588 ->ShowBlockedPopup(item_id_from_item_index(index)); | 588 helper->ShowBlockedPopup(item_id_from_item_index(index)); |
589 } | 589 } |
590 } | 590 } |
591 | 591 |
592 // ContentSettingMediaStreamBubbleModel ---------------------------------------- | 592 // ContentSettingMediaStreamBubbleModel ---------------------------------------- |
593 | 593 |
594 ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel( | 594 ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel( |
595 Delegate* delegate, | 595 Delegate* delegate, |
596 WebContents* web_contents, | 596 WebContents* web_contents, |
597 Profile* profile) | 597 Profile* profile) |
598 : ContentSettingBubbleModel(delegate, web_contents, profile), | 598 : ContentSettingBubbleModel(delegate, web_contents, profile), |
(...skipping 21 matching lines...) Expand all Loading... |
620 SetManageText(); | 620 SetManageText(); |
621 SetCustomLink(); | 621 SetCustomLink(); |
622 } | 622 } |
623 | 623 |
624 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() { | 624 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() { |
625 // On some platforms (e.g. MacOS X) it is possible to close a tab while the | 625 // On some platforms (e.g. MacOS X) it is possible to close a tab while the |
626 // media stream bubble is open. This resets the web contents to NULL. | 626 // media stream bubble is open. This resets the web contents to NULL. |
627 if (!web_contents()) | 627 if (!web_contents()) |
628 return; | 628 return; |
629 | 629 |
630 for (const std::pair<content::MediaStreamType, MediaMenu>& media_menu : | 630 for (const auto& media_menu : bubble_content().media_menus) { |
631 bubble_content().media_menus) { | 631 const MediaMenu& menu = media_menu.second; |
632 if (media_menu.second.selected_device.id != | 632 if (menu.selected_device.id != menu.default_device.id) |
633 media_menu.second.default_device.id) { | 633 UpdateDefaultDeviceForType(media_menu.first, menu.selected_device.id); |
634 UpdateDefaultDeviceForType(media_menu.first, | |
635 media_menu.second.selected_device.id); | |
636 } | |
637 } | 634 } |
638 | 635 |
639 // Update the media settings if the radio button selection was changed. | 636 // Update the media settings if the radio button selection was changed. |
640 if (selected_item_ != bubble_content().radio_group.default_item) { | 637 if (selected_item_ != bubble_content().radio_group.default_item) |
641 UpdateSettings(radio_item_setting_[selected_item_]); | 638 UpdateSettings(radio_item_setting_[selected_item_]); |
642 } | |
643 } | 639 } |
644 | 640 |
645 ContentSettingMediaStreamBubbleModel* | 641 ContentSettingMediaStreamBubbleModel* |
646 ContentSettingMediaStreamBubbleModel::AsMediaStreamBubbleModel() { | 642 ContentSettingMediaStreamBubbleModel::AsMediaStreamBubbleModel() { |
647 return this; | 643 return this; |
648 } | 644 } |
649 | 645 |
650 void ContentSettingMediaStreamBubbleModel::OnManageLinkClicked() { | 646 void ContentSettingMediaStreamBubbleModel::OnManageLinkClicked() { |
651 if (!delegate()) | 647 if (!delegate()) |
652 return; | 648 return; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 radio_group.default_item = selected_item_; | 744 radio_group.default_item = selected_item_; |
749 radio_group.radio_items.push_back(radio_allow_label); | 745 radio_group.radio_items.push_back(radio_allow_label); |
750 radio_group.radio_items.push_back(radio_block_label); | 746 radio_group.radio_items.push_back(radio_block_label); |
751 | 747 |
752 set_radio_group(radio_group); | 748 set_radio_group(radio_group); |
753 set_radio_group_enabled(true); | 749 set_radio_group_enabled(true); |
754 } | 750 } |
755 | 751 |
756 void ContentSettingMediaStreamBubbleModel::UpdateSettings( | 752 void ContentSettingMediaStreamBubbleModel::UpdateSettings( |
757 ContentSetting setting) { | 753 ContentSetting setting) { |
758 if (profile()) { | 754 if (!profile()) |
759 TabSpecificContentSettings* tab_content_settings = | 755 return; |
760 TabSpecificContentSettings::FromWebContents(web_contents()); | 756 |
761 // The same urls must be used as in other places (e.g. the infobar) in | 757 TabSpecificContentSettings* tab_content_settings = |
762 // order to override the existing rule. Otherwise a new rule is created. | 758 TabSpecificContentSettings::FromWebContents(web_contents()); |
763 // TODO(markusheintz): Extract to a helper so that there is only a single | 759 // The same urls must be used as in other places (e.g. the infobar) in |
764 // place to touch. | 760 // order to override the existing rule. Otherwise a new rule is created. |
765 HostContentSettingsMap* map = | 761 // TODO(markusheintz): Extract to a helper so that there is only a single |
766 HostContentSettingsMapFactory::GetForProfile(profile()); | 762 // place to touch. |
767 if (MicrophoneAccessed()) { | 763 HostContentSettingsMap* map = |
768 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( | 764 HostContentSettingsMapFactory::GetForProfile(profile()); |
769 profile(), tab_content_settings->media_stream_access_origin(), GURL(), | 765 if (MicrophoneAccessed()) { |
770 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 766 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( |
771 PermissionSourceUI::PAGE_ACTION); | 767 profile(), tab_content_settings->media_stream_access_origin(), GURL(), |
772 map->SetContentSettingDefaultScope( | 768 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, PermissionSourceUI::PAGE_ACTION); |
773 tab_content_settings->media_stream_access_origin(), GURL(), | 769 map->SetContentSettingDefaultScope( |
774 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting); | 770 tab_content_settings->media_stream_access_origin(), GURL(), |
775 } | 771 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting); |
776 if (CameraAccessed()) { | 772 } |
777 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( | 773 if (CameraAccessed()) { |
778 profile(), tab_content_settings->media_stream_access_origin(), GURL(), | 774 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( |
779 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 775 profile(), tab_content_settings->media_stream_access_origin(), GURL(), |
780 PermissionSourceUI::PAGE_ACTION); | 776 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
781 map->SetContentSettingDefaultScope( | 777 PermissionSourceUI::PAGE_ACTION); |
782 tab_content_settings->media_stream_access_origin(), GURL(), | 778 map->SetContentSettingDefaultScope( |
783 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting); | 779 tab_content_settings->media_stream_access_origin(), GURL(), |
784 } | 780 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting); |
785 } | 781 } |
786 } | 782 } |
787 | 783 |
788 void ContentSettingMediaStreamBubbleModel::UpdateDefaultDeviceForType( | 784 void ContentSettingMediaStreamBubbleModel::UpdateDefaultDeviceForType( |
789 content::MediaStreamType type, | 785 content::MediaStreamType type, |
790 const std::string& device) { | 786 const std::string& device) { |
791 PrefService* prefs = profile()->GetPrefs(); | 787 PrefService* prefs = profile()->GetPrefs(); |
792 if (type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { | 788 if (type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { |
793 prefs->SetString(prefs::kDefaultAudioCaptureDevice, device); | 789 prefs->SetString(prefs::kDefaultAudioCaptureDevice, device); |
794 } else { | 790 } else { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 ContentSettingDomainListBubbleModel(Delegate* delegate, | 910 ContentSettingDomainListBubbleModel(Delegate* delegate, |
915 WebContents* web_contents, | 911 WebContents* web_contents, |
916 Profile* profile, | 912 Profile* profile, |
917 ContentSettingsType content_type); | 913 ContentSettingsType content_type); |
918 ~ContentSettingDomainListBubbleModel() override {} | 914 ~ContentSettingDomainListBubbleModel() override {} |
919 | 915 |
920 private: | 916 private: |
921 void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id); | 917 void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id); |
922 void SetDomainsAndCustomLink(); | 918 void SetDomainsAndCustomLink(); |
923 void OnCustomLinkClicked() override; | 919 void OnCustomLinkClicked() override; |
| 920 |
| 921 DISALLOW_COPY_AND_ASSIGN(ContentSettingDomainListBubbleModel); |
924 }; | 922 }; |
925 | 923 |
926 ContentSettingDomainListBubbleModel::ContentSettingDomainListBubbleModel( | 924 ContentSettingDomainListBubbleModel::ContentSettingDomainListBubbleModel( |
927 Delegate* delegate, | 925 Delegate* delegate, |
928 WebContents* web_contents, | 926 WebContents* web_contents, |
929 Profile* profile, | 927 Profile* profile, |
930 ContentSettingsType content_type) | 928 ContentSettingsType content_type) |
931 : ContentSettingSimpleBubbleModel( | 929 : ContentSettingSimpleBubbleModel( |
932 delegate, web_contents, profile, content_type) { | 930 delegate, web_contents, profile, content_type) { |
933 DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) << | 931 DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) << |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 : public ContentSettingSimpleBubbleModel { | 998 : public ContentSettingSimpleBubbleModel { |
1001 public: | 999 public: |
1002 ContentSettingMixedScriptBubbleModel(Delegate* delegate, | 1000 ContentSettingMixedScriptBubbleModel(Delegate* delegate, |
1003 WebContents* web_contents, | 1001 WebContents* web_contents, |
1004 Profile* profile); | 1002 Profile* profile); |
1005 | 1003 |
1006 ~ContentSettingMixedScriptBubbleModel() override {} | 1004 ~ContentSettingMixedScriptBubbleModel() override {} |
1007 | 1005 |
1008 private: | 1006 private: |
1009 void OnCustomLinkClicked() override; | 1007 void OnCustomLinkClicked() override; |
| 1008 |
| 1009 DISALLOW_COPY_AND_ASSIGN(ContentSettingMixedScriptBubbleModel); |
1010 }; | 1010 }; |
1011 | 1011 |
1012 ContentSettingMixedScriptBubbleModel::ContentSettingMixedScriptBubbleModel( | 1012 ContentSettingMixedScriptBubbleModel::ContentSettingMixedScriptBubbleModel( |
1013 Delegate* delegate, | 1013 Delegate* delegate, |
1014 WebContents* web_contents, | 1014 WebContents* web_contents, |
1015 Profile* profile) | 1015 Profile* profile) |
1016 : ContentSettingSimpleBubbleModel( | 1016 : ContentSettingSimpleBubbleModel( |
1017 delegate, | 1017 delegate, |
1018 web_contents, | 1018 web_contents, |
1019 profile, | 1019 profile, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 set_radio_group_enabled(true); | 1114 set_radio_group_enabled(true); |
1115 set_radio_group(radio_group); | 1115 set_radio_group(radio_group); |
1116 } | 1116 } |
1117 | 1117 |
1118 ContentSettingRPHBubbleModel::~ContentSettingRPHBubbleModel() { | 1118 ContentSettingRPHBubbleModel::~ContentSettingRPHBubbleModel() { |
1119 if (!web_contents() || !interacted_) | 1119 if (!web_contents() || !interacted_) |
1120 return; | 1120 return; |
1121 | 1121 |
1122 // The user has one chance to deal with the RPH content setting UI, | 1122 // The user has one chance to deal with the RPH content setting UI, |
1123 // then we remove it. | 1123 // then we remove it. |
1124 TabSpecificContentSettings::FromWebContents(web_contents())-> | 1124 auto* settings = TabSpecificContentSettings::FromWebContents(web_contents()); |
1125 ClearPendingProtocolHandler(); | 1125 settings->ClearPendingProtocolHandler(); |
1126 content::NotificationService::current()->Notify( | 1126 content::NotificationService::current()->Notify( |
1127 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | 1127 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
1128 content::Source<WebContents>(web_contents()), | 1128 content::Source<WebContents>(web_contents()), |
1129 content::NotificationService::NoDetails()); | 1129 content::NotificationService::NoDetails()); |
1130 } | 1130 } |
1131 | 1131 |
1132 void ContentSettingRPHBubbleModel::OnRadioClicked(int radio_index) { | 1132 void ContentSettingRPHBubbleModel::OnRadioClicked(int radio_index) { |
1133 if (selected_item_ == radio_index) | 1133 if (selected_item_ == radio_index) |
1134 return; | 1134 return; |
1135 | 1135 |
(...skipping 25 matching lines...) Expand all Loading... |
1161 registry_->OnAcceptRegisterProtocolHandler(pending_handler_); | 1161 registry_->OnAcceptRegisterProtocolHandler(pending_handler_); |
1162 TabSpecificContentSettings::FromWebContents(web_contents())-> | 1162 TabSpecificContentSettings::FromWebContents(web_contents())-> |
1163 set_pending_protocol_handler_setting(CONTENT_SETTING_ALLOW); | 1163 set_pending_protocol_handler_setting(CONTENT_SETTING_ALLOW); |
1164 } | 1164 } |
1165 | 1165 |
1166 void ContentSettingRPHBubbleModel::UnregisterProtocolHandler() { | 1166 void ContentSettingRPHBubbleModel::UnregisterProtocolHandler() { |
1167 if (!web_contents()) | 1167 if (!web_contents()) |
1168 return; | 1168 return; |
1169 | 1169 |
1170 registry_->OnDenyRegisterProtocolHandler(pending_handler_); | 1170 registry_->OnDenyRegisterProtocolHandler(pending_handler_); |
1171 TabSpecificContentSettings::FromWebContents(web_contents())-> | 1171 auto* settings = TabSpecificContentSettings::FromWebContents(web_contents()); |
1172 set_pending_protocol_handler_setting(CONTENT_SETTING_BLOCK); | 1172 settings->set_pending_protocol_handler_setting(CONTENT_SETTING_BLOCK); |
1173 ClearOrSetPreviousHandler(); | 1173 ClearOrSetPreviousHandler(); |
1174 } | 1174 } |
1175 | 1175 |
1176 void ContentSettingRPHBubbleModel::IgnoreProtocolHandler() { | 1176 void ContentSettingRPHBubbleModel::IgnoreProtocolHandler() { |
1177 if (!web_contents()) | 1177 if (!web_contents()) |
1178 return; | 1178 return; |
1179 | 1179 |
1180 registry_->OnIgnoreRegisterProtocolHandler(pending_handler_); | 1180 registry_->OnIgnoreRegisterProtocolHandler(pending_handler_); |
1181 TabSpecificContentSettings::FromWebContents(web_contents())-> | 1181 auto* settings = TabSpecificContentSettings::FromWebContents(web_contents()); |
1182 set_pending_protocol_handler_setting(CONTENT_SETTING_DEFAULT); | 1182 settings->set_pending_protocol_handler_setting(CONTENT_SETTING_DEFAULT); |
1183 ClearOrSetPreviousHandler(); | 1183 ClearOrSetPreviousHandler(); |
1184 } | 1184 } |
1185 | 1185 |
1186 void ContentSettingRPHBubbleModel::ClearOrSetPreviousHandler() { | 1186 void ContentSettingRPHBubbleModel::ClearOrSetPreviousHandler() { |
1187 if (previous_handler_.IsEmpty()) { | 1187 if (previous_handler_.IsEmpty()) { |
1188 registry_->ClearDefault(pending_handler_.protocol()); | 1188 registry_->ClearDefault(pending_handler_.protocol()); |
1189 } else { | 1189 } else { |
1190 registry_->OnAcceptRegisterProtocolHandler(previous_handler_); | 1190 registry_->OnAcceptRegisterProtocolHandler(previous_handler_); |
1191 } | 1191 } |
1192 } | 1192 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1241 public: | 1241 public: |
1242 ContentSettingMidiSysExBubbleModel(Delegate* delegate, | 1242 ContentSettingMidiSysExBubbleModel(Delegate* delegate, |
1243 WebContents* web_contents, | 1243 WebContents* web_contents, |
1244 Profile* profile); | 1244 Profile* profile); |
1245 ~ContentSettingMidiSysExBubbleModel() override {} | 1245 ~ContentSettingMidiSysExBubbleModel() override {} |
1246 | 1246 |
1247 private: | 1247 private: |
1248 void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id); | 1248 void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id); |
1249 void SetDomainsAndCustomLink(); | 1249 void SetDomainsAndCustomLink(); |
1250 void OnCustomLinkClicked() override; | 1250 void OnCustomLinkClicked() override; |
| 1251 |
| 1252 DISALLOW_COPY_AND_ASSIGN(ContentSettingMidiSysExBubbleModel); |
1251 }; | 1253 }; |
1252 | 1254 |
1253 ContentSettingMidiSysExBubbleModel::ContentSettingMidiSysExBubbleModel( | 1255 ContentSettingMidiSysExBubbleModel::ContentSettingMidiSysExBubbleModel( |
1254 Delegate* delegate, | 1256 Delegate* delegate, |
1255 WebContents* web_contents, | 1257 WebContents* web_contents, |
1256 Profile* profile) | 1258 Profile* profile) |
1257 : ContentSettingSimpleBubbleModel(delegate, | 1259 : ContentSettingSimpleBubbleModel(delegate, |
1258 web_contents, | 1260 web_contents, |
1259 profile, | 1261 profile, |
1260 CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { | 1262 CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 | 1412 |
1411 ContentSettingBubbleModel::BubbleContent::~BubbleContent() {} | 1413 ContentSettingBubbleModel::BubbleContent::~BubbleContent() {} |
1412 | 1414 |
1413 void ContentSettingBubbleModel::Observe( | 1415 void ContentSettingBubbleModel::Observe( |
1414 int type, | 1416 int type, |
1415 const content::NotificationSource& source, | 1417 const content::NotificationSource& source, |
1416 const content::NotificationDetails& details) { | 1418 const content::NotificationDetails& details) { |
1417 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 1419 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
1418 DCHECK_EQ(web_contents_, | 1420 DCHECK_EQ(web_contents_, |
1419 content::Source<WebContents>(source).ptr()); | 1421 content::Source<WebContents>(source).ptr()); |
1420 web_contents_ = NULL; | 1422 web_contents_ = nullptr; |
1421 } else { | 1423 } else { |
1422 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 1424 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
1423 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 1425 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
1424 profile_ = NULL; | 1426 profile_ = nullptr; |
1425 } | 1427 } |
1426 } | 1428 } |
1427 | 1429 |
1428 ContentSettingSimpleBubbleModel* | 1430 ContentSettingSimpleBubbleModel* |
1429 ContentSettingBubbleModel::AsSimpleBubbleModel() { | 1431 ContentSettingBubbleModel::AsSimpleBubbleModel() { |
1430 // In general, bubble models might not inherit from the simple bubble model. | 1432 // In general, bubble models might not inherit from the simple bubble model. |
1431 return nullptr; | 1433 return nullptr; |
1432 } | 1434 } |
1433 | 1435 |
1434 ContentSettingMediaStreamBubbleModel* | 1436 ContentSettingMediaStreamBubbleModel* |
1435 ContentSettingBubbleModel::AsMediaStreamBubbleModel() { | 1437 ContentSettingBubbleModel::AsMediaStreamBubbleModel() { |
1436 // In general, bubble models might not inherit from the media bubble model. | 1438 // In general, bubble models might not inherit from the media bubble model. |
1437 return nullptr; | 1439 return nullptr; |
1438 } | 1440 } |
1439 | 1441 |
1440 ContentSettingSubresourceFilterBubbleModel* | 1442 ContentSettingSubresourceFilterBubbleModel* |
1441 ContentSettingBubbleModel::AsSubresourceFilterBubbleModel() { | 1443 ContentSettingBubbleModel::AsSubresourceFilterBubbleModel() { |
1442 return nullptr; | 1444 return nullptr; |
1443 } | 1445 } |
OLD | NEW |