Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 bindings for the app_window API. | 5 // Custom bindings for the app_window API. |
| 6 | 6 |
| 7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
| 8 var sendRequest = require('sendRequest').sendRequest; | 8 var sendRequest = require('sendRequest').sendRequest; |
| 9 var appWindowNatives = requireNative('app_window'); | 9 var appWindowNatives = requireNative('app_window'); |
| 10 var forEach = require('utils').forEach; | 10 var forEach = require('utils').forEach; |
| 11 var GetView = appWindowNatives.GetView; | 11 var GetView = appWindowNatives.GetView; |
| 12 var GetCurrentRoutingID = appWindowNatives.GetCurrentRoutingID; | |
| 12 | 13 |
| 13 chromeHidden.registerCustomHook('app.window', function(bindingsAPI) { | 14 chromeHidden.registerCustomHook('app.window', function(bindingsAPI) { |
| 15 chromeHidden.appWindow = {}; | |
| 16 chromeHidden.appWindow.windowCache = {}; | |
| 17 | |
| 14 var apiFunctions = bindingsAPI.apiFunctions; | 18 var apiFunctions = bindingsAPI.apiFunctions; |
| 15 apiFunctions.setCustomCallback('create', function(name, request, viewId) { | 19 apiFunctions.setCustomCallback('create', function(name, request, viewId) { |
| 16 var view = null; | 20 if (!viewId) { |
| 17 if (viewId) { | 21 if (request.callback) { |
| 18 var shouldShowFrame = !request.args[1] || request.args[1].frame != 'none'; | 22 request.callback() |
| 19 view = GetView(viewId, !!shouldShowFrame); | 23 delete request.callback; |
| 24 } | |
| 25 return; // under what cases can this be null..? | |
| 20 } | 26 } |
| 27 | |
| 28 var params = request.args[1]; | |
| 29 var shouldShowFrame = !params || params.frame != 'none'; | |
| 30 var view = GetView(viewId, !!shouldShowFrame); | |
| 31 var state = { | |
| 32 viewId: viewId, | |
| 33 windowKey: params.id ? params.id : '', | |
| 34 minWidth: parms.minWidth ? params.minWidth : 0, | |
| 35 minHeight: params.minHeight ? parmas.minHeight : 0, | |
| 36 maxWidth: params.maxWidth ? params.maxWidth : -1, | |
| 37 maxHeight: params.maxHeight ? params.maxHeight : -1, | |
| 38 windowState: '', | |
| 39 windowType: params.type ? params.type : 'shell', | |
| 40 frameType: params.frame ? params.frame : 'chrome' | |
| 41 }; | |
| 42 var appWindow = view.chrome.app.window.makeAppWindow(state); | |
| 43 | |
| 21 if (request.callback) { | 44 if (request.callback) { |
| 22 request.callback(view.chrome.app.window.current()); | 45 request.callback(appWindow); |
| 23 delete request.callback; | 46 delete request.callback; |
| 24 } | 47 } |
| 25 }) | 48 }); |
| 26 var AppWindow = function() {}; | 49 var AppWindow = function() {}; |
| 27 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) { | 50 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) { |
| 28 AppWindow.prototype[fn] = | 51 AppWindow.prototype[fn] = |
| 29 chromeHidden.internalAPIs.app.currentWindowInternal[fn]; | 52 chromeHidden.internalAPIs.app.currentWindowInternal[fn]; |
| 30 }); | 53 }); |
| 31 AppWindow.prototype.moveTo = window.moveTo.bind(window); | 54 AppWindow.prototype.moveTo = window.moveTo.bind(window); |
| 32 AppWindow.prototype.resizeTo = window.resizeTo.bind(window); | 55 AppWindow.prototype.resizeTo = window.resizeTo.bind(window); |
| 33 AppWindow.prototype.contentWindow = window; | 56 AppWindow.prototype.contentWindow = window; |
| 34 // So as not to break apps that use .dom. http://crbug.com/147668 | 57 // So as not to break apps that use .dom. http://crbug.com/147668 |
| 35 // TODO(jeremya): remove this once M23 has branched. | 58 // TODO(jeremya): remove this once M23 has branched. |
| 36 AppWindow.prototype.dom = window; | 59 AppWindow.prototype.dom = window; |
| 60 AppWindow.prototype.__defineGetter__('windowKey', function() { | |
| 61 var meta = chromeHidden.appWindow.windowCache[this.viewId]; | |
| 62 return meta ? meta.windowKey : ''; | |
| 63 }); | |
| 64 AppWindow.prototype.__defineGetter__('width', function() { | |
| 65 return this.contentWindow.innerWidth; | |
| 66 }); | |
| 67 AppWindow.prototype.__defineGetter__('height', function() { | |
| 68 // NOTE(tapted) Should we subtract the height of the injected titlebar? | |
| 69 // see crbug.com/148594 | |
| 70 return this.contentWindow.innerHeight; | |
| 71 }); | |
| 72 AppWindow.prototype.__defineGetter__('left', function() { | |
| 73 return this.contentWindow.screenX; | |
| 74 }); | |
| 75 AppWindow.prototype.__defineGetter__('top', function() { | |
| 76 // NOTE(tapted) Should we add the height of the injected titlebar? | |
| 77 return this.contentWindow.screenY; | |
| 78 }); | |
| 79 AppWindow.prototype.__defineGetter__('minWidth', function() { | |
| 80 var meta = chromeHidden.appWindow.windowCache[this.viewId]; | |
| 81 return meta ? meta.minWidth : ''; | |
| 82 }); | |
| 83 AppWindow.prototype.__defineGetter__('minHeight', function() { | |
| 84 var meta = chromeHidden.appWindow.windowCache[this.viewId]; | |
| 85 return meta ? meta.minHeight : ''; | |
| 86 }); | |
| 87 AppWindow.prototype.__defineGetter__('maxWidth', function() { | |
| 88 var meta = chromeHidden.appWindow.windowCache[this.viewId]; | |
| 89 return meta ? meta.maxWidth : ''; | |
| 90 }); | |
| 91 AppWindow.prototype.__defineGetter__('maxHeight', function() { | |
| 92 var meta = chromeHidden.appWindow.windowCache[this.viewId]; | |
| 93 return meta ? meta.maxHeight : ''; | |
| 94 }); | |
| 95 AppWindow.prototype.__defineGetter__('windowState', function() { | |
| 96 var meta = chromeHidden.appWindow.windowCache[this.viewId]; | |
| 97 return meta ? meta.windowState : ''; | |
| 98 }); | |
| 99 AppWindow.prototype.__defineGetter__('windowType', function() { | |
| 100 var meta = chromeHidden.appWindow.windowCache[this.viewId]; | |
| 101 return meta ? meta.windowType : ''; | |
| 102 }); | |
| 103 AppWindow.prototype.__defineGetter__('frameType', function() { | |
| 104 var meta = chromeHidden.appWindow.windowCache[this.viewId]; | |
| 105 return meta ? meta.frameType : ''; | |
| 106 }); | |
| 107 | |
| 108 // 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
| |
| 37 apiFunctions.setHandleRequest('current', function() { | 109 apiFunctions.setHandleRequest('current', function() { |
| 38 return new AppWindow; | 110 var viewId = GetCurrentRoutingID(); |
| 39 }) | 111 var meta = chromeHidden.appWindow.windowCache[viewId]; |
| 112 if (meta) | |
| 113 return meta.appWindow; | |
| 114 | |
| 115 var appWindow = chrome.app.window.makeAppWindow({ | |
| 116 viewId: viewId, | |
| 117 windowKey: 'waiting-for-callback' | |
| 118 /* others */ | |
| 119 }); | |
| 120 console.log('slowpath (developer refresh?) windowCache[viewId] = null'); | |
| 121 return appWindow; | |
| 122 }); | |
| 123 | |
| 124 // TODO(tapted) this should be "internal only" but needs to be called on a | |
| 125 // different JS context -- still need to find out how to do that neatly | |
| 126 apiFunctions.setHandleRequest('makeAppWindow', function(params) { | |
| 127 var newWindow = new AppWindow; | |
| 128 newWindow.viewId = params.viewId; | |
| 129 var cache = { | |
| 130 appWindow: newWindow, | |
| 131 windowKey: params.windowKey, | |
| 132 minWidth: params.minWidth, | |
| 133 minHeight: params.minHeight, | |
| 134 maxWidth: params.maxWidth, | |
| 135 maxHeight: params.maxHeight, | |
| 136 windowState: params.windowState, | |
| 137 windowType: params.windowType, | |
| 138 frameType: params.frameType | |
| 139 }; | |
| 140 chromeHidden.appWindow.windowCache[newWindow.viewId] = cache; | |
| 141 // asynchronously update state from actual window properties | |
| 142 newWindow.getState(function(state) { | |
| 143 for (k in state) | |
| 144 cache[k] = state[k]; | |
| 145 }); | |
| 146 newWindow.contentWindow.addEventListener('resize', function(e) { | |
| 147 // TODO(tapted): why is this called twice on each resize? | |
| 148 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
| |
| 149 var meta = appWindow ? | |
| 150 chromeHidden.appWindow.windowCache[appWindow.viewId] : | |
| 151 null; | |
| 152 if (!meta) | |
| 153 return; | |
| 154 }); | |
| 155 Object.freeze(newWindow); | |
| 156 return newWindow; | |
| 157 }); | |
| 40 }); | 158 }); |
| OLD | NEW |