зеркало из https://github.com/mozilla/pjs.git
Bug 325812 r=annie.sullivan Add annotation Int64, remove variant functions.
This commit is contained in:
Родитель
629a6b8f21
Коммит
65814174c2
|
@ -108,36 +108,37 @@ interface nsIAnnotationService : nsISupports
|
|||
* service, but are special cased in the protocol handler so they look like
|
||||
* annotations. Do not set favicons using this service.
|
||||
*/
|
||||
void setAnnotation(in nsIURI aURI, in AUTF8String aName, in nsIVariant aValue,
|
||||
in PRInt32 aFlags, in PRInt32 aExpiration);
|
||||
|
||||
/**
|
||||
* Sets an annotation just like setAnnotation, but takes a string as
|
||||
* input, which will be more convenient for C++.
|
||||
*/
|
||||
void setAnnotationString(in nsIURI aURI, in AUTF8String aName,
|
||||
in AString aValue, in PRInt32 aFlags,
|
||||
in PRInt32 aExpiration);
|
||||
|
||||
/**
|
||||
* Sets an annotation just like setAnnotation, but takes an Int32 as input
|
||||
* for convenience.
|
||||
* Sets an annotation just like setAnnotationString, but takes an Int32 as
|
||||
* input.
|
||||
*/
|
||||
void setAnnotationInt32(in nsIURI aURI, in AUTF8String aName,
|
||||
in PRInt32 aValue, in PRInt32 aFlags,
|
||||
in PRInt32 aExpiration);
|
||||
|
||||
/**
|
||||
* Sets an annotation just like setAnnotation, but takes an Int64 as input
|
||||
* for convenience.
|
||||
* Sets an annotation just like setAnnotationString, but takes an Int64 as
|
||||
* input.
|
||||
*/
|
||||
void setAnnotationInt64(in nsIURI aURI, in AUTF8String aName,
|
||||
in PRInt64 aValue, in PRInt32 aFlags,
|
||||
in PRInt32 aExpiration);
|
||||
|
||||
/**
|
||||
* Sets an annotation just like setAnnotationString, but takes a double as
|
||||
* input.
|
||||
*/
|
||||
void setAnnotationDouble(in nsIURI aURI, in AUTF8String aName,
|
||||
in double aValue, in PRInt32 aFlags,
|
||||
in PRInt32 aExpiration);
|
||||
|
||||
/*
|
||||
* Sets an annotation just like setAnnotation, but takes binary data as
|
||||
* input. You MUST supply a valid MIME type.
|
||||
* Sets an annotation just like setAnnotationString, but takes binary data
|
||||
* as input. You MUST supply a valid MIME type.
|
||||
*/
|
||||
void setAnnotationBinary(in nsIURI aURI, in AUTF8String aName,
|
||||
[const,array,size_is(aDataLen)] in octet aData,
|
||||
|
@ -145,34 +146,41 @@ interface nsIAnnotationService : nsISupports
|
|||
in PRInt32 aFlags, in PRInt32 aExpiration);
|
||||
|
||||
/**
|
||||
* Retrieves the value of an existing annotation. Throws if the annotation
|
||||
* does not exist.
|
||||
*/
|
||||
nsIVariant getAnnotation(in nsIURI aURI, in AUTF8String aName);
|
||||
|
||||
/**
|
||||
* Same as getAnnotation but a convenience function for C++ for strings.
|
||||
* Retrieves the string value of a given annotation. Throws an error if the
|
||||
* annotation does not exist. If the annotation was set as a different
|
||||
* type than you are retrieving it as, the value will be converted as best
|
||||
* as we can. You aren't always guaranteed a good conversion, however,
|
||||
* and errors will not be thrown in this case. (For example, doubles will
|
||||
* lose precision when stringified.)
|
||||
*/
|
||||
AString getAnnotationString(in nsIURI aURI, in AUTF8String aName);
|
||||
|
||||
/**
|
||||
* Same as getAnnotation but a convenience function for C++ for ints. If
|
||||
* the value doesn't look like an int, returns 0. (this is current sqlite
|
||||
* behavior when asking for an int when there is not one, it will likely
|
||||
* change in the future if we start caching stuff).
|
||||
* Same as getAnnotationString but for ints. If the value doesn't look like
|
||||
* an int, returns 0. (this is current sqlite behavior when asking for an
|
||||
* int when there is not one, it will possibly change in the future if we
|
||||
* start caching stuff).
|
||||
*/
|
||||
PRInt32 getAnnotationInt32(in nsIURI aURI, in AUTF8String aName);
|
||||
|
||||
/**
|
||||
* Same as getAnnotation but a convenience function for C++ for int64s. If
|
||||
* the value doesn't look like an int, returns 0. (this is current sqlite
|
||||
* behavior when asking for an int when there is not one, it will likely
|
||||
* change in the future if we start caching stuff).
|
||||
* Same as getAnnotationString for Int64s. If the value doesn't look like
|
||||
* an int, returns 0. (this is current sqlite behavior when asking for an
|
||||
* int when there is not one, it will possibly change in the future if we
|
||||
* start caching stuff).
|
||||
*/
|
||||
PRInt64 getAnnotationInt64(in nsIURI aURI, in AUTF8String aName);
|
||||
|
||||
/**
|
||||
* Same as getAnnotation but for binary data. This also returns the
|
||||
* Same as getAnnotationString but returns a double-precision float. If the
|
||||
* value doesn't look like an float, returns 0. (this is current sqlite
|
||||
* behavior when asking for an number when there is not one, it will
|
||||
* possibly change in the future if we start caching stuff).
|
||||
*/
|
||||
double getAnnotationDouble(in nsIURI aURI, in AUTF8String aName);
|
||||
|
||||
/**
|
||||
* Same as getAnnotationString but for binary data. This also returns the
|
||||
* MIME type.
|
||||
*/
|
||||
void getAnnotationBinary(in nsIURI aURI, in AUTF8String aName,
|
||||
|
|
|
@ -116,23 +116,6 @@ nsAnnotationService::Init()
|
|||
}
|
||||
|
||||
|
||||
// nsAnnotationService::SetAnnotation
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAnnotationService::SetAnnotation(nsIURI* aURI,
|
||||
const nsACString& aName,
|
||||
nsIVariant *aValue,
|
||||
PRInt32 aFlags, PRInt32 aExpiration)
|
||||
{
|
||||
if (! aValue)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
nsAutoString stringValue;
|
||||
nsresult rv = aValue->GetAsAString(stringValue);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return SetAnnotationString(aURI, aName, stringValue, aFlags, aExpiration);
|
||||
}
|
||||
|
||||
|
||||
// nsAnnotationService::SetAnnotationString
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -229,6 +212,38 @@ nsAnnotationService::SetAnnotationInt64(nsIURI* aURI,
|
|||
}
|
||||
|
||||
|
||||
// nsAnnotationService::SetAnnotationDouble
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAnnotationService::SetAnnotationDouble(nsIURI* aURI,
|
||||
const nsACString& aName,
|
||||
double aValue,
|
||||
PRInt32 aFlags, PRInt32 aExpiration)
|
||||
{
|
||||
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
||||
mozIStorageStatement* statement; // class var, not owned by this function
|
||||
nsresult rv = StartSetAnnotation(aURI, aName, aFlags, aExpiration, &statement);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mozStorageStatementScoper statementResetter(statement);
|
||||
|
||||
rv = statement->BindDoubleParameter(kAnnoIndex_Content, aValue);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = statement->BindNullParameter(kAnnoIndex_MimeType);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = statement->Execute();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
transaction.Commit();
|
||||
|
||||
// should reset the statement; observers may call our service back to get
|
||||
// annotation values!
|
||||
statement->Reset();
|
||||
statementResetter.Abandon();
|
||||
CallSetObservers(aURI, aName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// nsAnnotationService::SetAnnotationBinary
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -266,29 +281,6 @@ nsAnnotationService::SetAnnotationBinary(nsIURI* aURI,
|
|||
}
|
||||
|
||||
|
||||
// nsAnnotationService::GetAnnotation
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAnnotationService::GetAnnotation(nsIURI* aURI,
|
||||
const nsACString& aName,
|
||||
nsIVariant** _retval)
|
||||
{
|
||||
nsAutoString stringValue;
|
||||
nsresult rv = GetAnnotationString(aURI, aName, stringValue);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIWritableVariant> var = do_CreateInstance("@mozilla.org/variant;1",
|
||||
&rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = var->SetAsAString(stringValue);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
*_retval = var;
|
||||
NS_ADDREF(*_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// nsAnnotationService::GetAnnotationString
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -337,6 +329,22 @@ nsAnnotationService::GetAnnotationInt64(nsIURI* aURI,
|
|||
}
|
||||
|
||||
|
||||
// nsAnnotationService::GetAnnotationDouble
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAnnotationService::GetAnnotationDouble(nsIURI* aURI,
|
||||
const nsACString& aName,
|
||||
double *_retval)
|
||||
{
|
||||
nsresult rv = StartGetAnnotationFromURI(aURI, aName);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
*_retval = mDBGetAnnotationFromURI->AsDouble(kAnnoIndex_Content);
|
||||
mDBGetAnnotationFromURI->Reset();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// nsAnnotationService::GetAnnotationBinary
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
Загрузка…
Ссылка в новой задаче