зеркало из https://github.com/mozilla/gecko-dev.git
Final part of Bug 389070 Port bookmarks to frozen linkage. r=Neil. NPOTFFB.
This commit is contained in:
Родитель
b71eba5bbb
Коммит
b1f095b4b5
|
@ -45,7 +45,6 @@ include $(DEPTH)/config/autoconf.mk
|
||||||
MODULE = appcomps
|
MODULE = appcomps
|
||||||
LIBRARY_NAME = bookmark
|
LIBRARY_NAME = bookmark
|
||||||
MODULE_NAME = BookmarkModule
|
MODULE_NAME = BookmarkModule
|
||||||
MOZILLA_INTERNAL_API = 1
|
|
||||||
IS_COMPONENT = 1
|
IS_COMPONENT = 1
|
||||||
EXPORT_LIBRARY = 1
|
EXPORT_LIBRARY = 1
|
||||||
|
|
||||||
|
@ -74,6 +73,7 @@ CPPSRCS = nsBookmarksService.cpp
|
||||||
include $(topsrcdir)/config/rules.mk
|
include $(topsrcdir)/config/rules.mk
|
||||||
|
|
||||||
EXTRA_DSO_LDOPTS += \
|
EXTRA_DSO_LDOPTS += \
|
||||||
$(MOZ_UNICHARUTIL_LIBS) \
|
$(call EXPAND_LIBNAME_PATH,unicharutil_external_s,$(LIBXUL_DIST)/lib) \
|
||||||
|
$(XPCOM_GLUE_LDOPTS) \
|
||||||
$(MOZ_COMPONENT_LIBS) \
|
$(MOZ_COMPONENT_LIBS) \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
|
@ -96,12 +96,7 @@
|
||||||
#include "nsVoidArray.h"
|
#include "nsVoidArray.h"
|
||||||
#include "nsUnicharUtils.h"
|
#include "nsUnicharUtils.h"
|
||||||
#include "nsAutoBuffer.h"
|
#include "nsAutoBuffer.h"
|
||||||
|
#include "nsINetUtil.h"
|
||||||
// Tempoarary defines while we convert to the frozen API
|
|
||||||
#ifdef MOZILLA_INTERNAL_API
|
|
||||||
#include "nsEscape.h"
|
|
||||||
#define CaseInsensitiveCompare nsCaseInsensitiveStringComparator()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(XP_WIN) || defined(XP_OS2)
|
#if defined(XP_WIN) || defined(XP_OS2)
|
||||||
#define NS_LINEBREAK "\015\012"
|
#define NS_LINEBREAK "\015\012"
|
||||||
|
@ -399,6 +394,43 @@ bm_ReleaseGlobals()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape HTML-special characters in a string.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
EscapeHTML(nsCString &data)
|
||||||
|
{
|
||||||
|
const char *begin = data.get();
|
||||||
|
|
||||||
|
for (PRInt32 pos = data.Length() - 1; pos >= 0; --pos) {
|
||||||
|
switch (begin[pos]) {
|
||||||
|
case '<':
|
||||||
|
data.Replace(pos, 1, "<");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '>':
|
||||||
|
data.Replace(pos, 1, ">");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '&':
|
||||||
|
data.Replace(pos, 1, "&");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '"':
|
||||||
|
data.Replace(pos, 1, """);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\'':
|
||||||
|
data.Replace(pos, 1, "'");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
begin = data.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -749,7 +781,7 @@ BookmarkParser::DecodeBuffer(nsString &line, char *buf, PRUint32 aLength)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CopyASCIItoUTF16(buf, line);
|
CopyASCIItoUTF16(nsDependentCString(buf), line);
|
||||||
}
|
}
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -1350,7 +1382,7 @@ BookmarkParser::ParseDate(nsIRDFResource *arc, nsString& aValue, nsIRDFNode** aR
|
||||||
PRInt32 theDate = 0;
|
PRInt32 theDate = 0;
|
||||||
if (!aValue.IsEmpty())
|
if (!aValue.IsEmpty())
|
||||||
{
|
{
|
||||||
PRInt32 err;
|
nsresult err;
|
||||||
theDate = aValue.ToInteger(&err); // ignored.
|
theDate = aValue.ToInteger(&err); // ignored.
|
||||||
}
|
}
|
||||||
if (theDate == 0)
|
if (theDate == 0)
|
||||||
|
@ -1862,11 +1894,11 @@ nsBookmarksService::ExamineBookmarkSchedule(nsIRDFResource *theBookmark, PRBool
|
||||||
nsAutoString startStr(StringHead(hourRange, dashOffset));
|
nsAutoString startStr(StringHead(hourRange, dashOffset));
|
||||||
nsAutoString endStr(Substring(hourRange, dashOffset + 1));
|
nsAutoString endStr(Substring(hourRange, dashOffset + 1));
|
||||||
|
|
||||||
PRInt32 rv2 = 0;
|
nsresult rv2;
|
||||||
startHour = startStr.ToInteger(&rv2);
|
startHour = startStr.ToInteger(&rv2);
|
||||||
if (rv2) startHour = -1;
|
if (NS_FAILED(rv2)) startHour = -1;
|
||||||
endHour = endStr.ToInteger(&rv2);
|
endHour = endStr.ToInteger(&rv2);
|
||||||
if (rv2) endHour = -1;
|
if (NS_FAILED(rv2)) endHour = -1;
|
||||||
|
|
||||||
if ((startHour >=0) && (endHour >=0))
|
if ((startHour >=0) && (endHour >=0))
|
||||||
{
|
{
|
||||||
|
@ -1878,7 +1910,7 @@ nsBookmarksService::ExamineBookmarkSchedule(nsIRDFResource *theBookmark, PRBool
|
||||||
|
|
||||||
// get duration
|
// get duration
|
||||||
duration = durationStr.ToInteger(&rv2);
|
duration = durationStr.ToInteger(&rv2);
|
||||||
if (rv2) duration = -1;
|
if (NS_FAILED(rv2)) duration = -1;
|
||||||
|
|
||||||
// what's left is the notification options
|
// what's left is the notification options
|
||||||
notificationMethod = schedule;
|
notificationMethod = schedule;
|
||||||
|
@ -2299,9 +2331,7 @@ nsBookmarksService::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
|
||||||
}
|
}
|
||||||
|
|
||||||
// update icon?
|
// update icon?
|
||||||
if (FindInReadable(NS_LITERAL_STRING("icon"),
|
if (schedule.Find(NS_LITERAL_STRING("icon"), PR_TRUE) != -1)
|
||||||
schedule,
|
|
||||||
CaseInsensitiveCompare))
|
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIRDFLiteral> statusLiteral;
|
nsCOMPtr<nsIRDFLiteral> statusLiteral;
|
||||||
if (NS_SUCCEEDED(rv = gRDF->GetLiteral(NS_LITERAL_STRING("new").get(), getter_AddRefs(statusLiteral))))
|
if (NS_SUCCEEDED(rv = gRDF->GetLiteral(NS_LITERAL_STRING("new").get(), getter_AddRefs(statusLiteral))))
|
||||||
|
@ -2321,9 +2351,7 @@ nsBookmarksService::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
|
||||||
}
|
}
|
||||||
|
|
||||||
// play a sound?
|
// play a sound?
|
||||||
if (FindInReadable(NS_LITERAL_STRING("sound"),
|
if (schedule.Find(NS_LITERAL_STRING("sound"), PR_TRUE) != -1)
|
||||||
schedule,
|
|
||||||
CaseInsensitiveCompare))
|
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsISound> soundInterface =
|
nsCOMPtr<nsISound> soundInterface =
|
||||||
do_CreateInstance("@mozilla.org/sound;1", &rv);
|
do_CreateInstance("@mozilla.org/sound;1", &rv);
|
||||||
|
@ -2337,9 +2365,7 @@ nsBookmarksService::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
|
||||||
PRBool openURLFlag = PR_FALSE;
|
PRBool openURLFlag = PR_FALSE;
|
||||||
|
|
||||||
// show an alert?
|
// show an alert?
|
||||||
if (FindInReadable(NS_LITERAL_STRING("alert"),
|
if (schedule.Find(NS_LITERAL_STRING("alert"), PR_TRUE) != -1)
|
||||||
schedule,
|
|
||||||
CaseInsensitiveCompare))
|
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIPrompt> prompter;
|
nsCOMPtr<nsIPrompt> prompter;
|
||||||
NS_QueryNotificationCallbacks(channel, prompter);
|
NS_QueryNotificationCallbacks(channel, prompter);
|
||||||
|
@ -2412,9 +2438,7 @@ nsBookmarksService::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
|
||||||
|
|
||||||
// open the URL in a new window?
|
// open the URL in a new window?
|
||||||
if ((openURLFlag == PR_TRUE) ||
|
if ((openURLFlag == PR_TRUE) ||
|
||||||
FindInReadable(NS_LITERAL_STRING("open"),
|
schedule.Find(NS_LITERAL_STRING("open"), PR_TRUE) != -1)
|
||||||
schedule,
|
|
||||||
CaseInsensitiveCompare))
|
|
||||||
{
|
{
|
||||||
if (NS_SUCCEEDED(rv))
|
if (NS_SUCCEEDED(rv))
|
||||||
{
|
{
|
||||||
|
@ -2710,9 +2734,8 @@ nsBookmarksService::Compare(const void* aElement1, const void* aElement2, void*
|
||||||
&result);
|
&result);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = ::Compare(nsDependentString(value1),
|
result = nsDependentString(value1).Compare(nsDependentString(value2),
|
||||||
nsDependentString(value2),
|
CaseInsensitiveCompare);
|
||||||
CaseInsensitiveCompare);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result * sortInfo->mDirection;
|
return result * sortInfo->mDirection;
|
||||||
|
@ -3847,7 +3870,7 @@ nsBookmarksService::ParseFavoritesFolder(nsIFile* aDirectory, nsIRDFResource* aP
|
||||||
PRInt32 lnkExtStart = bookmarkName.Length() - lnkExt.Length();
|
PRInt32 lnkExtStart = bookmarkName.Length() - lnkExt.Length();
|
||||||
if (StringEndsWith(bookmarkName, lnkExt,
|
if (StringEndsWith(bookmarkName, lnkExt,
|
||||||
CaseInsensitiveCompare))
|
CaseInsensitiveCompare))
|
||||||
bookmarkName.Truncate(lnkExtStart);
|
bookmarkName.SetLength(lnkExtStart);
|
||||||
|
|
||||||
nsCOMPtr<nsIRDFResource> bookmark;
|
nsCOMPtr<nsIRDFResource> bookmark;
|
||||||
// NS_GetURLSpecFromFile on Windows returns url-escaped URL in
|
// NS_GetURLSpecFromFile on Windows returns url-escaped URL in
|
||||||
|
@ -3878,7 +3901,7 @@ nsBookmarksService::ParseFavoritesFolder(nsIFile* aDirectory, nsIRDFResource* aP
|
||||||
nsCAutoString extension;
|
nsCAutoString extension;
|
||||||
|
|
||||||
url->GetFileExtension(extension);
|
url->GetFileExtension(extension);
|
||||||
if (!extension.LowerCaseEqualsLiteral("url"))
|
if (!extension.Equals(NS_LITERAL_CSTRING("url"), CaseInsensitiveCompare))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
nsAutoString name(Substring(bookmarkName, 0,
|
nsAutoString name(Substring(bookmarkName, 0,
|
||||||
|
@ -4097,7 +4120,7 @@ nsBookmarksService::ProcessCachedBookmarkIcon(nsIRDFResource* aSource,
|
||||||
// if we have a new icon URL, save it away into our internal graph
|
// if we have a new icon URL, save it away into our internal graph
|
||||||
if (iconURL)
|
if (iconURL)
|
||||||
{
|
{
|
||||||
LossyCopyUTF16toASCII(iconURL, path);
|
LossyCopyUTF16toASCII(nsDependentString(iconURL), path);
|
||||||
|
|
||||||
nsCOMPtr<nsIRDFLiteral> iconLiteral;
|
nsCOMPtr<nsIRDFLiteral> iconLiteral;
|
||||||
if (NS_FAILED(rv = gRDF->GetLiteral(iconURL, getter_AddRefs(iconLiteral))))
|
if (NS_FAILED(rv = gRDF->GetLiteral(iconURL, getter_AddRefs(iconLiteral))))
|
||||||
|
@ -4128,7 +4151,7 @@ nsBookmarksService::ProcessCachedBookmarkIcon(nsIRDFResource* aSource,
|
||||||
const PRUnichar *uni = nsnull;
|
const PRUnichar *uni = nsnull;
|
||||||
tempLiteral->GetValueConst(&uni);
|
tempLiteral->GetValueConst(&uni);
|
||||||
if (uni)
|
if (uni)
|
||||||
LossyCopyUTF16toASCII(uni, path);
|
LossyCopyUTF16toASCII(nsDependentString(uni), path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5532,7 +5555,7 @@ nsBookmarksService::WriteBookmarksContainer(nsIRDFDataSource *ds,
|
||||||
const PRUnichar *title = nsnull;
|
const PRUnichar *title = nsnull;
|
||||||
if (NS_SUCCEEDED(rv = nameLiteral->GetValueConst(&title)))
|
if (NS_SUCCEEDED(rv = nameLiteral->GetValueConst(&title)))
|
||||||
{
|
{
|
||||||
CopyUTF16toUTF8(title, name);
|
CopyUTF16toUTF8(nsDependentString(title), name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5605,12 +5628,9 @@ nsBookmarksService::WriteBookmarksContainer(nsIRDFDataSource *ds,
|
||||||
if (!name.IsEmpty())
|
if (!name.IsEmpty())
|
||||||
{
|
{
|
||||||
// see bug #65098
|
// see bug #65098
|
||||||
char *escapedAttrib = nsEscapeHTML(name.get());
|
EscapeHTML(name);
|
||||||
if (escapedAttrib)
|
|
||||||
{
|
rv |= strm->Write(name.get(), name.Length(), &dummy);
|
||||||
rv |= strm->Write(escapedAttrib, strlen(escapedAttrib), &dummy);
|
|
||||||
NS_Free(escapedAttrib);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
rv |= strm->Write(kCloseH3, sizeof(kCloseH3)-1, &dummy);
|
rv |= strm->Write(kCloseH3, sizeof(kCloseH3)-1, &dummy);
|
||||||
|
|
||||||
|
@ -5703,15 +5723,10 @@ nsBookmarksService::WriteBookmarksContainer(nsIRDFDataSource *ds,
|
||||||
{
|
{
|
||||||
// Note: we escape the title due to security issues;
|
// Note: we escape the title due to security issues;
|
||||||
// see bug # 13197 for details
|
// see bug # 13197 for details
|
||||||
char *escapedAttrib = nsEscapeHTML(name.get());
|
EscapeHTML(name);
|
||||||
if (escapedAttrib)
|
|
||||||
{
|
rv |= strm->Write(name.get(), name.Length(),
|
||||||
rv |= strm->Write(escapedAttrib,
|
&dummy);
|
||||||
strlen(escapedAttrib),
|
|
||||||
&dummy);
|
|
||||||
NS_Free(escapedAttrib);
|
|
||||||
escapedAttrib = nsnull;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rv |= strm->Write(kAClose, sizeof(kAClose)-1, &dummy);
|
rv |= strm->Write(kAClose, sizeof(kAClose)-1, &dummy);
|
||||||
|
@ -5868,38 +5883,34 @@ nsBookmarksService::WriteBookmarkProperties(nsIRDFDataSource *ds,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *attribute = ToNewUTF8String(literalString);
|
nsCAutoString attribute;
|
||||||
if (nsnull != attribute)
|
CopyUTF16toUTF8(literalString, attribute);
|
||||||
|
|
||||||
|
if (isFirst == PR_FALSE)
|
||||||
{
|
{
|
||||||
if (isFirst == PR_FALSE)
|
rv |= strm->Write(kSpaceStr, sizeof(kSpaceStr)-1, &dummy);
|
||||||
{
|
}
|
||||||
rv |= strm->Write(kSpaceStr, sizeof(kSpaceStr)-1, &dummy);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (property == kNC_Description)
|
if (property == kNC_Description)
|
||||||
|
{
|
||||||
|
if (!literalString.IsEmpty())
|
||||||
{
|
{
|
||||||
if (!literalString.IsEmpty())
|
EscapeHTML(attribute);
|
||||||
|
|
||||||
|
if (NS_SUCCEEDED(rv))
|
||||||
{
|
{
|
||||||
char *escapedAttrib = nsEscapeHTML(attribute);
|
rv |= strm->Write(htmlAttrib, strlen(htmlAttrib), &dummy);
|
||||||
if (escapedAttrib)
|
rv |= strm->Write(attribute.get(),
|
||||||
{
|
attribute.Length(), &dummy);
|
||||||
rv |= strm->Write(htmlAttrib, strlen(htmlAttrib), &dummy);
|
rv |= strm->Write(kNL, sizeof(kNL)-1, &dummy);
|
||||||
rv |= strm->Write(escapedAttrib, strlen(escapedAttrib), &dummy);
|
|
||||||
rv |= strm->Write(kNL, sizeof(kNL)-1, &dummy);
|
|
||||||
|
|
||||||
NS_Free(escapedAttrib);
|
|
||||||
escapedAttrib = nsnull;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
rv |= strm->Write(htmlAttrib, strlen(htmlAttrib), &dummy);
|
{
|
||||||
rv |= strm->Write(attribute, strlen(attribute), &dummy);
|
rv |= strm->Write(htmlAttrib, strlen(htmlAttrib), &dummy);
|
||||||
rv |= strm->Write(kQuoteStr, sizeof(kQuoteStr)-1, &dummy);
|
rv |= strm->Write(attribute.get(), attribute.Length(), &dummy);
|
||||||
}
|
rv |= strm->Write(kQuoteStr, sizeof(kQuoteStr)-1, &dummy);
|
||||||
NS_Free(attribute);
|
|
||||||
attribute = nsnull;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче