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 Bindings = require('schema_binding_generator').Bindings; |
| 8 var bindings = new Bindings('app.window'); |
| 9 |
7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 10 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
| 11 var chrome = requireNative('chrome').GetChrome(); |
8 var sendRequest = require('sendRequest').sendRequest; | 12 var sendRequest = require('sendRequest').sendRequest; |
9 var appWindowNatives = requireNative('app_window'); | 13 var appWindowNatives = requireNative('app_window'); |
10 var forEach = require('utils').forEach; | 14 var forEach = require('utils').forEach; |
11 var GetView = appWindowNatives.GetView; | 15 var GetView = appWindowNatives.GetView; |
12 var OnContextReady = appWindowNatives.OnContextReady; | 16 var OnContextReady = appWindowNatives.OnContextReady; |
13 | 17 |
14 chromeHidden.registerCustomHook('app.window', function(bindingsAPI) { | 18 bindings.registerCustomHook(function(bindingsAPI) { |
15 var apiFunctions = bindingsAPI.apiFunctions; | 19 var apiFunctions = bindingsAPI.apiFunctions; |
| 20 |
16 apiFunctions.setCustomCallback('create', | 21 apiFunctions.setCustomCallback('create', |
17 function(name, request, windowParams) { | 22 function(name, request, windowParams) { |
18 var view = null; | 23 var view = null; |
19 if (windowParams.viewId) | 24 if (windowParams.viewId) |
20 view = GetView(windowParams.viewId, windowParams.injectTitlebar); | 25 view = GetView(windowParams.viewId, windowParams.injectTitlebar); |
21 | 26 |
22 if (!view) { | 27 if (!view) { |
23 // No route to created window. If given a callback, trigger it with an | 28 // No route to created window. If given a callback, trigger it with an |
24 // undefined object. | 29 // undefined object. |
25 if (request.callback) { | 30 if (request.callback) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 79 |
75 chromeHidden.OnAppWindowClosed = function() { | 80 chromeHidden.OnAppWindowClosed = function() { |
76 if (!chromeHidden.currentAppWindow) | 81 if (!chromeHidden.currentAppWindow) |
77 return; | 82 return; |
78 chromeHidden.currentAppWindow.onClosed.dispatch(); | 83 chromeHidden.currentAppWindow.onClosed.dispatch(); |
79 }; | 84 }; |
80 | 85 |
81 // This is an internal function, but needs to be bound with setHandleRequest | 86 // This is an internal function, but needs to be bound with setHandleRequest |
82 // because it is called from a different JS context. | 87 // because it is called from a different JS context. |
83 apiFunctions.setHandleRequest('initializeAppWindow', function(params) { | 88 apiFunctions.setHandleRequest('initializeAppWindow', function(params) { |
| 89 // TODO(cduvall): Fix dependencies. |
| 90 chrome.app.currentWindowInternal; |
| 91 |
84 var AppWindow = function() {}; | 92 var AppWindow = function() {}; |
85 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) { | 93 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) { |
86 AppWindow.prototype[fn] = | 94 AppWindow.prototype[fn] = |
87 chromeHidden.internalAPIs.app.currentWindowInternal[fn]; | 95 chromeHidden.internalAPIs.app.currentWindowInternal[fn]; |
88 }); | 96 }); |
89 AppWindow.prototype.moveTo = window.moveTo.bind(window); | 97 AppWindow.prototype.moveTo = window.moveTo.bind(window); |
90 AppWindow.prototype.resizeTo = window.resizeTo.bind(window); | 98 AppWindow.prototype.resizeTo = window.resizeTo.bind(window); |
91 AppWindow.prototype.contentWindow = window; | 99 AppWindow.prototype.contentWindow = window; |
92 AppWindow.prototype.onClosed = new chrome.Event; | 100 AppWindow.prototype.onClosed = new chrome.Event; |
93 AppWindow.prototype.close = function() { | 101 AppWindow.prototype.close = function() { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 149 |
142 if (!oldData.minimized && update.minimized) | 150 if (!oldData.minimized && update.minimized) |
143 currentWindow["onMinimized"].dispatch(); | 151 currentWindow["onMinimized"].dispatch(); |
144 if (!oldData.maximized && update.maximized) | 152 if (!oldData.maximized && update.maximized) |
145 currentWindow["onMaximized"].dispatch(); | 153 currentWindow["onMaximized"].dispatch(); |
146 | 154 |
147 if ((oldData.minimized && !update.minimized) || | 155 if ((oldData.minimized && !update.minimized) || |
148 (oldData.maximized && !update.maximized)) | 156 (oldData.maximized && !update.maximized)) |
149 currentWindow["onRestored"].dispatch(); | 157 currentWindow["onRestored"].dispatch(); |
150 }; | 158 }; |
| 159 |
| 160 exports.bindings = bindings.generate(); |
OLD | NEW |