12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/**
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * Register a callback function with the commands api, which will be called when
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * one of our registered commands is detected.
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) */
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)chrome.commands.onCommand.addListener(function(command) {
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Call 'update' with an empty properties object to get access to the current
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // tab (given to us in the callback function).
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  chrome.tabs.update({}, function(tab) {
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (command == 'toggle-pin-tab')
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      chrome.tabs.update({pinned: !tab.pinned});
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    else if (command == 'duplicate-tab')
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      chrome.tabs.duplicate(tab.id);
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  });
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)});
19