2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-05-02 16:05:09 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_API_ATOM_API_APP_H_
|
|
|
|
#define ATOM_BROWSER_API_ATOM_API_APP_H_
|
|
|
|
|
2017-05-26 15:32:08 +00:00
|
|
|
#include <memory>
|
2014-03-16 01:13:06 +00:00
|
|
|
#include <string>
|
2017-05-26 14:51:17 +00:00
|
|
|
#include <utility>
|
2016-09-15 13:37:35 +00:00
|
|
|
#include <vector>
|
2014-03-16 01:13:06 +00:00
|
|
|
|
2014-04-17 09:13:46 +00:00
|
|
|
#include "atom/browser/api/event_emitter.h"
|
2015-11-18 02:07:03 +00:00
|
|
|
#include "atom/browser/atom_browser_client.h"
|
2017-01-30 22:01:40 +00:00
|
|
|
#include "atom/browser/browser.h"
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/browser_observer.h"
|
2015-10-19 21:43:04 +00:00
|
|
|
#include "atom/common/native_mate_converters/callback.h"
|
2017-04-17 11:59:16 +00:00
|
|
|
#include "base/process/process_iterator.h"
|
2017-02-16 19:19:19 +00:00
|
|
|
#include "base/task/cancelable_task_tracker.h"
|
|
|
|
#include "chrome/browser/icon_manager.h"
|
2015-10-20 21:36:01 +00:00
|
|
|
#include "chrome/browser/process_singleton.h"
|
2017-05-16 00:41:45 +00:00
|
|
|
#include "content/public/browser/browser_child_process_observer.h"
|
2015-06-25 12:28:07 +00:00
|
|
|
#include "content/public/browser/gpu_data_manager_observer.h"
|
2017-05-16 00:41:45 +00:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2017-04-28 04:07:35 +00:00
|
|
|
#include "native_mate/dictionary.h"
|
2014-04-17 09:13:46 +00:00
|
|
|
#include "native_mate/handle.h"
|
2016-04-18 05:11:31 +00:00
|
|
|
#include "net/base/completion_callback.h"
|
2017-08-20 21:35:04 +00:00
|
|
|
#include "net/ssl/client_cert_identity.h"
|
2013-05-02 16:05:09 +00:00
|
|
|
|
2016-04-19 05:17:28 +00:00
|
|
|
#if defined(USE_NSS_CERTS)
|
|
|
|
#include "chrome/browser/certificate_manager_model.h"
|
|
|
|
#endif
|
|
|
|
|
2014-08-19 13:26:45 +00:00
|
|
|
namespace base {
|
|
|
|
class FilePath;
|
|
|
|
}
|
|
|
|
|
2015-01-19 04:24:58 +00:00
|
|
|
namespace mate {
|
|
|
|
class Arguments;
|
2016-08-12 09:31:17 +00:00
|
|
|
} // namespace mate
|
2015-10-20 20:27:34 +00:00
|
|
|
|
2013-05-02 16:05:09 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2016-08-12 09:31:17 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
enum class JumpListResult : int;
|
|
|
|
#endif
|
|
|
|
|
2017-05-16 00:41:45 +00:00
|
|
|
struct ProcessMetric {
|
2017-05-26 15:53:26 +00:00
|
|
|
int type;
|
2017-05-16 00:41:45 +00:00
|
|
|
base::ProcessId pid;
|
|
|
|
std::unique_ptr<base::ProcessMetrics> metrics;
|
2017-05-26 14:51:17 +00:00
|
|
|
|
2017-05-26 15:53:26 +00:00
|
|
|
ProcessMetric(int type,
|
2017-05-16 00:41:45 +00:00
|
|
|
base::ProcessId pid,
|
2018-04-17 23:37:22 +00:00
|
|
|
std::unique_ptr<base::ProcessMetrics> metrics);
|
|
|
|
~ProcessMetric();
|
2017-05-16 00:41:45 +00:00
|
|
|
};
|
|
|
|
|
2013-05-02 16:05:09 +00:00
|
|
|
namespace api {
|
|
|
|
|
2015-11-18 02:07:03 +00:00
|
|
|
class App : public AtomBrowserClient::Delegate,
|
2016-04-25 01:17:54 +00:00
|
|
|
public mate::EventEmitter<App>,
|
2015-06-25 12:28:07 +00:00
|
|
|
public BrowserObserver,
|
2017-05-16 00:41:45 +00:00
|
|
|
public content::GpuDataManagerObserver,
|
|
|
|
public content::BrowserChildProcessObserver {
|
2013-05-02 16:05:09 +00:00
|
|
|
public:
|
2018-04-18 01:44:10 +00:00
|
|
|
using FileIconCallback =
|
|
|
|
base::Callback<void(v8::Local<v8::Value>, const gfx::Image&)>;
|
2016-11-02 18:57:16 +00:00
|
|
|
|
2014-04-17 09:13:46 +00:00
|
|
|
static mate::Handle<App> Create(v8::Isolate* isolate);
|
2013-05-02 16:05:09 +00:00
|
|
|
|
2016-04-25 01:17:54 +00:00
|
|
|
static void BuildPrototype(v8::Isolate* isolate,
|
2016-08-02 09:08:12 +00:00
|
|
|
v8::Local<v8::FunctionTemplate> prototype);
|
2016-04-25 01:17:54 +00:00
|
|
|
|
2016-04-19 05:17:28 +00:00
|
|
|
#if defined(USE_NSS_CERTS)
|
2016-04-18 05:11:31 +00:00
|
|
|
void OnCertificateManagerModelCreated(
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<base::DictionaryValue> options,
|
2016-04-18 05:11:31 +00:00
|
|
|
const net::CompletionCallback& callback,
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<CertificateManagerModel> model);
|
2016-04-19 05:17:28 +00:00
|
|
|
#endif
|
2016-04-18 05:11:31 +00:00
|
|
|
|
2017-04-13 14:26:42 +00:00
|
|
|
base::FilePath GetAppPath() const;
|
2017-05-25 04:15:34 +00:00
|
|
|
void RenderProcessReady(content::RenderProcessHost* host);
|
2017-05-26 15:32:08 +00:00
|
|
|
void RenderProcessDisconnected(base::ProcessId host_pid);
|
2017-09-14 13:08:18 +00:00
|
|
|
void PreMainMessageLoopRun();
|
2017-04-04 00:36:01 +00:00
|
|
|
|
2013-05-03 02:53:54 +00:00
|
|
|
protected:
|
2016-04-25 01:17:54 +00:00
|
|
|
explicit App(v8::Isolate* isolate);
|
|
|
|
~App() override;
|
2013-05-03 02:53:54 +00:00
|
|
|
|
2014-11-16 14:45:29 +00:00
|
|
|
// BrowserObserver:
|
2015-02-26 03:33:42 +00:00
|
|
|
void OnBeforeQuit(bool* prevent_default) override;
|
2014-11-16 14:45:29 +00:00
|
|
|
void OnWillQuit(bool* prevent_default) override;
|
|
|
|
void OnWindowAllClosed() override;
|
|
|
|
void OnQuit() override;
|
|
|
|
void OnOpenFile(bool* prevent_default, const std::string& file_path) override;
|
|
|
|
void OnOpenURL(const std::string& url) override;
|
2015-09-15 02:05:53 +00:00
|
|
|
void OnActivate(bool has_visible_windows) override;
|
2014-11-16 14:45:29 +00:00
|
|
|
void OnWillFinishLaunching() override;
|
2016-09-01 00:17:44 +00:00
|
|
|
void OnFinishLaunching(const base::DictionaryValue& launch_info) override;
|
2016-06-08 13:52:21 +00:00
|
|
|
void OnLogin(LoginHandler* login_handler,
|
|
|
|
const base::DictionaryValue& request_details) override;
|
2016-07-11 21:32:14 +00:00
|
|
|
void OnAccessibilitySupportChanged() override;
|
2017-09-15 19:33:12 +00:00
|
|
|
void OnPreMainMessageLoopRun() override;
|
2016-05-05 03:26:23 +00:00
|
|
|
#if defined(OS_MACOSX)
|
2018-04-18 01:44:10 +00:00
|
|
|
void OnWillContinueUserActivity(bool* prevent_default,
|
|
|
|
const std::string& type) override;
|
|
|
|
void OnDidFailToContinueUserActivity(const std::string& type,
|
|
|
|
const std::string& error) override;
|
|
|
|
void OnContinueUserActivity(bool* prevent_default,
|
|
|
|
const std::string& type,
|
|
|
|
const base::DictionaryValue& user_info) override;
|
2017-06-26 19:14:44 +00:00
|
|
|
void OnUserActivityWasContinued(
|
|
|
|
const std::string& type,
|
|
|
|
const base::DictionaryValue& user_info) override;
|
|
|
|
void OnUpdateUserActivityState(
|
2017-08-09 15:09:47 +00:00
|
|
|
bool* prevent_default,
|
2017-06-26 19:14:44 +00:00
|
|
|
const std::string& type,
|
|
|
|
const base::DictionaryValue& user_info) override;
|
2017-06-11 08:19:01 +00:00
|
|
|
void OnNewWindowForTab() override;
|
2016-05-05 03:26:23 +00:00
|
|
|
#endif
|
2015-11-18 02:07:03 +00:00
|
|
|
|
|
|
|
// content::ContentBrowserClient:
|
2015-11-18 02:39:25 +00:00
|
|
|
void AllowCertificateError(
|
2016-03-08 14:28:53 +00:00
|
|
|
content::WebContents* web_contents,
|
2015-11-18 02:39:25 +00:00
|
|
|
int cert_error,
|
|
|
|
const net::SSLInfo& ssl_info,
|
|
|
|
const GURL& request_url,
|
|
|
|
content::ResourceType resource_type,
|
|
|
|
bool strict_enforcement,
|
|
|
|
bool expired_previous_decision,
|
2016-11-30 07:30:03 +00:00
|
|
|
const base::Callback<void(content::CertificateRequestResultType)>&
|
|
|
|
callback) override;
|
2015-11-18 02:07:03 +00:00
|
|
|
void SelectClientCertificate(
|
2015-06-11 15:22:07 +00:00
|
|
|
content::WebContents* web_contents,
|
|
|
|
net::SSLCertRequestInfo* cert_request_info,
|
2017-08-20 21:35:04 +00:00
|
|
|
net::ClientCertIdentityList client_certs,
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<content::ClientCertificateDelegate> delegate) override;
|
2017-12-07 04:12:38 +00:00
|
|
|
bool CanCreateWindow(content::RenderFrameHost* opener,
|
|
|
|
const GURL& opener_url,
|
|
|
|
const GURL& opener_top_level_frame_url,
|
|
|
|
const GURL& source_origin,
|
|
|
|
content::mojom::WindowContainerType container_type,
|
|
|
|
const GURL& target_url,
|
|
|
|
const content::Referrer& referrer,
|
|
|
|
const std::string& frame_name,
|
|
|
|
WindowOpenDisposition disposition,
|
|
|
|
const blink::mojom::WindowFeatures& features,
|
|
|
|
const std::vector<std::string>& additional_features,
|
|
|
|
const scoped_refptr<content::ResourceRequestBody>& body,
|
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access) override;
|
2014-11-16 14:45:29 +00:00
|
|
|
|
2015-06-25 12:28:07 +00:00
|
|
|
// content::GpuDataManagerObserver:
|
2016-09-18 00:00:45 +00:00
|
|
|
void OnGpuProcessCrashed(base::TerminationStatus status) override;
|
2015-06-25 12:28:07 +00:00
|
|
|
|
2017-05-16 00:41:45 +00:00
|
|
|
// content::BrowserChildProcessObserver:
|
|
|
|
void BrowserChildProcessLaunchedAndConnected(
|
|
|
|
const content::ChildProcessData& data) override;
|
|
|
|
void BrowserChildProcessHostDisconnected(
|
|
|
|
const content::ChildProcessData& data) override;
|
2018-04-18 01:44:10 +00:00
|
|
|
void BrowserChildProcessCrashed(const content::ChildProcessData& data,
|
|
|
|
int exit_code) override;
|
|
|
|
void BrowserChildProcessKilled(const content::ChildProcessData& data,
|
|
|
|
int exit_code) override;
|
2017-05-16 00:41:45 +00:00
|
|
|
|
2014-04-17 09:13:46 +00:00
|
|
|
private:
|
2017-04-13 01:59:12 +00:00
|
|
|
void SetAppPath(const base::FilePath& app_path);
|
2017-05-25 04:15:34 +00:00
|
|
|
void ChildProcessLaunched(int process_type, base::ProcessHandle handle);
|
|
|
|
void ChildProcessDisconnected(base::ProcessId pid);
|
2017-04-04 00:36:01 +00:00
|
|
|
|
2015-01-19 01:52:15 +00:00
|
|
|
// Get/Set the pre-defined path in PathService.
|
2015-01-19 04:24:58 +00:00
|
|
|
base::FilePath GetPath(mate::Arguments* args, const std::string& name);
|
|
|
|
void SetPath(mate::Arguments* args,
|
|
|
|
const std::string& name,
|
|
|
|
const base::FilePath& path);
|
2015-01-19 01:52:15 +00:00
|
|
|
|
2014-09-18 11:12:24 +00:00
|
|
|
void SetDesktopName(const std::string& desktop_name);
|
2016-06-02 12:49:29 +00:00
|
|
|
std::string GetLocale();
|
2015-10-22 08:24:35 +00:00
|
|
|
bool MakeSingleInstance(
|
|
|
|
const ProcessSingleton::NotificationCallback& callback);
|
2016-05-26 18:07:19 +00:00
|
|
|
void ReleaseSingleInstance();
|
2016-06-02 12:49:29 +00:00
|
|
|
bool Relaunch(mate::Arguments* args);
|
2016-06-06 11:19:55 +00:00
|
|
|
void DisableHardwareAcceleration(mate::Arguments* args);
|
2017-07-13 22:27:03 +00:00
|
|
|
void DisableDomainBlockingFor3DAPIs(mate::Arguments* args);
|
2016-07-11 21:32:14 +00:00
|
|
|
bool IsAccessibilitySupportEnabled();
|
2017-08-27 14:53:25 +00:00
|
|
|
void SetAccessibilitySupportEnabled(bool enabled);
|
2017-01-30 22:01:40 +00:00
|
|
|
Browser::LoginItemSettings GetLoginItemSettings(mate::Arguments* args);
|
2016-04-19 05:17:28 +00:00
|
|
|
#if defined(USE_NSS_CERTS)
|
2016-04-20 03:15:49 +00:00
|
|
|
void ImportCertificate(const base::DictionaryValue& options,
|
|
|
|
const net::CompletionCallback& callback);
|
2016-04-19 05:17:28 +00:00
|
|
|
#endif
|
2018-04-18 01:44:10 +00:00
|
|
|
void GetFileIcon(const base::FilePath& path, mate::Arguments* args);
|
2015-10-21 20:17:56 +00:00
|
|
|
|
2017-05-16 00:41:45 +00:00
|
|
|
std::vector<mate::Dictionary> GetAppMetrics(v8::Isolate* isolate);
|
2017-05-30 20:00:55 +00:00
|
|
|
v8::Local<v8::Value> GetGPUFeatureStatus(v8::Isolate* isolate);
|
2017-06-26 21:13:41 +00:00
|
|
|
void EnableMixedSandbox(mate::Arguments* args);
|
2017-04-17 11:59:16 +00:00
|
|
|
|
2017-08-31 14:37:12 +00:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
bool MoveToApplicationsFolder(mate::Arguments* args);
|
|
|
|
bool IsInApplicationsFolder();
|
|
|
|
#endif
|
2018-02-12 18:25:06 +00:00
|
|
|
#if defined(MAS_BUILD)
|
|
|
|
base::Callback<void()> StartAccessingSecurityScopedResource(
|
2018-04-18 01:44:10 +00:00
|
|
|
mate::Arguments* args);
|
2018-02-12 18:25:06 +00:00
|
|
|
#endif
|
2017-08-31 14:37:12 +00:00
|
|
|
|
2016-08-12 09:31:17 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Get the current Jump List settings.
|
|
|
|
v8::Local<v8::Value> GetJumpListSettings();
|
|
|
|
|
|
|
|
// Set or remove a custom Jump List for the application.
|
|
|
|
JumpListResult SetJumpList(v8::Local<v8::Value> val, mate::Arguments* args);
|
|
|
|
#endif // defined(OS_WIN)
|
|
|
|
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<ProcessSingleton> process_singleton_;
|
2016-04-19 05:17:28 +00:00
|
|
|
|
|
|
|
#if defined(USE_NSS_CERTS)
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<CertificateManagerModel> certificate_manager_model_;
|
2016-04-19 05:17:28 +00:00
|
|
|
#endif
|
2014-08-19 13:26:45 +00:00
|
|
|
|
2017-02-17 08:33:46 +00:00
|
|
|
// Tracks tasks requesting file icons.
|
|
|
|
base::CancelableTaskTracker cancelable_task_tracker_;
|
|
|
|
|
2017-04-13 01:59:12 +00:00
|
|
|
base::FilePath app_path_;
|
2017-04-04 00:36:01 +00:00
|
|
|
|
2017-05-16 00:41:45 +00:00
|
|
|
using ProcessMetricMap =
|
2018-04-18 01:44:10 +00:00
|
|
|
std::unordered_map<base::ProcessId, std::unique_ptr<atom::ProcessMetric>>;
|
2017-05-16 00:41:45 +00:00
|
|
|
ProcessMetricMap app_metrics_;
|
|
|
|
|
2013-05-03 02:53:54 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(App);
|
2013-05-02 16:05:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_API_ATOM_API_APP_H_
|