context_impl.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright 2018 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 FUCHSIA_WEB_WEBENGINE_BROWSER_CONTEXT_IMPL_H_
  5. #define FUCHSIA_WEB_WEBENGINE_BROWSER_CONTEXT_IMPL_H_
  6. #include <fuchsia/web/cpp/fidl.h>
  7. #include <lib/fidl/cpp/binding_set.h>
  8. #include <lib/inspect/cpp/vmo/types.h>
  9. #include <memory>
  10. #include <set>
  11. #include "base/containers/unique_ptr_adapters.h"
  12. #include "fuchsia_web/webengine/browser/cookie_manager_impl.h"
  13. #include "fuchsia_web/webengine/web_engine_export.h"
  14. namespace content {
  15. class BrowserContext;
  16. class WebContents;
  17. } // namespace content
  18. namespace network {
  19. namespace mojom {
  20. class NetworkContext;
  21. } // namespace mojom
  22. } // namespace network
  23. class FrameImpl;
  24. class WebEngineDevToolsController;
  25. // Implementation of Context from fuchsia.web.
  26. // Owns a BrowserContext instance and uses it to create new WebContents/Frames.
  27. // All created Frames are owned by this object.
  28. class WEB_ENGINE_EXPORT ContextImpl final : public fuchsia::web::Context {
  29. public:
  30. // |devtools_controller| must outlive ContextImpl.
  31. // Diagnostics about the context will be placed in |inspect_node|.
  32. ContextImpl(std::unique_ptr<content::BrowserContext> browser_context,
  33. inspect::Node inspect_node,
  34. WebEngineDevToolsController* devtools_controller);
  35. // Tears down the Context, destroying any active Frames in the process.
  36. ~ContextImpl() override;
  37. ContextImpl(const ContextImpl&) = delete;
  38. ContextImpl& operator=(const ContextImpl&) = delete;
  39. // Removes and destroys the specified |frame|.
  40. void DestroyFrame(FrameImpl* frame);
  41. // Returns |true| if JS injection was enabled for this Context.
  42. bool IsJavaScriptInjectionAllowed();
  43. // Creates a Frame with |params| for the |web_contents| and binds it to
  44. // |frame_request|. The Frame will self-delete when |frame_request|
  45. // disconnects.
  46. FrameImpl* CreateFrameForWebContents(
  47. std::unique_ptr<content::WebContents> web_contents,
  48. fuchsia::web::CreateFrameParams params,
  49. fidl::InterfaceRequest<fuchsia::web::Frame> frame_request);
  50. // Returns the DevTools controller for this Context.
  51. WebEngineDevToolsController* devtools_controller() const {
  52. return devtools_controller_;
  53. }
  54. // Controls whether the CastStreaming receiver is available in this instance.
  55. // At most one ContextImpl per-process may have CastStreaming enabled.
  56. void SetCastStreamingEnabled();
  57. bool has_cast_streaming_enabled() const { return cast_streaming_enabled_; }
  58. // fuchsia::web::Context implementation.
  59. void CreateFrame(fidl::InterfaceRequest<fuchsia::web::Frame> frame) override;
  60. void CreateFrameWithParams(
  61. fuchsia::web::CreateFrameParams params,
  62. fidl::InterfaceRequest<fuchsia::web::Frame> frame) override;
  63. void GetCookieManager(
  64. fidl::InterfaceRequest<fuchsia::web::CookieManager> manager) override;
  65. void GetRemoteDebuggingPort(GetRemoteDebuggingPortCallback callback) override;
  66. // Gets the underlying FrameImpl service object associated with a connected
  67. // |frame_ptr| client.
  68. FrameImpl* GetFrameImplForTest(fuchsia::web::FramePtr* frame_ptr) const;
  69. content::BrowserContext* browser_context() const {
  70. return browser_context_.get();
  71. }
  72. private:
  73. // Returns the NetworkContext from the default StoragePartition.
  74. network::mojom::NetworkContext* GetNetworkContext();
  75. // Reference to the browser implementation for this Context.
  76. std::unique_ptr<content::BrowserContext> const browser_context_;
  77. // Reference to the class managing the DevTools remote debugging service.
  78. WebEngineDevToolsController* const devtools_controller_;
  79. // Inspect node & properties for this browsing context.
  80. inspect::Node inspect_node_;
  81. // CookieManager API implementation for this Context.
  82. CookieManagerImpl cookie_manager_;
  83. fidl::BindingSet<fuchsia::web::CookieManager> cookie_manager_bindings_;
  84. // TODO(crbug.com/893236): Make this false by default, and allow it to be
  85. // initialized at Context creation time.
  86. bool allow_javascript_injection_ = true;
  87. // True if this instance should allows Frames to use CastStreaming.
  88. bool cast_streaming_enabled_ = false;
  89. // Tracks all active FrameImpl instances, so that we can request their
  90. // destruction when this ContextImpl is destroyed.
  91. std::set<std::unique_ptr<FrameImpl>, base::UniquePtrComparator> frames_;
  92. };
  93. #endif // FUCHSIA_WEB_WEBENGINE_BROWSER_CONTEXT_IMPL_H_