content_setting.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2017 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. #ifndef EXTENSIONS_RENDERER_CONTENT_SETTING_H_
  5. #define EXTENSIONS_RENDERER_CONTENT_SETTING_H_
  6. #include <string>
  7. #include "extensions/renderer/bindings/argument_spec.h"
  8. #include "gin/wrappable.h"
  9. #include "v8/include/v8-forward.h"
  10. namespace base {
  11. class DictionaryValue;
  12. class ListValue;
  13. }
  14. namespace gin {
  15. class Arguments;
  16. }
  17. namespace extensions {
  18. class APIEventHandler;
  19. class APIRequestHandler;
  20. class BindingAccessChecker;
  21. // The custom implementation of the contentSettings.ContentSetting type exposed
  22. // to APIs.
  23. class ContentSetting final : public gin::Wrappable<ContentSetting> {
  24. public:
  25. ContentSetting(const ContentSetting&) = delete;
  26. ContentSetting& operator=(const ContentSetting&) = delete;
  27. ~ContentSetting() override;
  28. // Creates a ContentSetting object for the given property.
  29. static v8::Local<v8::Object> Create(
  30. v8::Isolate* isolate,
  31. const std::string& property_name,
  32. const base::ListValue* property_values,
  33. APIRequestHandler* request_handler,
  34. APIEventHandler* event_handler,
  35. APITypeReferenceMap* type_refs,
  36. const BindingAccessChecker* access_checker);
  37. static gin::WrapperInfo kWrapperInfo;
  38. gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
  39. v8::Isolate* isolate) override;
  40. const char* GetTypeName() override;
  41. private:
  42. ContentSetting(APIRequestHandler* request_handler,
  43. const APITypeReferenceMap* type_refs,
  44. const BindingAccessChecker* access_checker,
  45. const std::string& pref_name,
  46. const base::DictionaryValue& argument_spec);
  47. // JS function handlers:
  48. void Get(gin::Arguments* arguments);
  49. void Set(gin::Arguments* arguments);
  50. void Clear(gin::Arguments* arguments);
  51. void GetResourceIdentifiers(gin::Arguments* arguments);
  52. // Common function handling endpoint.
  53. void HandleFunction(const std::string& function_name,
  54. gin::Arguments* arguments);
  55. APIRequestHandler* request_handler_;
  56. const APITypeReferenceMap* type_refs_;
  57. const BindingAccessChecker* const access_checker_;
  58. // The name of the preference this ContentSetting is managing.
  59. std::string pref_name_;
  60. // The type of argument that calling set() on the ContentSetting expects
  61. // (since different settings can take a different type of argument depending
  62. // on the preference it manages).
  63. ArgumentSpec argument_spec_;
  64. };
  65. } // namespace extensions
  66. #endif // EXTENSIONS_RENDERER_CONTENT_SETTING_H_