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', function(name, request, result) { | 15 apiFunctions.setCustomCallback('create', |
| 16 var view = null; | 16 function(name, request, windowParams) { |
| 17 if (result.viewId) { | 17 if (!windowParams.viewId) { |
| 18 view = GetView(result.viewId, result.injectTitlebar); | 18 // Create failed? If given a callback, trigger it with an undefined object |
|
Mihai Parparita -not on Chrome
2012/09/26 22:22:23
Nit: period at the end of the comment sentence (ap
tapted
2012/09/27 01:27:15
Done.
| |
| 19 if (request.callback) { | |
| 20 request.callback() | |
| 21 delete request.callback; | |
| 22 } | |
| 23 return; | |
| 19 } | 24 } |
| 25 | |
| 26 var view = GetView(windowParams.viewId, windowParams.injectTitlebar); | |
| 27 | |
| 28 // Initialize appWindowData in the newly created JS context | |
| 29 view.chrome.app.window.initializeAppWindow(windowParams); | |
| 30 | |
| 20 if (request.callback) { | 31 if (request.callback) { |
| 21 request.callback(view.chrome.app.window.current()); | 32 request.callback(view.chrome.app.window.current()); |
| 22 delete request.callback; | 33 delete request.callback; |
| 23 } | 34 } |
| 24 }) | |
| 25 var AppWindow = function() {}; | |
| 26 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) { | |
| 27 AppWindow.prototype[fn] = | |
| 28 chromeHidden.internalAPIs.app.currentWindowInternal[fn]; | |
| 29 }); | 35 }); |
| 30 AppWindow.prototype.moveTo = window.moveTo.bind(window); | |
| 31 AppWindow.prototype.resizeTo = window.resizeTo.bind(window); | |
| 32 AppWindow.prototype.contentWindow = window; | |
| 33 | 36 |
| 34 apiFunctions.setHandleRequest('current', function() { | 37 apiFunctions.setHandleRequest('current', function() { |
| 35 return new AppWindow; | 38 if (!chromeHidden.currentAppWindow) { |
| 36 }) | 39 console.error('chrome.app.window.current() is null -- window not ' + |
| 40 'created with chrome.app.window.create()'); | |
| 41 return null; | |
| 42 } | |
| 43 return chromeHidden.currentAppWindow; | |
| 44 }); | |
| 45 | |
| 46 // This is an internal function, but needs to be bound with setHandleRequest | |
| 47 // because it is called from a different JS context | |
| 48 apiFunctions.setHandleRequest('initializeAppWindow', function(params) { | |
| 49 var AppWindow = function() {}; | |
| 50 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) { | |
| 51 AppWindow.prototype[fn] = | |
| 52 chromeHidden.internalAPIs.app.currentWindowInternal[fn]; | |
| 53 }); | |
| 54 AppWindow.prototype.moveTo = window.moveTo.bind(window); | |
| 55 AppWindow.prototype.resizeTo = window.resizeTo.bind(window); | |
| 56 AppWindow.prototype.contentWindow = window; | |
| 57 | |
| 58 Object.defineProperty(AppWindow.prototype, 'id', {get: function() { | |
| 59 return chromeHidden.appWindowData.id; | |
| 60 }}); | |
| 61 | |
| 62 chromeHidden.appWindowData = { | |
| 63 id: params.id ? params.id : '' | |
|
Mihai Parparita -not on Chrome
2012/09/26 22:22:23
Nit: params.id || '' is more idiomatic.
tapted
2012/09/27 01:27:15
Done (also: cool).
| |
| 64 }; | |
| 65 chromeHidden.currentAppWindow = new AppWindow; | |
| 66 }); | |
| 37 }); | 67 }); |
| OLD | NEW |