Commit dc2dbcbd authored by Mike Dougherty's avatar Mike Dougherty Committed by Commit Bot

Enable post message context menu and remove flag.

This fully enables support for context menu in iFrames.

Bug: 873660, 873662
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I3345f56f6812ef619c6ed5b7bcabd34e09de410f
Reviewed-on: https://chromium-review.googlesource.com/1174052
Commit-Queue: Mike Dougherty <michaeldo@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583053}
parent 7755fb6c
...@@ -274,11 +274,6 @@ const flags_ui::FeatureEntry kFeatureEntries[] = { ...@@ -274,11 +274,6 @@ const flags_ui::FeatureEntry kFeatureEntries[] = {
{"infobars-ui-reboot", flag_descriptions::kInfobarsUIRebootName, {"infobars-ui-reboot", flag_descriptions::kInfobarsUIRebootName,
flag_descriptions::kInfobarsUIRebootDescription, flags_ui::kOsIos, flag_descriptions::kInfobarsUIRebootDescription, flags_ui::kOsIos,
FEATURE_VALUE_TYPE(kInfobarsUIReboot)}, FEATURE_VALUE_TYPE(kInfobarsUIReboot)},
{"context-menu-element-post-message",
flag_descriptions::kContextMenuElementPostMessageName,
flag_descriptions::kContextMenuElementPostMessageDescription,
flags_ui::kOsIos,
FEATURE_VALUE_TYPE(web::features::kContextMenuElementPostMessage)},
{"mailto-handling-google-ui", {"mailto-handling-google-ui",
flag_descriptions::kMailtoHandlingWithGoogleUIName, flag_descriptions::kMailtoHandlingWithGoogleUIName,
flag_descriptions::kMailtoHandlingWithGoogleUIDescription, flag_descriptions::kMailtoHandlingWithGoogleUIDescription,
......
...@@ -125,13 +125,6 @@ const char kContextualSearch[] = "Contextual Search"; ...@@ -125,13 +125,6 @@ const char kContextualSearch[] = "Contextual Search";
const char kContextualSearchDescription[] = const char kContextualSearchDescription[] =
"Whether or not Contextual Search is enabled."; "Whether or not Contextual Search is enabled.";
const char kContextMenuElementPostMessageName[] =
"Context Menu Element Post Message";
const char kContextMenuElementPostMessageDescription[] =
"When enabled, the DOM element for the Context Menu is returned using a "
"webkit postMessage call instead of directly returned from the JavaScript "
"function.";
const char kCopyImageName[] = "Copy Image"; const char kCopyImageName[] = "Copy Image";
const char kCopyImageDescription[] = const char kCopyImageDescription[] =
"Enable copying image to system pasteboard via context menu."; "Enable copying image to system pasteboard via context menu.";
......
...@@ -100,11 +100,6 @@ extern const char kCaptivePortalMetricsDescription[]; ...@@ -100,11 +100,6 @@ extern const char kCaptivePortalMetricsDescription[];
extern const char kContextualSearch[]; extern const char kContextualSearch[];
extern const char kContextualSearchDescription[]; extern const char kContextualSearchDescription[];
// Title and description for the flag to enable returning the DOM element for
// context menu using webkit postMessage API.
extern const char kContextMenuElementPostMessageName[];
extern const char kContextMenuElementPostMessageDescription[];
// Title and description for the flag to enable copying image. // Title and description for the flag to enable copying image.
extern const char kCopyImageName[]; extern const char kCopyImageName[];
extern const char kCopyImageDescription[]; extern const char kCopyImageDescription[];
......
...@@ -7,9 +7,6 @@ ...@@ -7,9 +7,6 @@
namespace web { namespace web {
namespace features { namespace features {
const base::Feature kContextMenuElementPostMessage{
"ContextMenuElementPostMessage", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kWebFrameMessaging{"WebFrameMessaging", const base::Feature kWebFrameMessaging{"WebFrameMessaging",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_DISABLED_BY_DEFAULT};
......
...@@ -10,9 +10,6 @@ ...@@ -10,9 +10,6 @@
namespace web { namespace web {
namespace features { namespace features {
// Used to enable asynchronous DOM element fetching for context menu.
extern const base::Feature kContextMenuElementPostMessage;
// Used to enable API to send messages directly to frames of a webpage. // Used to enable API to send messages directly to frames of a webpage.
extern const base::Feature kWebFrameMessaging; extern const base::Feature kWebFrameMessaging;
......
...@@ -7,15 +7,15 @@ ...@@ -7,15 +7,15 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
// Contains keys present in dictionary returned by __gCrWeb.getElementFromPoint // Contains keys present in dictionary created by __gCrWeb.findElementAtPoint
// and __gCrWeb.findElementAtPoint JS APIs. // to represent the DOM element.
namespace web { namespace web {
// Required in findElementAtPoint response. (Not used by getElementFromPoint.) // Required key. Represents a unique string request ID that is passed through
// Represents a unique string request ID that is passed through directly from a // directly from a call to findElementAtPoint to the response dictionary. The
// call to findElementAtPoint to the response dictionary. The request ID should // request ID should be used to correlate a response with a previous call to
// be used to correlate a response with a previous call to findElementAtPoint. // findElementAtPoint.
extern NSString* const kContextMenuElementRequestId; extern NSString* const kContextMenuElementRequestId;
// Optional key. Represents element's href attribute if present or parent's href // Optional key. Represents element's href attribute if present or parent's href
......
...@@ -14,59 +14,6 @@ goog.require('__crWeb.common'); ...@@ -14,59 +14,6 @@ goog.require('__crWeb.common');
/** Beginning of anonymous object */ /** Beginning of anonymous object */
(function() { (function() {
/**
* Returns an object representing the details of the given element.
* @param {number} x Horizontal center of the selected point in page
* coordinates.
* @param {number} y Vertical center of the selected point in page
* coordinates.
* @return {Object} An object of the same form as returned by
* {@code getResponseForLinkElement} or
* {@code getResponseForImageElement} or null if no element was
* found.
*/
__gCrWeb['getElementFromPointInPageCoordinates'] = function(x, y) {
var hitCoordinates = spiralCoordinates_(x, y);
for (var index = 0; index < hitCoordinates.length; index++) {
var coordinates = hitCoordinates[index];
var coordinateDetails = newCoordinate(coordinates.x, coordinates.y);
var element = elementsFromCoordinates(coordinateDetails);
if (!element || !element.tagName) {
// Nothing under the hit point. Try the next hit point.
continue;
}
// Also check element's ancestors. A bound on the level is used here to
// avoid large overhead when no links or images are found.
var level = 0;
while (++level < 8 && element && element != document) {
var tagName = element.tagName;
if (!tagName) continue;
tagName = tagName.toLowerCase();
if (tagName === 'input' || tagName === 'textarea' ||
tagName === 'select' || tagName === 'option') {
// If the element is a known input element, stop the spiral search and
// return empty results.
return {};
}
if (getComputedWebkitTouchCallout_(element) !== 'none') {
if (tagName === 'a' && element.href) {
return getResponseForLinkElement(element);
}
if (tagName === 'img' && element.src) {
return getResponseForImageElement(element);
}
}
element = element.parentNode;
}
}
return {};
};
/** /**
* Returns an object representing the details of a given link element. * Returns an object representing the details of a given link element.
* @param {HTMLElement} element The element whose details will be returned. * @param {HTMLElement} element The element whose details will be returned.
......
...@@ -18,7 +18,7 @@ goog.provide('__crWeb.mainFrameContextMenu'); ...@@ -18,7 +18,7 @@ goog.provide('__crWeb.mainFrameContextMenu');
* found element (or an empty object if no links or images are found) back to * found element (or an empty object if no links or images are found) back to
* the application by posting a 'FindElementResultHandler' message. * the application by posting a 'FindElementResultHandler' message.
* The object returned in the message is of the same form as * The object returned in the message is of the same form as
* {@code getElementFromPointInPageCoordinates} result. * {@code findElementAtPointInPageCoordinates} result.
* @param {string} requestId An identifier which be returned in the result * @param {string} requestId An identifier which be returned in the result
* dictionary of this request. * dictionary of this request.
* @param {number} x Horizontal center of the selected point in web view * @param {number} x Horizontal center of the selected point in web view
...@@ -36,23 +36,6 @@ __gCrWeb['findElementAtPoint'] = ...@@ -36,23 +36,6 @@ __gCrWeb['findElementAtPoint'] =
y * scale); y * scale);
}; };
/**
* Returns the url of the image or link under the selected point. Returns an
* empty object if no links or images are found.
* @param {number} x Horizontal center of the selected point in web view
* coordinates.
* @param {number} y Vertical center of the selected point in web view
* coordinates.
* @param {number} webViewWidth the width of web view.
* @param {number} webViewHeight the height of web view.
* @return {!Object} An object in the same form as
* {@code getElementFromPointInPageCoordinates} result.
*/
__gCrWeb['getElementFromPoint'] = function(x, y, webViewWidth, webViewHeight) {
var scale = getPageWidth() / webViewWidth;
return __gCrWeb.getElementFromPointInPageCoordinates(x * scale, y * scale);
};
/** /**
* Suppresses the next click such that they are not handled by JS click * Suppresses the next click such that they are not handled by JS click
* event handlers. * event handlers.
......
...@@ -178,10 +178,6 @@ struct ContextMenuInfo { ...@@ -178,10 +178,6 @@ struct ContextMenuInfo {
_delegate = delegate; _delegate = delegate;
_injectionEvaluator = injectionEvaluator; _injectionEvaluator = injectionEvaluator;
_pendingElementFetchRequests = [[NSMutableDictionary alloc] init]; _pendingElementFetchRequests = [[NSMutableDictionary alloc] init];
// Default to assuming all elements are from the main frame since this value
// will not be updated unless the
// |web::features::kContextMenuElementPostMessage| feature is enabled.
_contextMenuInfoForLastTouch.is_main_frame = YES;
// The system context menu triggers after 0.55 second. Add a gesture // The system context menu triggers after 0.55 second. Add a gesture
// recognizer with a shorter delay to be able to cancel the system menu if // recognizer with a shorter delay to be able to cancel the system menu if
...@@ -219,20 +215,17 @@ struct ContextMenuInfo { ...@@ -219,20 +215,17 @@ struct ContextMenuInfo {
} }
} }
if (base::FeatureList::IsEnabled( // Listen for fetched element response.
web::features::kContextMenuElementPostMessage)) { web::WKWebViewConfigurationProvider& configurationProvider =
// Listen for fetched element response. web::WKWebViewConfigurationProvider::FromBrowserState(browserState);
web::WKWebViewConfigurationProvider& configurationProvider = CRWWKScriptMessageRouter* messageRouter =
web::WKWebViewConfigurationProvider::FromBrowserState(browserState); configurationProvider.GetScriptMessageRouter();
CRWWKScriptMessageRouter* messageRouter = __weak CRWContextMenuController* weakSelf = self;
configurationProvider.GetScriptMessageRouter(); [messageRouter setScriptMessageHandler:^(WKScriptMessage* message) {
__weak CRWContextMenuController* weakSelf = self; [weakSelf didReceiveScriptMessage:message];
[messageRouter setScriptMessageHandler:^(WKScriptMessage* message) {
[weakSelf didReceiveScriptMessage:message];
}
name:kFindElementResultHandlerName
webView:webView];
} }
name:kFindElementResultHandlerName
webView:webView];
} }
return self; return self;
} }
...@@ -492,41 +485,20 @@ struct ContextMenuInfo { ...@@ -492,41 +485,20 @@ struct ContextMenuInfo {
CGFloat webViewContentWidth = webViewContentSize.width; CGFloat webViewContentWidth = webViewContentSize.width;
CGFloat webViewContentHeight = webViewContentSize.height; CGFloat webViewContentHeight = webViewContentSize.height;
NSString* formatString; NSString* requestID =
web::JavaScriptResultBlock completionHandler = nil; base::SysUTF8ToNSString(base::UnguessableToken::Create().ToString());
if (base::FeatureList::IsEnabled( HTMLElementFetchRequest* fetchRequest =
web::features::kContextMenuElementPostMessage)) { [[HTMLElementFetchRequest alloc] initWithFoundElementHandler:handler];
NSString* requestID = _pendingElementFetchRequests[requestID] = fetchRequest;
base::SysUTF8ToNSString(base::UnguessableToken::Create().ToString()); NSString* formatString = [NSString
HTMLElementFetchRequest* fetchRequest = stringWithFormat:
[[HTMLElementFetchRequest alloc] initWithFoundElementHandler:handler]; @"__gCrWeb.findElementAtPoint('%@', %%g, %%g, %%g, %%g);", requestID];
_pendingElementFetchRequests[requestID] = fetchRequest;
formatString =
[NSString stringWithFormat:
@"__gCrWeb.findElementAtPoint('%@', %%g, %%g, %%g, %%g);",
requestID];
} else {
formatString = @"__gCrWeb.getElementFromPoint(%g, %g, %g, %g);";
base::TimeTicks getElementStartTime = base::TimeTicks::Now();
__weak CRWContextMenuController* weakSelf = self;
completionHandler = ^(id element, NSError* error) {
[weakSelf logElementFetchDurationWithStartTime:getElementStartTime];
if (error.code == WKErrorWebContentProcessTerminated ||
error.code == WKErrorWebViewInvalidated) {
// Renderer was terminated or view deallocated.
handler(nil);
} else {
handler(base::mac::ObjCCastStrict<NSDictionary>(element));
}
};
}
NSString* getElementScript = NSString* getElementScript =
[NSString stringWithFormat:formatString, point.x + scrollOffset.x, [NSString stringWithFormat:formatString, point.x + scrollOffset.x,
point.y + scrollOffset.y, webViewContentWidth, point.y + scrollOffset.y, webViewContentWidth,
webViewContentHeight]; webViewContentHeight];
[self executeJavaScript:getElementScript completionHandler:completionHandler]; [self executeJavaScript:getElementScript completionHandler:nil];
} }
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment