gecko-dev/toolkit/components/alerts/AlertNotification.cpp
Kit Cambridge f66e1ecefa Bug 1224785, Part 1 - Implement alert favicons backend. r=wchen
MozReview-Commit-ID: Day8Hj8lT1f

--HG--
extra : rebase_source : b96c8afcfd8da93f8803accb0cda22deaa4820c5
2016-01-07 13:15:55 -07:00

152 lines
3.2 KiB
C++

/* This Source Code Form is subject to the terms of the Mozilla Pub
* License, v. 2.0. If a copy of the MPL was not distributed with t
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/AlertNotification.h"
#include "nsAlertsUtils.h"
namespace mozilla {
NS_IMPL_CYCLE_COLLECTION(AlertNotification, mPrincipal)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AlertNotification)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIAlertNotification)
NS_INTERFACE_MAP_ENTRY(nsIAlertNotification)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(AlertNotification)
NS_IMPL_CYCLE_COLLECTING_RELEASE(AlertNotification)
AlertNotification::AlertNotification()
: mTextClickable(false)
, mPrincipal(nullptr)
, mInPrivateBrowsing(false)
{}
AlertNotification::~AlertNotification()
{}
NS_IMETHODIMP
AlertNotification::Init(const nsAString& aName, const nsAString& aImageURL,
const nsAString& aTitle, const nsAString& aText,
bool aTextClickable, const nsAString& aCookie,
const nsAString& aDir, const nsAString& aLang,
const nsAString& aData, nsIPrincipal* aPrincipal,
bool aInPrivateBrowsing)
{
mName = aName;
mImageURL = aImageURL;
mTitle = aTitle;
mText = aText;
mTextClickable = aTextClickable;
mCookie = aCookie;
mDir = aDir;
mLang = aLang;
mData = aData;
mPrincipal = aPrincipal;
mInPrivateBrowsing = aInPrivateBrowsing;
return NS_OK;
}
NS_IMETHODIMP
AlertNotification::GetName(nsAString& aName)
{
aName = mName;
return NS_OK;
}
NS_IMETHODIMP
AlertNotification::GetImageURL(nsAString& aImageURL)
{
aImageURL = mImageURL;
return NS_OK;
}
NS_IMETHODIMP
AlertNotification::GetTitle(nsAString& aTitle)
{
aTitle = mTitle;
return NS_OK;
}
NS_IMETHODIMP
AlertNotification::GetText(nsAString& aText)
{
aText = mText;
return NS_OK;
}
NS_IMETHODIMP
AlertNotification::GetTextClickable(bool* aTextClickable)
{
*aTextClickable = mTextClickable;
return NS_OK;
}
NS_IMETHODIMP
AlertNotification::GetCookie(nsAString& aCookie)
{
aCookie = mCookie;
return NS_OK;
}
NS_IMETHODIMP
AlertNotification::GetDir(nsAString& aDir)
{
aDir = mDir;
return NS_OK;
}
NS_IMETHODIMP
AlertNotification::GetLang(nsAString& aLang)
{
aLang = mLang;
return NS_OK;
}
NS_IMETHODIMP
AlertNotification::GetData(nsAString& aData)
{
aData = mData;
return NS_OK;
}
NS_IMETHODIMP
AlertNotification::GetPrincipal(nsIPrincipal** aPrincipal)
{
NS_IF_ADDREF(*aPrincipal = mPrincipal);
return NS_OK;
}
NS_IMETHODIMP
AlertNotification::GetURI(nsIURI** aURI)
{
if (!nsAlertsUtils::IsActionablePrincipal(mPrincipal)) {
*aURI = nullptr;
return NS_OK;
}
return mPrincipal->GetURI(aURI);
}
NS_IMETHODIMP
AlertNotification::GetInPrivateBrowsing(bool* aInPrivateBrowsing)
{
*aInPrivateBrowsing = mInPrivateBrowsing;
return NS_OK;
}
NS_IMETHODIMP
AlertNotification::GetActionable(bool* aActionable)
{
*aActionable = nsAlertsUtils::IsActionablePrincipal(mPrincipal);
return NS_OK;
}
NS_IMETHODIMP
AlertNotification::GetSource(nsAString& aSource)
{
nsAlertsUtils::GetSourceHostPort(mPrincipal, aSource);
return NS_OK;
}
} // namespace mozilla