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

Side by Side Diff: chrome/test/data/extensions/subscribe_page_action/background.js

Issue 12843037: Convert the RSS extension to event pages to avoid a dedicated background process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // A dictionary keyed off of tabId that keeps track of data per tab (for 5 chrome.extension.onMessage.addListener(function(request, sender) {
6 // example what feedUrl was detected in the tab).
7 var feedData = {};
8
9 chrome.extension.onRequest.addListener(function(request, sender) {
10 if (request.msg == "feedIcon") { 6 if (request.msg == "feedIcon") {
11 // First validate that all the URLs have the right schema. 7 // First validate that all the URLs have the right schema.
12 var input = []; 8 var input = [];
13 for (var i = 0; i < request.feeds.length; ++i) { 9 for (var i = 0; i < request.feeds.length; ++i) {
14 var a = document.createElement('a'); 10 var a = document.createElement('a');
15 a.href = request.feeds[i].href; 11 a.href = request.feeds[i].href;
16 if (a.protocol == "http:" || a.protocol == "https:") { 12 if (a.protocol == "http:" || a.protocol == "https:") {
17 input.push(request.feeds[i]); 13 input.push(request.feeds[i]);
18 } else { 14 } else {
19 console.log('Warning: feed source rejected (wrong protocol): ' + 15 console.log('Warning: feed source rejected (wrong protocol): ' +
20 request.feeds[i].href); 16 request.feeds[i].href);
21 } 17 }
22 } 18 }
23 19
24 if (input.length == 0) 20 if (input.length == 0)
25 return; // We've rejected all the input, so abort. 21 return; // We've rejected all the input, so abort.
26 22
27 // We have received a list of feed urls found on the page. 23 // We have received a list of feed urls found on the page.
28 // Enable the page action icon. 24 var feeds = {};
29 feedData[sender.tab.id] = input; 25 feeds[sender.tab.id] = input;
not at google - send to devlin 2013/04/08 04:39:55 initialize directly? var feeds = {...} (in fact yo
Finnur 2013/04/08 12:59:24 This is actually the only way I could get it to wo
not at google - send to devlin 2013/04/08 22:01:27 Doh. I've been writing too much python.
30 chrome.pageAction.setTitle( 26 chrome.storage.local.set(feeds, function() {
31 { tabId: sender.tab.id, 27 // Enable the page action icon.
32 title: chrome.i18n.getMessage("rss_subscription_action_title") 28 chrome.pageAction.setTitle(
33 }); 29 { tabId: sender.tab.id,
34 chrome.pageAction.show(sender.tab.id); 30 title: chrome.i18n.getMessage("rss_subscription_action_title")
31 });
32 chrome.pageAction.show(sender.tab.id);
33 });
35 } else if (request.msg == "feedDocument") { 34 } else if (request.msg == "feedDocument") {
36 // We received word from the content script that this document 35 // We received word from the content script that this document
37 // is an RSS feed (not just a document linking to the feed). 36 // is an RSS feed (not just a document linking to the feed).
38 // So, we go straight to the subscribe page in a new tab and 37 // So, we go straight to the subscribe page in a new tab and
39 // navigate back on the current page (to get out of the xml page). 38 // navigate back on the current page (to get out of the xml page).
40 // We don't want to navigate in-place because trying to go back 39 // We don't want to navigate in-place because trying to go back
41 // from the subscribe page takes us back to the xml page, which 40 // from the subscribe page takes us back to the xml page, which
42 // will redirect to the subscribe page again (we don't support a 41 // will redirect to the subscribe page again (we don't support a
43 // location.replace equivalant in the Tab navigation system). 42 // location.replace equivalant in the Tab navigation system).
44 chrome.tabs.executeScript(sender.tab.id, 43 chrome.tabs.executeScript(sender.tab.id,
45 { code: "if (history.length > 1) " + 44 { code: "if (history.length > 1) " +
46 "history.go(-1); else window.close();" 45 "history.go(-1); else window.close();"
47 }); 46 });
48 var url = "subscribe.html?" + encodeURIComponent(request.href); 47 var url = "subscribe.html?" + encodeURIComponent(request.href);
49 url = chrome.extension.getURL(url); 48 url = chrome.extension.getURL(url);
50 chrome.tabs.create({ url: url, index: sender.tab.index }); 49 chrome.tabs.create({ url: url, index: sender.tab.index });
51 } 50 }
52 }); 51 });
53 52
54 chrome.tabs.onRemoved.addListener(function(tabId) { 53 chrome.tabs.onRemoved.addListener(function(tabId) {
55 delete feedData[tabId]; 54 chrome.storage.local.remove(tabId.toString());
not at google - send to devlin 2013/04/08 04:39:55 I think (hope) the toString() is unnecessary.
Finnur 2013/04/08 12:59:24 Nope, toString is needed. Otherwise I get: Error
not at google - send to devlin 2013/04/08 22:01:27 Dang. Could you file bugs? I'm fixing the int key
56 }); 55 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698