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 | 648 |
693 void TabSpecificContentSettings::DidNavigateMainFrame( | 649 void TabSpecificContentSettings::DidNavigateMainFrame( |
694 const content::LoadCommittedDetails& details, | 650 const content::LoadCommittedDetails& details, |
695 const content::FrameNavigateParams& params) { | 651 const content::FrameNavigateParams& params) { |
696 if (!details.is_in_page) { | 652 if (!details.is_in_page) { |
697 // Clear "blocked" flags. | 653 // Clear "blocked" flags. |
698 ClearBlockedContentSettingsExceptForCookies(); | 654 ClearBlockedContentSettingsExceptForCookies(); |
699 GeolocationDidNavigate(details); | 655 GeolocationDidNavigate(details); |
700 MIDIDidNavigate(details); | 656 MIDIDidNavigate(details); |
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 | 659 |
710 void TabSpecificContentSettings::DidStartProvisionalLoadForFrame( | 660 void TabSpecificContentSettings::DidStartProvisionalLoadForFrame( |
711 int64 frame_id, | 661 int64 frame_id, |
712 int64 parent_frame_id, | 662 int64 parent_frame_id, |
713 bool is_main_frame, | 663 bool is_main_frame, |
714 const GURL& validated_url, | 664 const GURL& validated_url, |
715 bool is_error_page, | 665 bool is_error_page, |
716 bool is_iframe_srcdoc, | 666 bool is_iframe_srcdoc, |
(...skipping 15 matching lines...) Expand all Loading... |
732 bool blocked_by_policy) { | 682 bool blocked_by_policy) { |
733 if (blocked_by_policy) { | 683 if (blocked_by_policy) { |
734 blocked_local_shared_objects_.appcaches()->AddAppCache(manifest_url); | 684 blocked_local_shared_objects_.appcaches()->AddAppCache(manifest_url); |
735 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); | 685 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); |
736 } else { | 686 } else { |
737 allowed_local_shared_objects_.appcaches()->AddAppCache(manifest_url); | 687 allowed_local_shared_objects_.appcaches()->AddAppCache(manifest_url); |
738 OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES); | 688 OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES); |
739 } | 689 } |
740 } | 690 } |
741 | 691 |
742 void TabSpecificContentSettings::SavePassword() { | |
743 DCHECK(form_manager_.get()); | |
744 form_manager_->Save(); | |
745 } | |
746 | |
747 void TabSpecificContentSettings::Observe( | 692 void TabSpecificContentSettings::Observe( |
748 int type, | 693 int type, |
749 const content::NotificationSource& source, | 694 const content::NotificationSource& source, |
750 const content::NotificationDetails& details) { | 695 const content::NotificationDetails& details) { |
751 DCHECK(type == chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED); | 696 DCHECK(type == chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED); |
752 | 697 |
753 content::Details<const ContentSettingsDetails> settings_details(details); | 698 content::Details<const ContentSettingsDetails> settings_details(details); |
754 const NavigationController& controller = web_contents()->GetController(); | 699 const NavigationController& controller = web_contents()->GetController(); |
755 NavigationEntry* entry = controller.GetVisibleEntry(); | 700 NavigationEntry* entry = controller.GetVisibleEntry(); |
756 GURL entry_url; | 701 GURL entry_url; |
757 if (entry) | 702 if (entry) |
758 entry_url = entry->GetURL(); | 703 entry_url = entry->GetURL(); |
759 if (settings_details.ptr()->update_all() || | 704 if (settings_details.ptr()->update_all() || |
760 // The visible NavigationEntry is the URL in the URL field of a tab. | 705 // The visible NavigationEntry is the URL in the URL field of a tab. |
761 // Currently this should be matched by the |primary_pattern|. | 706 // Currently this should be matched by the |primary_pattern|. |
762 settings_details.ptr()->primary_pattern().Matches(entry_url)) { | 707 settings_details.ptr()->primary_pattern().Matches(entry_url)) { |
763 Profile* profile = | 708 Profile* profile = |
764 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 709 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
765 RendererContentSettingRules rules; | 710 RendererContentSettingRules rules; |
766 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), | 711 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), |
767 &rules); | 712 &rules); |
768 Send(new ChromeViewMsg_SetContentSettingRules(rules)); | 713 Send(new ChromeViewMsg_SetContentSettingRules(rules)); |
769 } | 714 } |
770 } | 715 } |
771 | 716 |
772 void TabSpecificContentSettings::SetPasswordObserver( | |
773 PasswordObserver* observer) { | |
774 password_observer_ = observer; | |
775 } | |
776 | |
777 void TabSpecificContentSettings::NotifyPasswordObserver() { | |
778 if (password_observer_) | |
779 password_observer_->OnPasswordAction(); | |
780 } | |
781 | |
782 void TabSpecificContentSettings::AddSiteDataObserver( | 717 void TabSpecificContentSettings::AddSiteDataObserver( |
783 SiteDataObserver* observer) { | 718 SiteDataObserver* observer) { |
784 observer_list_.AddObserver(observer); | 719 observer_list_.AddObserver(observer); |
785 } | 720 } |
786 | 721 |
787 void TabSpecificContentSettings::RemoveSiteDataObserver( | 722 void TabSpecificContentSettings::RemoveSiteDataObserver( |
788 SiteDataObserver* observer) { | 723 SiteDataObserver* observer) { |
789 observer_list_.RemoveObserver(observer); | 724 observer_list_.RemoveObserver(observer); |
790 } | 725 } |
791 | 726 |
792 void TabSpecificContentSettings::NotifySiteDataObservers() { | 727 void TabSpecificContentSettings::NotifySiteDataObservers() { |
793 FOR_EACH_OBSERVER(SiteDataObserver, observer_list_, OnSiteDataAccessed()); | 728 FOR_EACH_OBSERVER(SiteDataObserver, observer_list_, OnSiteDataAccessed()); |
794 } | 729 } |
OLD | NEW |