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

Unified Diff: chrome/browser/resources/chromeos/chromevox/chromevox/injected/api.js

Issue 2754363003: Do more strict checking when calling into MathJaX (Closed)
Patch Set: Address nits. Created 3 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/resources/chromeos/chromevox/cvox2/injected/loader.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/chromeos/chromevox/chromevox/injected/api.js
diff --git a/chrome/browser/resources/chromeos/chromevox/chromevox/injected/api.js b/chrome/browser/resources/chromeos/chromevox/chromevox/injected/api.js
index ee366e312521a038ba2180f0a8d6bef52f697750..c4c3cf6d0ff797bb8b4b651550cd15b98e03ff86 100644
--- a/chrome/browser/resources/chromeos/chromevox/chromevox/injected/api.js
+++ b/chrome/browser/resources/chromeos/chromevox/chromevox/injected/api.js
@@ -128,20 +128,41 @@ if (typeof(goog) != 'undefined' && goog.require) {
callAsync_(message, callback);
};
+ /**
+ * Gets an object given a dotted namespace object path.
+ * @param {string} path
+ * @return {*}
+ */
+ function getObjectByName(path) {
+ var pieces = path.split('.');
+ var resolved = window;
+ for (var i = 0; i < pieces.length; i++) {
+ resolved = resolved[pieces[i]];
+ if (!resolved) {
+ return null;
+ }
+ }
+ return resolved;
+ }
+
/**
* Maybe enable MathJaX support.
*/
- function maybeEnableMathJaX() {
- if (!MathJax || !MathJax.Hub || !MathJax.Hub.Register ||
- !MathJax.Hub.Register.LoadHook)
+ function maybeEnableMathJaX() {
+ if (!getObjectByName('MathJax.Hub.Register.LoadHook') ||
+ !getObjectByName('MathJax.Ajax.Require')) {
return;
+ }
- MathJax.Hub.Register.LoadHook(
- '[a11y]/explorer.js',
- function() {
- MathJax.Extension.explorer.Enable(true, true);
- });
+ MathJax.Hub.Register.LoadHook('[a11y]/explorer.js', function() {
+ // |explorer| is an object instance, so we get it to call an instance
+ // |method.
+ var explorer = getObjectByName('MathJax.Extension.explorer');
+ if (explorer.Enable) {
+ explorer.Enable(true, true);
+ }
+ });
MathJax.Ajax.Require('[a11y]/explorer.js');
}
« no previous file with comments | « no previous file | chrome/browser/resources/chromeos/chromevox/cvox2/injected/loader.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698