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, viewId) { | 15 apiFunctions.setCustomCallback('create', |
| 16 var view = null; | 16 function(name, request, shellWindow) { |
|
benwells
2012/09/19 00:09:21
Nit: windowParams feels like a better name than sh
tapted
2012/09/19 00:54:02
Done.
| |
| 17 if (viewId) { | 17 if (!shellWindow || !shellWindow.viewId) { |
| 18 var shouldShowFrame = !request.args[1] || request.args[1].frame != 'none'; | 18 // Create failed? If given a callback, trigger it with an undefined object |
| 19 view = GetView(viewId, !!shouldShowFrame); | 19 if (request.callback) { |
| 20 request.callback() | |
| 21 delete request.callback; | |
| 22 } | |
| 23 return; | |
| 20 } | 24 } |
| 25 | |
| 26 var params = request.args[1]; | |
| 27 var shouldShowFrame = !params || params.frame != 'none'; | |
| 28 var view = GetView(shellWindow.viewId, !!shouldShowFrame); | |
| 29 | |
| 30 // Call makeAppWindow in the newly created JS context | |
| 31 var appWindow = view.chrome.app.window.makeAppWindow(shellWindow); | |
|
benwells
2012/09/19 00:09:21
Something to consider: have makeAppWindow just mak
| |
| 32 | |
| 21 if (request.callback) { | 33 if (request.callback) { |
| 22 request.callback(view.chrome.app.window.current()); | 34 request.callback(appWindow); |
| 23 delete request.callback; | 35 delete request.callback; |
| 24 } | 36 } |
| 25 }) | |
| 26 var AppWindow = function() {}; | |
| 27 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) { | |
| 28 AppWindow.prototype[fn] = | |
| 29 chromeHidden.internalAPIs.app.currentWindowInternal[fn]; | |
| 30 }); | 37 }); |
| 31 AppWindow.prototype.moveTo = window.moveTo.bind(window); | 38 |
| 32 AppWindow.prototype.resizeTo = window.resizeTo.bind(window); | |
| 33 AppWindow.prototype.contentWindow = window; | |
| 34 // So as not to break apps that use .dom. http://crbug.com/147668 | |
| 35 // TODO(jeremya): remove this once M23 has branched. | |
| 36 AppWindow.prototype.dom = window; | |
| 37 apiFunctions.setHandleRequest('current', function() { | 39 apiFunctions.setHandleRequest('current', function() { |
| 38 return new AppWindow; | 40 if (!chromeHidden.appWindow) { |
| 39 }) | 41 console.error('chrome.app.window.current() is null -- window not ' + |
| 42 'created with chrome.app.window.create()'); | |
| 43 return null; | |
| 44 } | |
| 45 return chromeHidden.appWindow.currentWindow; | |
| 46 }); | |
| 47 | |
| 48 // This is an internal function, but needs to be bound with setHandleRequest | |
| 49 // because it is called from a different JS context | |
| 50 apiFunctions.setHandleRequest('makeAppWindow', function(params) { | |
| 51 var AppWindow = function() {}; | |
| 52 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) { | |
| 53 AppWindow.prototype[fn] = | |
| 54 chromeHidden.internalAPIs.app.currentWindowInternal[fn]; | |
| 55 }); | |
| 56 AppWindow.prototype.moveTo = window.moveTo.bind(window); | |
| 57 AppWindow.prototype.resizeTo = window.resizeTo.bind(window); | |
| 58 AppWindow.prototype.contentWindow = window; | |
| 59 // So as not to break apps that use .dom. http://crbug.com/147668 | |
| 60 // TODO(jeremya): remove this once M23 has branched. | |
| 61 AppWindow.prototype.dom = window; | |
| 62 | |
| 63 Object.defineProperty(AppWindow.prototype, 'id', {get: function() { | |
| 64 return chromeHidden.appWindow.windowCache.id; | |
| 65 }}); | |
| 66 | |
| 67 chromeHidden.appWindow = { | |
|
benwells
2012/09/19 00:09:21
Something else to consider: don't use an object un
tapted
2012/09/19 00:54:02
Done.
| |
| 68 windowCache: { | |
| 69 id: params.id ? params.id : '' | |
| 70 }, | |
| 71 currentWindow: new AppWindow | |
| 72 }; | |
| 73 return chromeHidden.appWindow.currentWindow; | |
| 74 }); | |
| 40 }); | 75 }); |
| OLD | NEW |