shell_content_browser_client.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // Copyright 2014 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_SHELL_BROWSER_SHELL_CONTENT_BROWSER_CLIENT_H_
  5. #define EXTENSIONS_SHELL_BROWSER_SHELL_CONTENT_BROWSER_CLIENT_H_
  6. #include <memory>
  7. #include "base/compiler_specific.h"
  8. #include "base/memory/raw_ptr.h"
  9. #include "content/public/browser/content_browser_client.h"
  10. #include "content/public/browser/web_contents.h"
  11. #include "mojo/public/cpp/bindings/pending_receiver.h"
  12. #include "mojo/public/cpp/bindings/pending_remote.h"
  13. #include "services/metrics/public/cpp/ukm_source_id.h"
  14. class GURL;
  15. namespace base {
  16. class CommandLine;
  17. }
  18. namespace blink {
  19. class AssociatedInterfaceRegistry;
  20. }
  21. namespace content {
  22. class BrowserContext;
  23. }
  24. namespace service_manager {
  25. template <typename...>
  26. class BinderRegistryWithArgs;
  27. using BinderRegistry = BinderRegistryWithArgs<>;
  28. } // namespace service_manager
  29. namespace extensions {
  30. class Extension;
  31. class ShellBrowserMainDelegate;
  32. class ShellBrowserMainParts;
  33. // Content module browser process support for app_shell.
  34. class ShellContentBrowserClient : public content::ContentBrowserClient {
  35. public:
  36. explicit ShellContentBrowserClient(
  37. ShellBrowserMainDelegate* browser_main_delegate);
  38. ShellContentBrowserClient(const ShellContentBrowserClient&) = delete;
  39. ShellContentBrowserClient& operator=(const ShellContentBrowserClient&) =
  40. delete;
  41. ~ShellContentBrowserClient() override;
  42. // Returns the single instance.
  43. static ShellContentBrowserClient* Get();
  44. // Returns the single browser context for app_shell.
  45. content::BrowserContext* GetBrowserContext();
  46. // content::ContentBrowserClient overrides.
  47. std::unique_ptr<content::BrowserMainParts> CreateBrowserMainParts(
  48. bool is_integration_test) override;
  49. void RenderProcessWillLaunch(content::RenderProcessHost* host) override;
  50. bool ShouldUseProcessPerSite(content::BrowserContext* browser_context,
  51. const GURL& site_url) override;
  52. bool IsHandledURL(const GURL& url) override;
  53. void SiteInstanceGotProcess(content::SiteInstance* site_instance) override;
  54. void SiteInstanceDeleting(content::SiteInstance* site_instance) override;
  55. void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
  56. int child_process_id) override;
  57. content::SpeechRecognitionManagerDelegate*
  58. CreateSpeechRecognitionManagerDelegate() override;
  59. content::BrowserPpapiHost* GetExternalBrowserPpapiHost(
  60. int plugin_process_id) override;
  61. void GetAdditionalAllowedSchemesForFileSystem(
  62. std::vector<std::string>* additional_schemes) override;
  63. std::unique_ptr<content::DevToolsManagerDelegate>
  64. CreateDevToolsManagerDelegate() override;
  65. void ExposeInterfacesToRenderer(
  66. service_manager::BinderRegistry* registry,
  67. blink::AssociatedInterfaceRegistry* associated_registry,
  68. content::RenderProcessHost* render_process_host) override;
  69. void RegisterAssociatedInterfaceBindersForRenderFrameHost(
  70. content::RenderFrameHost& render_frame_host,
  71. blink::AssociatedInterfaceRegistry& associated_registry) override;
  72. std::vector<std::unique_ptr<content::NavigationThrottle>>
  73. CreateThrottlesForNavigation(
  74. content::NavigationHandle* navigation_handle) override;
  75. std::unique_ptr<content::NavigationUIData> GetNavigationUIData(
  76. content::NavigationHandle* navigation_handle) override;
  77. void RegisterNonNetworkNavigationURLLoaderFactories(
  78. int frame_tree_node_id,
  79. ukm::SourceIdObj ukm_source_id,
  80. NonNetworkURLLoaderFactoryMap* factories) override;
  81. void RegisterNonNetworkWorkerMainResourceURLLoaderFactories(
  82. content::BrowserContext* browser_context,
  83. NonNetworkURLLoaderFactoryMap* factories) override;
  84. void RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(
  85. content::BrowserContext* browser_context,
  86. NonNetworkURLLoaderFactoryMap* factories) override;
  87. void RegisterNonNetworkSubresourceURLLoaderFactories(
  88. int render_process_id,
  89. int render_frame_id,
  90. const absl::optional<url::Origin>& request_initiator_origin,
  91. NonNetworkURLLoaderFactoryMap* factories) override;
  92. bool WillCreateURLLoaderFactory(
  93. content::BrowserContext* browser_context,
  94. content::RenderFrameHost* frame_host,
  95. int render_process_id,
  96. URLLoaderFactoryType type,
  97. const url::Origin& request_initiator,
  98. absl::optional<int64_t> navigation_id,
  99. ukm::SourceIdObj ukm_source_id,
  100. mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
  101. mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
  102. header_client,
  103. bool* bypass_redirect_checks,
  104. bool* disable_secure_dns,
  105. network::mojom::URLLoaderFactoryOverridePtr* factory_override) override;
  106. bool HandleExternalProtocol(
  107. const GURL& url,
  108. content::WebContents::Getter web_contents_getter,
  109. int frame_tree_node_id,
  110. content::NavigationUIData* navigation_data,
  111. bool is_primary_main_frame,
  112. bool is_in_fenced_frame_tree,
  113. network::mojom::WebSandboxFlags sandbox_flags,
  114. ui::PageTransition page_transition,
  115. bool has_user_gesture,
  116. const absl::optional<url::Origin>& initiating_origin,
  117. content::RenderFrameHost* initiator_document,
  118. mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory)
  119. override;
  120. void OverrideURLLoaderFactoryParams(
  121. content::BrowserContext* browser_context,
  122. const url::Origin& origin,
  123. bool is_for_isolated_world,
  124. network::mojom::URLLoaderFactoryParams* factory_params) override;
  125. base::FilePath GetSandboxedStorageServiceDataDirectory() override;
  126. std::string GetUserAgent() override;
  127. protected:
  128. // Subclasses may wish to provide their own ShellBrowserMainParts.
  129. virtual std::unique_ptr<ShellBrowserMainParts> CreateShellBrowserMainParts(
  130. ShellBrowserMainDelegate* browser_main_delegate,
  131. bool is_integration_test);
  132. private:
  133. // Appends command line switches for a renderer process.
  134. void AppendRendererSwitches(base::CommandLine* command_line);
  135. // Returns the extension or app associated with |site_instance| or NULL.
  136. const Extension* GetExtension(content::SiteInstance* site_instance);
  137. // Owned by content::BrowserMainLoop.
  138. raw_ptr<ShellBrowserMainParts> browser_main_parts_;
  139. // Owned by ShellBrowserMainParts.
  140. raw_ptr<ShellBrowserMainDelegate> browser_main_delegate_;
  141. };
  142. } // namespace extensions
  143. #endif // EXTENSIONS_SHELL_BROWSER_SHELL_CONTENT_BROWSER_CLIENT_H_