per_context_data.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2013 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 GIN_PER_CONTEXT_DATA_H_
  5. #define GIN_PER_CONTEXT_DATA_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "base/supports_user_data.h"
  8. #include "gin/gin_export.h"
  9. #include "v8/include/v8-forward.h"
  10. namespace gin {
  11. class ContextHolder;
  12. class Runner;
  13. // There is one instance of PerContextData per v8::Context managed by Gin. This
  14. // class stores all the Gin-related data that varies per context. Arbitrary data
  15. // can be associated with this class by way of the SupportsUserData methods.
  16. // Instances of this class (and any associated user data) are destroyed before
  17. // the associated v8::Context.
  18. class GIN_EXPORT PerContextData : public base::SupportsUserData {
  19. public:
  20. PerContextData(ContextHolder* context_holder,
  21. v8::Local<v8::Context> context);
  22. PerContextData(const PerContextData&) = delete;
  23. PerContextData& operator=(const PerContextData&) = delete;
  24. ~PerContextData() override;
  25. // Can return NULL after the ContextHolder has detached from context.
  26. static PerContextData* From(v8::Local<v8::Context> context);
  27. // The Runner associated with this context. To execute script in this context,
  28. // please use the appropriate API on Runner.
  29. Runner* runner() const { return runner_; }
  30. void set_runner(Runner* runner) { runner_ = runner; }
  31. ContextHolder* context_holder() { return context_holder_; }
  32. private:
  33. raw_ptr<ContextHolder> context_holder_;
  34. raw_ptr<Runner> runner_;
  35. };
  36. } // namespace gin
  37. #endif // GIN_PER_CONTEXT_DATA_H_