e70ce89235
* chore: iwyu shell/browser/electron_pdf_document_helper_client.h * chore: iwyu shell/browser/hid/electron_hid_delegate.h * chore: iwyu content/public/browser/web_contents.h * chore: iwyu shell/browser/usb/electron_usb_delegate.h * chore: iwyu shell/browser/browser_observer.h * chore: iwyu shell/browser/bluetooth/electron_bluetooth_delegate.h * chore: iwyu shell/browser/serial/electron_serial_delegate.h * chore: iwyu shell/browser/api/frame_subscriber.h * chore: iwyu mojo/public/cpp/bindings/ * chore: iwyu components/ * chore: iwyu extensions/ * chore: iwyu shell/common/gin_helper/ * chore: iwyu v8/ * chore: iwyu base/containers/linked_list.h * chore: iwyu shell/browser/native_window.h * chore: iwyu shell/browser/api/electron_api_base_window.h * chore: iwyu shell/common/node_includes.h * chore: iwyu gin/handle.h * chore: iwyu base/functional/callback.h * chore: iwyu ui/gfx/ * chore: iwyu content/public/browser/render_frame_host.h * fix: mac * fix: mac * fix: win * chore: iwyu base/files/file_path.h * chore: iwyu base/unguessable_token.h * chore: iwyu ui/display/screen.h * chore: iwyu chrome/browser/predictors/preconnect_manager.h * chore: iwyu base/observer_list_types.h * chore: iwyu content/public/browser/web_contents.h * chore: iwyu chrome/browser/devtools/devtools_eye_dropper.h * chore: iwyu shell/browser/ui/inspectable_web_contents.h * chore: iwyu content/public/browser/keyboard_event_processing_result.h * chore: iwyu net/cookies/canonical_cookie.h * chore: iwyu net/base/address_list.h * chore: iwyu net/cert/x509_certificate.h * chore: iwyu net/cookies/cookie_change_dispatcher.h * chore: iwyu net/dns/public/host_resolver_results.h * fix: mac * Revert "chore: iwyu net/cert/x509_certificate.h" This reverts commit 002896f71146e90f1e29e090a1d6eede48cee11e.
170 lines
5.6 KiB
C++
170 lines
5.6 KiB
C++
// Copyright (c) 2016 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_SYSTEM_PREFERENCES_H_
|
|
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_SYSTEM_PREFERENCES_H_
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "base/values.h"
|
|
#include "gin/wrappable.h"
|
|
#include "shell/browser/event_emitter_mixin.h"
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
#include "shell/browser/browser.h"
|
|
#include "shell/browser/browser_observer.h"
|
|
#include "ui/gfx/sys_color_change_listener.h"
|
|
#endif
|
|
|
|
namespace gin {
|
|
template <typename T>
|
|
class Handle;
|
|
} // namespace gin
|
|
|
|
namespace gin_helper {
|
|
class ErrorThrower;
|
|
} // namespace gin_helper
|
|
|
|
namespace electron::api {
|
|
|
|
#if BUILDFLAG(IS_MAC)
|
|
enum class NotificationCenterKind {
|
|
kNSDistributedNotificationCenter = 0,
|
|
kNSNotificationCenter,
|
|
kNSWorkspaceNotificationCenter,
|
|
};
|
|
#endif
|
|
|
|
class SystemPreferences
|
|
: public gin::Wrappable<SystemPreferences>,
|
|
public gin_helper::EventEmitterMixin<SystemPreferences>
|
|
#if BUILDFLAG(IS_WIN)
|
|
,
|
|
public BrowserObserver,
|
|
public gfx::SysColorChangeListener
|
|
#endif
|
|
{
|
|
public:
|
|
static gin::Handle<SystemPreferences> Create(v8::Isolate* isolate);
|
|
|
|
// gin::Wrappable
|
|
static gin::WrapperInfo kWrapperInfo;
|
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
|
v8::Isolate* isolate) override;
|
|
const char* GetTypeName() override;
|
|
|
|
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
|
|
std::string GetAccentColor();
|
|
std::string GetColor(gin_helper::ErrorThrower thrower,
|
|
const std::string& color);
|
|
std::string GetMediaAccessStatus(gin_helper::ErrorThrower thrower,
|
|
const std::string& media_type);
|
|
#endif
|
|
#if BUILDFLAG(IS_WIN)
|
|
bool IsAeroGlassEnabled();
|
|
|
|
void InitializeWindow();
|
|
|
|
// gfx::SysColorChangeListener:
|
|
void OnSysColorChange() override;
|
|
|
|
// BrowserObserver:
|
|
void OnFinishLaunching(base::Value::Dict launch_info) override;
|
|
|
|
#elif BUILDFLAG(IS_MAC)
|
|
using NotificationCallback = base::RepeatingCallback<
|
|
void(const std::string&, base::Value, const std::string&)>;
|
|
|
|
void PostNotification(const std::string& name,
|
|
base::Value::Dict user_info,
|
|
gin::Arguments* args);
|
|
int SubscribeNotification(v8::Local<v8::Value> maybe_name,
|
|
const NotificationCallback& callback);
|
|
void UnsubscribeNotification(int id);
|
|
void PostLocalNotification(const std::string& name,
|
|
base::Value::Dict user_info);
|
|
int SubscribeLocalNotification(v8::Local<v8::Value> maybe_name,
|
|
const NotificationCallback& callback);
|
|
void UnsubscribeLocalNotification(int request_id);
|
|
void PostWorkspaceNotification(const std::string& name,
|
|
base::Value::Dict user_info);
|
|
int SubscribeWorkspaceNotification(v8::Local<v8::Value> maybe_name,
|
|
const NotificationCallback& callback);
|
|
void UnsubscribeWorkspaceNotification(int request_id);
|
|
v8::Local<v8::Value> GetUserDefault(v8::Isolate* isolate,
|
|
const std::string& name,
|
|
const std::string& type);
|
|
void RegisterDefaults(gin::Arguments* args);
|
|
void SetUserDefault(const std::string& name,
|
|
const std::string& type,
|
|
gin::Arguments* args);
|
|
void RemoveUserDefault(const std::string& name);
|
|
bool IsSwipeTrackingFromScrollEventsEnabled();
|
|
bool AccessibilityDisplayShouldReduceTransparency();
|
|
|
|
std::string GetSystemColor(gin_helper::ErrorThrower thrower,
|
|
const std::string& color);
|
|
|
|
bool CanPromptTouchID();
|
|
v8::Local<v8::Promise> PromptTouchID(v8::Isolate* isolate,
|
|
const std::string& reason);
|
|
|
|
static bool IsTrustedAccessibilityClient(bool prompt);
|
|
|
|
v8::Local<v8::Promise> AskForMediaAccess(v8::Isolate* isolate,
|
|
const std::string& media_type);
|
|
|
|
// TODO(MarshallOfSound): Write tests for these methods once we
|
|
// are running tests on a Mojave machine
|
|
v8::Local<v8::Value> GetEffectiveAppearance(v8::Isolate* isolate);
|
|
#endif
|
|
v8::Local<v8::Value> GetAnimationSettings(v8::Isolate* isolate);
|
|
|
|
// disable copy
|
|
SystemPreferences(const SystemPreferences&) = delete;
|
|
SystemPreferences& operator=(const SystemPreferences&) = delete;
|
|
|
|
protected:
|
|
SystemPreferences();
|
|
~SystemPreferences() override;
|
|
|
|
#if BUILDFLAG(IS_MAC)
|
|
int DoSubscribeNotification(v8::Local<v8::Value> maybe_name,
|
|
const NotificationCallback& callback,
|
|
NotificationCenterKind kind);
|
|
void DoUnsubscribeNotification(int request_id, NotificationCenterKind kind);
|
|
#endif
|
|
|
|
private:
|
|
#if BUILDFLAG(IS_WIN)
|
|
// Static callback invoked when a message comes in to our messaging window.
|
|
static LRESULT CALLBACK WndProcStatic(HWND hwnd,
|
|
UINT message,
|
|
WPARAM wparam,
|
|
LPARAM lparam);
|
|
|
|
LRESULT CALLBACK WndProc(HWND hwnd,
|
|
UINT message,
|
|
WPARAM wparam,
|
|
LPARAM lparam);
|
|
|
|
// The window class of |window_|.
|
|
ATOM atom_;
|
|
|
|
// The handle of the module that contains the window procedure of |window_|.
|
|
HMODULE instance_;
|
|
|
|
// The window used for processing events.
|
|
HWND window_;
|
|
|
|
std::string current_color_;
|
|
|
|
std::unique_ptr<gfx::ScopedSysColorChangeListener> color_change_listener_;
|
|
#endif
|
|
};
|
|
|
|
} // namespace electron::api
|
|
|
|
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_SYSTEM_PREFERENCES_H_
|