Skip to content

Commit

Permalink
Changed the persistent mode of the background to false.
Browse files Browse the repository at this point in the history
  • Loading branch information
yoichiro committed Feb 3, 2013
1 parent 1f3741f commit a1af0d5
Show file tree
Hide file tree
Showing 6 changed files with 319 additions and 256 deletions.
31 changes: 22 additions & 9 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ IC.SERVER_URL = "http://ics.eisbahn.jp/";

IC.prototype = {
initialize: function() {
this.tabs = {};
// this.tabs = {};
this.setupEventHandler();
this.setupContextMenus();
this.establishSession();
Expand All @@ -20,7 +20,10 @@ IC.prototype = {
this.onSelectionChanged(id);
}
}.bind(this));
chrome.extension.onRequest.addListener(
chrome.tabs.onRemoved.addListener(function(id, removeInfo) {
this.deleteTabImageInfo(id);
}.bind(this));
chrome.extension.onMessage.addListener(
function(message, sender, sendRequest) {
this.onRequest(message, sender.tab, sendRequest);
}.bind(this)
Expand Down Expand Up @@ -71,19 +74,19 @@ IC.prototype = {
return image.url;
});
if (urls.length > 0) {
this.tabs[tab.id] = {
this.setTabImageInfo(tab.id, {
urls: urls,
images: message.images,
filtered: filteredImages
};
});
chrome.pageAction.show(tab.id);
chrome.pageAction.setTitle({
tabId: tab.id,
title: String(urls.length) + " images"
});
this.previewImages(filteredImages, tab);
} else {
delete this.tabs[tab.id];
this.deleteTabImageInfo(tab.id);
chrome.pageAction.hide(tab.id);
chrome.pageAction.setTitle({
tabId: tab.id,
Expand All @@ -98,7 +101,7 @@ IC.prototype = {
sendRequest({});
},
reloadImages: function(tab) {
delete this.tabs[tab.id];
this.deleteTabImageInfo(tab.id);
chrome.pageAction.hide(tab.id);
this.executeContentScript(tab.id);
},
Expand All @@ -112,11 +115,21 @@ IC.prototype = {
},
getSelectedTabImageInfo: function(callback) {
chrome.tabs.getSelected(null, function(tab) {
callback(this.tabs[tab.id], tab.title, tab.url);
callback(this.getTabImageInfo(tab.id), tab.title, tab.url);
}.bind(this));
},
getTabImageInfo: function(tabId) {
return this.tabs[tabId];
// return this.tabs[tabId];
var info = localStorage["tab_" + String(tabId)];
return info.evalJSON();
},
setTabImageInfo: function(tabId, info) {
// this.tabs[tabId] = info;
localStorage["tab_" + String(tabId)] = Object.toJSON(info);
},
deleteTabImageInfo: function(tabId) {
// delete this.tabs[tabId];
localStorage.removeItem("tab_" + String(tabId));
},
filterUrls: function(images) {
var filterExts = utils.split(this.getFilterExts(), " ");
Expand Down Expand Up @@ -301,7 +314,7 @@ IC.prototype = {
},
goToImage: function(url) {
chrome.tabs.getSelected(null, function(tab) {
var images = this.tabs[tab.id].images;
var images = this.getTabImageInfo(tab.id).images;
var pos = -1;
for (var i = 0; i < images.length; i++) {
var image = images[i];
Expand Down
6 changes: 3 additions & 3 deletions content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ if (typeof CS == "undefined") {
type: "parsed_images",
images: images
};
chrome.extension.sendRequest(message);
chrome.extension.sendMessage(message);
},
previewImages: function(images, position, tabId) {
var panel = this.createPreviewPanel(position);
Expand Down Expand Up @@ -163,13 +163,13 @@ if (typeof CS == "undefined") {
type: "disable_button",
tabId: tabId
};
chrome.extension.sendRequest(message);
chrome.extension.sendMessage(message);
},
sendDismissHotPreviewMessage: function() {
var message = {
type: "dismiss_hotpreview"
};
chrome.extension.sendRequest(message);
chrome.extension.sendMessage(message);
},
adjustPreviewPanelHeight: function(panel) {
var clientHeight = document.documentElement.clientHeight;
Expand Down
5 changes: 3 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
"manifest_version": 2,
"name": "Image collector extension",
"description": "__MSG_extDescription__",
"version": "6.0.0",
"version": "6.0.1",
"icons": {
"48": "icon48.png",
"128": "icon128.png"
},
"background": {
"page": "background.html"
"page": "background.html",
"persistent": false
},
"default_locale": "en",
"page_action": {
Expand Down
195 changes: 108 additions & 87 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var Options = function() {

Options.prototype = {
initialize: function() {
this.bg = chrome.extension.getBackgroundPage();
window.addEventListener("load", function(evt) {
this.start();
}.bind(this));
Expand Down Expand Up @@ -112,48 +111,56 @@ Options.prototype = {
this.onChangePreviewPosition.bind(this);
},
restoreConfigurations: function() {
$("command_template").value = this.bg.ic.getCommandTemplate();
$("filter_exts").value = this.bg.ic.getFilterExts();
$("filter_excepts").value = this.bg.ic.getFilterExcepts();
$("filter_size_width").value = this.bg.ic.getFilterSizeWidth();
$("filter_size_height").value = this.bg.ic.getFilterSizeHeight();
$("priority_link_href").checked = this.bg.ic.isPriorityLinkHref();
$("download_filename").value = this.bg.ic.getDownloadFilename();
$("without_creating_folder").checked = this.bg.ic.isWithoutCreatingFolder();
$("preview_position").value = this.bg.ic.getPreviewPosition();
chrome.runtime.getBackgroundPage(function(bg) {
$("command_template").value = bg.ic.getCommandTemplate();
$("filter_exts").value = bg.ic.getFilterExts();
$("filter_excepts").value = bg.ic.getFilterExcepts();
$("filter_size_width").value = bg.ic.getFilterSizeWidth();
$("filter_size_height").value = bg.ic.getFilterSizeHeight();
$("priority_link_href").checked = bg.ic.isPriorityLinkHref();
$("download_filename").value = bg.ic.getDownloadFilename();
$("without_creating_folder").checked = bg.ic.isWithoutCreatingFolder();
$("preview_position").value = bg.ic.getPreviewPosition();
});
},
checkDropboxAuthorized: function() {
this.bg.ic.checkDropboxAuthorized({
onSuccess: function(req) {
var result = req.responseJSON.result;
utils.setVisible($("dropbox_authorized"), result);
utils.setVisible($("dropbox_unauthorized"), !result);
utils.setVisible($("auth_dropbox"), !result);
utils.setVisible($("cancel_dropbox"), result);
}.bind(this)
});
chrome.runtime.getBackgroundPage(function(bg) {
bg.ic.checkDropboxAuthorized({
onSuccess: function(req) {
var result = req.responseJSON.result;
utils.setVisible($("dropbox_authorized"), result);
utils.setVisible($("dropbox_unauthorized"), !result);
utils.setVisible($("auth_dropbox"), !result);
utils.setVisible($("cancel_dropbox"), result);
}.bind(this)
});
}.bind(this));
},
checkGDriveAuthorized: function() {
this.bg.ic.checkGDriveAuthorized({
onSuccess: function(req) {
var result = req.responseJSON.result;
utils.setVisible($("gdrive_authorized"), result);
utils.setVisible($("gdrive_unauthorized"), !result);
utils.setVisible($("auth_gdrive"), !result);
utils.setVisible($("cancel_gdrive"), result);
}.bind(this)
});
chrome.runtime.getBackgroundPage(function(bg) {
bg.ic.checkGDriveAuthorized({
onSuccess: function(req) {
var result = req.responseJSON.result;
utils.setVisible($("gdrive_authorized"), result);
utils.setVisible($("gdrive_unauthorized"), !result);
utils.setVisible($("auth_gdrive"), !result);
utils.setVisible($("cancel_gdrive"), result);
}.bind(this)
});
}.bind(this));
},
checkSDriveAuthorized: function() {
this.bg.ic.checkSDriveAuthorized({
onSuccess: function(req) {
var result = req.responseJSON.result;
utils.setVisible($("sdrive_authorized"), result);
utils.setVisible($("sdrive_unauthorized"), !result);
utils.setVisible($("auth_sdrive"), !result);
utils.setVisible($("cancel_sdrive"), result);
}.bind(this)
});
chrome.runtime.getBackgroundPage(function(bg) {
bg.ic.checkSDriveAuthorized({
onSuccess: function(req) {
var result = req.responseJSON.result;
utils.setVisible($("sdrive_authorized"), result);
utils.setVisible($("sdrive_unauthorized"), !result);
utils.setVisible($("auth_sdrive"), !result);
utils.setVisible($("cancel_sdrive"), result);
}.bind(this)
});
}.bind(this));
},
onClickCommandTemplateSave: function(evt) {
localStorage["command_template"] = $("command_template").value;
Expand Down Expand Up @@ -209,71 +216,85 @@ Options.prototype = {
localStorage[name] = $(name).checked ? "true" : "";
},
onClickAuthDropbox: function(evt) {
location.href = this.bg.ic.getDropboxAuthUrl();
chrome.runtime.getBackgroundPage(function(bg) {
location.href = bg.ic.getDropboxAuthUrl();
});
},
onClickCancelDropbox: function(evt) {
this.bg.ic.cancelDropbox({
onSuccess: function(req) {
this.checkDropboxAuthorized();
}.bind(this),
onFailure: function(req) {
this.checkDropboxAuthorized();
}.bind(this)
});
chrome.runtime.getBackgroundPage(function(bg) {
bg.ic.cancelDropbox({
onSuccess: function(req) {
this.checkDropboxAuthorized();
}.bind(this),
onFailure: function(req) {
this.checkDropboxAuthorized();
}.bind(this)
});
}.bind(this));
},
onClickCancelGDrive: function(evt) {
this.bg.ic.cancelGDrive({
onSuccess: function(req) {
this.checkGDriveAuthorized();
}.bind(this),
onFailure: function(req) {
this.checkGDriveAuthorized();
}.bind(this)
});
chrome.runtime.getBackgroundPage(function(bg) {
bg.ic.cancelGDrive({
onSuccess: function(req) {
this.checkGDriveAuthorized();
}.bind(this),
onFailure: function(req) {
this.checkGDriveAuthorized();
}.bind(this)
});
}.bind(this));
},
onClickCancelSDrive: function(evt) {
this.bg.ic.cancelSDrive({
onSuccess: function(req) {
this.checkSDriveAuthorized();
}.bind(this),
onFailure: function(req) {
this.checkSDriveAuthorized();
}.bind(this)
});
chrome.runtime.getBackgroundPage(function(bg) {
bg.ic.cancelSDrive({
onSuccess: function(req) {
this.checkSDriveAuthorized();
}.bind(this),
onFailure: function(req) {
this.checkSDriveAuthorized();
}.bind(this)
});
}.bind(this));
},
onClickAuthGDrive: function(evt) {
var token = this.bg.ic.getSessionToken();
var optionUrl = chrome.extension.getURL("options.html");
var url =
this.bg.ic.getServerUrl() + "auth_gdrive?"
+ "token=" + token
+ "&callback=" + encodeURIComponent(optionUrl);
location.href = url;
chrome.runtime.getBackgroundPage(function(bg) {
var token = bg.ic.getSessionToken();
var optionUrl = chrome.extension.getURL("options.html");
var url =
bg.ic.getServerUrl() + "auth_gdrive?"
+ "token=" + token
+ "&callback=" + encodeURIComponent(optionUrl);
location.href = url;
});
},
onClickAuthSDrive: function(evt) {
var token = this.bg.ic.getSessionToken();
var optionUrl = chrome.extension.getURL("options.html");
var url =
this.bg.ic.getServerUrl() + "auth_sdrive?"
+ "token=" + token
+ "&callback=" + encodeURIComponent(optionUrl);
location.href = url;
chrome.runtime.getBackgroundPage(function(bg) {
var token = bg.ic.getSessionToken();
var optionUrl = chrome.extension.getURL("options.html");
var url =
bg.ic.getServerUrl() + "auth_sdrive?"
+ "token=" + token
+ "&callback=" + encodeURIComponent(optionUrl);
location.href = url;
});
},
onClickWithoutCreatingFolder: function() {
this.changeCheckboxConfiguration("without_creating_folder");
},
loadMonitor: function() {
this.bg.ic.loadMonitor({
onSuccess: function(req) {
var result = req.responseJSON;
$("stat_remaining_job_count").innerText =
this.addFigure(result.job_count);
$("stat_page_count").innerText =
this.addFigure(result.page_count);
$("stat_image_count").innerText =
this.addFigure(result.image_count);
}.bind(this)
});
chrome.runtime.getBackgroundPage(function(bg) {
bg.ic.loadMonitor({
onSuccess: function(req) {
var result = req.responseJSON;
$("stat_remaining_job_count").innerText =
this.addFigure(result.job_count);
$("stat_page_count").innerText =
this.addFigure(result.page_count);
$("stat_image_count").innerText =
this.addFigure(result.image_count);
}.bind(this)
});
}.bind(this));
},
addFigure: function(value) {
var num = new String(value).replace(/,/g, "");
Expand Down
Loading

0 comments on commit a1af0d5

Please sign in to comment.