background.js revision 8bcbed890bc3ce4d7a057a8f32cab53fa534672e
1// Copyright (c) 2013 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.
4
5function makeURL(toolchain, config) {
6  return 'index.html?tc=' + toolchain + '&config=' + config;
7}
8
9function createWindow(url) {
10  console.log('loading ' + url);
11  chrome.app.window.create(url, {
12    width: 1024,
13    height: 800,
14    frame: 'none'
15  });
16}
17
18function onLaunched(launchData) {
19  // Send and XHR to get the URL to load from a configuration file.
20  // Normally you won't need to do this; just call:
21  //
22  // chrome.app.window.create('<your url>', {...});
23  //
24  // In the SDK we want to be able to load different URLs (for different
25  // toolchain/config combinations) from the commandline, so we to read
26  // this information from the file "run_package_config".
27  var xhr = new XMLHttpRequest();
28  xhr.open('GET', 'run_package_config', true);
29  xhr.onload = function() {
30    var toolchain_config = this.responseText.split(' ');
31    createWindow(makeURL.apply(null, toolchain_config));
32  };
33  xhr.onerror = function() {
34    // Can't find the config file, just load the default.
35    createWindow('index.html');
36  };
37  xhr.send();
38}
39
40chrome.app.runtime.onLaunched.addListener(onLaunched);
41