Thank you for your enquiry. There are several aspects to you questions and I'll try to answer each in a general way.
Login: In the appAPI.browserAction.onClick callback, before saving the bookmark, you can certainly add code to display a login popup if the user is not logged in. You can achieve this using forms displayed to the user in one of several ways such as using our sidebar plugin, or jQUeryUI.
Tab Url: Since I'm assuming you are using the extension button to trigger the bookmark save, you will require the URL in the background scope where the button callback is defined. The easiest way to achieve this is to keep track of the active tab using the appAPI.tabs.onTabSelectionChanged method, for example:
background.js:
appAPI.ready(function() {
var activeTab = null;
appAPI.tabs.onTabSelectionChanged(function(tabInfo) {
activeTab = tabInfo.tabUrl;
});
});
So putting both ideas together, you code might look something like:
background.js:
appAPI.ready(function() {
var activeTabURL = null;
// Keep track of activeTabs URL
appAPI.tabs.onTabSelectionChanged(function(tabInfo) {
activeTabURL = tabInfo.tabUrl;
});
// Configure button
appAPI.browserAction.setResourceIcon('icon.png');
appAPI.browserAction.onClick(function() {
// Code to check if user is logged in
if (!userLoggedIn) {
// Send message to extension scope to display login form
appAPI.message.toActiveTab({action:'userLogin', bookmarkURL: activeTabURL});
return;
}
// User already logged in, save activeTab's URL
saveBookmark(activeTabURL);
});
// Listen for message that user has logged in and save bookmarkURL
appAPI.message.addListener(function(msg) {
if (msg.action === 'saveBookmark') saveBookmark(msg.bookmarkURL);
});
// Common function to save bookmark URL
function saveBookmark(bookmarkURL) {
// Your bookmark save function
}
});
extension.js:
appAPI.ready(function($) {
appAPI.message.addListener(function($) {
if (msg.action === 'userLogin') {
// your code for user login
...
// Once user logged in send message to background to save bookmarkURL
if (userLoggedIn) {
appAPI.message,toBackground({action:'saveBookmark', boomarkURL:msg.bookmarkURL});
return;
}
}
});
});