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-07-04 12:58:28 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/browser.h"
|
2013-07-04 12:58:28 +00:00
|
|
|
|
2016-08-26 22:43:40 +00:00
|
|
|
#include <windows.h> // windows.h must be included first
|
|
|
|
|
2014-11-17 07:53:18 +00:00
|
|
|
#include <atlbase.h>
|
|
|
|
#include <shlobj.h>
|
|
|
|
#include <shobjidl.h>
|
2013-07-04 12:58:28 +00:00
|
|
|
|
|
|
|
#include "base/base_paths.h"
|
|
|
|
#include "base/file_version_info.h"
|
|
|
|
#include "base/files/file_path.h"
|
|
|
|
#include "base/path_service.h"
|
2015-11-03 07:49:37 +00:00
|
|
|
#include "base/strings/string_util.h"
|
2014-11-17 07:53:18 +00:00
|
|
|
#include "base/strings/stringprintf.h"
|
2013-07-04 12:58:28 +00:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2018-01-02 08:02:12 +00:00
|
|
|
#include "base/threading/thread_restrictions.h"
|
2016-03-21 18:24:25 +00:00
|
|
|
#include "base/win/registry.h"
|
2016-08-26 22:30:02 +00:00
|
|
|
#include "base/win/win_util.h"
|
2014-11-17 07:53:18 +00:00
|
|
|
#include "base/win/windows_version.h"
|
2019-06-19 21:31:55 +00:00
|
|
|
#include "electron/electron_version.h"
|
2019-08-12 23:32:51 +00:00
|
|
|
#include "shell/browser/ui/message_box.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/win/jump_list.h"
|
|
|
|
#include "shell/common/application_info.h"
|
2019-10-24 05:47:58 +00:00
|
|
|
#include "shell/common/gin_helper/arguments.h"
|
2019-08-12 23:32:51 +00:00
|
|
|
#include "shell/common/skia_util.h"
|
2019-03-14 20:39:52 +00:00
|
|
|
#include "ui/events/keycodes/keyboard_code_conversion_win.h"
|
2013-07-04 12:58:28 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2013-07-04 12:58:28 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) {
|
|
|
|
DWORD target_process_id = *reinterpret_cast<DWORD*>(param);
|
|
|
|
DWORD process_id = 0;
|
|
|
|
|
|
|
|
GetWindowThreadProcessId(hwnd, &process_id);
|
|
|
|
if (process_id == target_process_id) {
|
|
|
|
SetFocus(hwnd);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-02-04 01:38:16 +00:00
|
|
|
bool GetProcessExecPath(base::string16* exe) {
|
|
|
|
base::FilePath path;
|
2018-09-15 00:09:42 +00:00
|
|
|
if (!base::PathService::Get(base::FILE_EXE, &path)) {
|
2017-02-04 01:38:16 +00:00
|
|
|
LOG(ERROR) << "Error getting app exe path";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*exe = path.value();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-24 05:47:58 +00:00
|
|
|
bool GetProtocolLaunchPath(gin_helper::Arguments* args, base::string16* exe) {
|
2017-02-06 16:34:28 +00:00
|
|
|
if (!args->GetNext(exe) && !GetProcessExecPath(exe)) {
|
|
|
|
return false;
|
2017-02-04 01:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Read in optional args arg
|
|
|
|
std::vector<base::string16> launch_args;
|
|
|
|
if (args->GetNext(&launch_args) && !launch_args.empty())
|
2018-04-18 01:55:30 +00:00
|
|
|
*exe = base::StringPrintf(L"\"%ls\" %ls \"%%1\"", exe->c_str(),
|
2017-02-04 01:38:16 +00:00
|
|
|
base::JoinString(launch_args, L" ").c_str());
|
|
|
|
else
|
2017-04-05 12:45:46 +00:00
|
|
|
*exe = base::StringPrintf(L"\"%ls\" \"%%1\"", exe->c_str());
|
2017-02-04 01:38:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FormatCommandLineString(base::string16* exe,
|
|
|
|
const std::vector<base::string16>& launch_args) {
|
2017-02-06 16:34:28 +00:00
|
|
|
if (exe->empty() && !GetProcessExecPath(exe)) {
|
|
|
|
return false;
|
2016-08-22 00:50:58 +00:00
|
|
|
}
|
|
|
|
|
2017-02-04 01:38:16 +00:00
|
|
|
if (!launch_args.empty()) {
|
2018-04-18 01:55:30 +00:00
|
|
|
*exe = base::StringPrintf(L"%ls %ls", exe->c_str(),
|
2016-08-22 00:50:58 +00:00
|
|
|
base::JoinString(launch_args, L" ").c_str());
|
2017-01-26 22:15:59 +00:00
|
|
|
}
|
2017-01-30 22:01:40 +00:00
|
|
|
|
2016-08-22 00:50:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-12 23:32:51 +00:00
|
|
|
std::unique_ptr<FileVersionInfo> FetchFileVersionInfo() {
|
|
|
|
base::FilePath path;
|
|
|
|
|
|
|
|
if (base::PathService::Get(base::FILE_EXE, &path)) {
|
|
|
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
|
|
|
return FileVersionInfo::CreateFileVersionInfo(path);
|
|
|
|
}
|
|
|
|
return std::unique_ptr<FileVersionInfo>();
|
|
|
|
}
|
|
|
|
|
2013-07-04 12:58:28 +00:00
|
|
|
} // namespace
|
|
|
|
|
2018-06-25 20:30:00 +00:00
|
|
|
Browser::UserTask::UserTask() = default;
|
|
|
|
Browser::UserTask::UserTask(const UserTask&) = default;
|
|
|
|
Browser::UserTask::~UserTask() = default;
|
|
|
|
|
2013-07-04 12:58:28 +00:00
|
|
|
void Browser::Focus() {
|
|
|
|
// On Windows we just focus on the first window found for this process.
|
|
|
|
DWORD pid = GetCurrentProcessId();
|
|
|
|
EnumWindows(&WindowsEnumerationHandler, reinterpret_cast<LPARAM>(&pid));
|
|
|
|
}
|
|
|
|
|
2014-11-17 05:05:06 +00:00
|
|
|
void Browser::AddRecentDocument(const base::FilePath& path) {
|
2014-11-17 07:53:18 +00:00
|
|
|
CComPtr<IShellItem> item;
|
2018-04-18 01:55:30 +00:00
|
|
|
HRESULT hr = SHCreateItemFromParsingName(path.value().c_str(), NULL,
|
|
|
|
IID_PPV_ARGS(&item));
|
2014-11-17 07:53:18 +00:00
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
SHARDAPPIDINFO info;
|
|
|
|
info.psi = item;
|
2015-11-03 06:55:43 +00:00
|
|
|
info.pszAppID = GetAppUserModelID();
|
2014-11-17 07:53:18 +00:00
|
|
|
SHAddToRecentDocs(SHARD_APPIDINFO, &info);
|
|
|
|
}
|
2014-11-17 05:05:06 +00:00
|
|
|
}
|
|
|
|
|
2014-11-17 08:13:47 +00:00
|
|
|
void Browser::ClearRecentDocuments() {
|
2019-08-05 22:11:43 +00:00
|
|
|
SHAddToRecentDocs(SHARD_APPIDINFO, nullptr);
|
2014-11-17 08:13:47 +00:00
|
|
|
}
|
|
|
|
|
2015-11-03 07:09:31 +00:00
|
|
|
void Browser::SetAppUserModelID(const base::string16& name) {
|
2019-06-19 21:23:04 +00:00
|
|
|
electron::SetAppUserModelID(name);
|
2015-11-03 07:09:31 +00:00
|
|
|
}
|
|
|
|
|
2016-08-07 22:22:32 +00:00
|
|
|
bool Browser::SetUserTasks(const std::vector<UserTask>& tasks) {
|
2016-08-12 09:31:17 +00:00
|
|
|
JumpList jump_list(GetAppUserModelID());
|
|
|
|
if (!jump_list.Begin())
|
2016-08-07 22:22:32 +00:00
|
|
|
return false;
|
2014-11-17 09:19:41 +00:00
|
|
|
|
2016-08-12 09:31:17 +00:00
|
|
|
JumpListCategory category;
|
|
|
|
category.type = JumpListCategory::Type::TASKS;
|
|
|
|
category.items.reserve(tasks.size());
|
|
|
|
JumpListItem item;
|
|
|
|
item.type = JumpListItem::Type::TASK;
|
|
|
|
for (const auto& task : tasks) {
|
|
|
|
item.title = task.title;
|
|
|
|
item.path = task.program;
|
|
|
|
item.arguments = task.arguments;
|
|
|
|
item.icon_path = task.icon_path;
|
|
|
|
item.icon_index = task.icon_index;
|
|
|
|
item.description = task.description;
|
2019-05-13 16:17:12 +00:00
|
|
|
item.working_dir = task.working_dir;
|
2016-08-12 09:31:17 +00:00
|
|
|
category.items.push_back(item);
|
2014-11-17 09:19:41 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 09:31:17 +00:00
|
|
|
jump_list.AppendCategory(category);
|
|
|
|
return jump_list.Commit();
|
2014-11-17 09:19:41 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 05:54:30 +00:00
|
|
|
bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
|
2019-10-24 05:47:58 +00:00
|
|
|
gin_helper::Arguments* args) {
|
2016-08-16 05:35:20 +00:00
|
|
|
if (protocol.empty())
|
|
|
|
return false;
|
2016-03-24 17:55:09 +00:00
|
|
|
|
|
|
|
// Main Registry Key
|
|
|
|
HKEY root = HKEY_CURRENT_USER;
|
2017-12-02 01:39:54 +00:00
|
|
|
base::string16 keyPath = L"Software\\Classes\\";
|
2016-03-24 17:55:09 +00:00
|
|
|
|
|
|
|
// Command Key
|
2017-12-04 18:30:20 +00:00
|
|
|
base::string16 wprotocol = base::UTF8ToUTF16(protocol);
|
|
|
|
base::string16 shellPath = wprotocol + L"\\shell";
|
|
|
|
base::string16 cmdPath = keyPath + shellPath + L"\\open\\command";
|
2016-03-24 17:55:09 +00:00
|
|
|
|
2017-12-04 18:30:20 +00:00
|
|
|
base::win::RegKey classesKey;
|
2016-03-24 17:55:09 +00:00
|
|
|
base::win::RegKey commandKey;
|
2017-12-04 18:30:20 +00:00
|
|
|
|
|
|
|
if (FAILED(classesKey.Open(root, keyPath.c_str(), KEY_ALL_ACCESS)))
|
2017-12-04 18:46:53 +00:00
|
|
|
// Classes key doesn't exist, that's concerning, but I guess
|
|
|
|
// we're not the default handler
|
2016-03-24 17:55:09 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (FAILED(commandKey.Open(root, cmdPath.c_str(), KEY_ALL_ACCESS)))
|
|
|
|
// Key doesn't even exist, we can confirm that it is not set
|
|
|
|
return true;
|
|
|
|
|
2016-08-22 00:57:52 +00:00
|
|
|
base::string16 keyVal;
|
2016-03-24 17:55:09 +00:00
|
|
|
if (FAILED(commandKey.ReadValue(L"", &keyVal)))
|
|
|
|
// Default value not set, we can confirm that it is not set
|
|
|
|
return true;
|
|
|
|
|
2016-08-22 00:57:52 +00:00
|
|
|
base::string16 exe;
|
2017-02-04 01:38:16 +00:00
|
|
|
if (!GetProtocolLaunchPath(args, &exe))
|
2016-08-16 05:35:20 +00:00
|
|
|
return false;
|
2016-08-22 00:50:58 +00:00
|
|
|
|
2016-03-24 17:55:09 +00:00
|
|
|
if (keyVal == exe) {
|
|
|
|
// Let's kill the key
|
2017-12-04 18:30:20 +00:00
|
|
|
if (FAILED(classesKey.DeleteKey(shellPath.c_str())))
|
2016-03-24 17:55:09 +00:00
|
|
|
return false;
|
|
|
|
|
2017-12-04 18:30:20 +00:00
|
|
|
// Let's clean up after ourselves
|
|
|
|
base::win::RegKey protocolKey;
|
|
|
|
base::string16 protocolPath = keyPath + wprotocol;
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
if (SUCCEEDED(
|
|
|
|
protocolKey.Open(root, protocolPath.c_str(), KEY_ALL_ACCESS))) {
|
2017-12-04 18:30:20 +00:00
|
|
|
protocolKey.DeleteValue(L"URL Protocol");
|
|
|
|
|
|
|
|
// Overwrite the default value to be empty, we can't delete it right away
|
|
|
|
protocolKey.WriteValue(L"", L"");
|
2017-12-04 18:46:53 +00:00
|
|
|
protocolKey.DeleteValue(L"");
|
2017-12-04 18:30:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If now empty, delete the whole key
|
|
|
|
classesKey.DeleteEmptyKey(wprotocol.c_str());
|
2017-12-02 01:39:54 +00:00
|
|
|
|
2016-03-24 17:55:09 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-16 05:54:30 +00:00
|
|
|
bool Browser::SetAsDefaultProtocolClient(const std::string& protocol,
|
2019-10-24 05:47:58 +00:00
|
|
|
gin_helper::Arguments* args) {
|
2016-03-21 18:24:25 +00:00
|
|
|
// HKEY_CLASSES_ROOT
|
|
|
|
// $PROTOCOL
|
|
|
|
// (Default) = "URL:$NAME"
|
|
|
|
// URL Protocol = ""
|
|
|
|
// shell
|
|
|
|
// open
|
|
|
|
// command
|
|
|
|
// (Default) = "$COMMAND" "%1"
|
|
|
|
//
|
|
|
|
// However, the "HKEY_CLASSES_ROOT" key can only be written by the
|
|
|
|
// Administrator user. So, we instead write to "HKEY_CURRENT_USER\
|
|
|
|
// Software\Classes", which is inherited by "HKEY_CLASSES_ROOT"
|
|
|
|
// anyway, and can be written by unprivileged users.
|
|
|
|
|
|
|
|
if (protocol.empty())
|
|
|
|
return false;
|
|
|
|
|
2016-08-22 00:57:52 +00:00
|
|
|
base::string16 exe;
|
2017-02-04 01:38:16 +00:00
|
|
|
if (!GetProtocolLaunchPath(args, &exe))
|
2016-03-21 18:24:25 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Main Registry Key
|
|
|
|
HKEY root = HKEY_CURRENT_USER;
|
2016-08-22 00:57:52 +00:00
|
|
|
base::string16 keyPath = base::UTF8ToUTF16("Software\\Classes\\" + protocol);
|
|
|
|
base::string16 urlDecl = base::UTF8ToUTF16("URL:" + protocol);
|
2016-03-21 18:24:25 +00:00
|
|
|
|
|
|
|
// Command Key
|
2016-08-22 00:57:52 +00:00
|
|
|
base::string16 cmdPath = keyPath + L"\\shell\\open\\command";
|
2016-03-21 18:24:25 +00:00
|
|
|
|
|
|
|
// Write information to registry
|
|
|
|
base::win::RegKey key(root, keyPath.c_str(), KEY_ALL_ACCESS);
|
|
|
|
if (FAILED(key.WriteValue(L"URL Protocol", L"")) ||
|
|
|
|
FAILED(key.WriteValue(L"", urlDecl.c_str())))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
base::win::RegKey commandKey(root, cmdPath.c_str(), KEY_ALL_ACCESS);
|
|
|
|
if (FAILED(commandKey.WriteValue(L"", exe.c_str())))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-16 05:54:30 +00:00
|
|
|
bool Browser::IsDefaultProtocolClient(const std::string& protocol,
|
2019-10-24 05:47:58 +00:00
|
|
|
gin_helper::Arguments* args) {
|
2016-04-25 05:17:01 +00:00
|
|
|
if (protocol.empty())
|
|
|
|
return false;
|
|
|
|
|
2016-08-22 00:57:52 +00:00
|
|
|
base::string16 exe;
|
2017-02-04 01:38:16 +00:00
|
|
|
if (!GetProtocolLaunchPath(args, &exe))
|
2016-04-25 05:17:01 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Main Registry Key
|
|
|
|
HKEY root = HKEY_CURRENT_USER;
|
2016-08-22 00:57:52 +00:00
|
|
|
base::string16 keyPath = base::UTF8ToUTF16("Software\\Classes\\" + protocol);
|
2016-04-25 05:17:01 +00:00
|
|
|
|
|
|
|
// Command Key
|
2016-08-22 00:57:52 +00:00
|
|
|
base::string16 cmdPath = keyPath + L"\\shell\\open\\command";
|
2016-04-25 05:17:01 +00:00
|
|
|
|
|
|
|
base::win::RegKey key;
|
|
|
|
base::win::RegKey commandKey;
|
|
|
|
if (FAILED(key.Open(root, keyPath.c_str(), KEY_ALL_ACCESS)))
|
|
|
|
// Key doesn't exist, we can confirm that it is not set
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (FAILED(commandKey.Open(root, cmdPath.c_str(), KEY_ALL_ACCESS)))
|
|
|
|
// Key doesn't exist, we can confirm that it is not set
|
|
|
|
return false;
|
|
|
|
|
2016-08-22 00:57:52 +00:00
|
|
|
base::string16 keyVal;
|
2016-04-25 05:17:01 +00:00
|
|
|
if (FAILED(commandKey.ReadValue(L"", &keyVal)))
|
|
|
|
// Default value not set, we can confirm that it is not set
|
|
|
|
return false;
|
|
|
|
|
2016-08-22 00:57:52 +00:00
|
|
|
// Default value is the same as current file path
|
|
|
|
return keyVal == exe;
|
2016-04-25 05:17:01 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 13:18:39 +00:00
|
|
|
bool Browser::SetBadgeCount(int count) {
|
|
|
|
return false;
|
2016-07-01 08:39:01 +00:00
|
|
|
}
|
|
|
|
|
2017-01-30 22:01:40 +00:00
|
|
|
void Browser::SetLoginItemSettings(LoginItemSettings settings) {
|
2016-08-22 00:57:52 +00:00
|
|
|
base::string16 keyPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
2016-07-11 19:29:01 +00:00
|
|
|
base::win::RegKey key(HKEY_CURRENT_USER, keyPath.c_str(), KEY_ALL_ACCESS);
|
|
|
|
|
|
|
|
if (settings.open_at_login) {
|
2017-01-30 22:01:40 +00:00
|
|
|
base::string16 exe = settings.path;
|
2017-02-06 16:34:28 +00:00
|
|
|
if (FormatCommandLineString(&exe, settings.args)) {
|
|
|
|
key.WriteValue(GetAppUserModelID(), exe.c_str());
|
|
|
|
}
|
2016-07-11 19:29:01 +00:00
|
|
|
} else {
|
|
|
|
key.DeleteValue(GetAppUserModelID());
|
2016-07-11 18:12:26 +00:00
|
|
|
}
|
2016-07-11 17:57:53 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 10:18:18 +00:00
|
|
|
Browser::LoginItemSettings Browser::GetLoginItemSettings(
|
2017-03-29 19:29:52 +00:00
|
|
|
const LoginItemSettings& options) {
|
2016-07-11 18:12:26 +00:00
|
|
|
LoginItemSettings settings;
|
2016-08-22 00:57:52 +00:00
|
|
|
base::string16 keyPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
2016-07-11 19:29:01 +00:00
|
|
|
base::win::RegKey key(HKEY_CURRENT_USER, keyPath.c_str(), KEY_ALL_ACCESS);
|
2016-08-22 00:57:52 +00:00
|
|
|
base::string16 keyVal;
|
2016-07-11 18:12:26 +00:00
|
|
|
|
2016-07-11 19:29:01 +00:00
|
|
|
if (!FAILED(key.ReadValue(GetAppUserModelID(), &keyVal))) {
|
2017-01-30 22:01:40 +00:00
|
|
|
base::string16 exe = options.path;
|
2017-02-04 01:38:16 +00:00
|
|
|
if (FormatCommandLineString(&exe, options.args)) {
|
2017-01-26 10:05:35 +00:00
|
|
|
settings.open_at_login = keyVal == exe;
|
2016-07-11 19:29:01 +00:00
|
|
|
}
|
2016-07-11 18:12:26 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 19:29:01 +00:00
|
|
|
return settings;
|
2016-07-11 17:57:53 +00:00
|
|
|
}
|
|
|
|
|
2015-11-03 06:55:43 +00:00
|
|
|
PCWSTR Browser::GetAppUserModelID() {
|
2018-10-24 10:49:10 +00:00
|
|
|
return GetRawAppUserModelID();
|
2015-11-03 06:55:43 +00:00
|
|
|
}
|
|
|
|
|
2013-12-05 02:26:01 +00:00
|
|
|
std::string Browser::GetExecutableFileVersion() const {
|
2013-07-04 12:58:28 +00:00
|
|
|
base::FilePath path;
|
2018-09-15 00:09:42 +00:00
|
|
|
if (base::PathService::Get(base::FILE_EXE, &path)) {
|
2018-01-02 08:02:12 +00:00
|
|
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
2019-08-12 23:32:51 +00:00
|
|
|
std::unique_ptr<FileVersionInfo> version_info = FetchFileVersionInfo();
|
2014-07-11 04:19:01 +00:00
|
|
|
return base::UTF16ToUTF8(version_info->product_version());
|
2013-07-04 12:58:28 +00:00
|
|
|
}
|
|
|
|
|
2019-06-17 20:37:55 +00:00
|
|
|
return ELECTRON_VERSION_STRING;
|
2013-12-05 02:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Browser::GetExecutableFileProductName() const {
|
2018-10-24 10:49:10 +00:00
|
|
|
return GetApplicationName();
|
2013-07-04 12:58:28 +00:00
|
|
|
}
|
|
|
|
|
2019-03-14 20:39:52 +00:00
|
|
|
bool Browser::IsEmojiPanelSupported() {
|
|
|
|
// emoji picker is supported on Windows 10's Spring 2018 update & above.
|
2019-05-01 00:18:22 +00:00
|
|
|
return base::win::GetVersion() >= base::win::Version::WIN10_RS4;
|
2019-03-14 20:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Browser::ShowEmojiPanel() {
|
|
|
|
// This sends Windows Key + '.' (both keydown and keyup events).
|
|
|
|
// "SendInput" is used because Windows needs to receive these events and
|
|
|
|
// open the Emoji picker.
|
|
|
|
INPUT input[4] = {};
|
|
|
|
input[0].type = INPUT_KEYBOARD;
|
|
|
|
input[0].ki.wVk = ui::WindowsKeyCodeForKeyboardCode(ui::VKEY_COMMAND);
|
|
|
|
input[1].type = INPUT_KEYBOARD;
|
|
|
|
input[1].ki.wVk = ui::WindowsKeyCodeForKeyboardCode(ui::VKEY_OEM_PERIOD);
|
|
|
|
|
|
|
|
input[2].type = INPUT_KEYBOARD;
|
|
|
|
input[2].ki.wVk = ui::WindowsKeyCodeForKeyboardCode(ui::VKEY_COMMAND);
|
|
|
|
input[2].ki.dwFlags |= KEYEVENTF_KEYUP;
|
|
|
|
input[3].type = INPUT_KEYBOARD;
|
|
|
|
input[3].ki.wVk = ui::WindowsKeyCodeForKeyboardCode(ui::VKEY_OEM_PERIOD);
|
|
|
|
input[3].ki.dwFlags |= KEYEVENTF_KEYUP;
|
|
|
|
::SendInput(4, input, sizeof(INPUT));
|
|
|
|
}
|
|
|
|
|
2019-08-12 23:32:51 +00:00
|
|
|
void Browser::ShowAboutPanel() {
|
|
|
|
base::Value dict(base::Value::Type::DICTIONARY);
|
|
|
|
std::string aboutMessage = "";
|
|
|
|
gfx::ImageSkia image;
|
|
|
|
|
|
|
|
// grab defaults from Windows .EXE file
|
|
|
|
std::unique_ptr<FileVersionInfo> exe_info = FetchFileVersionInfo();
|
|
|
|
dict.SetStringKey("applicationName", exe_info->file_description());
|
|
|
|
dict.SetStringKey("applicationVersion", exe_info->product_version());
|
|
|
|
|
|
|
|
if (about_panel_options_.is_dict()) {
|
|
|
|
dict.MergeDictionary(&about_panel_options_);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> stringOptions = {
|
|
|
|
"applicationName", "applicationVersion", "copyright", "credits"};
|
|
|
|
|
|
|
|
const std::string* str;
|
|
|
|
for (std::string opt : stringOptions) {
|
|
|
|
if ((str = dict.FindStringKey(opt))) {
|
|
|
|
aboutMessage.append(*str).append("\r\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((str = dict.FindStringKey("iconPath"))) {
|
|
|
|
base::FilePath path = base::FilePath::FromUTF8Unsafe(*str);
|
|
|
|
electron::util::PopulateImageSkiaRepsFromPath(&image, path);
|
|
|
|
}
|
|
|
|
|
|
|
|
electron::MessageBoxSettings settings = {};
|
|
|
|
settings.message = aboutMessage;
|
|
|
|
settings.icon = image;
|
|
|
|
settings.type = electron::MessageBoxType::kInformation;
|
|
|
|
electron::ShowMessageBoxSync(settings);
|
|
|
|
}
|
|
|
|
|
2019-10-30 05:30:59 +00:00
|
|
|
void Browser::SetAboutPanelOptions(base::DictionaryValue options) {
|
|
|
|
about_panel_options_ = std::move(options);
|
2019-08-12 23:32:51 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|