background.js 1.2 KB

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