renderer_extension_registry.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2015 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_RENDERER_EXTENSION_REGISTRY_H_
  5. #define EXTENSIONS_RENDERER_RENDERER_EXTENSION_REGISTRY_H_
  6. #include <stddef.h>
  7. #include <string>
  8. #include "base/synchronization/lock.h"
  9. #include "extensions/common/activation_sequence.h"
  10. #include "extensions/common/extension_id.h"
  11. #include "extensions/common/extension_set.h"
  12. #include "third_party/abseil-cpp/absl/types/optional.h"
  13. class GURL;
  14. namespace extensions {
  15. // Thread safe container for all loaded extensions in this process,
  16. // essentially the renderer counterpart to ExtensionRegistry.
  17. class RendererExtensionRegistry {
  18. public:
  19. RendererExtensionRegistry();
  20. RendererExtensionRegistry(const RendererExtensionRegistry&) = delete;
  21. RendererExtensionRegistry& operator=(const RendererExtensionRegistry&) =
  22. delete;
  23. ~RendererExtensionRegistry();
  24. static RendererExtensionRegistry* Get();
  25. // Returns the ExtensionSet that underlies this RenderExtensionRegistry.
  26. //
  27. // This is not thread-safe and must only be called on the RenderThread, but
  28. // even so, it's not thread safe because other threads may decide to
  29. // modify this. Don't persist a reference to this.
  30. //
  31. // TODO(annekao): remove or make thread-safe and callback-based.
  32. const ExtensionSet* GetMainThreadExtensionSet() const;
  33. size_t size() const;
  34. bool is_empty() const;
  35. // Forwards to the ExtensionSet methods by the same name.
  36. bool Contains(const std::string& id) const;
  37. bool ContainsGUID(const std::string& guid) const;
  38. bool Insert(const scoped_refptr<const Extension>& extension);
  39. bool Remove(const std::string& id);
  40. std::string GetExtensionOrAppIDByURL(const GURL& url) const;
  41. const Extension* GetExtensionOrAppByURL(const GURL& url,
  42. bool include_guid = false) const;
  43. const Extension* GetHostedAppByURL(const GURL& url) const;
  44. const Extension* GetByID(const std::string& id) const;
  45. ExtensionIdSet GetIDs() const;
  46. bool ExtensionBindingsAllowed(const GURL& url) const;
  47. // ActivationSequence related methods.
  48. //
  49. // Sets ActivationSequence for a Service Worker based |extension|.
  50. void SetWorkerActivationSequence(
  51. const scoped_refptr<const Extension>& extension,
  52. ActivationSequence worker_activation_sequence);
  53. // Returns the current activation sequence for worker based extension with
  54. // |extension_id|. Returns absl::nullopt otherwise.
  55. absl::optional<ActivationSequence> GetWorkerActivationSequence(
  56. const ExtensionId& extension_id) const;
  57. private:
  58. ExtensionSet extensions_;
  59. // Maps extension id to ActivationSequence, for worker based extensions.
  60. std::map<ExtensionId, ActivationSequence> worker_activation_sequences_;
  61. mutable base::Lock lock_;
  62. };
  63. } // namespace extensions
  64. #endif // EXTENSIONS_RENDERER_RENDERER_EXTENSION_REGISTRY_H_