From dcbe4e9e79423d8cac981a0bc646657f0b2cbc49 Mon Sep 17 00:00:00 2001
From: aa <aa@aboodman2-corp.ad.corp.google.com>
Date: Sun, 13 Sep 2009 16:14:20 -0700
Subject: [PATCH] meh

---
 background.html       |   23 +++++++++++------------
 enable-readability.js |   14 +++++++++++---
 2 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/background.html b/background.html
index 16a303f..fd76693 100644
--- a/background.html
+++ b/background.html
@@ -1,23 +1,22 @@
 <script>
 var kActionId = "readability";
 
-chrome.tabs.onCreated.addListener(function(tab) {
-  console.log("tab " + tab.id + " created");
-  chrome.pageActions.enableForTab(kActionId,
-                                  { tabId: tab.id, url: tab.url });
-});
-
+// BUG 21729: It would be better if there were unambiguous page loading/loaded
+// events, that came with URLs every time.
 chrome.tabs.onUpdated.addListener(function(tabid, info) {
-  console.log("tab " + tabid + " updated");
-  if (info.url) {
-    chrome.pageActions.enableForTab(kActionId,
-                                    { tabId: tabid, url: info.url });
+  if (info.status == 'loading') {
+    // Blech: We need the URL parameter for enableForTab(), but for reloads,
+    // status==loading doesn't contain it (because it hasn't changed).  So we
+    // need to now turn around and re-request the URL.
+    chrome.tabs.get(tabid, function(tab) {
+      chrome.pageActions.enableForTab(kActionId,
+                                      { tabId: tab.id, url: tab.url });
+    });
   }
 });
 
 chrome.pageActions["readability"].addListener(function(actionid, info) {
-  console.log(info.tabUrl);
-  chrome.tabs.connect(info.tabId).postMessage("hello");
+  chrome.tabs.connect(info.tabId).postMessage("go");
 });
 
 </script>
diff --git a/enable-readability.js b/enable-readability.js
index 99f8aba..5b9e0d6 100644
--- a/enable-readability.js
+++ b/enable-readability.js
@@ -1,3 +1,12 @@
+// BUG 17410: If a content script doesn't use a DOM event, it can get GC'd.
+function dummy(){
+  console.log(chrome.extension);
+}
+window.addEventListener("load", dummy, false);
+
+
+// These don't make it through to the readability-injected <script> because
+// of isolated worlds.  :~(
 var readStyle='style-novel';
 var readSize='size-medium';
 var readMargin='margin-wide';
@@ -22,8 +31,7 @@ function readabilityize() {
 }
 
 chrome.extension.onConnect.addListener(function(port) {
-  port.onMessage.addListener(function(msg) {
-    alert("message! " + msg);
+  if (window == top) {
     readabilityize();
-  });
+  }
 });
-- 
1.6.1.2

