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/content_settings/tab_specific_content_settings.h" | 5 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "content/public/browser/navigation_controller.h" | 27 #include "content/public/browser/navigation_controller.h" |
28 #include "content/public/browser/navigation_details.h" | 28 #include "content/public/browser/navigation_details.h" |
29 #include "content/public/browser/navigation_entry.h" | 29 #include "content/public/browser/navigation_entry.h" |
30 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
31 #include "content/public/browser/render_view_host.h" | 31 #include "content/public/browser/render_view_host.h" |
32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
33 #include "content/public/browser/web_contents_delegate.h" | 33 #include "content/public/browser/web_contents_delegate.h" |
34 #include "net/cookies/canonical_cookie.h" | 34 #include "net/cookies/canonical_cookie.h" |
35 #include "webkit/common/fileapi/file_system_types.h" | 35 #include "webkit/common/fileapi/file_system_types.h" |
36 | 36 |
37 using autofill::PasswordFormMap; | |
38 using content::BrowserThread; | 37 using content::BrowserThread; |
39 using content::NavigationController; | 38 using content::NavigationController; |
40 using content::NavigationEntry; | 39 using content::NavigationEntry; |
41 using content::RenderViewHost; | 40 using content::RenderViewHost; |
42 using content::WebContents; | 41 using content::WebContents; |
43 | 42 |
44 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabSpecificContentSettings); | 43 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabSpecificContentSettings); |
45 | 44 |
46 TabSpecificContentSettings::PasswordObserver::PasswordObserver( | |
47 TabSpecificContentSettings* tab_specific_content_settings) | |
48 : tab_specific_content_settings_(tab_specific_content_settings) { | |
49 tab_specific_content_settings_->SetPasswordObserver(this); | |
50 } | |
51 | |
52 TabSpecificContentSettings::PasswordObserver::~PasswordObserver() { | |
53 if (tab_specific_content_settings_) | |
54 tab_specific_content_settings_->SetPasswordObserver(NULL); | |
55 } | |
56 | |
57 void TabSpecificContentSettings::PasswordObserver::ContentSettingsDestroyed() { | |
58 tab_specific_content_settings_ = NULL; | |
59 } | |
60 | |
61 TabSpecificContentSettings::SiteDataObserver::SiteDataObserver( | 45 TabSpecificContentSettings::SiteDataObserver::SiteDataObserver( |
62 TabSpecificContentSettings* tab_specific_content_settings) | 46 TabSpecificContentSettings* tab_specific_content_settings) |
63 : tab_specific_content_settings_(tab_specific_content_settings) { | 47 : tab_specific_content_settings_(tab_specific_content_settings) { |
64 tab_specific_content_settings_->AddSiteDataObserver(this); | 48 tab_specific_content_settings_->AddSiteDataObserver(this); |
65 } | 49 } |
66 | 50 |
67 TabSpecificContentSettings::SiteDataObserver::~SiteDataObserver() { | 51 TabSpecificContentSettings::SiteDataObserver::~SiteDataObserver() { |
68 if (tab_specific_content_settings_) | 52 if (tab_specific_content_settings_) |
69 tab_specific_content_settings_->RemoveSiteDataObserver(this); | 53 tab_specific_content_settings_->RemoveSiteDataObserver(this); |
70 } | 54 } |
71 | 55 |
72 void TabSpecificContentSettings::SiteDataObserver::ContentSettingsDestroyed() { | 56 void TabSpecificContentSettings::SiteDataObserver::ContentSettingsDestroyed() { |
73 tab_specific_content_settings_ = NULL; | 57 tab_specific_content_settings_ = NULL; |
74 } | 58 } |
75 | 59 |
76 TabSpecificContentSettings::TabSpecificContentSettings(WebContents* tab) | 60 TabSpecificContentSettings::TabSpecificContentSettings(WebContents* tab) |
77 : content::WebContentsObserver(tab), | 61 : content::WebContentsObserver(tab), |
78 password_observer_(NULL), | |
79 profile_(Profile::FromBrowserContext(tab->GetBrowserContext())), | 62 profile_(Profile::FromBrowserContext(tab->GetBrowserContext())), |
80 allowed_local_shared_objects_(profile_), | 63 allowed_local_shared_objects_(profile_), |
81 blocked_local_shared_objects_(profile_), | 64 blocked_local_shared_objects_(profile_), |
82 geolocation_usages_state_(profile_, CONTENT_SETTINGS_TYPE_GEOLOCATION), | 65 geolocation_usages_state_(profile_, CONTENT_SETTINGS_TYPE_GEOLOCATION), |
83 midi_usages_state_(profile_, CONTENT_SETTINGS_TYPE_MIDI_SYSEX), | 66 midi_usages_state_(profile_, CONTENT_SETTINGS_TYPE_MIDI_SYSEX), |
84 pending_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), | 67 pending_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), |
85 previous_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), | 68 previous_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), |
86 pending_protocol_handler_setting_(CONTENT_SETTING_DEFAULT), | 69 pending_protocol_handler_setting_(CONTENT_SETTING_DEFAULT), |
87 load_plugins_link_enabled_(true), | 70 load_plugins_link_enabled_(true) { |
88 manage_passwords_icon_to_be_shown_(false), | |
89 password_to_be_saved_(false), | |
90 manage_passwords_bubble_needs_showing_(false), | |
91 password_submitted_(false) { | |
92 ClearBlockedContentSettingsExceptForCookies(); | 71 ClearBlockedContentSettingsExceptForCookies(); |
93 ClearCookieSpecificContentSettings(); | 72 ClearCookieSpecificContentSettings(); |
94 | 73 |
95 registrar_.Add(this, chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, | 74 registrar_.Add(this, chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, |
96 content::Source<HostContentSettingsMap>( | 75 content::Source<HostContentSettingsMap>( |
97 profile_->GetHostContentSettingsMap())); | 76 profile_->GetHostContentSettingsMap())); |
98 } | 77 } |
99 | 78 |
100 TabSpecificContentSettings::~TabSpecificContentSettings() { | 79 TabSpecificContentSettings::~TabSpecificContentSettings() { |
101 FOR_EACH_OBSERVER( | 80 FOR_EACH_OBSERVER( |
102 SiteDataObserver, observer_list_, ContentSettingsDestroyed()); | 81 SiteDataObserver, observer_list_, ContentSettingsDestroyed()); |
103 if (password_observer_) | |
104 password_observer_->ContentSettingsDestroyed(); | |
105 } | 82 } |
106 | 83 |
107 TabSpecificContentSettings* TabSpecificContentSettings::Get( | 84 TabSpecificContentSettings* TabSpecificContentSettings::Get( |
108 int render_process_id, int render_view_id) { | 85 int render_process_id, int render_view_id) { |
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
110 | 87 |
111 RenderViewHost* view = RenderViewHost::FromID(render_process_id, | 88 RenderViewHost* view = RenderViewHost::FromID(render_process_id, |
112 render_view_id); | 89 render_view_id); |
113 if (!view) | 90 if (!view) |
114 return NULL; | 91 return NULL; |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 bool allowed) { | 464 bool allowed) { |
488 if (allowed) { | 465 if (allowed) { |
489 OnContentAllowed(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); | 466 OnContentAllowed(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); |
490 } else { | 467 } else { |
491 OnContentBlocked(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, | 468 OnContentBlocked(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, |
492 std::string()); | 469 std::string()); |
493 } | 470 } |
494 } | 471 } |
495 #endif | 472 #endif |
496 | 473 |
497 void TabSpecificContentSettings::OnPasswordSubmitted( | |
498 PasswordFormManager* form_manager) { | |
499 form_manager_.reset(form_manager); | |
500 password_form_map_ = form_manager_->best_matches(); | |
501 manage_passwords_icon_to_be_shown_ = true; | |
502 password_to_be_saved_ = true; | |
503 manage_passwords_bubble_needs_showing_ = true; | |
504 password_submitted_ = true; | |
505 NotifyPasswordObserver(); | |
506 } | |
507 | |
508 void TabSpecificContentSettings::OnPasswordAutofilled( | |
509 const PasswordFormMap& password_form_map) { | |
510 password_form_map_ = password_form_map; | |
511 manage_passwords_icon_to_be_shown_ = true; | |
512 password_to_be_saved_ = false; | |
513 manage_passwords_bubble_needs_showing_ = false; | |
514 password_submitted_ = false; | |
515 NotifyPasswordObserver(); | |
516 } | |
517 | |
518 TabSpecificContentSettings::MicrophoneCameraState | 474 TabSpecificContentSettings::MicrophoneCameraState |
519 TabSpecificContentSettings::GetMicrophoneCameraState() const { | 475 TabSpecificContentSettings::GetMicrophoneCameraState() const { |
520 if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && | 476 if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && |
521 IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { | 477 IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { |
522 return MICROPHONE_CAMERA_ACCESSED; | 478 return MICROPHONE_CAMERA_ACCESSED; |
523 } else if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) { | 479 } else if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) { |
524 return MICROPHONE_ACCESSED; | 480 return MICROPHONE_ACCESSED; |
525 } else if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { | 481 } else if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { |
526 return CAMERA_ACCESSED; | 482 return CAMERA_ACCESSED; |
527 } | 483 } |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 | 647 |
692 void TabSpecificContentSettings::DidNavigateMainFrame( | 648 void TabSpecificContentSettings::DidNavigateMainFrame( |
693 const content::LoadCommittedDetails& details, | 649 const content::LoadCommittedDetails& details, |
694 const content::FrameNavigateParams& params) { | 650 const content::FrameNavigateParams& params) { |
695 if (!details.is_in_page) { | 651 if (!details.is_in_page) { |
696 // Clear "blocked" flags. | 652 // Clear "blocked" flags. |
697 ClearBlockedContentSettingsExceptForCookies(); | 653 ClearBlockedContentSettingsExceptForCookies(); |
698 GeolocationDidNavigate(details); | 654 GeolocationDidNavigate(details); |
699 MIDIDidNavigate(details); | 655 MIDIDidNavigate(details); |
700 } | 656 } |
701 // Reset password states for next page. | |
702 manage_passwords_icon_to_be_shown_ = false; | |
703 password_to_be_saved_ = false; | |
704 manage_passwords_bubble_needs_showing_ = false; | |
705 NotifySiteDataObservers(); | |
706 NotifyPasswordObserver(); | |
707 } | 657 } |
708 | 658 |
709 void TabSpecificContentSettings::DidStartProvisionalLoadForFrame( | 659 void TabSpecificContentSettings::DidStartProvisionalLoadForFrame( |
710 int64 frame_id, | 660 int64 frame_id, |
711 int64 parent_frame_id, | 661 int64 parent_frame_id, |
712 bool is_main_frame, | 662 bool is_main_frame, |
713 const GURL& validated_url, | 663 const GURL& validated_url, |
714 bool is_error_page, | 664 bool is_error_page, |
715 bool is_iframe_srcdoc, | 665 bool is_iframe_srcdoc, |
716 RenderViewHost* render_view_host) { | 666 RenderViewHost* render_view_host) { |
(...skipping 14 matching lines...) Expand all Loading... |
731 bool blocked_by_policy) { | 681 bool blocked_by_policy) { |
732 if (blocked_by_policy) { | 682 if (blocked_by_policy) { |
733 blocked_local_shared_objects_.appcaches()->AddAppCache(manifest_url); | 683 blocked_local_shared_objects_.appcaches()->AddAppCache(manifest_url); |
734 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); | 684 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); |
735 } else { | 685 } else { |
736 allowed_local_shared_objects_.appcaches()->AddAppCache(manifest_url); | 686 allowed_local_shared_objects_.appcaches()->AddAppCache(manifest_url); |
737 OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES); | 687 OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES); |
738 } | 688 } |
739 } | 689 } |
740 | 690 |
741 void TabSpecificContentSettings::SavePassword() { | |
742 DCHECK(form_manager_.get()); | |
743 form_manager_->Save(); | |
744 } | |
745 | |
746 void TabSpecificContentSettings::Observe( | 691 void TabSpecificContentSettings::Observe( |
747 int type, | 692 int type, |
748 const content::NotificationSource& source, | 693 const content::NotificationSource& source, |
749 const content::NotificationDetails& details) { | 694 const content::NotificationDetails& details) { |
750 DCHECK(type == chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED); | 695 DCHECK(type == chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED); |
751 | 696 |
752 content::Details<const ContentSettingsDetails> settings_details(details); | 697 content::Details<const ContentSettingsDetails> settings_details(details); |
753 const NavigationController& controller = web_contents()->GetController(); | 698 const NavigationController& controller = web_contents()->GetController(); |
754 NavigationEntry* entry = controller.GetVisibleEntry(); | 699 NavigationEntry* entry = controller.GetVisibleEntry(); |
755 GURL entry_url; | 700 GURL entry_url; |
756 if (entry) | 701 if (entry) |
757 entry_url = entry->GetURL(); | 702 entry_url = entry->GetURL(); |
758 if (settings_details.ptr()->update_all() || | 703 if (settings_details.ptr()->update_all() || |
759 // The visible NavigationEntry is the URL in the URL field of a tab. | 704 // The visible NavigationEntry is the URL in the URL field of a tab. |
760 // Currently this should be matched by the |primary_pattern|. | 705 // Currently this should be matched by the |primary_pattern|. |
761 settings_details.ptr()->primary_pattern().Matches(entry_url)) { | 706 settings_details.ptr()->primary_pattern().Matches(entry_url)) { |
762 Profile* profile = | 707 Profile* profile = |
763 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 708 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
764 RendererContentSettingRules rules; | 709 RendererContentSettingRules rules; |
765 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), | 710 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), |
766 &rules); | 711 &rules); |
767 Send(new ChromeViewMsg_SetContentSettingRules(rules)); | 712 Send(new ChromeViewMsg_SetContentSettingRules(rules)); |
768 } | 713 } |
769 } | 714 } |
770 | 715 |
771 void TabSpecificContentSettings::SetPasswordObserver( | |
772 PasswordObserver* observer) { | |
773 password_observer_ = observer; | |
774 } | |
775 | |
776 void TabSpecificContentSettings::NotifyPasswordObserver() { | |
777 if (password_observer_) | |
778 password_observer_->OnPasswordAction(); | |
779 } | |
780 | |
781 void TabSpecificContentSettings::AddSiteDataObserver( | 716 void TabSpecificContentSettings::AddSiteDataObserver( |
782 SiteDataObserver* observer) { | 717 SiteDataObserver* observer) { |
783 observer_list_.AddObserver(observer); | 718 observer_list_.AddObserver(observer); |
784 } | 719 } |
785 | 720 |
786 void TabSpecificContentSettings::RemoveSiteDataObserver( | 721 void TabSpecificContentSettings::RemoveSiteDataObserver( |
787 SiteDataObserver* observer) { | 722 SiteDataObserver* observer) { |
788 observer_list_.RemoveObserver(observer); | 723 observer_list_.RemoveObserver(observer); |
789 } | 724 } |
790 | 725 |
791 void TabSpecificContentSettings::NotifySiteDataObservers() { | 726 void TabSpecificContentSettings::NotifySiteDataObservers() { |
792 FOR_EACH_OBSERVER(SiteDataObserver, observer_list_, OnSiteDataAccessed()); | 727 FOR_EACH_OBSERVER(SiteDataObserver, observer_list_, OnSiteDataAccessed()); |
793 } | 728 } |
OLD | NEW |