atom_browser_client.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. namespace content {
  13. class QuotaPermissionContext;
  14. class ClientCertificateDelegate;
  15. }
  16. namespace net {
  17. class SSLCertRequestInfo;
  18. }
  19. namespace atom {
  20. class AtomResourceDispatcherHostDelegate;
  21. class AtomBrowserClient : public brightray::BrowserClient,
  22. public content::RenderProcessHostObserver {
  23. public:
  24. AtomBrowserClient();
  25. virtual ~AtomBrowserClient();
  26. using Delegate = content::ContentBrowserClient;
  27. void set_delegate(Delegate* delegate) { delegate_ = delegate; }
  28. // Returns the WebContents for pending render processes.
  29. content::WebContents* GetWebContentsFromProcessID(int process_id);
  30. // Don't force renderer process to restart for once.
  31. static void SuppressRendererProcessRestartForOnce();
  32. // Custom schemes to be registered to handle service worker.
  33. static void SetCustomServiceWorkerSchemes(
  34. const std::vector<std::string>& schemes);
  35. protected:
  36. // content::ContentBrowserClient:
  37. void RenderProcessWillLaunch(content::RenderProcessHost* host) override;
  38. content::SpeechRecognitionManagerDelegate*
  39. CreateSpeechRecognitionManagerDelegate() override;
  40. content::GeolocationDelegate* CreateGeolocationDelegate() override;
  41. void OverrideWebkitPrefs(content::RenderViewHost* render_view_host,
  42. content::WebPreferences* prefs) override;
  43. std::string GetApplicationLocale() override;
  44. void OverrideSiteInstanceForNavigation(
  45. content::BrowserContext* browser_context,
  46. content::SiteInstance* current_instance,
  47. const GURL& dest_url,
  48. content::SiteInstance** new_instance) override;
  49. void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
  50. int child_process_id) override;
  51. void DidCreatePpapiPlugin(content::BrowserPpapiHost* browser_host) override;
  52. content::QuotaPermissionContext* CreateQuotaPermissionContext() override;
  53. void AllowCertificateError(
  54. content::WebContents* web_contents,
  55. int cert_error,
  56. const net::SSLInfo& ssl_info,
  57. const GURL& request_url,
  58. content::ResourceType resource_type,
  59. bool overridable,
  60. bool strict_enforcement,
  61. bool expired_previous_decision,
  62. const base::Callback<void(bool)>& callback,
  63. content::CertificateRequestResultType* request) override;
  64. void SelectClientCertificate(
  65. content::WebContents* web_contents,
  66. net::SSLCertRequestInfo* cert_request_info,
  67. std::unique_ptr<content::ClientCertificateDelegate> delegate) override;
  68. void ResourceDispatcherHostCreated() override;
  69. bool CanCreateWindow(
  70. const GURL& opener_url,
  71. const GURL& opener_top_level_frame_url,
  72. const GURL& source_origin,
  73. WindowContainerType container_type,
  74. const std::string& frame_name,
  75. const GURL& target_url,
  76. const content::Referrer& referrer,
  77. WindowOpenDisposition disposition,
  78. const blink::WebWindowFeatures& features,
  79. const std::vector<base::string16>& additional_features,
  80. const scoped_refptr<content::ResourceRequestBodyImpl>& body,
  81. bool user_gesture,
  82. bool opener_suppressed,
  83. content::ResourceContext* context,
  84. int render_process_id,
  85. int opener_render_view_id,
  86. int opener_render_frame_id,
  87. bool* no_javascript_access) override;
  88. void GetAdditionalAllowedSchemesForFileSystem(
  89. std::vector<std::string>* schemes) override;
  90. // brightray::BrowserClient:
  91. brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
  92. const content::MainFunctionParams&) override;
  93. void WebNotificationAllowed(
  94. int render_process_id,
  95. const base::Callback<void(bool, bool)>& callback) override;
  96. // content::RenderProcessHostObserver:
  97. void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
  98. private:
  99. bool ShouldCreateNewSiteInstance(content::BrowserContext* browser_context,
  100. content::SiteInstance* current_instance,
  101. const GURL& dest_url);
  102. // Add/remove a process id to `sandboxed_renderers_`.
  103. void AddSandboxedRendererId(int process_id);
  104. void RemoveSandboxedRendererId(int process_id);
  105. bool IsRendererSandboxed(int process_id);
  106. // pending_render_process => current_render_process.
  107. std::map<int, int> pending_processes_;
  108. // Set that contains the process ids of all sandboxed renderers
  109. std::set<int> sandboxed_renderers_;
  110. base::Lock sandboxed_renderers_lock_;
  111. std::unique_ptr<AtomResourceDispatcherHostDelegate>
  112. resource_dispatcher_host_delegate_;
  113. Delegate* delegate_;
  114. DISALLOW_COPY_AND_ASSIGN(AtomBrowserClient);
  115. };
  116. } // namespace atom
  117. #endif // ATOM_BROWSER_ATOM_BROWSER_CLIENT_H_