Skip to content

Commit

Permalink
[iOS]: Add new function to return elements to add to context_menu
Browse files Browse the repository at this point in the history
New function to return the contextMenu title and the list of elements to
add.

Bug: 1336264
Change-Id: Id81a143dedd0861bd557500e349e06b2b15a1117
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3721638
Reviewed-by: Rohit Rao <[email protected]>
Commit-Queue: Elmehdi Rahmaoui <[email protected]>
Reviewed-by: David Jean <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1018612}
  • Loading branch information
Elmehdi Rahmaoui authored and Chromium LUCI CQ committed Jun 28, 2022
1 parent 497021c commit 3bd8f05
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ bool AddContextMenuElements(NSMutableArray<UIMenuElement*>* menu_elements,
ChromeBrowserState* browser_state,
web::WebState* web_state,
web::ContextMenuParams params,
UIViewController* presentingViewController) {
UIViewController* presenting_view_controller) {
// Chromium does not add elements to the context menu.
return false;
}

ElementsToAddToContextMenu* GetContextMenuElementsToAdd(
ChromeBrowserState* browser_state,
web::WebState* web_state,
web::ContextMenuParams params,
UIViewController* presenting_view_controller) {
return nil;
}

} // namespace provider
} // namespace ios
9 changes: 8 additions & 1 deletion ios/chrome/test/providers/context_menu/test_context_menu.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ bool AddContextMenuElements(NSMutableArray<UIMenuElement*>* menu_elements,
ChromeBrowserState* browser_state,
web::WebState* web_state,
web::ContextMenuParams params,
UIViewController* presentingViewController) {
UIViewController* presenting_view_controller) {
// No context menu elements added for tests.
return false;
}

ElementsToAddToContextMenu* GetContextMenuElementsToAdd(
ChromeBrowserState* browser_state,
web::WebState* web_state,
web::ContextMenuParams params,
UIViewController* presenting_view_controller) {
return nil;
}
} // namespace provider
} // namespace ios
6 changes: 5 additions & 1 deletion ios/public/provider/chrome/browser/context_menu/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

source_set("context_menu_api") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [ "context_menu_api.h" ]
sources = [
"context_menu_api.h",
"context_menu_api.mm",
]

deps = [ "//ios/web/public/ui" ]
frameworks = [ "UIKit.framework" ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@

class ChromeBrowserState;

// Wraps information to add/show to/in a context menu
@interface ElementsToAddToContextMenu : NSObject

// The title of the context menu. Can be nil.
@property(nonatomic, copy) NSString* title;

// List of elements to add to a context menu. Can be nil.
@property(nonatomic, copy) NSMutableArray<UIMenuElement*>* elements;

@end

namespace web {
class WebState;
} // namespace web
Expand All @@ -24,7 +35,15 @@ bool AddContextMenuElements(NSMutableArray<UIMenuElement*>* menu_elements,
ChromeBrowserState* browser_state,
web::WebState* web_state,
web::ContextMenuParams params,
UIViewController* presentingViewController);
UIViewController* presenting_view_controller);

// Returns the elements to add to the context menu, with their title. If no
// elements needs to be added, returns nil.
ElementsToAddToContextMenu* GetContextMenuElementsToAdd(
ChromeBrowserState* browser_state,
web::WebState* web_state,
web::ContextMenuParams params,
UIViewController* presenting_view_controller);

} // namespace provider
} // namespace ios
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/public/provider/chrome/browser/context_menu/context_menu_api.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif

@implementation ElementsToAddToContextMenu
@end

0 comments on commit 3bd8f05

Please sign in to comment.