mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-20 17:20:54 +00:00
Bug 676906 - Added async getFaviconDataForPage in mozIAsyncFavicons. r=mak
This commit is contained in:
parent
b9a5702625
commit
7374e2a323
@ -859,7 +859,7 @@ AsyncAssociateIconToPage::Run()
|
||||
|
||||
// static
|
||||
nsresult
|
||||
AsyncGetFaviconURLForPage::start(nsIURI *aPageURI,
|
||||
AsyncGetFaviconURLForPage::start(nsIURI* aPageURI,
|
||||
nsCOMPtr<mozIStorageConnection>& aDBConn,
|
||||
nsIFaviconDataCallback* aCallback)
|
||||
{
|
||||
@ -927,6 +927,83 @@ AsyncGetFaviconURLForPage::Run()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// AsyncGetFaviconDataForPage
|
||||
|
||||
// static
|
||||
nsresult
|
||||
AsyncGetFaviconDataForPage::start(nsIURI* aPageURI,
|
||||
nsCOMPtr<mozIStorageConnection>& aDBConn,
|
||||
nsIFaviconDataCallback* aCallback)
|
||||
{
|
||||
NS_ENSURE_ARG(aCallback);
|
||||
NS_ENSURE_ARG(aPageURI);
|
||||
NS_PRECONDITION(NS_IsMainThread(),
|
||||
"This should be called on the main thread.");
|
||||
|
||||
nsRefPtr<nsFaviconService> fs = nsFaviconService::GetFaviconService();
|
||||
NS_ENSURE_TRUE(fs, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
nsCAutoString pageSpec;
|
||||
nsresult rv = aPageURI->GetSpec(pageSpec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIFaviconDataCallback> callback = aCallback;
|
||||
nsRefPtr<AsyncGetFaviconDataForPage> event =
|
||||
new AsyncGetFaviconDataForPage(pageSpec, aDBConn, fs, callback);
|
||||
|
||||
nsCOMPtr<nsIEventTarget> target = do_GetInterface(aDBConn);
|
||||
NS_ENSURE_TRUE(target, NS_ERROR_OUT_OF_MEMORY);
|
||||
rv = target->Dispatch(event, NS_DISPATCH_NORMAL);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
AsyncGetFaviconDataForPage::AsyncGetFaviconDataForPage(const nsACString& aPageSpec,
|
||||
nsCOMPtr<mozIStorageConnection>& aDBConn,
|
||||
nsRefPtr<nsFaviconService>& aFaviconSvc,
|
||||
nsCOMPtr<nsIFaviconDataCallback>& aCallback)
|
||||
: AsyncFaviconHelperBase(aDBConn, aFaviconSvc, aCallback)
|
||||
{
|
||||
mPageSpec.Assign(aPageSpec);
|
||||
}
|
||||
|
||||
AsyncGetFaviconDataForPage::~AsyncGetFaviconDataForPage()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AsyncGetFaviconDataForPage::Run()
|
||||
{
|
||||
NS_PRECONDITION(!NS_IsMainThread(),
|
||||
"This should not be called on the main thread.");
|
||||
|
||||
nsCAutoString iconSpec;
|
||||
nsresult rv = FetchIconURL(mFaviconSvc->mSyncStatements,
|
||||
mPageSpec, iconSpec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!iconSpec.Length()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
IconData iconData;
|
||||
iconData.spec.Assign(iconSpec);
|
||||
|
||||
PageData pageData;
|
||||
pageData.spec.Assign(mPageSpec);
|
||||
|
||||
rv = FetchIconInfo(mFaviconSvc->mSyncStatements, iconData);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIRunnable> event =
|
||||
new NotifyIconObservers(iconData, pageData, mDBConn,
|
||||
mFaviconSvc, mCallback);
|
||||
rv = NS_DispatchToMainThread(event);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// NotifyIconObservers
|
||||
|
||||
|
@ -314,6 +314,53 @@ private:
|
||||
nsCString mPageSpec;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Asynchronously tries to get the URL and data of a page's favicon.
|
||||
* If this succeeds, notifies the given observer.
|
||||
*/
|
||||
class AsyncGetFaviconDataForPage : public AsyncFaviconHelperBase
|
||||
{
|
||||
public:
|
||||
NS_DECL_NSIRUNNABLE
|
||||
|
||||
/**
|
||||
* Creates the event and dispatches it to the I/O thread.
|
||||
*
|
||||
* @param aPageURI
|
||||
* URL of the page whose favicon URL and data we're fetching
|
||||
* @param aDBConn
|
||||
* database connection to use
|
||||
* @param aCallback
|
||||
* function to be called once the URL and data is retrieved from the database
|
||||
*/
|
||||
static nsresult start(nsIURI* aPageURI,
|
||||
nsCOMPtr<mozIStorageConnection>& aDBConn,
|
||||
nsIFaviconDataCallback* aCallback);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param aPageSpec
|
||||
* URL of the page whose favicon URL and data we're fetching
|
||||
* @param aDBConn
|
||||
* database connection to use
|
||||
* @param aFaviconSvc
|
||||
* the favicon service to query
|
||||
* @param aCallback
|
||||
* function to be called once the URL is retrieved from the database
|
||||
*/
|
||||
AsyncGetFaviconDataForPage(const nsACString& aPageSpec,
|
||||
nsCOMPtr<mozIStorageConnection>& aDBConn,
|
||||
nsRefPtr<nsFaviconService>& aFaviconSvc,
|
||||
nsCOMPtr<nsIFaviconDataCallback>& aCallback);
|
||||
|
||||
virtual ~AsyncGetFaviconDataForPage();
|
||||
|
||||
private:
|
||||
nsCString mPageSpec;
|
||||
};
|
||||
|
||||
/**
|
||||
* Notifies the icon change to favicon observers.
|
||||
*/
|
||||
|
@ -718,6 +718,17 @@ nsFaviconService::GetFaviconURLForPage(nsIURI *aPageURI,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFaviconService::GetFaviconDataForPage(nsIURI* aPageURI,
|
||||
nsIFaviconDataCallback* aCallback)
|
||||
{
|
||||
NS_ENSURE_ARG(aPageURI);
|
||||
NS_ENSURE_ARG(aCallback);
|
||||
|
||||
nsresult rv = AsyncGetFaviconDataForPage::start(aPageURI, mDBConn, aCallback);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFaviconService::GetFaviconImageForPage(nsIURI* aPageURI, nsIURI** _retval)
|
||||
|
Loading…
x
Reference in New Issue
Block a user