1 // Copyright (c) 2012 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.
8 chrome.tabs.onSelectionChanged.addListener(function(tabId) {
10 chrome.pageAction.show(lastTabId);
13 chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
14 lastTabId = tabs[0].id;
15 chrome.pageAction.show(lastTabId);
18 // Called when the user clicks on the page action.
19 chrome.pageAction.onClicked.addListener(function(tab) {
20 var clicks = tab_clicks[tab.id] || 0;
21 chrome.pageAction.setIcon({path: "icon" + (clicks + 1) + ".png",
24 chrome.pageAction.show(tab.id);
26 chrome.pageAction.hide(tab.id);
27 setTimeout(function() { chrome.pageAction.show(tab.id); }, 200);
29 chrome.pageAction.setTitle({title: "click:" + clicks, tabId: tab.id});
31 // We only have 2 icons, but cycle through 3 icons to test the
32 // out-of-bounds index bug.
36 tab_clicks[tab.id] = clicks;
40 window.setInterval(function() {
41 var clicks = tab_clicks[lastTabId] || 0;
43 // Don't animate while in "click" mode.
44 if (clicks > 0) return;
46 // Don't do anything if we don't have a tab yet.
47 if (lastTabId == 0) return;
50 chrome.pageAction.setIcon({imageData: draw(i*2, i*4), tabId: lastTabId});
53 function draw(starty, startx) {
54 var canvas = document.getElementById('canvas');
55 var context = canvas.getContext('2d');
56 context.clearRect(0, 0, canvas.width, canvas.height);
57 context.fillStyle = "rgba(0,200,0,255)";
58 context.fillRect(startx % 19, starty % 19, 8, 8);
59 context.fillStyle = "rgba(0,0,200,255)";
60 context.fillRect((startx + 5) % 19, (starty + 5) % 19, 8, 8);
61 context.fillStyle = "rgba(200,0,0,255)";
62 context.fillRect((startx + 10) % 19, (starty + 10) % 19, 8, 8);
63 return context.getImageData(0, 0, 19, 19);