Chromium Code Reviews| 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 3c0093e398709a524b47a2912070d3cf248f0a6c..822c7c11b25e8cf0bfb81159d08d66c01bd95ed5 100644 |
| --- a/chrome/renderer/resources/extensions/app_window_custom_bindings.js |
| +++ b/chrome/renderer/resources/extensions/app_window_custom_bindings.js |
| @@ -12,26 +12,56 @@ 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 |
|
Mihai Parparita -not on Chrome
2012/09/26 22:22:23
Nit: period at the end of the comment sentence (ap
tapted
2012/09/27 01:27:15
Done.
|
| + if (request.callback) { |
| + request.callback() |
| + delete request.callback; |
| + } |
| + return; |
| } |
| + |
| + var view = GetView(windowParams.viewId, windowParams.injectTitlebar); |
| + |
| + // Initialize appWindowData in the newly created JS context |
| + view.chrome.app.window.initializeAppWindow(windowParams); |
| + |
| if (request.callback) { |
| request.callback(view.chrome.app.window.current()); |
| 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; |
| 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('initializeAppWindow', 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; |
| + |
| + Object.defineProperty(AppWindow.prototype, 'id', {get: function() { |
| + return chromeHidden.appWindowData.id; |
| + }}); |
| + |
| + chromeHidden.appWindowData = { |
| + id: params.id ? params.id : '' |
|
Mihai Parparita -not on Chrome
2012/09/26 22:22:23
Nit: params.id || '' is more idiomatic.
tapted
2012/09/27 01:27:15
Done (also: cool).
|
| + }; |
| + chromeHidden.currentAppWindow = new AppWindow; |
| + }); |
| }); |