1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 * Singleton object representing the Memory Inspector Chrome App.
11 var MemoryInspectorApp = function() {
12 this.window_ = undefined;
15 /** Main window parameters. */
16 MemoryInspectorApp.WINDOW_URL = 'main_window.html';
17 MemoryInspectorApp.WINDOW_ID = 'main';
18 MemoryInspectorApp.WINDOW_WIDTH = Math.min(screen.width, 1200);
19 MemoryInspectorApp.WINDOW_HEIGHT = Math.min(screen.height, 800);
22 * Launch the Memory Inspector. If it is already running, focus the main window.
24 MemoryInspectorApp.prototype.launch = function() {
25 if (this.window_ === undefined) {
33 * Start the Memory Inspector by creating the main window.
36 MemoryInspectorApp.prototype.start_ = function() {
38 'id': MemoryInspectorApp.WINDOW_ID,
40 'width': MemoryInspectorApp.WINDOW_WIDTH,
41 'height': MemoryInspectorApp.WINDOW_HEIGHT
43 'hidden': true // The main window shows itself after it retrieves settings.
45 chrome.app.window.create(MemoryInspectorApp.WINDOW_URL, options,
46 this.onWindowCreated_.bind(this));
50 * Listener called when the main window is created.
52 * @param {AppWindow} createdWindow The created window.
54 MemoryInspectorApp.prototype.onWindowCreated_ = function(createdWindow) {
55 this.window_ = createdWindow;
56 this.window_.onClosed.addListener(this.onWindowClosed_.bind(this));
60 * Listener called when the main window is closed.
63 MemoryInspectorApp.prototype.onWindowClosed_ = function() {
64 this.window_ = undefined;
68 * Focus the main window.
71 MemoryInspectorApp.prototype.focus_ = function() {
72 if (this.window_ !== undefined) {
77 window.addEventListener('load', function() {
78 // Create the singleton MemoryInspectorApp instance and hook it up with the
80 var app = new MemoryInspectorApp();
81 chrome.app.runtime.onLaunched.addListener(app.launch.bind(app));
83 // Make the instance global for debugging purposes.