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 binding for the app_window API. | 5 // Custom binding for the app_window API. |
6 | 6 |
7 var Binding = require('binding').Binding; | 7 var Binding = require('binding').Binding; |
8 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 8 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
9 var chrome = requireNative('chrome').GetChrome(); | 9 var chrome = requireNative('chrome').GetChrome(); |
10 var sendRequest = require('sendRequest').sendRequest; | 10 var sendRequest = require('sendRequest').sendRequest; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 69 |
70 apiFunctions.setHandleRequest('current', function() { | 70 apiFunctions.setHandleRequest('current', function() { |
71 if (!chromeHidden.currentAppWindow) { | 71 if (!chromeHidden.currentAppWindow) { |
72 console.error('chrome.app.window.current() is null -- window not ' + | 72 console.error('chrome.app.window.current() is null -- window not ' + |
73 'created with chrome.app.window.create()'); | 73 'created with chrome.app.window.create()'); |
74 return null; | 74 return null; |
75 } | 75 } |
76 return chromeHidden.currentAppWindow; | 76 return chromeHidden.currentAppWindow; |
77 }); | 77 }); |
78 | 78 |
79 chromeHidden.OnAppWindowClosed = function() { | |
80 if (!chromeHidden.currentAppWindow) | |
81 return; | |
82 chromeHidden.currentAppWindow.onClosed.dispatch(); | |
83 }; | |
84 | |
85 // This is an internal function, but needs to be bound with setHandleRequest | 79 // This is an internal function, but needs to be bound with setHandleRequest |
86 // because it is called from a different JS context. | 80 // because it is called from a different JS context. |
87 apiFunctions.setHandleRequest('initializeAppWindow', function(params) { | 81 apiFunctions.setHandleRequest('initializeAppWindow', function(params) { |
88 var currentWindowInternal = | 82 var currentWindowInternal = |
89 Binding.create('app.currentWindowInternal').generate(); | 83 Binding.create('app.currentWindowInternal').generate(); |
90 var AppWindow = function() {}; | 84 var AppWindow = function() {}; |
91 forEach(currentWindowInternal, function(fn) { | 85 forEach(currentWindowInternal, function(fn) { |
92 AppWindow.prototype[fn] = | 86 AppWindow.prototype[fn] = |
93 currentWindowInternal[fn]; | 87 currentWindowInternal[fn]; |
94 }); | 88 }); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 }); | 124 }); |
131 }); | 125 }); |
132 | 126 |
133 function boundsEqual(bounds1, bounds2) { | 127 function boundsEqual(bounds1, bounds2) { |
134 if (!bounds1 || !bounds2) | 128 if (!bounds1 || !bounds2) |
135 return false; | 129 return false; |
136 return (bounds1.left == bounds2.left && bounds1.top == bounds2.top && | 130 return (bounds1.left == bounds2.left && bounds1.top == bounds2.top && |
137 bounds1.width == bounds2.width && bounds1.height == bounds2.height); | 131 bounds1.width == bounds2.width && bounds1.height == bounds2.height); |
138 } | 132 } |
139 | 133 |
140 chromeHidden.updateAppWindowProperties = function(update) { | 134 function updateAppWindowProperties(update) { |
141 if (!chromeHidden.appWindowData) | 135 if (!chromeHidden.appWindowData) |
142 return; | 136 return; |
143 var oldData = chromeHidden.appWindowData; | 137 var oldData = chromeHidden.appWindowData; |
144 update.id = oldData.id; | 138 update.id = oldData.id; |
145 chromeHidden.appWindowData = update; | 139 chromeHidden.appWindowData = update; |
146 | 140 |
147 var currentWindow = chromeHidden.currentAppWindow; | 141 var currentWindow = chromeHidden.currentAppWindow; |
148 | 142 |
149 if (!boundsEqual(oldData.bounds, update.bounds)) | 143 if (!boundsEqual(oldData.bounds, update.bounds)) |
150 currentWindow["onBoundsChanged"].dispatch(); | 144 currentWindow["onBoundsChanged"].dispatch(); |
151 | 145 |
152 if (!oldData.fullscreen && update.fullscreen) | 146 if (!oldData.fullscreen && update.fullscreen) |
153 currentWindow["onFullscreened"].dispatch(); | 147 currentWindow["onFullscreened"].dispatch(); |
154 if (!oldData.minimized && update.minimized) | 148 if (!oldData.minimized && update.minimized) |
155 currentWindow["onMinimized"].dispatch(); | 149 currentWindow["onMinimized"].dispatch(); |
156 if (!oldData.maximized && update.maximized) | 150 if (!oldData.maximized && update.maximized) |
157 currentWindow["onMaximized"].dispatch(); | 151 currentWindow["onMaximized"].dispatch(); |
158 | 152 |
159 if ((oldData.fullscreen && !update.fullscreen) || | 153 if ((oldData.fullscreen && !update.fullscreen) || |
160 (oldData.minimized && !update.minimized) || | 154 (oldData.minimized && !update.minimized) || |
161 (oldData.maximized && !update.maximized)) | 155 (oldData.maximized && !update.maximized)) |
162 currentWindow["onRestored"].dispatch(); | 156 currentWindow["onRestored"].dispatch(); |
163 }; | 157 }; |
164 | 158 |
| 159 function onAppWindowClosed() { |
| 160 if (!chromeHidden.currentAppWindow) |
| 161 return; |
| 162 chromeHidden.currentAppWindow.onClosed.dispatch(); |
| 163 } |
| 164 |
165 exports.binding = appWindow.generate(); | 165 exports.binding = appWindow.generate(); |
| 166 exports.onAppWindowClosed = onAppWindowClosed; |
| 167 exports.updateAppWindowProperties = updateAppWindowProperties; |
OLD | NEW |