Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: chrome/test/data/extensions/samples/test_page_action/background.html

Issue 332021: Move page actions over to ExtensionAction2 (Closed)
Patch Set: Review feedback Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <html> 1 <html>
2 <head> 2 <head>
3 <script> 3 <script>
4 var lastTabId = 0; 4 var lastTabId = 0;
5 var visible = false;
5 chrome.tabs.onUpdated.addListener(function(tabId, p) { 6 chrome.tabs.onUpdated.addListener(function(tabId, p) {
6 lastTabId = tabId; 7 lastTabId = tabId;
8 chrome.pageAction.show(tabId);
7 }); 9 });
8 10
9 // Called when the user clicks on the browser action. 11 // Called when the user clicks on the page action.
10 var clicks = 0; 12 var clicks = 0;
11 var text = ""; 13 var text = "";
12 chrome.pageAction.onClicked.addListener(function(_, info) { 14 chrome.pageAction.onClicked.addListener(function(_, info) {
13 chrome.pageAction.setIcon({iconIndex: clicks, tabId: info.tabId}); 15 chrome.pageAction.setIcon({path: "icon" + (clicks + 1) + ".png",
16 tabId: info.tabId});
14 if (clicks % 2) { 17 if (clicks % 2) {
15 chrome.pageAction.show(info.tabId); 18 chrome.pageAction.show(info.tabId);
16 } else { 19 } else {
17 chrome.pageAction.hide(info.tabId); 20 chrome.pageAction.hide(info.tabId);
18 setTimeout(function() { chrome.pageAction.show(info.tabId); }, 200); 21 setTimeout(function() { chrome.pageAction.show(info.tabId); }, 200);
19 } 22 }
20 chrome.pageAction.setTitle({title: "click:" + clicks, tabId: info.tabId}); 23 chrome.pageAction.setTitle({title: "click:" + clicks, tabId: info.tabId});
21 chrome.pageAction.setBadgeTextColor({
22 tabId: info.tabId,
23 color: [255, 255, clicks * 50, 255]
24 });
25 chrome.pageAction.setBadgeBackgroundColor({
26 tabId: info.tabId,
27 color: [255, clicks * 50, 0, 255]
28 });
29 text += clicks.toString(); 24 text += clicks.toString();
30 chrome.pageAction.setBadgeText({
31 tabId: info.tabId,
32 text: text
33 });
34 25
35 // We only have 2 icons, but cycle through 3 icons to test the 26 // We only have 2 icons, but cycle through 3 icons to test the
36 // out-of-bounds index bug. 27 // out-of-bounds index bug.
37 clicks++; 28 clicks++;
38 if (clicks > 3) 29 if (clicks > 3)
39 clicks = 0; 30 clicks = 0;
40 }); 31 });
41 var i = 0; 32 var i = 0;
42 33
43 window.setInterval(function() { 34 window.setInterval(function() {
44 // Don't animate while in "click" mode. 35 // Don't animate while in "click" mode.
45 if (clicks > 0) return; 36 if (clicks > 0) return;
37
38 // Don't do anything if we don't have a tab yet.
39 if (lastTabId == 0) return;
40
46 i++; 41 i++;
47 chrome.pageAction.setIcon({imageData: draw(i*2, i*4), tabId: lastTabId}); 42 chrome.pageAction.setIcon({imageData: draw(i*2, i*4), tabId: lastTabId});
48 }, 50); 43 }, 50);
49 44
50 function draw(starty, startx) { 45 function draw(starty, startx) {
51 var canvas = document.getElementById('canvas'); 46 var canvas = document.getElementById('canvas');
52 var context = canvas.getContext('2d'); 47 var context = canvas.getContext('2d');
53 context.clearRect(0, 0, canvas.width, canvas.height); 48 context.clearRect(0, 0, canvas.width, canvas.height);
54 context.fillStyle = "rgba(0,200,0,255)"; 49 context.fillStyle = "rgba(0,200,0,255)";
55 context.fillRect(startx % 19, starty % 19, 8, 8); 50 context.fillRect(startx % 19, starty % 19, 8, 8);
56 context.fillStyle = "rgba(0,0,200,255)"; 51 context.fillStyle = "rgba(0,0,200,255)";
57 context.fillRect((startx + 5) % 19, (starty + 5) % 19, 8, 8); 52 context.fillRect((startx + 5) % 19, (starty + 5) % 19, 8, 8);
58 context.fillStyle = "rgba(200,0,0,255)"; 53 context.fillStyle = "rgba(200,0,0,255)";
59 context.fillRect((startx + 10) % 19, (starty + 10) % 19, 8, 8); 54 context.fillRect((startx + 10) % 19, (starty + 10) % 19, 8, 8);
60 return context.getImageData(0, 0, 19, 19); 55 return context.getImageData(0, 0, 19, 19);
61 } 56 }
62 </script> 57 </script>
63 </head> 58 </head>
64 <body> 59 <body>
65 <canvas id="canvas" width="19" height="19"></canvas> 60 <canvas id="canvas" width="19" height="19"></canvas>
66 </body> 61 </body>
67 </html> 62 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698