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..0b60d0fa2af057807766d4f8183909e8c58b53f3 100644 |
| --- a/chrome/renderer/resources/extensions/app_window_custom_bindings.js |
| +++ b/chrome/renderer/resources/extensions/app_window_custom_bindings.js |
| @@ -9,20 +9,43 @@ var sendRequest = require('sendRequest').sendRequest; |
| var appWindowNatives = requireNative('app_window'); |
| var forEach = require('utils').forEach; |
| var GetView = appWindowNatives.GetView; |
| +var GetCurrentRoutingID = appWindowNatives.GetCurrentRoutingID; |
| chromeHidden.registerCustomHook('app.window', function(bindingsAPI) { |
| + chromeHidden.appWindow = {}; |
| + chromeHidden.appWindow.windowCache = {}; |
| + |
| 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); |
| + if (!viewId) { |
| + if (request.callback) { |
| + request.callback() |
| + delete request.callback; |
| + } |
| + return; // under what cases can this be null..? |
| } |
| + |
| + var params = request.args[1]; |
| + var shouldShowFrame = !params || params.frame != 'none'; |
| + var view = GetView(viewId, !!shouldShowFrame); |
| + var state = { |
| + viewId: viewId, |
| + windowKey: params.id ? params.id : '', |
| + minWidth: parms.minWidth ? params.minWidth : 0, |
| + minHeight: params.minHeight ? parmas.minHeight : 0, |
| + maxWidth: params.maxWidth ? params.maxWidth : -1, |
| + maxHeight: params.maxHeight ? params.maxHeight : -1, |
| + windowState: '', |
| + windowType: params.type ? params.type : 'shell', |
| + frameType: params.frame ? params.frame : 'chrome' |
| + }; |
| + var appWindow = view.chrome.app.window.makeAppWindow(state); |
| + |
| 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] = |
| @@ -34,7 +57,102 @@ chromeHidden.registerCustomHook('app.window', function(bindingsAPI) { |
| // 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; |
| + AppWindow.prototype.__defineGetter__('windowKey', function() { |
| + var meta = chromeHidden.appWindow.windowCache[this.viewId]; |
| + return meta ? meta.windowKey : ''; |
| + }); |
| + AppWindow.prototype.__defineGetter__('width', function() { |
| + return this.contentWindow.innerWidth; |
| + }); |
| + AppWindow.prototype.__defineGetter__('height', function() { |
| + // NOTE(tapted) Should we subtract the height of the injected titlebar? |
| + // see crbug.com/148594 |
| + return this.contentWindow.innerHeight; |
| + }); |
| + AppWindow.prototype.__defineGetter__('left', function() { |
| + return this.contentWindow.screenX; |
| + }); |
| + AppWindow.prototype.__defineGetter__('top', function() { |
| + // NOTE(tapted) Should we add the height of the injected titlebar? |
| + return this.contentWindow.screenY; |
| + }); |
| + AppWindow.prototype.__defineGetter__('minWidth', function() { |
| + var meta = chromeHidden.appWindow.windowCache[this.viewId]; |
| + return meta ? meta.minWidth : ''; |
| + }); |
| + AppWindow.prototype.__defineGetter__('minHeight', function() { |
| + var meta = chromeHidden.appWindow.windowCache[this.viewId]; |
| + return meta ? meta.minHeight : ''; |
| + }); |
| + AppWindow.prototype.__defineGetter__('maxWidth', function() { |
| + var meta = chromeHidden.appWindow.windowCache[this.viewId]; |
| + return meta ? meta.maxWidth : ''; |
| + }); |
| + AppWindow.prototype.__defineGetter__('maxHeight', function() { |
| + var meta = chromeHidden.appWindow.windowCache[this.viewId]; |
| + return meta ? meta.maxHeight : ''; |
| + }); |
| + AppWindow.prototype.__defineGetter__('windowState', function() { |
| + var meta = chromeHidden.appWindow.windowCache[this.viewId]; |
| + return meta ? meta.windowState : ''; |
| + }); |
| + AppWindow.prototype.__defineGetter__('windowType', function() { |
| + var meta = chromeHidden.appWindow.windowCache[this.viewId]; |
| + return meta ? meta.windowType : ''; |
| + }); |
| + AppWindow.prototype.__defineGetter__('frameType', function() { |
| + var meta = chromeHidden.appWindow.windowCache[this.viewId]; |
| + return meta ? meta.frameType : ''; |
| + }); |
| + |
| + // NOTE(tapted) this version should solve crbug.com/148814 |
|
Mihai Parparita -not on Chrome
2012/09/16 05:31:39
Can you break out the fix for this bug into a sepa
tapted
2012/09/17 08:48:56
Good call -- I've created http://codereview.chromi
|
| apiFunctions.setHandleRequest('current', function() { |
| - return new AppWindow; |
| - }) |
| + var viewId = GetCurrentRoutingID(); |
| + var meta = chromeHidden.appWindow.windowCache[viewId]; |
| + if (meta) |
| + return meta.appWindow; |
| + |
| + var appWindow = chrome.app.window.makeAppWindow({ |
| + viewId: viewId, |
| + windowKey: 'waiting-for-callback' |
| + /* others */ |
| + }); |
| + console.log('slowpath (developer refresh?) windowCache[viewId] = null'); |
| + return appWindow; |
| + }); |
| + |
| + // TODO(tapted) this should be "internal only" but needs to be called on a |
| + // different JS context -- still need to find out how to do that neatly |
| + apiFunctions.setHandleRequest('makeAppWindow', function(params) { |
| + var newWindow = new AppWindow; |
| + newWindow.viewId = params.viewId; |
| + var cache = { |
| + appWindow: newWindow, |
| + windowKey: params.windowKey, |
| + minWidth: params.minWidth, |
| + minHeight: params.minHeight, |
| + maxWidth: params.maxWidth, |
| + maxHeight: params.maxHeight, |
| + windowState: params.windowState, |
| + windowType: params.windowType, |
| + frameType: params.frameType |
| + }; |
| + chromeHidden.appWindow.windowCache[newWindow.viewId] = cache; |
| + // asynchronously update state from actual window properties |
| + newWindow.getState(function(state) { |
| + for (k in state) |
| + cache[k] = state[k]; |
| + }); |
| + newWindow.contentWindow.addEventListener('resize', function(e) { |
| + // TODO(tapted): why is this called twice on each resize? |
| + var appWindow = chrome.app.window.current(); |
|
Mihai Parparita -not on Chrome
2012/09/16 05:31:39
Do you need to look up the current window? It seem
tapted
2012/09/17 08:48:56
current() had some logic to deal with developer-re
|
| + var meta = appWindow ? |
| + chromeHidden.appWindow.windowCache[appWindow.viewId] : |
| + null; |
| + if (!meta) |
| + return; |
| + }); |
| + Object.freeze(newWindow); |
| + return newWindow; |
| + }); |
| }); |