30e992dec4
* chore: bump chromium in DEPS to 115.0.5772.0
* chore: update disable_color_correct_rendering.patch
no manual changes; patch succeeded with fuzz 2.
* chore: update chromium/build_libc_as_static_library.patch
no manual changes; patch succeeded with fuzz 2 (offset 1 line).
* chore: update chromium/feat_configure_launch_options_for_service_process.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4518747
patch manually reapplied due to upstream code shear
* chore: update chromium/chore_patch_out_profile_methods_in_profile_selections_cc.patch
https://chromium-review.googlesource.com/c/chromium/src/+/4502965
patch manually reapplied due to upstream code shear
* chore: update bundle_locations #include location
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4525355
* chore: Remove `extension_name` from DesktopStreamsRegistry
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4514081
* chore: bump chromium in DEPS to 115.0.5778.0
* chore: add chromium/chore_patch_out_profile_methods_in_chrome_browser_pdf.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4482679
Another instance of patching out upstream references to Profile code
* refactor: add WebViewGuestDelegate::GetGuestDelegateWeakPtr()
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4515455
This approach copied from GuestViewBase::GetGuestDelegateWeakPtr() approach in that same commit.
* fixup! chore: update bundle_locations #include location
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4525355
Sync namespace use to upstream base::mac -> base::apple changes
* fixup! chore: update bundle_locations #include location
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4525355
Sync namespace use to upstream base::mac -> base::apple changes
* chore: update chromium/mas_disable_remote_accessibility.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4530546
patch manually reapplied due to upstream code shear
* chore: update chromium/printing.patch
no manual changes; patch succeeded with fuzz
* chore: update chromium/build_add_electron_tracing_category.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4517872
no manual changes; patch succeeded with fuzz
* chore: update chromium/feat_ensure_mas_builds_of_the_same_application_can_use_safestorage.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4529098
patch manually reapplied due to upstream code shear
* chromium/build_only_use_the_mas_build_config_in_the_required_components.patch
https://chromium-review.googlesource.com/c/chromium/src/+/4529098
patch manually reapplied due to upstream code shear
* chore: update chromium/mas-cgdisplayusesforcetogray.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4529475
no manual changes; patch succeeded with fuzz
* chore: update chromium/build_only_use_the_mas_build_config_in_the_required_components.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4429011
no manual changes; patch succeeded with fuzz
* chore: remove chromium/cherry-pick-48a136e77e6d.patch
already present upstream
* chore: remove chromium/cherry-pick-e6e23ba00379.patch
already present upstream
* [Code Health] Remove value based RegisterPref for Dict and List
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4533537
* Remove `cxx17_backports.h` and adjust unittest file
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4534916
Notes: mostly just removing #include and s/base::clamp/std::clamp/
* refactor: add FakeBrowserProcess helper class
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4424072
Used in ElectronBrowserMainParts' fake_browser_process_ field. Previously
this was an BrowserProcessImpl instance, but upstream 4424072 makes that
an abstract base class. `FakeBrowserProcess` is a thin subclass with the
minimum code needed to make it concrete.
`ElectronBrowserMainParts::fake_browser_process_` is now a `shared_ptr`
instead of a `unique_ptr` so we can avoid exposing `FakeBrowserProcess`
in the header.
* fixup! refactor: add FakeBrowserProcess helper class
remove unnecessary unique_ptr
* fix: Browser::SetDockIcon() when !Browser.is_ready()
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4410741
An alternative fix for https://github.com/electron/electron/pull/36279 .
The previous fix was to call `SetSupportedScales()` ourselves (1b1609a
),
but upstream has removed this API.
CC @codebytere
* fixup! chore: remove chromium/cherry-pick-e6e23ba00379.patch
* chore: update chromium/export_gin_v8platform_pageallocator_for_usage_outside_of_the_gin.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4517404
patch manually reapplied due to upstream code shear
* chore: update patches
* chore: add dep: resource_coordinator:mojo_bindings
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4521464
* fixup! chore: add dep: resource_coordinator:mojo_bindings
chore: make lint happy
* chore: patch out Profile methods in titlebar_config
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4508143 (primary)
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4534461 (followup)
* chore: bump chromium in DEPS to 115.0.5780.0
* chore: update chromium/disable_hidden.patch
no manual changes; patch succeeded with fuzz
* chore: update chromium/sysroot.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4535715
no manual changes; patch succeeded with fuzz
* chore: update chromium/feat_enable_offscreen_rendering_with_viz_compositor.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4403623
patch manually reapplied due to upstream code shear
* chore: update chromium/refactor_expose_cursor_changes_to_the_webcontentsobserver.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4547380
patch manually reapplied due to upstream code shear
* chore: update patches
* fixup! fix: Browser::SetDockIcon() when !Browser.is_ready()
chore: iwyu image.h
* chore: bump chromium in DEPS to 115.0.5782.0
* chore: bump chromium in DEPS to 115.0.5784.0
* 4514181: CR2023: Update filled cr-input styles.
https://chromium-review.googlesource.com/c/chromium/src/+/4514181
* 4521894: Remove SiteInstanceDeleting usage outside of tests.
https://chromium-review.googlesource.com/c/chromium/src/+/4521894
* 4525355: Move backup_util and bundle_locations to base/apple
https://chromium-review.googlesource.com/c/chromium/src/+/4525355
* 4484743: webauthn: add underlying support for calling iCloud Keychain on macOS.
https://chromium-review.googlesource.com/c/chromium/src/+/4484743
* chore: fixup patch indices
* 4546398: Convert /chrome/browser to use ARC
https://chromium-review.googlesource.com/c/chromium/src/+/4546398
* chore: bump chromium in DEPS to 115.0.5786.0
* chore: update patches
* 4540682: Initialize PDF SDK with policy in chrome_pdf::RenderPDFPageToDC()
https://chromium-review.googlesource.com/c/chromium/src/+/4540682
* Don't import ObjC++ fn headers into electron_api_app
* 4535715: Refactor sysroot-creator.sh
https://chromium-review.googlesource.com/c/chromium/src/+/4535715
* fixup! refactor: add FakeBrowserProcess helper class
* 4531903: [string][test] Create/Copy strings to old space before externalization
https://chromium-review.googlesource.com/c/v8/v8/+/4531903
* 59645: Add APIs to support RSA keys with large e.
https://boringssl-review.googlesource.com/c/boringssl/+/59645
---------
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
393 lines
11 KiB
C++
393 lines
11 KiB
C++
// 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 "third_party/abseil-cpp/absl/types/optional.h"
|
||
#include "ui/base/cocoa/secure_password_input.h"
|
||
#include "ui/gfx/image/image.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();
|
||
bool IsHidden();
|
||
|
||
// Show the application.
|
||
void Show();
|
||
|
||
// Creates an activity and sets it as the one currently in use.
|
||
void SetUserActivity(const std::string& type,
|
||
base::Value::Dict 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::Value::Dict 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::Value::Dict user_info,
|
||
base::Value::Dict details);
|
||
|
||
// Indicates that an activity was continued on another device.
|
||
void UserActivityWasContinued(const std::string& type,
|
||
base::Value::Dict user_info);
|
||
|
||
// Gives an opportunity to update the Handoff payload.
|
||
bool UpdateUserActivityState(const std::string& type,
|
||
base::Value::Dict user_info);
|
||
|
||
void ApplyForcedRTL();
|
||
|
||
// 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::Value::Dict 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();
|
||
|
||
// Indicate that the app is now active.
|
||
void DidBecomeActive();
|
||
// Indicate that the app is no longer active and doesn’t have focus.
|
||
void DidResignActive();
|
||
|
||
#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::Value::Dict 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;
|
||
|
||
#if BUILDFLAG(IS_MAC)
|
||
void DockSetIconImage(gfx::Image const& icon);
|
||
#endif
|
||
|
||
// 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_;
|
||
|
||
// DockSetIcon() can't set the icon if is_ready_ is false.
|
||
// This field caches it until the browser is ready. (#26604)
|
||
absl::optional<gfx::Image> dock_icon_;
|
||
#endif
|
||
|
||
base::Value::Dict about_panel_options_;
|
||
|
||
#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_
|