Home | History | Annotate | Download | only in graphics_test_extension
      1 // Copyright (c) 2013 The Chromium OS 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 
      5 function createWindow(url, l, t, w, h, fullscreen) {
      6   chrome.windows.create(
      7       {left: l, top: t, width: w, height: h, focused: true, url: url},
      8       function(win) {
      9         if (fullscreen) {
     10           chrome.windows.update(win.id, {state: "fullscreen"});
     11         }
     12       });
     13 }
     14 
     15 function onMessageHandler(message, sender, sendResponse) {
     16   console.log("Background got message: " + message.method);
     17   if (!message.method)
     18     return;
     19   if (message.method == "createWindow") {
     20     console.log("Create window.");
     21     createWindow(message.url, message.left, message.top,
     22         message.width, message.height, message.fullscreen);
     23   } else if (message.method == "setFullscreen") {
     24     console.log("Set window " + sender.tab.windowId + " to fullscreen.");
     25     chrome.windows.update(sender.tab.windowId, {state: "fullscreen"});
     26   } else if (message.method == "updateWindow") {
     27     console.log("Update window " + sender.tab.windowId + ": " +
     28                 message.updateInfo);
     29     chrome.windows.update(sender.tab.windowId, message.updateInfo);
     30   } else if (message.method == "moveAndSetFullscreen") {
     31     console.log("Move window " + sender.tab.windowId +
     32                 " to external display and set it to fullscreen.");
     33     chrome.system.display.getInfo(function(info) {
     34         var internal_width = null;
     35         var i = 0;
     36         for (i = 0; i < info.length; i++) {
     37           if (info[i].isInternal) {
     38             internal_width = info[i].bounds.width;
     39           }
     40         }
     41 
     42         if (internal_width == null) {
     43           console.log('Cannot get internal display width.');
     44           return;
     45         }
     46         chrome.windows.update(sender.tab.windowId, {
     47             left: internal_width + 1,
     48             top: 0,
     49             width: 300,
     50             height: 300});
     51         chrome.windows.update(sender.tab.windowId, {state: "fullscreen"});
     52     });
     53   }
     54 }
     55 
     56 chrome.runtime.onMessage.addListener(onMessageHandler);
     57