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

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

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more progress Created 7 years, 11 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
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 Permissions API. 5 // Custom bindings for the Permissions API.
6 6
7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 7 var Bindings = require('schema_binding_generator').Bindings;
8 var bindings = new Bindings('permissions');
9
8 var sendRequest = require('sendRequest').sendRequest; 10 var sendRequest = require('sendRequest').sendRequest;
9 var lastError = require('lastError'); 11 var lastError = require('lastError');
10 12
11 // These custom bindings are only necessary because it is not currently 13 // These custom bindings are only necessary because it is not currently
12 // possible to have a union of types as the type of the items in an array. 14 // possible to have a union of types as the type of the items in an array.
13 // Once that is fixed, this entire file should go away. 15 // Once that is fixed, this entire file should go away.
14 // See, 16 // See,
15 // https://code.google.com/p/chromium/issues/detail?id=162044 17 // https://code.google.com/p/chromium/issues/detail?id=162044
16 // https://code.google.com/p/chromium/issues/detail?id=162042 18 // https://code.google.com/p/chromium/issues/detail?id=162042
17 // TODO(bryeung): delete this file. 19 // TODO(bryeung): delete this file.
18 chromeHidden.registerCustomHook('permissions', function(api) { 20 bindings.registerCustomHook(function(api) {
19 var apiFunctions = api.apiFunctions; 21 var apiFunctions = api.apiFunctions;
22 var permissions = api.compiledApi;
20 23
21 function maybeConvertToObject(str) { 24 function maybeConvertToObject(str) {
22 var parts = str.split('|'); 25 var parts = str.split('|');
23 if (parts.length != 2) 26 if (parts.length != 2)
24 return str; 27 return str;
25 28
26 var ret = {}; 29 var ret = {};
27 ret[parts[0]] = JSON.parse(parts[1]); 30 ret[parts[0]] = JSON.parse(parts[1]);
28 return ret; 31 return ret;
29 } 32 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // that handleResponse doesn't call it again. 76 // that handleResponse doesn't call it again.
74 if (request.callback) 77 if (request.callback)
75 request.callback.apply(request, [response]); 78 request.callback.apply(request, [response]);
76 delete request.callback; 79 delete request.callback;
77 }); 80 });
78 81
79 // Also convert complex permissions back to objects for events. The 82 // Also convert complex permissions back to objects for events. The
80 // dispatchToListener call happens after argument validation, which works 83 // dispatchToListener call happens after argument validation, which works
81 // around the problem that Permissions.permissions is supposed to be a list 84 // around the problem that Permissions.permissions is supposed to be a list
82 // of strings. 85 // of strings.
83 chrome.permissions.onAdded.dispatchToListener = function(callback, args) { 86 permissions.onAdded.dispatchToListener = function(callback, args) {
84 for (var i = 0; i < args[0].permissions.length; i += 1) { 87 for (var i = 0; i < args[0].permissions.length; i += 1) {
85 args[0].permissions[i] = maybeConvertToObject(args[0].permissions[i]); 88 args[0].permissions[i] = maybeConvertToObject(args[0].permissions[i]);
86 } 89 }
87 chrome.Event.prototype.dispatchToListener(callback, args); 90 chrome.Event.prototype.dispatchToListener(callback, args);
88 }; 91 };
89 chrome.permissions.onRemoved.dispatchToListener = 92 permissions.onRemoved.dispatchToListener =
90 chrome.permissions.onAdded.dispatchToListener; 93 permissions.onAdded.dispatchToListener;
91 }); 94 });
95
96 exports.bindings = bindings.generate();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698