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[] = {
{"infobars-ui-reboot", flag_descriptions::kInfobarsUIRebootName,
flag_descriptions::kInfobarsUIRebootDescription, flags_ui::kOsIos,
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",
flag_descriptions::kMailtoHandlingWithGoogleUIName,
flag_descriptions::kMailtoHandlingWithGoogleUIDescription,
......
......@@ -125,13 +125,6 @@ const char kContextualSearch[] = "Contextual Search";
const char kContextualSearchDescription[] =
"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 kCopyImageDescription[] =
"Enable copying image to system pasteboard via context menu.";
......
......@@ -100,11 +100,6 @@ extern const char kCaptivePortalMetricsDescription[];
extern const char kContextualSearch[];
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.
extern const char kCopyImageName[];
extern const char kCopyImageDescription[];
......
......@@ -7,9 +7,6 @@
namespace web {
namespace features {
const base::Feature kContextMenuElementPostMessage{
"ContextMenuElementPostMessage", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kWebFrameMessaging{"WebFrameMessaging",
base::FEATURE_DISABLED_BY_DEFAULT};
......
......@@ -10,9 +10,6 @@
namespace web {
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.
extern const base::Feature kWebFrameMessaging;
......
......@@ -7,15 +7,15 @@
#import <Foundation/Foundation.h>
// Contains keys present in dictionary returned by __gCrWeb.getElementFromPoint
// and __gCrWeb.findElementAtPoint JS APIs.
// Contains keys present in dictionary created by __gCrWeb.findElementAtPoint
// to represent the DOM element.
namespace web {
// Required in findElementAtPoint response. (Not used by getElementFromPoint.)
// Represents a unique string request ID that is passed through directly from a
// call to findElementAtPoint to the response dictionary. The request ID should
// be used to correlate a response with a previous call to findElementAtPoint.
// Required key. Represents a unique string request ID that is passed through
// directly from a call to findElementAtPoint to the response dictionary. The
// request ID should be used to correlate a response with a previous call to
// findElementAtPoint.
extern NSString* const kContextMenuElementRequestId;
// Optional key. Represents element's href attribute if present or parent's href
......
......@@ -14,59 +14,6 @@ goog.require('__crWeb.common');
/** Beginning of anonymous object */
(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.
* @param {HTMLElement} element The element whose details will be returned.
......
......@@ -18,7 +18,7 @@ goog.provide('__crWeb.mainFrameContextMenu');
* found element (or an empty object if no links or images are found) back to
* the application by posting a 'FindElementResultHandler' message.
* 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
* dictionary of this request.
* @param {number} x Horizontal center of the selected point in web view
......@@ -36,23 +36,6 @@ __gCrWeb['findElementAtPoint'] =
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
* event handlers.
......
......@@ -178,10 +178,6 @@ struct ContextMenuInfo {
_delegate = delegate;
_injectionEvaluator = injectionEvaluator;
_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
// recognizer with a shorter delay to be able to cancel the system menu if
......@@ -219,20 +215,17 @@ struct ContextMenuInfo {
}
}
if (base::FeatureList::IsEnabled(
web::features::kContextMenuElementPostMessage)) {
// Listen for fetched element response.
web::WKWebViewConfigurationProvider& configurationProvider =
web::WKWebViewConfigurationProvider::FromBrowserState(browserState);
CRWWKScriptMessageRouter* messageRouter =
configurationProvider.GetScriptMessageRouter();
__weak CRWContextMenuController* weakSelf = self;
[messageRouter setScriptMessageHandler:^(WKScriptMessage* message) {
[weakSelf didReceiveScriptMessage:message];
}
name:kFindElementResultHandlerName
webView:webView];
// Listen for fetched element response.
web::WKWebViewConfigurationProvider& configurationProvider =
web::WKWebViewConfigurationProvider::FromBrowserState(browserState);
CRWWKScriptMessageRouter* messageRouter =
configurationProvider.GetScriptMessageRouter();
__weak CRWContextMenuController* weakSelf = self;
[messageRouter setScriptMessageHandler:^(WKScriptMessage* message) {
[weakSelf didReceiveScriptMessage:message];
}
name:kFindElementResultHandlerName
webView:webView];
}
return self;
}
......@@ -492,41 +485,20 @@ struct ContextMenuInfo {
CGFloat webViewContentWidth = webViewContentSize.width;
CGFloat webViewContentHeight = webViewContentSize.height;
NSString* formatString;
web::JavaScriptResultBlock completionHandler = nil;
if (base::FeatureList::IsEnabled(
web::features::kContextMenuElementPostMessage)) {
NSString* requestID =
base::SysUTF8ToNSString(base::UnguessableToken::Create().ToString());
HTMLElementFetchRequest* fetchRequest =
[[HTMLElementFetchRequest alloc] initWithFoundElementHandler:handler];
_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* requestID =
base::SysUTF8ToNSString(base::UnguessableToken::Create().ToString());
HTMLElementFetchRequest* fetchRequest =
[[HTMLElementFetchRequest alloc] initWithFoundElementHandler:handler];
_pendingElementFetchRequests[requestID] = fetchRequest;
NSString* formatString = [NSString
stringWithFormat:
@"__gCrWeb.findElementAtPoint('%@', %%g, %%g, %%g, %%g);", requestID];
NSString* getElementScript =
[NSString stringWithFormat:formatString, point.x + scrollOffset.x,
point.y + scrollOffset.y, webViewContentWidth,
webViewContentHeight];
[self executeJavaScript:getElementScript completionHandler:completionHandler];
[self executeJavaScript:getElementScript completionHandler:nil];
}
@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