atom_browser_client.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // Copyright (c) 2013 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_ATOM_BROWSER_CLIENT_H_
  5. #define ATOM_BROWSER_ATOM_BROWSER_CLIENT_H_
  6. #include <map>
  7. #include <set>
  8. #include <string>
  9. #include <vector>
  10. #include "brightray/browser/browser_client.h"
  11. #include "content/public/browser/render_process_host_observer.h"
  12. #include "net/ssl/client_cert_identity.h"
  13. namespace content {
  14. class QuotaPermissionContext;
  15. class ClientCertificateDelegate;
  16. } // namespace content
  17. namespace net {
  18. class SSLCertRequestInfo;
  19. }
  20. namespace atom {
  21. class AtomResourceDispatcherHostDelegate;
  22. class AtomBrowserClient : public brightray::BrowserClient,
  23. public content::RenderProcessHostObserver {
  24. public:
  25. AtomBrowserClient();
  26. ~AtomBrowserClient() override;
  27. using Delegate = content::ContentBrowserClient;
  28. void set_delegate(Delegate* delegate) { delegate_ = delegate; }
  29. // Returns the WebContents for pending render processes.
  30. content::WebContents* GetWebContentsFromProcessID(int process_id);
  31. // Don't force renderer process to restart for once.
  32. static void SuppressRendererProcessRestartForOnce();
  33. // Custom schemes to be registered to handle service worker.
  34. static void SetCustomServiceWorkerSchemes(
  35. const std::vector<std::string>& schemes);
  36. protected:
  37. // content::ContentBrowserClient:
  38. void RenderProcessWillLaunch(content::RenderProcessHost* host) override;
  39. content::SpeechRecognitionManagerDelegate*
  40. CreateSpeechRecognitionManagerDelegate() override;
  41. void OverrideWebkitPrefs(content::RenderViewHost* render_view_host,
  42. content::WebPreferences* prefs) override;
  43. void OverrideSiteInstanceForNavigation(
  44. content::RenderFrameHost* render_frame_host,
  45. content::BrowserContext* browser_context,
  46. const GURL& dest_url,
  47. bool has_request_started,
  48. content::SiteInstance* candidate_instance,
  49. content::SiteInstance** new_instance) override;
  50. void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
  51. int child_process_id) override;
  52. void DidCreatePpapiPlugin(content::BrowserPpapiHost* browser_host) override;
  53. void GetGeolocationRequestContext(
  54. base::OnceCallback<void(scoped_refptr<net::URLRequestContextGetter>)>
  55. callback) override;
  56. std::string GetGeolocationApiKey() override;
  57. content::QuotaPermissionContext* CreateQuotaPermissionContext() override;
  58. void AllowCertificateError(
  59. content::WebContents* web_contents,
  60. int cert_error,
  61. const net::SSLInfo& ssl_info,
  62. const GURL& request_url,
  63. content::ResourceType resource_type,
  64. bool strict_enforcement,
  65. bool expired_previous_decision,
  66. const base::Callback<void(content::CertificateRequestResultType)>&
  67. callback) override;
  68. void SelectClientCertificate(
  69. content::WebContents* web_contents,
  70. net::SSLCertRequestInfo* cert_request_info,
  71. net::ClientCertIdentityList client_certs,
  72. std::unique_ptr<content::ClientCertificateDelegate> delegate) override;
  73. void ResourceDispatcherHostCreated() override;
  74. bool CanCreateWindow(content::RenderFrameHost* opener,
  75. const GURL& opener_url,
  76. const GURL& opener_top_level_frame_url,
  77. const GURL& source_origin,
  78. content::mojom::WindowContainerType container_type,
  79. const GURL& target_url,
  80. const content::Referrer& referrer,
  81. const std::string& frame_name,
  82. WindowOpenDisposition disposition,
  83. const blink::mojom::WindowFeatures& features,
  84. const std::vector<std::string>& additional_features,
  85. const scoped_refptr<content::ResourceRequestBody>& body,
  86. bool user_gesture,
  87. bool opener_suppressed,
  88. bool* no_javascript_access) override;
  89. void GetAdditionalAllowedSchemesForFileSystem(
  90. std::vector<std::string>* schemes) override;
  91. void SiteInstanceDeleting(content::SiteInstance* site_instance) override;
  92. // brightray::BrowserClient:
  93. brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
  94. const content::MainFunctionParams&) override;
  95. void WebNotificationAllowed(
  96. int render_process_id,
  97. const base::Callback<void(bool, bool)>& callback) override;
  98. // content::RenderProcessHostObserver:
  99. void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
  100. void RenderProcessReady(content::RenderProcessHost* host) override;
  101. void RenderProcessExited(content::RenderProcessHost* host,
  102. base::TerminationStatus status,
  103. int exit_code) override;
  104. private:
  105. struct ProcessPreferences {
  106. bool sandbox = false;
  107. bool native_window_open = false;
  108. bool disable_popups = false;
  109. };
  110. bool ShouldCreateNewSiteInstance(content::RenderFrameHost* render_frame_host,
  111. content::BrowserContext* browser_context,
  112. content::SiteInstance* current_instance,
  113. const GURL& dest_url);
  114. void AddProcessPreferences(int process_id, ProcessPreferences prefs);
  115. void RemoveProcessPreferences(int process_id);
  116. bool IsProcessObserved(int process_id);
  117. bool IsRendererSandboxed(int process_id);
  118. bool RendererUsesNativeWindowOpen(int process_id);
  119. bool RendererDisablesPopups(int process_id);
  120. // pending_render_process => web contents.
  121. std::map<int, content::WebContents*> pending_processes_;
  122. std::map<int, ProcessPreferences> process_preferences_;
  123. std::map<int, base::ProcessId> render_process_host_pids_;
  124. // list of site per affinity. weak_ptr to prevent instance locking
  125. std::map<std::string, content::SiteInstance*> site_per_affinities;
  126. std::unique_ptr<AtomResourceDispatcherHostDelegate>
  127. resource_dispatcher_host_delegate_;
  128. Delegate* delegate_ = nullptr;
  129. DISALLOW_COPY_AND_ASSIGN(AtomBrowserClient);
  130. };
  131. } // namespace atom
  132. #endif // ATOM_BROWSER_ATOM_BROWSER_CLIENT_H_