browser_mac.mm 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. // Copyright (c) 2013 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/browser/browser.h"
  5. #include <memory>
  6. #include <string>
  7. #include <utility>
  8. #include "base/apple/bridging.h"
  9. #include "base/apple/bundle_locations.h"
  10. #include "base/apple/scoped_cftyperef.h"
  11. #include "base/i18n/rtl.h"
  12. #include "base/mac/mac_util.h"
  13. #include "base/mac/mac_util.mm"
  14. #include "base/strings/string_number_conversions.h"
  15. #include "base/strings/sys_string_conversions.h"
  16. #include "chrome/browser/browser_process.h"
  17. #include "net/base/mac/url_conversions.h"
  18. #include "shell/browser/badging/badge_manager.h"
  19. #include "shell/browser/mac/dict_util.h"
  20. #include "shell/browser/mac/electron_application.h"
  21. #include "shell/browser/mac/electron_application_delegate.h"
  22. #include "shell/browser/native_window.h"
  23. #include "shell/browser/window_list.h"
  24. #include "shell/common/api/electron_api_native_image.h"
  25. #include "shell/common/application_info.h"
  26. #include "shell/common/gin_converters/image_converter.h"
  27. #include "shell/common/gin_helper/arguments.h"
  28. #include "shell/common/gin_helper/dictionary.h"
  29. #include "shell/common/gin_helper/error_thrower.h"
  30. #include "shell/common/gin_helper/promise.h"
  31. #include "shell/common/platform_util.h"
  32. #include "ui/base/resource/resource_scale_factor.h"
  33. #include "ui/gfx/image/image.h"
  34. #include "url/gurl.h"
  35. namespace electron {
  36. namespace {
  37. bool IsAppRTL() {
  38. const std::string& locale = g_browser_process->GetApplicationLocale();
  39. base::i18n::TextDirection text_direction =
  40. base::i18n::GetTextDirectionForLocaleInStartUp(locale.c_str());
  41. return text_direction == base::i18n::RIGHT_TO_LEFT;
  42. }
  43. NSString* GetAppPathForProtocol(const GURL& url) {
  44. NSURL* ns_url = [NSURL
  45. URLWithString:base::SysUTF8ToNSString(url.possibly_invalid_spec())];
  46. base::apple::ScopedCFTypeRef<CFErrorRef> out_err;
  47. base::apple::ScopedCFTypeRef<CFURLRef> openingApp(
  48. LSCopyDefaultApplicationURLForURL(base::apple::NSToCFPtrCast(ns_url),
  49. kLSRolesAll, out_err.InitializeInto()));
  50. if (out_err) {
  51. // likely kLSApplicationNotFoundErr
  52. return nullptr;
  53. }
  54. NSString* app_path = [base::apple::CFToNSPtrCast(openingApp.get()) path];
  55. return app_path;
  56. }
  57. gfx::Image GetApplicationIconForProtocol(NSString* _Nonnull app_path) {
  58. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile:app_path];
  59. gfx::Image icon(image);
  60. return icon;
  61. }
  62. std::u16string GetAppDisplayNameForProtocol(NSString* app_path) {
  63. NSString* app_display_name =
  64. [[NSFileManager defaultManager] displayNameAtPath:app_path];
  65. return base::SysNSStringToUTF16(app_display_name);
  66. }
  67. #if !IS_MAS_BUILD()
  68. bool CheckLoginItemStatus(bool* is_hidden) {
  69. base::mac::LoginItemsFileList login_items;
  70. if (!login_items.Initialize())
  71. return false;
  72. base::apple::ScopedCFTypeRef<LSSharedFileListItemRef> item(
  73. login_items.GetLoginItemForMainApp());
  74. if (!item.get())
  75. return false;
  76. if (is_hidden)
  77. *is_hidden = base::mac::IsHiddenLoginItem(item);
  78. return true;
  79. }
  80. #endif
  81. } // namespace
  82. v8::Local<v8::Promise> Browser::GetApplicationInfoForProtocol(
  83. v8::Isolate* isolate,
  84. const GURL& url) {
  85. gin_helper::Promise<gin_helper::Dictionary> promise(isolate);
  86. v8::Local<v8::Promise> handle = promise.GetHandle();
  87. auto dict = gin_helper::Dictionary::CreateEmpty(isolate);
  88. NSString* ns_app_path = GetAppPathForProtocol(url);
  89. if (!ns_app_path) {
  90. promise.RejectWithErrorMessage(
  91. "Unable to retrieve installation path to app");
  92. return handle;
  93. }
  94. std::u16string app_path = base::SysNSStringToUTF16(ns_app_path);
  95. std::u16string app_display_name = GetAppDisplayNameForProtocol(ns_app_path);
  96. gfx::Image app_icon = GetApplicationIconForProtocol(ns_app_path);
  97. dict.Set("name", app_display_name);
  98. dict.Set("path", app_path);
  99. dict.Set("icon", app_icon);
  100. promise.Resolve(dict);
  101. return handle;
  102. }
  103. void Browser::SetShutdownHandler(base::RepeatingCallback<bool()> handler) {
  104. [[AtomApplication sharedApplication] setShutdownHandler:std::move(handler)];
  105. }
  106. void Browser::Focus(gin::Arguments* args) {
  107. gin_helper::Dictionary opts;
  108. bool steal_focus = false;
  109. if (args->GetNext(&opts)) {
  110. gin_helper::ErrorThrower thrower(args->isolate());
  111. if (!opts.Get("steal", &steal_focus)) {
  112. thrower.ThrowError(
  113. "Expected options object to contain a 'steal' boolean property");
  114. return;
  115. }
  116. }
  117. [[AtomApplication sharedApplication] activateIgnoringOtherApps:steal_focus];
  118. }
  119. void Browser::Hide() {
  120. [[AtomApplication sharedApplication] hide:nil];
  121. }
  122. bool Browser::IsHidden() {
  123. return [[AtomApplication sharedApplication] isHidden];
  124. }
  125. void Browser::Show() {
  126. [[AtomApplication sharedApplication] unhide:nil];
  127. }
  128. void Browser::AddRecentDocument(const base::FilePath& path) {
  129. NSString* path_string = base::apple::FilePathToNSString(path);
  130. if (!path_string)
  131. return;
  132. NSURL* u = [NSURL fileURLWithPath:path_string];
  133. if (!u)
  134. return;
  135. [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:u];
  136. }
  137. void Browser::ClearRecentDocuments() {
  138. [[NSDocumentController sharedDocumentController] clearRecentDocuments:nil];
  139. }
  140. bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
  141. gin::Arguments* args) {
  142. NSString* identifier = [base::apple::MainBundle() bundleIdentifier];
  143. if (!identifier)
  144. return false;
  145. if (!Browser::IsDefaultProtocolClient(protocol, args))
  146. return false;
  147. NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()];
  148. CFStringRef protocol_cf = base::apple::NSToCFPtrCast(protocol_ns);
  149. // TODO(codebytere): Use -[NSWorkspace URLForApplicationToOpenURL:] instead
  150. #pragma clang diagnostic push
  151. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  152. CFArrayRef bundleList = LSCopyAllHandlersForURLScheme(protocol_cf);
  153. #pragma clang diagnostic pop
  154. if (!bundleList) {
  155. return false;
  156. }
  157. // On macOS, we can't query the default, but the handlers list seems to put
  158. // Apple's defaults first, so we'll use the first option that isn't our bundle
  159. CFStringRef other = nil;
  160. for (CFIndex i = 0; i < CFArrayGetCount(bundleList); ++i) {
  161. other =
  162. base::apple::CFCast<CFStringRef>(CFArrayGetValueAtIndex(bundleList, i));
  163. if (![identifier isEqualToString:(__bridge NSString*)other]) {
  164. break;
  165. }
  166. }
  167. // No other app was found set it to none instead of setting it back to itself.
  168. if ([identifier isEqualToString:(__bridge NSString*)other]) {
  169. other = base::apple::NSToCFPtrCast(@"None");
  170. }
  171. OSStatus return_code = LSSetDefaultHandlerForURLScheme(protocol_cf, other);
  172. return return_code == noErr;
  173. }
  174. bool Browser::SetAsDefaultProtocolClient(const std::string& protocol,
  175. gin::Arguments* args) {
  176. if (protocol.empty())
  177. return false;
  178. NSString* identifier = [base::apple::MainBundle() bundleIdentifier];
  179. if (!identifier)
  180. return false;
  181. NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()];
  182. OSStatus return_code =
  183. LSSetDefaultHandlerForURLScheme(base::apple::NSToCFPtrCast(protocol_ns),
  184. base::apple::NSToCFPtrCast(identifier));
  185. return return_code == noErr;
  186. }
  187. bool Browser::IsDefaultProtocolClient(const std::string& protocol,
  188. gin::Arguments* args) {
  189. if (protocol.empty())
  190. return false;
  191. NSString* identifier = [base::apple::MainBundle() bundleIdentifier];
  192. if (!identifier)
  193. return false;
  194. NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()];
  195. // TODO(codebytere): Use -[NSWorkspace URLForApplicationToOpenURL:] instead
  196. #pragma clang diagnostic push
  197. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  198. base::apple::ScopedCFTypeRef<CFStringRef> bundleId(
  199. LSCopyDefaultHandlerForURLScheme(
  200. base::apple::NSToCFPtrCast(protocol_ns)));
  201. #pragma clang diagnostic pop
  202. if (!bundleId)
  203. return false;
  204. // Ensure the comparison is case-insensitive
  205. // as LS does not persist the case of the bundle id.
  206. NSComparisonResult result =
  207. [base::apple::CFToNSPtrCast(bundleId) caseInsensitiveCompare:identifier];
  208. return result == NSOrderedSame;
  209. }
  210. std::u16string Browser::GetApplicationNameForProtocol(const GURL& url) {
  211. NSString* app_path = GetAppPathForProtocol(url);
  212. if (!app_path) {
  213. return std::u16string();
  214. }
  215. std::u16string app_display_name = GetAppDisplayNameForProtocol(app_path);
  216. return app_display_name;
  217. }
  218. bool Browser::SetBadgeCount(absl::optional<int> count) {
  219. DockSetBadgeText(!count.has_value() || count.value() != 0
  220. ? badging::BadgeManager::GetBadgeString(count)
  221. : "");
  222. if (count.has_value()) {
  223. badge_count_ = count.value();
  224. } else {
  225. badge_count_ = 0;
  226. }
  227. return true;
  228. }
  229. void Browser::SetUserActivity(const std::string& type,
  230. base::Value::Dict user_info,
  231. gin::Arguments* args) {
  232. std::string url_string;
  233. args->GetNext(&url_string);
  234. [[AtomApplication sharedApplication]
  235. setCurrentActivity:base::SysUTF8ToNSString(type)
  236. withUserInfo:DictionaryValueToNSDictionary(std::move(user_info))
  237. withWebpageURL:net::NSURLWithGURL(GURL(url_string))];
  238. }
  239. std::string Browser::GetCurrentActivityType() {
  240. NSUserActivity* userActivity =
  241. [[AtomApplication sharedApplication] getCurrentActivity];
  242. return base::SysNSStringToUTF8(userActivity.activityType);
  243. }
  244. void Browser::InvalidateCurrentActivity() {
  245. [[AtomApplication sharedApplication] invalidateCurrentActivity];
  246. }
  247. void Browser::ResignCurrentActivity() {
  248. [[AtomApplication sharedApplication] resignCurrentActivity];
  249. }
  250. void Browser::UpdateCurrentActivity(const std::string& type,
  251. base::Value::Dict user_info) {
  252. [[AtomApplication sharedApplication]
  253. updateCurrentActivity:base::SysUTF8ToNSString(type)
  254. withUserInfo:DictionaryValueToNSDictionary(
  255. std::move(user_info))];
  256. }
  257. bool Browser::WillContinueUserActivity(const std::string& type) {
  258. bool prevent_default = false;
  259. for (BrowserObserver& observer : observers_)
  260. observer.OnWillContinueUserActivity(&prevent_default, type);
  261. return prevent_default;
  262. }
  263. void Browser::DidFailToContinueUserActivity(const std::string& type,
  264. const std::string& error) {
  265. for (BrowserObserver& observer : observers_)
  266. observer.OnDidFailToContinueUserActivity(type, error);
  267. }
  268. bool Browser::ContinueUserActivity(const std::string& type,
  269. base::Value::Dict user_info,
  270. base::Value::Dict details) {
  271. bool prevent_default = false;
  272. for (BrowserObserver& observer : observers_)
  273. observer.OnContinueUserActivity(&prevent_default, type, user_info.Clone(),
  274. details.Clone());
  275. return prevent_default;
  276. }
  277. void Browser::UserActivityWasContinued(const std::string& type,
  278. base::Value::Dict user_info) {
  279. for (BrowserObserver& observer : observers_)
  280. observer.OnUserActivityWasContinued(type, user_info.Clone());
  281. }
  282. bool Browser::UpdateUserActivityState(const std::string& type,
  283. base::Value::Dict user_info) {
  284. bool prevent_default = false;
  285. for (BrowserObserver& observer : observers_)
  286. observer.OnUpdateUserActivityState(&prevent_default, type,
  287. user_info.Clone());
  288. return prevent_default;
  289. }
  290. // Modified from chrome/browser/ui/cocoa/l10n_util.mm.
  291. void Browser::ApplyForcedRTL() {
  292. NSUserDefaults* defaults = NSUserDefaults.standardUserDefaults;
  293. auto dir = base::i18n::GetForcedTextDirection();
  294. // An Electron app should respect RTL behavior of application locale over
  295. // system locale.
  296. auto should_be_rtl = dir == base::i18n::RIGHT_TO_LEFT || IsAppRTL();
  297. auto should_be_ltr = dir == base::i18n::LEFT_TO_RIGHT || !IsAppRTL();
  298. // -registerDefaults: won't do the trick here because these defaults exist
  299. // (in the global domain) to reflect the system locale. They need to be set
  300. // in Chrome's domain to supersede the system value.
  301. if (should_be_rtl) {
  302. [defaults setBool:YES forKey:@"AppleTextDirection"];
  303. [defaults setBool:YES forKey:@"NSForceRightToLeftWritingDirection"];
  304. } else if (should_be_ltr) {
  305. [defaults setBool:YES forKey:@"AppleTextDirection"];
  306. [defaults setBool:NO forKey:@"NSForceRightToLeftWritingDirection"];
  307. } else {
  308. [defaults removeObjectForKey:@"AppleTextDirection"];
  309. [defaults removeObjectForKey:@"NSForceRightToLeftWritingDirection"];
  310. }
  311. }
  312. Browser::LoginItemSettings Browser::GetLoginItemSettings(
  313. const LoginItemSettings& options) {
  314. LoginItemSettings settings;
  315. #if IS_MAS_BUILD()
  316. settings.open_at_login = platform_util::GetLoginItemEnabled();
  317. #else
  318. settings.open_at_login = CheckLoginItemStatus(&settings.open_as_hidden);
  319. settings.restore_state = base::mac::WasLaunchedAsLoginItemRestoreState();
  320. settings.opened_at_login = base::mac::WasLaunchedAsLoginOrResumeItem();
  321. settings.opened_as_hidden = base::mac::WasLaunchedAsHiddenLoginItem();
  322. #endif
  323. return settings;
  324. }
  325. void Browser::SetLoginItemSettings(LoginItemSettings settings) {
  326. #if IS_MAS_BUILD()
  327. if (!platform_util::SetLoginItemEnabled(settings.open_at_login)) {
  328. LOG(ERROR) << "Unable to set login item enabled on sandboxed app.";
  329. }
  330. #else
  331. if (settings.open_at_login) {
  332. base::mac::AddToLoginItems(base::apple::MainBundlePath(),
  333. settings.open_as_hidden);
  334. } else {
  335. base::mac::RemoveFromLoginItems(base::apple::MainBundlePath());
  336. }
  337. #endif
  338. }
  339. std::string Browser::GetExecutableFileVersion() const {
  340. return GetApplicationVersion();
  341. }
  342. std::string Browser::GetExecutableFileProductName() const {
  343. return GetApplicationName();
  344. }
  345. int Browser::DockBounce(BounceType type) {
  346. return [[AtomApplication sharedApplication]
  347. requestUserAttention:static_cast<NSRequestUserAttentionType>(type)];
  348. }
  349. void Browser::DockCancelBounce(int request_id) {
  350. [[AtomApplication sharedApplication] cancelUserAttentionRequest:request_id];
  351. }
  352. void Browser::DockSetBadgeText(const std::string& label) {
  353. NSDockTile* tile = [[AtomApplication sharedApplication] dockTile];
  354. [tile setBadgeLabel:base::SysUTF8ToNSString(label)];
  355. }
  356. void Browser::DockDownloadFinished(const std::string& filePath) {
  357. [[NSDistributedNotificationCenter defaultCenter]
  358. postNotificationName:@"com.apple.DownloadFileFinished"
  359. object:base::SysUTF8ToNSString(filePath)];
  360. }
  361. std::string Browser::DockGetBadgeText() {
  362. NSDockTile* tile = [[AtomApplication sharedApplication] dockTile];
  363. return base::SysNSStringToUTF8([tile badgeLabel]);
  364. }
  365. void Browser::DockHide() {
  366. // Transforming application state from UIElement to Foreground is an
  367. // asynchronous operation, and unfortunately there is currently no way to know
  368. // when it is finished.
  369. // So if we call DockHide => DockShow => DockHide => DockShow in a very short
  370. // time, we would trigger a bug of macOS that, there would be multiple dock
  371. // icons of the app left in system.
  372. // To work around this, we make sure DockHide does nothing if it is called
  373. // immediately after DockShow. After some experiments, 1 second seems to be
  374. // a proper interval.
  375. if (!last_dock_show_.is_null() &&
  376. base::Time::Now() - last_dock_show_ < base::Seconds(1)) {
  377. return;
  378. }
  379. for (auto* const& window : WindowList::GetWindows())
  380. [window->GetNativeWindow().GetNativeNSWindow() setCanHide:NO];
  381. ProcessSerialNumber psn = {0, kCurrentProcess};
  382. TransformProcessType(&psn, kProcessTransformToUIElementApplication);
  383. }
  384. bool Browser::DockIsVisible() {
  385. // Because DockShow has a slight delay this may not be true immediately
  386. // after that call.
  387. return ([[NSRunningApplication currentApplication] activationPolicy] ==
  388. NSApplicationActivationPolicyRegular);
  389. }
  390. v8::Local<v8::Promise> Browser::DockShow(v8::Isolate* isolate) {
  391. last_dock_show_ = base::Time::Now();
  392. gin_helper::Promise<void> promise(isolate);
  393. v8::Local<v8::Promise> handle = promise.GetHandle();
  394. BOOL active = [[NSRunningApplication currentApplication] isActive];
  395. ProcessSerialNumber psn = {0, kCurrentProcess};
  396. if (active) {
  397. // Workaround buggy behavior of TransformProcessType.
  398. // http://stackoverflow.com/questions/7596643/
  399. NSArray* runningApps = [NSRunningApplication
  400. runningApplicationsWithBundleIdentifier:@"com.apple.dock"];
  401. for (NSRunningApplication* app in runningApps) {
  402. [app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
  403. break;
  404. }
  405. __block gin_helper::Promise<void> p = std::move(promise);
  406. dispatch_time_t one_ms = dispatch_time(DISPATCH_TIME_NOW, USEC_PER_SEC);
  407. dispatch_after(one_ms, dispatch_get_main_queue(), ^{
  408. TransformProcessType(&psn, kProcessTransformToForegroundApplication);
  409. dispatch_time_t one_ms_2 = dispatch_time(DISPATCH_TIME_NOW, USEC_PER_SEC);
  410. dispatch_after(one_ms_2, dispatch_get_main_queue(), ^{
  411. [[NSRunningApplication currentApplication]
  412. activateWithOptions:NSApplicationActivateIgnoringOtherApps];
  413. p.Resolve();
  414. });
  415. });
  416. } else {
  417. TransformProcessType(&psn, kProcessTransformToForegroundApplication);
  418. promise.Resolve();
  419. }
  420. return handle;
  421. }
  422. void Browser::DockSetMenu(ElectronMenuModel* model) {
  423. ElectronApplicationDelegate* delegate =
  424. (ElectronApplicationDelegate*)[NSApp delegate];
  425. [delegate setApplicationDockMenu:model];
  426. }
  427. void Browser::DockSetIcon(v8::Isolate* isolate, v8::Local<v8::Value> icon) {
  428. gfx::Image image;
  429. if (!icon->IsNull()) {
  430. api::NativeImage* native_image = nullptr;
  431. if (!api::NativeImage::TryConvertNativeImage(isolate, icon, &native_image))
  432. return;
  433. image = native_image->image();
  434. }
  435. // This is needed to avoid a hard CHECK when this fn is called
  436. // before the browser process is ready, since supported scales
  437. // are normally set by ui::ResourceBundle::InitSharedInstance
  438. // during browser process startup.
  439. if (!is_ready())
  440. ui::SetSupportedResourceScaleFactors({ui::k100Percent});
  441. [[AtomApplication sharedApplication]
  442. setApplicationIconImage:image.AsNSImage()];
  443. }
  444. void Browser::ShowAboutPanel() {
  445. NSDictionary* options = DictionaryValueToNSDictionary(about_panel_options_);
  446. // Credits must be a NSAttributedString instead of NSString
  447. NSString* credits = (NSString*)options[@"Credits"];
  448. if (credits != nil) {
  449. NSMutableDictionary* mutable_options = [options mutableCopy];
  450. NSAttributedString* creditString = [[NSAttributedString alloc]
  451. initWithString:credits
  452. attributes:@{NSForegroundColorAttributeName : [NSColor textColor]}];
  453. [mutable_options setValue:creditString forKey:@"Credits"];
  454. options = [NSDictionary dictionaryWithDictionary:mutable_options];
  455. }
  456. [[AtomApplication sharedApplication]
  457. orderFrontStandardAboutPanelWithOptions:options];
  458. }
  459. void Browser::SetAboutPanelOptions(base::Value::Dict options) {
  460. about_panel_options_.clear();
  461. for (const auto pair : options) {
  462. std::string key = pair.first;
  463. if (!key.empty() && pair.second.is_string()) {
  464. key[0] = base::ToUpperASCII(key[0]);
  465. about_panel_options_.Set(key, pair.second.Clone());
  466. }
  467. }
  468. }
  469. void Browser::ShowEmojiPanel() {
  470. [[AtomApplication sharedApplication] orderFrontCharacterPalette:nil];
  471. }
  472. bool Browser::IsEmojiPanelSupported() {
  473. return true;
  474. }
  475. bool Browser::IsSecureKeyboardEntryEnabled() {
  476. return password_input_enabler_.get() != nullptr;
  477. }
  478. void Browser::SetSecureKeyboardEntryEnabled(bool enabled) {
  479. if (enabled) {
  480. password_input_enabler_ =
  481. std::make_unique<ui::ScopedPasswordInputEnabler>();
  482. } else {
  483. password_input_enabler_.reset();
  484. }
  485. }
  486. } // namespace electron