Chromium Code Reviews| 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" |
| 11 #include "base/metrics/histogram.h" | |
| 11 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h" | 16 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h" |
| 16 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" | 17 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" |
| 17 #include "chrome/browser/browsing_data/browsing_data_database_helper.h" | 18 #include "chrome/browser/browsing_data/browsing_data_database_helper.h" |
| 18 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h" | 19 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h" |
| 19 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h" | 20 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h" |
| 20 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" | 21 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 50 | 51 |
| 51 using content::BrowserThread; | 52 using content::BrowserThread; |
| 52 using content::NavigationController; | 53 using content::NavigationController; |
| 53 using content::NavigationEntry; | 54 using content::NavigationEntry; |
| 54 using content::WebContents; | 55 using content::WebContents; |
| 55 | 56 |
| 56 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabSpecificContentSettings); | 57 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabSpecificContentSettings); |
| 57 | 58 |
| 58 namespace { | 59 namespace { |
| 59 | 60 |
| 61 enum { | |
| 62 INSECURE_CONTENT_DISPLAY = 0, | |
| 63 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE, | |
| 64 INSECURE_CONTENT_DISPLAY_HOST_WWW_GOOGLE, | |
| 65 INSECURE_CONTENT_DISPLAY_HTML, | |
| 66 INSECURE_CONTENT_RUN, | |
| 67 INSECURE_CONTENT_RUN_HOST_GOOGLE, | |
| 68 INSECURE_CONTENT_RUN_HOST_WWW_GOOGLE, | |
| 69 INSECURE_CONTENT_RUN_TARGET_YOUTUBE, | |
| 70 INSECURE_CONTENT_RUN_JS, | |
| 71 INSECURE_CONTENT_RUN_CSS, | |
| 72 INSECURE_CONTENT_RUN_SWF, | |
| 73 INSECURE_CONTENT_DISPLAY_HOST_YOUTUBE, | |
| 74 INSECURE_CONTENT_RUN_HOST_YOUTUBE, | |
| 75 INSECURE_CONTENT_RUN_HOST_GOOGLEUSERCONTENT, | |
| 76 INSECURE_CONTENT_DISPLAY_HOST_MAIL_GOOGLE, | |
| 77 INSECURE_CONTENT_RUN_HOST_MAIL_GOOGLE, | |
| 78 INSECURE_CONTENT_DISPLAY_HOST_PLUS_GOOGLE, | |
| 79 INSECURE_CONTENT_RUN_HOST_PLUS_GOOGLE, | |
| 80 INSECURE_CONTENT_DISPLAY_HOST_DOCS_GOOGLE, | |
| 81 INSECURE_CONTENT_RUN_HOST_DOCS_GOOGLE, | |
| 82 INSECURE_CONTENT_DISPLAY_HOST_SITES_GOOGLE, | |
| 83 INSECURE_CONTENT_RUN_HOST_SITES_GOOGLE, | |
| 84 INSECURE_CONTENT_DISPLAY_HOST_PICASAWEB_GOOGLE, | |
| 85 INSECURE_CONTENT_RUN_HOST_PICASAWEB_GOOGLE, | |
| 86 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_READER, | |
| 87 INSECURE_CONTENT_RUN_HOST_GOOGLE_READER, | |
| 88 INSECURE_CONTENT_DISPLAY_HOST_CODE_GOOGLE, | |
| 89 INSECURE_CONTENT_RUN_HOST_CODE_GOOGLE, | |
| 90 INSECURE_CONTENT_DISPLAY_HOST_GROUPS_GOOGLE, | |
| 91 INSECURE_CONTENT_RUN_HOST_GROUPS_GOOGLE, | |
| 92 INSECURE_CONTENT_DISPLAY_HOST_MAPS_GOOGLE, | |
| 93 INSECURE_CONTENT_RUN_HOST_MAPS_GOOGLE, | |
| 94 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_SUPPORT, | |
| 95 INSECURE_CONTENT_RUN_HOST_GOOGLE_SUPPORT, | |
| 96 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_INTL, | |
| 97 INSECURE_CONTENT_RUN_HOST_GOOGLE_INTL, | |
| 98 INSECURE_CONTENT_NUM_EVENTS | |
| 99 }; | |
| 100 | |
| 101 // Constants for UMA statistic collection. | |
| 102 static const char kWWWDotGoogleDotCom[] = "www.google.com"; | |
| 103 static const char kMailDotGoogleDotCom[] = "mail.google.com"; | |
| 104 static const char kPlusDotGoogleDotCom[] = "plus.google.com"; | |
| 105 static const char kDocsDotGoogleDotCom[] = "docs.google.com"; | |
| 106 static const char kSitesDotGoogleDotCom[] = "sites.google.com"; | |
| 107 static const char kPicasawebDotGoogleDotCom[] = "picasaweb.google.com"; | |
| 108 static const char kCodeDotGoogleDotCom[] = "code.google.com"; | |
| 109 static const char kGroupsDotGoogleDotCom[] = "groups.google.com"; | |
| 110 static const char kMapsDotGoogleDotCom[] = "maps.google.com"; | |
| 111 static const char kWWWDotYoutubeDotCom[] = "www.youtube.com"; | |
| 112 static const char kDotGoogleUserContentDotCom[] = ".googleusercontent.com"; | |
| 113 static const char kGoogleReaderPathPrefix[] = "/reader/"; | |
| 114 static const char kGoogleSupportPathPrefix[] = "/support/"; | |
| 115 static const char kGoogleIntlPathPrefix[] = "/intl/"; | |
| 116 static const char kDotJS[] = ".js"; | |
| 117 static const char kDotCSS[] = ".css"; | |
| 118 static const char kDotSWF[] = ".swf"; | |
| 119 static const char kDotHTML[] = ".html"; | |
| 120 | |
| 121 // Constants for mixed-content blocking. | |
| 122 static const char kGoogleDotCom[] = "google.com"; | |
| 123 | |
| 124 static bool IsHostInDomain(const std::string& host, const std::string& domain) { | |
| 125 return (base::EndsWith(host, domain, base::CompareCase::INSENSITIVE_ASCII) && | |
| 126 (host.length() == domain.length() || | |
| 127 (host.length() > domain.length() && | |
| 128 host[host.length() - domain.length() - 1] == '.'))); | |
| 129 } | |
| 130 | |
| 131 static void SendInsecureContentSignal(int signal) { | |
| 132 UMA_HISTOGRAM_ENUMERATION("SSL.InsecureContent", signal, | |
| 133 INSECURE_CONTENT_NUM_EVENTS); | |
| 134 } | |
| 135 | |
| 60 ContentSettingsUsagesState::CommittedDetails GetCommittedDetails( | 136 ContentSettingsUsagesState::CommittedDetails GetCommittedDetails( |
| 61 const content::LoadCommittedDetails& details) { | 137 const content::LoadCommittedDetails& details) { |
| 62 ContentSettingsUsagesState::CommittedDetails committed_details; | 138 ContentSettingsUsagesState::CommittedDetails committed_details; |
| 63 committed_details.current_url_valid = !!details.entry; | 139 committed_details.current_url_valid = !!details.entry; |
| 64 if (details.entry) | 140 if (details.entry) |
| 65 committed_details.current_url = details.entry->GetURL(); | 141 committed_details.current_url = details.entry->GetURL(); |
| 66 committed_details.previous_url = details.previous_url; | 142 committed_details.previous_url = details.previous_url; |
| 67 return committed_details; | 143 return committed_details; |
| 68 } | 144 } |
| 69 | 145 |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 787 bool blocked_by_policy) { | 863 bool blocked_by_policy) { |
| 788 if (blocked_by_policy) { | 864 if (blocked_by_policy) { |
| 789 blocked_local_shared_objects_.appcaches()->AddAppCache(manifest_url); | 865 blocked_local_shared_objects_.appcaches()->AddAppCache(manifest_url); |
| 790 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES); | 866 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES); |
| 791 } else { | 867 } else { |
| 792 allowed_local_shared_objects_.appcaches()->AddAppCache(manifest_url); | 868 allowed_local_shared_objects_.appcaches()->AddAppCache(manifest_url); |
| 793 OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES); | 869 OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES); |
| 794 } | 870 } |
| 795 } | 871 } |
| 796 | 872 |
| 873 void TabSpecificContentSettings::OnTriedDisplayingInsecureContent( | |
| 874 content::RenderFrameHost* rfh, | |
| 875 const GURL& origin, | |
| 876 const GURL& url) { | |
|
alexmos
2016/01/09 01:39:02
It's a little unclear what origin and url refer to
| |
| 877 std::string origin_host(origin.host()); | |
| 878 GURL frame_gurl(rfh->GetLastCommittedURL()); | |
| 879 DCHECK_EQ(frame_gurl.host(), origin_host); | |
|
alexmos
2016/01/09 01:39:02
Hmm, I'm thinking there may be a race here, where
Charlie Reis
2016/01/12 18:10:47
Yes, this race is possible. See the documentation
| |
| 880 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY); | |
| 881 | |
| 882 if (IsHostInDomain(origin_host, kGoogleDotCom)) { | |
| 883 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_GOOGLE); | |
| 884 if (base::StartsWith(frame_gurl.path(), kGoogleSupportPathPrefix, | |
| 885 base::CompareCase::INSENSITIVE_ASCII)) { | |
| 886 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_SUPPORT); | |
| 887 } else if (base::StartsWith(frame_gurl.path(), kGoogleIntlPathPrefix, | |
| 888 base::CompareCase::INSENSITIVE_ASCII)) { | |
| 889 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_INTL); | |
| 890 } | |
| 891 } | |
| 892 | |
| 893 if (origin_host == kWWWDotGoogleDotCom) { | |
| 894 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_WWW_GOOGLE); | |
| 895 if (base::StartsWith(frame_gurl.path(), kGoogleReaderPathPrefix, | |
|
alexmos
2016/01/09 01:39:02
Another thought: there are three uses of frame_gur
| |
| 896 base::CompareCase::INSENSITIVE_ASCII)) | |
| 897 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_READER); | |
| 898 } else if (origin_host == kMailDotGoogleDotCom) { | |
| 899 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_MAIL_GOOGLE); | |
| 900 } else if (origin_host == kPlusDotGoogleDotCom) { | |
| 901 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_PLUS_GOOGLE); | |
| 902 } else if (origin_host == kDocsDotGoogleDotCom) { | |
| 903 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_DOCS_GOOGLE); | |
| 904 } else if (origin_host == kSitesDotGoogleDotCom) { | |
| 905 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_SITES_GOOGLE); | |
| 906 } else if (origin_host == kPicasawebDotGoogleDotCom) { | |
| 907 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_PICASAWEB_GOOGLE); | |
| 908 } else if (origin_host == kCodeDotGoogleDotCom) { | |
| 909 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_CODE_GOOGLE); | |
| 910 } else if (origin_host == kGroupsDotGoogleDotCom) { | |
| 911 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_GROUPS_GOOGLE); | |
| 912 } else if (origin_host == kMapsDotGoogleDotCom) { | |
| 913 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_MAPS_GOOGLE); | |
| 914 } else if (origin_host == kWWWDotYoutubeDotCom) { | |
| 915 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_YOUTUBE); | |
| 916 } | |
| 917 | |
| 918 if (base::EndsWith(url.path(), kDotHTML, | |
| 919 base::CompareCase::INSENSITIVE_ASCII)) | |
| 920 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HTML); | |
| 921 } | |
| 922 | |
| 923 void TabSpecificContentSettings::OnTriedRunningInsecureContent( | |
| 924 content::RenderFrameHost* rfh, | |
| 925 const GURL& origin, | |
| 926 const GURL& url) { | |
| 927 std::string origin_host(origin.host()); | |
| 928 GURL frame_gurl(rfh->GetLastCommittedURL()); | |
| 929 DCHECK_EQ(frame_gurl.host(), origin_host); | |
| 930 | |
| 931 bool is_google = IsHostInDomain(origin_host, kGoogleDotCom); | |
| 932 if (is_google) { | |
| 933 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GOOGLE); | |
| 934 if (base::StartsWith(frame_gurl.path(), kGoogleSupportPathPrefix, | |
| 935 base::CompareCase::INSENSITIVE_ASCII)) { | |
| 936 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GOOGLE_SUPPORT); | |
| 937 } else if (base::StartsWith(frame_gurl.path(), kGoogleIntlPathPrefix, | |
| 938 base::CompareCase::INSENSITIVE_ASCII)) { | |
| 939 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GOOGLE_INTL); | |
| 940 } | |
| 941 } | |
| 942 | |
| 943 if (origin_host == kWWWDotGoogleDotCom) { | |
| 944 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_WWW_GOOGLE); | |
| 945 if (base::StartsWith(frame_gurl.path(), kGoogleReaderPathPrefix, | |
| 946 base::CompareCase::INSENSITIVE_ASCII)) | |
| 947 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GOOGLE_READER); | |
| 948 } else if (origin_host == kMailDotGoogleDotCom) { | |
| 949 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_MAIL_GOOGLE); | |
| 950 } else if (origin_host == kPlusDotGoogleDotCom) { | |
| 951 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_PLUS_GOOGLE); | |
| 952 } else if (origin_host == kDocsDotGoogleDotCom) { | |
| 953 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_DOCS_GOOGLE); | |
| 954 } else if (origin_host == kSitesDotGoogleDotCom) { | |
| 955 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_SITES_GOOGLE); | |
| 956 } else if (origin_host == kPicasawebDotGoogleDotCom) { | |
| 957 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_PICASAWEB_GOOGLE); | |
| 958 } else if (origin_host == kCodeDotGoogleDotCom) { | |
| 959 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_CODE_GOOGLE); | |
| 960 } else if (origin_host == kGroupsDotGoogleDotCom) { | |
| 961 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GROUPS_GOOGLE); | |
| 962 } else if (origin_host == kMapsDotGoogleDotCom) { | |
| 963 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_MAPS_GOOGLE); | |
| 964 } else if (origin_host == kWWWDotYoutubeDotCom) { | |
| 965 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_YOUTUBE); | |
| 966 } else if (base::EndsWith(origin_host, kDotGoogleUserContentDotCom, | |
| 967 base::CompareCase::INSENSITIVE_ASCII)) { | |
| 968 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GOOGLEUSERCONTENT); | |
| 969 } | |
| 970 | |
| 971 if (url.host() == kWWWDotYoutubeDotCom) | |
| 972 SendInsecureContentSignal(INSECURE_CONTENT_RUN_TARGET_YOUTUBE); | |
| 973 | |
| 974 if (base::EndsWith(url.path(), kDotJS, base::CompareCase::INSENSITIVE_ASCII)) | |
| 975 SendInsecureContentSignal(INSECURE_CONTENT_RUN_JS); | |
| 976 else if (base::EndsWith(url.path(), kDotCSS, | |
| 977 base::CompareCase::INSENSITIVE_ASCII)) | |
| 978 SendInsecureContentSignal(INSECURE_CONTENT_RUN_CSS); | |
| 979 else if (base::EndsWith(url.path(), kDotSWF, | |
| 980 base::CompareCase::INSENSITIVE_ASCII)) | |
| 981 SendInsecureContentSignal(INSECURE_CONTENT_RUN_SWF); | |
| 982 } | |
| 983 | |
| 797 void TabSpecificContentSettings::AddSiteDataObserver( | 984 void TabSpecificContentSettings::AddSiteDataObserver( |
| 798 SiteDataObserver* observer) { | 985 SiteDataObserver* observer) { |
| 799 observer_list_.AddObserver(observer); | 986 observer_list_.AddObserver(observer); |
| 800 } | 987 } |
| 801 | 988 |
| 802 void TabSpecificContentSettings::RemoveSiteDataObserver( | 989 void TabSpecificContentSettings::RemoveSiteDataObserver( |
| 803 SiteDataObserver* observer) { | 990 SiteDataObserver* observer) { |
| 804 observer_list_.RemoveObserver(observer); | 991 observer_list_.RemoveObserver(observer); |
| 805 } | 992 } |
| 806 | 993 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 845 static_cast<MicrophoneCameraStateFlags>( | 1032 static_cast<MicrophoneCameraStateFlags>( |
| 846 TabSpecificContentSettings::MICROPHONE_ACCESSED | | 1033 TabSpecificContentSettings::MICROPHONE_ACCESSED | |
| 847 TabSpecificContentSettings::MICROPHONE_BLOCKED | | 1034 TabSpecificContentSettings::MICROPHONE_BLOCKED | |
| 848 TabSpecificContentSettings::CAMERA_ACCESSED | | 1035 TabSpecificContentSettings::CAMERA_ACCESSED | |
| 849 TabSpecificContentSettings::CAMERA_BLOCKED); | 1036 TabSpecificContentSettings::CAMERA_BLOCKED); |
| 850 OnMediaStreamPermissionSet( | 1037 OnMediaStreamPermissionSet( |
| 851 web_contents()->GetLastCommittedURL(), | 1038 web_contents()->GetLastCommittedURL(), |
| 852 media_blocked, | 1039 media_blocked, |
| 853 std::string(), std::string(), std::string(), std::string()); | 1040 std::string(), std::string(), std::string(), std::string()); |
| 854 } | 1041 } |
| OLD | NEW |