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

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

Issue 269079: Implement new page action API. (Closed)
Patch Set: compile fixes Created 11 years, 2 months 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
(Empty)
1 <html>
2 <head>
3 <script>
4 var lastTabId = 0;
5 chrome.tabs.onUpdated.addListener(function(tabId, p) {
6 lastTabId = tabId;
7 });
8
9 // Called when the user clicks on the browser action.
10 var clicks = 0;
11 chrome.pageAction.onClicked.addListener(function(_, info) {
12 chrome.pageAction.setIcon({iconIndex: clicks, tabId: info.tabId});
13 if (clicks % 2) {
14 chrome.pageAction.show(info.tabId);
15 } else {
16 chrome.pageAction.hide(info.tabId);
17 setTimeout(function() { chrome.pageAction.show(info.tabId); }, 1000);
18 }
19 chrome.pageAction.setTitle({title: "click:" + clicks, tabId: info.tabId});
20 chrome.pageAction.setBadgeTextColor({
21 tabId: info.tabId,
22 color: [0, 255, clicks * 50, 255]
23 });
24 chrome.pageAction.setBadgeBackgroundColor({
25 tabId: info.tabId,
26 color: [255, clicks * 50, 0, 255]
27 });
28 chrome.pageAction.setBadgeText({
29 tabId: info.tabId,
30 text: clicks + ""
31 });
32
33 // We only have 2 icons, but cycle through 3 icons to test the
34 // out-of-bounds index bug.
35 clicks++;
36 if (clicks > 3)
37 clicks = 0;
38 });
39 var i = 0;
40
41 window.setInterval(function() {
42 // Don't animate while in "click" mode.
43 if (clicks > 0) return;
44 i++;
45 chrome.pageAction.setIcon({imageData: draw(i*2, i*4), tabId: lastTabId});
46 }, 50);
47
48 function draw(starty, startx) {
49 var canvas = document.getElementById('canvas');
50 var context = canvas.getContext('2d');
51 context.clearRect(0, 0, canvas.width, canvas.height);
52 context.fillStyle = "rgba(0,200,0,255)";
53 context.fillRect(startx % 19, starty % 19, 8, 8);
54 context.fillStyle = "rgba(0,0,200,255)";
55 context.fillRect((startx + 5) % 19, (starty + 5) % 19, 8, 8);
56 context.fillStyle = "rgba(200,0,0,255)";
57 context.fillRect((startx + 10) % 19, (starty + 10) % 19, 8, 8);
58 return context.getImageData(0, 0, 19, 19);
59 }
60 </script>
61 </head>
62 <body>
63 <canvas id="canvas" width="19" height="19"></canvas>
64 </body>
65 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698