atom_api_app.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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_API_ATOM_API_APP_H_
  5. #define ATOM_BROWSER_API_ATOM_API_APP_H_
  6. #include <string>
  7. #include <vector>
  8. #include "atom/browser/api/event_emitter.h"
  9. #include "atom/browser/atom_browser_client.h"
  10. #include "atom/browser/browser.h"
  11. #include "atom/browser/browser_observer.h"
  12. #include "atom/common/native_mate_converters/callback.h"
  13. #include "base/process/process_iterator.h"
  14. #include "base/task/cancelable_task_tracker.h"
  15. #include "chrome/browser/icon_manager.h"
  16. #include "chrome/browser/process_singleton.h"
  17. #include "content/public/browser/gpu_data_manager_observer.h"
  18. #include "native_mate/dictionary.h"
  19. #include "native_mate/handle.h"
  20. #include "net/base/completion_callback.h"
  21. #if defined(USE_NSS_CERTS)
  22. #include "chrome/browser/certificate_manager_model.h"
  23. #endif
  24. namespace base {
  25. class FilePath;
  26. }
  27. namespace mate {
  28. class Arguments;
  29. } // namespace mate
  30. namespace atom {
  31. #if defined(OS_WIN)
  32. enum class JumpListResult : int;
  33. #endif
  34. namespace api {
  35. class App : public AtomBrowserClient::Delegate,
  36. public mate::EventEmitter<App>,
  37. public BrowserObserver,
  38. public content::GpuDataManagerObserver {
  39. public:
  40. using FileIconCallback = base::Callback<void(v8::Local<v8::Value>,
  41. const gfx::Image&)>;
  42. static mate::Handle<App> Create(v8::Isolate* isolate);
  43. static void BuildPrototype(v8::Isolate* isolate,
  44. v8::Local<v8::FunctionTemplate> prototype);
  45. // Called when window with disposition needs to be created.
  46. void OnCreateWindow(
  47. const GURL& target_url,
  48. const std::string& frame_name,
  49. WindowOpenDisposition disposition,
  50. const std::vector<std::string>& features,
  51. const scoped_refptr<content::ResourceRequestBodyImpl>& body,
  52. int render_process_id,
  53. int render_frame_id);
  54. #if defined(USE_NSS_CERTS)
  55. void OnCertificateManagerModelCreated(
  56. std::unique_ptr<base::DictionaryValue> options,
  57. const net::CompletionCallback& callback,
  58. std::unique_ptr<CertificateManagerModel> model);
  59. #endif
  60. base::FilePath GetAppPath() const;
  61. protected:
  62. explicit App(v8::Isolate* isolate);
  63. ~App() override;
  64. // BrowserObserver:
  65. void OnBeforeQuit(bool* prevent_default) override;
  66. void OnWillQuit(bool* prevent_default) override;
  67. void OnWindowAllClosed() override;
  68. void OnQuit() override;
  69. void OnOpenFile(bool* prevent_default, const std::string& file_path) override;
  70. void OnOpenURL(const std::string& url) override;
  71. void OnActivate(bool has_visible_windows) override;
  72. void OnWillFinishLaunching() override;
  73. void OnFinishLaunching(const base::DictionaryValue& launch_info) override;
  74. void OnLogin(LoginHandler* login_handler,
  75. const base::DictionaryValue& request_details) override;
  76. void OnAccessibilitySupportChanged() override;
  77. #if defined(OS_MACOSX)
  78. void OnContinueUserActivity(
  79. bool* prevent_default,
  80. const std::string& type,
  81. const base::DictionaryValue& user_info) override;
  82. #endif
  83. // content::ContentBrowserClient:
  84. void AllowCertificateError(
  85. content::WebContents* web_contents,
  86. int cert_error,
  87. const net::SSLInfo& ssl_info,
  88. const GURL& request_url,
  89. content::ResourceType resource_type,
  90. bool overridable,
  91. bool strict_enforcement,
  92. bool expired_previous_decision,
  93. const base::Callback<void(content::CertificateRequestResultType)>&
  94. callback) override;
  95. void SelectClientCertificate(
  96. content::WebContents* web_contents,
  97. net::SSLCertRequestInfo* cert_request_info,
  98. std::unique_ptr<content::ClientCertificateDelegate> delegate) override;
  99. // content::GpuDataManagerObserver:
  100. void OnGpuProcessCrashed(base::TerminationStatus status) override;
  101. private:
  102. void SetAppPath(const base::FilePath& app_path);
  103. // Get/Set the pre-defined path in PathService.
  104. base::FilePath GetPath(mate::Arguments* args, const std::string& name);
  105. void SetPath(mate::Arguments* args,
  106. const std::string& name,
  107. const base::FilePath& path);
  108. void SetDesktopName(const std::string& desktop_name);
  109. std::string GetLocale();
  110. bool MakeSingleInstance(
  111. const ProcessSingleton::NotificationCallback& callback);
  112. void ReleaseSingleInstance();
  113. bool Relaunch(mate::Arguments* args);
  114. void DisableHardwareAcceleration(mate::Arguments* args);
  115. bool IsAccessibilitySupportEnabled();
  116. Browser::LoginItemSettings GetLoginItemSettings(mate::Arguments* args);
  117. #if defined(USE_NSS_CERTS)
  118. void ImportCertificate(const base::DictionaryValue& options,
  119. const net::CompletionCallback& callback);
  120. #endif
  121. void GetFileIcon(const base::FilePath& path,
  122. mate::Arguments* args);
  123. std::vector<mate::Dictionary> GetAppMemoryInfo(v8::Isolate* isolate);
  124. #if defined(OS_WIN)
  125. // Get the current Jump List settings.
  126. v8::Local<v8::Value> GetJumpListSettings();
  127. // Set or remove a custom Jump List for the application.
  128. JumpListResult SetJumpList(v8::Local<v8::Value> val, mate::Arguments* args);
  129. #endif // defined(OS_WIN)
  130. std::unique_ptr<ProcessSingleton> process_singleton_;
  131. #if defined(USE_NSS_CERTS)
  132. std::unique_ptr<CertificateManagerModel> certificate_manager_model_;
  133. #endif
  134. // Tracks tasks requesting file icons.
  135. base::CancelableTaskTracker cancelable_task_tracker_;
  136. base::FilePath app_path_;
  137. DISALLOW_COPY_AND_ASSIGN(App);
  138. };
  139. } // namespace api
  140. } // namespace atom
  141. #endif // ATOM_BROWSER_API_ATOM_API_APP_H_