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 | 12 |
| 13 chromeHidden.registerCustomHook('app.window', function(bindingsAPI) { | 13 chromeHidden.registerCustomHook('app.window', function(bindingsAPI) { |
| 14 var apiFunctions = bindingsAPI.apiFunctions; | 14 var apiFunctions = bindingsAPI.apiFunctions; |
| 15 apiFunctions.setCustomCallback('create', | 15 apiFunctions.setCustomCallback('create', |
| 16 function(name, request, windowParams) { | 16 function(name, request, windowParams) { |
| 17 var view = null; | 17 var view = null; |
| 18 if (windowParams.viewId) | 18 if (windowParams.viewId) |
| 19 view = GetView(windowParams.viewId, windowParams.injectTitlebar); | 19 view = GetView(windowParams.viewId, windowParams.injectTitlebar); |
| 20 | 20 |
| 21 if (!view) { | 21 if (!view) { |
| 22 // No route to created window. If given a callback, trigger it with an | 22 // No route to created window. If given a callback, trigger it with an |
| 23 // undefined object. | 23 // undefined object. |
| 24 if (request.callback) { | 24 if (request.callback) { |
| 25 request.callback() | 25 request.callback(); |
| 26 delete request.callback; | 26 delete request.callback; |
| 27 } | 27 } |
| 28 return; | 28 return; |
| 29 } | 29 } |
| 30 | 30 |
| 31 // Initialize appWindowData in the newly created JS context | 31 // Initialize appWindowData in the newly created JS context |
| 32 view.chrome.app.window.initializeAppWindow(windowParams); | 32 view.chrome.app.window.initializeAppWindow(windowParams); |
| 33 | 33 |
| 34 if (request.callback) { | 34 if (request.callback) { |
| 35 request.callback(view.chrome.app.window.current()); | 35 request.callback(view.chrome.app.window.current()); |
| 36 delete request.callback; | 36 delete request.callback; |
| 37 } | 37 } |
| 38 }); | 38 }); |
| 39 | 39 |
| 40 apiFunctions.setHandleRequest('current', function() { | 40 apiFunctions.setHandleRequest('current', function() { |
| 41 if (!chromeHidden.currentAppWindow) { | 41 if (!chromeHidden.currentAppWindow) { |
| 42 console.error('chrome.app.window.current() is null -- window not ' + | 42 console.error('chrome.app.window.current() is null -- window not ' + |
| 43 'created with chrome.app.window.create()'); | 43 'created with chrome.app.window.create()'); |
| 44 return null; | 44 return null; |
| 45 } | 45 } |
| 46 return chromeHidden.currentAppWindow; | 46 return chromeHidden.currentAppWindow; |
| 47 }); | 47 }); |
| 48 | 48 |
| 49 chromeHidden.OnAppWindowClosed = function() { | 49 chromeHidden.OnAppWindowClosed = function() { |
| 50 if (!chromeHidden.currentAppWindow) | 50 if (!chromeHidden.currentAppWindow) |
| 51 return; | 51 return; |
| 52 chromeHidden.currentAppWindow.onClose.dispatch(); | 52 chromeHidden.currentAppWindow.onClose.dispatch(); |
| 53 } | 53 }; |
| 54 | 54 |
| 55 // This is an internal function, but needs to be bound with setHandleRequest | 55 // This is an internal function, but needs to be bound with setHandleRequest |
| 56 // because it is called from a different JS context | 56 // because it is called from a different JS context. |
| 57 apiFunctions.setHandleRequest('initializeAppWindow', function(params) { | 57 apiFunctions.setHandleRequest('initializeAppWindow', function(params) { |
| 58 var AppWindow = function() {}; | 58 var AppWindow = function() {}; |
| 59 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) { | 59 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) { |
| 60 AppWindow.prototype[fn] = | 60 AppWindow.prototype[fn] = |
| 61 chromeHidden.internalAPIs.app.currentWindowInternal[fn]; | 61 chromeHidden.internalAPIs.app.currentWindowInternal[fn]; |
| 62 }); | 62 }); |
| 63 AppWindow.prototype.moveTo = window.moveTo.bind(window); | 63 AppWindow.prototype.moveTo = window.moveTo.bind(window); |
| 64 AppWindow.prototype.resizeTo = window.resizeTo.bind(window); | 64 AppWindow.prototype.resizeTo = window.resizeTo.bind(window); |
| 65 AppWindow.prototype.contentWindow = window; | 65 AppWindow.prototype.contentWindow = window; |
| 66 AppWindow.prototype.onClose = new chrome.Event; | 66 AppWindow.prototype.onClose = new chrome.Event; |
| 67 AppWindow.prototype.getBounds = function() { | |
| 68 var data = chromeHidden.appWindowData; | |
| 69 return { x: data.x, y: data.y, width: data.width, height: data.height }; | |
| 70 }; | |
| 67 | 71 |
| 68 Object.defineProperty(AppWindow.prototype, 'id', {get: function() { | 72 Object.defineProperty(AppWindow.prototype, 'id', {get: function() { |
| 69 return chromeHidden.appWindowData.id; | 73 return chromeHidden.appWindowData.id; |
| 70 }}); | 74 }}); |
| 71 | 75 |
| 72 chromeHidden.appWindowData = { | 76 chromeHidden.appWindowData = { |
| 73 id: params.id || '' | 77 id: params.id || '', |
| 78 x: 0, | |
| 79 y: 0, | |
| 80 width: 0, | |
| 81 height: 0 | |
| 74 }; | 82 }; |
| 75 chromeHidden.currentAppWindow = new AppWindow; | 83 chromeHidden.currentAppWindow = new AppWindow; |
| 76 }); | 84 }); |
| 77 }); | 85 }); |
| 86 | |
| 87 chromeHidden.updateAppWindowBounds = function(info) { | |
|
jeremya
2012/10/19 00:26:45
Hm, I should probably use this instead of my bespo
| |
| 88 var data = chromeHidden.appWindowData; | |
| 89 if (!data) | |
| 90 return; | |
| 91 data.x = info.x; | |
|
jeremya
2012/10/19 00:26:45
Perhaps this should be in data.bounds?
| |
| 92 data.y = info.y; | |
| 93 data.width = info.width; | |
| 94 data.height = info.height; | |
| 95 }; | |
| OLD | NEW |