| 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_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
| 12 #include "chrome/renderer/chrome_content_renderer_client.h" | 12 #include "chrome/renderer/chrome_content_renderer_client.h" |
| 13 #include "content/public/renderer/pepper_plugin_instance.h" |
| 13 #include "content/public/renderer/render_thread.h" | 14 #include "content/public/renderer/render_thread.h" |
| 14 #include "content/public/renderer/renderer_ppapi_host.h" | 15 #include "content/public/renderer/renderer_ppapi_host.h" |
| 15 #include "extensions/common/constants.h" | 16 #include "extensions/common/constants.h" |
| 16 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
| 17 #include "ppapi/c/pp_errors.h" | 18 #include "ppapi/c/pp_errors.h" |
| 18 #include "ppapi/host/dispatch_host_message.h" | 19 #include "ppapi/host/dispatch_host_message.h" |
| 19 #include "ppapi/host/host_message_context.h" | 20 #include "ppapi/host/host_message_context.h" |
| 20 #include "ppapi/host/ppapi_host.h" | 21 #include "ppapi/host/ppapi_host.h" |
| 21 #include "ppapi/proxy/ppapi_messages.h" | 22 #include "ppapi/proxy/ppapi_messages.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 const char* const kPredefinedAllowedUMAOrigins[] = { | 26 const char* const kPredefinedAllowedUMAOrigins[] = { |
| 26 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see http://crbug.com/317833 | 27 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see http://crbug.com/317833 |
| 27 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see http://crbug.com/317833 | 28 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see http://crbug.com/317833 |
| 28 }; | 29 }; |
| 29 | 30 |
| 30 const char* const kWhitelistedHistogramPrefixes[] = { | 31 const char* const kWhitelistedHistogramPrefixes[] = { |
| 31 "CD190EA2B764EDF0BB97552A638D32072F3CFD41", // see http://crbug.com/317833 | 32 "CD190EA2B764EDF0BB97552A638D32072F3CFD41", // see http://crbug.com/317833 |
| 32 }; | 33 }; |
| 33 | 34 |
| 35 const char* const kWhitelistedPluginBaseNames[] = { |
| 36 "libwidevinecdmadapter.so" // see http://crbug.com/368743 |
| 37 }; |
| 38 |
| 34 std::string HashPrefix(const std::string& histogram) { | 39 std::string HashPrefix(const std::string& histogram) { |
| 35 const std::string id_hash = | 40 const std::string id_hash = |
| 36 base::SHA1HashString(histogram.substr(0, histogram.find('.'))); | 41 base::SHA1HashString(histogram.substr(0, histogram.find('.'))); |
| 37 DCHECK_EQ(id_hash.length(), base::kSHA1Length); | 42 DCHECK_EQ(id_hash.length(), base::kSHA1Length); |
| 38 return base::HexEncode(id_hash.c_str(), id_hash.length()); | 43 return base::HexEncode(id_hash.c_str(), id_hash.length()); |
| 39 } | 44 } |
| 40 | 45 |
| 41 } // namespace | 46 } // namespace |
| 42 | 47 |
| 43 PepperUMAHost::PepperUMAHost(content::RendererPpapiHost* host, | 48 PepperUMAHost::PepperUMAHost(content::RendererPpapiHost* host, |
| 44 PP_Instance instance, | 49 PP_Instance instance, |
| 45 PP_Resource resource) | 50 PP_Resource resource) |
| 46 : ResourceHost(host->GetPpapiHost(), instance, resource), | 51 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 47 document_url_(host->GetDocumentURL(instance)), | 52 document_url_(host->GetDocumentURL(instance)), |
| 48 is_plugin_in_process_(host->IsRunningInProcess()) { | 53 is_plugin_in_process_(host->IsRunningInProcess()) { |
| 54 if (host->GetPluginInstance(instance)) { |
| 55 plugin_base_name_ = |
| 56 host->GetPluginInstance(instance)->GetModulePath().BaseName(); |
| 57 } |
| 58 |
| 49 for (size_t i = 0; i < arraysize(kPredefinedAllowedUMAOrigins); ++i) | 59 for (size_t i = 0; i < arraysize(kPredefinedAllowedUMAOrigins); ++i) |
| 50 allowed_origins_.insert(kPredefinedAllowedUMAOrigins[i]); | 60 allowed_origins_.insert(kPredefinedAllowedUMAOrigins[i]); |
| 51 for (size_t i = 0; i < arraysize(kWhitelistedHistogramPrefixes); ++i) | 61 for (size_t i = 0; i < arraysize(kWhitelistedHistogramPrefixes); ++i) |
| 52 allowed_histogram_prefixes_.insert(kWhitelistedHistogramPrefixes[i]); | 62 allowed_histogram_prefixes_.insert(kWhitelistedHistogramPrefixes[i]); |
| 63 for (size_t i = 0; i < arraysize(kWhitelistedPluginBaseNames); ++i) |
| 64 allowed_plugin_base_names_.insert(kWhitelistedPluginBaseNames[i]); |
| 53 } | 65 } |
| 54 | 66 |
| 55 PepperUMAHost::~PepperUMAHost() {} | 67 PepperUMAHost::~PepperUMAHost() {} |
| 56 | 68 |
| 57 int32_t PepperUMAHost::OnResourceMessageReceived( | 69 int32_t PepperUMAHost::OnResourceMessageReceived( |
| 58 const IPC::Message& msg, | 70 const IPC::Message& msg, |
| 59 ppapi::host::HostMessageContext* context) { | 71 ppapi::host::HostMessageContext* context) { |
| 60 PPAPI_BEGIN_MESSAGE_MAP(PepperUMAHost, msg) | 72 PPAPI_BEGIN_MESSAGE_MAP(PepperUMAHost, msg) |
| 61 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramCustomTimes, | 73 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramCustomTimes, |
| 62 OnHistogramCustomTimes) | 74 OnHistogramCustomTimes) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 79 if (is_plugin_in_process_ && histogram.find("NaCl.") == 0) { | 91 if (is_plugin_in_process_ && histogram.find("NaCl.") == 0) { |
| 80 return true; | 92 return true; |
| 81 } | 93 } |
| 82 | 94 |
| 83 if (IsPluginWhitelisted() && | 95 if (IsPluginWhitelisted() && |
| 84 allowed_histogram_prefixes_.find(HashPrefix(histogram)) != | 96 allowed_histogram_prefixes_.find(HashPrefix(histogram)) != |
| 85 allowed_histogram_prefixes_.end()) { | 97 allowed_histogram_prefixes_.end()) { |
| 86 return true; | 98 return true; |
| 87 } | 99 } |
| 88 | 100 |
| 101 if (allowed_plugin_base_names_.find(plugin_base_name_.MaybeAsASCII()) != |
| 102 allowed_plugin_base_names_.end()) { |
| 103 return true; |
| 104 } |
| 105 |
| 89 LOG(ERROR) << "Host or histogram name is not allowed to use the UMA API."; | 106 LOG(ERROR) << "Host or histogram name is not allowed to use the UMA API."; |
| 90 return false; | 107 return false; |
| 91 } | 108 } |
| 92 | 109 |
| 93 #define RETURN_IF_BAD_ARGS(_min, _max, _buckets) \ | 110 #define RETURN_IF_BAD_ARGS(_min, _max, _buckets) \ |
| 94 do { \ | 111 do { \ |
| 95 if (_min >= _max || _buckets <= 1) \ | 112 if (_min >= _max || _buckets <= 1) \ |
| 96 return PP_ERROR_BADARGUMENT; \ | 113 return PP_ERROR_BADARGUMENT; \ |
| 97 } while (0) | 114 } while (0) |
| 98 | 115 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 ppapi::host::HostMessageContext* context) { | 190 ppapi::host::HostMessageContext* context) { |
| 174 if (!IsPluginWhitelisted()) | 191 if (!IsPluginWhitelisted()) |
| 175 return PP_ERROR_NOACCESS; | 192 return PP_ERROR_NOACCESS; |
| 176 bool enabled = false; | 193 bool enabled = false; |
| 177 content::RenderThread::Get()->Send( | 194 content::RenderThread::Get()->Send( |
| 178 new ChromeViewHostMsg_IsCrashReportingEnabled(&enabled)); | 195 new ChromeViewHostMsg_IsCrashReportingEnabled(&enabled)); |
| 179 if (enabled) | 196 if (enabled) |
| 180 return PP_OK; | 197 return PP_OK; |
| 181 return PP_ERROR_FAILED; | 198 return PP_ERROR_FAILED; |
| 182 } | 199 } |
| OLD | NEW |