Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: ios/web/web_state/js/resources/common.js

Issue 2807213003: Move stringify, form, navigation and scroll methods out of core.js. (Closed)
Patch Set: Re-upload patch after rebase-update in local branch Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/web/web_state/js/core_js_unittest.mm ('k') | ios/web/web_state/js/resources/core.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file provides common methods that can be shared by other JavaScripts. 5 // This file provides common methods that can be shared by other JavaScripts.
6 6
7 goog.provide('__crWeb.common'); 7 goog.provide('__crWeb.common');
8 8
9 goog.require('__crWeb.base'); 9 goog.require('__crWeb.base');
10 10
11 11
12 /** @typedef {HTMLInputElement|HTMLTextAreaElement|HTMLSelectElement} */ 12 /** @typedef {HTMLInputElement|HTMLTextAreaElement|HTMLSelectElement} */
13 var FormControlElement; 13 var FormControlElement;
14 14
15 /** 15 /**
16 * Namespace for this file. It depends on |__gCrWeb| having already been 16 * Namespace for this file. It depends on |__gCrWeb| having already been
17 * injected. String 'common' is used in |__gCrWeb['common']| as it needs to be 17 * injected. String 'common' is used in |__gCrWeb['common']| as it needs to be
18 * accessed in Objective-C code. 18 * accessed in Objective-C code.
19 */ 19 */
20 __gCrWeb.common = {}; 20 __gCrWeb.common = {};
21 21
22 // Store common namespace object in a global __gCrWeb object referenced by a 22 // Store common namespace object in a global __gCrWeb object referenced by a
23 // string, so it does not get renamed by closure compiler during the 23 // string, so it does not get renamed by closure compiler during the
24 // minification. 24 // minification.
25 __gCrWeb['common'] = __gCrWeb.common; 25 __gCrWeb['common'] = __gCrWeb.common;
26 26
27 /* Beginning of anonymous object. */ 27 /* Beginning of anonymous object. */
28 (function() { 28 (function() {
29
29 /** 30 /**
30 * JSON safe object to protect against custom implementation of Object.toJSON 31 * JSON safe object to protect against custom implementation of Object.toJSON
31 * in host pages. 32 * in host pages.
32 * @constructor 33 * @constructor
33 */ 34 */
34 __gCrWeb.common.JSONSafeObject = function JSONSafeObject() { 35 __gCrWeb.common.JSONSafeObject = function JSONSafeObject() {
35 }; 36 };
36 37
37 /** 38 /**
38 * Protect against custom implementation of Object.toJSON in host pages. 39 * Protect against custom implementation of Object.toJSON in host pages.
39 */ 40 */
40 __gCrWeb.common.JSONSafeObject.prototype['toJSON'] = null; 41 __gCrWeb.common.JSONSafeObject.prototype['toJSON'] = null;
41 42
42 /** 43 /**
43 * Retain the original JSON.stringify method where possible to reduce the 44 * Retain the original JSON.stringify method where possible to reduce the
44 * impact of sites overriding it 45 * impact of sites overriding it
45 */ 46 */
46 __gCrWeb.common.JSONStringify = JSON.stringify; 47 __gCrWeb.common.JSONStringify = JSON.stringify;
47 48
48 /** 49 /**
50 * Returns a string that is formatted according to the JSON syntax rules.
51 * This is equivalent to the built-in JSON.stringify() function, but is
52 * less likely to be overridden by the website itself. Prefer the private
53 * {@code __gcrWeb.common.JSONStringify} whenever possible instead of using
54 * this public function. The |__gCrWeb| object itself does not use it; it uses
55 * its private counterpart instead.
56 */
57 __gCrWeb['stringify'] = function(value) {
58 if (value === null)
59 return 'null';
60 if (value === undefined)
61 return 'undefined';
62 if (typeof(value.toJSON) == 'function') {
63 // Prevents websites from changing stringify's behavior by adding the
64 // method toJSON() by temporarily removing it.
65 var originalToJSON = value.toJSON;
66 value.toJSON = undefined;
67 var stringifiedValue = __gCrWeb.common.JSONStringify(value);
68 value.toJSON = originalToJSON;
69 return stringifiedValue;
70 }
71 return __gCrWeb.common.JSONStringify(value);
72 };
73
74 /**
49 * Prefix used in references to form elements that have no 'id' or 'name' 75 * Prefix used in references to form elements that have no 'id' or 'name'
50 */ 76 */
51 __gCrWeb.common.kNamelessFormIDPrefix = 'gChrome~'; 77 __gCrWeb.common.kNamelessFormIDPrefix = 'gChrome~';
52 78
53 /** 79 /**
54 * Tests an element's visiblity. This test is expensive so should be used 80 * Tests an element's visiblity. This test is expensive so should be used
55 * sparingly. 81 * sparingly.
56 * @param {Element} element A DOM element. 82 * @param {Element} element A DOM element.
57 * @return {boolean} true if the |element| is currently part of the visible 83 * @return {boolean} true if the |element| is currently part of the visible
58 * DOM. 84 * DOM.
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 __gCrWeb.common.updatePluginPlaceholders = function() { 708 __gCrWeb.common.updatePluginPlaceholders = function() {
683 var plugins = findPluginNodesWithoutFallback_(); 709 var plugins = findPluginNodesWithoutFallback_();
684 if (plugins.length > 0) { 710 if (plugins.length > 0) {
685 // Store the list of plugins in a known place for the replacement script 711 // Store the list of plugins in a known place for the replacement script
686 // to use, then trigger it. 712 // to use, then trigger it.
687 __gCrWeb['placeholderTargetPlugins'] = plugins; 713 __gCrWeb['placeholderTargetPlugins'] = plugins;
688 return true; 714 return true;
689 } 715 }
690 return false; 716 return false;
691 }; 717 };
718
692 }()); // End of anonymous object 719 }()); // End of anonymous object
OLDNEW
« no previous file with comments | « ios/web/web_state/js/core_js_unittest.mm ('k') | ios/web/web_state/js/resources/core.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698