summaryrefslogtreecommitdiffstats
path: root/remoting/webapp
diff options
context:
space:
mode:
authorjamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-02 00:39:53 +0000
committerjamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-02 00:39:53 +0000
commit54e18a5e0c3dd927b08791ed987df5db1f59ba21 (patch)
tree29f131042981574e612097aa74e3615527708ad7 /remoting/webapp
parentd5f51841e615700231b131d2a4de43fe09c29c91 (diff)
downloadchromium_src-54e18a5e0c3dd927b08791ed987df5db1f59ba21.zip
chromium_src-54e18a5e0c3dd927b08791ed987df5db1f59ba21.tar.gz
chromium_src-54e18a5e0c3dd927b08791ed987df5db1f59ba21.tar.bz2
Refactored innerText vs. innerHTML in l10n.js and removed other uses of innerHTML.
BUG=130582 TEST=Manual Review URL: https://chromiumcodereview.appspot.com/10501005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140141 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/webapp')
-rw-r--r--remoting/webapp/client_screen.js2
-rw-r--r--remoting/webapp/connection_history.js2
-rw-r--r--remoting/webapp/host_list.js2
-rw-r--r--remoting/webapp/host_setup_dialog.js2
-rw-r--r--remoting/webapp/host_table_entry.js4
-rw-r--r--remoting/webapp/l10n.js58
6 files changed, 25 insertions, 45 deletions
diff --git a/remoting/webapp/client_screen.js b/remoting/webapp/client_screen.js
index 2bc2d3d..baa7e56 100644
--- a/remoting/webapp/client_screen.js
+++ b/remoting/webapp/client_screen.js
@@ -477,7 +477,7 @@ remoting.connectMe2Me = function(hostId, retryIfOffline) {
return;
}
var message = document.getElementById('pin-message');
- l10n.localizeElementToText(message, host.hostName);
+ l10n.localizeElement(message, host.hostName);
remoting.setMode(remoting.AppMode.CLIENT_PIN_PROMPT);
};
diff --git a/remoting/webapp/connection_history.js b/remoting/webapp/connection_history.js
index da28701..dc10d22 100644
--- a/remoting/webapp/connection_history.js
+++ b/remoting/webapp/connection_history.js
@@ -165,7 +165,7 @@ remoting.ConnectionHistory.prototype.load = function() {
var history = [];
// Remove existing entries from the DOM and repopulate.
// TODO(jamiewalch): Enforce the filter.
- this.historyEntries_.innerHTML = '';
+ this.historyEntries_.innerText = '';
for (var i in history) {
var connection = new remoting.ConnectionHistory.Entry(history[i]);
if (connection.valid) {
diff --git a/remoting/webapp/host_list.js b/remoting/webapp/host_list.js
index d997e5b..0061068 100644
--- a/remoting/webapp/host_list.js
+++ b/remoting/webapp/host_list.js
@@ -171,7 +171,7 @@ remoting.HostList.prototype.parseHostListResponse_ = function(onDone, xhr) {
* @return {void} Nothing.
*/
remoting.HostList.prototype.display = function(thisHostId) {
- this.table_.innerHTML = '';
+ this.table_.innerText = '';
this.errorDiv_.innerText = '';
this.hostTableEntries_ = [];
diff --git a/remoting/webapp/host_setup_dialog.js b/remoting/webapp/host_setup_dialog.js
index 51c713d..1e80910 100644
--- a/remoting/webapp/host_setup_dialog.js
+++ b/remoting/webapp/host_setup_dialog.js
@@ -227,7 +227,7 @@ remoting.HostSetupDialog.prototype.updateState_ = function() {
if (opt_tag2) {
l10n.localizeElementFromTag(messageDiv, opt_tag2);
} else {
- messageDiv.innerHTML = '';
+ messageDiv.innerText = '';
}
remoting.setMode(remoting.AppMode.HOST_SETUP_DONE);
}
diff --git a/remoting/webapp/host_table_entry.js b/remoting/webapp/host_table_entry.js
index ecda62f..4190b68 100644
--- a/remoting/webapp/host_table_entry.js
+++ b/remoting/webapp/host_table_entry.js
@@ -221,7 +221,7 @@ remoting.HostTableEntry.prototype.beginRename_ = function() {
var editBox = /** @type {HTMLInputElement} */ document.createElement('input');
editBox.type = 'text';
editBox.value = this.host.hostName;
- this.hostNameCell_.innerHTML = '';
+ this.hostNameCell_.innerText = '';
this.hostNameCell_.appendChild(editBox);
editBox.select();
@@ -343,7 +343,7 @@ remoting.HostTableEntry.prototype.setHostName_ = function() {
this.host.hostName);
}
hostNameNode.classList.add('host-list-label');
- this.hostNameCell_.innerHTML = ''; // Remove previous contents (if any).
+ this.hostNameCell_.innerText = ''; // Remove previous contents (if any).
this.hostNameCell_.appendChild(hostNameNode);
};
diff --git a/remoting/webapp/l10n.js b/remoting/webapp/l10n.js
index 9756b87..467a570 100644
--- a/remoting/webapp/l10n.js
+++ b/remoting/webapp/l10n.js
@@ -12,46 +12,19 @@ var l10n = l10n || {};
* @param {string} tag The localization tag.
* @param {(string|Array)=} opt_substitutions An optional set of substitution
* strings corresponding to the "placeholders" attributes in messages.json.
+ * @param {boolean=} opt_asHtml If true, set innerHTML instead of innerText.
+ * This parameter should be used with caution.
* @return {boolean} True if the localization was successful; false otherwise.
*/
-l10n.localizeElementFromTag = function(element, tag, opt_substitutions) {
+l10n.localizeElementFromTag = function(element, tag, opt_substitutions,
+ opt_asHtml) {
var translation = chrome.i18n.getMessage(tag, opt_substitutions);
if (translation) {
- element.innerHTML = translation;
- } else {
- console.error('Missing translation for "' + tag + '":', element);
- }
- return translation != null;
-};
-
-/**
- * Localize an element by setting its innerText according to its i18n-content
- * attribute, and an optional set of substitutions.
- * @param {Element} element The element to localize.
- * @param {(string|Array)=} opt_substitutions An optional set of substitution
- * strings corresponding to the "placeholders" attributes in messages.json.
- * @return {boolean} True if the localization was successful; false otherwise.
- */
-l10n.localizeElement = function(element, opt_substitutions) {
- var tag = element.getAttribute('i18n-content');
- return l10n.localizeElementFromTag(element, tag, opt_substitutions);
-};
-
-// TODO(simonmorris): To simplify a merge, the next two methods were
-// cut-and-pasted from the previous two. Refactor.
-/**
- * Localize an element by setting its innerText according to the specified tag
- * and an optional set of substitutions.
- * @param {Element} element The element to localize.
- * @param {string} tag The localization tag.
- * @param {(string|Array)=} opt_substitutions An optional set of substitution
- * strings corresponding to the "placeholders" attributes in messages.json.
- * @return {boolean} True if the localization was successful; false otherwise.
- */
-l10n.localizeElementToTextFromTag = function(element, tag, opt_substitutions) {
- var translation = chrome.i18n.getMessage(tag, opt_substitutions);
- if (translation) {
- element.innerText = translation;
+ if (opt_asHtml) {
+ element.innerHTML = translation;
+ } else {
+ element.innerText = translation;
+ }
} else {
console.error('Missing translation for "' + tag + '":', element);
}
@@ -64,16 +37,23 @@ l10n.localizeElementToTextFromTag = function(element, tag, opt_substitutions) {
* @param {Element} element The element to localize.
* @param {(string|Array)=} opt_substitutions An optional set of substitution
* strings corresponding to the "placeholders" attributes in messages.json.
+ * @param {boolean=} opt_asHtml If true, set innerHTML instead of innerText.
+ * This parameter should be used with caution.
* @return {boolean} True if the localization was successful; false otherwise.
*/
-l10n.localizeElementToText = function(element, opt_substitutions) {
+l10n.localizeElement = function(element, opt_substitutions, opt_asHtml) {
var tag = element.getAttribute('i18n-content');
- return l10n.localizeElementToTextFromTag(element, tag, opt_substitutions);
+ return l10n.localizeElementFromTag(element, tag, opt_substitutions,
+ opt_asHtml);
};
/**
* Localize all tags with the i18n-content attribute, using i18n-data-n
* attributes to specify any placeholder substitutions.
+ *
+ * Because we use i18n-value attributes to implement translations of rich
+ * content (including paragraphs with hyperlinks), we localize these as
+ * HTML iff there are any substitutions.
*/
l10n.localize = function() {
var elements = document.querySelectorAll('[i18n-content]');
@@ -91,7 +71,7 @@ l10n.localize = function() {
break;
}
}
- l10n.localizeElement(element, substitutions);
+ l10n.localizeElement(element, substitutions, !!substitutions);
// Localize tool-tips
// TODO(jamiewalch): Move this logic to the html document.
var editButton = document.getElementById('this-host-rename');