1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Custom binding for the developerPrivate API.
7 var binding = require('binding').Binding.create('developerPrivate');
9 binding.registerCustomHook(function(bindingsAPI) {
10 var apiFunctions = bindingsAPI.apiFunctions;
12 // Converts the argument of |functionName| from DirectoryEntry to URL.
13 function bindFileSystemFunction(functionName) {
14 apiFunctions.setUpdateArgumentsPostValidate(
15 functionName, function(directoryEntry, callback) {
16 var fileSystemName = directoryEntry.filesystem.name;
17 var relativePath = $String.slice(directoryEntry.fullPath, 1);
18 var url = directoryEntry.toURL();
19 return [fileSystemName, relativePath, url, callback];
23 bindFileSystemFunction('loadDirectory');
25 // developerPrivate.enable is the same as chrome.management.setEnabled.
26 // TODO(devlin): Migrate callers off developerPrivate.enable.
27 bindingsAPI.compiledApi.enable = chrome.management.setEnabled;
29 apiFunctions.setHandleRequest('allowFileAccess',
30 function(id, allow, callback) {
31 chrome.developerPrivate.updateExtensionConfiguration(
32 {extensionId: id, fileAccess: allow}, callback);
35 apiFunctions.setHandleRequest('allowIncognito',
36 function(id, allow, callback) {
37 chrome.developerPrivate.updateExtensionConfiguration(
38 {extensionId: id, incognitoAccess: allow}, callback);
41 apiFunctions.setHandleRequest('inspect', function(options, callback) {
42 var renderViewId = options.render_view_id;
43 if (typeof renderViewId == 'string') {
44 renderViewId = parseInt(renderViewId);
45 if (isNaN(renderViewId))
46 throw new Error('Invalid value for render_view_id');
48 var renderProcessId = options.render_process_id;
49 if (typeof renderProcessId == 'string') {
50 renderProcessId = parseInt(renderProcessId);
51 if (isNaN(renderProcessId))
52 throw new Error('Invalid value for render_process_id');
54 chrome.developerPrivate.openDevTools({
55 extensionId: options.extension_id,
56 renderProcessId: renderProcessId,
57 renderViewId: renderViewId,
58 incognito: options.incognito
63 exports.binding = binding.generate();