OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/renderer/pepper/pepper_uma_host.h" | 5 #include "chrome/renderer/pepper/pepper_uma_host.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/sha1.h" | 8 #include "base/sha1.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "chrome/common/chrome_content_client.h" |
10 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/render_messages.h" |
12 #include "chrome/renderer/chrome_content_renderer_client.h" | 13 #include "chrome/renderer/chrome_content_renderer_client.h" |
13 #include "content/public/renderer/pepper_plugin_instance.h" | 14 #include "content/public/renderer/pepper_plugin_instance.h" |
14 #include "content/public/renderer/render_thread.h" | 15 #include "content/public/renderer/render_thread.h" |
15 #include "content/public/renderer/renderer_ppapi_host.h" | 16 #include "content/public/renderer/renderer_ppapi_host.h" |
16 #include "ppapi/c/pp_errors.h" | 17 #include "ppapi/c/pp_errors.h" |
17 #include "ppapi/host/dispatch_host_message.h" | 18 #include "ppapi/host/dispatch_host_message.h" |
18 #include "ppapi/host/host_message_context.h" | 19 #include "ppapi/host/host_message_context.h" |
19 #include "ppapi/host/ppapi_host.h" | 20 #include "ppapi/host/ppapi_host.h" |
20 #include "ppapi/proxy/ppapi_messages.h" | 21 #include "ppapi/proxy/ppapi_messages.h" |
21 | 22 |
22 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 23 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
23 | 24 |
24 #if defined(ENABLE_EXTENSIONS) | 25 #if defined(ENABLE_EXTENSIONS) |
25 #include "extensions/common/constants.h" | 26 #include "extensions/common/constants.h" |
26 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
27 #endif // defined(ENABLE_EXTENSIONS) | 28 #endif // defined(ENABLE_EXTENSIONS) |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 const char* const kPredefinedAllowedUMAOrigins[] = { | 32 const char* const kPredefinedAllowedUMAOrigins[] = { |
32 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see http://crbug.com/317833 | 33 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see http://crbug.com/317833 |
33 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see http://crbug.com/317833 | 34 "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see http://crbug.com/317833 |
34 }; | 35 }; |
35 | 36 |
36 const char* const kWhitelistedHistogramPrefixes[] = { | 37 const char* const kWhitelistedHistogramPrefixes[] = { |
37 "22F67DA2061FFC4DC9A4974036348D9C38C22919" // see http://crbug.com/390221 | 38 "22F67DA2061FFC4DC9A4974036348D9C38C22919", // see http://crbug.com/390221 |
38 }; | 39 }; |
39 | 40 |
40 const char* const kWhitelistedPluginBaseNames[] = { | 41 const char* const kWhitelistedPluginBaseNames[] = { |
41 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) | 42 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) |
42 kWidevineCdmAdapterFileName, // see http://crbug.com/368743 | 43 kWidevineCdmAdapterFileName, // see http://crbug.com/368743 |
43 // and http://crbug.com/410630 | 44 // and http://crbug.com/410630 |
44 #endif | 45 #endif |
45 "libpdf.so" // see http://crbug.com/405305 | 46 ChromeContentClient::kPDFPluginPath, |
46 }; | 47 }; |
47 | 48 |
48 std::string HashPrefix(const std::string& histogram) { | 49 std::string HashPrefix(const std::string& histogram) { |
49 const std::string id_hash = | 50 const std::string id_hash = |
50 base::SHA1HashString(histogram.substr(0, histogram.find('.'))); | 51 base::SHA1HashString(histogram.substr(0, histogram.find('.'))); |
51 DCHECK_EQ(id_hash.length(), base::kSHA1Length); | 52 DCHECK_EQ(id_hash.length(), base::kSHA1Length); |
52 return base::HexEncode(id_hash.c_str(), id_hash.length()); | 53 return base::HexEncode(id_hash.c_str(), id_hash.length()); |
53 } | 54 } |
54 | 55 |
55 } // namespace | 56 } // namespace |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 return false; | 100 return false; |
100 #endif | 101 #endif |
101 } | 102 } |
102 | 103 |
103 bool PepperUMAHost::IsHistogramAllowed(const std::string& histogram) { | 104 bool PepperUMAHost::IsHistogramAllowed(const std::string& histogram) { |
104 if (is_plugin_in_process_ && histogram.find("NaCl.") == 0) { | 105 if (is_plugin_in_process_ && histogram.find("NaCl.") == 0) { |
105 return true; | 106 return true; |
106 } | 107 } |
107 | 108 |
108 if (IsPluginWhitelisted() && | 109 if (IsPluginWhitelisted() && |
109 allowed_histogram_prefixes_.find(HashPrefix(histogram)) != | 110 ContainsKey(allowed_histogram_prefixes_, HashPrefix(histogram))) { |
110 allowed_histogram_prefixes_.end()) { | |
111 return true; | 111 return true; |
112 } | 112 } |
113 | 113 |
114 if (allowed_plugin_base_names_.find(plugin_base_name_.MaybeAsASCII()) != | 114 if (ContainsKey(allowed_plugin_base_names_, |
115 allowed_plugin_base_names_.end()) { | 115 plugin_base_name_.MaybeAsASCII())) { |
116 return true; | 116 return true; |
117 } | 117 } |
118 | 118 |
119 LOG(ERROR) << "Host or histogram name is not allowed to use the UMA API."; | 119 LOG(ERROR) << "Host or histogram name is not allowed to use the UMA API."; |
120 return false; | 120 return false; |
121 } | 121 } |
122 | 122 |
123 #define RETURN_IF_BAD_ARGS(_min, _max, _buckets) \ | 123 #define RETURN_IF_BAD_ARGS(_min, _max, _buckets) \ |
124 do { \ | 124 do { \ |
125 if (_min >= _max || _buckets <= 1) \ | 125 if (_min >= _max || _buckets <= 1) \ |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 ppapi::host::HostMessageContext* context) { | 203 ppapi::host::HostMessageContext* context) { |
204 if (!IsPluginWhitelisted()) | 204 if (!IsPluginWhitelisted()) |
205 return PP_ERROR_NOACCESS; | 205 return PP_ERROR_NOACCESS; |
206 bool enabled = false; | 206 bool enabled = false; |
207 content::RenderThread::Get()->Send( | 207 content::RenderThread::Get()->Send( |
208 new ChromeViewHostMsg_IsCrashReportingEnabled(&enabled)); | 208 new ChromeViewHostMsg_IsCrashReportingEnabled(&enabled)); |
209 if (enabled) | 209 if (enabled) |
210 return PP_OK; | 210 return PP_OK; |
211 return PP_ERROR_FAILED; | 211 return PP_ERROR_FAILED; |
212 } | 212 } |
OLD | NEW |