Home | History | Annotate | Download | only in merge_windows
      1 // Copyright (c) 2011 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 
      5 var targetWindow = null;
      6 var tabCount = 0;
      7 
      8 function start(tab) {
      9   chrome.windows.getCurrent(getWindows);
     10 }
     11 
     12 function getWindows(win) {
     13   targetWindow = win;
     14   chrome.tabs.getAllInWindow(targetWindow.id, getTabs);
     15 }
     16 
     17 function getTabs(tabs) {
     18   tabCount = tabs.length;
     19   // We require all the tab information to be populated.
     20   chrome.windows.getAll({"populate" : true}, moveTabs);
     21 }
     22 
     23 function moveTabs(windows) {
     24   var numWindows = windows.length;
     25   var tabPosition = tabCount;
     26 
     27   for (var i = 0; i < numWindows; i++) {
     28     var win = windows[i];
     29 
     30     if (targetWindow.id != win.id) {
     31       var numTabs = win.tabs.length;
     32 
     33       for (var j = 0; j < numTabs; j++) {
     34         var tab = win.tabs[j];
     35         // Move the tab into the window that triggered the browser action.
     36         chrome.tabs.move(tab.id,
     37             {"windowId": targetWindow.id, "index": tabPosition});
     38         tabPosition++;
     39       }
     40     }
     41   }
     42 }
     43 
     44 // Set up a click handler so that we can merge all the windows.
     45 chrome.browserAction.onClicked.addListener(start);
     46