| Index: chrome/renderer/resources/extensions/app_window_custom_bindings.js
|
| diff --git a/chrome/renderer/resources/extensions/app_window_custom_bindings.js b/chrome/renderer/resources/extensions/app_window_custom_bindings.js
|
| index f42829ac0b9915494de628350410379a7c8d5172..7acfcf0bb874dca088841e3ec6b10a4b878488a8 100644
|
| --- a/chrome/renderer/resources/extensions/app_window_custom_bindings.js
|
| +++ b/chrome/renderer/resources/extensions/app_window_custom_bindings.js
|
| @@ -12,28 +12,60 @@ var GetView = appWindowNatives.GetView;
|
|
|
| chromeHidden.registerCustomHook('app.window', function(bindingsAPI) {
|
| var apiFunctions = bindingsAPI.apiFunctions;
|
| - apiFunctions.setCustomCallback('create', function(name, request, result) {
|
| - var view = null;
|
| - if (result.viewId) {
|
| - view = GetView(result.viewId, result.injectTitlebar);
|
| + apiFunctions.setCustomCallback('create',
|
| + function(name, request, windowParams) {
|
| + if (!windowParams.viewId) {
|
| + // Create failed? If given a callback, trigger it with an undefined object
|
| + if (request.callback) {
|
| + request.callback()
|
| + delete request.callback;
|
| + }
|
| + return;
|
| }
|
| +
|
| + var view = GetView(windowParams.viewId, windowParams.injectTitlebar);
|
| +
|
| + // Call makeAppWindow in the newly created JS context
|
| + var appWindow = view.chrome.app.window.makeAppWindow(windowParams);
|
| +
|
| if (request.callback) {
|
| - request.callback(view.chrome.app.window.current());
|
| + request.callback(appWindow);
|
| delete request.callback;
|
| }
|
| - })
|
| - var AppWindow = function() {};
|
| - forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) {
|
| - AppWindow.prototype[fn] =
|
| - chromeHidden.internalAPIs.app.currentWindowInternal[fn];
|
| });
|
| - AppWindow.prototype.moveTo = window.moveTo.bind(window);
|
| - AppWindow.prototype.resizeTo = window.resizeTo.bind(window);
|
| - AppWindow.prototype.contentWindow = window;
|
| - // So as not to break apps that use .dom. http://crbug.com/147668
|
| - // TODO(jeremya): remove this once M23 has branched.
|
| - AppWindow.prototype.dom = window;
|
| +
|
| apiFunctions.setHandleRequest('current', function() {
|
| - return new AppWindow;
|
| - })
|
| + if (!chromeHidden.currentAppWindow) {
|
| + console.error('chrome.app.window.current() is null -- window not ' +
|
| + 'created with chrome.app.window.create()');
|
| + return null;
|
| + }
|
| + return chromeHidden.currentAppWindow;
|
| + });
|
| +
|
| + // This is an internal function, but needs to be bound with setHandleRequest
|
| + // because it is called from a different JS context
|
| + apiFunctions.setHandleRequest('makeAppWindow', function(params) {
|
| + var AppWindow = function() {};
|
| + forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) {
|
| + AppWindow.prototype[fn] =
|
| + chromeHidden.internalAPIs.app.currentWindowInternal[fn];
|
| + });
|
| + AppWindow.prototype.moveTo = window.moveTo.bind(window);
|
| + AppWindow.prototype.resizeTo = window.resizeTo.bind(window);
|
| + AppWindow.prototype.contentWindow = window;
|
| + // So as not to break apps that use .dom. http://crbug.com/147668
|
| + // TODO(jeremya): remove this once M23 has branched.
|
| + AppWindow.prototype.dom = window;
|
| +
|
| + Object.defineProperty(AppWindow.prototype, 'id', {get: function() {
|
| + return chromeHidden.appWindowCache.id;
|
| + }});
|
| +
|
| + chromeHidden.appWindowCache = {
|
| + id: params.id ? params.id : ''
|
| + };
|
| + chromeHidden.currentAppWindow = new AppWindow;
|
| + return chromeHidden.currentAppWindow;
|
| + });
|
| });
|
|
|