electron_renderer_pepper_host_factory.cc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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
  3. // found in the LICENSE file.
  4. #include "shell/renderer/electron_renderer_pepper_host_factory.h"
  5. #include <memory>
  6. #include <string>
  7. #include "content/public/renderer/renderer_ppapi_host.h"
  8. #include "ppapi/host/dispatch_host_message.h"
  9. #include "ppapi/host/ppapi_host.h"
  10. #include "ppapi/host/resource_host.h"
  11. #include "ppapi/proxy/ppapi_message_utils.h"
  12. #include "ppapi/proxy/ppapi_messages.h"
  13. #include "ppapi/shared_impl/ppapi_permissions.h"
  14. using ppapi::host::ResourceHost;
  15. // Stub class which ignores all messages
  16. class PepperUMAHost : public ppapi::host::ResourceHost {
  17. public:
  18. PepperUMAHost(content::RendererPpapiHost* host,
  19. PP_Instance instance,
  20. PP_Resource resource)
  21. : ResourceHost(host->GetPpapiHost(), instance, resource) {}
  22. ~PepperUMAHost() override = default;
  23. // ppapi::host::ResourceMessageHandler implementation.
  24. int32_t OnResourceMessageReceived(
  25. const IPC::Message& msg,
  26. ppapi::host::HostMessageContext* context) override {
  27. PPAPI_BEGIN_MESSAGE_MAP(PepperUMAHost, msg)
  28. PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramCustomTimes,
  29. OnHistogramCustomTimes)
  30. PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramCustomCounts,
  31. OnHistogramCustomCounts)
  32. PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramEnumeration,
  33. OnHistogramEnumeration)
  34. PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
  35. PpapiHostMsg_UMA_IsCrashReportingEnabled, OnIsCrashReportingEnabled)
  36. PPAPI_END_MESSAGE_MAP()
  37. return PP_ERROR_FAILED;
  38. }
  39. private:
  40. int32_t OnHistogramCustomTimes(ppapi::host::HostMessageContext* context,
  41. const std::string& name,
  42. int64_t sample,
  43. int64_t min,
  44. int64_t max,
  45. uint32_t bucket_count) {
  46. return PP_OK;
  47. }
  48. int32_t OnHistogramCustomCounts(ppapi::host::HostMessageContext* context,
  49. const std::string& name,
  50. int32_t sample,
  51. int32_t min,
  52. int32_t max,
  53. uint32_t bucket_count) {
  54. return PP_OK;
  55. }
  56. int32_t OnHistogramEnumeration(ppapi::host::HostMessageContext* context,
  57. const std::string& name,
  58. int32_t sample,
  59. int32_t boundary_value) {
  60. return PP_OK;
  61. }
  62. int32_t OnIsCrashReportingEnabled(ppapi::host::HostMessageContext* context) {
  63. return PP_OK;
  64. }
  65. };
  66. ElectronRendererPepperHostFactory::ElectronRendererPepperHostFactory(
  67. content::RendererPpapiHost* host)
  68. : host_(host) {}
  69. ElectronRendererPepperHostFactory::~ElectronRendererPepperHostFactory() =
  70. default;
  71. std::unique_ptr<ResourceHost>
  72. ElectronRendererPepperHostFactory::CreateResourceHost(
  73. ppapi::host::PpapiHost* host,
  74. PP_Resource resource,
  75. PP_Instance instance,
  76. const IPC::Message& message) {
  77. DCHECK_EQ(host_->GetPpapiHost(), host);
  78. // Make sure the plugin is giving us a valid instance for this resource.
  79. if (!host_->IsValidInstance(instance))
  80. return nullptr;
  81. // Permissions for the following interfaces will be checked at the
  82. // time of the corresponding instance's method calls. Currently these
  83. // interfaces are available only for specifically permitted apps which may
  84. // not have access to the other private interfaces.
  85. switch (message.type()) {
  86. case PpapiHostMsg_UMA_Create::ID: {
  87. return std::make_unique<PepperUMAHost>(host_, instance, resource);
  88. }
  89. }
  90. return nullptr;
  91. }