summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-30 16:59:03 +0000
committerasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-30 16:59:03 +0000
commit42a614dd5fe677fd2b98e3b7615c6b2cd733f60b (patch)
tree04d4f56eab9a50915b6acf76fe26b3f4d241f5ac /chrome
parent7ec2ce2b207f434fdc77c74ba92b30efe07bc1d3 (diff)
downloadchromium_src-42a614dd5fe677fd2b98e3b7615c6b2cd733f60b.zip
chromium_src-42a614dd5fe677fd2b98e3b7615c6b2cd733f60b.tar.gz
chromium_src-42a614dd5fe677fd2b98e3b7615c6b2cd733f60b.tar.bz2
Add optional notifications for open/close changes in buildbot monitor sample.
BUG=none TEST=none Review URL: http://codereview.chromium.org/3127004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57871 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/common/extensions/docs/examples/extensions/buildbot/bg.html37
-rw-r--r--chrome/common/extensions/docs/examples/extensions/buildbot/manifest.json6
-rw-r--r--chrome/common/extensions/docs/examples/extensions/buildbot/options.html27
3 files changed, 57 insertions, 13 deletions
diff --git a/chrome/common/extensions/docs/examples/extensions/buildbot/bg.html b/chrome/common/extensions/docs/examples/extensions/buildbot/bg.html
index 1324fb1..39dd344 100644
--- a/chrome/common/extensions/docs/examples/extensions/buildbot/bg.html
+++ b/chrome/common/extensions/docs/examples/extensions/buildbot/bg.html
@@ -1,22 +1,37 @@
<script>
-var statusURL = "http://chromium-status.appspot.com/current";
-
-function updateStatus(text) {
- // Page outputs a line like this:
- // <div class="Notice">Tree is open (issue -> person) </div>
- // Although what's in the <div> is arbitrary and typed by a person.
- var results = (new RegExp('"Notice"[^>]*>(.*)<', 'g')).exec(text);
- if (!results || results.index < 0) {
- throw new Error("couldn't find status div in " + text);
+var statusURL = "http://chromium-status.appspot.com/current?format=raw";
+
+if (!localStorage.prefs) {
+ // Default to notifications being on.
+ localStorage.prefs = JSON.stringify({ "use_notifications": true });
+}
+
+var lastOpen = null;
+var lastNotification = null;
+function notifyIfStatusChange(open, status) {
+ var prefs = JSON.parse(localStorage.prefs);
+ if (lastOpen && lastOpen != open && prefs.use_notifications) {
+ if (lastNotification) {
+ lastNotification.cancel();
+ }
+ var notification = webkitNotifications.createNotification(
+ chrome.extension.getURL("icon.png"), "Tree is " + open, status);
+ lastNotification = notification;
+ notification.show();
}
- var status = results[1];
+ lastOpen = open;
+}
+
+function updateStatus(status) {
chrome.browserAction.setTitle({title:status});
var open = /open/i;
if (open.exec(status)) {
+ notifyIfStatusChange("open", status);
//chrome.browserAction.setBadgeText("\u263A");
chrome.browserAction.setBadgeText({text:"\u2022"});
chrome.browserAction.setBadgeBackgroundColor({color:[0,255,0,255]});
} else {
+ notifyIfStatusChange("closed", status);
//chrome.browserAction.setBadgeText("\u2639");
chrome.browserAction.setBadgeText({text:"\u00D7"});
chrome.browserAction.setBadgeBackgroundColor({color:[255,0,0,255]});
@@ -29,7 +44,7 @@ function requestStatus() {
}
function requestURL(url, callback) {
- console.log("requestURL: " + url);
+ //console.log("requestURL: " + url);
var xhr = new XMLHttpRequest();
try {
xhr.onreadystatechange = function(state) {
diff --git a/chrome/common/extensions/docs/examples/extensions/buildbot/manifest.json b/chrome/common/extensions/docs/examples/extensions/buildbot/manifest.json
index 4308433..1acb250 100644
--- a/chrome/common/extensions/docs/examples/extensions/buildbot/manifest.json
+++ b/chrome/common/extensions/docs/examples/extensions/buildbot/manifest.json
@@ -1,10 +1,11 @@
{
"name": "Chromium Buildbot Monitor",
- "version": "0.7.3",
+ "version": "0.7.5",
"description": "Displays the status of the Chromium buildbot in the toolbar. Click to see more detailed status in a popup.",
"icons": { "128": "icon.png" },
"background_page": "bg.html",
"permissions": [
+ "notifications",
"http://build.chromium.org/",
"http://chromium-status.appspot.com/"
],
@@ -12,5 +13,6 @@
"default_title": "",
"default_icon": "chromium.png",
"popup": "popup.html"
- }
+ },
+ "options_page": "options.html"
}
diff --git a/chrome/common/extensions/docs/examples/extensions/buildbot/options.html b/chrome/common/extensions/docs/examples/extensions/buildbot/options.html
new file mode 100644
index 0000000..b02af77
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/extensions/buildbot/options.html
@@ -0,0 +1,27 @@
+<!doctype html>
+<html>
+<head>
+<script>
+
+function save() {
+ var prefs = JSON.parse(localStorage.prefs);
+ prefs.use_notifications = document.getElementById("notifications").checked;
+ localStorage.prefs = JSON.stringify(prefs);
+}
+
+// Make sure the checkbox checked state gets properly initialized from the
+// saved preference.
+window.onload = function() {
+ var prefs = JSON.parse(localStorage.prefs);
+ document.getElementById("notifications").checked = prefs.use_notifications;
+}
+
+</script>
+</head>
+<body>
+<h2>Options for Chromium Buildbot Monitor</h2>
+<br>
+Use desktop notifications: <input id="notifications" type="checkbox" onclick="save()">
+
+</body>
+</html>