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

Side by Side Diff: chrome/renderer/resources/extension_process_bindings.js

Issue 165323: Add chrome.extension to extension_api.json and docs (Closed)
Patch Set: precommit Created 11 years, 4 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
« no previous file with comments | « chrome/renderer/renderer_resources.grd ('k') | 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) 2009 The chrome Authors. All rights reserved. 1 // Copyright (c) 2009 The chrome 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 // ----------------------------------------------------------------------------- 5 // -----------------------------------------------------------------------------
6 // NOTE: If you change this file you need to touch renderer_resources.grd to 6 // NOTE: If you change this file you need to touch renderer_resources.grd to
7 // have your change take effect. 7 // have your change take effect.
8 // ----------------------------------------------------------------------------- 8 // -----------------------------------------------------------------------------
9 9
10 // This script contains privileged chrome extension related javascript APIs. 10 // This script contains privileged chrome extension related javascript APIs.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 143 }
144 } 144 }
145 145
146 function bind(obj, func) { 146 function bind(obj, func) {
147 return function() { 147 return function() {
148 return func.apply(obj, arguments); 148 return func.apply(obj, arguments);
149 }; 149 };
150 } 150 }
151 151
152 forEach(apiDefinitions, function(apiDef) { 152 forEach(apiDefinitions, function(apiDef) {
153 var module = {}; 153 chrome[apiDef.namespace] = chrome[apiDef.namespace] || {};
154 chrome[apiDef.namespace] = module; 154 var module = chrome[apiDef.namespace];
155 155
156 // Setup Functions. 156 // Setup Functions.
157 if (apiDef.functions) { 157 if (apiDef.functions) {
158 forEach(apiDef.functions, function(functionDef) { 158 forEach(apiDef.functions, function(functionDef) {
159 // Module functions may have been defined earlier by hand. Don't clobber
160 // them.
161 if (module[functionDef.name])
162 return;
163
159 var apiFunction = {}; 164 var apiFunction = {};
160 apiFunction.definition = functionDef; 165 apiFunction.definition = functionDef;
161 apiFunction.name = apiDef.namespace + "." + functionDef.name;; 166 apiFunction.name = apiDef.namespace + "." + functionDef.name;;
162 apiFunctions[apiFunction.name] = apiFunction; 167 apiFunctions[apiFunction.name] = apiFunction;
163 168
164 module[functionDef.name] = bind(apiFunction, function() { 169 module[functionDef.name] = bind(apiFunction, function() {
165 validate(arguments, this.definition.parameters); 170 validate(arguments, this.definition.parameters);
166 171
167 if (this.handleRequest) 172 if (this.handleRequest)
168 return this.handleRequest.apply(this, arguments); 173 return this.handleRequest.apply(this, arguments);
169 else 174 else
170 return sendRequest(this.name, arguments, 175 return sendRequest(this.name, arguments,
171 this.definition.parameters); 176 this.definition.parameters);
172 }); 177 });
173 }); 178 });
174 } 179 }
175 180
176 // Setup Events 181 // Setup Events
177 if (apiDef.events) { 182 if (apiDef.events) {
178 forEach(apiDef.events, function(eventDef) { 183 forEach(apiDef.events, function(eventDef) {
184 // Module events may have been defined earlier by hand. Don't clobber
185 // them.
186 if (module[eventDef.name])
187 return;
188
179 var eventName = apiDef.namespace + "." + eventDef.name; 189 var eventName = apiDef.namespace + "." + eventDef.name;
180 module[eventDef.name] = new chrome.Event(eventName); 190 module[eventDef.name] = new chrome.Event(eventName);
181 }); 191 });
182 } 192 }
183 }); 193 });
184 194
185 // --- Setup additional api's not currently handled in common/extensions/api 195 // --- Setup additional api's not currently handled in common/extensions/api
186 196
187 // Page action events send (pageActionId, {tabId, tabUrl}). 197 // Page action events send (pageActionId, {tabId, tabUrl}).
188 function setupPageActionEvents(extensionId) { 198 function setupPageActionEvents(extensionId) {
(...skipping 22 matching lines...) Expand all
211 chrome.self.onConnect = chrome.extension.onConnect; 221 chrome.self.onConnect = chrome.extension.onConnect;
212 222
213 setupPageActionEvents(extensionId); 223 setupPageActionEvents(extensionId);
214 }); 224 });
215 225
216 // Self getViews(); 226 // Self getViews();
217 apiFunctions["self.getViews"].handleRequest = function() { 227 apiFunctions["self.getViews"].handleRequest = function() {
218 return GetViews(); 228 return GetViews();
219 } 229 }
220 })(); 230 })();
OLDNEW
« no previous file with comments | « chrome/renderer/renderer_resources.grd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698