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

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

Issue 11369039: Add setBounds method and browsertest for get/set bounds to app window API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased, responded to review feedback Created 8 years, 1 month 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 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 var OnContextReady = appWindowNatives.OnContextReady; 12 var OnContextReady = appWindowNatives.OnContextReady;
13 13
14 chromeHidden.registerCustomHook('app.window', function(bindingsAPI) { 14 chromeHidden.registerCustomHook('app.window', function(bindingsAPI) {
15 var apiFunctions = bindingsAPI.apiFunctions; 15 var apiFunctions = bindingsAPI.apiFunctions;
16 apiFunctions.setCustomCallback('create', 16 apiFunctions.setCustomCallback('create',
17 function(name, request, windowParams) { 17 function(name, request, windowParams) {
18 var view = null; 18 var view = null;
19 if (windowParams.viewId) 19 if (windowParams.viewId)
20 view = GetView(windowParams.viewId, windowParams.injectTitlebar); 20 view = GetView(windowParams.viewId, windowParams.injectTitlebar);
21 21
22 if (!view) { 22 if (!view) {
23 // No route to created window. If given a callback, trigger it with an 23 // No route to created window. If given a callback, trigger it with an
24 // undefined object. 24 // undefined object.
25 if (request.callback) { 25 if (request.callback) {
26 request.callback() 26 request.callback();
27 delete request.callback; 27 delete request.callback;
28 } 28 }
29 return; 29 return;
30 } 30 }
31 31
32 // Initialize appWindowData in the newly created JS context 32 // Initialize appWindowData in the newly created JS context
33 view.chrome.app.window.initializeAppWindow(windowParams); 33 view.chrome.app.window.initializeAppWindow(windowParams);
34 34
35 var callback = request.callback; 35 var callback = request.callback;
36 if (callback) { 36 if (callback) {
(...skipping 25 matching lines...) Expand all
62 return chromeHidden.currentAppWindow; 62 return chromeHidden.currentAppWindow;
63 }); 63 });
64 64
65 chromeHidden.OnAppWindowClosed = function() { 65 chromeHidden.OnAppWindowClosed = function() {
66 if (!chromeHidden.currentAppWindow) 66 if (!chromeHidden.currentAppWindow)
67 return; 67 return;
68 chromeHidden.currentAppWindow.onClosed.dispatch(); 68 chromeHidden.currentAppWindow.onClosed.dispatch();
69 }; 69 };
70 70
71 // This is an internal function, but needs to be bound with setHandleRequest 71 // This is an internal function, but needs to be bound with setHandleRequest
72 // because it is called from a different JS context 72 // because it is called from a different JS context.
73 apiFunctions.setHandleRequest('initializeAppWindow', function(params) { 73 apiFunctions.setHandleRequest('initializeAppWindow', function(params) {
74 var AppWindow = function() {}; 74 var AppWindow = function() {};
75 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) { 75 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) {
76 AppWindow.prototype[fn] = 76 AppWindow.prototype[fn] =
77 chromeHidden.internalAPIs.app.currentWindowInternal[fn]; 77 chromeHidden.internalAPIs.app.currentWindowInternal[fn];
78 }); 78 });
79 AppWindow.prototype.moveTo = window.moveTo.bind(window); 79 AppWindow.prototype.moveTo = window.moveTo.bind(window);
80 AppWindow.prototype.resizeTo = window.resizeTo.bind(window); 80 AppWindow.prototype.resizeTo = window.resizeTo.bind(window);
81 AppWindow.prototype.contentWindow = window; 81 AppWindow.prototype.contentWindow = window;
82 AppWindow.prototype.onClosed = new chrome.Event; 82 AppWindow.prototype.onClosed = new chrome.Event;
83 AppWindow.prototype.close = function() { 83 AppWindow.prototype.close = function() {
84 this.contentWindow.close(); 84 this.contentWindow.close();
85 }; 85 };
86 AppWindow.prototype.getBounds = function() { 86 AppWindow.prototype.getBounds = function() {
87 var bounds = chromeHidden.appWindowData.bounds; 87 var bounds = chromeHidden.appWindowData.bounds;
88 return { left: bounds.left, top: bounds.top, 88 return { left: bounds.left, top: bounds.top,
89 width: bounds.width, height: bounds.height }; 89 width: bounds.width, height: bounds.height };
90 }; 90 };
91 91
92 Object.defineProperty(AppWindow.prototype, 'id', {get: function() { 92 Object.defineProperty(AppWindow.prototype, 'id', {get: function() {
93 return chromeHidden.appWindowData.id; 93 return chromeHidden.appWindowData.id;
94 }}); 94 }});
95 95
96 chromeHidden.appWindowData = { 96 chromeHidden.appWindowData = {
97 id: params.id || '', 97 id: params.id || '',
98 bounds: { left: 0, top: 0, width: 0, height: 0 } 98 bounds: { left: params.bounds.left, top: params.bounds.top,
99 width: params.bounds.width, height: params.bounds.height }
99 }; 100 };
100 chromeHidden.currentAppWindow = new AppWindow; 101 chromeHidden.currentAppWindow = new AppWindow;
101 }); 102 });
102 }); 103 });
103 104
104 chromeHidden.updateAppWindowBounds = function(info) { 105 chromeHidden.updateAppWindowBounds = function(info) {
105 var data = chromeHidden.appWindowData; 106 var data = chromeHidden.appWindowData;
106 if (!data) 107 if (!data)
107 return; 108 return;
108 data.bounds.left = info.left; 109 data.bounds.left = info.left;
109 data.bounds.top = info.top; 110 data.bounds.top = info.top;
110 data.bounds.width = info.width; 111 data.bounds.width = info.width;
111 data.bounds.height = info.height; 112 data.bounds.height = info.height;
112 }; 113 };
114
115 chromeHidden.registerCustomHook('app.currentWindowInternal',
116 function(bindingsAPI) {
117 var apiFunctions = bindingsAPI.apiFunctions;
118 apiFunctions.setUpdateArgumentsPostValidate('setBounds', function(bounds) {
119 // Cache the update locally so that getBounds can immediately return the
120 // updated value.
jeremya 2012/11/13 06:16:30 What happens if the bounds you set aren't the boun
asargent_no_longer_on_chrome 2012/11/14 05:22:12 We won't know synchronously that this has happened
121 var cachedBounds = chromeHidden.appWindowData.bounds;
122 var names = ['left', 'top', 'width', 'height'];
123 for (var i = 0; i < names.length; i++) {
124 if (typeof(bounds[names[i]]) != 'undefined')
125 cachedBounds[names[i]] = bounds[names[i]];
126 }
127 return arguments;
128 });
129 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698