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 04283fec5a0ed4059a0a36f007f8decec9d2bf11..9d86791e133cd73e98213c193ddf05bcbcfc860e 100644 |
| --- a/chrome/renderer/resources/extensions/app_window_custom_bindings.js |
| +++ b/chrome/renderer/resources/extensions/app_window_custom_bindings.js |
| @@ -12,29 +12,64 @@ var GetView = appWindowNatives.GetView; |
| chromeHidden.registerCustomHook('app.window', function(bindingsAPI) { |
| var apiFunctions = bindingsAPI.apiFunctions; |
| - apiFunctions.setCustomCallback('create', function(name, request, viewId) { |
| - var view = null; |
| - if (viewId) { |
| - var shouldShowFrame = !request.args[1] || request.args[1].frame != 'none'; |
| - view = GetView(viewId, !!shouldShowFrame); |
| + apiFunctions.setCustomCallback('create', |
| + function(name, request, shellWindow) { |
|
benwells
2012/09/19 00:09:21
Nit: windowParams feels like a better name than sh
tapted
2012/09/19 00:54:02
Done.
|
| + if (!shellWindow || !shellWindow.viewId) { |
| + // Create failed? If given a callback, trigger it with an undefined object |
| + if (request.callback) { |
| + request.callback() |
| + delete request.callback; |
| + } |
| + return; |
| } |
| + |
| + var params = request.args[1]; |
| + var shouldShowFrame = !params || params.frame != 'none'; |
| + var view = GetView(shellWindow.viewId, !!shouldShowFrame); |
| + |
| + // Call makeAppWindow in the newly created JS context |
| + var appWindow = view.chrome.app.window.makeAppWindow(shellWindow); |
|
benwells
2012/09/19 00:09:21
Something to consider: have makeAppWindow just mak
|
| + |
| 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.appWindow) { |
| + console.error('chrome.app.window.current() is null -- window not ' + |
| + 'created with chrome.app.window.create()'); |
| + return null; |
| + } |
| + return chromeHidden.appWindow.currentWindow; |
| + }); |
| + |
| + // 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.appWindow.windowCache.id; |
| + }}); |
| + |
| + chromeHidden.appWindow = { |
|
benwells
2012/09/19 00:09:21
Something else to consider: don't use an object un
tapted
2012/09/19 00:54:02
Done.
|
| + windowCache: { |
| + id: params.id ? params.id : '' |
| + }, |
| + currentWindow: new AppWindow |
| + }; |
| + return chromeHidden.appWindow.currentWindow; |
| + }); |
| }); |