| 
									
										
										
										
											2014-10-31 11:17:05 -07:00
										 |  |  | // Copyright (c) 2013 GitHub, Inc.
 | 
					
						
							| 
									
										
										
										
											2014-04-25 17:49:37 +08:00
										 |  |  | // Use of this source code is governed by the MIT license that can be
 | 
					
						
							| 
									
										
										
										
											2013-07-04 20:58:28 +08:00
										 |  |  | // found in the LICENSE file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 13:46:59 -07:00
										 |  |  | #include "shell/browser/browser.h"
 | 
					
						
							| 
									
										
										
										
											2013-07-04 20:58:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 16:43:43 -07:00
										 |  |  | // must come before other includes. fixes bad #defines from <shlwapi.h>.
 | 
					
						
							|  |  |  | #include "base/win/shlwapi.h"  // NOLINT(build/include_order)
 | 
					
						
							| 
									
										
										
										
											2016-08-26 15:43:40 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 16:43:43 -07:00
										 |  |  | #include <windows.h>  // NOLINT(build/include_order)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <atlbase.h>   // NOLINT(build/include_order)
 | 
					
						
							|  |  |  | #include <shlobj.h>    // NOLINT(build/include_order)
 | 
					
						
							|  |  |  | #include <shobjidl.h>  // NOLINT(build/include_order)
 | 
					
						
							| 
									
										
										
										
											2013-07-04 20:58:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "base/base_paths.h"
 | 
					
						
							|  |  |  | #include "base/file_version_info.h"
 | 
					
						
							|  |  |  | #include "base/files/file_path.h"
 | 
					
						
							| 
									
										
										
										
											2020-07-29 10:08:37 -07:00
										 |  |  | #include "base/logging.h"
 | 
					
						
							| 
									
										
										
										
											2013-07-04 20:58:28 +08:00
										 |  |  | #include "base/path_service.h"
 | 
					
						
							| 
									
										
										
										
											2015-11-03 15:49:37 +08:00
										 |  |  | #include "base/strings/string_util.h"
 | 
					
						
							| 
									
										
										
										
											2014-11-17 15:53:18 +08:00
										 |  |  | #include "base/strings/stringprintf.h"
 | 
					
						
							| 
									
										
										
										
											2013-07-04 20:58:28 +08:00
										 |  |  | #include "base/strings/utf_string_conversions.h"
 | 
					
						
							| 
									
										
										
										
											2018-01-02 17:02:12 +09:00
										 |  |  | #include "base/threading/thread_restrictions.h"
 | 
					
						
							| 
									
										
										
										
											2016-03-21 11:24:25 -07:00
										 |  |  | #include "base/win/registry.h"
 | 
					
						
							| 
									
										
										
										
											2016-08-26 15:30:02 -07:00
										 |  |  | #include "base/win/win_util.h"
 | 
					
						
							| 
									
										
										
										
											2014-11-17 15:53:18 +08:00
										 |  |  | #include "base/win/windows_version.h"
 | 
					
						
							| 
									
										
										
										
											2020-06-30 12:22:30 -07:00
										 |  |  | #include "chrome/browser/icon_manager.h"
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:31:55 -07:00
										 |  |  | #include "electron/electron_version.h"
 | 
					
						
							| 
									
										
										
										
											2020-06-30 12:22:30 -07:00
										 |  |  | #include "shell/browser/api/electron_api_app.h"
 | 
					
						
							| 
									
										
										
										
											2021-01-21 00:45:06 -05:00
										 |  |  | #include "shell/browser/badging/badge_manager.h"
 | 
					
						
							| 
									
										
										
										
											2020-06-30 12:22:30 -07:00
										 |  |  | #include "shell/browser/electron_browser_main_parts.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-12 16:32:51 -07:00
										 |  |  | #include "shell/browser/ui/message_box.h"
 | 
					
						
							| 
									
										
										
										
											2019-06-19 13:46:59 -07:00
										 |  |  | #include "shell/browser/ui/win/jump_list.h"
 | 
					
						
							| 
									
										
										
										
											2021-01-21 00:45:06 -05:00
										 |  |  | #include "shell/browser/window_list.h"
 | 
					
						
							| 
									
										
										
										
											2019-06-19 13:46:59 -07:00
										 |  |  | #include "shell/common/application_info.h"
 | 
					
						
							| 
									
										
										
										
											2020-06-30 12:22:30 -07:00
										 |  |  | #include "shell/common/gin_converters/file_path_converter.h"
 | 
					
						
							|  |  |  | #include "shell/common/gin_converters/image_converter.h"
 | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  | #include "shell/common/gin_helper/arguments.h"
 | 
					
						
							| 
									
										
										
										
											2020-06-30 12:22:30 -07:00
										 |  |  | #include "shell/common/gin_helper/dictionary.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-12 16:32:51 -07:00
										 |  |  | #include "shell/common/skia_util.h"
 | 
					
						
							| 
									
										
										
										
											2021-01-21 00:45:06 -05:00
										 |  |  | #include "skia/ext/legacy_display_globals.h"
 | 
					
						
							|  |  |  | #include "ui/base/l10n/l10n_util.h"
 | 
					
						
							| 
									
										
										
										
											2019-03-14 13:39:52 -07:00
										 |  |  | #include "ui/events/keycodes/keyboard_code_conversion_win.h"
 | 
					
						
							| 
									
										
										
										
											2021-01-21 00:45:06 -05:00
										 |  |  | #include "ui/strings/grit/ui_strings.h"
 | 
					
						
							| 
									
										
										
										
											2013-07-04 20:58:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  | namespace electron { | 
					
						
							| 
									
										
										
										
											2013-07-04 20:58:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-03 17:38:16 -08:00
										 |  |  | bool GetProcessExecPath(base::string16* exe) { | 
					
						
							|  |  |  |   base::FilePath path; | 
					
						
							| 
									
										
										
										
											2018-09-14 17:09:42 -07:00
										 |  |  |   if (!base::PathService::Get(base::FILE_EXE, &path)) { | 
					
						
							| 
									
										
										
										
											2017-02-03 17:38:16 -08:00
										 |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   *exe = path.value(); | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 16:43:43 -07:00
										 |  |  | bool GetProtocolLaunchPath(gin::Arguments* args, base::string16* exe) { | 
					
						
							| 
									
										
										
										
											2017-02-06 08:34:28 -08:00
										 |  |  |   if (!args->GetNext(exe) && !GetProcessExecPath(exe)) { | 
					
						
							|  |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2017-02-03 17:38:16 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Read in optional args arg
 | 
					
						
							|  |  |  |   std::vector<base::string16> launch_args; | 
					
						
							|  |  |  |   if (args->GetNext(&launch_args) && !launch_args.empty()) | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |     *exe = base::StringPrintf(L"\"%ls\" %ls \"%%1\"", exe->c_str(), | 
					
						
							| 
									
										
										
										
											2017-02-03 17:38:16 -08:00
										 |  |  |                               base::JoinString(launch_args, L" ").c_str()); | 
					
						
							|  |  |  |   else | 
					
						
							| 
									
										
										
										
											2017-04-05 14:45:46 +02:00
										 |  |  |     *exe = base::StringPrintf(L"\"%ls\" \"%%1\"", exe->c_str()); | 
					
						
							| 
									
										
										
										
											2017-02-03 17:38:16 -08:00
										 |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 17:50:33 -08:00
										 |  |  | // Windows treats a given scheme as an Internet scheme only if its registry
 | 
					
						
							|  |  |  | // entry has a "URL Protocol" key. Check this, otherwise we allow ProgIDs to be
 | 
					
						
							|  |  |  | // used as custom protocols which leads to security bugs.
 | 
					
						
							|  |  |  | bool IsValidCustomProtocol(const base::string16& scheme) { | 
					
						
							|  |  |  |   if (scheme.empty()) | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   base::win::RegKey cmd_key(HKEY_CLASSES_ROOT, scheme.c_str(), KEY_QUERY_VALUE); | 
					
						
							|  |  |  |   return cmd_key.Valid() && cmd_key.HasValue(L"URL Protocol"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-30 12:22:30 -07:00
										 |  |  | // Helper for GetApplicationInfoForProtocol().
 | 
					
						
							|  |  |  | // takes in an assoc_str
 | 
					
						
							|  |  |  | // (https://docs.microsoft.com/en-us/windows/win32/api/shlwapi/ne-shlwapi-assocstr)
 | 
					
						
							|  |  |  | // and returns the application name, icon and path that handles the protocol.
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2019-11-06 17:50:33 -08:00
										 |  |  | // Windows 8 introduced a new protocol->executable binding system which cannot
 | 
					
						
							|  |  |  | // be retrieved in the HKCR registry subkey method implemented below. We call
 | 
					
						
							|  |  |  | // AssocQueryString with the new Win8-only flag ASSOCF_IS_PROTOCOL instead.
 | 
					
						
							| 
									
										
										
										
											2020-06-30 12:22:30 -07:00
										 |  |  | base::string16 GetAppInfoHelperForProtocol(ASSOCSTR assoc_str, | 
					
						
							|  |  |  |                                            const GURL& url) { | 
					
						
							| 
									
										
										
										
											2019-11-06 17:50:33 -08:00
										 |  |  |   const base::string16 url_scheme = base::ASCIIToUTF16(url.scheme()); | 
					
						
							|  |  |  |   if (!IsValidCustomProtocol(url_scheme)) | 
					
						
							|  |  |  |     return base::string16(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   wchar_t out_buffer[1024]; | 
					
						
							|  |  |  |   DWORD buffer_size = base::size(out_buffer); | 
					
						
							|  |  |  |   HRESULT hr = | 
					
						
							| 
									
										
										
										
											2020-06-30 12:22:30 -07:00
										 |  |  |       AssocQueryString(ASSOCF_IS_PROTOCOL, assoc_str, url_scheme.c_str(), NULL, | 
					
						
							|  |  |  |                        out_buffer, &buffer_size); | 
					
						
							| 
									
										
										
										
											2019-11-06 17:50:33 -08:00
										 |  |  |   if (FAILED(hr)) { | 
					
						
							|  |  |  |     DLOG(WARNING) << "AssocQueryString failed!"; | 
					
						
							|  |  |  |     return base::string16(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return base::string16(out_buffer); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-30 12:22:30 -07:00
										 |  |  | void OnIconDataAvailable(const base::FilePath& app_path, | 
					
						
							|  |  |  |                          const base::string16& app_display_name, | 
					
						
							|  |  |  |                          gin_helper::Promise<gin_helper::Dictionary> promise, | 
					
						
							|  |  |  |                          gfx::Image icon) { | 
					
						
							|  |  |  |   if (!icon.IsEmpty()) { | 
					
						
							|  |  |  |     v8::HandleScope scope(promise.isolate()); | 
					
						
							|  |  |  |     gin_helper::Dictionary dict = | 
					
						
							|  |  |  |         gin::Dictionary::CreateEmpty(promise.isolate()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dict.Set("path", app_path); | 
					
						
							|  |  |  |     dict.Set("name", app_display_name); | 
					
						
							|  |  |  |     dict.Set("icon", icon); | 
					
						
							|  |  |  |     promise.Resolve(dict); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     promise.RejectWithErrorMessage("Failed to get file icon."); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | base::string16 GetAppDisplayNameForProtocol(const GURL& url) { | 
					
						
							|  |  |  |   return GetAppInfoHelperForProtocol(ASSOCSTR_FRIENDLYAPPNAME, url); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | base::string16 GetAppPathForProtocol(const GURL& url) { | 
					
						
							|  |  |  |   return GetAppInfoHelperForProtocol(ASSOCSTR_EXECUTABLE, url); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 17:50:33 -08:00
										 |  |  | base::string16 GetAppForProtocolUsingRegistry(const GURL& url) { | 
					
						
							|  |  |  |   const base::string16 url_scheme = base::ASCIIToUTF16(url.scheme()); | 
					
						
							|  |  |  |   if (!IsValidCustomProtocol(url_scheme)) | 
					
						
							|  |  |  |     return base::string16(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // First, try and extract the application's display name.
 | 
					
						
							|  |  |  |   base::string16 command_to_launch; | 
					
						
							|  |  |  |   base::win::RegKey cmd_key_name(HKEY_CLASSES_ROOT, url_scheme.c_str(), | 
					
						
							|  |  |  |                                  KEY_READ); | 
					
						
							|  |  |  |   if (cmd_key_name.ReadValue(NULL, &command_to_launch) == ERROR_SUCCESS && | 
					
						
							|  |  |  |       !command_to_launch.empty()) { | 
					
						
							|  |  |  |     return command_to_launch; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Otherwise, parse the command line in the registry, and return the basename
 | 
					
						
							|  |  |  |   // of the program path if it exists.
 | 
					
						
							|  |  |  |   const base::string16 cmd_key_path = url_scheme + L"\\shell\\open\\command"; | 
					
						
							|  |  |  |   base::win::RegKey cmd_key_exe(HKEY_CLASSES_ROOT, cmd_key_path.c_str(), | 
					
						
							|  |  |  |                                 KEY_READ); | 
					
						
							|  |  |  |   if (cmd_key_exe.ReadValue(NULL, &command_to_launch) == ERROR_SUCCESS) { | 
					
						
							|  |  |  |     base::CommandLine command_line( | 
					
						
							|  |  |  |         base::CommandLine::FromString(command_to_launch)); | 
					
						
							|  |  |  |     return command_line.GetProgram().BaseName().value(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return base::string16(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-03 17:38:16 -08:00
										 |  |  | bool FormatCommandLineString(base::string16* exe, | 
					
						
							|  |  |  |                              const std::vector<base::string16>& launch_args) { | 
					
						
							| 
									
										
										
										
											2017-02-06 08:34:28 -08:00
										 |  |  |   if (exe->empty() && !GetProcessExecPath(exe)) { | 
					
						
							|  |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2016-08-22 09:50:58 +09:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-03 17:38:16 -08:00
										 |  |  |   if (!launch_args.empty()) { | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |     *exe = base::StringPrintf(L"%ls %ls", exe->c_str(), | 
					
						
							| 
									
										
										
										
											2016-08-22 09:50:58 +09:00
										 |  |  |                               base::JoinString(launch_args, L" ").c_str()); | 
					
						
							| 
									
										
										
										
											2017-01-26 14:15:59 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-01-30 14:01:40 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-22 09:50:58 +09:00
										 |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-29 10:08:37 -07:00
										 |  |  | // Helper for GetLoginItemSettings().
 | 
					
						
							|  |  |  | // iterates over all the entries in a windows registry path and returns
 | 
					
						
							|  |  |  | // a list of launchItem with matching paths to our application.
 | 
					
						
							|  |  |  | // if a launchItem with a matching path also has a matching entry within the
 | 
					
						
							|  |  |  | // startup_approved_key_path, set executable_will_launch_at_login to be `true`
 | 
					
						
							|  |  |  | std::vector<Browser::LaunchItem> GetLoginItemSettingsHelper( | 
					
						
							|  |  |  |     base::win::RegistryValueIterator* it, | 
					
						
							|  |  |  |     boolean* executable_will_launch_at_login, | 
					
						
							|  |  |  |     base::string16 scope, | 
					
						
							|  |  |  |     const Browser::LoginItemSettings& options) { | 
					
						
							|  |  |  |   std::vector<Browser::LaunchItem> launch_items; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-17 12:13:08 -08:00
										 |  |  |   base::FilePath lookup_exe_path; | 
					
						
							|  |  |  |   if (options.path.empty()) { | 
					
						
							|  |  |  |     base::string16 process_exe_path; | 
					
						
							|  |  |  |     GetProcessExecPath(&process_exe_path); | 
					
						
							|  |  |  |     lookup_exe_path = | 
					
						
							|  |  |  |         base::CommandLine::FromString(process_exe_path).GetProgram(); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     lookup_exe_path = base::CommandLine::FromString(options.path).GetProgram(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!lookup_exe_path.empty()) { | 
					
						
							|  |  |  |     while (it->Valid()) { | 
					
						
							|  |  |  |       base::CommandLine registry_launch_cmd = | 
					
						
							|  |  |  |           base::CommandLine::FromString(it->Value()); | 
					
						
							|  |  |  |       base::FilePath registry_launch_path = registry_launch_cmd.GetProgram(); | 
					
						
							|  |  |  |       bool exe_match = base::FilePath::CompareEqualIgnoreCase( | 
					
						
							|  |  |  |           lookup_exe_path.value(), registry_launch_path.value()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-29 10:08:37 -07:00
										 |  |  |       // add launch item to vector if it has a matching path (case-insensitive)
 | 
					
						
							| 
									
										
										
										
											2020-11-17 12:13:08 -08:00
										 |  |  |       if (exe_match) { | 
					
						
							| 
									
										
										
										
											2020-07-29 10:08:37 -07:00
										 |  |  |         Browser::LaunchItem launch_item; | 
					
						
							|  |  |  |         launch_item.name = it->Name(); | 
					
						
							| 
									
										
										
										
											2020-11-17 12:13:08 -08:00
										 |  |  |         launch_item.path = registry_launch_path.value(); | 
					
						
							|  |  |  |         launch_item.args = registry_launch_cmd.GetArgs(); | 
					
						
							| 
									
										
										
										
											2020-07-29 10:08:37 -07:00
										 |  |  |         launch_item.scope = scope; | 
					
						
							|  |  |  |         launch_item.enabled = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // attempt to update launch_item.enabled if there is a matching key
 | 
					
						
							|  |  |  |         // value entry in the StartupApproved registry
 | 
					
						
							|  |  |  |         HKEY hkey; | 
					
						
							|  |  |  |         // StartupApproved registry path
 | 
					
						
							|  |  |  |         LPCTSTR path = TEXT( | 
					
						
							|  |  |  |             "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApp" | 
					
						
							|  |  |  |             "roved\\Run"); | 
					
						
							|  |  |  |         LONG res; | 
					
						
							|  |  |  |         if (scope == L"user") { | 
					
						
							|  |  |  |           res = | 
					
						
							|  |  |  |               RegOpenKeyEx(HKEY_CURRENT_USER, path, 0, KEY_QUERY_VALUE, &hkey); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |           res = | 
					
						
							|  |  |  |               RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_QUERY_VALUE, &hkey); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (res == ERROR_SUCCESS) { | 
					
						
							|  |  |  |           DWORD type, size; | 
					
						
							|  |  |  |           wchar_t startup_binary[12]; | 
					
						
							|  |  |  |           LONG result = | 
					
						
							|  |  |  |               RegQueryValueEx(hkey, it->Name(), nullptr, &type, | 
					
						
							|  |  |  |                               reinterpret_cast<BYTE*>(&startup_binary), | 
					
						
							|  |  |  |                               &(size = sizeof(startup_binary))); | 
					
						
							|  |  |  |           if (result == ERROR_SUCCESS) { | 
					
						
							|  |  |  |             if (type == REG_BINARY) { | 
					
						
							|  |  |  |               // any other binary other than this indicates that the program is
 | 
					
						
							|  |  |  |               // not set to launch at login
 | 
					
						
							|  |  |  |               wchar_t binary_accepted[12] = {0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  |                                              0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  |                                              0x00, 0x00, 0x00, 0x00}; | 
					
						
							|  |  |  |               wchar_t binary_accepted_alt[12] = {0x02, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  |                                                  0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  |                                                  0x00, 0x00, 0x00, 0x00}; | 
					
						
							|  |  |  |               std::string reg_binary(reinterpret_cast<char*>(binary_accepted)); | 
					
						
							|  |  |  |               std::string reg_binary_alt( | 
					
						
							|  |  |  |                   reinterpret_cast<char*>(binary_accepted_alt)); | 
					
						
							|  |  |  |               std::string reg_startup_binary( | 
					
						
							|  |  |  |                   reinterpret_cast<char*>(startup_binary)); | 
					
						
							| 
									
										
										
										
											2020-11-17 12:13:08 -08:00
										 |  |  |               launch_item.enabled = (reg_startup_binary == reg_binary) || | 
					
						
							|  |  |  |                                     (reg_startup_binary == reg_binary_alt); | 
					
						
							| 
									
										
										
										
											2020-07-29 10:08:37 -07:00
										 |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         *executable_will_launch_at_login = | 
					
						
							|  |  |  |             *executable_will_launch_at_login || launch_item.enabled; | 
					
						
							|  |  |  |         launch_items.push_back(launch_item); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-11-17 12:13:08 -08:00
										 |  |  |       it->operator++(); | 
					
						
							| 
									
										
										
										
											2020-07-29 10:08:37 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return launch_items; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 16:32:51 -07: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 20:58:28 +08:00
										 |  |  | }  // namespace
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-25 22:30:00 +02:00
										 |  |  | Browser::UserTask::UserTask() = default; | 
					
						
							|  |  |  | Browser::UserTask::UserTask(const UserTask&) = default; | 
					
						
							|  |  |  | Browser::UserTask::~UserTask() = default; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-30 12:22:30 -07:00
										 |  |  | void GetFileIcon(const base::FilePath& path, | 
					
						
							|  |  |  |                  v8::Isolate* isolate, | 
					
						
							|  |  |  |                  base::CancelableTaskTracker* cancelable_task_tracker_, | 
					
						
							|  |  |  |                  const base::string16 app_display_name, | 
					
						
							|  |  |  |                  gin_helper::Promise<gin_helper::Dictionary> promise) { | 
					
						
							|  |  |  |   base::FilePath normalized_path = path.NormalizePathSeparators(); | 
					
						
							|  |  |  |   IconLoader::IconSize icon_size = IconLoader::IconSize::LARGE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   auto* icon_manager = ElectronBrowserMainParts::Get()->GetIconManager(); | 
					
						
							|  |  |  |   gfx::Image* icon = | 
					
						
							|  |  |  |       icon_manager->LookupIconFromFilepath(normalized_path, icon_size); | 
					
						
							|  |  |  |   if (icon) { | 
					
						
							|  |  |  |     gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate); | 
					
						
							|  |  |  |     dict.Set("icon", *icon); | 
					
						
							|  |  |  |     dict.Set("name", app_display_name); | 
					
						
							|  |  |  |     dict.Set("path", normalized_path); | 
					
						
							|  |  |  |     promise.Resolve(dict); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     icon_manager->LoadIcon(normalized_path, icon_size, | 
					
						
							|  |  |  |                            base::BindOnce(&OnIconDataAvailable, normalized_path, | 
					
						
							|  |  |  |                                           app_display_name, std::move(promise)), | 
					
						
							|  |  |  |                            cancelable_task_tracker_); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GetApplicationInfoForProtocolUsingRegistry( | 
					
						
							|  |  |  |     v8::Isolate* isolate, | 
					
						
							|  |  |  |     const GURL& url, | 
					
						
							|  |  |  |     gin_helper::Promise<gin_helper::Dictionary> promise, | 
					
						
							|  |  |  |     base::CancelableTaskTracker* cancelable_task_tracker_) { | 
					
						
							|  |  |  |   base::FilePath app_path; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const base::string16 url_scheme = base::ASCIIToUTF16(url.scheme()); | 
					
						
							|  |  |  |   if (!IsValidCustomProtocol(url_scheme)) { | 
					
						
							|  |  |  |     promise.RejectWithErrorMessage("invalid url_scheme"); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   base::string16 command_to_launch; | 
					
						
							|  |  |  |   const base::string16 cmd_key_path = url_scheme + L"\\shell\\open\\command"; | 
					
						
							|  |  |  |   base::win::RegKey cmd_key_exe(HKEY_CLASSES_ROOT, cmd_key_path.c_str(), | 
					
						
							|  |  |  |                                 KEY_READ); | 
					
						
							|  |  |  |   if (cmd_key_exe.ReadValue(NULL, &command_to_launch) == ERROR_SUCCESS) { | 
					
						
							|  |  |  |     base::CommandLine command_line( | 
					
						
							|  |  |  |         base::CommandLine::FromString(command_to_launch)); | 
					
						
							|  |  |  |     app_path = command_line.GetProgram(); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     promise.RejectWithErrorMessage( | 
					
						
							|  |  |  |         "Unable to retrieve installation path to app"); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   const base::string16 app_display_name = GetAppForProtocolUsingRegistry(url); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-22 13:24:59 -07:00
										 |  |  |   if (app_display_name.empty()) { | 
					
						
							| 
									
										
										
										
											2020-06-30 12:22:30 -07:00
										 |  |  |     promise.RejectWithErrorMessage( | 
					
						
							|  |  |  |         "Unable to retrieve application display name"); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   GetFileIcon(app_path, isolate, cancelable_task_tracker_, app_display_name, | 
					
						
							|  |  |  |               std::move(promise)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // resolves `Promise<Object>` - Resolve with an object containing the following:
 | 
					
						
							|  |  |  | // * `icon` NativeImage - the display icon of the app handling the protocol.
 | 
					
						
							|  |  |  | // * `path` String  - installation path of the app handling the protocol.
 | 
					
						
							|  |  |  | // * `name` String - display name of the app handling the protocol.
 | 
					
						
							|  |  |  | void GetApplicationInfoForProtocolUsingAssocQuery( | 
					
						
							|  |  |  |     v8::Isolate* isolate, | 
					
						
							|  |  |  |     const GURL& url, | 
					
						
							|  |  |  |     gin_helper::Promise<gin_helper::Dictionary> promise, | 
					
						
							|  |  |  |     base::CancelableTaskTracker* cancelable_task_tracker_) { | 
					
						
							|  |  |  |   base::string16 app_path = GetAppPathForProtocol(url); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (app_path.empty()) { | 
					
						
							|  |  |  |     promise.RejectWithErrorMessage( | 
					
						
							|  |  |  |         "Unable to retrieve installation path to app"); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   base::string16 app_display_name = GetAppDisplayNameForProtocol(url); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (app_display_name.empty()) { | 
					
						
							|  |  |  |     promise.RejectWithErrorMessage("Unable to retrieve display name of app"); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   base::FilePath app_path_file_path = base::FilePath(app_path); | 
					
						
							|  |  |  |   GetFileIcon(app_path_file_path, isolate, cancelable_task_tracker_, | 
					
						
							|  |  |  |               app_display_name, std::move(promise)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:05:06 +08:00
										 |  |  | void Browser::AddRecentDocument(const base::FilePath& path) { | 
					
						
							| 
									
										
										
										
											2014-11-17 15:53:18 +08:00
										 |  |  |   CComPtr<IShellItem> item; | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |   HRESULT hr = SHCreateItemFromParsingName(path.value().c_str(), NULL, | 
					
						
							|  |  |  |                                            IID_PPV_ARGS(&item)); | 
					
						
							| 
									
										
										
										
											2014-11-17 15:53:18 +08:00
										 |  |  |   if (SUCCEEDED(hr)) { | 
					
						
							|  |  |  |     SHARDAPPIDINFO info; | 
					
						
							|  |  |  |     info.psi = item; | 
					
						
							| 
									
										
										
										
											2015-11-03 14:55:43 +08:00
										 |  |  |     info.pszAppID = GetAppUserModelID(); | 
					
						
							| 
									
										
										
										
											2014-11-17 15:53:18 +08:00
										 |  |  |     SHAddToRecentDocs(SHARD_APPIDINFO, &info); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-11-17 13:05:06 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-17 16:13:47 +08:00
										 |  |  | void Browser::ClearRecentDocuments() { | 
					
						
							| 
									
										
										
										
											2019-08-05 15:11:43 -07:00
										 |  |  |   SHAddToRecentDocs(SHARD_APPIDINFO, nullptr); | 
					
						
							| 
									
										
										
										
											2014-11-17 16:13:47 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-03 15:09:31 +08:00
										 |  |  | void Browser::SetAppUserModelID(const base::string16& name) { | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  |   electron::SetAppUserModelID(name); | 
					
						
							| 
									
										
										
										
											2015-11-03 15:09:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-08 00:22:32 +02:00
										 |  |  | bool Browser::SetUserTasks(const std::vector<UserTask>& tasks) { | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |   JumpList jump_list(GetAppUserModelID()); | 
					
						
							|  |  |  |   if (!jump_list.Begin()) | 
					
						
							| 
									
										
										
										
											2016-08-08 00:22:32 +02:00
										 |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2014-11-17 17:19:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |   JumpListCategory category; | 
					
						
							| 
									
										
										
										
											2020-10-27 18:51:45 +01:00
										 |  |  |   category.type = JumpListCategory::Type::kTasks; | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |   category.items.reserve(tasks.size()); | 
					
						
							|  |  |  |   JumpListItem item; | 
					
						
							| 
									
										
										
										
											2020-10-27 18:51:45 +01:00
										 |  |  |   item.type = JumpListItem::Type::kTask; | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |   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 18:17:12 +02:00
										 |  |  |     item.working_dir = task.working_dir; | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |     category.items.push_back(item); | 
					
						
							| 
									
										
										
										
											2014-11-17 17:19:41 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |   jump_list.AppendCategory(category); | 
					
						
							|  |  |  |   return jump_list.Commit(); | 
					
						
							| 
									
										
										
										
											2014-11-17 17:19:41 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-16 15:54:30 +10:00
										 |  |  | bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol, | 
					
						
							| 
									
										
										
										
											2020-07-28 16:43:43 -07:00
										 |  |  |                                             gin::Arguments* args) { | 
					
						
							| 
									
										
										
										
											2016-08-16 15:35:20 +10:00
										 |  |  |   if (protocol.empty()) | 
					
						
							|  |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2016-03-24 10:55:09 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Main Registry Key
 | 
					
						
							|  |  |  |   HKEY root = HKEY_CURRENT_USER; | 
					
						
							| 
									
										
										
										
											2017-12-01 17:39:54 -08:00
										 |  |  |   base::string16 keyPath = L"Software\\Classes\\"; | 
					
						
							| 
									
										
										
										
											2016-03-24 10:55:09 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Command Key
 | 
					
						
							| 
									
										
										
										
											2017-12-04 10:30:20 -08:00
										 |  |  |   base::string16 wprotocol = base::UTF8ToUTF16(protocol); | 
					
						
							|  |  |  |   base::string16 shellPath = wprotocol + L"\\shell"; | 
					
						
							|  |  |  |   base::string16 cmdPath = keyPath + shellPath + L"\\open\\command"; | 
					
						
							| 
									
										
										
										
											2016-03-24 10:55:09 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-04 10:30:20 -08:00
										 |  |  |   base::win::RegKey classesKey; | 
					
						
							| 
									
										
										
										
											2016-03-24 10:55:09 -07:00
										 |  |  |   base::win::RegKey commandKey; | 
					
						
							| 
									
										
										
										
											2017-12-04 10:30:20 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (FAILED(classesKey.Open(root, keyPath.c_str(), KEY_ALL_ACCESS))) | 
					
						
							| 
									
										
										
										
											2017-12-04 10:46:53 -08:00
										 |  |  |     // Classes key doesn't exist, that's concerning, but I guess
 | 
					
						
							|  |  |  |     // we're not the default handler
 | 
					
						
							| 
									
										
										
										
											2016-03-24 10:55:09 -07: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 09:57:52 +09:00
										 |  |  |   base::string16 keyVal; | 
					
						
							| 
									
										
										
										
											2016-03-24 10:55:09 -07:00
										 |  |  |   if (FAILED(commandKey.ReadValue(L"", &keyVal))) | 
					
						
							|  |  |  |     // Default value not set, we can confirm that it is not set
 | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-22 09:57:52 +09:00
										 |  |  |   base::string16 exe; | 
					
						
							| 
									
										
										
										
											2017-02-03 17:38:16 -08:00
										 |  |  |   if (!GetProtocolLaunchPath(args, &exe)) | 
					
						
							| 
									
										
										
										
											2016-08-16 15:35:20 +10:00
										 |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2016-08-22 09:50:58 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 10:55:09 -07:00
										 |  |  |   if (keyVal == exe) { | 
					
						
							|  |  |  |     // Let's kill the key
 | 
					
						
							| 
									
										
										
										
											2017-12-04 10:30:20 -08:00
										 |  |  |     if (FAILED(classesKey.DeleteKey(shellPath.c_str()))) | 
					
						
							| 
									
										
										
										
											2016-03-24 10:55:09 -07:00
										 |  |  |       return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-04 10:30:20 -08:00
										 |  |  |     // Let's clean up after ourselves
 | 
					
						
							|  |  |  |     base::win::RegKey protocolKey; | 
					
						
							|  |  |  |     base::string16 protocolPath = keyPath + wprotocol; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |     if (SUCCEEDED( | 
					
						
							|  |  |  |             protocolKey.Open(root, protocolPath.c_str(), KEY_ALL_ACCESS))) { | 
					
						
							| 
									
										
										
										
											2017-12-04 10:30:20 -08: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 10:46:53 -08:00
										 |  |  |       protocolKey.DeleteValue(L""); | 
					
						
							| 
									
										
										
										
											2017-12-04 10:30:20 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // If now empty, delete the whole key
 | 
					
						
							|  |  |  |     classesKey.DeleteEmptyKey(wprotocol.c_str()); | 
					
						
							| 
									
										
										
										
											2017-12-01 17:39:54 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 10:55:09 -07:00
										 |  |  |     return true; | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-16 15:54:30 +10:00
										 |  |  | bool Browser::SetAsDefaultProtocolClient(const std::string& protocol, | 
					
						
							| 
									
										
										
										
											2020-07-28 16:43:43 -07:00
										 |  |  |                                          gin::Arguments* args) { | 
					
						
							| 
									
										
										
										
											2016-03-21 11:24:25 -07: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 09:57:52 +09:00
										 |  |  |   base::string16 exe; | 
					
						
							| 
									
										
										
										
											2017-02-03 17:38:16 -08:00
										 |  |  |   if (!GetProtocolLaunchPath(args, &exe)) | 
					
						
							| 
									
										
										
										
											2016-03-21 11:24:25 -07:00
										 |  |  |     return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Main Registry Key
 | 
					
						
							|  |  |  |   HKEY root = HKEY_CURRENT_USER; | 
					
						
							| 
									
										
										
										
											2016-08-22 09:57:52 +09:00
										 |  |  |   base::string16 keyPath = base::UTF8ToUTF16("Software\\Classes\\" + protocol); | 
					
						
							|  |  |  |   base::string16 urlDecl = base::UTF8ToUTF16("URL:" + protocol); | 
					
						
							| 
									
										
										
										
											2016-03-21 11:24:25 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Command Key
 | 
					
						
							| 
									
										
										
										
											2016-08-22 09:57:52 +09:00
										 |  |  |   base::string16 cmdPath = keyPath + L"\\shell\\open\\command"; | 
					
						
							| 
									
										
										
										
											2016-03-21 11:24:25 -07: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 15:54:30 +10:00
										 |  |  | bool Browser::IsDefaultProtocolClient(const std::string& protocol, | 
					
						
							| 
									
										
										
										
											2020-07-28 16:43:43 -07:00
										 |  |  |                                       gin::Arguments* args) { | 
					
						
							| 
									
										
										
										
											2016-04-24 22:17:01 -07:00
										 |  |  |   if (protocol.empty()) | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-22 09:57:52 +09:00
										 |  |  |   base::string16 exe; | 
					
						
							| 
									
										
										
										
											2017-02-03 17:38:16 -08:00
										 |  |  |   if (!GetProtocolLaunchPath(args, &exe)) | 
					
						
							| 
									
										
										
										
											2016-04-24 22:17:01 -07:00
										 |  |  |     return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Main Registry Key
 | 
					
						
							|  |  |  |   HKEY root = HKEY_CURRENT_USER; | 
					
						
							| 
									
										
										
										
											2016-08-22 09:57:52 +09:00
										 |  |  |   base::string16 keyPath = base::UTF8ToUTF16("Software\\Classes\\" + protocol); | 
					
						
							| 
									
										
										
										
											2016-04-24 22:17:01 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Command Key
 | 
					
						
							| 
									
										
										
										
											2016-08-22 09:57:52 +09:00
										 |  |  |   base::string16 cmdPath = keyPath + L"\\shell\\open\\command"; | 
					
						
							| 
									
										
										
										
											2016-04-24 22:17:01 -07: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 09:57:52 +09:00
										 |  |  |   base::string16 keyVal; | 
					
						
							| 
									
										
										
										
											2016-04-24 22:17:01 -07:00
										 |  |  |   if (FAILED(commandKey.ReadValue(L"", &keyVal))) | 
					
						
							|  |  |  |     // Default value not set, we can confirm that it is not set
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-22 09:57:52 +09:00
										 |  |  |   // Default value is the same as current file path
 | 
					
						
							|  |  |  |   return keyVal == exe; | 
					
						
							| 
									
										
										
										
											2016-04-24 22:17:01 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 17:50:33 -08:00
										 |  |  | base::string16 Browser::GetApplicationNameForProtocol(const GURL& url) { | 
					
						
							|  |  |  |   // Windows 8 or above has a new protocol association query.
 | 
					
						
							|  |  |  |   if (base::win::GetVersion() >= base::win::Version::WIN8) { | 
					
						
							| 
									
										
										
										
											2020-06-30 12:22:30 -07:00
										 |  |  |     base::string16 application_name = GetAppDisplayNameForProtocol(url); | 
					
						
							| 
									
										
										
										
											2019-11-06 17:50:33 -08:00
										 |  |  |     if (!application_name.empty()) | 
					
						
							|  |  |  |       return application_name; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return GetAppForProtocolUsingRegistry(url); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-30 12:22:30 -07:00
										 |  |  | v8::Local<v8::Promise> Browser::GetApplicationInfoForProtocol( | 
					
						
							|  |  |  |     v8::Isolate* isolate, | 
					
						
							|  |  |  |     const GURL& url) { | 
					
						
							|  |  |  |   gin_helper::Promise<gin_helper::Dictionary> promise(isolate); | 
					
						
							|  |  |  |   v8::Local<v8::Promise> handle = promise.GetHandle(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Windows 8 or above has a new protocol association query.
 | 
					
						
							|  |  |  |   if (base::win::GetVersion() >= base::win::Version::WIN8) { | 
					
						
							|  |  |  |     GetApplicationInfoForProtocolUsingAssocQuery( | 
					
						
							|  |  |  |         isolate, url, std::move(promise), &cancelable_task_tracker_); | 
					
						
							|  |  |  |     return handle; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GetApplicationInfoForProtocolUsingRegistry(isolate, url, std::move(promise), | 
					
						
							|  |  |  |                                              &cancelable_task_tracker_); | 
					
						
							|  |  |  |   return handle; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-21 00:45:06 -05:00
										 |  |  | bool Browser::SetBadgeCount(base::Optional<int> count) { | 
					
						
							|  |  |  |   base::Optional<std::string> badge_content; | 
					
						
							|  |  |  |   if (count.has_value() && count.value() == 0) { | 
					
						
							|  |  |  |     badge_content = base::nullopt; | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     badge_content = badging::BadgeManager::GetBadgeString(count); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // There are 3 different cases when the badge has a value:
 | 
					
						
							|  |  |  |   // 1. |contents| is between 1 and 99 inclusive => Set the accessibility text
 | 
					
						
							|  |  |  |   //    to a pluralized notification count (e.g. 4 Unread Notifications).
 | 
					
						
							|  |  |  |   // 2. |contents| is greater than 99 => Set the accessibility text to
 | 
					
						
							|  |  |  |   //    More than |kMaxBadgeContent| unread notifications, so the
 | 
					
						
							|  |  |  |   //    accessibility text matches what is displayed on the badge (e.g. More
 | 
					
						
							|  |  |  |   //    than 99 notifications).
 | 
					
						
							|  |  |  |   // 3. The badge is set to 'flag' => Set the accessibility text to something
 | 
					
						
							|  |  |  |   //    less specific (e.g. Unread Notifications).
 | 
					
						
							|  |  |  |   std::string badge_alt_string; | 
					
						
							|  |  |  |   if (count.has_value()) { | 
					
						
							|  |  |  |     badge_count_ = count.value(); | 
					
						
							|  |  |  |     badge_alt_string = (uint64_t)badge_count_ <= badging::kMaxBadgeContent | 
					
						
							|  |  |  |                            // Case 1.
 | 
					
						
							|  |  |  |                            ? l10n_util::GetPluralStringFUTF8( | 
					
						
							|  |  |  |                                  IDS_BADGE_UNREAD_NOTIFICATIONS, badge_count_) | 
					
						
							|  |  |  |                            // Case 2.
 | 
					
						
							|  |  |  |                            : l10n_util::GetPluralStringFUTF8( | 
					
						
							|  |  |  |                                  IDS_BADGE_UNREAD_NOTIFICATIONS_SATURATED, | 
					
						
							|  |  |  |                                  badging::kMaxBadgeContent); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     // Case 3.
 | 
					
						
							|  |  |  |     badge_alt_string = | 
					
						
							|  |  |  |         l10n_util::GetStringUTF8(IDS_BADGE_UNREAD_NOTIFICATIONS_UNSPECIFIED); | 
					
						
							|  |  |  |     badge_count_ = 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   for (auto* window : WindowList::GetWindows()) { | 
					
						
							|  |  |  |     // On Windows set the badge on the first window found.
 | 
					
						
							|  |  |  |     UpdateBadgeContents(window->GetAcceleratedWidget(), badge_content, | 
					
						
							|  |  |  |                         badge_alt_string); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Browser::UpdateBadgeContents( | 
					
						
							|  |  |  |     HWND hwnd, | 
					
						
							|  |  |  |     const base::Optional<std::string>& badge_content, | 
					
						
							|  |  |  |     const std::string& badge_alt_string) { | 
					
						
							|  |  |  |   SkBitmap badge; | 
					
						
							|  |  |  |   if (badge_content) { | 
					
						
							|  |  |  |     std::string content = badge_content.value(); | 
					
						
							|  |  |  |     constexpr int kOverlayIconSize = 16; | 
					
						
							|  |  |  |     // This is the color used by the Windows 10 Badge API, for platform
 | 
					
						
							|  |  |  |     // consistency.
 | 
					
						
							|  |  |  |     constexpr int kBackgroundColor = SkColorSetRGB(0x26, 0x25, 0x2D); | 
					
						
							|  |  |  |     constexpr int kForegroundColor = SK_ColorWHITE; | 
					
						
							|  |  |  |     constexpr int kRadius = kOverlayIconSize / 2; | 
					
						
							|  |  |  |     // The minimum gap to have between our content and the edge of the badge.
 | 
					
						
							|  |  |  |     constexpr int kMinMargin = 3; | 
					
						
							|  |  |  |     // The amount of space we have to render the icon.
 | 
					
						
							|  |  |  |     constexpr int kMaxBounds = kOverlayIconSize - 2 * kMinMargin; | 
					
						
							|  |  |  |     constexpr int kMaxTextSize = 24;  // Max size for our text.
 | 
					
						
							|  |  |  |     constexpr int kMinTextSize = 7;   // Min size for our text.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     badge.allocN32Pixels(kOverlayIconSize, kOverlayIconSize); | 
					
						
							|  |  |  |     SkCanvas canvas(badge, skia::LegacyDisplayGlobals::GetSkSurfaceProps()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     SkPaint paint; | 
					
						
							|  |  |  |     paint.setAntiAlias(true); | 
					
						
							|  |  |  |     paint.setColor(kBackgroundColor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     canvas.clear(SK_ColorTRANSPARENT); | 
					
						
							|  |  |  |     canvas.drawCircle(kRadius, kRadius, kRadius, paint); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     paint.reset(); | 
					
						
							|  |  |  |     paint.setColor(kForegroundColor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     SkFont font; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     SkRect bounds; | 
					
						
							|  |  |  |     int text_size = kMaxTextSize; | 
					
						
							|  |  |  |     // Find the largest |text_size| larger than |kMinTextSize| in which
 | 
					
						
							|  |  |  |     // |content| fits into our 16x16px icon, with margins.
 | 
					
						
							|  |  |  |     do { | 
					
						
							|  |  |  |       font.setSize(text_size--); | 
					
						
							|  |  |  |       font.measureText(content.c_str(), content.size(), SkTextEncoding::kUTF8, | 
					
						
							|  |  |  |                        &bounds); | 
					
						
							|  |  |  |     } while (text_size >= kMinTextSize && | 
					
						
							|  |  |  |              (bounds.width() > kMaxBounds || bounds.height() > kMaxBounds)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     canvas.drawSimpleText( | 
					
						
							|  |  |  |         content.c_str(), content.size(), SkTextEncoding::kUTF8, | 
					
						
							|  |  |  |         kRadius - bounds.width() / 2 - bounds.x(), | 
					
						
							|  |  |  |         kRadius - bounds.height() / 2 - bounds.y(), font, paint); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   taskbar_host_.SetOverlayIcon(hwnd, badge, badge_alt_string); | 
					
						
							| 
									
										
										
										
											2016-07-01 17:39:01 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-30 14:01:40 -08:00
										 |  |  | void Browser::SetLoginItemSettings(LoginItemSettings settings) { | 
					
						
							| 
									
										
										
										
											2020-07-29 10:08:37 -07:00
										 |  |  |   base::string16 key_path = | 
					
						
							|  |  |  |       L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; | 
					
						
							|  |  |  |   base::win::RegKey key(HKEY_CURRENT_USER, key_path.c_str(), KEY_ALL_ACCESS); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   base::string16 startup_approved_key_path = | 
					
						
							|  |  |  |       L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved" | 
					
						
							|  |  |  |       L"\\Run"; | 
					
						
							|  |  |  |   base::win::RegKey startup_approved_key( | 
					
						
							|  |  |  |       HKEY_CURRENT_USER, startup_approved_key_path.c_str(), KEY_ALL_ACCESS); | 
					
						
							|  |  |  |   PCWSTR key_name = | 
					
						
							| 
									
										
										
										
											2020-10-22 13:24:59 -07:00
										 |  |  |       !settings.name.empty() ? settings.name.c_str() : GetAppUserModelID(); | 
					
						
							| 
									
										
										
										
											2016-07-11 12:29:01 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (settings.open_at_login) { | 
					
						
							| 
									
										
										
										
											2017-01-30 14:01:40 -08:00
										 |  |  |     base::string16 exe = settings.path; | 
					
						
							| 
									
										
										
										
											2017-02-06 08:34:28 -08:00
										 |  |  |     if (FormatCommandLineString(&exe, settings.args)) { | 
					
						
							| 
									
										
										
										
											2020-07-29 10:08:37 -07:00
										 |  |  |       key.WriteValue(key_name, exe.c_str()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (settings.enabled) { | 
					
						
							|  |  |  |         startup_approved_key.DeleteValue(key_name); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         HKEY hard_key; | 
					
						
							|  |  |  |         LPCTSTR path = TEXT( | 
					
						
							|  |  |  |             "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApp" | 
					
						
							|  |  |  |             "roved\\Run"); | 
					
						
							|  |  |  |         LONG res = | 
					
						
							|  |  |  |             RegOpenKeyEx(HKEY_CURRENT_USER, path, 0, KEY_ALL_ACCESS, &hard_key); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (res == ERROR_SUCCESS) { | 
					
						
							|  |  |  |           UCHAR disable_startup_binary[] = {0x03, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  |                                             0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; | 
					
						
							|  |  |  |           RegSetValueEx(hard_key, key_name, 0, REG_BINARY, | 
					
						
							|  |  |  |                         reinterpret_cast<const BYTE*>(disable_startup_binary), | 
					
						
							|  |  |  |                         sizeof(disable_startup_binary)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-02-06 08:34:28 -08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-07-11 12:29:01 -07:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2020-07-29 10:08:37 -07:00
										 |  |  |     // if open at login is false, delete both values
 | 
					
						
							|  |  |  |     startup_approved_key.DeleteValue(key_name); | 
					
						
							|  |  |  |     key.DeleteValue(key_name); | 
					
						
							| 
									
										
										
										
											2016-07-11 11:12:26 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-07-11 10:57:53 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-26 02:18:18 -08:00
										 |  |  | Browser::LoginItemSettings Browser::GetLoginItemSettings( | 
					
						
							| 
									
										
										
										
											2017-03-29 21:29:52 +02:00
										 |  |  |     const LoginItemSettings& options) { | 
					
						
							| 
									
										
										
										
											2016-07-11 11:12:26 -07:00
										 |  |  |   LoginItemSettings settings; | 
					
						
							| 
									
										
										
										
											2016-08-22 09:57:52 +09:00
										 |  |  |   base::string16 keyPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; | 
					
						
							| 
									
										
										
										
											2016-07-11 12:29:01 -07:00
										 |  |  |   base::win::RegKey key(HKEY_CURRENT_USER, keyPath.c_str(), KEY_ALL_ACCESS); | 
					
						
							| 
									
										
										
										
											2016-08-22 09:57:52 +09:00
										 |  |  |   base::string16 keyVal; | 
					
						
							| 
									
										
										
										
											2016-07-11 11:12:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-29 10:08:37 -07:00
										 |  |  |   // keep old openAtLogin behaviour
 | 
					
						
							| 
									
										
										
										
											2016-07-11 12:29:01 -07:00
										 |  |  |   if (!FAILED(key.ReadValue(GetAppUserModelID(), &keyVal))) { | 
					
						
							| 
									
										
										
										
											2017-01-30 14:01:40 -08:00
										 |  |  |     base::string16 exe = options.path; | 
					
						
							| 
									
										
										
										
											2017-02-03 17:38:16 -08:00
										 |  |  |     if (FormatCommandLineString(&exe, options.args)) { | 
					
						
							| 
									
										
										
										
											2017-01-26 02:05:35 -08:00
										 |  |  |       settings.open_at_login = keyVal == exe; | 
					
						
							| 
									
										
										
										
											2016-07-11 12:29:01 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-07-11 11:12:26 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-29 10:08:37 -07:00
										 |  |  |   // iterate over current user and machine registries and populate launch items
 | 
					
						
							|  |  |  |   // if there exists a launch entry with property enabled=='true',
 | 
					
						
							|  |  |  |   // set executable_will_launch_at_login to 'true'.
 | 
					
						
							|  |  |  |   boolean executable_will_launch_at_login = false; | 
					
						
							|  |  |  |   std::vector<Browser::LaunchItem> launch_items; | 
					
						
							|  |  |  |   base::win::RegistryValueIterator hkcu_iterator(HKEY_CURRENT_USER, | 
					
						
							|  |  |  |                                                  keyPath.c_str()); | 
					
						
							|  |  |  |   base::win::RegistryValueIterator hklm_iterator(HKEY_LOCAL_MACHINE, | 
					
						
							|  |  |  |                                                  keyPath.c_str()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   launch_items = GetLoginItemSettingsHelper( | 
					
						
							|  |  |  |       &hkcu_iterator, &executable_will_launch_at_login, L"user", options); | 
					
						
							|  |  |  |   std::vector<Browser::LaunchItem> launch_items_hklm = | 
					
						
							|  |  |  |       GetLoginItemSettingsHelper(&hklm_iterator, | 
					
						
							|  |  |  |                                  &executable_will_launch_at_login, L"machine", | 
					
						
							|  |  |  |                                  options); | 
					
						
							|  |  |  |   launch_items.insert(launch_items.end(), launch_items_hklm.begin(), | 
					
						
							|  |  |  |                       launch_items_hklm.end()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   settings.executable_will_launch_at_login = executable_will_launch_at_login; | 
					
						
							|  |  |  |   settings.launch_items = launch_items; | 
					
						
							| 
									
										
										
										
											2016-07-11 12:29:01 -07:00
										 |  |  |   return settings; | 
					
						
							| 
									
										
										
										
											2016-07-11 10:57:53 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-03 14:55:43 +08:00
										 |  |  | PCWSTR Browser::GetAppUserModelID() { | 
					
						
							| 
									
										
										
										
											2018-10-24 12:49:10 +02:00
										 |  |  |   return GetRawAppUserModelID(); | 
					
						
							| 
									
										
										
										
											2015-11-03 14:55:43 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-05 10:26:01 +08:00
										 |  |  | std::string Browser::GetExecutableFileVersion() const { | 
					
						
							| 
									
										
										
										
											2013-07-04 20:58:28 +08:00
										 |  |  |   base::FilePath path; | 
					
						
							| 
									
										
										
										
											2018-09-14 17:09:42 -07:00
										 |  |  |   if (base::PathService::Get(base::FILE_EXE, &path)) { | 
					
						
							| 
									
										
										
										
											2018-01-02 17:02:12 +09:00
										 |  |  |     base::ThreadRestrictions::ScopedAllowIO allow_io; | 
					
						
							| 
									
										
										
										
											2019-08-12 16:32:51 -07:00
										 |  |  |     std::unique_ptr<FileVersionInfo> version_info = FetchFileVersionInfo(); | 
					
						
							| 
									
										
										
										
											2014-07-11 12:19:01 +08:00
										 |  |  |     return base::UTF16ToUTF8(version_info->product_version()); | 
					
						
							| 
									
										
										
										
											2013-07-04 20:58:28 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-17 13:37:55 -07:00
										 |  |  |   return ELECTRON_VERSION_STRING; | 
					
						
							| 
									
										
										
										
											2013-12-05 10:42:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | std::string Browser::GetExecutableFileProductName() const { | 
					
						
							| 
									
										
										
										
											2018-10-24 12:49:10 +02:00
										 |  |  |   return GetApplicationName(); | 
					
						
							| 
									
										
										
										
											2013-07-04 20:58:28 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-14 13:39:52 -07:00
										 |  |  | bool Browser::IsEmojiPanelSupported() { | 
					
						
							|  |  |  |   // emoji picker is supported on Windows 10's Spring 2018 update & above.
 | 
					
						
							| 
									
										
										
										
											2019-04-30 20:18:22 -04:00
										 |  |  |   return base::win::GetVersion() >= base::win::Version::WIN10_RS4; | 
					
						
							| 
									
										
										
										
											2019-03-14 13:39:52 -07: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 16:32:51 -07: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 14:30:59 +09:00
										 |  |  | void Browser::SetAboutPanelOptions(base::DictionaryValue options) { | 
					
						
							|  |  |  |   about_panel_options_ = std::move(options); | 
					
						
							| 
									
										
										
										
											2019-08-12 16:32:51 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  | }  // namespace electron
 |