Commit 989be132 authored by Mike Dougherty's avatar Mike Dougherty Committed by Commit Bot

Inject Context Menu Javascript into all frames.

Bug: 228355
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I871fe76d7e2d8ce96ce5e70475e503216f711326
Reviewed-on: https://chromium-review.googlesource.com/975996
Commit-Queue: Mike Dougherty <michaeldo@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545581}
parent fd4c46a1
......@@ -596,9 +596,9 @@ js_compile_bundle("main_frame_web_bundle") {
sources = [
"web_state/js/resources/console.js",
"web_state/js/resources/context_menu.js",
"web_state/js/resources/error.js",
"web_state/js/resources/legacy.js",
"web_state/js/resources/main_frame_context_menu.js",
"web_state/js/resources/main_frame_web_bundle.js",
"web_state/js/resources/navigation.js",
"web_state/js/resources/scroll_workaround.js",
......@@ -610,6 +610,7 @@ js_compile_bundle("all_frames_web_bundle") {
closure_entry_point = "__crWeb.allFramesWebBundle"
sources = [
"web_state/js/resources/all_frames_context_menu.js",
"web_state/js/resources/all_frames_web_bundle.js",
"web_state/js/resources/base.js",
"web_state/js/resources/common.js",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Copyright 2018 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.
......@@ -6,64 +6,13 @@
* @fileoverview APIs used by CRWContextMenuController.
*/
goog.provide('__crWeb.contextMenu');
goog.provide('__crWeb.allFramesContextMenu');
goog.require('__crWeb.base');
/** Beginning of anonymous object */
(function() {
/**
* Finds the url of the image or link under the selected point. Sends the
* 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.
* @param {string} identifier An identifier which be returned in the result
* dictionary of this request.
* @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.
*/
__gCrWeb['findElementAtPoint'] =
function(requestID, x, y, webViewWidth, webViewHeight) {
var scale = getPageWidth() / webViewWidth;
var result = getElementFromPointInPageCoordinates(x * scale, y * scale);
result.requestID = requestID;
__gCrWeb.common.sendWebKitMessage('FindElementResultHandler', result);
};
/**
* 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 getElementFromPointInPageCoordinates(x * scale, y * scale);
};
/**
* Suppresses the next click such that they are not handled by JS click
* event handlers.
* @type {void}
*/
__gCrWeb['suppressNextClick'] = function() {
var suppressNextClick = function(evt) {
evt.preventDefault();
document.removeEventListener('click', suppressNextClick, false);
};
document.addEventListener('click', suppressNextClick);
};
/**
* Returns an object representing the details of the given element.
* @param {number} x Horizontal center of the selected point in page
......@@ -86,7 +35,7 @@ __gCrWeb['suppressNextClick'] = function() {
* from the current page.
* </ul>
*/
var getElementFromPointInPageCoordinates = function(x, y) {
__gCrWeb['getElementFromPointInPageCoordinates'] = function(x, y) {
var hitCoordinates = spiralCoordinates_(x, y);
for (var index = 0; index < hitCoordinates.length; index++) {
var coordinates = hitCoordinates[index];
......@@ -158,20 +107,6 @@ var getElementFromPointInPageCoordinates = function(x, y) {
return {};
};
/**
* Returns the margin in points around touchable elements (e.g. links for
* custom context menu).
* @type {number}
*/
var getPageWidth = function() {
var documentElement = document.documentElement;
var documentBody = document.body;
return Math.max(
documentElement.clientWidth, documentElement.scrollWidth,
documentElement.offsetWidth, documentBody.scrollWidth,
documentBody.offsetWidth);
};
/**
* Returns whether or not view port coordinates should be used for the given
* window.
......
......@@ -5,6 +5,7 @@
// Set of scripts required by web layer backed up by WKWebView.
goog.provide('__crWeb.allFramesWebBundle');
goog.require('__crWeb.allFramesContextMenu');
goog.require('__crWeb.base');
goog.require('__crWeb.common');
goog.require('__crWeb.message');
......
// Copyright 2017 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.
/**
* @fileoverview APIs used by CRWContextMenuController.
*/
goog.provide('__crWeb.mainFrameContextMenu');
// Requires __crWeb.allFramesContextMenu provided by __crWeb.allFramesWebBundle.
/** Beginning of anonymous object */
(function() {
/**
* Finds the url of the image or link under the selected point. Sends the
* 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.
* @param {string} identifier An identifier which be returned in the result
* dictionary of this request.
* @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.
*/
__gCrWeb['findElementAtPoint'] =
function(requestID, x, y, webViewWidth, webViewHeight) {
var scale = getPageWidth() / webViewWidth;
var result =
__gCrWeb.getElementFromPointInPageCoordinates(x * scale, y * scale);
result.requestID = requestID;
__gCrWeb.common.sendWebKitMessage('FindElementResultHandler', result);
};
/**
* 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.
* @type {void}
*/
__gCrWeb['suppressNextClick'] = function() {
var suppressNextClick = function(evt) {
evt.preventDefault();
document.removeEventListener('click', suppressNextClick, false);
};
document.addEventListener('click', suppressNextClick);
};
/**
* Returns the margin in points around touchable elements (e.g. links for
* custom context menu).
* @type {number}
*/
var getPageWidth = function() {
var documentElement = document.documentElement;
var documentBody = document.body;
return Math.max(
documentElement.clientWidth, documentElement.scrollWidth,
documentElement.offsetWidth, documentBody.scrollWidth,
documentBody.offsetWidth);
};
}()); // End of anonymouse object
......@@ -8,8 +8,8 @@ goog.provide('__crWeb.mainFrameWebBundle');
// Requires __crWeb.form provided by __crWeb.allFramesWebBundle.
goog.require('__crWeb.console');
goog.require('__crWeb.contextMenu');
goog.require('__crWeb.error');
goog.require('__crWeb.legacy');
goog.require('__crWeb.mainFrameContextMenu');
goog.require('__crWeb.navigation');
goog.require('__crWeb.scrollWorkaround');
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