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

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: 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 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
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,
35 id: params.id ? params.id : ''
36 };
37 // Call makeAppWindow in the newly created JS context
38 var appWindow = view.chrome.app.window.makeAppWindow(state);
39
21 if (request.callback) { 40 if (request.callback) {
22 request.callback(view.chrome.app.window.current()); 41 request.callback(appWindow);
23 delete request.callback; 42 delete request.callback;
24 } 43 }
25 }) 44 });
26 var AppWindow = function() {}; 45 var AppWindow = function() {};
27 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) { 46 forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) {
28 AppWindow.prototype[fn] = 47 AppWindow.prototype[fn] =
29 chromeHidden.internalAPIs.app.currentWindowInternal[fn]; 48 chromeHidden.internalAPIs.app.currentWindowInternal[fn];
30 }); 49 });
31 AppWindow.prototype.moveTo = window.moveTo.bind(window); 50 AppWindow.prototype.moveTo = window.moveTo.bind(window);
51 Object.defineProperty(AppWindow.prototype, 'id', {get: function() {
52 return chromeHidden.appWindow.windowCache.id;
53 }});
32 AppWindow.prototype.resizeTo = window.resizeTo.bind(window); 54 AppWindow.prototype.resizeTo = window.resizeTo.bind(window);
33 AppWindow.prototype.contentWindow = window; 55 AppWindow.prototype.contentWindow = window;
34 // So as not to break apps that use .dom. http://crbug.com/147668 56 // So as not to break apps that use .dom. http://crbug.com/147668
35 // TODO(jeremya): remove this once M23 has branched. 57 // TODO(jeremya): remove this once M23 has branched.
36 AppWindow.prototype.dom = window; 58 AppWindow.prototype.dom = window;
37 apiFunctions.setHandleRequest('current', function() { 59 apiFunctions.setHandleRequest('current', function() {
38 return new AppWindow; 60 if (!chromeHidden.appWindow.currentWindow)
39 }) 61 console.error('chrome.app.window.current() is null -- possible reload, ' +
62 'or not created with chrome.app.window.create()');
63 return chromeHidden.appWindow.currentWindow;
64 // That should "always" work in production. However, a right-click reload
65 // in developer mode will clear the cache, so we need to bootstrap it again.
66 // 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.
67 });
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).
68
69 // TODO(tapted) this should be "internal only" but needs to be called on a
70 // different JS context -- is there a neater way?
71 apiFunctions.setHandleRequest('makeAppWindow', function(params) {
72 chromeHidden.appWindow.windowCache = {
73 viewId: params.viewId,
74 id: params.id ? params.id : ''
75 };
76 chromeHidden.appWindow.currentWindow = new AppWindow;
77 // TODO(tapted) we need to fire-off a mechanism here to bootstrap the cache
78 // with values from the browser thread not known by create() (or pass them
79 // in to the custom callback, and ignore developer-reloads)
80 return chromeHidden.appWindow.currentWindow;
81 });
40 }); 82 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698