Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(548)

Side by Side Diff: chrome/renderer/resources/extensions/app_window_custom_bindings.js

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: apitest.js Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 binding for the app_window API.
6
7 var binding = require('binding').Binding.create('app.window');
6 8
7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 9 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
10 var chrome = requireNative('chrome').GetChrome();
8 var sendRequest = require('sendRequest').sendRequest; 11 var sendRequest = require('sendRequest').sendRequest;
9 var appWindowNatives = requireNative('app_window'); 12 var appWindowNatives = requireNative('app_window');
10 var forEach = require('utils').forEach; 13 var forEach = require('utils').forEach;
11 var GetView = appWindowNatives.GetView; 14 var GetView = appWindowNatives.GetView;
12 var OnContextReady = appWindowNatives.OnContextReady; 15 var OnContextReady = appWindowNatives.OnContextReady;
16 var currentWindowInternal = require('binding').Binding.create(
17 'app.currentWindowInternal').generate();
13 18
14 chromeHidden.registerCustomHook('app.window', function(bindingsAPI) { 19 binding.registerCustomHook(function(bindingsAPI) {
15 var apiFunctions = bindingsAPI.apiFunctions; 20 var apiFunctions = bindingsAPI.apiFunctions;
21
16 apiFunctions.setCustomCallback('create', 22 apiFunctions.setCustomCallback('create',
17 function(name, request, windowParams) { 23 function(name, request, windowParams) {
18 var view = null; 24 var view = null;
19 if (windowParams.viewId) 25 if (windowParams.viewId)
20 view = GetView(windowParams.viewId, windowParams.injectTitlebar); 26 view = GetView(windowParams.viewId, windowParams.injectTitlebar);
21 27
22 if (!view) { 28 if (!view) {
23 // No route to created window. If given a callback, trigger it with an 29 // No route to created window. If given a callback, trigger it with an
24 // undefined object. 30 // undefined object.
25 if (request.callback) { 31 if (request.callback) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 chromeHidden.OnAppWindowClosed = function() { 81 chromeHidden.OnAppWindowClosed = function() {
76 if (!chromeHidden.currentAppWindow) 82 if (!chromeHidden.currentAppWindow)
77 return; 83 return;
78 chromeHidden.currentAppWindow.onClosed.dispatch(); 84 chromeHidden.currentAppWindow.onClosed.dispatch();
79 }; 85 };
80 86
81 // This is an internal function, but needs to be bound with setHandleRequest 87 // This is an internal function, but needs to be bound with setHandleRequest
82 // because it is called from a different JS context. 88 // because it is called from a different JS context.
83 apiFunctions.setHandleRequest('initializeAppWindow', function(params) { 89 apiFunctions.setHandleRequest('initializeAppWindow', function(params) {
84 var AppWindow = function() {}; 90 var AppWindow = function() {};
85 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) { 91 forEach(currentWindowInternal, function(fn) {
86 AppWindow.prototype[fn] = 92 AppWindow.prototype[fn] =
87 chromeHidden.internalAPIs.app.currentWindowInternal[fn]; 93 currentWindowInternal[fn];
88 }); 94 });
89 AppWindow.prototype.moveTo = window.moveTo.bind(window); 95 AppWindow.prototype.moveTo = window.moveTo.bind(window);
90 AppWindow.prototype.resizeTo = window.resizeTo.bind(window); 96 AppWindow.prototype.resizeTo = window.resizeTo.bind(window);
91 AppWindow.prototype.contentWindow = window; 97 AppWindow.prototype.contentWindow = window;
92 AppWindow.prototype.onClosed = new chrome.Event; 98 AppWindow.prototype.onClosed = new chrome.Event;
93 AppWindow.prototype.close = function() { 99 AppWindow.prototype.close = function() {
94 this.contentWindow.close(); 100 this.contentWindow.close();
95 }; 101 };
96 AppWindow.prototype.getBounds = function() { 102 AppWindow.prototype.getBounds = function() {
97 var bounds = chromeHidden.appWindowData.bounds; 103 var bounds = chromeHidden.appWindowData.bounds;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 147
142 if (!oldData.minimized && update.minimized) 148 if (!oldData.minimized && update.minimized)
143 currentWindow["onMinimized"].dispatch(); 149 currentWindow["onMinimized"].dispatch();
144 if (!oldData.maximized && update.maximized) 150 if (!oldData.maximized && update.maximized)
145 currentWindow["onMaximized"].dispatch(); 151 currentWindow["onMaximized"].dispatch();
146 152
147 if ((oldData.minimized && !update.minimized) || 153 if ((oldData.minimized && !update.minimized) ||
148 (oldData.maximized && !update.maximized)) 154 (oldData.maximized && !update.maximized))
149 currentWindow["onRestored"].dispatch(); 155 currentWindow["onRestored"].dispatch();
150 }; 156 };
157
158 exports.binding = binding.generate();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698