Commit bbef79b0 authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

Lint and format javascript.

Running glint and clang-format on JavaScript files.

Bug: 487804, 802170
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ic13a1a141b74b761b83d5aee20c0f4bff384b57b
Reviewed-on: https://chromium-review.googlesource.com/919263Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537295}
parent 45a12805
...@@ -24,25 +24,23 @@ __gCrWeb.suggestion = {}; ...@@ -24,25 +24,23 @@ __gCrWeb.suggestion = {};
// minification. // minification.
__gCrWeb['suggestion'] = __gCrWeb.suggestion; __gCrWeb['suggestion'] = __gCrWeb.suggestion;
/** /**
* Returns the element with the specified name that is a child of the * Returns the element with the specified name that is a child of the
* specified parent element. * specified parent element.
* @param {Element} parent The parent of the desired element. * @param {Element} parent The parent of the desired element.
* @param {string} name The name of the desired element. * @param {string} name The name of the desired element.
* @return {Element} The element if found, otherwise null; * @return {Element} The element if found, otherwise null;
*/ */
var getElementByNameWithParent_ = function(parent, name) { var getElementByNameWithParent_ = function(parent, name) {
if (parent.name === name) if (parent.name === name) return parent;
return parent;
var el; var el;
for (var i = 0; i < parent.children.length; i++) { for (var i = 0; i < parent.children.length; i++) {
el = getElementByNameWithParent_(parent.children[i], name); el = getElementByNameWithParent_(parent.children[i], name);
if (el) if (el) return el;
return el;
} }
return null; return null;
}; };
/** /**
* Returns the first element in |elements| that is later than |elementToCompare| * Returns the first element in |elements| that is later than |elementToCompare|
...@@ -57,8 +55,8 @@ __gCrWeb['suggestion'] = __gCrWeb.suggestion; ...@@ -57,8 +55,8 @@ __gCrWeb['suggestion'] = __gCrWeb.suggestion;
* @return {Element} the first element in |elements| that is later than * @return {Element} the first element in |elements| that is later than
* |elementToCompare| in tab order if there is one; null otherwise. * |elementToCompare| in tab order if there is one; null otherwise.
*/ */
__gCrWeb.suggestion.getNextElementInTabOrder = __gCrWeb.suggestion.getNextElementInTabOrder = function(
function(elementToCompare, elementList) { elementToCompare, elementList) {
var elements = []; var elements = [];
for (var i = 0; i < elementList.length; ++i) { for (var i = 0; i < elementList.length; ++i) {
elements[i] = elementList[i]; elements[i] = elementList[i];
...@@ -109,8 +107,8 @@ __gCrWeb.suggestion.getNextElementInTabOrder = ...@@ -109,8 +107,8 @@ __gCrWeb.suggestion.getNextElementInTabOrder =
* @return {Element} the last element in |elements| that is earlier than * @return {Element} the last element in |elements| that is earlier than
* |elementToCompare| in tab order if there is one; null otherwise. * |elementToCompare| in tab order if there is one; null otherwise.
*/ */
__gCrWeb.suggestion.getPreviousElementInTabOrder = __gCrWeb.suggestion.getPreviousElementInTabOrder = function(
function(elementToCompare, elementList) { elementToCompare, elementList) {
var elements = []; var elements = [];
for (var i = 0; i < elementList.length; ++i) { for (var i = 0; i < elementList.length; ++i) {
elements[i] = elementList[i]; elements[i] = elementList[i];
...@@ -165,8 +163,8 @@ __gCrWeb.suggestion.getPreviousElementInTabOrder = ...@@ -165,8 +163,8 @@ __gCrWeb.suggestion.getPreviousElementInTabOrder =
* tree order. * tree order.
* @return {Element} The element that satisfies the conditions given above. * @return {Element} The element that satisfies the conditions given above.
*/ */
__gCrWeb.suggestion.getFormElementAfter = __gCrWeb.suggestion.getFormElementAfter = function(
function(elementToCompare, elements, comparator) { elementToCompare, elements, comparator) {
// Computes the index |indexToCompare| of |elementToCompare| in |element|. // Computes the index |indexToCompare| of |elementToCompare| in |element|.
var indexToCompare = elements.indexOf(elementToCompare); var indexToCompare = elements.indexOf(elementToCompare);
if (indexToCompare === -1) { if (indexToCompare === -1) {
...@@ -234,8 +232,7 @@ __gCrWeb.suggestion.isSequentiallyReachable = function(element) { ...@@ -234,8 +232,7 @@ __gCrWeb.suggestion.isSequentiallyReachable = function(element) {
// on this condition, false is returned for an iframe (as Mobile Safari does // on this condition, false is returned for an iframe (as Mobile Safari does
// not navigate to elements in an iframe, there is no need to recursively // not navigate to elements in an iframe, there is no need to recursively
// check if there is a reachable element in an iframe). // check if there is a reachable element in an iframe).
if (element.tagName !== 'INPUT' && if (element.tagName !== 'INPUT' && element.tagName !== 'SELECT' &&
element.tagName !== 'SELECT' &&
element.tagName !== 'TEXTAREA') { element.tagName !== 'TEXTAREA') {
return false; return false;
} }
...@@ -243,12 +240,9 @@ __gCrWeb.suggestion.isSequentiallyReachable = function(element) { ...@@ -243,12 +240,9 @@ __gCrWeb.suggestion.isSequentiallyReachable = function(element) {
// The following elements are skipped when navigating using 'Prev' and "Next' // The following elements are skipped when navigating using 'Prev' and "Next'
// buttons in Mobile Safari. // buttons in Mobile Safari.
if (element.tagName === 'INPUT' && if (element.tagName === 'INPUT' &&
(element.type === 'submit' || (element.type === 'submit' || element.type === 'reset' ||
element.type === 'reset' || element.type === 'image' || element.type === 'button' ||
element.type === 'image' || element.type === 'range' || element.type === 'radio' ||
element.type === 'button' ||
element.type === 'range' ||
element.type === 'radio' ||
element.type === 'checkbox')) { element.type === 'checkbox')) {
return false; return false;
} }
...@@ -289,8 +283,7 @@ __gCrWeb.suggestion.getTabOrder = function(element) { ...@@ -289,8 +283,7 @@ __gCrWeb.suggestion.getTabOrder = function(element) {
*/ */
__gCrWeb.suggestion.getFormElement = function(formName, fieldName) { __gCrWeb.suggestion.getFormElement = function(formName, fieldName) {
var form = __gCrWeb.common.getFormElementFromIdentifier(formName); var form = __gCrWeb.common.getFormElementFromIdentifier(formName);
if (!form) if (!form) return null;
return null;
return getElementByNameWithParent_(form, fieldName); return getElementByNameWithParent_(form, fieldName);
}; };
...@@ -299,11 +292,11 @@ __gCrWeb.suggestion.getFormElement = function(formName, fieldName) { ...@@ -299,11 +292,11 @@ __gCrWeb.suggestion.getFormElement = function(formName, fieldName) {
* if there is no such element. * if there is no such element.
*/ */
__gCrWeb.suggestion['selectNextElement'] = function(formName, fieldName) { __gCrWeb.suggestion['selectNextElement'] = function(formName, fieldName) {
var currentElement = var currentElement = formName ?
formName ? __gCrWeb.suggestion.getFormElement(formName, fieldName) : __gCrWeb.suggestion.getFormElement(formName, fieldName) :
document.activeElement; document.activeElement;
var nextElement = __gCrWeb.suggestion.getNextElementInTabOrder(currentElement, var nextElement = __gCrWeb.suggestion.getNextElementInTabOrder(
document.all); currentElement, document.all);
if (nextElement) { if (nextElement) {
nextElement.focus(); nextElement.focus();
} }
...@@ -314,8 +307,8 @@ __gCrWeb.suggestion['selectNextElement'] = function(formName, fieldName) { ...@@ -314,8 +307,8 @@ __gCrWeb.suggestion['selectNextElement'] = function(formName, fieldName) {
* operation if there is no such element. * operation if there is no such element.
*/ */
__gCrWeb.suggestion['selectPreviousElement'] = function(formName, fieldName) { __gCrWeb.suggestion['selectPreviousElement'] = function(formName, fieldName) {
var currentElement = var currentElement = formName ?
formName ? __gCrWeb.suggestion.getFormElement(formName, fieldName) : __gCrWeb.suggestion.getFormElement(formName, fieldName) :
document.activeElement; document.activeElement;
var prevElement = __gCrWeb.suggestion.getPreviousElementInTabOrder( var prevElement = __gCrWeb.suggestion.getPreviousElementInTabOrder(
currentElement, document.all); currentElement, document.all);
...@@ -325,24 +318,28 @@ __gCrWeb.suggestion['selectPreviousElement'] = function(formName, fieldName) { ...@@ -325,24 +318,28 @@ __gCrWeb.suggestion['selectPreviousElement'] = function(formName, fieldName) {
}; };
/** /**
* @param {string} formName The name of the form containing the element.
* @param {string} fieldName The name of the field containing the element.
* @return {boolean} Whether there is an element in the sequential navigation * @return {boolean} Whether there is an element in the sequential navigation
* after the currently active element. * after the currently active element.
*/ */
__gCrWeb.suggestion['hasNextElement'] = function(formName, fieldName) { __gCrWeb.suggestion['hasNextElement'] = function(formName, fieldName) {
var currentElement = var currentElement = formName ?
formName ? __gCrWeb.suggestion.getFormElement(formName, fieldName) : __gCrWeb.suggestion.getFormElement(formName, fieldName) :
document.activeElement; document.activeElement;
return __gCrWeb.suggestion.getNextElementInTabOrder(currentElement, return __gCrWeb.suggestion.getNextElementInTabOrder(
document.all) !== null; currentElement, document.all) !== null;
}; };
/** /**
* @param {string} formName The name of the form containing the element.
* @param {string} fieldName The name of the field containing the element.
* @return {boolean} Whether there is an element in the sequential navigation * @return {boolean} Whether there is an element in the sequential navigation
* before the currently active element. * before the currently active element.
*/ */
__gCrWeb.suggestion['hasPreviousElement'] = function(formName, fieldName) { __gCrWeb.suggestion['hasPreviousElement'] = function(formName, fieldName) {
var currentElement = var currentElement = formName ?
formName ? __gCrWeb.suggestion.getFormElement(formName, fieldName) : __gCrWeb.suggestion.getFormElement(formName, fieldName) :
document.activeElement; document.activeElement;
return __gCrWeb.suggestion.getPreviousElementInTabOrder( return __gCrWeb.suggestion.getPreviousElementInTabOrder(
currentElement, document.all) !== null; currentElement, document.all) !== null;
......
...@@ -184,9 +184,7 @@ source_set("eg_tests") { ...@@ -184,9 +184,7 @@ source_set("eg_tests") {
] ]
} }
# TODO(crbug.com/487804): use js_compile_checked instead once the errors have js_compile_checked("injected_js") {
# been fixed.
js_compile_unchecked("injected_js") {
visibility = [ ":passwords" ] visibility = [ ":passwords" ]
sources = [ sources = [
"resources/password_controller.js", "resources/password_controller.js",
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
// Only install the password management functions once. // Only install the password management functions once.
if (__gCrWeb && !__gCrWeb['fillPasswordForm']) { if (__gCrWeb && !__gCrWeb['fillPasswordForm']) {
/** /**
* Finds all password forms in the window and returns form data as a JSON * Finds all password forms in the window and returns form data as a JSON
* string. * string.
...@@ -37,6 +36,9 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) { ...@@ -37,6 +36,9 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) {
/** Returns true if the supplied window or any frames inside contain an input /** Returns true if the supplied window or any frames inside contain an input
* field of type 'password'. * field of type 'password'.
* @private * @private
* @param {Window} win Whether the supplied window or any frames inside
* contain an input field of type 'password'.
* @return {boolean}
*/ */
var hasPasswordField_ = function(win) { var hasPasswordField_ = function(win) {
var doc = win.document; var doc = win.document;
...@@ -61,7 +63,7 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) { ...@@ -61,7 +63,7 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) {
* @return {Array.<Window>} Array of the same-origin frames found. * @return {Array.<Window>} Array of the same-origin frames found.
*/ */
var getSameOriginFrames_ = function(win) { var getSameOriginFrames_ = function(win) {
var frames = win.document.getElementsByTagName("iframe"); var frames = win.document.getElementsByTagName('iframe');
var result = []; var result = [];
for (var i = 0; i < frames.length; i++) { for (var i = 0; i < frames.length; i++) {
if (!frames[i].src || if (!frames[i].src ||
...@@ -75,13 +77,13 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) { ...@@ -75,13 +77,13 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) {
/** /**
* Returns a canonical action for |formElement|. It works the same as upstream * Returns a canonical action for |formElement|. It works the same as upstream
* function GetCanonicalActionForForm. * function GetCanonicalActionForForm.
* @param {Form} formElement. * @param {HTMLFormElement} formElement
* @return {string} Canonical action. * @return {string} Canonical action.
*/ */
var getCanonicalActionForForm_ = function(formElement) { var getCanonicalActionForForm_ = function(formElement) {
var raw_action = formElement.getAttribute('action') || ""; var raw_action = formElement.getAttribute('action') || '';
var absolute_url = __gCrWeb.common.absoluteURL( var absolute_url =
formElement.ownerDocument, raw_action); __gCrWeb.common.absoluteURL(formElement.ownerDocument, raw_action);
return __gCrWeb.common.removeQueryAndReferenceFromURL(absolute_url); return __gCrWeb.common.removeQueryAndReferenceFromURL(absolute_url);
}; };
...@@ -93,16 +95,14 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) { ...@@ -93,16 +95,14 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) {
* the site JavaScript. * the site JavaScript.
*/ */
var addSubmitButtonTouchEndHandler_ = function(form) { var addSubmitButtonTouchEndHandler_ = function(form) {
if (form.querySelector('input[type=submit]')) if (form.querySelector('input[type=submit]')) return;
return;
// Try to find buttons of type submit at first. // Try to find buttons of type submit at first.
var buttons = form.querySelectorAll('button[type="submit"]'); var buttons = form.querySelectorAll('button[type="submit"]');
if (buttons.length == 0) { if (buttons.length == 0) {
// Try to check all buttons. If there is only one button, assume that this // Try to check all buttons. If there is only one button, assume that this
// is the submit button. // is the submit button.
buttons = form.querySelectorAll('button'); buttons = form.querySelectorAll('button');
if (buttons.length != 1) if (buttons.length != 1) return;
return;
} }
for (var i = 0; i < buttons.length; ++i) for (var i = 0; i < buttons.length; ++i)
buttons[0].addEventListener('touchend', onSubmitButtonTouchEnd_); buttons[0].addEventListener('touchend', onSubmitButtonTouchEnd_);
...@@ -115,17 +115,17 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) { ...@@ -115,17 +115,17 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) {
var onSubmitButtonTouchEnd_ = function(evt) { var onSubmitButtonTouchEnd_ = function(evt) {
var form = evt.currentTarget.form; var form = evt.currentTarget.form;
var formData = __gCrWeb.getPasswordFormData(form); var formData = __gCrWeb.getPasswordFormData(form);
if (!formData) if (!formData) return;
return; formData['command'] = 'passwordForm.submitButtonClick';
formData["command"] = 'passwordForm.submitButtonClick';
__gCrWeb.message.invokeOnHost(formData); __gCrWeb.message.invokeOnHost(formData);
}; };
/** /**
* Returns the element from |inputs| which has the field identifier equal to * Returns the element from |inputs| which has the field identifier equal to
* |identifier| and null if there is no such element. * |identifier| and null if there is no such element.
* @param {Array.<Input>} * @param {Array.<HTMLInputElement>} inputs
* @return {Input} * @param {string} identifier
* @return {HTMLInputElement}
*/ */
var findInputByFieldIdentifier_ = function(inputs, identifier) { var findInputByFieldIdentifier_ = function(inputs, identifier) {
for (var i = 0; i < inputs.length; ++i) { for (var i = 0; i < inputs.length; ++i) {
...@@ -134,51 +134,49 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) { ...@@ -134,51 +134,49 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) {
} }
} }
return null; return null;
} };
/** /**
* Returns the password form with the given |identifier| as a JSON string * Returns the password form with the given |identifier| as a JSON string
* from the frame |win| and all its same-origin subframes. * from the frame |win| and all its same-origin subframes.
* @param {Window} The window in which to look for forms. * @param {Window} win The window in which to look for forms.
* @param {string} identifier The name of the form to extract. * @param {string} identifier The name of the form to extract.
* @return {Element} The password form. * @return {HTMLFormElement} The password form.
*/ */
var getPasswordFormElement_ = function(win, identifier) { var getPasswordFormElement_ = function(win, identifier) {
var el = win.__gCrWeb.common.getFormElementFromIdentifier(identifier); var el = win.__gCrWeb.common.getFormElementFromIdentifier(identifier);
if (el) if (el) return el;
return el;
var frames = getSameOriginFrames_(win); var frames = getSameOriginFrames_(win);
for (var i = 0; i < frames.length; ++i) { for (var i = 0; i < frames.length; ++i) {
el = getPasswordFormElement_(frames[i], identifier); el = getPasswordFormElement_(frames[i], identifier);
if (el) if (el) return el;
return el;
} }
return null; return null;
} };
/** /**
* Returns an array of input elements in a form. * Returns an array of input elements in a form.
* @param {Element} form A form element for which the input elements are * @param {HTMLFormElement} form A form element for which the input elements
* returned. * are returned.
* @return {Array<InputElement>} * @return {Array<HTMLInputElement>}
*/ */
var getFormInputElements_ = function(form) { var getFormInputElements_ = function(form) {
return __gCrWeb.common.getFormControlElements(form). return __gCrWeb.common.getFormControlElements(form).filter(function(
filter(function(element) { return element.tagName === "INPUT"; }); element) {
} return element.tagName === 'INPUT';
});
};
/** /**
* Returns the password form with the given |identifier| as a JSON string. * Returns the password form with the given |identifier| as a JSON string.
* @param {string} name The name of the form to extract. * @param {string} identifier The identifier of the form to extract.
* @return {string} The password form. * @return {string} The password form.
*/ */
__gCrWeb['getPasswordFormDataAsString'] = function(identifier) { __gCrWeb['getPasswordFormDataAsString'] = function(identifier) {
var el = getPasswordFormElement_(window, identifier); var el = getPasswordFormElement_(window, identifier);
if (!el) if (!el) return 'noPasswordsFound';
return 'noPasswordsFound';
var formData = __gCrWeb.getPasswordFormData(el); var formData = __gCrWeb.getPasswordFormData(el);
if (!formData) if (!formData) return 'noPasswordsFound';
return 'noPasswordsFound';
return __gCrWeb.stringify(formData); return __gCrWeb.stringify(formData);
}; };
...@@ -198,11 +196,11 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) { ...@@ -198,11 +196,11 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) {
* @param {string=} opt_normalizedOrigin The origin URL to compare to. * @param {string=} opt_normalizedOrigin The origin URL to compare to.
* @return {boolean} Whether a form field has been filled. * @return {boolean} Whether a form field has been filled.
*/ */
__gCrWeb['fillPasswordForm'] = function(formData, username, password, __gCrWeb['fillPasswordForm'] = function(
opt_normalizedOrigin) { formData, username, password, opt_normalizedOrigin) {
var normalizedOrigin = opt_normalizedOrigin || var normalizedOrigin = opt_normalizedOrigin ||
__gCrWeb.common.removeQueryAndReferenceFromURL(window.location.href); __gCrWeb.common.removeQueryAndReferenceFromURL(window.location.href);
var origin = formData['origin']; var origin = /** @type {string} */ (formData['origin']);
if (!__gCrWeb.common.isSameOrigin(origin, normalizedOrigin)) { if (!__gCrWeb.common.isSameOrigin(origin, normalizedOrigin)) {
return false; return false;
} }
...@@ -218,7 +216,7 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) { ...@@ -218,7 +216,7 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) {
* @param {Object} formData Form data. * @param {Object} formData Form data.
* @param {string} username The username to fill. * @param {string} username The username to fill.
* @param {string} password The password to fill. * @param {string} password The password to fill.
* @param {Object} win A window or a frame containing formData. * @param {Window} win A window or a frame containing formData.
* @param {string=} opt_normalizedOrigin The origin URL to compare to. * @param {string=} opt_normalizedOrigin The origin URL to compare to.
* @return {boolean} Whether a form field has been filled. * @return {boolean} Whether a form field has been filled.
*/ */
...@@ -230,20 +228,19 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) { ...@@ -230,20 +228,19 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) {
for (var i = 0; i < forms.length; i++) { for (var i = 0; i < forms.length; i++) {
var form = forms[i]; var form = forms[i];
var normalizedFormAction = opt_normalizedOrigin || var normalizedFormAction =
getCanonicalActionForForm_(form); opt_normalizedOrigin || getCanonicalActionForForm_(form);
if (formData.action != normalizedFormAction) if (formData.action != normalizedFormAction) continue;
continue;
var inputs = getFormInputElements_(form); var inputs = getFormInputElements_(form);
var usernameInput = var usernameInput =
findInputByFieldIdentifier_(inputs, formData.fields[0].name); findInputByFieldIdentifier_(inputs, formData.fields[0].name);
if (usernameInput == null || !__gCrWeb.common.isTextField(usernameInput) if (usernameInput == null ||
|| usernameInput.disabled) !__gCrWeb.common.isTextField(usernameInput) || usernameInput.disabled)
continue; continue;
var passwordInput = var passwordInput =
findInputByFieldIdentifier_(inputs, formData.fields[1].name); findInputByFieldIdentifier_(inputs, formData.fields[1].name);
if (passwordInput == null || passwordInput.type != "password" || if (passwordInput == null || passwordInput.type != 'password' ||
passwordInput.readOnly || passwordInput.disabled) passwordInput.readOnly || passwordInput.disabled)
continue; continue;
...@@ -308,7 +305,7 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) { ...@@ -308,7 +305,7 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) {
/** /**
* Returns a JS object containing the data from |formElement|. * Returns a JS object containing the data from |formElement|.
* @param {Element} formElement An HTML Form element. * @param {HTMLFormElement} formElement An HTML Form element.
* @return {Object} Object of data from formElement. * @return {Object} Object of data from formElement.
*/ */
__gCrWeb.getPasswordFormData = function(formElement) { __gCrWeb.getPasswordFormData = function(formElement) {
...@@ -336,8 +333,7 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) { ...@@ -336,8 +333,7 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) {
} }
} }
if (passwords.length == 0) if (passwords.length == 0) return null;
return null;
var usernameElement = ''; var usernameElement = '';
var usernameValue = ''; var usernameValue = '';
......
// Copyright 2017 The Chromium Authors. All rights reserved. // Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// The set of scripts to be injected into the web view as early as possible. // The set of scripts to be injected into the web view as early as possible.
goog.provide('__crWeb.chromeBundle'); goog.provide('__crWeb.chromeBundle');
goog.require('__crWeb.print');
goog.require('__crWeb.autofill'); goog.require('__crWeb.autofill');
goog.require('__crWeb.print');
...@@ -16,4 +16,3 @@ var __gCrWeb = {}; ...@@ -16,4 +16,3 @@ var __gCrWeb = {};
// Store __gCrWeb global namespace object referenced by a string, so it does not // Store __gCrWeb global namespace object referenced by a string, so it does not
// get renamed by closure compiler during the minification. // get renamed by closure compiler during the minification.
window['__gCrWeb'] = __gCrWeb; window['__gCrWeb'] = __gCrWeb;
This diff is collapsed.
...@@ -16,36 +16,37 @@ __gCrWeb.console = {}; ...@@ -16,36 +16,37 @@ __gCrWeb.console = {};
/* Beginning of anonymous object. */ /* Beginning of anonymous object. */
(function() { (function() {
function sendConsoleMessage(method, originalArgs) { function sendConsoleMessage(method, originalArgs) {
var message, slicedArgs = Array.prototype.slice.call(originalArgs); var message, slicedArgs = Array.prototype.slice.call(originalArgs);
try { try {
message = slicedArgs.join(' '); message = slicedArgs.join(' ');
} catch (err) { } catch (err) {
} }
__gCrWeb.message.invokeOnHost({'command': 'console', __gCrWeb.message.invokeOnHost({
'command': 'console',
'method': method, 'method': method,
'message': message, 'message': message,
'origin': document.location.origin}); 'origin': document.location.origin
} });
}
console.log = function() { console.log = function() {
sendConsoleMessage('log', arguments); sendConsoleMessage('log', arguments);
}; };
console.debug = function() { console.debug = function() {
sendConsoleMessage('debug', arguments); sendConsoleMessage('debug', arguments);
}; };
console.info = function() { console.info = function() {
sendConsoleMessage('info', arguments); sendConsoleMessage('info', arguments);
}; };
console.warn = function() { console.warn = function() {
sendConsoleMessage('warn', arguments); sendConsoleMessage('warn', arguments);
}; };
console.error = function() { console.error = function() {
sendConsoleMessage('error', arguments); sendConsoleMessage('error', arguments);
}; };
}()); }());
...@@ -11,7 +11,7 @@ goog.provide('__crWeb.contextMenu'); ...@@ -11,7 +11,7 @@ goog.provide('__crWeb.contextMenu');
/** Beginning of anonymous object */ /** Beginning of anonymous object */
(function() { (function() {
/** /**
* Returns the url of the image or link under the selected point. Returns an * Returns the url of the image or link under the selected point. Returns an
* empty object if no links or images are found. * empty object if no links or images are found.
* @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,26 +36,25 @@ goog.provide('__crWeb.contextMenu'); ...@@ -36,26 +36,25 @@ goog.provide('__crWeb.contextMenu');
* from the current page. * from the current page.
* </ul> * </ul>
*/ */
__gCrWeb['getElementFromPoint'] = __gCrWeb['getElementFromPoint'] = function(x, y, webViewWidth, webViewHeight) {
function(x, y, webViewWidth, webViewHeight) {
var scale = getPageWidth() / webViewWidth; var scale = getPageWidth() / webViewWidth;
return getElementFromPointInPageCoordinates(x * scale, y * scale) return 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.
* @type {void} * @type {void}
*/ */
__gCrWeb['suppressNextClick'] = function() { __gCrWeb['suppressNextClick'] = function() {
var suppressNextClick = function(evt) { var suppressNextClick = function(evt) {
evt.preventDefault(); evt.preventDefault();
document.removeEventListener('click', suppressNextClick, false); document.removeEventListener('click', suppressNextClick, false);
}; };
document.addEventListener('click', suppressNextClick); document.addEventListener('click', suppressNextClick);
}; };
/** /**
* Returns the url of the image or link under the selected point in page * Returns the url of the image or link under the selected point in page
* coordinates. Returns an empty object if no links or images are found. * coordinates. Returns an empty object if no links or images are found.
* @param {number} x Horizontal center of the selected point in page * @param {number} x Horizontal center of the selected point in page
...@@ -65,7 +64,7 @@ goog.provide('__crWeb.contextMenu'); ...@@ -65,7 +64,7 @@ goog.provide('__crWeb.contextMenu');
* @return {!Object} An object in the same form as * @return {!Object} An object in the same form as
* {@code getElementFromPoint} result. * {@code getElementFromPoint} result.
*/ */
var getElementFromPointInPageCoordinates = function(x, y) { var getElementFromPointInPageCoordinates = function(x, y) {
var hitCoordinates = spiralCoordinates_(x, y); var hitCoordinates = spiralCoordinates_(x, y);
for (var index = 0; index < hitCoordinates.length; index++) { for (var index = 0; index < hitCoordinates.length; index++) {
var coordinates = hitCoordinates[index]; var coordinates = hitCoordinates[index];
...@@ -81,8 +80,7 @@ goog.provide('__crWeb.contextMenu'); ...@@ -81,8 +80,7 @@ goog.provide('__crWeb.contextMenu');
var level = 0; var level = 0;
while (++level < 8 && element && element != document) { while (++level < 8 && element && element != document) {
var tagName = element.tagName; var tagName = element.tagName;
if (!tagName) if (!tagName) continue;
continue;
tagName = tagName.toLowerCase(); tagName = tagName.toLowerCase();
if (tagName === 'input' || tagName === 'textarea' || if (tagName === 'input' || tagName === 'textarea' ||
...@@ -104,10 +102,7 @@ goog.provide('__crWeb.contextMenu'); ...@@ -104,10 +102,7 @@ goog.provide('__crWeb.contextMenu');
if (tagName === 'img' && element.src) { if (tagName === 'img' && element.src) {
// Found an image. // Found an image.
var result = { var result = {src: element.src, referrerPolicy: getReferrerPolicy_()};
src: element.src,
referrerPolicy: getReferrerPolicy_()
};
// Copy the title, if any. // Copy the title, if any.
if (element.title) { if (element.title) {
result.title = element.title; result.title = element.title;
...@@ -115,13 +110,12 @@ goog.provide('__crWeb.contextMenu'); ...@@ -115,13 +110,12 @@ goog.provide('__crWeb.contextMenu');
// Check if the image is also a link. // Check if the image is also a link.
var parent = element.parentNode; var parent = element.parentNode;
while (parent) { while (parent) {
if (parent.tagName && if (parent.tagName && parent.tagName.toLowerCase() === 'a' &&
parent.tagName.toLowerCase() === 'a' &&
parent.href) { parent.href) {
// This regex identifies strings like void(0), // This regex identifies strings like void(0),
// void(0) ;void(0);, ;;;; // void(0) ;void(0);, ;;;;
// which result in a NOP when executed as JavaScript. // which result in a NOP when executed as JavaScript.
var regex = RegExp("^javascript:(?:(?:void\\(0\\)|;)\\s*)+$"); var regex = RegExp('^javascript:(?:(?:void\\(0\\)|;)\\s*)+$');
if (parent.href.match(regex)) { if (parent.href.match(regex)) {
parent = parent.parentNode; parent = parent.parentNode;
continue; continue;
...@@ -139,36 +133,40 @@ goog.provide('__crWeb.contextMenu'); ...@@ -139,36 +133,40 @@ goog.provide('__crWeb.contextMenu');
} }
} }
return {}; return {};
}; };
/** /**
* Returns the margin in points around touchable elements (e.g. links for * Returns the margin in points around touchable elements (e.g. links for
* custom context menu). * custom context menu).
* @type {number} * @type {number}
*/ */
var getPageWidth = function() { var getPageWidth = function() {
var documentElement = document.documentElement; var documentElement = document.documentElement;
var documentBody = document.body; var documentBody = document.body;
return Math.max(documentElement.clientWidth, return Math.max(
documentElement.scrollWidth, documentElement.clientWidth, documentElement.scrollWidth,
documentElement.offsetWidth, documentElement.offsetWidth, documentBody.scrollWidth,
documentBody.scrollWidth,
documentBody.offsetWidth); documentBody.offsetWidth);
}; };
/** /**
* Implementation of document.elementFromPoint that is working for iOS4 and * Implementation of document.elementFromPoint that is working for iOS4 and
* iOS5 and that also goes into frames and iframes. * iOS5 and that also goes into frames and iframes.
* @private * @private
* @param {number} x
* @param {number} y
* @return {HTMLElement | boolean}
*/ */
var elementFromPoint_ = function(x, y) { var elementFromPoint_ = function(x, y) {
var elementFromPointIsUsingViewPortCoordinates = function(win) { var elementFromPointIsUsingViewPortCoordinates = function(win) {
if (win.pageYOffset > 0) { // Page scrolled down. if (win.pageYOffset > 0) { // Page scrolled down.
return (win.document.elementFromPoint( return (
win.document.elementFromPoint(
0, win.pageYOffset + win.innerHeight - 1) === null); 0, win.pageYOffset + win.innerHeight - 1) === null);
} }
if (win.pageXOffset > 0) { // Page scrolled to the right. if (win.pageXOffset > 0) { // Page scrolled to the right.
return (win.document.elementFromPoint( return (
win.document.elementFromPoint(
win.pageXOffset + win.innerWidth - 1, 0) === null); win.pageXOffset + win.innerWidth - 1, 0) === null);
} }
return false; // No scrolling, don't care. return false; // No scrolling, don't care.
...@@ -176,8 +174,10 @@ goog.provide('__crWeb.contextMenu'); ...@@ -176,8 +174,10 @@ goog.provide('__crWeb.contextMenu');
var newCoordinate = function(x, y) { var newCoordinate = function(x, y) {
var coordinates = { var coordinates = {
x: x, y: y, x: x,
viewPortX: x - window.pageXOffset, viewPortY: y - window.pageYOffset, y: y,
viewPortX: x - window.pageXOffset,
viewPortY: y - window.pageYOffset,
useViewPortCoordinates: false, useViewPortCoordinates: false,
window: window window: window
}; };
...@@ -187,7 +187,7 @@ goog.provide('__crWeb.contextMenu'); ...@@ -187,7 +187,7 @@ goog.provide('__crWeb.contextMenu');
// Returns the coordinates of the upper left corner of |obj| in the // Returns the coordinates of the upper left corner of |obj| in the
// coordinates of the window that |obj| is in. // coordinates of the window that |obj| is in.
var getPositionInWindow = function(obj) { var getPositionInWindow = function(obj) {
var coord = { x: 0, y: 0 }; var coord = {x: 0, y: 0};
while (obj.offsetParent) { while (obj.offsetParent) {
coord.x += obj.offsetLeft; coord.x += obj.offsetLeft;
coord.y += obj.offsetTop; coord.y += obj.offsetTop;
...@@ -223,10 +223,8 @@ goog.provide('__crWeb.contextMenu'); ...@@ -223,10 +223,8 @@ goog.provide('__crWeb.contextMenu');
return currentElement; return currentElement;
} }
var framePosition = getPositionInWindow(currentElement); var framePosition = getPositionInWindow(currentElement);
coordinates.viewPortX -= coordinates.viewPortX -= framePosition.x - coordinates.window.pageXOffset;
framePosition.x - coordinates.window.pageXOffset; coordinates.viewPortY -= framePosition.y - coordinates.window.pageYOffset;
coordinates.viewPortY -=
framePosition.y - coordinates.window.pageYOffset;
coordinates.window = currentElement.contentWindow; coordinates.window = currentElement.contentWindow;
coordinates.x -= framePosition.x + coordinates.window.pageXOffset; coordinates.x -= framePosition.x + coordinates.window.pageXOffset;
coordinates.y -= framePosition.y + coordinates.window.pageYOffset; coordinates.y -= framePosition.y + coordinates.window.pageYOffset;
...@@ -236,10 +234,14 @@ goog.provide('__crWeb.contextMenu'); ...@@ -236,10 +234,14 @@ goog.provide('__crWeb.contextMenu');
}; };
return elementsFromCoordinates(newCoordinate(x, y)); return elementsFromCoordinates(newCoordinate(x, y));
}; };
/** @private */ /** @private
var spiralCoordinates_ = function(x, y) { * @param {number} x
* @param {number} y
* @return {Object}
*/
var spiralCoordinates_ = function(x, y) {
var MAX_ANGLE = Math.PI * 2.0 * 3.0; var MAX_ANGLE = Math.PI * 2.0 * 3.0;
var POINT_COUNT = 30; var POINT_COUNT = 30;
var ANGLE_STEP = MAX_ANGLE / POINT_COUNT; var ANGLE_STEP = MAX_ANGLE / POINT_COUNT;
...@@ -251,19 +253,24 @@ goog.provide('__crWeb.contextMenu'); ...@@ -251,19 +253,24 @@ goog.provide('__crWeb.contextMenu');
var angle = ANGLE_STEP * index; var angle = ANGLE_STEP * index;
var radius = angle * SPEED; var radius = angle * SPEED;
coordinates.push({x: x + Math.round(Math.cos(angle) * radius), coordinates.push({
y: y + Math.round(Math.sin(angle) * radius)}); x: x + Math.round(Math.cos(angle) * radius),
y: y + Math.round(Math.sin(angle) * radius)
});
} }
return coordinates; return coordinates;
}; };
/** @private */ /** @private
var getComputedWebkitTouchCallout_ = function(element) { * @param {HTMLElement} element
* @return {Object}
*/
var getComputedWebkitTouchCallout_ = function(element) {
return window.getComputedStyle(element, null)['webkitTouchCallout']; return window.getComputedStyle(element, null)['webkitTouchCallout'];
}; };
/** /**
* Gets the referrer policy to use for navigations away from the current page. * Gets the referrer policy to use for navigations away from the current page.
* If a link element is passed, and it includes a rel=noreferrer tag, that * If a link element is passed, and it includes a rel=noreferrer tag, that
* will override the page setting. * will override the page setting.
...@@ -271,7 +278,7 @@ goog.provide('__crWeb.contextMenu'); ...@@ -271,7 +278,7 @@ goog.provide('__crWeb.contextMenu');
* @return {string} The policy string. * @return {string} The policy string.
* @private * @private
*/ */
var getReferrerPolicy_ = function(opt_linkElement) { var getReferrerPolicy_ = function(opt_linkElement) {
if (opt_linkElement) { if (opt_linkElement) {
var rel = opt_linkElement.getAttribute('rel'); var rel = opt_linkElement.getAttribute('rel');
if (rel && rel.toLowerCase() == 'noreferrer') { if (rel && rel.toLowerCase() == 'noreferrer') {
...@@ -286,10 +293,8 @@ goog.provide('__crWeb.contextMenu'); ...@@ -286,10 +293,8 @@ goog.provide('__crWeb.contextMenu');
for (var i = 0; i < metaTags.length; ++i) { for (var i = 0; i < metaTags.length; ++i) {
if (metaTags[i].name.toLowerCase() == 'referrer') { if (metaTags[i].name.toLowerCase() == 'referrer') {
var referrerPolicy = metaTags[i].content.toLowerCase(); var referrerPolicy = metaTags[i].content.toLowerCase();
if (referrerPolicy == 'default' || if (referrerPolicy == 'default' || referrerPolicy == 'always' ||
referrerPolicy == 'always' || referrerPolicy == 'no-referrer' || referrerPolicy == 'origin' ||
referrerPolicy == 'no-referrer' ||
referrerPolicy == 'origin' ||
referrerPolicy == 'no-referrer-when-downgrade' || referrerPolicy == 'no-referrer-when-downgrade' ||
referrerPolicy == 'unsafe-url') { referrerPolicy == 'unsafe-url') {
return referrerPolicy; return referrerPolicy;
...@@ -299,6 +304,6 @@ goog.provide('__crWeb.contextMenu'); ...@@ -299,6 +304,6 @@ goog.provide('__crWeb.contextMenu');
} }
} }
return 'default'; return 'default';
}; };
}()); // End of anonymouse object }()); // End of anonymouse object
...@@ -13,22 +13,22 @@ goog.provide('__crWeb.error'); ...@@ -13,22 +13,22 @@ goog.provide('__crWeb.error');
/** Beginning of anonymouse object */ /** Beginning of anonymouse object */
(function() { (function() {
/** /**
* JavaScript errors are logged on the main application side. The handler is * JavaScript errors are logged on the main application side. The handler is
* added ASAP to catch any errors in startup. * added ASAP to catch any errors in startup.
*/ */
window.addEventListener('error', function(event) { window.addEventListener('error', function(event) {
// Sadly, event.filename and event.lineno are always 'undefined' and '0' // Sadly, event.filename and event.lineno are always 'undefined' and '0'
// with UIWebView. // with UIWebView.
// TODO(crbug.com/711359): the aforementioned APIs may be working now in // TODO(crbug.com/711359): the aforementioned APIs may be working now in
// WKWebView. Evaluate any cleanup / improvement we can do here. // WKWebView. Evaluate any cleanup / improvement we can do here.
__gCrWeb.message.invokeOnHost( __gCrWeb.message.invokeOnHost(
{'command': 'window.error', 'message': event.message.toString()}); {'command': 'window.error', 'message': event.message.toString()});
}); });
// Flush the message queue. // Flush the message queue.
if (__gCrWeb.message) { if (__gCrWeb.message) {
__gCrWeb.message.invokeQueues(); __gCrWeb.message.invokeQueues();
} }
}()); // End of anonymous object }()); // End of anonymous object
...@@ -14,22 +14,20 @@ goog.require('__crWeb.message'); ...@@ -14,22 +14,20 @@ goog.require('__crWeb.message');
/** Beginning of anonymous object */ /** Beginning of anonymous object */
(function() { (function() {
// Skip iframes that have different origins from the main frame. For such // Skip iframes that have different origins from the main frame. For such
// frames no form related actions (eg. filling, saving) are supported. // frames no form related actions (eg. filling, saving) are supported.
try { try {
// The following line generates exception for iframes that have different // The following line generates exception for iframes that have different
// origin that. // origin that.
// TODO(crbug.com/792642): implement sending messages instead of using // TODO(crbug.com/792642): implement sending messages instead of using
// window.top, when messaging framework is ready. // window.top, when messaging framework is ready.
if (!window.top.document) if (!window.top.document) return;
} catch (error) {
return; return;
} }
catch(error) {
return;
}
/** /**
* Focus and input events for form elements are messaged to the main * Focus and input events for form elements are messaged to the main
* application for broadcast to WebStateObservers. * application for broadcast to WebStateObservers.
* This is done with a single event handler for each type being added to the * This is done with a single event handler for each type being added to the
...@@ -37,7 +35,7 @@ goog.require('__crWeb.message'); ...@@ -37,7 +35,7 @@ goog.require('__crWeb.message');
* is much easier to manage than adding handlers to individual elements. * is much easier to manage than adding handlers to individual elements.
* @private * @private
*/ */
var formActivity_ = function(evt) { var formActivity_ = function(evt) {
var srcElement = evt.srcElement; var srcElement = evt.srcElement;
var value = srcElement.value || ''; var value = srcElement.value || '';
var fieldType = srcElement.type || ''; var fieldType = srcElement.type || '';
...@@ -51,30 +49,29 @@ goog.require('__crWeb.message'); ...@@ -51,30 +49,29 @@ goog.require('__crWeb.message');
'value': value 'value': value
}; };
__gCrWeb.message.invokeOnHost(msg); __gCrWeb.message.invokeOnHost(msg);
}; };
/** /**
* Focus events performed on the 'capture' phase otherwise they are often * Focus events performed on the 'capture' phase otherwise they are often
* not received. * not received.
*/ */
document.addEventListener('focus', formActivity_, true); document.addEventListener('focus', formActivity_, true);
document.addEventListener('blur', formActivity_, true); document.addEventListener('blur', formActivity_, true);
document.addEventListener('change', formActivity_, true); document.addEventListener('change', formActivity_, true);
/** /**
* Text input is watched at the bubbling phase as this seems adequate in * Text input is watched at the bubbling phase as this seems adequate in
* practice and it is less obtrusive to page scripts than capture phase. * practice and it is less obtrusive to page scripts than capture phase.
*/ */
document.addEventListener('input', formActivity_, false); document.addEventListener('input', formActivity_, false);
document.addEventListener('keyup', formActivity_, false); document.addEventListener('keyup', formActivity_, false);
/** /**
* Capture form submit actions. * Capture form submit actions.
*/ */
document.addEventListener('submit', function(evt) { document.addEventListener('submit', function(evt) {
var action; var action;
if (evt['defaultPrevented']) if (evt['defaultPrevented']) return;
return;
action = evt.target.getAttribute('action'); action = evt.target.getAttribute('action');
// Default action is to re-submit to same page. // Default action is to re-submit to same page.
if (!action) { if (!action) {
...@@ -85,20 +82,23 @@ goog.require('__crWeb.message'); ...@@ -85,20 +82,23 @@ goog.require('__crWeb.message');
'formName': __gCrWeb.common.getFormIdentifier(evt.srcElement), 'formName': __gCrWeb.common.getFormIdentifier(evt.srcElement),
'href': getFullyQualifiedUrl_(action) 'href': getFullyQualifiedUrl_(action)
}); });
}, false); }, false);
/** @private */ /** @private
var getFullyQualifiedUrl_ = function(originalURL) { * @param {string} originalURL
* @return {string}
*/
var getFullyQualifiedUrl_ = function(originalURL) {
// A dummy anchor (never added to the document) is used to obtain the // A dummy anchor (never added to the document) is used to obtain the
// fully-qualified URL of |originalURL|. // fully-qualified URL of |originalURL|.
var anchor = document.createElement('a'); var anchor = document.createElement('a');
anchor.href = originalURL; anchor.href = originalURL;
return anchor.href; return anchor.href;
}; };
/** Flush the message queue. */ /** Flush the message queue. */
if (__gCrWeb.message) { if (__gCrWeb.message) {
__gCrWeb.message.invokeQueues(); __gCrWeb.message.invokeQueues();
} }
}()); // End of anonymous object }()); // End of anonymous object
...@@ -14,7 +14,7 @@ goog.provide('__crWeb.legacy'); ...@@ -14,7 +14,7 @@ goog.provide('__crWeb.legacy');
/** Beginning of anonymouse object */ /** Beginning of anonymouse object */
(function() { (function() {
/** /**
* Handles document load completion tasks. Invoked from * Handles document load completion tasks. Invoked from
* [WKNavigationDelegate webView:didFinishNavigation:], when document load is * [WKNavigationDelegate webView:didFinishNavigation:], when document load is
* complete. * complete.
...@@ -22,10 +22,12 @@ goog.provide('__crWeb.legacy'); ...@@ -22,10 +22,12 @@ goog.provide('__crWeb.legacy');
* WKUserScriptInjectionTimeAtDocumentEnd to inject this material at the * WKUserScriptInjectionTimeAtDocumentEnd to inject this material at the
* appropriate time so that this API will not be needed. * appropriate time so that this API will not be needed.
*/ */
__gCrWeb.didFinishNavigation = function() { __gCrWeb.didFinishNavigation = function() {
// Send the favicons to the browser. // Send the favicons to the browser.
__gCrWeb.message.invokeOnHost({'command': 'document.favicons', __gCrWeb.message.invokeOnHost({
'favicons': __gCrWeb.common.getFavicons()}); 'command': 'document.favicons',
} 'favicons': __gCrWeb.common.getFavicons()
});
};
}()); // End of anonymouse object }()); // End of anonymouse object
...@@ -7,30 +7,30 @@ ...@@ -7,30 +7,30 @@
* switching to WKBasedNavigationManager. * switching to WKBasedNavigationManager.
*/ */
goog.provide('__crWeb.legacynavigation'); goog.provide('__crWeb.legacynavigation');
/** Beginning of anonymouse object */ /** Beginning of anonymouse object */
(function() { (function() {
/** /**
* Intercept window.history methods to call back/forward natively. * Intercept window.history methods to call back/forward natively.
*/ */
window.history.back = function() { window.history.back = function() {
__gCrWeb.message.invokeOnHost({'command': 'window.history.back'}); __gCrWeb.message.invokeOnHost({'command': 'window.history.back'});
}; };
window.history.forward = function() { window.history.forward = function() {
__gCrWeb.message.invokeOnHost({'command': 'window.history.forward'}); __gCrWeb.message.invokeOnHost({'command': 'window.history.forward'});
}; };
window.history.go = function(delta) { window.history.go = function(delta) {
__gCrWeb.message.invokeOnHost( __gCrWeb.message.invokeOnHost(
{'command': 'window.history.go', 'value': delta | 0}); {'command': 'window.history.go', 'value': delta | 0});
}; };
/** Flush the message queue. */ /** Flush the message queue. */
if (__gCrWeb.message) { if (__gCrWeb.message) {
__gCrWeb.message.invokeQueues(); __gCrWeb.message.invokeQueues();
} }
}()); // End of anonymouse object }()); // End of anonymouse object
...@@ -11,5 +11,5 @@ goog.require('__crWeb.console'); ...@@ -11,5 +11,5 @@ goog.require('__crWeb.console');
goog.require('__crWeb.contextMenu'); goog.require('__crWeb.contextMenu');
goog.require('__crWeb.error'); goog.require('__crWeb.error');
goog.require('__crWeb.legacy'); goog.require('__crWeb.legacy');
goog.require('__crWeb.scrollWorkaround');
goog.require('__crWeb.navigation'); goog.require('__crWeb.navigation');
goog.require('__crWeb.scrollWorkaround');
...@@ -20,13 +20,13 @@ __gCrWeb['message'] = __gCrWeb.message; ...@@ -20,13 +20,13 @@ __gCrWeb['message'] = __gCrWeb.message;
/* Beginning of anonymous object. */ /* Beginning of anonymous object. */
(function() { (function() {
/** /**
* Object to manage queue of messages waiting to be sent to the main * Object to manage queue of messages waiting to be sent to the main
* application for asynchronous processing. * application for asynchronous processing.
* @type {Object} * @type {Object}
* @private * @private
*/ */
var messageQueue_ = { var messageQueue_ = {
scheme: 'crwebinvoke', scheme: 'crwebinvoke',
reset: function() { reset: function() {
messageQueue_.queue = []; messageQueue_.queue = [];
...@@ -34,38 +34,37 @@ __gCrWeb['message'] = __gCrWeb.message; ...@@ -34,38 +34,37 @@ __gCrWeb['message'] = __gCrWeb.message;
// custom versions of Array.prototype.toJSON. // custom versions of Array.prototype.toJSON.
delete messageQueue_.queue.toJSON; delete messageQueue_.queue.toJSON;
} }
}; };
messageQueue_.reset(); messageQueue_.reset();
/** /**
* Invokes a command on the Objective-C side. * Invokes a command on the Objective-C side.
* @param {Object} command The command in a JavaScript object. * @param {Object} command The command in a JavaScript object.
* @public * @public
*/ */
__gCrWeb.message.invokeOnHost = function(command) { __gCrWeb.message.invokeOnHost = function(command) {
messageQueue_.queue.push(command); messageQueue_.queue.push(command);
sendQueue_(messageQueue_); sendQueue_(messageQueue_);
}; };
/** /**
* Returns the message queue as a string. * Returns the message queue as a string.
* @return {string} The current message queue as a JSON string. * @return {string} The current message queue as a JSON string.
*/ */
__gCrWeb.message.getMessageQueue = function() { __gCrWeb.message.getMessageQueue = function() {
var messageQueueString = __gCrWeb.common.JSONStringify(messageQueue_.queue); var messageQueueString = __gCrWeb.common.JSONStringify(messageQueue_.queue);
messageQueue_.reset() messageQueue_.reset();
return messageQueueString; return messageQueueString;
}; };
/** /**
* Sends both queues if they contain messages. * Sends both queues if they contain messages.
*/ */
__gCrWeb.message.invokeQueues = function() { __gCrWeb.message.invokeQueues = function() {
if (messageQueue_.queue.length > 0) if (messageQueue_.queue.length > 0) sendQueue_(messageQueue_);
sendQueue_(messageQueue_); };
};
function sendQueue_(queueObject) { function sendQueue_(queueObject) {
// Do nothing if windowId has not been set. // Do nothing if windowId has not been set.
if (typeof window.top.__gCrWeb.windowId != 'string') { if (typeof window.top.__gCrWeb.windowId != 'string') {
return; return;
...@@ -73,13 +72,12 @@ __gCrWeb['message'] = __gCrWeb.message; ...@@ -73,13 +72,12 @@ __gCrWeb['message'] = __gCrWeb.message;
// Some pages/plugins implement Object.prototype.toJSON, which can result // Some pages/plugins implement Object.prototype.toJSON, which can result
// in serializing messageQueue_ to an invalid format. // in serializing messageQueue_ to an invalid format.
var originalObjectToJSON = Object.prototype.toJSON; var originalObjectToJSON = Object.prototype.toJSON;
if (originalObjectToJSON) if (originalObjectToJSON) delete Object.prototype.toJSON;
delete Object.prototype.toJSON;
queueObject.queue.forEach(function(command) { queueObject.queue.forEach(function(command) {
__gCrWeb.common.sendWebKitMessage(queueObject.scheme, { __gCrWeb.common.sendWebKitMessage(queueObject.scheme, {
"crwCommand": command, 'crwCommand': command,
"crwWindowId": window.top.__gCrWeb['windowId'] 'crwWindowId': window.top.__gCrWeb['windowId']
}); });
}); });
queueObject.reset(); queueObject.reset();
...@@ -89,5 +87,5 @@ __gCrWeb['message'] = __gCrWeb.message; ...@@ -89,5 +87,5 @@ __gCrWeb['message'] = __gCrWeb.message;
// functionality on the page that depends on its custom implementation. // functionality on the page that depends on its custom implementation.
Object.prototype.toJSON = originalObjectToJSON; Object.prototype.toJSON = originalObjectToJSON;
} }
}; }
}()); }());
...@@ -11,16 +11,15 @@ goog.provide('__crWeb.navigation'); ...@@ -11,16 +11,15 @@ goog.provide('__crWeb.navigation');
/** Beginning of anonymouse object */ /** Beginning of anonymouse object */
(function() { (function() {
/** /**
* A popstate event needs to be fired anytime the active history entry * A popstate event needs to be fired anytime the active history entry
* changes without an associated document change. Either via back, forward, go * changes without an associated document change. Either via back, forward, go
* navigation or by loading the URL, clicking on a link, etc. * navigation or by loading the URL, clicking on a link, etc.
*/ */
__gCrWeb['dispatchPopstateEvent'] = function(stateObject) { __gCrWeb['dispatchPopstateEvent'] = function(stateObject) {
var popstateEvent = window.document.createEvent('HTMLEvents'); var popstateEvent = window.document.createEvent('HTMLEvents');
popstateEvent.initEvent('popstate', true, false); popstateEvent.initEvent('popstate', true, false);
if (stateObject) if (stateObject) popstateEvent.state = JSON.parse(stateObject);
popstateEvent.state = JSON.parse(stateObject);
// setTimeout() is used in order to return immediately. Otherwise the // setTimeout() is used in order to return immediately. Otherwise the
// dispatchEvent call waits for all event handlers to return, which could // dispatchEvent call waits for all event handlers to return, which could
...@@ -28,19 +27,17 @@ goog.provide('__crWeb.navigation'); ...@@ -28,19 +27,17 @@ goog.provide('__crWeb.navigation');
window.setTimeout(function() { window.setTimeout(function() {
window.dispatchEvent(popstateEvent); window.dispatchEvent(popstateEvent);
}, 0); }, 0);
}; };
/** /**
* A hashchange event needs to be fired after a same-document history * A hashchange event needs to be fired after a same-document history
* navigation between two URLs that are equivalent except for their fragments. * navigation between two URLs that are equivalent except for their fragments.
*/ */
__gCrWeb['dispatchHashchangeEvent'] = function(oldURL, newURL) { __gCrWeb['dispatchHashchangeEvent'] = function(oldURL, newURL) {
var hashchangeEvent = window.document.createEvent('HTMLEvents'); var hashchangeEvent = window.document.createEvent('HTMLEvents');
hashchangeEvent.initEvent('hashchange', true, false); hashchangeEvent.initEvent('hashchange', true, false);
if (oldURL) if (oldURL) hashchangeEvent.oldURL = oldURL;
hashchangeEvent.oldURL = oldURL; if (newURL) hashchangeEvent.newURL = newURL;
if (newURL)
hashchangeEvent.newURL = newURL
// setTimeout() is used in order to return immediately. Otherwise the // setTimeout() is used in order to return immediately. Otherwise the
// dispatchEvent call waits for all event handlers to return, which could // dispatchEvent call waits for all event handlers to return, which could
...@@ -48,22 +45,22 @@ goog.provide('__crWeb.navigation'); ...@@ -48,22 +45,22 @@ goog.provide('__crWeb.navigation');
window.setTimeout(function() { window.setTimeout(function() {
window.dispatchEvent(hashchangeEvent); window.dispatchEvent(hashchangeEvent);
}, 0); }, 0);
}; };
/** /**
* Keep the original pushState() and replaceState() methods. It's needed to * Keep the original pushState() and replaceState() methods. It's needed to
* update the web view's URL and window.history.state property during history * update the web view's URL and window.history.state property during history
* navigations that don't cause a page load. * navigations that don't cause a page load.
* @private * @private
*/ */
var originalWindowHistoryPushState = window.history.pushState; var originalWindowHistoryPushState = window.history.pushState;
var originalWindowHistoryReplaceState = window.history.replaceState; var originalWindowHistoryReplaceState = window.history.replaceState;
__gCrWeb['replaceWebViewURL'] = function(url, stateObject) { __gCrWeb['replaceWebViewURL'] = function(url, stateObject) {
originalWindowHistoryReplaceState.call(history, stateObject, '', url); originalWindowHistoryReplaceState.call(history, stateObject, '', url);
}; };
/** /**
* Intercepts window.history methods so native code can differentiate between * Intercepts window.history methods so native code can differentiate between
* same-document navigation that are state navigations vs. hash navigations. * same-document navigation that are state navigations vs. hash navigations.
* This is needed for backward compatibility of DidStartLoading, which is * This is needed for backward compatibility of DidStartLoading, which is
...@@ -71,53 +68,54 @@ goog.provide('__crWeb.navigation'); ...@@ -71,53 +68,54 @@ goog.provide('__crWeb.navigation');
* TODO(crbug.com/783382): Remove this once DidStartLoading is no longer * TODO(crbug.com/783382): Remove this once DidStartLoading is no longer
* called for same-document navigation. * called for same-document navigation.
*/ */
window.history.pushState = function(stateObject, pageTitle, pageUrl) { window.history.pushState = function(stateObject, pageTitle, pageUrl) {
__gCrWeb.message.invokeOnHost( __gCrWeb.message.invokeOnHost({'command': 'window.history.willChangeState'});
{'command': 'window.history.willChangeState'});
// Calling stringify() on undefined causes a JSON parse error. // Calling stringify() on undefined causes a JSON parse error.
var serializedState = var serializedState = typeof(stateObject) == 'undefined' ?
typeof(stateObject) == 'undefined' ? '' : '' :
__gCrWeb.common.JSONStringify(stateObject); __gCrWeb.common.JSONStringify(stateObject);
pageUrl = pageUrl || window.location.href; pageUrl = pageUrl || window.location.href;
originalWindowHistoryPushState.call(history, stateObject, originalWindowHistoryPushState.call(history, stateObject, pageTitle, pageUrl);
pageTitle, pageUrl); __gCrWeb.message.invokeOnHost({
__gCrWeb.message.invokeOnHost( 'command': 'window.history.didPushState',
{'command': 'window.history.didPushState',
'stateObject': serializedState, 'stateObject': serializedState,
'baseUrl': document.baseURI, 'baseUrl': document.baseURI,
'pageUrl': pageUrl.toString()}); 'pageUrl': pageUrl.toString()
}; });
};
window.history.replaceState = function(stateObject, pageTitle, pageUrl) { window.history.replaceState = function(stateObject, pageTitle, pageUrl) {
__gCrWeb.message.invokeOnHost( __gCrWeb.message.invokeOnHost({'command': 'window.history.willChangeState'});
{'command': 'window.history.willChangeState'});
// Calling stringify() on undefined causes a JSON parse error. // Calling stringify() on undefined causes a JSON parse error.
var serializedState = var serializedState = typeof(stateObject) == 'undefined' ?
typeof(stateObject) == 'undefined' ? '' : '' :
__gCrWeb.common.JSONStringify(stateObject); __gCrWeb.common.JSONStringify(stateObject);
pageUrl = pageUrl || window.location.href; pageUrl = pageUrl || window.location.href;
originalWindowHistoryReplaceState.call(history, stateObject, originalWindowHistoryReplaceState.call(
pageTitle, pageUrl); history, stateObject, pageTitle, pageUrl);
__gCrWeb.message.invokeOnHost( __gCrWeb.message.invokeOnHost({
{'command': 'window.history.didReplaceState', 'command': 'window.history.didReplaceState',
'stateObject': serializedState, 'stateObject': serializedState,
'baseUrl': document.baseURI, 'baseUrl': document.baseURI,
'pageUrl': pageUrl.toString()}); 'pageUrl': pageUrl.toString()
}; });
};
window.addEventListener('hashchange', function(evt) { window.addEventListener('hashchange', function(evt) {
// Because hash changes don't trigger __gCrWeb.didFinishNavigation, so fetch // Because hash changes don't trigger __gCrWeb.didFinishNavigation, so fetch
// favicons for the new page manually. // favicons for the new page manually.
__gCrWeb.message.invokeOnHost({'command': 'document.favicons', __gCrWeb.message.invokeOnHost({
'favicons': __gCrWeb.common.getFavicons()}); 'command': 'document.favicons',
'favicons': __gCrWeb.common.getFavicons()
});
__gCrWeb.message.invokeOnHost({'command': 'window.hashchange'}); __gCrWeb.message.invokeOnHost({'command': 'window.hashchange'});
}); });
/** Flush the message queue. */ /** Flush the message queue. */
if (__gCrWeb.message) { if (__gCrWeb.message) {
__gCrWeb.message.invokeQueues(); __gCrWeb.message.invokeQueues();
} }
}()); // End of anonymouse object }()); // End of anonymouse object
...@@ -10,19 +10,19 @@ ...@@ -10,19 +10,19 @@
/* Beginning of anonymous object. */ /* Beginning of anonymous object. */
(function() { (function() {
/** /**
* Checks whether an <object> node is plugin content (as <object> can also be * Checks whether an <object> node is plugin content (as <object> can also be
* used to embed images). * used to embed images).
* @param {HTMLElement} node The <object> node to check. * @param {HTMLElement} node The <object> node to check.
* @return {boolean} Whether the node appears to be a plugin. * @return {boolean} Whether the node appears to be a plugin.
* @private * @private
*/ */
var objectNodeIsPlugin = function(node) { var objectNodeIsPlugin = function(node) {
return node.hasAttribute('classid') || return node.hasAttribute('classid') ||
(node.hasAttribute('type') && node.type.indexOf('image/') != 0); (node.hasAttribute('type') && node.type.indexOf('image/') != 0);
}; };
/** /**
* Checks whether a node has fallback content, which will be displayed in * Checks whether a node has fallback content, which will be displayed in
* browsers which do not support the required plugin to display the node's * browsers which do not support the required plugin to display the node's
* content. * content.
...@@ -30,14 +30,14 @@ ...@@ -30,14 +30,14 @@
* @return {boolean} Whether the node has any fallback content. * @return {boolean} Whether the node has any fallback content.
* @private * @private
*/ */
var nodeHasFallbackContent = function(node) { var nodeHasFallbackContent = function(node) {
if (node.textContent.trim().length > 0) { if (node.textContent.trim().length > 0) {
return true; return true;
} }
var childrenCount = node.children.length; var childrenCount = node.children.length;
for (var i = 0; i < childrenCount; i++) { for (var i = 0; i < childrenCount; i++) {
var childNode = /** @type {!HTMLElement} */(node.children[i]); var childNode = /** @type {!HTMLElement} */ (node.children[i]);
// Do not consider <param> elements which affect the contents of the // Do not consider <param> elements which affect the contents of the
// parent object node as fallback content. // parent object node as fallback content.
if (childNode.tagName !== 'PARAM') { if (childNode.tagName !== 'PARAM') {
...@@ -46,48 +46,48 @@ ...@@ -46,48 +46,48 @@
} }
return false; return false;
}; };
/** /**
* Finds the child embed element of node, if one exists. * Finds the child embed element of node, if one exists.
* @param {HTMLElement} node The node to check. * @param {HTMLElement} node The node to check.
* @return {HTMLElement} The embed fallback node, if one exists. * @return {HTMLElement} The embed fallback node, if one exists.
* @private * @private
*/ */
var getChildEmbedElement = function(node) { var getChildEmbedElement = function(node) {
var childrenCount = node.children.length; var childrenCount = node.children.length;
if (childrenCount == 0) { if (childrenCount == 0) {
return null; return null;
} }
for (var i = 0; i < childrenCount; i++) { for (var i = 0; i < childrenCount; i++) {
var childNode = /** @type {!HTMLElement} */(node.children[i]); var childNode = /** @type {!HTMLElement} */ (node.children[i]);
if (childNode.tagName === 'EMBED') { if (childNode.tagName === 'EMBED') {
return childNode; return childNode;
} }
} }
return null; return null;
}; };
/** /**
* Checks if an embed node explicitly defines the content type to be flash. * Checks if an embed node explicitly defines the content type to be flash.
* @param {HTMLElement} node The node to check. * @param {HTMLElement} node The node to check.
* @return {boolean} Whether the node is known to be flash content. * @return {boolean} Whether the node is known to be flash content.
* @private * @private
*/ */
var embedNodeIsKnownFlashContent = function(node) { var embedNodeIsKnownFlashContent = function(node) {
return node.hasAttribute('type') && return node.hasAttribute('type') &&
(node.type.indexOf('application/x-shockwave-flash') == 0 || (node.type.indexOf('application/x-shockwave-flash') == 0 ||
node.type.indexOf('application/vnd.adobe.flash-movie') == 0); node.type.indexOf('application/vnd.adobe.flash-movie') == 0);
}; };
/** /**
* Checks whether a plugin is supported. A supported plugin must have fallback * Checks whether a plugin is supported. A supported plugin must have fallback
* content and that fallback content must not be known flash content. * content and that fallback content must not be known flash content.
* @param {HTMLElement} node The node to check. * @param {HTMLElement} node The node to check.
* @return {boolean} Whether the node is supported. * @return {boolean} Whether the node is supported.
* @private * @private
*/ */
var pluginNodeIsSupported = function(node) { var pluginNodeIsSupported = function(node) {
if (!nodeHasFallbackContent(node)) { if (!nodeHasFallbackContent(node)) {
return false; return false;
} }
...@@ -98,21 +98,21 @@ ...@@ -98,21 +98,21 @@
} }
return true; return true;
}; };
/** /**
* Returns a list of plugin elements in the document that have either no * Returns a list of plugin elements in the document that have either no
* fallback content or have fallback content that is explicitly defined as * fallback content or have fallback content that is explicitly defined as
* flash. For nested plugins, only the innermost plugin element is returned. * flash. For nested plugins, only the innermost plugin element is returned.
* @return {!Array<!HTMLElement>} A list of plugin elements. * @return {!Array<!HTMLElement>} A list of plugin elements.
* @private * @private
*/ */
var findPluginNodesWithoutFallback = function() { var findPluginNodesWithoutFallback = function() {
var i, pluginNodes = []; var i, pluginNodes = [];
var objects = document.getElementsByTagName('object'); var objects = document.getElementsByTagName('object');
var objectCount = objects.length; var objectCount = objects.length;
for (i = 0; i < objectCount; i++) { for (i = 0; i < objectCount; i++) {
var object = /** @type {!HTMLElement} */(objects[i]); var object = /** @type {!HTMLElement} */ (objects[i]);
if (objectNodeIsPlugin(object) && !pluginNodeIsSupported(object)) { if (objectNodeIsPlugin(object) && !pluginNodeIsSupported(object)) {
pluginNodes.push(object); pluginNodes.push(object);
} }
...@@ -120,18 +120,18 @@ ...@@ -120,18 +120,18 @@
var applets = document.getElementsByTagName('applet'); var applets = document.getElementsByTagName('applet');
var appletsCount = applets.length; var appletsCount = applets.length;
for (i = 0; i < appletsCount; i++) { for (i = 0; i < appletsCount; i++) {
var applet = /** @type {!HTMLElement} */(applets[i]); var applet = /** @type {!HTMLElement} */ (applets[i]);
if (!pluginNodeIsSupported(applet)) { if (!pluginNodeIsSupported(applet)) {
pluginNodes.push(applet); pluginNodes.push(applet);
} }
} }
return pluginNodes; return pluginNodes;
}; };
/* Data-URL version of plugin_blocked_android.png. Served this way rather /* Data-URL version of plugin_blocked_android.png. Served this way rather
* than with an intercepted URL to avoid messing up https pages. * than with an intercepted URL to avoid messing up https pages.
*/ */
var imageData = var imageData =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAQAAABLCVATAAAD' + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAQAAABLCVATAAAD' +
'aklEQVR4Xn2Wz2tcVRTHP/e+O28mMxONJKlF4kIkP4luXFgQuuxCBaG41IWrLupOXLur+A' + 'aklEQVR4Xn2Wz2tcVRTHP/e+O28mMxONJKlF4kIkP4luXFgQuuxCBaG41IWrLupOXLur+A' +
'e4cmV3LiS6qujSLgq2CIKQUqS2YnWsRkzGSTIz7zyHw+EdchnkcOd+7+OeT84578tMwmet' + 'e4cmV3LiS6qujSLgq2CIKQUqS2YnWsRkzGSTIz7zyHw+EdchnkcOd+7+OeT84578tMwmet' +
...@@ -152,13 +152,13 @@ ...@@ -152,13 +152,13 @@
'yepFOFy5fu1agI9XH71RbRWRrDmHOhrfLYrx9ndv3Wz98R+P7LgG2uyMvgAAAABJRU5Erk' + 'yepFOFy5fu1agI9XH71RbRWRrDmHOhrfLYrx9ndv3Wz98R+P7LgG2uyMvgAAAABJRU5Erk' +
'Jggg=='; 'Jggg==';
/** /**
* Returns the first <embed> child of the given node, if any. * Returns the first <embed> child of the given node, if any.
* @param {Node} node The node to check. * @param {Node} node The node to check.
* @return {HTMLElement} The first <embed> child, or null. * @return {HTMLElement} The first <embed> child, or null.
* @private * @private
*/ */
var getEmbedChild = function(node) { var getEmbedChild = function(node) {
if (node.hasChildNodes()) { if (node.hasChildNodes()) {
for (var i = 0; i < node.childNodes.length; i++) { for (var i = 0; i < node.childNodes.length; i++) {
if (node.childNodes[i].nodeName === 'EMBED') { if (node.childNodes[i].nodeName === 'EMBED') {
...@@ -167,9 +167,9 @@ ...@@ -167,9 +167,9 @@
} }
} }
return null; return null;
}; };
/** /**
* Returns the size for the given plugin element. For the common * Returns the size for the given plugin element. For the common
* pattern of an IE-specific <object> wrapping an all-other-browsers <embed>, * pattern of an IE-specific <object> wrapping an all-other-browsers <embed>,
* the object doesn't have real style info (most notably size), so this uses * the object doesn't have real style info (most notably size), so this uses
...@@ -178,7 +178,7 @@ ...@@ -178,7 +178,7 @@
* @return {Object} The size (width and height) for the plugin element. * @return {Object} The size (width and height) for the plugin element.
* @private * @private
*/ */
var getPluginSize = function(plugin) { var getPluginSize = function(plugin) {
var style; var style;
// For the common pattern of an IE-specific <object> wrapping an // For the common pattern of an IE-specific <object> wrapping an
// all-other-browsers <embed>, the object doesn't have real style info // all-other-browsers <embed>, the object doesn't have real style info
...@@ -203,13 +203,10 @@ ...@@ -203,13 +203,10 @@
} }
} }
return { return {'width': width, 'height': height};
'width': width, };
'height': height
};
};
/** /**
* Checks whether an element is "significant". Whether a plugin is * Checks whether an element is "significant". Whether a plugin is
* "significant" is a heuristic that attempts to determine if it's a critical * "significant" is a heuristic that attempts to determine if it's a critical
* visual element for the page (i.e., not invisible, or an incidental ad). * visual element for the page (i.e., not invisible, or an incidental ad).
...@@ -217,7 +214,7 @@ ...@@ -217,7 +214,7 @@
* @return {boolean} Whether the node is significant. * @return {boolean} Whether the node is significant.
* @private * @private
*/ */
var isSignificantPlugin = function(plugin) { var isSignificantPlugin = function(plugin) {
var windowWidth = window.innerWidth; var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight; var windowHeight = window.innerHeight;
var pluginSize = getPluginSize(plugin); var pluginSize = getPluginSize(plugin);
...@@ -232,16 +229,16 @@ ...@@ -232,16 +229,16 @@
pluginHeight > minSize) || pluginHeight > minSize) ||
(pluginHeight > windowHeight * significantFraction && (pluginHeight > windowHeight * significantFraction &&
pluginWidth > minSize); pluginWidth > minSize);
}; };
/** /**
* Walks the list of detected plugin elements, adding a placeholder to any * Walks the list of detected plugin elements, adding a placeholder to any
* that are "significant" (see above). * that are "significant" (see above).
* @param {string} message The message to show in the placeholder. * @param {string} message The message to show in the placeholder.
* @param {!Array<!HTMLElement>} plugins A list of plugin elements. * @param {!Array<!HTMLElement>} plugins A list of plugin elements.
* @private * @private
*/ */
var addPluginPlaceholders = function(message, plugins) { var addPluginPlaceholders = function(message, plugins) {
var i; var i;
for (i = 0; i < plugins.length; i++) { for (i = 0; i < plugins.length; i++) {
var plugin = plugins[i]; var plugin = plugins[i];
...@@ -309,14 +306,14 @@ ...@@ -309,14 +306,14 @@
plugin.insertBefore(placeholder, plugin.firstChild); plugin.insertBefore(placeholder, plugin.firstChild);
} }
}; };
// Add placeholders for plugin content. // Add placeholders for plugin content.
var plugins = findPluginNodesWithoutFallback(); var plugins = findPluginNodesWithoutFallback();
if (plugins.length > 0) { if (plugins.length > 0) {
// web::GetDocumentEndScriptForAllFrames replaces // web::GetDocumentEndScriptForAllFrames replaces
// $(PLUGIN_NOT_SUPPORTED_TEXT) with approproate string upon injection. // $(PLUGIN_NOT_SUPPORTED_TEXT) with approproate string upon injection.
addPluginPlaceholders('$(PLUGIN_NOT_SUPPORTED_TEXT)', plugins); addPluginPlaceholders('$(PLUGIN_NOT_SUPPORTED_TEXT)', plugins);
} }
}()); // End of anonymous object }()); // End of anonymous object
...@@ -48,7 +48,7 @@ __crPostRequestWorkaround.runPostRequest = function( ...@@ -48,7 +48,7 @@ __crPostRequestWorkaround.runPostRequest = function(
byteArrays.push(byteArray); byteArrays.push(byteArray);
} }
return new Blob(byteArrays, {type: contentType}); return new Blob(byteArrays, {type: contentType});
} };
/** /**
* Creates and executes a POST request. * Creates and executes a POST request.
...@@ -57,6 +57,7 @@ __crPostRequestWorkaround.runPostRequest = function( ...@@ -57,6 +57,7 @@ __crPostRequestWorkaround.runPostRequest = function(
* Each header value must be expressed as a key-value pair in this object. * Each header value must be expressed as a key-value pair in this object.
* @param {string} body Request body encoded with Base64. * @param {string} body Request body encoded with Base64.
* @param {string} contentType Content-Type header value. * @param {string} contentType Content-Type header value.
* @return {number | string}
*/ */
var createAndSendPostRequest = function(url, headers, body, contentType) { var createAndSendPostRequest = function(url, headers, body, contentType) {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
...@@ -72,14 +73,15 @@ __crPostRequestWorkaround.runPostRequest = function( ...@@ -72,14 +73,15 @@ __crPostRequestWorkaround.runPostRequest = function(
throw request.status; throw request.status;
} }
return request.responseText; return request.responseText;
} };
document.open(); document.open();
try { try {
document.write(createAndSendPostRequest(url, headers, body, contentType)); document.write(/** @type {string} */ (
window.webkit.messageHandlers['POSTSuccessHandler'].postMessage(""); createAndSendPostRequest(url, headers, body, contentType)));
} catch(error) { window.webkit.messageHandlers['POSTSuccessHandler'].postMessage('');
} catch (error) {
window.webkit.messageHandlers['POSTErrorHandler'].postMessage(error); window.webkit.messageHandlers['POSTErrorHandler'].postMessage(error);
} }
document.close(); document.close();
} };
...@@ -11,28 +11,27 @@ goog.provide('__crWeb.scrollWorkaround'); ...@@ -11,28 +11,27 @@ goog.provide('__crWeb.scrollWorkaround');
/** Beginning of anonymous object */ /** Beginning of anonymous object */
(function() { (function() {
/** @private */ /** @private */
var webViewScrollViewIsDragging_ = false; var webViewScrollViewIsDragging_ = false;
/** /**
* Tracks whether user is in the middle of scrolling/dragging. If user is * Tracks whether user is in the middle of scrolling/dragging. If user is
* scrolling, ignore window.scrollTo() until user stops scrolling. * scrolling, ignore window.scrollTo() until user stops scrolling.
*/ */
__gCrWeb['setWebViewScrollViewIsDragging'] = function(state) { __gCrWeb['setWebViewScrollViewIsDragging'] = function(state) {
webViewScrollViewIsDragging_ = state; webViewScrollViewIsDragging_ = state;
}; };
/** @private */ /** @private */
var originalWindowScrollTo_ = window.scrollTo; var originalWindowScrollTo_ = window.scrollTo;
/** /**
* Wraps the original window.scrollTo() to suppress it as long as * Wraps the original window.scrollTo() to suppress it as long as
* webViewScrollViewIsDragging is true. * webViewScrollViewIsDragging is true.
*/ */
window.scrollTo = function(x, y) { window.scrollTo = function(x, y) {
if (webViewScrollViewIsDragging_) if (webViewScrollViewIsDragging_) return;
return;
originalWindowScrollTo_(x, y); originalWindowScrollTo_(x, y);
}; };
}()) // End of anonymouse object }()); // End of anonymous object
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
// Script to set windowId. // Script to set windowId.
(function() { (function() {
// CRWJSWindowIDManager replaces $(WINDOW_ID) with appropriate string upon // CRWJSWindowIDManager replaces $(WINDOW_ID) with appropriate string upon
// injection. // injection.
__gCrWeb['windowId'] = '$(WINDOW_ID)'; __gCrWeb['windowId'] = '$(WINDOW_ID)';
// Send messages queued since message.js injection. // Send messages queued since message.js injection.
__gCrWeb.message.invokeQueues(); __gCrWeb.message.invokeQueues();
}()); }());
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