| Index: ios/web/web_state/js/resources/form.js
|
| diff --git a/ios/web/web_state/js/resources/form.js b/ios/web/web_state/js/resources/form.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c18d3da91d6ad28a9ac4f1a87251cf393f9a876c
|
| --- /dev/null
|
| +++ b/ios/web/web_state/js/resources/form.js
|
| @@ -0,0 +1,89 @@
|
| +// 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 Adds listeners that are used to handle forms, enabling autofill
|
| + * and the replacement method to dismiss the keyboard needed because of the
|
| + * Autofill keyboard accessory.
|
| + */
|
| +
|
| +goog.provide('__crWeb.form');
|
| +
|
| +goog.require('__crWeb.message');
|
| +
|
| +/** Beginning of anonymous object */
|
| +(function() {
|
| +
|
| + /**
|
| + * Focus and input events for form elements are messaged to the main
|
| + * application for broadcast to CRWWebControllerObservers.
|
| + * This is done with a single event handler for each type being added to the
|
| + * main document element which checks the source element of the event; this
|
| + * is much easier to manage than adding handlers to individual elements.
|
| + * @private
|
| + */
|
| + var formActivity_ = function(evt) {
|
| + var srcElement = evt.srcElement;
|
| + var fieldName = srcElement.name || '';
|
| + var value = srcElement.value || '';
|
| +
|
| + var msg = {
|
| + 'command': 'form.activity',
|
| + 'formName': __gCrWeb.common.getFormIdentifier(evt.srcElement.form),
|
| + 'fieldName': fieldName,
|
| + 'type': evt.type,
|
| + 'value': value
|
| + };
|
| + __gCrWeb.message.invokeOnHost(msg);
|
| + };
|
| +
|
| + /**
|
| + * Focus events performed on the 'capture' phase otherwise they are often
|
| + * not received.
|
| + */
|
| + document.addEventListener('focus', formActivity_, true);
|
| + document.addEventListener('blur', formActivity_, true);
|
| + document.addEventListener('change', formActivity_, true);
|
| +
|
| + /**
|
| + * 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.
|
| + */
|
| + document.addEventListener('input', formActivity_, false);
|
| + document.addEventListener('keyup', formActivity_, false);
|
| +
|
| + /**
|
| + * Capture form submit actions.
|
| + */
|
| + document.addEventListener('submit', function(evt) {
|
| + var action;
|
| + if (evt['defaultPrevented'])
|
| + return;
|
| + action = evt.target.getAttribute('action');
|
| + // Default action is to re-submit to same page.
|
| + if (!action) {
|
| + action = document.location.href;
|
| + }
|
| + __gCrWeb.message.invokeOnHost({
|
| + 'command': 'document.submit',
|
| + 'formName': __gCrWeb.common.getFormIdentifier(evt.srcElement),
|
| + 'href': getFullyQualifiedUrl_(action)
|
| + });
|
| + }, false);
|
| +
|
| + /** @private */
|
| + var getFullyQualifiedUrl_ = function(originalURL) {
|
| + // A dummy anchor (never added to the document) is used to obtain the
|
| + // fully-qualified URL of |originalURL|.
|
| + var anchor = document.createElement('a');
|
| + anchor.href = originalURL;
|
| + return anchor.href;
|
| + };
|
| +
|
| + /** Flush the message queue. */
|
| + if (__gCrWeb.message) {
|
| + __gCrWeb.message.invokeQueues();
|
| + }
|
| +
|
| +}()); // End of anonymous object
|
|
|