2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2013-08-14 14:24:21 +00:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-08-14 14:24:21 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#import "shell/browser/ui/cocoa/electron_menu_controller.h"
|
2013-08-14 14:24:21 +00:00
|
|
|
|
2020-10-20 01:33:06 +00:00
|
|
|
#include <string>
|
2020-01-29 17:03:53 +00:00
|
|
|
#include <utility>
|
|
|
|
|
chore: bump chromium to 118.0.5975.0 (main) (#39531)
* chore: bump chromium in DEPS to 118.0.5951.0
* chore: update printing.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4727894
No logic changes, but patch needed to be manually re-applied due to upstream code shear
* chore: update port_autofill_colors_to_the_color_pipeline.patch
No manual changes; patch applied with fuzz
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5953.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5955.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5957.0
* chore: update patches
* chore: include path of native_web_keyboard_event.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
* chore: remove reference to eextensions/browser/notification-types.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4771627
* chore: update references to renamed upstream field NativeWebKeyboardEvent.skip_if_unhandled (formerly known as skip_in_browser
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
Need a second pair of eyes on this commit. In particular the reference in content_converter.cc, skipInBrowser, seems to not be set or documented anywhere? Is this unused/vestigal code?
* chore: sync signature of ElectronExtensionsBrowserClient::IsValidContext() to upstream change
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4784198
* chore: add auto_pip_setting_helper.[cc,h] to chromium_src build
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4688277
Exiting upstream code used by chromium_src now depends on this new upstream class
* chore: bump chromium in DEPS to 118.0.5959.0
* chore: update add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
Xref: add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
manually adjust patch to minor upstream chagnes
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5961.0
* chore: bump chromium in DEPS to 118.0.5963.0
* chore: update patches
* 4780994: Rename various base files to "apple" since iOS uses them too
https://chromium-review.googlesource.com/c/chromium/src/+/4780994
* Many files moved from `mac` -> `apple`
This commit follows a handful of CLs that simply rename files/symbols to change `mac`
to `apple`
to signify their use across both macOS and iOS:
- 4784010: Move scoped_nsautorelease_pool to base/apple, leave a forwarding header
- 4790744: Move foundation_util to base/apple, leave a forwarding header
- 4790741: Move scoped_cftypreref to base/apple, leave a forwarding header
- 4787627: Move and rename macOS+iOS base/ files in PA to "apple"
- 4780399: Move OSStatus logging to base/apple
- 4787387: Remove forwarding headers
- 4781113: Rename message_pump_mac to "apple" because iOS uses it too
* fixup minor patch update error
A function param got dropped from this patch somewhere earlier
* chore: bump chromium in DEPS to 118.0.5965.2
* chore: update patches
* 4799213: Move ScopedTypeRef and ScopedCFTypeRef into base::apple::
https://chromium-review.googlesource.com/c/chromium/src/+/4799213
* Fix removed include to BrowserContext
In crrev.com/c/4767962 an include to BrowserContext was removed,
which was necessary for compilation. This broke only for us because
"chrome/browser/profiles/profile.h" includes that class, but we remove
all references to profiles.
* chore: bump chromium in DEPS to 118.0.5967.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5969.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5971.0
* chore: bump chromium in DEPS to 118.0.5973.0
* chore: update patches
* 4772121: [OOPIF PDF] Replace PDFWebContentsHelper with PDFDocumentHelper
https://chromium-review.googlesource.com/c/chromium/src/+/4772121
* 4811164: [Extensions] Do some cleanup in ChromeManagementAPIDelegate.
https://chromium-review.googlesource.com/c/chromium/src/+/4811164
* 4809488: Remove duplicate dnd functionality between Web and Renderer prefs
https://chromium-review.googlesource.com/c/chromium/src/+/4809488
Given that this is no longer an option of web preferences, we should
consider deprecating this option and then removing it.
* chore: bump chromium in DEPS to 118.0.5975.0
* chore: update patches
* fixup! chore: add auto_pip_settings_helper.{cc|h} to chromium_src build
* Reland "[windows] Remove RegKey::DeleteEmptyKey"
Refs https://chromium-review.googlesource.com/c/chromium/src/+/4813255
* Ensure StrCat means StrCat
Refs https://chromium-review.googlesource.com/c/chromium/src/+/1117180
* fixup! Remove RegKey::DeleteEmptyKey
* Consistently reject large p and large q in DH
Refs https://boringssl-review.googlesource.com/c/boringssl/+/62226
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: clavin <clavin@electronjs.org>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
2023-09-01 06:54:59 +00:00
|
|
|
#include "base/apple/foundation_util.h"
|
2013-08-14 14:24:21 +00:00
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/strings/sys_string_conversions.h"
|
2015-09-01 11:48:11 +00:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2019-01-12 01:00:43 +00:00
|
|
|
#include "content/public/browser/browser_task_traits.h"
|
2018-02-25 22:19:40 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2020-10-20 01:33:06 +00:00
|
|
|
#include "net/base/mac/url_conversions.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/mac/electron_application.h"
|
2020-10-20 01:33:06 +00:00
|
|
|
#include "shell/browser/native_window.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/electron_menu_model.h"
|
2020-10-20 01:33:06 +00:00
|
|
|
#include "shell/browser/window_list.h"
|
2013-08-14 14:24:21 +00:00
|
|
|
#include "ui/base/accelerators/accelerator.h"
|
|
|
|
#include "ui/base/l10n/l10n_util_mac.h"
|
2015-07-29 04:01:27 +00:00
|
|
|
#include "ui/events/cocoa/cocoa_event_utils.h"
|
2021-06-02 07:32:48 +00:00
|
|
|
#include "ui/events/keycodes/keyboard_code_conversion_mac.h"
|
2013-08-14 14:24:21 +00:00
|
|
|
#include "ui/gfx/image/image.h"
|
2019-02-08 21:19:01 +00:00
|
|
|
#include "ui/strings/grit/ui_strings.h"
|
2013-08-14 14:24:21 +00:00
|
|
|
|
2018-02-25 22:19:40 +00:00
|
|
|
using content::BrowserThread;
|
2020-10-20 01:33:06 +00:00
|
|
|
using SharingItem = electron::ElectronMenuModel::SharingItem;
|
2018-02-25 22:19:40 +00:00
|
|
|
|
2015-09-01 11:48:11 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct Role {
|
|
|
|
SEL selector;
|
|
|
|
const char* role;
|
|
|
|
};
|
|
|
|
Role kRolesMap[] = {
|
2018-04-20 18:47:04 +00:00
|
|
|
{@selector(orderFrontStandardAboutPanel:), "about"},
|
|
|
|
{@selector(hide:), "hide"},
|
|
|
|
{@selector(hideOtherApplications:), "hideothers"},
|
|
|
|
{@selector(unhideAllApplications:), "unhide"},
|
|
|
|
{@selector(arrangeInFront:), "front"},
|
|
|
|
{@selector(undo:), "undo"},
|
|
|
|
{@selector(redo:), "redo"},
|
|
|
|
{@selector(cut:), "cut"},
|
|
|
|
{@selector(copy:), "copy"},
|
|
|
|
{@selector(paste:), "paste"},
|
|
|
|
{@selector(delete:), "delete"},
|
|
|
|
{@selector(pasteAndMatchStyle:), "pasteandmatchstyle"},
|
|
|
|
{@selector(selectAll:), "selectall"},
|
2022-01-06 18:41:28 +00:00
|
|
|
{@selector(orderFrontSubstitutionsPanel:), "showsubstitutions"},
|
|
|
|
{@selector(toggleAutomaticQuoteSubstitution:), "togglesmartquotes"},
|
|
|
|
{@selector(toggleAutomaticDashSubstitution:), "togglesmartdashes"},
|
|
|
|
{@selector(toggleAutomaticTextReplacement:), "toggletextreplacement"},
|
2018-04-20 18:47:04 +00:00
|
|
|
{@selector(startSpeaking:), "startspeaking"},
|
|
|
|
{@selector(stopSpeaking:), "stopspeaking"},
|
|
|
|
{@selector(performMiniaturize:), "minimize"},
|
|
|
|
{@selector(performClose:), "close"},
|
|
|
|
{@selector(performZoom:), "zoom"},
|
|
|
|
{@selector(terminate:), "quit"},
|
|
|
|
// ↓ is intentionally not `toggleFullScreen`. The macOS full screen menu
|
|
|
|
// item behaves weird. If we use `toggleFullScreen`, then the menu item will
|
|
|
|
// use the default label, and not take the one provided.
|
|
|
|
{@selector(toggleFullScreenMode:), "togglefullscreen"},
|
|
|
|
{@selector(toggleTabBar:), "toggletabbar"},
|
|
|
|
{@selector(selectNextTab:), "selectnexttab"},
|
2023-07-10 08:43:37 +00:00
|
|
|
{@selector(toggleTabOverview:), "showalltabs"},
|
2018-04-20 18:47:04 +00:00
|
|
|
{@selector(selectPreviousTab:), "selectprevioustab"},
|
|
|
|
{@selector(mergeAllWindows:), "mergeallwindows"},
|
|
|
|
{@selector(moveTabToNewWindow:), "movetabtonewwindow"},
|
|
|
|
{@selector(clearRecentDocuments:), "clearrecentdocuments"},
|
2015-09-01 11:48:11 +00:00
|
|
|
};
|
|
|
|
|
2019-02-08 21:19:01 +00:00
|
|
|
// Called when adding a submenu to the menu and checks if the submenu, via its
|
|
|
|
// |model|, has visible child items.
|
|
|
|
bool MenuHasVisibleItems(const electron::ElectronMenuModel* model) {
|
|
|
|
int count = model->GetItemCount();
|
|
|
|
for (int index = 0; index < count; index++) {
|
|
|
|
if (model->IsVisibleAt(index))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called when an empty submenu is created. This inserts a menu item labeled
|
|
|
|
// "(empty)" into the submenu. Matches Windows behavior.
|
|
|
|
NSMenu* MakeEmptySubmenu() {
|
2023-07-18 22:26:27 +00:00
|
|
|
NSMenu* submenu = [[NSMenu alloc] initWithTitle:@""];
|
2019-02-08 21:19:01 +00:00
|
|
|
NSString* empty_menu_title =
|
|
|
|
l10n_util::GetNSString(IDS_APP_MENU_EMPTY_SUBMENU);
|
|
|
|
|
|
|
|
[submenu addItemWithTitle:empty_menu_title action:NULL keyEquivalent:@""];
|
|
|
|
[[submenu itemAtIndex:0] setEnabled:NO];
|
2023-07-18 22:26:27 +00:00
|
|
|
return submenu;
|
2019-02-08 21:19:01 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 01:33:06 +00:00
|
|
|
// Convert an SharingItem to an array of NSObjects.
|
|
|
|
NSArray* ConvertSharingItemToNS(const SharingItem& item) {
|
|
|
|
NSMutableArray* result = [NSMutableArray array];
|
|
|
|
if (item.texts) {
|
|
|
|
for (const std::string& str : *item.texts)
|
|
|
|
[result addObject:base::SysUTF8ToNSString(str)];
|
|
|
|
}
|
|
|
|
if (item.file_paths) {
|
|
|
|
for (const base::FilePath& path : *item.file_paths)
|
chore: bump chromium to 118.0.5975.0 (main) (#39531)
* chore: bump chromium in DEPS to 118.0.5951.0
* chore: update printing.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4727894
No logic changes, but patch needed to be manually re-applied due to upstream code shear
* chore: update port_autofill_colors_to_the_color_pipeline.patch
No manual changes; patch applied with fuzz
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5953.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5955.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5957.0
* chore: update patches
* chore: include path of native_web_keyboard_event.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
* chore: remove reference to eextensions/browser/notification-types.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4771627
* chore: update references to renamed upstream field NativeWebKeyboardEvent.skip_if_unhandled (formerly known as skip_in_browser
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
Need a second pair of eyes on this commit. In particular the reference in content_converter.cc, skipInBrowser, seems to not be set or documented anywhere? Is this unused/vestigal code?
* chore: sync signature of ElectronExtensionsBrowserClient::IsValidContext() to upstream change
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4784198
* chore: add auto_pip_setting_helper.[cc,h] to chromium_src build
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4688277
Exiting upstream code used by chromium_src now depends on this new upstream class
* chore: bump chromium in DEPS to 118.0.5959.0
* chore: update add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
Xref: add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
manually adjust patch to minor upstream chagnes
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5961.0
* chore: bump chromium in DEPS to 118.0.5963.0
* chore: update patches
* 4780994: Rename various base files to "apple" since iOS uses them too
https://chromium-review.googlesource.com/c/chromium/src/+/4780994
* Many files moved from `mac` -> `apple`
This commit follows a handful of CLs that simply rename files/symbols to change `mac`
to `apple`
to signify their use across both macOS and iOS:
- 4784010: Move scoped_nsautorelease_pool to base/apple, leave a forwarding header
- 4790744: Move foundation_util to base/apple, leave a forwarding header
- 4790741: Move scoped_cftypreref to base/apple, leave a forwarding header
- 4787627: Move and rename macOS+iOS base/ files in PA to "apple"
- 4780399: Move OSStatus logging to base/apple
- 4787387: Remove forwarding headers
- 4781113: Rename message_pump_mac to "apple" because iOS uses it too
* fixup minor patch update error
A function param got dropped from this patch somewhere earlier
* chore: bump chromium in DEPS to 118.0.5965.2
* chore: update patches
* 4799213: Move ScopedTypeRef and ScopedCFTypeRef into base::apple::
https://chromium-review.googlesource.com/c/chromium/src/+/4799213
* Fix removed include to BrowserContext
In crrev.com/c/4767962 an include to BrowserContext was removed,
which was necessary for compilation. This broke only for us because
"chrome/browser/profiles/profile.h" includes that class, but we remove
all references to profiles.
* chore: bump chromium in DEPS to 118.0.5967.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5969.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5971.0
* chore: bump chromium in DEPS to 118.0.5973.0
* chore: update patches
* 4772121: [OOPIF PDF] Replace PDFWebContentsHelper with PDFDocumentHelper
https://chromium-review.googlesource.com/c/chromium/src/+/4772121
* 4811164: [Extensions] Do some cleanup in ChromeManagementAPIDelegate.
https://chromium-review.googlesource.com/c/chromium/src/+/4811164
* 4809488: Remove duplicate dnd functionality between Web and Renderer prefs
https://chromium-review.googlesource.com/c/chromium/src/+/4809488
Given that this is no longer an option of web preferences, we should
consider deprecating this option and then removing it.
* chore: bump chromium in DEPS to 118.0.5975.0
* chore: update patches
* fixup! chore: add auto_pip_settings_helper.{cc|h} to chromium_src build
* Reland "[windows] Remove RegKey::DeleteEmptyKey"
Refs https://chromium-review.googlesource.com/c/chromium/src/+/4813255
* Ensure StrCat means StrCat
Refs https://chromium-review.googlesource.com/c/chromium/src/+/1117180
* fixup! Remove RegKey::DeleteEmptyKey
* Consistently reject large p and large q in DH
Refs https://boringssl-review.googlesource.com/c/boringssl/+/62226
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: clavin <clavin@electronjs.org>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
2023-09-01 06:54:59 +00:00
|
|
|
[result addObject:base::apple::FilePathToNSURL(path)];
|
2020-10-20 01:33:06 +00:00
|
|
|
}
|
|
|
|
if (item.urls) {
|
|
|
|
for (const GURL& url : *item.urls)
|
|
|
|
[result addObject:net::NSURLWithGURL(url)];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-09-01 11:48:11 +00:00
|
|
|
} // namespace
|
2013-08-14 14:24:21 +00:00
|
|
|
|
2020-05-27 20:54:52 +00:00
|
|
|
// This class stores a base::WeakPtr<electron::ElectronMenuModel> as an
|
|
|
|
// Objective-C object, which allows it to be stored in the representedObject
|
|
|
|
// field of an NSMenuItem.
|
|
|
|
@interface WeakPtrToElectronMenuModelAsNSObject : NSObject
|
|
|
|
+ (instancetype)weakPtrForModel:(electron::ElectronMenuModel*)model;
|
|
|
|
+ (electron::ElectronMenuModel*)getFrom:(id)instance;
|
|
|
|
- (instancetype)initWithModel:(electron::ElectronMenuModel*)model;
|
|
|
|
- (electron::ElectronMenuModel*)menuModel;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation WeakPtrToElectronMenuModelAsNSObject {
|
|
|
|
base::WeakPtr<electron::ElectronMenuModel> _model;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (instancetype)weakPtrForModel:(electron::ElectronMenuModel*)model {
|
2023-07-18 22:26:27 +00:00
|
|
|
return [[WeakPtrToElectronMenuModelAsNSObject alloc] initWithModel:model];
|
2020-05-27 20:54:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (electron::ElectronMenuModel*)getFrom:(id)instance {
|
chore: bump chromium to 118.0.5975.0 (main) (#39531)
* chore: bump chromium in DEPS to 118.0.5951.0
* chore: update printing.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4727894
No logic changes, but patch needed to be manually re-applied due to upstream code shear
* chore: update port_autofill_colors_to_the_color_pipeline.patch
No manual changes; patch applied with fuzz
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5953.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5955.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5957.0
* chore: update patches
* chore: include path of native_web_keyboard_event.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
* chore: remove reference to eextensions/browser/notification-types.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4771627
* chore: update references to renamed upstream field NativeWebKeyboardEvent.skip_if_unhandled (formerly known as skip_in_browser
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
Need a second pair of eyes on this commit. In particular the reference in content_converter.cc, skipInBrowser, seems to not be set or documented anywhere? Is this unused/vestigal code?
* chore: sync signature of ElectronExtensionsBrowserClient::IsValidContext() to upstream change
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4784198
* chore: add auto_pip_setting_helper.[cc,h] to chromium_src build
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4688277
Exiting upstream code used by chromium_src now depends on this new upstream class
* chore: bump chromium in DEPS to 118.0.5959.0
* chore: update add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
Xref: add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
manually adjust patch to minor upstream chagnes
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5961.0
* chore: bump chromium in DEPS to 118.0.5963.0
* chore: update patches
* 4780994: Rename various base files to "apple" since iOS uses them too
https://chromium-review.googlesource.com/c/chromium/src/+/4780994
* Many files moved from `mac` -> `apple`
This commit follows a handful of CLs that simply rename files/symbols to change `mac`
to `apple`
to signify their use across both macOS and iOS:
- 4784010: Move scoped_nsautorelease_pool to base/apple, leave a forwarding header
- 4790744: Move foundation_util to base/apple, leave a forwarding header
- 4790741: Move scoped_cftypreref to base/apple, leave a forwarding header
- 4787627: Move and rename macOS+iOS base/ files in PA to "apple"
- 4780399: Move OSStatus logging to base/apple
- 4787387: Remove forwarding headers
- 4781113: Rename message_pump_mac to "apple" because iOS uses it too
* fixup minor patch update error
A function param got dropped from this patch somewhere earlier
* chore: bump chromium in DEPS to 118.0.5965.2
* chore: update patches
* 4799213: Move ScopedTypeRef and ScopedCFTypeRef into base::apple::
https://chromium-review.googlesource.com/c/chromium/src/+/4799213
* Fix removed include to BrowserContext
In crrev.com/c/4767962 an include to BrowserContext was removed,
which was necessary for compilation. This broke only for us because
"chrome/browser/profiles/profile.h" includes that class, but we remove
all references to profiles.
* chore: bump chromium in DEPS to 118.0.5967.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5969.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5971.0
* chore: bump chromium in DEPS to 118.0.5973.0
* chore: update patches
* 4772121: [OOPIF PDF] Replace PDFWebContentsHelper with PDFDocumentHelper
https://chromium-review.googlesource.com/c/chromium/src/+/4772121
* 4811164: [Extensions] Do some cleanup in ChromeManagementAPIDelegate.
https://chromium-review.googlesource.com/c/chromium/src/+/4811164
* 4809488: Remove duplicate dnd functionality between Web and Renderer prefs
https://chromium-review.googlesource.com/c/chromium/src/+/4809488
Given that this is no longer an option of web preferences, we should
consider deprecating this option and then removing it.
* chore: bump chromium in DEPS to 118.0.5975.0
* chore: update patches
* fixup! chore: add auto_pip_settings_helper.{cc|h} to chromium_src build
* Reland "[windows] Remove RegKey::DeleteEmptyKey"
Refs https://chromium-review.googlesource.com/c/chromium/src/+/4813255
* Ensure StrCat means StrCat
Refs https://chromium-review.googlesource.com/c/chromium/src/+/1117180
* fixup! Remove RegKey::DeleteEmptyKey
* Consistently reject large p and large q in DH
Refs https://boringssl-review.googlesource.com/c/boringssl/+/62226
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: clavin <clavin@electronjs.org>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
2023-09-01 06:54:59 +00:00
|
|
|
return [base::apple::ObjCCastStrict<WeakPtrToElectronMenuModelAsNSObject>(
|
|
|
|
instance) menuModel];
|
2020-05-27 20:54:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)initWithModel:(electron::ElectronMenuModel*)model {
|
|
|
|
if ((self = [super init])) {
|
|
|
|
_model = model->GetWeakPtr();
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (electron::ElectronMenuModel*)menuModel {
|
|
|
|
return _model.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2013-08-14 14:24:21 +00:00
|
|
|
@implementation ElectronMenuController
|
|
|
|
|
2020-05-27 20:54:52 +00:00
|
|
|
- (electron::ElectronMenuModel*)model {
|
|
|
|
return model_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setModel:(electron::ElectronMenuModel*)model {
|
|
|
|
model_ = model->GetWeakPtr();
|
|
|
|
}
|
2013-08-14 14:24:21 +00:00
|
|
|
|
2020-05-27 20:54:52 +00:00
|
|
|
- (instancetype)initWithModel:(electron::ElectronMenuModel*)model
|
|
|
|
useDefaultAccelerator:(BOOL)use {
|
2013-08-14 14:24:21 +00:00
|
|
|
if ((self = [super init])) {
|
2020-05-27 20:54:52 +00:00
|
|
|
model_ = model->GetWeakPtr();
|
2016-07-02 02:47:40 +00:00
|
|
|
isMenuOpen_ = NO;
|
|
|
|
useDefaultAccelerator_ = use;
|
2013-08-14 14:24:21 +00:00
|
|
|
[self menu];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
[menu_ setDelegate:nil];
|
|
|
|
|
|
|
|
// Close the menu if it is still open. This could happen if a tab gets closed
|
|
|
|
// while its context menu is still open.
|
|
|
|
[self cancel];
|
|
|
|
|
2020-05-27 20:54:52 +00:00
|
|
|
model_ = nullptr;
|
2013-08-14 14:24:21 +00:00
|
|
|
}
|
|
|
|
|
2019-11-20 11:17:39 +00:00
|
|
|
- (void)setCloseCallback:(base::OnceClosure)callback {
|
|
|
|
closeCallback = std::move(callback);
|
2017-02-16 18:58:02 +00:00
|
|
|
}
|
|
|
|
|
2016-07-02 02:47:40 +00:00
|
|
|
- (void)populateWithModel:(electron::ElectronMenuModel*)model {
|
2014-11-16 12:24:29 +00:00
|
|
|
if (!menu_)
|
|
|
|
return;
|
|
|
|
|
2019-10-03 05:25:14 +00:00
|
|
|
// Locate & retain the recent documents menu item
|
2017-11-21 00:15:43 +00:00
|
|
|
if (!recentDocumentsMenuItem_) {
|
2021-04-27 21:27:34 +00:00
|
|
|
std::u16string title = u"Open Recent";
|
2019-11-04 22:20:31 +00:00
|
|
|
NSString* openTitle = l10n_util::FixUpWindowsStyleLabel(title);
|
|
|
|
|
2023-07-18 22:26:27 +00:00
|
|
|
recentDocumentsMenuItem_ = [[[[NSApp mainMenu] itemWithTitle:@"Electron"]
|
|
|
|
submenu] itemWithTitle:openTitle];
|
2017-11-19 05:52:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 20:54:52 +00:00
|
|
|
model_ = model->GetWeakPtr();
|
2014-11-16 12:24:29 +00:00
|
|
|
[menu_ removeAllItems];
|
|
|
|
|
|
|
|
const int count = model->GetItemCount();
|
|
|
|
for (int index = 0; index < count; index++) {
|
2016-07-02 02:47:40 +00:00
|
|
|
if (model->GetTypeAt(index) == electron::ElectronMenuModel::TYPE_SEPARATOR)
|
2014-11-16 12:24:29 +00:00
|
|
|
[self addSeparatorToMenu:menu_ atIndex:index];
|
|
|
|
else
|
|
|
|
[self addItemToMenu:menu_ atIndex:index fromModel:model];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-14 14:24:21 +00:00
|
|
|
- (void)cancel {
|
|
|
|
if (isMenuOpen_) {
|
|
|
|
[menu_ cancelTracking];
|
|
|
|
isMenuOpen_ = NO;
|
2020-05-27 20:54:52 +00:00
|
|
|
if (model_)
|
|
|
|
model_->MenuWillClose();
|
2018-06-29 21:48:26 +00:00
|
|
|
if (!closeCallback.is_null()) {
|
2022-05-17 16:48:40 +00:00
|
|
|
content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE,
|
|
|
|
std::move(closeCallback));
|
2018-06-29 21:48:26 +00:00
|
|
|
}
|
2013-08-14 14:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a NSMenu from the given model. If the model has submenus, this can
|
|
|
|
// be invoked recursively.
|
2016-07-02 02:47:40 +00:00
|
|
|
- (NSMenu*)menuFromModel:(electron::ElectronMenuModel*)model {
|
2023-07-18 22:26:27 +00:00
|
|
|
NSMenu* menu = [[NSMenu alloc] initWithTitle:@""];
|
2013-08-14 14:24:21 +00:00
|
|
|
|
|
|
|
const int count = model->GetItemCount();
|
|
|
|
for (int index = 0; index < count; index++) {
|
2016-07-02 02:47:40 +00:00
|
|
|
if (model->GetTypeAt(index) == electron::ElectronMenuModel::TYPE_SEPARATOR)
|
2013-08-14 14:24:21 +00:00
|
|
|
[self addSeparatorToMenu:menu atIndex:index];
|
|
|
|
else
|
|
|
|
[self addItemToMenu:menu atIndex:index fromModel:model];
|
|
|
|
}
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adds a separator item at the given index. As the separator doesn't need
|
|
|
|
// anything from the model, this method doesn't need the model index as the
|
|
|
|
// other method below does.
|
2018-04-20 18:47:04 +00:00
|
|
|
- (void)addSeparatorToMenu:(NSMenu*)menu atIndex:(int)index {
|
2013-08-14 14:24:21 +00:00
|
|
|
NSMenuItem* separator = [NSMenuItem separatorItem];
|
|
|
|
[menu insertItem:separator atIndex:index];
|
|
|
|
}
|
|
|
|
|
2017-11-21 02:07:11 +00:00
|
|
|
// Empties the source menu items to the destination.
|
2018-04-20 18:47:04 +00:00
|
|
|
- (void)moveMenuItems:(NSMenu*)source to:(NSMenu*)destination {
|
2019-05-02 12:05:37 +00:00
|
|
|
const NSInteger count = [source numberOfItems];
|
|
|
|
for (NSInteger index = 0; index < count; index++) {
|
2023-07-18 22:26:27 +00:00
|
|
|
NSMenuItem* removedItem = [source itemAtIndex:0];
|
2017-11-21 00:15:43 +00:00
|
|
|
[source removeItemAtIndex:0];
|
|
|
|
[destination addItem:removedItem];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-21 02:07:11 +00:00
|
|
|
// Replaces the item's submenu instance with the singleton recent documents
|
|
|
|
// menu. Previously replaced menu items will be recovered.
|
2017-11-21 00:15:43 +00:00
|
|
|
- (void)replaceSubmenuShowingRecentDocuments:(NSMenuItem*)item {
|
2023-07-18 22:26:27 +00:00
|
|
|
NSMenu* recentDocumentsMenu = [recentDocumentsMenuItem_ submenu];
|
2017-11-21 00:15:43 +00:00
|
|
|
|
|
|
|
// Remove menu items in recent documents back to swap menu
|
2018-04-20 18:47:04 +00:00
|
|
|
[self moveMenuItems:recentDocumentsMenu to:recentDocumentsMenuSwap_];
|
2017-11-21 00:15:43 +00:00
|
|
|
// Swap back the submenu
|
2017-11-21 02:07:11 +00:00
|
|
|
[recentDocumentsMenuItem_ setSubmenu:recentDocumentsMenuSwap_];
|
2017-11-21 00:15:43 +00:00
|
|
|
|
|
|
|
// Retain the item's submenu for a future recovery
|
2023-07-18 22:26:27 +00:00
|
|
|
recentDocumentsMenuSwap_ = [item submenu];
|
2017-11-21 00:15:43 +00:00
|
|
|
|
|
|
|
// Repopulate with items from the submenu to be replaced
|
2018-04-20 18:47:04 +00:00
|
|
|
[self moveMenuItems:recentDocumentsMenuSwap_ to:recentDocumentsMenu];
|
2017-11-29 03:38:07 +00:00
|
|
|
// Update the submenu's title
|
|
|
|
[recentDocumentsMenu setTitle:[recentDocumentsMenuSwap_ title]];
|
2017-11-21 00:15:43 +00:00
|
|
|
// Replace submenu
|
|
|
|
[item setSubmenu:recentDocumentsMenu];
|
|
|
|
|
2019-10-03 05:25:14 +00:00
|
|
|
DCHECK_EQ([item action], @selector(submenuAction:));
|
|
|
|
DCHECK_EQ([item target], recentDocumentsMenu);
|
|
|
|
|
2017-11-21 00:15:43 +00:00
|
|
|
// Remember the new menu item that carries the recent documents menu
|
2023-07-18 22:26:27 +00:00
|
|
|
recentDocumentsMenuItem_ = item;
|
2017-11-21 00:15:43 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 01:33:06 +00:00
|
|
|
// Fill the menu with Share Menu items.
|
|
|
|
- (NSMenu*)createShareMenuForItem:(const SharingItem&)item {
|
|
|
|
NSArray* items = ConvertSharingItemToNS(item);
|
|
|
|
if ([items count] == 0)
|
|
|
|
return MakeEmptySubmenu();
|
2023-07-18 22:26:27 +00:00
|
|
|
NSMenu* menu = [[NSMenu alloc] init];
|
2020-10-20 01:33:06 +00:00
|
|
|
NSArray* services = [NSSharingService sharingServicesForItems:items];
|
|
|
|
for (NSSharingService* service in services)
|
|
|
|
[menu addItem:[self menuItemForService:service withItems:items]];
|
2023-07-18 22:26:27 +00:00
|
|
|
return menu;
|
2020-10-20 01:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a menu item that calls |service| when invoked.
|
|
|
|
- (NSMenuItem*)menuItemForService:(NSSharingService*)service
|
|
|
|
withItems:(NSArray*)items {
|
2023-07-18 22:26:27 +00:00
|
|
|
NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:service.menuItemTitle
|
|
|
|
action:@selector(performShare:)
|
|
|
|
keyEquivalent:@""];
|
2020-10-20 01:33:06 +00:00
|
|
|
[item setTarget:self];
|
|
|
|
[item setImage:service.image];
|
|
|
|
[item setRepresentedObject:@{@"service" : service, @"items" : items}];
|
2023-07-18 22:26:27 +00:00
|
|
|
return item;
|
2020-10-20 01:33:06 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 22:26:27 +00:00
|
|
|
- (NSMenuItem*)makeMenuItemForIndex:(NSInteger)index
|
|
|
|
fromModel:(electron::ElectronMenuModel*)model {
|
2021-03-16 16:18:45 +00:00
|
|
|
std::u16string label16 = model->GetLabelAt(index);
|
2013-08-14 14:24:21 +00:00
|
|
|
NSString* label = l10n_util::FixUpWindowsStyleLabel(label16);
|
2017-11-19 05:52:52 +00:00
|
|
|
|
2023-07-18 22:26:27 +00:00
|
|
|
NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:label
|
|
|
|
action:@selector(itemSelected:)
|
|
|
|
keyEquivalent:@""];
|
2013-08-14 14:24:21 +00:00
|
|
|
|
|
|
|
// If the menu item has an icon, set it.
|
2020-04-13 23:39:26 +00:00
|
|
|
ui::ImageModel icon = model->GetIconAt(index);
|
|
|
|
if (icon.IsImage())
|
|
|
|
[item setImage:icon.GetImage().ToNSImage()];
|
2013-08-14 14:24:21 +00:00
|
|
|
|
2021-03-16 16:18:45 +00:00
|
|
|
std::u16string toolTip = model->GetToolTipAt(index);
|
2019-07-11 08:56:22 +00:00
|
|
|
[item setToolTip:base::SysUTF16ToNSString(toolTip)];
|
|
|
|
|
2021-03-16 16:18:45 +00:00
|
|
|
std::u16string role = model->GetRoleAt(index);
|
2016-07-02 02:47:40 +00:00
|
|
|
electron::ElectronMenuModel::ItemType type = model->GetTypeAt(index);
|
2018-11-10 17:47:55 +00:00
|
|
|
|
2021-04-27 21:27:34 +00:00
|
|
|
if (role == u"services") {
|
|
|
|
std::u16string title = u"Services";
|
2022-10-03 20:21:00 +00:00
|
|
|
NSString* sub_label = l10n_util::FixUpWindowsStyleLabel(title);
|
2018-11-10 17:47:55 +00:00
|
|
|
|
|
|
|
[item setTarget:nil];
|
|
|
|
[item setAction:nil];
|
2023-07-18 22:26:27 +00:00
|
|
|
NSMenu* submenu = [[NSMenu alloc] initWithTitle:sub_label];
|
2018-11-10 17:47:55 +00:00
|
|
|
[item setSubmenu:submenu];
|
|
|
|
[NSApp setServicesMenu:submenu];
|
2021-04-27 21:27:34 +00:00
|
|
|
} else if (role == u"sharemenu") {
|
2020-10-20 01:33:06 +00:00
|
|
|
SharingItem sharing_item;
|
|
|
|
model->GetSharingItemAt(index, &sharing_item);
|
|
|
|
[item setTarget:nil];
|
|
|
|
[item setAction:nil];
|
|
|
|
[item setSubmenu:[self createShareMenuForItem:sharing_item]];
|
2019-02-08 20:54:39 +00:00
|
|
|
} else if (type == electron::ElectronMenuModel::TYPE_SUBMENU &&
|
|
|
|
model->IsVisibleAt(index)) {
|
2019-02-09 02:07:08 +00:00
|
|
|
// We need to specifically check that the submenu top-level item has been
|
|
|
|
// enabled as it's not validated by validateUserInterfaceItem
|
|
|
|
if (!model->IsEnabledAt(index))
|
|
|
|
[item setEnabled:NO];
|
|
|
|
|
2013-08-14 14:24:21 +00:00
|
|
|
// Recursively build a submenu from the sub-model at this index.
|
|
|
|
[item setTarget:nil];
|
|
|
|
[item setAction:nil];
|
2018-04-20 18:47:04 +00:00
|
|
|
electron::ElectronMenuModel* submenuModel =
|
|
|
|
static_cast<electron::ElectronMenuModel*>(
|
|
|
|
model->GetSubmenuModelAt(index));
|
2019-02-08 21:19:01 +00:00
|
|
|
NSMenu* submenu = MenuHasVisibleItems(submenuModel)
|
|
|
|
? [self menuFromModel:submenuModel]
|
|
|
|
: MakeEmptySubmenu();
|
2013-08-14 14:33:18 +00:00
|
|
|
[submenu setTitle:[item title]];
|
2013-08-14 14:24:21 +00:00
|
|
|
[item setSubmenu:submenu];
|
2013-08-14 14:33:18 +00:00
|
|
|
|
2015-09-01 11:48:11 +00:00
|
|
|
// Set submenu's role.
|
2021-04-27 21:27:34 +00:00
|
|
|
if ((role == u"window" || role == u"windowmenu") && [submenu numberOfItems])
|
2013-08-14 14:33:18 +00:00
|
|
|
[NSApp setWindowsMenu:submenu];
|
2021-04-27 21:27:34 +00:00
|
|
|
else if (role == u"help")
|
2013-10-17 02:15:57 +00:00
|
|
|
[NSApp setHelpMenu:submenu];
|
2021-04-27 21:27:34 +00:00
|
|
|
else if (role == u"recentdocuments")
|
2017-11-21 00:15:43 +00:00
|
|
|
[self replaceSubmenuShowingRecentDocuments:item];
|
2013-08-14 14:24:21 +00:00
|
|
|
} else {
|
|
|
|
// The MenuModel works on indexes so we can't just set the command id as the
|
|
|
|
// tag like we do in other menus. Also set the represented object to be
|
|
|
|
// the model so hierarchical menus check the correct index in the correct
|
|
|
|
// model. Setting the target to |self| allows this class to participate
|
|
|
|
// in validation of the menu items.
|
|
|
|
[item setTag:index];
|
2020-05-27 20:54:52 +00:00
|
|
|
[item setRepresentedObject:[WeakPtrToElectronMenuModelAsNSObject
|
|
|
|
weakPtrForModel:model]];
|
2013-08-14 14:24:21 +00:00
|
|
|
ui::Accelerator accelerator;
|
2018-04-20 18:47:04 +00:00
|
|
|
if (model->GetAcceleratorAtWithParams(index, useDefaultAccelerator_,
|
|
|
|
&accelerator)) {
|
2021-06-02 07:32:48 +00:00
|
|
|
// Note that we are not using Chromium's
|
|
|
|
// GetKeyEquivalentAndModifierMaskFromAccelerator API,
|
|
|
|
// because it will convert Shift+Character to ShiftedCharacter, for
|
|
|
|
// example Shift+/ would be converted to ?, which is against macOS HIG.
|
|
|
|
// See also https://github.com/electron/electron/issues/21790.
|
|
|
|
NSUInteger modifier_mask = 0;
|
|
|
|
if (accelerator.IsCtrlDown())
|
|
|
|
modifier_mask |= NSEventModifierFlagControl;
|
|
|
|
if (accelerator.IsAltDown())
|
|
|
|
modifier_mask |= NSEventModifierFlagOption;
|
|
|
|
if (accelerator.IsCmdDown())
|
|
|
|
modifier_mask |= NSEventModifierFlagCommand;
|
|
|
|
unichar character;
|
|
|
|
if (accelerator.shifted_char) {
|
|
|
|
// When a shifted char is explicitly specified, for example Ctrl+Plus,
|
|
|
|
// use the shifted char directly.
|
|
|
|
character = static_cast<unichar>(*accelerator.shifted_char);
|
|
|
|
} else {
|
|
|
|
// Otherwise use the unshifted combinations, for example Ctrl+Shift+=.
|
|
|
|
if (accelerator.IsShiftDown())
|
|
|
|
modifier_mask |= NSEventModifierFlagShift;
|
|
|
|
ui::MacKeyCodeForWindowsKeyCode(accelerator.key_code(), modifier_mask,
|
|
|
|
nullptr, &character);
|
|
|
|
}
|
|
|
|
[item setKeyEquivalent:[NSString stringWithFormat:@"%C", character]];
|
2018-10-02 22:22:48 +00:00
|
|
|
[item setKeyEquivalentModifierMask:modifier_mask];
|
2013-08-14 14:24:21 +00:00
|
|
|
}
|
2015-09-01 11:48:11 +00:00
|
|
|
|
2022-06-02 18:43:40 +00:00
|
|
|
[(id)item
|
|
|
|
setAllowsKeyEquivalentWhenHidden:(model->WorksWhenHiddenAt(index))];
|
2019-02-28 17:00:54 +00:00
|
|
|
|
2015-09-01 11:48:11 +00:00
|
|
|
// Set menu item's role.
|
2016-08-08 17:09:45 +00:00
|
|
|
[item setTarget:self];
|
|
|
|
if (!role.empty()) {
|
2015-09-01 11:48:11 +00:00
|
|
|
for (const Role& pair : kRolesMap) {
|
|
|
|
if (role == base::ASCIIToUTF16(pair.role)) {
|
2016-08-08 17:09:45 +00:00
|
|
|
[item setTarget:nil];
|
2015-09-01 11:48:11 +00:00
|
|
|
[item setAction:pair.selector];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-14 14:24:21 +00:00
|
|
|
}
|
2021-06-29 23:28:16 +00:00
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adds an item or a hierarchical menu to the item at the |index|,
|
|
|
|
// associated with the entry in the model identified by |modelIndex|.
|
|
|
|
- (void)addItemToMenu:(NSMenu*)menu
|
|
|
|
atIndex:(NSInteger)index
|
|
|
|
fromModel:(electron::ElectronMenuModel*)model {
|
|
|
|
[menu insertItem:[self makeMenuItemForIndex:index fromModel:model]
|
|
|
|
atIndex:index];
|
2013-08-14 14:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Called before the menu is to be displayed to update the state (enabled,
|
2019-02-28 17:00:54 +00:00
|
|
|
// radio, etc) of each item in the menu.
|
2013-08-14 14:24:21 +00:00
|
|
|
- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
|
|
|
|
SEL action = [item action];
|
2020-10-20 01:33:06 +00:00
|
|
|
if (action == @selector(performShare:))
|
|
|
|
return YES;
|
2013-08-14 14:24:21 +00:00
|
|
|
if (action != @selector(itemSelected:))
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
NSInteger modelIndex = [item tag];
|
2020-05-27 20:54:52 +00:00
|
|
|
electron::ElectronMenuModel* model = [WeakPtrToElectronMenuModelAsNSObject
|
|
|
|
getFrom:[(id)item representedObject]];
|
2013-08-14 14:24:21 +00:00
|
|
|
DCHECK(model);
|
|
|
|
if (model) {
|
|
|
|
BOOL checked = model->IsItemCheckedAt(modelIndex);
|
|
|
|
DCHECK([(id)item isKindOfClass:[NSMenuItem class]]);
|
2018-10-03 07:24:28 +00:00
|
|
|
|
2023-07-01 20:22:55 +00:00
|
|
|
[(id)item
|
|
|
|
setState:(checked ? NSControlStateValueOn : NSControlStateValueOff)];
|
2013-08-14 14:24:21 +00:00
|
|
|
[(id)item setHidden:(!model->IsVisibleAt(modelIndex))];
|
2018-10-03 07:24:28 +00:00
|
|
|
|
2013-08-14 14:24:21 +00:00
|
|
|
return model->IsEnabledAt(modelIndex);
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called when the user chooses a particular menu item. |sender| is the menu
|
|
|
|
// item chosen.
|
|
|
|
- (void)itemSelected:(id)sender {
|
|
|
|
NSInteger modelIndex = [sender tag];
|
2018-04-20 18:47:04 +00:00
|
|
|
electron::ElectronMenuModel* model =
|
2020-05-27 20:54:52 +00:00
|
|
|
[WeakPtrToElectronMenuModelAsNSObject getFrom:[sender representedObject]];
|
2013-08-14 14:24:21 +00:00
|
|
|
DCHECK(model);
|
|
|
|
if (model) {
|
2015-07-29 04:01:27 +00:00
|
|
|
NSEvent* event = [NSApp currentEvent];
|
2019-07-11 08:56:22 +00:00
|
|
|
model->ActivatedAt(modelIndex, ui::EventFlagsFromNSEventWithModifiers(
|
|
|
|
event, [event modifierFlags]));
|
2013-08-14 14:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-20 01:33:06 +00:00
|
|
|
// Performs the share action using the sharing service represented by |sender|.
|
|
|
|
- (void)performShare:(NSMenuItem*)sender {
|
|
|
|
NSDictionary* object =
|
chore: bump chromium to 118.0.5975.0 (main) (#39531)
* chore: bump chromium in DEPS to 118.0.5951.0
* chore: update printing.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4727894
No logic changes, but patch needed to be manually re-applied due to upstream code shear
* chore: update port_autofill_colors_to_the_color_pipeline.patch
No manual changes; patch applied with fuzz
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5953.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5955.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5957.0
* chore: update patches
* chore: include path of native_web_keyboard_event.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
* chore: remove reference to eextensions/browser/notification-types.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4771627
* chore: update references to renamed upstream field NativeWebKeyboardEvent.skip_if_unhandled (formerly known as skip_in_browser
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
Need a second pair of eyes on this commit. In particular the reference in content_converter.cc, skipInBrowser, seems to not be set or documented anywhere? Is this unused/vestigal code?
* chore: sync signature of ElectronExtensionsBrowserClient::IsValidContext() to upstream change
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4784198
* chore: add auto_pip_setting_helper.[cc,h] to chromium_src build
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4688277
Exiting upstream code used by chromium_src now depends on this new upstream class
* chore: bump chromium in DEPS to 118.0.5959.0
* chore: update add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
Xref: add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
manually adjust patch to minor upstream chagnes
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5961.0
* chore: bump chromium in DEPS to 118.0.5963.0
* chore: update patches
* 4780994: Rename various base files to "apple" since iOS uses them too
https://chromium-review.googlesource.com/c/chromium/src/+/4780994
* Many files moved from `mac` -> `apple`
This commit follows a handful of CLs that simply rename files/symbols to change `mac`
to `apple`
to signify their use across both macOS and iOS:
- 4784010: Move scoped_nsautorelease_pool to base/apple, leave a forwarding header
- 4790744: Move foundation_util to base/apple, leave a forwarding header
- 4790741: Move scoped_cftypreref to base/apple, leave a forwarding header
- 4787627: Move and rename macOS+iOS base/ files in PA to "apple"
- 4780399: Move OSStatus logging to base/apple
- 4787387: Remove forwarding headers
- 4781113: Rename message_pump_mac to "apple" because iOS uses it too
* fixup minor patch update error
A function param got dropped from this patch somewhere earlier
* chore: bump chromium in DEPS to 118.0.5965.2
* chore: update patches
* 4799213: Move ScopedTypeRef and ScopedCFTypeRef into base::apple::
https://chromium-review.googlesource.com/c/chromium/src/+/4799213
* Fix removed include to BrowserContext
In crrev.com/c/4767962 an include to BrowserContext was removed,
which was necessary for compilation. This broke only for us because
"chrome/browser/profiles/profile.h" includes that class, but we remove
all references to profiles.
* chore: bump chromium in DEPS to 118.0.5967.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5969.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5971.0
* chore: bump chromium in DEPS to 118.0.5973.0
* chore: update patches
* 4772121: [OOPIF PDF] Replace PDFWebContentsHelper with PDFDocumentHelper
https://chromium-review.googlesource.com/c/chromium/src/+/4772121
* 4811164: [Extensions] Do some cleanup in ChromeManagementAPIDelegate.
https://chromium-review.googlesource.com/c/chromium/src/+/4811164
* 4809488: Remove duplicate dnd functionality between Web and Renderer prefs
https://chromium-review.googlesource.com/c/chromium/src/+/4809488
Given that this is no longer an option of web preferences, we should
consider deprecating this option and then removing it.
* chore: bump chromium in DEPS to 118.0.5975.0
* chore: update patches
* fixup! chore: add auto_pip_settings_helper.{cc|h} to chromium_src build
* Reland "[windows] Remove RegKey::DeleteEmptyKey"
Refs https://chromium-review.googlesource.com/c/chromium/src/+/4813255
* Ensure StrCat means StrCat
Refs https://chromium-review.googlesource.com/c/chromium/src/+/1117180
* fixup! Remove RegKey::DeleteEmptyKey
* Consistently reject large p and large q in DH
Refs https://boringssl-review.googlesource.com/c/boringssl/+/62226
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: clavin <clavin@electronjs.org>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
2023-09-01 06:54:59 +00:00
|
|
|
base::apple::ObjCCastStrict<NSDictionary>([sender representedObject]);
|
2020-10-20 01:33:06 +00:00
|
|
|
NSSharingService* service =
|
chore: bump chromium to 118.0.5975.0 (main) (#39531)
* chore: bump chromium in DEPS to 118.0.5951.0
* chore: update printing.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4727894
No logic changes, but patch needed to be manually re-applied due to upstream code shear
* chore: update port_autofill_colors_to_the_color_pipeline.patch
No manual changes; patch applied with fuzz
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5953.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5955.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5957.0
* chore: update patches
* chore: include path of native_web_keyboard_event.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
* chore: remove reference to eextensions/browser/notification-types.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4771627
* chore: update references to renamed upstream field NativeWebKeyboardEvent.skip_if_unhandled (formerly known as skip_in_browser
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
Need a second pair of eyes on this commit. In particular the reference in content_converter.cc, skipInBrowser, seems to not be set or documented anywhere? Is this unused/vestigal code?
* chore: sync signature of ElectronExtensionsBrowserClient::IsValidContext() to upstream change
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4784198
* chore: add auto_pip_setting_helper.[cc,h] to chromium_src build
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4688277
Exiting upstream code used by chromium_src now depends on this new upstream class
* chore: bump chromium in DEPS to 118.0.5959.0
* chore: update add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
Xref: add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
manually adjust patch to minor upstream chagnes
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5961.0
* chore: bump chromium in DEPS to 118.0.5963.0
* chore: update patches
* 4780994: Rename various base files to "apple" since iOS uses them too
https://chromium-review.googlesource.com/c/chromium/src/+/4780994
* Many files moved from `mac` -> `apple`
This commit follows a handful of CLs that simply rename files/symbols to change `mac`
to `apple`
to signify their use across both macOS and iOS:
- 4784010: Move scoped_nsautorelease_pool to base/apple, leave a forwarding header
- 4790744: Move foundation_util to base/apple, leave a forwarding header
- 4790741: Move scoped_cftypreref to base/apple, leave a forwarding header
- 4787627: Move and rename macOS+iOS base/ files in PA to "apple"
- 4780399: Move OSStatus logging to base/apple
- 4787387: Remove forwarding headers
- 4781113: Rename message_pump_mac to "apple" because iOS uses it too
* fixup minor patch update error
A function param got dropped from this patch somewhere earlier
* chore: bump chromium in DEPS to 118.0.5965.2
* chore: update patches
* 4799213: Move ScopedTypeRef and ScopedCFTypeRef into base::apple::
https://chromium-review.googlesource.com/c/chromium/src/+/4799213
* Fix removed include to BrowserContext
In crrev.com/c/4767962 an include to BrowserContext was removed,
which was necessary for compilation. This broke only for us because
"chrome/browser/profiles/profile.h" includes that class, but we remove
all references to profiles.
* chore: bump chromium in DEPS to 118.0.5967.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5969.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5971.0
* chore: bump chromium in DEPS to 118.0.5973.0
* chore: update patches
* 4772121: [OOPIF PDF] Replace PDFWebContentsHelper with PDFDocumentHelper
https://chromium-review.googlesource.com/c/chromium/src/+/4772121
* 4811164: [Extensions] Do some cleanup in ChromeManagementAPIDelegate.
https://chromium-review.googlesource.com/c/chromium/src/+/4811164
* 4809488: Remove duplicate dnd functionality between Web and Renderer prefs
https://chromium-review.googlesource.com/c/chromium/src/+/4809488
Given that this is no longer an option of web preferences, we should
consider deprecating this option and then removing it.
* chore: bump chromium in DEPS to 118.0.5975.0
* chore: update patches
* fixup! chore: add auto_pip_settings_helper.{cc|h} to chromium_src build
* Reland "[windows] Remove RegKey::DeleteEmptyKey"
Refs https://chromium-review.googlesource.com/c/chromium/src/+/4813255
* Ensure StrCat means StrCat
Refs https://chromium-review.googlesource.com/c/chromium/src/+/1117180
* fixup! Remove RegKey::DeleteEmptyKey
* Consistently reject large p and large q in DH
Refs https://boringssl-review.googlesource.com/c/boringssl/+/62226
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: clavin <clavin@electronjs.org>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
2023-09-01 06:54:59 +00:00
|
|
|
base::apple::ObjCCastStrict<NSSharingService>(object[@"service"]);
|
|
|
|
NSArray* items = base::apple::ObjCCastStrict<NSArray>(object[@"items"]);
|
2020-10-20 01:33:06 +00:00
|
|
|
[service setDelegate:self];
|
|
|
|
[service performWithItems:items];
|
|
|
|
}
|
|
|
|
|
2013-08-14 14:24:21 +00:00
|
|
|
- (NSMenu*)menu {
|
2014-11-16 13:06:16 +00:00
|
|
|
if (menu_)
|
2023-07-18 22:26:27 +00:00
|
|
|
return menu_;
|
2014-11-16 13:06:16 +00:00
|
|
|
|
2020-10-20 01:33:06 +00:00
|
|
|
if (model_ && model_->GetSharingItem()) {
|
|
|
|
NSMenu* menu = [self createShareMenuForItem:*model_->GetSharingItem()];
|
2023-07-18 22:26:27 +00:00
|
|
|
menu_ = menu;
|
2020-10-20 01:33:06 +00:00
|
|
|
} else {
|
2023-07-18 22:26:27 +00:00
|
|
|
menu_ = [[NSMenu alloc] initWithTitle:@""];
|
2020-10-20 01:33:06 +00:00
|
|
|
if (model_)
|
|
|
|
[self populateWithModel:model_.get()];
|
|
|
|
}
|
2014-11-16 13:06:16 +00:00
|
|
|
[menu_ setDelegate:self];
|
2023-07-18 22:26:27 +00:00
|
|
|
return menu_;
|
2013-08-14 14:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isMenuOpen {
|
|
|
|
return isMenuOpen_;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)menuWillOpen:(NSMenu*)menu {
|
|
|
|
isMenuOpen_ = YES;
|
2020-05-27 20:54:52 +00:00
|
|
|
if (model_)
|
|
|
|
model_->MenuWillShow();
|
2013-08-14 14:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)menuDidClose:(NSMenu*)menu {
|
|
|
|
if (isMenuOpen_) {
|
|
|
|
isMenuOpen_ = NO;
|
2019-09-04 20:42:23 +00:00
|
|
|
if (model_)
|
|
|
|
model_->MenuWillClose();
|
2018-04-20 18:47:04 +00:00
|
|
|
// Post async task so that itemSelected runs before the close callback
|
|
|
|
// deletes the controller from the map which deallocates it
|
2018-02-25 22:19:40 +00:00
|
|
|
if (!closeCallback.is_null()) {
|
2022-05-17 16:48:40 +00:00
|
|
|
content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE,
|
|
|
|
std::move(closeCallback));
|
2018-02-25 22:19:40 +00:00
|
|
|
}
|
2013-08-14 14:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-20 01:33:06 +00:00
|
|
|
// NSSharingServiceDelegate
|
|
|
|
|
|
|
|
- (NSWindow*)sharingService:(NSSharingService*)service
|
|
|
|
sourceWindowForShareItems:(NSArray*)items
|
|
|
|
sharingContentScope:(NSSharingContentScope*)scope {
|
|
|
|
// Return the current active window.
|
|
|
|
const auto& list = electron::WindowList::GetWindows();
|
|
|
|
for (electron::NativeWindow* window : list) {
|
|
|
|
if (window->IsFocused())
|
|
|
|
return window->GetNativeWindow().GetNativeNSWindow();
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2013-08-14 14:24:21 +00:00
|
|
|
@end
|