diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-19 20:35:21 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-19 20:35:21 +0000 |
commit | 9c813dad1bb091fb122b8c81f61432fc3c9978c5 (patch) | |
tree | 6d1f19856a0558c2238b999f11b18b6da46fc923 | |
parent | 38d6bb7c6f4e18c9b4db500ac1c1421971ea9afa (diff) | |
download | chromium_src-9c813dad1bb091fb122b8c81f61432fc3c9978c5.zip chromium_src-9c813dad1bb091fb122b8c81f61432fc3c9978c5.tar.gz chromium_src-9c813dad1bb091fb122b8c81f61432fc3c9978c5.tar.bz2 |
Add debugging to track down chrome.runtime being null/undefined while clearing
lastError.
BUG=258526
Review URL: https://chromiumcodereview.appspot.com/19188003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212641 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/common/extensions/api/_api_features.json | 3 | ||||
-rw-r--r-- | chrome/renderer/resources/extensions/last_error.js | 33 |
2 files changed, 28 insertions, 8 deletions
diff --git a/chrome/common/extensions/api/_api_features.json b/chrome/common/extensions/api/_api_features.json index 07ff307..887b615 100644 --- a/chrome/common/extensions/api/_api_features.json +++ b/chrome/common/extensions/api/_api_features.json @@ -403,7 +403,8 @@ "contexts": ["blessed_extension", "unblessed_extension", "content_script"] }, "runtime.lastError": { - "contexts": ["blessed_extension", "unblessed_extension", "content_script"] + "contexts": "all", + "matches": ["<all_urls>"] }, "runtime.onConnect": { "contexts": ["blessed_extension", "unblessed_extension", "content_script"] diff --git a/chrome/renderer/resources/extensions/last_error.js b/chrome/renderer/resources/extensions/last_error.js index 7252a2e..f368964 100644 --- a/chrome/renderer/resources/extensions/last_error.js +++ b/chrome/renderer/resources/extensions/last_error.js @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -var DCHECK = requireNative('logging').DCHECK; var GetAvailability = requireNative('v8_context').GetAvailability; var GetGlobal = requireNative('sendRequest').GetGlobal; @@ -20,17 +19,21 @@ var GetGlobal = requireNative('sendRequest').GetGlobal; * optional |stack|. */ function set(name, message, stack, targetChrome) { - DCHECK(targetChrome != undefined); - clear(targetChrome); // in case somebody has set a sneaky getter/setter - var errorMessage = name + ': ' + message; if (stack != null && stack != '') errorMessage += '\n' + stack; + + if (!targetChrome) + throw new Error('No chrome object to set error: ' + errorMessage); + clear(targetChrome); // in case somebody has set a sneaky getter/setter + console.error(errorMessage); var errorObject = { message: message }; - if (GetAvailability('extension').is_available) + if (GetAvailability('extension.lastError').is_available) targetChrome.extension.lastError = errorObject; + + assertRuntimeIsAvailable(); targetChrome.runtime.lastError = errorObject; }; @@ -38,12 +41,28 @@ function set(name, message, stack, targetChrome) { * Clears the last error on |targetChrome|. */ function clear(targetChrome) { - DCHECK(targetChrome != undefined); - if (GetAvailability('extension').is_available) + if (!targetChrome) + throw new Error('No target chrome to clear error'); + + if (GetAvailability('extension.lastError').is_available) delete targetChrome.extension.lastError; + + assertRuntimeIsAvailable(); delete targetChrome.runtime.lastError; }; +function assertRuntimeIsAvailable() { + // chrome.runtime should always be available, but maybe it's disappeared for + // some reason? Add debugging for http://crbug.com/258526. + var runtimeAvailability = GetAvailability('runtime.lastError'); + if (!runtimeAvailability.is_available) { + throw new Error('runtime.lastError is not available: ' + + runtimeAvailability.message); + } + if (!chrome.runtime) + throw new Error('runtime namespace is null or undefined'); +} + /** * Runs |callback(args)| with last error args as in set(). * |