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