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

Unified Diff: trunk/src/extensions/renderer/resources/permissions_custom_bindings.js

Issue 309413002: Revert 274558 "Move some extensions renderer resources to extens..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 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
Index: trunk/src/extensions/renderer/resources/permissions_custom_bindings.js
===================================================================
--- trunk/src/extensions/renderer/resources/permissions_custom_bindings.js (revision 274563)
+++ trunk/src/extensions/renderer/resources/permissions_custom_bindings.js (working copy)
@@ -1,97 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Custom binding for the Permissions API.
-
-var binding = require('binding').Binding.create('permissions');
-
-var Event = require('event_bindings').Event;
-
-// These custom binding are only necessary because it is not currently
-// possible to have a union of types as the type of the items in an array.
-// Once that is fixed, this entire file should go away.
-// See,
-// https://code.google.com/p/chromium/issues/detail?id=162044
-// https://code.google.com/p/chromium/issues/detail?id=162042
-// TODO(bryeung): delete this file.
-binding.registerCustomHook(function(api) {
- var apiFunctions = api.apiFunctions;
- var permissions = api.compiledApi;
-
- function maybeConvertToObject(str) {
- var parts = $String.split(str, '|');
- if (parts.length != 2)
- return str;
-
- var ret = {};
- ret[parts[0]] = JSON.parse(parts[1]);
- return ret;
- }
-
- function convertObjectPermissionsToStrings() {
- if (arguments.length < 1)
- return arguments;
-
- var args = arguments[0].permissions;
- if (!args)
- return arguments;
-
- for (var i = 0; i < args.length; i += 1) {
- if (typeof(args[i]) == 'object') {
- var a = args[i];
- var keys = $Object.keys(a);
- if (keys.length != 1) {
- throw new Error("Too many keys in object-style permission.");
- }
- arguments[0].permissions[i] = keys[0] + '|' +
- JSON.stringify(a[keys[0]]);
- }
- }
-
- return arguments;
- }
-
- // Convert complex permissions to strings so they validate against the schema
- apiFunctions.setUpdateArgumentsPreValidate(
- 'contains', convertObjectPermissionsToStrings);
- apiFunctions.setUpdateArgumentsPreValidate(
- 'remove', convertObjectPermissionsToStrings);
- apiFunctions.setUpdateArgumentsPreValidate(
- 'request', convertObjectPermissionsToStrings);
-
- // Convert complex permissions back to objects
- apiFunctions.setCustomCallback('getAll',
- function(name, request, response) {
- for (var i = 0; i < response.permissions.length; i += 1) {
- response.permissions[i] =
- maybeConvertToObject(response.permissions[i]);
- }
-
- // Since the schema says Permissions.permissions contains strings and
- // not objects, validation will fail after the for-loop above. This
- // skips validation and calls the callback directly, then clears it so
- // that handleResponse doesn't call it again.
- try {
- if (request.callback)
- $Function.apply(request.callback, request, [response]);
- } finally {
- delete request.callback;
- }
- });
-
- // Also convert complex permissions back to objects for events. The
- // dispatchToListener call happens after argument validation, which works
- // around the problem that Permissions.permissions is supposed to be a list
- // of strings.
- permissions.onAdded.dispatchToListener = function(callback, args) {
- for (var i = 0; i < args[0].permissions.length; i += 1) {
- args[0].permissions[i] = maybeConvertToObject(args[0].permissions[i]);
- }
- $Function.call(Event.prototype.dispatchToListener, this, callback, args);
- };
- permissions.onRemoved.dispatchToListener =
- permissions.onAdded.dispatchToListener;
-});
-
-exports.binding = binding.generate();
« no previous file with comments | « trunk/src/extensions/renderer/resources/messaging_utils.js ('k') | trunk/src/extensions/renderer/resources/platform_app.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698