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

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: first round of comments 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..62fee464fa94691f816011803fda55b9d7f6d70d 100644
--- a/chrome/renderer/resources/extensions/app_window_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/app_window_custom_bindings.js
@@ -11,30 +11,72 @@ 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
+ 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,
+ id: params.id ? params.id : ''
+ };
+ // Call makeAppWindow in the newly created JS context
+ var appWindow = view.chrome.app.window.makeAppWindow(state);
+
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;
apiFunctions.setHandleRequest('current', function() {
- return new AppWindow;
- })
+ if (!chromeHidden.appWindow.currentWindow)
+ console.error('chrome.app.window.current() is null -- possible reload, ' +
+ 'or not created with chrome.app.window.create()');
+ return chromeHidden.appWindow.currentWindow;
+ // 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..
benwells 2012/09/18 03:47:24 Given crbug.com/150033 I think this comment can be
tapted 2012/09/18 04:17:24 Done.
+ });
jeremya 2012/09/17 17:46:58 Why not just cache the appWindow as a closure vari
tapted 2012/09/18 04:17:24 Done (detached from chromeHidden).
+
+ // 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) {
+ chromeHidden.appWindow.windowCache = {
+ viewId: params.viewId,
+ id: params.id ? params.id : ''
+ };
+ chromeHidden.appWindow.currentWindow = new AppWindow;
+ // 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
+ // in to the custom callback, and ignore developer-reloads)
+ return chromeHidden.appWindow.currentWindow;
+ });
});

Powered by Google App Engine
This is Rietveld 408576698