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

Unified Diff: chrome/browser/resources/shared/js/load_time_data.js

Issue 11962043: Move webui resources from chrome\browser\resources\shared to ui\webui\resources. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/shared/js/load_time_data.js
===================================================================
--- chrome/browser/resources/shared/js/load_time_data.js (revision 177292)
+++ chrome/browser/resources/shared/js/load_time_data.js (working copy)
@@ -1,138 +0,0 @@
-// Copyright (c) 2012 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 This file defines a singleton which provides access to all data
- * that is available as soon as the page's resources are loaded (before DOM
- * content has finished loading). This data includes both localized strings and
- * any data that is important to have ready from a very early stage (e.g. things
- * that must be displayed right away).
- */
-
-var loadTimeData;
-
-(function() {
- 'use strict';
-
- function LoadTimeData() {
- }
-
- LoadTimeData.prototype = {
- /**
- * Sets the backing object.
- * @param {Object} value The de-serialized page data.
- */
- set data(value) {
- expect(!this.data_, 'Re-setting data.');
- this.data_ = value;
- },
-
- /**
- * @return {boolean} True if |id| is a key in the dictionary.
- */
- valueExists: function(id) {
- return id in this.data_;
- },
-
- /**
- * Fetches a value, expecting that it exists.
- * @param {string} id The key that identifies the desired value.
- * @return {*} The corresponding value.
- */
- getValue: function(id) {
- expect(this.data_, 'No data. Did you remember to include strings.js?');
- var value = this.data_[id];
- expect(typeof value != 'undefined', 'Could not find value for ' + id);
- return value;
- },
-
- /**
- * As above, but also makes sure that the value is a string.
- * @param {string} id The key that identifies the desired string.
- * @return {string} The corresponding string value.
- */
- getString: function(id) {
- var value = this.getValue(id);
- expectIsType(id, value, 'string');
- return value;
- },
-
- /**
- * Returns a formatted localized string where $1 to $9 are replaced by the
- * second to the tenth argument.
- * @param {string} id The ID of the string we want.
- * @param {...string} The extra values to include in the formatted output.
- * @return {string} The formatted string.
- */
- getStringF: function(id) {
- var value = this.getString(id);
- if (!value)
- return;
-
- var varArgs = arguments;
- return value.replace(/\$[$1-9]/g, function(m) {
- return m == '$$' ? '$' : varArgs[m[1]];
- });
- },
-
- /**
- * As above, but also makes sure that the value is a boolean.
- * @param {string} id The key that identifies the desired boolean.
- * @return {boolean} The corresponding boolean value.
- */
- getBoolean: function(id) {
- var value = this.getValue(id);
- expectIsType(id, value, 'boolean');
- return value;
- },
-
- /**
- * As above, but also makes sure that the value is an integer.
- * @param {string} id The key that identifies the desired number.
- * @return {number} The corresponding number value.
- */
- getInteger: function(id) {
- var value = this.getValue(id);
- expectIsType(id, value, 'number');
- expect(value == Math.floor(value), 'Number isn\'t integer: ' + value);
- return value;
- },
-
- /**
- * Override values in loadTimeData with the values found in |replacements|.
- * @param {Object} replacements The dictionary object of keys to replace.
- */
- overrideValues: function(replacements) {
- expect(typeof replacements == 'object',
- 'Replacements must be a dictionary object.');
- for (var key in replacements) {
- this.data_[key] = replacements[key];
- }
- }
- };
-
- /**
- * Checks condition, displays error message if expectation fails.
- * @param {*} condition The condition to check for truthiness.
- * @param {string} message The message to display if the check fails.
- */
- function expect(condition, message) {
- if (!condition)
- console.error(message);
- }
-
- /**
- * Checks that the given value has the given type.
- * @param {string} id The id of the value (only used for error message).
- * @param {*} value The value to check the type on.
- * @param {string} type The type we expect |value| to be.
- */
- function expectIsType(id, value, type) {
- expect(typeof value == type, '[' + value + '] (' + id +
- ') is not a ' + type);
- }
-
- expect(!loadTimeData, 'should only include this file once');
- loadTimeData = new LoadTimeData;
-})();
« no previous file with comments | « chrome/browser/resources/shared/js/jstemplate_compiled.js ('k') | chrome/browser/resources/shared/js/local_strings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698