interaction_provider.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2019 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_BINDINGS_INTERACTION_PROVIDER_H_
  5. #define EXTENSIONS_RENDERER_BINDINGS_INTERACTION_PROVIDER_H_
  6. #include <memory>
  7. #include "v8/include/v8.h"
  8. namespace extensions {
  9. // Provides user interaction related utilities.
  10. class InteractionProvider {
  11. public:
  12. // A token for an interaction. This can be used for deferred creation of an
  13. // interaction.
  14. class Token {
  15. public:
  16. virtual ~Token() {}
  17. };
  18. // The scope for an interaction.
  19. // A context is assumed to have active interaction while this is present.
  20. class Scope {
  21. public:
  22. virtual ~Scope() {}
  23. };
  24. virtual ~InteractionProvider() {}
  25. // Returns a token representing the current state of interaction,
  26. // possibly for use in later point in time to create a |Scope|.
  27. virtual std::unique_ptr<Token> GetCurrentToken(
  28. v8::Local<v8::Context> v8_context) const = 0;
  29. // Creates a scoped interaction from a |token|, possibly retrieved earlier.
  30. virtual std::unique_ptr<Scope> CreateScopedInteraction(
  31. v8::Local<v8::Context> v8_context,
  32. std::unique_ptr<Token> token) const = 0;
  33. // Returns true if |v8_context| has an active interaction.
  34. virtual bool HasActiveInteraction(
  35. v8::Local<v8::Context> v8_context) const = 0;
  36. };
  37. } // namespace extensions
  38. #endif // EXTENSIONS_RENDERER_BINDINGS_INTERACTION_PROVIDER_H_