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

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

Issue 16470003: Add chrome.runtime.getPackageDirectoryEntry. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 6 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
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 binding for the runtime API. 5 // Custom binding for the runtime API.
6 6
7 var binding = require('binding').Binding.create('runtime'); 7 var binding = require('binding').Binding.create('runtime');
8 8
9 var extensionNatives = requireNative('extension'); 9 var extensionNatives = requireNative('extension');
10 var miscBindings = require('miscellaneous_bindings'); 10 var miscBindings = require('miscellaneous_bindings');
11 var runtimeNatives = requireNative('runtime'); 11 var runtimeNatives = requireNative('runtime');
12 var unloadEvent = require('unload_event'); 12 var unloadEvent = require('unload_event');
13 13
14 var manifest = runtimeNatives.GetManifest();
15 if (manifest.app && manifest.app.background) {
16 var backgroundPage = extensionNatives.GetExtensionViews(-1, 'BACKGROUND')[0];
17 var GetModuleSystem = requireNative('v8_context').GetModuleSystem;
18 var backgroundRequire = GetModuleSystem(backgroundPage).require;
19 } else {
20 var backgroundPage = window;
21 var backgroundRequire = require;
22 }
23
24 // For packaged apps, all windows use the bindFileEntryCallback from the
25 // background page so their FileEntry objects have the background page's context
26 // as their own. This allows them to be used from other windows (including the
27 // background page) after the original window is closed.
28 if (window == backgroundPage) {
29 var lastError = require('lastError');
30 var fileSystemNatives = requireNative('file_system_natives');
31 var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem;
32 var bindDirectoryEntryCallback = function(functionName, apiFunctions) {
33 apiFunctions.setCustomCallback(functionName,
34 function(name, request, response) {
35 if (request.callback && response) {
36 var callback = request.callback;
37 request.callback = null;
38
39 var fileSystemId = response.fileSystemId;
40 var baseName = response.baseName;
41 var fs = GetIsolatedFileSystem(fileSystemId);
42
43 try {
44 fs.root.getDirectory(baseName, {}, callback, function(fileError) {
45 lastError.run('runtime.' + functionName,
46 'Error getting Entry, code: ' + fileError.code,
47 request.stack,
48 callback);
49 });
50 } catch (e) {
51 lastError.run('runtime.' + functionName,
52 'Error: ' + e.stack,
53 request.stack,
54 callback);
55 }
56 }
57 });
58 };
59 } else {
60 // Force the runtime API to be loaded in the background page. Using
61 // backgroundPageModuleSystem.require('runtime') is insufficient as
62 // requireNative is only allowed while lazily loading an API.
63 backgroundPage.runtime;
64 var bindDirectoryEntryCallback = backgroundRequire(
65 'runtime').bindDirectoryEntryCallback;
66 }
67
14 binding.registerCustomHook(function(binding, id, contextType) { 68 binding.registerCustomHook(function(binding, id, contextType) {
15 var apiFunctions = binding.apiFunctions; 69 var apiFunctions = binding.apiFunctions;
16 var runtime = binding.compiledApi; 70 var runtime = binding.compiledApi;
17 71
18 // 72 //
19 // Unprivileged APIs. 73 // Unprivileged APIs.
20 // 74 //
21 75
22 runtime.id = id; 76 runtime.id = id;
23 77
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 173
120 apiFunctions.setCustomCallback('getBackgroundPage', 174 apiFunctions.setCustomCallback('getBackgroundPage',
121 function(name, request, response) { 175 function(name, request, response) {
122 if (request.callback) { 176 if (request.callback) {
123 var bg = extensionNatives.GetExtensionViews(-1, 'BACKGROUND')[0] || null; 177 var bg = extensionNatives.GetExtensionViews(-1, 'BACKGROUND')[0] || null;
124 request.callback(bg); 178 request.callback(bg);
125 } 179 }
126 request.callback = null; 180 request.callback = null;
127 }); 181 });
128 182
183 bindDirectoryEntryCallback('getPackageDirectoryEntry', apiFunctions);
129 }); 184 });
130 185
186 exports.bindDirectoryEntryCallback = bindDirectoryEntryCallback;
131 exports.binding = binding.generate(); 187 exports.binding = binding.generate();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698