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

Side by Side 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 logging 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 unified diff | Download patch
OLDNEW
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/tab_contents/navigation_metrics_recorder.h" 5 #include "chrome/browser/tab_contents/navigation_metrics_recorder.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/tab_contents/origins_seen_service_factory.h" 10 #include "chrome/browser/tab_contents/origins_seen_service_factory.h"
11 #include "components/navigation_metrics/navigation_metrics.h" 11 #include "components/navigation_metrics/navigation_metrics.h"
12 #include "components/navigation_metrics/origins_seen_service.h" 12 #include "components/navigation_metrics/origins_seen_service.h"
13 #include "components/rappor/public/rappor_utils.h" 13 #include "components/rappor/public/rappor_utils.h"
14 #include "components/rappor/rappor_service_impl.h" 14 #include "components/rappor/rappor_service_impl.h"
15 #include "content/public/browser/browser_context.h" 15 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/navigation_details.h" 17 #include "content/public/browser/navigation_details.h"
18 #include "content/public/browser/navigation_entry.h" 18 #include "content/public/browser/navigation_entry.h"
19 #include "content/public/browser/render_view_host.h" 19 #include "content/public/browser/render_view_host.h"
20 #include "content/public/browser/render_widget_host.h" 20 #include "content/public/browser/render_widget_host.h"
21 #include "content/public/browser/render_widget_host_view.h" 21 #include "content/public/browser/render_widget_host_view.h"
22 #include "content/public/common/frame_navigate_params.h" 22 #include "content/public/common/frame_navigate_params.h"
23 #include "net/base/data_url.h"
23 #include "url/gurl.h" 24 #include "url/gurl.h"
24 #include "url/origin.h" 25 #include "url/origin.h"
25 26
26 #if defined(OS_WIN) 27 #if defined(OS_WIN)
27 #include "base/win/windows_version.h" 28 #include "base/win/windows_version.h"
28 #endif 29 #endif
29 30
31 namespace {
32
33 // List of mime types that can run JavaScript.
34 static const struct MimeTypePair {
35 const char* const mime_type;
36 NavigationMetricsRecorder::MimeType histogram_value;
37 } kScriptingMimeTypes[] = {
38 {"text/html", NavigationMetricsRecorder::MIME_TYPE_HTML},
39 {"application/xhtml+xml", NavigationMetricsRecorder::MIME_TYPE_XHTML},
40 {"application/pdf", NavigationMetricsRecorder::MIME_TYPE_PDF},
41 {"image/svg+xml", NavigationMetricsRecorder::MIME_TYPE_SVG}};
42
43 void RecordDataURLMimeType(const std::string& mime_type) {
44 NavigationMetricsRecorder::MimeType value =
45 NavigationMetricsRecorder::MIME_TYPE_OTHER;
46 for (const MimeTypePair& pair : kScriptingMimeTypes) {
47 if (mime_type == pair.mime_type) {
48 value = pair.histogram_value;
49 break;
50 }
51 }
52 UMA_HISTOGRAM_ENUMERATION("Navigation.MainFrameScheme.DataUrl.MimeType",
53 value, NavigationMetricsRecorder::MIME_TYPE_MAX);
54 }
55
56 } // namespace
57
30 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NavigationMetricsRecorder); 58 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NavigationMetricsRecorder);
31 59
32 NavigationMetricsRecorder::NavigationMetricsRecorder( 60 NavigationMetricsRecorder::NavigationMetricsRecorder(
33 content::WebContents* web_contents) 61 content::WebContents* web_contents)
34 : content::WebContentsObserver(web_contents), 62 : content::WebContentsObserver(web_contents),
35 rappor_service_(g_browser_process->rappor_service()) {} 63 rappor_service_(g_browser_process->rappor_service()) {}
36 64
37 NavigationMetricsRecorder::~NavigationMetricsRecorder() { 65 NavigationMetricsRecorder::~NavigationMetricsRecorder() {
38 } 66 }
39 67
(...skipping 14 matching lines...) Expand all
54 bool have_already_seen_origin = service->Insert(origin); 82 bool have_already_seen_origin = service->Insert(origin);
55 83
56 navigation_metrics::RecordMainFrameNavigation( 84 navigation_metrics::RecordMainFrameNavigation(
57 details.entry->GetVirtualURL(), details.is_in_page, 85 details.entry->GetVirtualURL(), details.is_in_page,
58 context->IsOffTheRecord(), have_already_seen_origin); 86 context->IsOffTheRecord(), have_already_seen_origin);
59 87
60 // Record the domain and registry of the URL that resulted in a navigation to 88 // Record the domain and registry of the URL that resulted in a navigation to
61 // a |data:| URL, either by redirects or user clicking a link. 89 // a |data:| URL, either by redirects or user clicking a link.
62 if (details.entry->GetVirtualURL().SchemeIs(url::kDataScheme) && 90 if (details.entry->GetVirtualURL().SchemeIs(url::kDataScheme) &&
63 !ui::PageTransitionCoreTypeIs(params.transition, 91 !ui::PageTransitionCoreTypeIs(params.transition,
64 ui::PAGE_TRANSITION_TYPED) && 92 ui::PAGE_TRANSITION_TYPED)) {
65 !details.previous_url.is_empty()) { 93 if (!details.previous_url.is_empty()) {
66 rappor::SampleDomainAndRegistryFromGURL( 94 rappor::SampleDomainAndRegistryFromGURL(
67 rappor_service_, "Navigation.Scheme.Data", details.previous_url); 95 rappor_service_, "Navigation.Scheme.Data", details.previous_url);
96 }
97
98 // Also record the mime type of the data: URL.
99 std::string mime_type;
100 std::string charset;
101 if (net::DataURL::Parse(details.entry->GetVirtualURL(), &mime_type,
102 &charset, nullptr)) {
103 RecordDataURLMimeType(mime_type);
104 }
68 } 105 }
69 } 106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698