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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/resources/extensions/app_window_custom_bindings.js
diff --git a/chrome/renderer/resources/extensions/app_window_custom_bindings.js b/chrome/renderer/resources/extensions/app_window_custom_bindings.js
index 04283fec5a0ed4059a0a36f007f8decec9d2bf11..3fea8af558ed38288875d10af225cbde0b5cb81e 100644
--- a/chrome/renderer/resources/extensions/app_window_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/app_window_custom_bindings.js
@@ -11,30 +11,70 @@ var forEach = require('utils').forEach;
var GetView = appWindowNatives.GetView;
chromeHidden.registerCustomHook('app.window', function(bindingsAPI) {
+ chromeHidden.appWindow = {
+ windowCache: {},
+ currentWindow: null
+ };
+
var apiFunctions = bindingsAPI.apiFunctions;
apiFunctions.setCustomCallback('create', function(name, request, viewId) {
- var view = null;
- if (viewId) {
- var shouldShowFrame = !request.args[1] || request.args[1].frame != 'none';
- view = GetView(viewId, !!shouldShowFrame);
+ if (!viewId) {
+ // 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.
+ if (request.callback) {
+ request.callback()
+ delete request.callback;
+ }
+ return;
}
+
+ var params = request.args[1];
+ var shouldShowFrame = !params || params.frame != 'none';
+ var view = GetView(viewId, !!shouldShowFrame);
+ var state = {
+ 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.
+ id: params.id ? params.id : ''
+ };
+ 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.
+
if (request.callback) {
- request.callback(view.chrome.app.window.current());
+ request.callback(appWindow);
delete request.callback;
}
- })
+ });
var AppWindow = function() {};
forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) {
AppWindow.prototype[fn] =
chromeHidden.internalAPIs.app.currentWindowInternal[fn];
});
AppWindow.prototype.moveTo = window.moveTo.bind(window);
+ Object.defineProperty(AppWindow.prototype, 'id', {get: function() {
+ return chromeHidden.appWindow.windowCache.id;
+ }});
AppWindow.prototype.resizeTo = window.resizeTo.bind(window);
AppWindow.prototype.contentWindow = window;
// So as not to break apps that use .dom. http://crbug.com/147668
// TODO(jeremya): remove this once M23 has branched.
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
apiFunctions.setHandleRequest('current', function() {
- return new AppWindow;
- })
+ 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.
+ // That should "always" work in production. However, a right-click reload
+ // in developer mode will clear the cache, so we need to bootstrap it again.
+ // First step is to determine whether we are actually an appWindow via IPC..
+ });
+
+ // TODO(tapted) this should be "internal only" but needs to be called on a
+ // different JS context -- is there a neater way?
+ apiFunctions.setHandleRequest('makeAppWindow', function(params) {
+ 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.
+ var cache = {
+ viewId: params.viewId,
+ id: params.id ? params.id : ''
+ };
+ chromeHidden.appWindow.windowCache = cache;
+ chromeHidden.appWindow.currentWindow = newWindow;
+ // TODO(tapted) we need to fire-off a mechanism here to bootstrap the cache
+ // 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
+ // in to the custom callback, and ignore developer-reloads)
+ return newWindow;
+ });
});

Powered by Google App Engine
This is Rietveld 408576698