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

Unified Diff: chrome/renderer/resources/extensions/last_error.js

Issue 12378077: Attempting to fix problems in 11571014. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 10 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/renderer/resources/extensions/last_error.js
diff --git a/chrome/renderer/resources/extensions/last_error.js b/chrome/renderer/resources/extensions/last_error.js
index 5eb5c01206572febb8b5abc2f14ea5f08a76c772..ac5c719c4be54677b1e74c29c1416457796d42b3 100644
--- a/chrome/renderer/resources/extensions/last_error.js
+++ b/chrome/renderer/resources/extensions/last_error.js
@@ -2,21 +2,56 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-requireNative('runtime');
+var DCHECK = requireNative('logging').DCHECK;
var GetAvailability = requireNative('v8_context').GetAvailability;
+var GetGlobal = requireNative('sendRequest').GetGlobal;
-function set(message) {
+// Utility for setting chrome.*.lastError.
+//
+// A utility here is useful for two reasons:
+// 1. For backwards compatibility we need to set chrome.extension.lastError,
+// but not all contexts actually have access to the extension namespace.
+// 2. When calling across contexts, the global object that gets lastError set
+// needs to be that of the caller. We force callers to explicitly specify
+// the chrome object to try to prevent bugs here.
+
+/**
+ * Sets the last error on |targetChrome| to |message|.
+ */
+function set(message, targetChrome) {
+ DCHECK(targetChrome != undefined);
var errorObject = { 'message': message };
if (GetAvailability('extension').is_available)
- chrome.extension.lastError = errorObject;
- chrome.runtime.lastError = errorObject;
+ targetChrome.extension.lastError = errorObject;
+ targetChrome.runtime.lastError = errorObject;
};
-function clear() {
+/**
+ * Clears the last error on |targetChrome|.
+ */
+function clear(targetChrome) {
+ DCHECK(targetChrome != undefined);
if (GetAvailability('extension').is_available)
- delete chrome.extension.lastError;
- delete chrome.runtime.lastError;
+ delete targetChrome.extension.lastError;
+ delete targetChrome.runtime.lastError;
};
+/**
+ * Runs |callback| with last error set to |message|.
+ *
+ * The target chrome object is the global object's of the callback, so this
+ * method won't work if the real callback has been wrapped (etc).
+ */
+function run(message, callback) {
+ var targetChrome = GetGlobal(callback);
+ set(message, targetChrome);
+ try {
+ callback();
+ } finally {
+ clear(targetChrome);
+ }
+}
+
exports.clear = clear;
exports.set = set;
+exports.run = run;

Powered by Google App Engine
This is Rietveld 408576698