| 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', function(name, request, result) { |
| 16 var view = null; | 16 var view = null; |
| 17 if (viewId) { | 17 if (result.viewId) { |
| 18 var shouldShowFrame = !request.args[1] || request.args[1].frame != 'none'; | 18 view = GetView(result.viewId, result.injectTitlebar); |
| 19 view = GetView(viewId, !!shouldShowFrame); | |
| 20 } | 19 } |
| 21 if (request.callback) { | 20 if (request.callback) { |
| 22 request.callback(view.chrome.app.window.current()); | 21 request.callback(view.chrome.app.window.current()); |
| 23 delete request.callback; | 22 delete request.callback; |
| 24 } | 23 } |
| 25 }) | 24 }) |
| 26 var AppWindow = function() {}; | 25 var AppWindow = function() {}; |
| 27 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) { | 26 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) { |
| 28 AppWindow.prototype[fn] = | 27 AppWindow.prototype[fn] = |
| 29 chromeHidden.internalAPIs.app.currentWindowInternal[fn]; | 28 chromeHidden.internalAPIs.app.currentWindowInternal[fn]; |
| 30 }); | 29 }); |
| 31 AppWindow.prototype.moveTo = window.moveTo.bind(window); | 30 AppWindow.prototype.moveTo = window.moveTo.bind(window); |
| 32 AppWindow.prototype.resizeTo = window.resizeTo.bind(window); | 31 AppWindow.prototype.resizeTo = window.resizeTo.bind(window); |
| 33 AppWindow.prototype.contentWindow = window; | 32 AppWindow.prototype.contentWindow = window; |
| 34 // So as not to break apps that use .dom. http://crbug.com/147668 | 33 // So as not to break apps that use .dom. http://crbug.com/147668 |
| 35 // TODO(jeremya): remove this once M23 has branched. | 34 // TODO(jeremya): remove this once M23 has branched. |
| 36 AppWindow.prototype.dom = window; | 35 AppWindow.prototype.dom = window; |
| 37 apiFunctions.setHandleRequest('current', function() { | 36 apiFunctions.setHandleRequest('current', function() { |
| 38 return new AppWindow; | 37 return new AppWindow; |
| 39 }) | 38 }) |
| 40 }); | 39 }); |
| OLD | NEW |