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

Side by Side Diff: chrome/renderer/resources/extensions/extension_custom_bindings.js

Issue 12210113: Check existence of chrome.runtime APIs using __lookupGetter__ to avoid throwing (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Custom bindings for the extension API. 5 // Custom bindings for the extension API.
6 6
7 var extensionNatives = requireNative('extension'); 7 var extensionNatives = requireNative('extension');
8 var GetExtensionViews = extensionNatives.GetExtensionViews; 8 var GetExtensionViews = extensionNatives.GetExtensionViews;
9 var runtimeNatives = requireNative('runtime'); 9 var runtimeNatives = requireNative('runtime');
10 var OpenChannelToExtension = runtimeNatives.OpenChannelToExtension; 10 var OpenChannelToExtension = runtimeNatives.OpenChannelToExtension;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // Alias several messaging deprecated APIs to their runtime counterparts. 72 // Alias several messaging deprecated APIs to their runtime counterparts.
73 var mayNeedAlias = [ 73 var mayNeedAlias = [
74 // Types 74 // Types
75 'Port', 75 'Port',
76 // Functions 76 // Functions
77 'connect', 'sendMessage', 'connectNative', 'sendNativeMessage', 77 'connect', 'sendMessage', 'connectNative', 'sendNativeMessage',
78 // Events 78 // Events
79 'onConnect', 'onConnectExternal', 'onMessage', 'onMessageExternal' 79 'onConnect', 'onConnectExternal', 'onMessage', 'onMessageExternal'
80 ]; 80 ];
81 mayNeedAlias.forEach(function(alias) { 81 mayNeedAlias.forEach(function(alias) {
82 try { 82 // Checking existence isn't enough since some functions are disabled via
83 // Deliberately accessing runtime[alias] rather than testing its 83 // getters that throw exceptions. Assume that any getter is such a function.
84 // existence, since accessing may throw an exception if this context 84 if (chrome.runtime.hasOwnProperty(alias) &&
85 // doesn't have access. 85 chrome.runtime.__lookupGetter__(alias) === undefined) {
86 if (chrome.runtime[alias]) 86 chrome.extension[alias] = chrome.runtime[alias];
87 chrome.extension[alias] = chrome.runtime[alias]; 87 }
88 } catch(e) {}
89 }); 88 });
90 89
91 apiFunctions.setUpdateArgumentsPreValidate('sendRequest', 90 apiFunctions.setUpdateArgumentsPreValidate('sendRequest',
92 sendMessageUpdateArguments.bind(null, 'sendRequest')); 91 sendMessageUpdateArguments.bind(null, 'sendRequest'));
93 92
94 apiFunctions.setHandleRequest('sendRequest', 93 apiFunctions.setHandleRequest('sendRequest',
95 function(targetId, request, responseCallback) { 94 function(targetId, request, responseCallback) {
96 if (sendRequestIsDisabled) 95 if (sendRequestIsDisabled)
97 throw new Error(sendRequestIsDisabled); 96 throw new Error(sendRequestIsDisabled);
98 var port = chrome.runtime.connect(targetId || extensionId, 97 var port = chrome.runtime.connect(targetId || extensionId,
99 {name: chromeHidden.kRequestChannel}); 98 {name: chromeHidden.kRequestChannel});
100 chromeHidden.Port.sendMessageImpl(port, request, responseCallback); 99 chromeHidden.Port.sendMessageImpl(port, request, responseCallback);
101 }); 100 });
102 101
103 if (sendRequestIsDisabled) { 102 if (sendRequestIsDisabled) {
104 chrome.extension.onRequest.addListener = function() { 103 chrome.extension.onRequest.addListener = function() {
105 throw new Error(sendRequestIsDisabled); 104 throw new Error(sendRequestIsDisabled);
106 }; 105 };
107 if (contextType == 'BLESSED_EXTENSION') { 106 if (contextType == 'BLESSED_EXTENSION') {
108 chrome.extension.onRequestExternal.addListener = function() { 107 chrome.extension.onRequestExternal.addListener = function() {
109 throw new Error(sendRequestIsDisabled); 108 throw new Error(sendRequestIsDisabled);
110 }; 109 };
111 } 110 }
112 } 111 }
113 112
114 }); 113 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698