Chromium Code Reviews| Index: chrome/browser/content_settings/tab_specific_content_settings.cc |
| diff --git a/chrome/browser/content_settings/tab_specific_content_settings.cc b/chrome/browser/content_settings/tab_specific_content_settings.cc |
| index 5edd14e06bcfeae630434bd456813b13e19fd08a..a13cf8f7a9ef2ee3a40091f53aaeb6aa0f1bfb4b 100644 |
| --- a/chrome/browser/content_settings/tab_specific_content_settings.cc |
| +++ b/chrome/browser/content_settings/tab_specific_content_settings.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/command_line.h" |
| #include "base/lazy_instance.h" |
| +#include "base/metrics/histogram.h" |
| #include "base/prefs/pref_service.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| @@ -57,6 +58,81 @@ DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabSpecificContentSettings); |
| namespace { |
| +enum { |
| + INSECURE_CONTENT_DISPLAY = 0, |
| + INSECURE_CONTENT_DISPLAY_HOST_GOOGLE, |
| + INSECURE_CONTENT_DISPLAY_HOST_WWW_GOOGLE, |
| + INSECURE_CONTENT_DISPLAY_HTML, |
| + INSECURE_CONTENT_RUN, |
| + INSECURE_CONTENT_RUN_HOST_GOOGLE, |
| + INSECURE_CONTENT_RUN_HOST_WWW_GOOGLE, |
| + INSECURE_CONTENT_RUN_TARGET_YOUTUBE, |
| + INSECURE_CONTENT_RUN_JS, |
| + INSECURE_CONTENT_RUN_CSS, |
| + INSECURE_CONTENT_RUN_SWF, |
| + INSECURE_CONTENT_DISPLAY_HOST_YOUTUBE, |
| + INSECURE_CONTENT_RUN_HOST_YOUTUBE, |
| + INSECURE_CONTENT_RUN_HOST_GOOGLEUSERCONTENT, |
| + INSECURE_CONTENT_DISPLAY_HOST_MAIL_GOOGLE, |
| + INSECURE_CONTENT_RUN_HOST_MAIL_GOOGLE, |
| + INSECURE_CONTENT_DISPLAY_HOST_PLUS_GOOGLE, |
| + INSECURE_CONTENT_RUN_HOST_PLUS_GOOGLE, |
| + INSECURE_CONTENT_DISPLAY_HOST_DOCS_GOOGLE, |
| + INSECURE_CONTENT_RUN_HOST_DOCS_GOOGLE, |
| + INSECURE_CONTENT_DISPLAY_HOST_SITES_GOOGLE, |
| + INSECURE_CONTENT_RUN_HOST_SITES_GOOGLE, |
| + INSECURE_CONTENT_DISPLAY_HOST_PICASAWEB_GOOGLE, |
| + INSECURE_CONTENT_RUN_HOST_PICASAWEB_GOOGLE, |
| + INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_READER, |
| + INSECURE_CONTENT_RUN_HOST_GOOGLE_READER, |
| + INSECURE_CONTENT_DISPLAY_HOST_CODE_GOOGLE, |
| + INSECURE_CONTENT_RUN_HOST_CODE_GOOGLE, |
| + INSECURE_CONTENT_DISPLAY_HOST_GROUPS_GOOGLE, |
| + INSECURE_CONTENT_RUN_HOST_GROUPS_GOOGLE, |
| + INSECURE_CONTENT_DISPLAY_HOST_MAPS_GOOGLE, |
| + INSECURE_CONTENT_RUN_HOST_MAPS_GOOGLE, |
| + INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_SUPPORT, |
| + INSECURE_CONTENT_RUN_HOST_GOOGLE_SUPPORT, |
| + INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_INTL, |
| + INSECURE_CONTENT_RUN_HOST_GOOGLE_INTL, |
| + INSECURE_CONTENT_NUM_EVENTS |
| +}; |
| + |
| +// Constants for UMA statistic collection. |
| +static const char kWWWDotGoogleDotCom[] = "www.google.com"; |
| +static const char kMailDotGoogleDotCom[] = "mail.google.com"; |
| +static const char kPlusDotGoogleDotCom[] = "plus.google.com"; |
| +static const char kDocsDotGoogleDotCom[] = "docs.google.com"; |
| +static const char kSitesDotGoogleDotCom[] = "sites.google.com"; |
| +static const char kPicasawebDotGoogleDotCom[] = "picasaweb.google.com"; |
| +static const char kCodeDotGoogleDotCom[] = "code.google.com"; |
| +static const char kGroupsDotGoogleDotCom[] = "groups.google.com"; |
| +static const char kMapsDotGoogleDotCom[] = "maps.google.com"; |
| +static const char kWWWDotYoutubeDotCom[] = "www.youtube.com"; |
| +static const char kDotGoogleUserContentDotCom[] = ".googleusercontent.com"; |
| +static const char kGoogleReaderPathPrefix[] = "/reader/"; |
| +static const char kGoogleSupportPathPrefix[] = "/support/"; |
| +static const char kGoogleIntlPathPrefix[] = "/intl/"; |
| +static const char kDotJS[] = ".js"; |
| +static const char kDotCSS[] = ".css"; |
| +static const char kDotSWF[] = ".swf"; |
| +static const char kDotHTML[] = ".html"; |
| + |
| +// Constants for mixed-content blocking. |
| +static const char kGoogleDotCom[] = "google.com"; |
| + |
| +static bool IsHostInDomain(const std::string& host, const std::string& domain) { |
| + return (base::EndsWith(host, domain, base::CompareCase::INSENSITIVE_ASCII) && |
| + (host.length() == domain.length() || |
| + (host.length() > domain.length() && |
| + host[host.length() - domain.length() - 1] == '.'))); |
| +} |
| + |
| +static void SendInsecureContentSignal(int signal) { |
| + UMA_HISTOGRAM_ENUMERATION("SSL.InsecureContent", signal, |
| + INSECURE_CONTENT_NUM_EVENTS); |
| +} |
| + |
| ContentSettingsUsagesState::CommittedDetails GetCommittedDetails( |
| const content::LoadCommittedDetails& details) { |
| ContentSettingsUsagesState::CommittedDetails committed_details; |
| @@ -794,6 +870,117 @@ void TabSpecificContentSettings::AppCacheAccessed(const GURL& manifest_url, |
| } |
| } |
| +void TabSpecificContentSettings::OnTriedDisplayingInsecureContent( |
| + content::RenderFrameHost* rfh, |
| + const GURL& origin, |
| + const GURL& url) { |
|
alexmos
2016/01/09 01:39:02
It's a little unclear what origin and url refer to
|
| + std::string origin_host(origin.host()); |
| + GURL frame_gurl(rfh->GetLastCommittedURL()); |
| + 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
|
| + SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY); |
| + |
| + if (IsHostInDomain(origin_host, kGoogleDotCom)) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_GOOGLE); |
| + if (base::StartsWith(frame_gurl.path(), kGoogleSupportPathPrefix, |
| + base::CompareCase::INSENSITIVE_ASCII)) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_SUPPORT); |
| + } else if (base::StartsWith(frame_gurl.path(), kGoogleIntlPathPrefix, |
| + base::CompareCase::INSENSITIVE_ASCII)) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_INTL); |
| + } |
| + } |
| + |
| + if (origin_host == kWWWDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_WWW_GOOGLE); |
| + if (base::StartsWith(frame_gurl.path(), kGoogleReaderPathPrefix, |
|
alexmos
2016/01/09 01:39:02
Another thought: there are three uses of frame_gur
|
| + base::CompareCase::INSENSITIVE_ASCII)) |
| + SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_READER); |
| + } else if (origin_host == kMailDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_MAIL_GOOGLE); |
| + } else if (origin_host == kPlusDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_PLUS_GOOGLE); |
| + } else if (origin_host == kDocsDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_DOCS_GOOGLE); |
| + } else if (origin_host == kSitesDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_SITES_GOOGLE); |
| + } else if (origin_host == kPicasawebDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_PICASAWEB_GOOGLE); |
| + } else if (origin_host == kCodeDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_CODE_GOOGLE); |
| + } else if (origin_host == kGroupsDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_GROUPS_GOOGLE); |
| + } else if (origin_host == kMapsDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_MAPS_GOOGLE); |
| + } else if (origin_host == kWWWDotYoutubeDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_YOUTUBE); |
| + } |
| + |
| + if (base::EndsWith(url.path(), kDotHTML, |
| + base::CompareCase::INSENSITIVE_ASCII)) |
| + SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HTML); |
| +} |
| + |
| +void TabSpecificContentSettings::OnTriedRunningInsecureContent( |
| + content::RenderFrameHost* rfh, |
| + const GURL& origin, |
| + const GURL& url) { |
| + std::string origin_host(origin.host()); |
| + GURL frame_gurl(rfh->GetLastCommittedURL()); |
| + DCHECK_EQ(frame_gurl.host(), origin_host); |
| + |
| + bool is_google = IsHostInDomain(origin_host, kGoogleDotCom); |
| + if (is_google) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GOOGLE); |
| + if (base::StartsWith(frame_gurl.path(), kGoogleSupportPathPrefix, |
| + base::CompareCase::INSENSITIVE_ASCII)) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GOOGLE_SUPPORT); |
| + } else if (base::StartsWith(frame_gurl.path(), kGoogleIntlPathPrefix, |
| + base::CompareCase::INSENSITIVE_ASCII)) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GOOGLE_INTL); |
| + } |
| + } |
| + |
| + if (origin_host == kWWWDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_WWW_GOOGLE); |
| + if (base::StartsWith(frame_gurl.path(), kGoogleReaderPathPrefix, |
| + base::CompareCase::INSENSITIVE_ASCII)) |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GOOGLE_READER); |
| + } else if (origin_host == kMailDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_MAIL_GOOGLE); |
| + } else if (origin_host == kPlusDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_PLUS_GOOGLE); |
| + } else if (origin_host == kDocsDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_DOCS_GOOGLE); |
| + } else if (origin_host == kSitesDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_SITES_GOOGLE); |
| + } else if (origin_host == kPicasawebDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_PICASAWEB_GOOGLE); |
| + } else if (origin_host == kCodeDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_CODE_GOOGLE); |
| + } else if (origin_host == kGroupsDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GROUPS_GOOGLE); |
| + } else if (origin_host == kMapsDotGoogleDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_MAPS_GOOGLE); |
| + } else if (origin_host == kWWWDotYoutubeDotCom) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_YOUTUBE); |
| + } else if (base::EndsWith(origin_host, kDotGoogleUserContentDotCom, |
| + base::CompareCase::INSENSITIVE_ASCII)) { |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GOOGLEUSERCONTENT); |
| + } |
| + |
| + if (url.host() == kWWWDotYoutubeDotCom) |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_TARGET_YOUTUBE); |
| + |
| + if (base::EndsWith(url.path(), kDotJS, base::CompareCase::INSENSITIVE_ASCII)) |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_JS); |
| + else if (base::EndsWith(url.path(), kDotCSS, |
| + base::CompareCase::INSENSITIVE_ASCII)) |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_CSS); |
| + else if (base::EndsWith(url.path(), kDotSWF, |
| + base::CompareCase::INSENSITIVE_ASCII)) |
| + SendInsecureContentSignal(INSECURE_CONTENT_RUN_SWF); |
| +} |
| + |
| void TabSpecificContentSettings::AddSiteDataObserver( |
| SiteDataObserver* observer) { |
| observer_list_.AddObserver(observer); |