electron/atom/browser/api/atom_api_app.h

151 lines
4.8 KiB
C
Raw Normal View History

// 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_
#include <string>
#include <vector>
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"
2014-03-16 00:30:26 +00:00
#include "atom/browser/browser_observer.h"
#include "atom/common/native_mate_converters/callback.h"
2015-10-20 21:36:01 +00:00
#include "chrome/browser/process_singleton.h"
2015-06-25 12:28:07 +00:00
#include "content/public/browser/gpu_data_manager_observer.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"
2013-05-02 16:05:09 +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;
}
namespace mate {
class Arguments;
} // namespace mate
2013-05-02 16:05:09 +00:00
namespace atom {
#if defined(OS_WIN)
enum class JumpListResult : int;
#endif
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,
public content::GpuDataManagerObserver {
2013-05-02 16:05:09 +00:00
public:
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,
v8::Local<v8::FunctionTemplate> prototype);
2016-04-25 01:17:54 +00:00
2016-03-31 14:21:18 +00:00
// Called when window with disposition needs to be created.
void OnCreateWindow(const GURL& target_url,
const std::string& frame_name,
WindowOpenDisposition disposition,
const std::vector<base::string16>& features,
2016-03-31 14:21:18 +00:00
int render_process_id,
int render_frame_id);
#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);
#endif
2016-04-18 05:11:31 +00:00
protected:
2016-04-25 01:17:54 +00:00
explicit App(v8::Isolate* isolate);
~App() override;
2014-11-16 14:45:29 +00:00
// BrowserObserver:
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;
void OnFinishLaunching(const base::DictionaryValue& launch_info) override;
void OnLogin(LoginHandler* login_handler,
const base::DictionaryValue& request_details) override;
void OnAccessibilitySupportChanged() override;
2016-05-05 03:26:23 +00:00
#if defined(OS_MACOSX)
void OnContinueUserActivity(
bool* prevent_default,
const std::string& type,
const base::DictionaryValue& user_info) 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 overridable,
bool strict_enforcement,
bool expired_previous_decision,
const base::Callback<void(bool)>& callback,
content::CertificateRequestResultType* request) override;
2015-11-18 02:07:03 +00:00
void SelectClientCertificate(
content::WebContents* web_contents,
net::SSLCertRequestInfo* cert_request_info,
2016-05-23 01:59:39 +00:00
std::unique_ptr<content::ClientCertificateDelegate> delegate) override;
2014-11-16 14:45:29 +00:00
2015-06-25 12:28:07 +00:00
// content::GpuDataManagerObserver:
void OnGpuProcessCrashed(base::TerminationStatus status) override;
2015-06-25 12:28:07 +00:00
2014-04-17 09:13:46 +00:00
private:
// Get/Set the pre-defined path in PathService.
base::FilePath GetPath(mate::Arguments* args, const std::string& name);
void SetPath(mate::Arguments* args,
const std::string& name,
const base::FilePath& path);
2014-09-18 11:12:24 +00:00
void SetDesktopName(const std::string& desktop_name);
std::string GetLocale();
bool MakeSingleInstance(
const ProcessSingleton::NotificationCallback& callback);
void ReleaseSingleInstance();
bool Relaunch(mate::Arguments* args);
void DisableHardwareAcceleration(mate::Arguments* args);
bool IsAccessibilitySupportEnabled();
#if defined(USE_NSS_CERTS)
void ImportCertificate(const base::DictionaryValue& options,
const net::CompletionCallback& callback);
#endif
2015-10-21 20:17:56 +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_;
#if defined(USE_NSS_CERTS)
2016-05-23 01:59:39 +00:00
std::unique_ptr<CertificateManagerModel> certificate_manager_model_;
#endif
2014-08-19 13:26:45 +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_