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

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

Issue 10910304: Cache the object given to the chrome.app.window.create callback (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: access to the id property via cache, leave out GetRoutingID for now Created 8 years, 3 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
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 12
13 chromeHidden.registerCustomHook('app.window', function(bindingsAPI) { 13 chromeHidden.registerCustomHook('app.window', function(bindingsAPI) {
14 chromeHidden.appWindow = {
15 windowCache: {},
16 currentWindow: null
17 };
18
14 var apiFunctions = bindingsAPI.apiFunctions; 19 var apiFunctions = bindingsAPI.apiFunctions;
15 apiFunctions.setCustomCallback('create', function(name, request, viewId) { 20 apiFunctions.setCustomCallback('create', function(name, request, viewId) {
16 var view = null; 21 if (!viewId) {
17 if (viewId) { 22 // create failed? If given a callback, trigger it with an undefined object
benwells 2012/09/17 08:33:31 Nit: Start comment with uppercase.
tapted 2012/09/17 09:22:13 Done.
18 var shouldShowFrame = !request.args[1] || request.args[1].frame != 'none'; 23 if (request.callback) {
19 view = GetView(viewId, !!shouldShowFrame); 24 request.callback()
25 delete request.callback;
26 }
27 return;
20 } 28 }
29
30 var params = request.args[1];
31 var shouldShowFrame = !params || params.frame != 'none';
32 var view = GetView(viewId, !!shouldShowFrame);
33 var state = {
34 viewId: viewId,
benwells 2012/09/17 08:33:31 Does the viewId need to be in the state?
tapted 2012/09/17 09:22:13 a case for it might be to index a collection of Ap
benwells 2012/09/18 03:47:24 Ah, ok. Let's take it out now, and add it back in
tapted 2012/09/18 04:17:24 Done.
35 id: params.id ? params.id : ''
36 };
37 var appWindow = view.chrome.app.window.makeAppWindow(state);
benwells 2012/09/17 08:33:31 Nit: it would be nice to add a comment that this r
tapted 2012/09/17 09:22:13 Done.
38
21 if (request.callback) { 39 if (request.callback) {
22 request.callback(view.chrome.app.window.current()); 40 request.callback(appWindow);
23 delete request.callback; 41 delete request.callback;
24 } 42 }
25 }) 43 });
26 var AppWindow = function() {}; 44 var AppWindow = function() {};
27 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) { 45 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) {
28 AppWindow.prototype[fn] = 46 AppWindow.prototype[fn] =
29 chromeHidden.internalAPIs.app.currentWindowInternal[fn]; 47 chromeHidden.internalAPIs.app.currentWindowInternal[fn];
30 }); 48 });
31 AppWindow.prototype.moveTo = window.moveTo.bind(window); 49 AppWindow.prototype.moveTo = window.moveTo.bind(window);
50 Object.defineProperty(AppWindow.prototype, 'id', {get: function() {
51 return chromeHidden.appWindow.windowCache.id;
52 }});
32 AppWindow.prototype.resizeTo = window.resizeTo.bind(window); 53 AppWindow.prototype.resizeTo = window.resizeTo.bind(window);
33 AppWindow.prototype.contentWindow = window; 54 AppWindow.prototype.contentWindow = window;
34 // So as not to break apps that use .dom. http://crbug.com/147668 55 // So as not to break apps that use .dom. http://crbug.com/147668
35 // TODO(jeremya): remove this once M23 has branched. 56 // TODO(jeremya): remove this once M23 has branched.
36 AppWindow.prototype.dom = window; 57 AppWindow.prototype.dom = window;
benwells 2012/09/17 08:33:31 Unless there is a reason to keep it, I'd prefer th
tapted 2012/09/17 09:22:13 I am for this - the cache means that the prototype
tapted 2012/09/18 07:47:32 Turns out trying to ditch the prototype will break
37 apiFunctions.setHandleRequest('current', function() { 58 apiFunctions.setHandleRequest('current', function() {
38 return new AppWindow; 59 return chromeHidden.appWindow.currentWindow;
benwells 2012/09/17 08:33:31 Would be nice to log an error here if currentWindo
tapted 2012/09/17 09:22:13 Done.
39 }) 60 // That should "always" work in production. However, a right-click reload
61 // in developer mode will clear the cache, so we need to bootstrap it again.
62 // First step is to determine whether we are actually an appWindow via IPC..
63 });
64
65 // TODO(tapted) this should be "internal only" but needs to be called on a
66 // different JS context -- is there a neater way?
67 apiFunctions.setHandleRequest('makeAppWindow', function(params) {
68 var newWindow = new AppWindow;
benwells 2012/09/17 08:33:31 you can get rid of two lines here by removing the
tapted 2012/09/17 09:22:13 Done.
69 var cache = {
70 viewId: params.viewId,
71 id: params.id ? params.id : ''
72 };
73 chromeHidden.appWindow.windowCache = cache;
74 chromeHidden.appWindow.currentWindow = newWindow;
75 // TODO(tapted) we need to fire-off a mechanism here to bootstrap the cache
76 // with values from the browser thread not known by create() (or pass them
benwells 2012/09/17 08:33:31 This comment is now invalid I think?
tapted 2012/09/17 09:22:13 There might be some properties we want to store in
benwells 2012/09/18 03:47:24 TODOs have a habit of sticking around, so I like t
tapted 2012/09/18 04:17:24 I can see if I can convince browser::create to pas
tapted 2012/09/18 05:07:46 Done for `id` without touching the IDL (but with t
77 // in to the custom callback, and ignore developer-reloads)
78 return newWindow;
79 });
40 }); 80 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698