Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5146)

Unified Diff: chrome/browser/tab_contents/navigation_metrics_recorder.cc

Issue 2633523003: Record data: URL metrics for mime types that can run JavaScript. (Closed)
Patch Set: Remove extra whitespace Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/tab_contents/navigation_metrics_recorder.cc
diff --git a/chrome/browser/tab_contents/navigation_metrics_recorder.cc b/chrome/browser/tab_contents/navigation_metrics_recorder.cc
index a6c13eb342d26a077178479871344c76f3f0f1a2..d003129b26a8970349f9fbfb7753acc8be2edc18 100644
--- a/chrome/browser/tab_contents/navigation_metrics_recorder.cc
+++ b/chrome/browser/tab_contents/navigation_metrics_recorder.cc
@@ -20,6 +20,7 @@
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/common/frame_navigate_params.h"
+#include "net/base/data_url.h"
#include "url/gurl.h"
#include "url/origin.h"
@@ -27,6 +28,33 @@
#include "base/win/windows_version.h"
#endif
+namespace {
+
+// List of mime types that can run JavaScript.
+static const struct MimeTypePair {
+ const char* const mime_type;
+ NavigationMetricsRecorder::MimeType histogram_value;
+} kScriptingMimeTypes[] = {
+ {"text/html", NavigationMetricsRecorder::MIME_TYPE_HTML},
+ {"application/xhtml+xml", NavigationMetricsRecorder::MIME_TYPE_XHTML},
+ {"application/pdf", NavigationMetricsRecorder::MIME_TYPE_PDF},
+ {"image/svg+xml", NavigationMetricsRecorder::MIME_TYPE_SVG}};
+
+void RecordDataURLMimeType(const std::string& mime_type) {
+ NavigationMetricsRecorder::MimeType value =
+ NavigationMetricsRecorder::MIME_TYPE_OTHER;
+ for (const MimeTypePair& pair : kScriptingMimeTypes) {
+ if (mime_type == pair.mime_type) {
+ value = pair.histogram_value;
+ break;
+ }
+ }
+ UMA_HISTOGRAM_ENUMERATION("Navigation.MainFrameScheme.DataUrl.MimeType",
+ value, NavigationMetricsRecorder::MIME_TYPE_MAX);
+}
+
+} // namespace
+
DEFINE_WEB_CONTENTS_USER_DATA_KEY(NavigationMetricsRecorder);
NavigationMetricsRecorder::NavigationMetricsRecorder(
@@ -61,9 +89,18 @@ void NavigationMetricsRecorder::DidNavigateMainFrame(
// a |data:| URL, either by redirects or user clicking a link.
if (details.entry->GetVirtualURL().SchemeIs(url::kDataScheme) &&
!ui::PageTransitionCoreTypeIs(params.transition,
- ui::PAGE_TRANSITION_TYPED) &&
- !details.previous_url.is_empty()) {
- rappor::SampleDomainAndRegistryFromGURL(
- rappor_service_, "Navigation.Scheme.Data", details.previous_url);
+ ui::PAGE_TRANSITION_TYPED)) {
+ if (!details.previous_url.is_empty()) {
+ rappor::SampleDomainAndRegistryFromGURL(
+ rappor_service_, "Navigation.Scheme.Data", details.previous_url);
+ }
+
+ // Also record the mime type of the data: URL.
+ std::string mime_type;
+ std::string charset;
+ if (net::DataURL::Parse(details.entry->GetVirtualURL(), &mime_type,
+ &charset, nullptr)) {
+ RecordDataURLMimeType(mime_type);
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698