| Index: chrome/common/extensions/docs/examples/extensions/storage_api_devtools/scripts/util.js
|
| ===================================================================
|
| --- chrome/common/extensions/docs/examples/extensions/storage_api_devtools/scripts/util.js (revision 0)
|
| +++ chrome/common/extensions/docs/examples/extensions/storage_api_devtools/scripts/util.js (revision 0)
|
| @@ -0,0 +1,74 @@
|
| +// Copyright 2013 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.
|
| +
|
| +// Escape a string so that it can be safely injected into the script being
|
| +// evaled.
|
| +function evalEscapeString(str) {
|
| + return str.replace(/\\/g, '\\\\').replace(/'/g, '\\\'');
|
| +}
|
| +
|
| +// Evaluate a script in the context of the inspected window.
|
| +// Before evaluating the script, some substitutions will be done to allow
|
| +// parameter passing. For example:
|
| +// <REPLACE_WITH_EXTENSION_ID_BEFORE_EVAL> ->
|
| +// chrome.i18n.getMessage('@@extension_id')
|
| +// <REPLACE_WITH_EXTRA_PARAMETER_BEFORE_EVAL:name> ->
|
| +// extra.name
|
| +// |path|: File path of the script.
|
| +// |options|: See the options parameter of
|
| +// chrome.devtools.inspectedWindow.eval (currently undocumented).
|
| +// |extra|: A dictionary containing extra parameters to inject into the
|
| +// script before eval. Parameter values will be converted to
|
| +// strings.
|
| +// |callback|: See the callback parameter of
|
| +// chrome.devtools.inspectedWindow.eval.
|
| +
|
| +function evalScript(path, options, extra, callback) {
|
| + var xhr = new XMLHttpRequest();
|
| + xhr.open('GET', path, true);
|
| + xhr.onreadystatechange = (function() {
|
| + if (xhr.readyState == XMLHttpRequest.DONE) {
|
| + if (xhr.status == 200) {
|
| + var script = xhr.responseText.replace(
|
| + '<REPLACE_WITH_EXTENSION_ID_BEFORE_EVAL>',
|
| + chrome.i18n.getMessage('@@extension_id'));
|
| + if (extra)
|
| + Object.keys(extra).forEach(function(key) {
|
| + script = script.replace(
|
| + '<REPLACE_WITH_EXTRA_PARAMETER_BEFORE_EVAL:' + key + '>',
|
| + evalEscapeString(extra[key].toString()));
|
| + });
|
| + chrome.devtools.inspectedWindow.eval(script, options, callback);
|
| + }
|
| + xhr = null;
|
| + }
|
| + });
|
| + xhr.send();
|
| +}
|
| +
|
| +// Workaround of http://crbug.com/178618
|
| +// See also bg.js.
|
| +(function() {
|
| + // We only use get() and set(), and we don't care about lastError.
|
| + function hookChromeStorageGetSet(area, method) {
|
| + chrome.storage[area][method] = (function(firstArgument, callback) {
|
| + var message = {
|
| + name: 'storageAPIWorkaround',
|
| + method: method,
|
| + area: area,
|
| + firstArgument: firstArgument
|
| + };
|
| + var sendMessage = chrome.runtime.sendMessage ||
|
| + chrome.extension.sendMessage;
|
| + sendMessage(message, callback || (function(){}));
|
| + });
|
| + }
|
| +
|
| + ['local', 'sync'].forEach(function(area) {
|
| + ['get', 'set'].forEach(function(method) {
|
| + hookChromeStorageGetSet(area, method);
|
| + });
|
| + });
|
| +})();
|
| +
|
|
|
| Property changes on: chrome/common/extensions/docs/examples/extensions/storage_api_devtools/scripts/util.js
|
| ___________________________________________________________________
|
| Added: svn:mime-type
|
| + text/javascript
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|