Commit 2a53188b authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit Bot

[Extensions Bindings] Don't load lastError module with native bindings

Setting the lastError property is implemented natively with native
bindings, and the JS version should never be used. Don't load the
lastError module when native bindings are enabled to enforce this.

BUG=653596

Review-Url: https://codereview.chromium.org/2959583002
Cr-Commit-Position: refs/heads/master@{#485073}
parent 19207423
......@@ -11,7 +11,12 @@ var getExtensionViews = requireNative('runtime').GetExtensionViews;
var sendRequest = bindingUtil ?
$Function.bind(bindingUtil.sendRequest, bindingUtil) :
require('sendRequest').sendRequest;
var lastError = require('lastError');
var jsLastError = bindingUtil ? undefined : require('lastError');
function hasLastError() {
return bindingUtil ?
bindingUtil.hasLastError() : jsLastError.hasError(chrome);
}
binding.registerCustomHook(function(bindingsAPI) {
var apiFunctions = bindingsAPI.apiFunctions;
......@@ -30,7 +35,7 @@ binding.registerCustomHook(function(bindingsAPI) {
if (!callback)
return;
if (lastError.hasError(chrome)) {
if (hasLastError()) {
callback();
} else {
var views = getExtensionViews(-1, -1, 'POPUP');
......
......@@ -727,7 +727,6 @@ std::vector<std::pair<const char*, int>> Dispatcher::GetJsResources() {
{"guestViewEvents", IDR_GUEST_VIEW_EVENTS_JS},
{"imageUtil", IDR_IMAGE_UTIL_JS},
{"json_schema", IDR_JSON_SCHEMA_JS},
{"lastError", IDR_LAST_ERROR_JS},
{"messaging", IDR_MESSAGING_JS},
{"messaging_utils", IDR_MESSAGING_UTILS_JS},
{kSchemaUtils, IDR_SCHEMA_UTILS_JS},
......@@ -801,6 +800,7 @@ std::vector<std::pair<const char*, int>> Dispatcher::GetJsResources() {
if (!FeatureSwitch::native_crx_bindings()->IsEnabled()) {
resources.emplace_back("binding", IDR_BINDING_JS);
resources.emplace_back(kEventBindings, IDR_EVENT_BINDINGS_JS);
resources.emplace_back("lastError", IDR_LAST_ERROR_JS);
resources.emplace_back("sendRequest", IDR_SEND_REQUEST_JS);
// Custom types sources.
......
......@@ -4,12 +4,20 @@
var fileSystemNatives = requireNative('file_system_natives');
var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem;
var lastError = require('lastError');
var GetModuleSystem = requireNative('v8_context').GetModuleSystem;
// TODO(sammc): Don't require extension. See http://crbug.com/235689.
var GetExtensionViews = requireNative('runtime').GetExtensionViews;
var safeCallbackApply = require('uncaught_exception_handler').safeCallbackApply;
var jsLastError = bindingUtil ? undefined : require('lastError');
function runCallbackWithLastError(name, message, stack, callback) {
if (bindingUtil)
bindingUtil.runCallbackWithLastError(message, callback);
else
jsLastError.run(name, message, stack, callback);
}
var WINDOW = {};
try {
WINDOW = window;
......@@ -51,7 +59,7 @@ function getFileBindingsForApi(apiName) {
var getEntryError = function(fileError) {
if (!hasError) {
hasError = true;
lastError.run(
runCallbackWithLastError(
apiName + '.' + functionName,
'Error getting fileEntry, code: ' + fileError.code,
request.stack,
......@@ -103,10 +111,9 @@ function getFileBindingsForApi(apiName) {
} catch (e) {
if (!hasError) {
hasError = true;
lastError.run(apiName + '.' + functionName,
'Error getting fileEntry: ' + e.stack,
request.stack,
callback);
runCallbackWithLastError(apiName + '.' + functionName,
'Error getting fileEntry: ' + e.stack,
request.stack, callback);
}
}
});
......@@ -150,16 +157,15 @@ function getBindDirectoryEntryCallback() {
try {
fs.root.getDirectory(baseName, {}, callback, function(fileError) {
lastError.run('runtime.' + functionName,
'Error getting Entry, code: ' + fileError.code,
request.stack,
callback);
runCallbackWithLastError(
'runtime.' + functionName,
'Error getting Entry, code: ' + fileError.code,
request.stack, callback);
});
} catch (e) {
lastError.run('runtime.' + functionName,
'Error: ' + e.stack,
request.stack,
callback);
runCallbackWithLastError('runtime.' + functionName,
'Error: ' + e.stack,
request.stack, callback);
}
}
}
......
......@@ -7,7 +7,6 @@
// TODO(kalman): factor requiring chrome out of here.
var chrome = requireNative('chrome').GetChrome();
var lastError = require('lastError');
var logActivity = requireNative('activityLogger');
var logging = requireNative('logging');
var messagingNatives = requireNative('messaging_natives');
......@@ -46,6 +45,28 @@
privates(event).impl.destroy_();
}
var jsLastError = bindingUtil ? undefined : require('lastError');
function setLastError(name, error) {
if (bindingUtil)
bindingUtil.setLastError(error);
else
jsLastError.set(name, error, null, chrome);
}
function clearLastError() {
if (bindingUtil)
bindingUtil.clearLastError();
else
jsLastError.clear(chrome);
}
function hasLastError() {
if (bindingUtil)
return bindingUtil.hasLastError();
else
return jsLastError.hasError(chrome);
}
// Map of port IDs to port object.
var ports = {__proto__: null};
......@@ -152,7 +173,7 @@
if (sourceUrl)
errorMsg += ' for URL ' + sourceUrl;
errorMsg += ').';
lastError.set(eventName, errorMsg, null, chrome);
setLastError(eventName, errorMsg);
}
// Helper function for dispatchOnConnect
......@@ -348,12 +369,12 @@
if (port) {
delete ports[portId];
if (errorMessage)
lastError.set('Port', errorMessage, null, chrome);
setLastError('Port', errorMessage);
try {
port.onDisconnect.dispatch(port);
} finally {
privates(port).impl.destroy_();
lastError.clear(chrome);
clearLastError();
}
}
};
......@@ -406,17 +427,16 @@
if (!responseCallback)
return;
if (lastError.hasError(chrome)) {
if (hasLastError()) {
sendResponseAndClearCallback();
} else {
lastError.set(
setLastError(
port.name,
'The message port closed before a response was received.', null,
chrome);
'The message port closed before a response was received.');
try {
sendResponseAndClearCallback();
} finally {
lastError.clear(chrome);
clearLastError();
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment