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

Unified Diff: extensions/renderer/resources/runtime_custom_bindings.js

Issue 1129033008: Don't crash on chrome.runtime.connect(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more tests Created 5 years, 7 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 | « chrome/test/data/extensions/api_test/messaging/externally_connectable/sites/assertions.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/resources/runtime_custom_bindings.js
diff --git a/extensions/renderer/resources/runtime_custom_bindings.js b/extensions/renderer/resources/runtime_custom_bindings.js
index 60c3bd02e2a0106153c3e810397fe3fe592b7d7d..4e4a71d1e0a2c7b313c4d29d7123ac6b68bbc3ce 100644
--- a/extensions/renderer/resources/runtime_custom_bindings.js
+++ b/extensions/renderer/resources/runtime_custom_bindings.js
@@ -158,8 +158,16 @@ binding.registerCustomHook(function(binding, id, contextType) {
if (unloadEvent.wasDispatched)
throw new Error('Error connecting to extension ' + targetId);
- if (!targetId)
+ if (!targetId) {
+ // runtime.id is only defined inside extensions. If we're in a webpage,
+ // the best we can do at this point is to fail.
+ if (!runtime.id) {
+ throw new Error('chrome.runtime.connect() called from a webpage must ' +
+ 'specify an Extension ID (string) for its first ' +
+ 'argument');
+ }
targetId = runtime.id;
+ }
var name = '';
if (connectInfo && connectInfo.name)
« no previous file with comments | « chrome/test/data/extensions/api_test/messaging/externally_connectable/sites/assertions.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698