| 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 if (!windowParams.viewId) { | 17 var view = null; |
| 18 // Create failed? If given a callback, trigger it with an undefined | 18 if (windowParams.viewId) |
| 19 // object. | 19 view = GetView(windowParams.viewId, windowParams.injectTitlebar); |
| 20 |
| 21 if (!view) { |
| 22 // No route to created window. If given a callback, trigger it with an |
| 23 // undefined object. |
| 20 if (request.callback) { | 24 if (request.callback) { |
| 21 request.callback() | 25 request.callback() |
| 22 delete request.callback; | 26 delete request.callback; |
| 23 } | 27 } |
| 24 return; | 28 return; |
| 25 } | 29 } |
| 26 | 30 |
| 27 var view = GetView(windowParams.viewId, windowParams.injectTitlebar); | |
| 28 | |
| 29 // Initialize appWindowData in the newly created JS context | 31 // Initialize appWindowData in the newly created JS context |
| 30 view.chrome.app.window.initializeAppWindow(windowParams); | 32 view.chrome.app.window.initializeAppWindow(windowParams); |
| 31 | 33 |
| 32 if (request.callback) { | 34 if (request.callback) { |
| 33 request.callback(view.chrome.app.window.current()); | 35 request.callback(view.chrome.app.window.current()); |
| 34 delete request.callback; | 36 delete request.callback; |
| 35 } | 37 } |
| 36 }); | 38 }); |
| 37 | 39 |
| 38 apiFunctions.setHandleRequest('current', function() { | 40 apiFunctions.setHandleRequest('current', function() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 59 Object.defineProperty(AppWindow.prototype, 'id', {get: function() { | 61 Object.defineProperty(AppWindow.prototype, 'id', {get: function() { |
| 60 return chromeHidden.appWindowData.id; | 62 return chromeHidden.appWindowData.id; |
| 61 }}); | 63 }}); |
| 62 | 64 |
| 63 chromeHidden.appWindowData = { | 65 chromeHidden.appWindowData = { |
| 64 id: params.id || '' | 66 id: params.id || '' |
| 65 }; | 67 }; |
| 66 chromeHidden.currentAppWindow = new AppWindow; | 68 chromeHidden.currentAppWindow = new AppWindow; |
| 67 }); | 69 }); |
| 68 }); | 70 }); |
| OLD | NEW |