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/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 LOG(ERROR) << ">> MIME TYPE: " << mime_type; | |
|
Avi (use Gerrit)
2017/01/13 16:52:52
You need to remove logging lines before committing
meacer
2017/01/13 18:37:12
Done.
| |
| 53 UMA_HISTOGRAM_ENUMERATION("Navigation.MainFrameScheme.DataUrl.MimeType", | |
| 54 value, NavigationMetricsRecorder::MIME_TYPE_MAX); | |
| 55 } | |
| 56 | |
| 57 } // namespace | |
| 58 | |
| 30 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NavigationMetricsRecorder); | 59 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NavigationMetricsRecorder); |
| 31 | 60 |
| 32 NavigationMetricsRecorder::NavigationMetricsRecorder( | 61 NavigationMetricsRecorder::NavigationMetricsRecorder( |
| 33 content::WebContents* web_contents) | 62 content::WebContents* web_contents) |
| 34 : content::WebContentsObserver(web_contents), | 63 : content::WebContentsObserver(web_contents), |
| 35 rappor_service_(g_browser_process->rappor_service()) {} | 64 rappor_service_(g_browser_process->rappor_service()) {} |
| 36 | 65 |
| 37 NavigationMetricsRecorder::~NavigationMetricsRecorder() { | 66 NavigationMetricsRecorder::~NavigationMetricsRecorder() { |
| 38 } | 67 } |
| 39 | 68 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 54 bool have_already_seen_origin = service->Insert(origin); | 83 bool have_already_seen_origin = service->Insert(origin); |
| 55 | 84 |
| 56 navigation_metrics::RecordMainFrameNavigation( | 85 navigation_metrics::RecordMainFrameNavigation( |
| 57 details.entry->GetVirtualURL(), details.is_in_page, | 86 details.entry->GetVirtualURL(), details.is_in_page, |
| 58 context->IsOffTheRecord(), have_already_seen_origin); | 87 context->IsOffTheRecord(), have_already_seen_origin); |
| 59 | 88 |
| 60 // Record the domain and registry of the URL that resulted in a navigation to | 89 // 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. | 90 // a |data:| URL, either by redirects or user clicking a link. |
| 62 if (details.entry->GetVirtualURL().SchemeIs(url::kDataScheme) && | 91 if (details.entry->GetVirtualURL().SchemeIs(url::kDataScheme) && |
| 63 !ui::PageTransitionCoreTypeIs(params.transition, | 92 !ui::PageTransitionCoreTypeIs(params.transition, |
| 64 ui::PAGE_TRANSITION_TYPED) && | 93 ui::PAGE_TRANSITION_TYPED)) { |
| 65 !details.previous_url.is_empty()) { | 94 if (!details.previous_url.is_empty()) { |
| 66 rappor::SampleDomainAndRegistryFromGURL( | 95 rappor::SampleDomainAndRegistryFromGURL( |
| 67 rappor_service_, "Navigation.Scheme.Data", details.previous_url); | 96 rappor_service_, "Navigation.Scheme.Data", details.previous_url); |
| 97 } | |
| 98 | |
| 99 // Also record the mime type of the data: URL. | |
| 100 std::string mime_type; | |
| 101 std::string charset; | |
| 102 if (net::DataURL::Parse(details.entry->GetVirtualURL(), &mime_type, | |
| 103 &charset, nullptr)) { | |
| 104 RecordDataURLMimeType(mime_type); | |
| 105 } | |
| 68 } | 106 } |
| 69 } | 107 } |
| OLD | NEW |