electron/shell/browser/browser.h
electron-roller[bot] 28ada6ea8b
chore: bump chromium to 100.0.4857.0 (main) (#32419)
* chore: bump chromium in DEPS to 99.0.4819.0

* chore: update patches

* chore: bump chromium in DEPS to 99.0.4824.0

* chore: update patches

* chore: bump chromium in DEPS to 99.0.4827.0

* chore: update patches

* 3352511: PiP: Add inkdrop and pointer cursor to PiP window buttons

https://chromium-review.googlesource.com/c/chromium/src/+/3352511

* 3309164: webhid: Show FIDO devices in the chooser if allowed

https://chromium-review.googlesource.com/c/chromium/src/+/3309164

* 3297868: hid: Add experimental HIDDevice.forget()

https://chromium-review.googlesource.com/c/chromium/src/+/3297868

* 3362491: [Extensions] Move i18n API to //extensions

https://chromium-review.googlesource.com/c/chromium/src/+/3362491

* MCC Refactor step0: Allow embedders to register associated_interface binders with RenderFrameHostImpl::associated_registry_.

https://chromium-review.googlesource.com/c/chromium/src/+/3281481

* 3352616: [Gtk] Remove libgtk from the link-line

https://chromium-review.googlesource.com/c/chromium/src/+/3352616

* 3249211: Clear-Site-Data support for partitioned cookies

https://chromium-review.googlesource.com/c/chromium/src/+/3249211

* [Extensions][COIL] Use [allow|block]list in //extensions/common

https://chromium-review.googlesource.com/c/chromium/src/+/3372668

* Begin ScopedUserPrefUpdate migration to modern base::Value

https://chromium-review.googlesource.com/c/chromium/src/+/3376154

* [Code Health] Refactor PrefService GetDict + GetList to use base::Value

https://chromium-review.googlesource.com/c/chromium/src/+/3343526

* 3354997: [CodeHealth] Remove deprecated SetDictionary method

https://chromium-review.googlesource.com/c/chromium/src/+/3354997

* 3287323: Add LacrosPrefStore for lacros settings

https://chromium-review.googlesource.com/c/chromium/src/+/3287323

* 3365916: [PA] Clean up remaining lazy commit code

https://chromium-review.googlesource.com/c/chromium/src/+/3365916

* [MPArch] Target the external protocol error at the responsible frame.

https://chromium-review.googlesource.com/c/chromium/src/+/3011560

* Pass origin to RegisterNonNetworkSubresourceURLLoaderFactories

https://chromium-review.googlesource.com/c/chromium/src/+/3350608

* Linux: Send OSCrypt raw encryption key to the Network Service

https://chromium-review.googlesource.com/c/chromium/src/+/3320484

* [PlzServiceWorker] Remove remaining references to PlzServiceWorker.

https://chromium-review.googlesource.com/c/chromium/src/+/3359441

* chore: fixup for lint

* 3327621: Fix tablet mode detection for Win 11.

https://chromium-review.googlesource.com/c/chromium/src/+/3327621

* 3342428: ax_mac: move AXTextMarker conversion utils under ui umbrella

https://chromium-review.googlesource.com/c/chromium/src/+/3342428

* 3353974: Mac: Use base::Feature for overlay features

https://chromium-review.googlesource.com/c/chromium/src/+/3353974

* chore: bump chromium in DEPS to 99.0.4828.0

* chore: update patches

* chore: bump chromium in DEPS to 99.0.4837.0

* chore: update patches

* chore: update patches

* 3379142: Drop FALLTHROUGH macro
Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3379142

* 3381749: C++17: Allow use of std::map::try_emplace and std::map::insert_or_assign
Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3381749

* chore: bump chromium in DEPS to 99.0.4839.0

* chore: update patches

* chore: bump chromium in DEPS to 99.0.4840.0

* chore: bump chromium in DEPS to 99.0.4844.0

* 3395881: [api] Deprecate Local<v8::Context> v8::Object::CreationContext()

Ref: https://chromium-review.googlesource.com/c/v8/v8/+/3395881

* chore: update patches

* chore: bump chromium in DEPS to 100.0.4845.0

* chore: update patches

* chore: bump chromium in DEPS to 100.0.4847.0

* chore: update patches

* chore: bump chromium in DEPS to 100.0.4849.0

* chore: update patches

* chore: bump chromium in DEPS to 100.0.4851.0

* chore: bump chromium in DEPS to 100.0.4853.0

* update patches

* chore: update patches

* update patches

* 3383599: Fonts Access: Remove prototype that uses a font picker.

https://chromium-review.googlesource.com/c/chromium/src/+/3383599

* 3404768: Remove ALLOW_UNUSED macros

https://chromium-review.googlesource.com/c/chromium/src/+/3404768

* 3374762: Remove ignore_result.h

https://chromium-review.googlesource.com/c/chromium/src/+/3374762

* 3399305: [unseasoned-pdf] Apply proper frame offsets for touch selections

https://chromium-review.googlesource.com/c/chromium/src/+/3399305

* 3402210: [Extensions] Don't trigger unload event for already unloaded extension

https://chromium-review.googlesource.com/c/chromium/src/+/3402210

* 3410912: Combine URLLoaderClient OnReceiveResponse and OnStartLoadingResponseBody.

https://chromium-review.googlesource.com/c/chromium/src/+/3410912

* 3370428: Make the AuthSchemes policy support dynamic refresh

https://chromium-review.googlesource.com/c/chromium/src/+/3370428

* 3407603: Finish ScopedUserPrefUpdate migration to modern base::Value

https://chromium-review.googlesource.com/c/chromium/src/+/3407603

* 3378352: ozone/x11: move code from //ui/p/x11 to //ui/ozone/p/x11

https://chromium-review.googlesource.com/c/chromium/src/+/3378352

* 3370810: Delete chrome/service, AKA the Cloud Print service process.

https://chromium-review.googlesource.com/c/chromium/src/+/3370810

* chore: bump chromium in DEPS to 100.0.4855.0

* chore: update patches

* fixup! 3370810: Delete chrome/service, AKA the Cloud Print service process.

* revert 3348007 to fix windows build

* 3318572: [Code health] Fix gn check errors in //extensions/browser:*

https://chromium-review.googlesource.com/c/chromium/src/+/3318572

* fix printing.patch

* fix iwyu issue

* 3408515: win: Make ShorcutOperation an enum class and modernize names

https://chromium-review.googlesource.com/c/chromium/src/+/3408515

* 3388333: [UIA] Remove dead code accessibility_misc_utils.h/cc

https://chromium-review.googlesource.com/c/chromium/src/+/3388333

* fix windows build? i hope

* patch gn visibility of //ui/ozone/platform/x11

* missing include base/logging.h

* use BUILDFLAG for USE_NSS_CERTS

https://chromium-review.googlesource.com/c/chromium/src/+/3379123

* defined(OS_*) ==> BUILDFLAG(IS_*)

https://bugs.chromium.org/p/chromium/issues/detail?id=1234043

* fixup! 3404768: Remove ALLOW_UNUSED macros

* another attempt to fix windows build

* temporarily disable the custom scheme service worker test

https://github.com/electron/electron/issues/32664

* fix loading mv3 extensions

not sure what cl broke this unfort.

* fixup! 3404768: Remove ALLOW_UNUSED macros

* patch nan

https://chromium-review.googlesource.com/c/v8/v8/+/3395880

* fix node test

* fix nullptr in FindPdfFrame

* patch perfetto to fix build issue on win-ia32

bc44c3c753

* fix build for linux-x64-testing-no-run-as-node

* fix patch

* skip <webview>.capturePage() test

https://github.com/electron/electron/issues/32705

* test: fix failing tests of focus/blur events of WebContents (#32711)

* inherit stdio from app module test child processes

this prevents them from timing out due to full stdout buffers

* test to see if we can get better logs on windows ci

* try again for appveyor log things

* skip contentTracing tests on ia32

* ci: disable gpu compositing

* drop applied patch

* fix merge fail

* Revert "ci: disable gpu compositing"

This reverts commit 0344129fcb19ea3e87e06c1110d751f22eba3fec.

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: John Kleinschmidt <jkleinsc@github.com>
Co-authored-by: VerteDinde <khammond@slack-corp.com>
Co-authored-by: VerteDinde <vertedinde@electronjs.org>
Co-authored-by: Jeremy Rose <jeremya@chromium.org>
Co-authored-by: Jeremy Rose <nornagon@nornagon.net>
Co-authored-by: Cheng Zhao <zcbenz@gmail.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
2022-02-09 18:58:52 -08:00

381 lines
11 KiB
C++
Executable file

// Copyright (c) 2013 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_BROWSER_H_
#define ELECTRON_SHELL_BROWSER_BROWSER_H_
#include <memory>
#include <string>
#include <vector>
#include "base/compiler_specific.h"
#include "base/observer_list.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/values.h"
#include "gin/dictionary.h"
#include "shell/browser/browser_observer.h"
#include "shell/browser/window_list_observer.h"
#include "shell/common/gin_helper/promise.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include "base/files/file_path.h"
#include "shell/browser/ui/win/taskbar_host.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "ui/base/cocoa/secure_password_input.h"
#endif
namespace base {
class FilePath;
}
namespace gin_helper {
class Arguments;
}
namespace electron {
class ElectronMenuModel;
// This class is used for control application-wide operations.
class Browser : public WindowListObserver {
public:
Browser();
~Browser() override;
// disable copy
Browser(const Browser&) = delete;
Browser& operator=(const Browser&) = delete;
static Browser* Get();
// Try to close all windows and quit the application.
void Quit();
// Exit the application immediately and set exit code.
void Exit(gin::Arguments* args);
// Cleanup everything and shutdown the application gracefully.
void Shutdown();
// Focus the application.
void Focus(gin::Arguments* args);
// Returns the version of the executable (or bundle).
std::string GetVersion() const;
// Overrides the application version.
void SetVersion(const std::string& version);
// Returns the application's name, default is just Electron.
std::string GetName() const;
// Overrides the application name.
void SetName(const std::string& name);
// Add the |path| to recent documents list.
void AddRecentDocument(const base::FilePath& path);
// Clear the recent documents list.
void ClearRecentDocuments();
#if BUILDFLAG(IS_WIN)
// Set the application user model ID.
void SetAppUserModelID(const std::wstring& name);
#endif
// Remove the default protocol handler registry key
bool RemoveAsDefaultProtocolClient(const std::string& protocol,
gin::Arguments* args);
// Set as default handler for a protocol.
bool SetAsDefaultProtocolClient(const std::string& protocol,
gin::Arguments* args);
// Query the current state of default handler for a protocol.
bool IsDefaultProtocolClient(const std::string& protocol,
gin::Arguments* args);
std::u16string GetApplicationNameForProtocol(const GURL& url);
#if !BUILDFLAG(IS_LINUX)
// get the name, icon and path for an application
v8::Local<v8::Promise> GetApplicationInfoForProtocol(v8::Isolate* isolate,
const GURL& url);
#endif
// Set/Get the badge count.
bool SetBadgeCount(absl::optional<int> count);
int GetBadgeCount();
#if BUILDFLAG(IS_WIN)
struct LaunchItem {
std::wstring name;
std::wstring path;
std::wstring scope;
std::vector<std::wstring> args;
bool enabled = true;
LaunchItem();
~LaunchItem();
LaunchItem(const LaunchItem&);
};
#endif
// Set/Get the login item settings of the app
struct LoginItemSettings {
bool open_at_login = false;
bool open_as_hidden = false;
bool restore_state = false;
bool opened_at_login = false;
bool opened_as_hidden = false;
std::u16string path;
std::vector<std::u16string> args;
#if BUILDFLAG(IS_WIN)
// used in browser::setLoginItemSettings
bool enabled = true;
std::wstring name;
// used in browser::getLoginItemSettings
bool executable_will_launch_at_login = false;
std::vector<LaunchItem> launch_items;
#endif
LoginItemSettings();
~LoginItemSettings();
LoginItemSettings(const LoginItemSettings&);
};
void SetLoginItemSettings(LoginItemSettings settings);
LoginItemSettings GetLoginItemSettings(const LoginItemSettings& options);
#if BUILDFLAG(IS_MAC)
// Set the handler which decides whether to shutdown.
void SetShutdownHandler(base::RepeatingCallback<bool()> handler);
// Hide the application.
void Hide();
// Show the application.
void Show();
// Creates an activity and sets it as the one currently in use.
void SetUserActivity(const std::string& type,
base::DictionaryValue user_info,
gin::Arguments* args);
// Returns the type name of the current user activity.
std::string GetCurrentActivityType();
// Invalidates an activity and marks it as no longer eligible for
// continuation
void InvalidateCurrentActivity();
// Marks this activity object as inactive without invalidating it.
void ResignCurrentActivity();
// Updates the current user activity
void UpdateCurrentActivity(const std::string& type,
base::DictionaryValue user_info);
// Indicates that an user activity is about to be resumed.
bool WillContinueUserActivity(const std::string& type);
// Indicates a failure to resume a Handoff activity.
void DidFailToContinueUserActivity(const std::string& type,
const std::string& error);
// Resumes an activity via hand-off.
bool ContinueUserActivity(const std::string& type,
base::DictionaryValue user_info,
base::DictionaryValue details);
// Indicates that an activity was continued on another device.
void UserActivityWasContinued(const std::string& type,
base::DictionaryValue user_info);
// Gives an opportunity to update the Handoff payload.
bool UpdateUserActivityState(const std::string& type,
base::DictionaryValue user_info);
// Bounce the dock icon.
enum class BounceType{
kCritical = 0, // NSCriticalRequest
kInformational = 10, // NSInformationalRequest
};
int DockBounce(BounceType type);
void DockCancelBounce(int request_id);
// Bounce the Downloads stack.
void DockDownloadFinished(const std::string& filePath);
// Set/Get dock's badge text.
void DockSetBadgeText(const std::string& label);
std::string DockGetBadgeText();
// Hide/Show dock.
void DockHide();
v8::Local<v8::Promise> DockShow(v8::Isolate* isolate);
bool DockIsVisible();
// Set docks' menu.
void DockSetMenu(ElectronMenuModel* model);
// Set docks' icon.
void DockSetIcon(v8::Isolate* isolate, v8::Local<v8::Value> icon);
#endif // BUILDFLAG(IS_MAC)
void ShowAboutPanel();
void SetAboutPanelOptions(base::DictionaryValue options);
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
void ShowEmojiPanel();
#endif
#if BUILDFLAG(IS_WIN)
struct UserTask {
base::FilePath program;
std::wstring arguments;
std::wstring title;
std::wstring description;
base::FilePath working_dir;
base::FilePath icon_path;
int icon_index;
UserTask();
UserTask(const UserTask&);
~UserTask();
};
// Add a custom task to jump list.
bool SetUserTasks(const std::vector<UserTask>& tasks);
// Returns the application user model ID, if there isn't one, then create
// one from app's name.
// The returned string managed by Browser, and should not be modified.
PCWSTR GetAppUserModelID();
#endif // BUILDFLAG(IS_WIN)
#if BUILDFLAG(IS_LINUX)
// Whether Unity launcher is running.
bool IsUnityRunning();
#endif // BUILDFLAG(IS_LINUX)
// Tell the application to open a file.
bool OpenFile(const std::string& file_path);
// Tell the application to open a url.
void OpenURL(const std::string& url);
#if BUILDFLAG(IS_MAC)
// Tell the application to create a new window for a tab.
void NewWindowForTab();
// Tell the application that application did become active
void DidBecomeActive();
#endif // BUILDFLAG(IS_MAC)
// Tell the application that application is activated with visible/invisible
// windows.
void Activate(bool has_visible_windows);
bool IsEmojiPanelSupported();
// Tell the application the loading has been done.
void WillFinishLaunching();
void DidFinishLaunching(base::DictionaryValue launch_info);
void OnAccessibilitySupportChanged();
void PreMainMessageLoopRun();
void PreCreateThreads();
// Stores the supplied |quit_closure|, to be run when the last Browser
// instance is destroyed.
void SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure);
void AddObserver(BrowserObserver* obs) { observers_.AddObserver(obs); }
void RemoveObserver(BrowserObserver* obs) { observers_.RemoveObserver(obs); }
#if BUILDFLAG(IS_MAC)
// Returns whether secure input is enabled
bool IsSecureKeyboardEntryEnabled();
void SetSecureKeyboardEntryEnabled(bool enabled);
#endif
bool is_shutting_down() const { return is_shutdown_; }
bool is_quitting() const { return is_quitting_; }
bool is_ready() const { return is_ready_; }
v8::Local<v8::Value> WhenReady(v8::Isolate* isolate);
protected:
// Returns the version of application bundle or executable file.
std::string GetExecutableFileVersion() const;
// Returns the name of application bundle or executable file.
std::string GetExecutableFileProductName() const;
// Send the will-quit message and then shutdown the application.
void NotifyAndShutdown();
// Send the before-quit message and start closing windows.
bool HandleBeforeQuit();
bool is_quitting_ = false;
private:
// WindowListObserver implementations:
void OnWindowCloseCancelled(NativeWindow* window) override;
void OnWindowAllClosed() override;
// Observers of the browser.
base::ObserverList<BrowserObserver> observers_;
// Tracks tasks requesting file icons.
base::CancelableTaskTracker cancelable_task_tracker_;
// Whether `app.exit()` has been called
bool is_exiting_ = false;
// Whether "ready" event has been emitted.
bool is_ready_ = false;
// The browser is being shutdown.
bool is_shutdown_ = false;
// Null until/unless the default main message loop is running.
base::OnceClosure quit_main_message_loop_;
int badge_count_ = 0;
std::unique_ptr<gin_helper::Promise<void>> ready_promise_;
#if BUILDFLAG(IS_MAC)
std::unique_ptr<ui::ScopedPasswordInputEnabler> password_input_enabler_;
base::Time last_dock_show_;
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
base::Value about_panel_options_;
#elif BUILDFLAG(IS_MAC)
base::DictionaryValue about_panel_options_;
#endif
#if BUILDFLAG(IS_WIN)
void UpdateBadgeContents(HWND hwnd,
const absl::optional<std::string>& badge_content,
const std::string& badge_alt_string);
// In charge of running taskbar related APIs.
TaskbarHost taskbar_host_;
#endif
};
} // namespace electron
#endif // ELECTRON_SHELL_BROWSER_BROWSER_H_