Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
nsBookmarksService Class Reference

#include <nsBookmarksService.h>

Collaboration diagram for nsBookmarksService:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsBookmarksService ()
virtual ~nsBookmarksService ()
nsresult Init ()
NS_DECL_ISUPPORTS
NS_DECL_NSIBOOKMARKSSERVICE
NS_IMETHOD 
GetURI (char **uri)
NS_IMETHOD GetSource (nsIRDFResource *property, nsIRDFNode *target, PRBool tv, nsIRDFResource **source)
NS_IMETHOD GetSources (nsIRDFResource *property, nsIRDFNode *target, PRBool tv, nsISimpleEnumerator **sources)
NS_IMETHOD GetTarget (nsIRDFResource *source, nsIRDFResource *property, PRBool tv, nsIRDFNode **target)
NS_IMETHOD GetTargets (nsIRDFResource *source, nsIRDFResource *property, PRBool tv, nsISimpleEnumerator **targets)
NS_IMETHOD Assert (nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue)
NS_IMETHOD Unassert (nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget)
NS_IMETHOD Change (nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aOldTarget, nsIRDFNode *aNewTarget)
NS_IMETHOD Move (nsIRDFResource *aOldSource, nsIRDFResource *aNewSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget)
NS_IMETHOD HasAssertion (nsIRDFResource *source, nsIRDFResource *property, nsIRDFNode *target, PRBool tv, PRBool *hasAssertion)
NS_IMETHOD AddObserver (nsIRDFObserver *aObserver)
NS_IMETHOD RemoveObserver (nsIRDFObserver *aObserver)
NS_IMETHOD HasArcIn (nsIRDFNode *aNode, nsIRDFResource *aArc, PRBool *_retval)
NS_IMETHOD HasArcOut (nsIRDFResource *aSource, nsIRDFResource *aArc, PRBool *_retval)
NS_IMETHOD ArcLabelsIn (nsIRDFNode *node, nsISimpleEnumerator **labels)
NS_IMETHOD ArcLabelsOut (nsIRDFResource *source, nsISimpleEnumerator **labels)
NS_IMETHOD GetAllResources (nsISimpleEnumerator **aResult)
NS_IMETHOD GetAllCmds (nsIRDFResource *source, nsISimpleEnumerator **commands)
NS_IMETHOD IsCommandEnabled (nsISupportsArray *aSources, nsIRDFResource *aCommand, nsISupportsArray *aArguments, PRBool *aResult)
NS_IMETHOD DoCommand (nsISupportsArray *aSources, nsIRDFResource *aCommand, nsISupportsArray *aArguments)
NS_IMETHOD BeginUpdateBatch ()
NS_IMETHOD EndUpdateBatch ()

Protected Member Functions

nsresult ExamineBookmarkSchedule (nsIRDFResource *theBookmark, PRBool &examineFlag)
nsresult GetBookmarkToPing (nsIRDFResource **theBookmark)
nsresult EnsureBookmarksFile ()
nsresult WriteBookmarks (nsIFile *bookmarksFile, nsIRDFDataSource *ds, nsIRDFResource *root)
nsresult WriteBookmarksContainer (nsIRDFDataSource *ds, nsIOutputStream *strm, nsIRDFResource *container, PRInt32 level, nsCOMArray< nsIRDFResource > &parentArray)
nsresult SerializeBookmarks (nsIURI *aURI)
nsresult GetTextForNode (nsIRDFNode *aNode, nsString &aResult)
nsresult GetSynthesizedType (nsIRDFResource *aNode, nsIRDFNode **aType)
nsresult UpdateBookmarkLastModifiedDate (nsIRDFResource *aSource)
nsresult WriteBookmarkProperties (nsIRDFDataSource *ds, nsIOutputStream *strm, nsIRDFResource *node, nsIRDFResource *property, const char *htmlAttrib, PRBool isFirst)
PRBool CanAccept (nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget)
nsresult getArgumentN (nsISupportsArray *arguments, nsIRDFResource *res, PRInt32 offset, nsIRDFNode **argValue)
nsresult insertBookmarkItem (nsIRDFResource *src, nsISupportsArray *aArguments, nsIRDFResource *objType)
 Inserts a bookmark item of the given type adjacent to the node specified with aRelativeNode.
nsresult deleteBookmarkItem (nsIRDFResource *src, nsISupportsArray *aArguments, PRInt32 parentArgIndex)
nsresult setFolderHint (nsIRDFResource *src, nsIRDFResource *objType)
nsresult getFolderViaHint (nsIRDFResource *src, PRBool fallbackFlag, nsIRDFResource **folder)
nsresult importBookmarks (nsISupportsArray *aArguments)
nsresult exportBookmarks (nsISupportsArray *aArguments)
nsresult ProcessCachedBookmarkIcon (nsIRDFResource *aSource, const PRUnichar *iconURL, nsIRDFNode **aTarget)
void AnnotateBookmarkSchedule (nsIRDFResource *aSource, PRBool scheduleFlag)
nsresult InsertResource (nsIRDFResource *aResource, nsIRDFResource *aParentFolder, PRInt32 aIndex)
nsresult getLocaleString (const char *key, nsString &str)
nsresult Sort (nsIRDFResource *aFolder, nsIRDFResource *aProperty, PRInt32 aDirection, PRBool aFoldersFirst, PRBool aRecurse)
nsresult GetURLFromResource (nsIRDFResource *aResource, nsAString &aURL)
nsresult CopyResource (nsIRDFResource *aOldResource, nsIRDFResource *aNewResource)
nsresult SetNewPersonalToolbarFolder (nsIRDFResource *aFolder)
nsresult LoadBookmarks ()
nsresult initDatasource ()

Static Protected Member Functions

static void FireTimer (nsITimer *aTimer, void *aClosure)
static int PR_CALLBACK Compare (const void *aElement1, const void *aElement2, void *aData)

Protected Attributes

nsIRDFDataSourcemInner
nsCOMPtr< nsIRDFResourcebusyResource
nsCOMArray< nsIRDFObservermObservers
nsCOMPtr< nsIStringBundlemBundle
nsCOMPtr< nsITimermTimer
nsCOMPtr< nsIIOServicemNetService
nsCOMPtr< nsICacheServicemCacheService
nsCOMPtr< nsICacheSessionmCacheSession
nsCOMPtr< nsITransactionManagermTransactionManager
nsCOMPtr< nsILocalFilemBookmarksFile
PRUint32 htmlSize
PRInt32 mUpdateBatchNest
nsXPIDLString mPersonalToolbarName
nsXPIDLString mBookmarksRootName
PRBool mDirty
PRBool mBrowserIcons
PRBool mAlwaysLoadIcons
PRBool busySchedule

Detailed Description

Definition at line 71 of file nsBookmarksService.h.


Constructor & Destructor Documentation

Definition at line 1597 of file nsBookmarksService.cpp.

                                       :
    mInner(nsnull),
    mUpdateBatchNest(0),
    mDirty(PR_FALSE)

#if defined(XP_MAC) || defined(XP_MACOSX)
    ,mIEFavoritesAvailable(PR_FALSE)
#endif
{ }

Definition at line 1607 of file nsBookmarksService.cpp.

{
    if (mTimer)
    {
        // be sure to cancel the timer, as it holds a
        // weak reference back to nsBookmarksService
        mTimer->Cancel();
        mTimer = nsnull;
    }

    // Unregister ourselves from the RDF service
    if (gRDF)
        gRDF->UnregisterDataSource(this);

    // Note: can't flush in the DTOR, as the RDF service
    // has probably already been destroyed
    // Flush();
    bm_ReleaseGlobals();
    NS_IF_RELEASE(mInner);
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 4325 of file nsBookmarksService.cpp.

{
    if (! aObserver)
        return NS_ERROR_NULL_POINTER;

    if (! mObservers.AppendObject(aObserver)) {
        return NS_ERROR_FAILURE;
    }
    
    return NS_OK;
}

Here is the call graph for this function:

void nsBookmarksService::AnnotateBookmarkSchedule ( nsIRDFResource aSource,
PRBool  scheduleFlag 
) [protected]

Definition at line 4204 of file nsBookmarksService.cpp.

{
    if (scheduleFlag)
    {
        PRBool exists = PR_FALSE;
        if (NS_SUCCEEDED(mInner->HasAssertion(aSource, kWEB_ScheduleActive,
                                              kTrueLiteral, PR_TRUE, &exists)) && (!exists))
        {
            (void)mInner->Assert(aSource, kWEB_ScheduleActive, kTrueLiteral, PR_TRUE);
        }
    }
    else
    {
        (void)mInner->Unassert(aSource, kWEB_ScheduleActive, kTrueLiteral);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 289 of file nsBookmarksService.h.

    {
        return mInner->ArcLabelsIn(node, labels);
    }

Here is the call graph for this function:

Definition at line 4369 of file nsBookmarksService.cpp.

{
#if defined(XP_WIN) || defined(XP_MAC) || defined(XP_MACOSX)
    HandleSystemBookmarks(source);
#endif

    return mInner->ArcLabelsOut(source, labels);
}

Here is the call graph for this function:

NS_IMETHODIMP nsBookmarksService::Assert ( nsIRDFResource aSource,
nsIRDFResource aProperty,
nsIRDFNode aTarget,
PRBool  aTruthValue 
)

Definition at line 4222 of file nsBookmarksService.cpp.

{
    nsresult rv = NS_RDF_ASSERTION_REJECTED;

    if (CanAccept(aSource, aProperty, aTarget))
    {
        rv = mInner->Assert(aSource, aProperty, aTarget, aTruthValue);
        if (NS_FAILED(rv))
            return rv;

        UpdateBookmarkLastModifiedDate(aSource);
            
        if (aProperty == kWEB_Schedule) {
              AnnotateBookmarkSchedule(aSource, PR_TRUE);
        }
    }

    return rv;
}

Here is the call graph for this function:

Definition at line 312 of file nsBookmarksService.h.

                                  {
        return mInner->BeginUpdateBatch();
    }

Here is the caller graph for this function:

PRBool nsBookmarksService::CanAccept ( nsIRDFResource aSource,
nsIRDFResource aProperty,
nsIRDFNode aTarget 
) [protected]

Definition at line 5916 of file nsBookmarksService.cpp.

{
    nsresult    rv;
    PRBool      isBookmarkedFlag = PR_FALSE, canAcceptFlag = PR_FALSE, isOrdinal;

    if (NS_SUCCEEDED(rv = IsBookmarkedResource(aSource, &isBookmarkedFlag)) &&
        (isBookmarkedFlag == PR_TRUE) &&
        (NS_SUCCEEDED(rv = gRDFC->IsOrdinalProperty(aProperty, &isOrdinal))))
    {
        if (isOrdinal == PR_TRUE)
        {
            canAcceptFlag = PR_TRUE;
        }
        else if ((aProperty == kNC_Description) ||
             (aProperty == kNC_Name) ||
             (aProperty == kNC_ShortcutURL) ||
             (aProperty == kNC_URL) ||
             (aProperty == kWEB_LastModifiedDate) ||
             (aProperty == kWEB_LastVisitDate) ||
             (aProperty == kNC_BookmarkAddDate) ||
             (aProperty == kRDF_nextVal) ||
             (aProperty == kRDF_type) ||
             (aProperty == kWEB_Schedule))
        {
            canAcceptFlag = PR_TRUE;
        }
    }
    return canAcceptFlag;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsBookmarksService::Change ( nsIRDFResource aSource,
nsIRDFResource aProperty,
nsIRDFNode aOldTarget,
nsIRDFNode aNewTarget 
)

Definition at line 4268 of file nsBookmarksService.cpp.

{
    nsresult rv = NS_RDF_ASSERTION_REJECTED;

    if (CanAccept(aSource, aProperty, aNewTarget)) {
        rv = mInner->Change(aSource, aProperty, aOldTarget, aNewTarget);
        if (NS_FAILED(rv))
            return rv;

        UpdateBookmarkLastModifiedDate(aSource);

        if (aProperty == kWEB_Schedule) {
            AnnotateBookmarkSchedule(aSource, PR_TRUE);
        }
    }

    return rv;
}

Here is the call graph for this function:

int nsBookmarksService::Compare ( const void aElement1,
const void aElement2,
void aData 
) [static, protected]

Definition at line 2663 of file nsBookmarksService.cpp.

{
    const ElementInfo* elementInfo1 =
      NS_STATIC_CAST(ElementInfo*, NS_CONST_CAST(void*, aElement1));
    const ElementInfo* elementInfo2 =
      NS_STATIC_CAST(ElementInfo*, NS_CONST_CAST(void*, aElement2));
    SortInfo* sortInfo = (SortInfo*)aData;

    if (sortInfo->mFoldersFirst) {
        if (elementInfo1->mIsFolder) {
            if (!elementInfo2->mIsFolder) {
                return -1;
            }
        }
        else {
            if (elementInfo2->mIsFolder) {
                return 1;
            }
        }
    }
 
    PRInt32 result = 0;
 
    nsIRDFNode* node1 = elementInfo1->mNode;
    nsIRDFNode* node2 = elementInfo2->mNode;
 
    // Literals?
    nsCOMPtr<nsIRDFLiteral> literal1 = do_QueryInterface(node1);
    if (literal1) {
        nsCOMPtr<nsIRDFLiteral> literal2 = do_QueryInterface(node2);
        if (literal2) {
            const PRUnichar* value1;
            literal1->GetValueConst(&value1);
            const PRUnichar* value2;
            literal2->GetValueConst(&value2);

            if (gCollation) {
                gCollation->CompareString(nsICollation::kCollationCaseInSensitive,
                                          nsDependentString(value1),
                                          nsDependentString(value2),
                                          &result);
            }
            else {
                result = ::Compare(nsDependentString(value1),
                                   nsDependentString(value2),
                                   nsCaseInsensitiveStringComparator());
            }

            return result * sortInfo->mDirection;
        }
    }
 
    // Dates?
    nsCOMPtr<nsIRDFDate> date1 = do_QueryInterface(node1);
    if (date1) {
        nsCOMPtr<nsIRDFDate> date2 = do_QueryInterface(node2);
        if (date2) {
            PRTime value1;
            date1->GetValue(&value1);
            PRTime value2;
            date2->GetValue(&value2);

            PRInt64 delta;
            LL_SUB(delta, value1, value2);

            if (LL_IS_ZERO(delta))
                result = 0;
            else if (LL_GE_ZERO(delta))
                result = 1;
            else
                result = -1;

            return result * sortInfo->mDirection;
        }
    }

    // Ack! Apples & oranges.
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsBookmarksService::CopyResource ( nsIRDFResource aOldResource,
nsIRDFResource aNewResource 
) [protected]

Definition at line 2929 of file nsBookmarksService.cpp.

{
    // Make all arcs coming out of aOldResource also come out of
    // aNewResource. Wallop any previous values.
    nsCOMPtr<nsISimpleEnumerator> arcsOut;
    nsresult rv = mInner->ArcLabelsOut(aOldResource, getter_AddRefs(arcsOut));
    if (NS_FAILED(rv))
        return rv;

    while (1) {
        PRBool hasMoreArcsOut;
        rv = arcsOut->HasMoreElements(&hasMoreArcsOut);
        if (NS_FAILED(rv))
            return rv;

        if (!hasMoreArcsOut)
            break;

        nsCOMPtr<nsISupports> supports;
        rv = arcsOut->GetNext(getter_AddRefs(supports));
        if (NS_FAILED(rv))
            return rv;

        nsCOMPtr<nsIRDFResource> property = do_QueryInterface(supports);
        if (!property)
            return NS_ERROR_UNEXPECTED;

        nsCOMPtr<nsIRDFNode> oldvalue;
        rv = mInner->GetTarget(aNewResource, property, PR_TRUE,
                               getter_AddRefs(oldvalue));
        if (NS_FAILED(rv))
            return rv;

        nsCOMPtr<nsIRDFNode> newvalue;
        rv = mInner->GetTarget(aOldResource, property, PR_TRUE,
                               getter_AddRefs(newvalue));
        if (NS_FAILED(rv))
            return rv;

        if (oldvalue) {
            if (newvalue) {
                 rv = mInner->Change(aNewResource, property, oldvalue, newvalue);
            }
            else {
                 rv = mInner->Unassert(aNewResource, property, oldvalue);
            }
        }
        else if (newvalue) {
            rv = mInner->Assert(aNewResource, property, newvalue, PR_TRUE);
        }

        if (NS_FAILED(rv))
            return rv;
    }

    // Make all arcs pointing to aOldResource now point to aNewResource.
    nsCOMPtr<nsISimpleEnumerator> arcsIn;
    rv = mInner->ArcLabelsIn(aOldResource, getter_AddRefs(arcsIn));
    if (NS_FAILED(rv))
        return rv;
                                                                                
    while (1) {
        PRBool hasMoreArcsIn;
        rv = arcsIn->HasMoreElements(&hasMoreArcsIn);
        if (NS_FAILED(rv))
            return rv;

        if (!hasMoreArcsIn)
            break;

        nsCOMPtr<nsISupports> supports;
        rv = arcsIn->GetNext(getter_AddRefs(supports));
        if (NS_FAILED(rv))
            return rv;
                                                                                
        nsCOMPtr<nsIRDFResource> property = do_QueryInterface(supports);
        if (!property)
            return NS_ERROR_UNEXPECTED;

        nsCOMPtr<nsISimpleEnumerator> sources;
        rv = GetSources(property, aOldResource, PR_TRUE,
                        getter_AddRefs(sources));
        if (NS_FAILED(rv))
            return rv;

        while (1) {
            PRBool hasMoreSrcs;
            rv = sources->HasMoreElements(&hasMoreSrcs);
            if (NS_FAILED(rv))
                return rv;

            if (!hasMoreSrcs)
                break;

            nsCOMPtr<nsISupports> supports;
            rv = sources->GetNext(getter_AddRefs(supports));
            if (NS_FAILED(rv))
                return rv;

            nsCOMPtr<nsIRDFResource> source = do_QueryInterface(supports);
            if (!source)
                return NS_ERROR_UNEXPECTED;

            rv = mInner->Change(source, property, aOldResource, aNewResource);
            if (NS_FAILED(rv))
                return rv;
        }
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsBookmarksService::deleteBookmarkItem ( nsIRDFResource src,
nsISupportsArray aArguments,
PRInt32  parentArgIndex 
) [protected]

Definition at line 4633 of file nsBookmarksService.cpp.

{
    nsresult            rv;

    nsCOMPtr<nsIRDFNode>        aNode;
    if (NS_FAILED(rv = getArgumentN(aArguments, kNC_Parent,
            parentArgIndex, getter_AddRefs(aNode))))
        return rv;
    nsCOMPtr<nsIRDFResource>    argParent = do_QueryInterface(aNode);
    if (!argParent) return NS_ERROR_NO_INTERFACE;

    nsCOMPtr<nsIRDFContainer> container =
            do_CreateInstance(kRDFContainerCID, &rv);
    if (NS_FAILED(rv))
        return rv;
    if (NS_FAILED(rv = container->Init(this, argParent)))
        return rv;

    if (NS_FAILED(rv = container->RemoveElement(src, PR_TRUE)))
        return rv;

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4838 of file nsBookmarksService.cpp.

{
    nsresult        rv = NS_OK;
    PRInt32         loop;
    PRUint32        numSources;
    if (NS_FAILED(rv = aSources->Count(&numSources)))   return rv;
    if (numSources < 1)
    {
        return NS_ERROR_ILLEGAL_VALUE;
    }

    // Note: some commands only run once (instead of looping over selection);
    //       if that's the case, be sure to "break" (if success) so that "mDirty"
    //       is set (and "bookmarks.html" will be flushed out shortly afterwards)

    for (loop=((PRInt32)numSources)-1; loop>=0; loop--)
    {
        nsCOMPtr<nsIRDFResource> src = do_QueryElementAt(aSources, loop, &rv);
        if (!src) return rv;

        if (aCommand == kNC_BookmarkCommand_NewBookmark)
        {
            rv = insertBookmarkItem(src, aArguments, kNC_Bookmark);
            if (NS_FAILED(rv))  return rv;
            break;
        }
        else if (aCommand == kNC_BookmarkCommand_NewFolder)
        {
            rv = insertBookmarkItem(src, aArguments, kNC_Folder);
            if (NS_FAILED(rv))  return rv;
            break;
        }
        else if (aCommand == kNC_BookmarkCommand_NewSeparator)
        {
            rv = insertBookmarkItem(src, aArguments, kNC_BookmarkSeparator);
            if (NS_FAILED(rv))  return rv;
            break;
        }
        else if (aCommand == kNC_BookmarkCommand_DeleteBookmark ||
            aCommand == kNC_BookmarkCommand_DeleteBookmarkFolder ||
            aCommand == kNC_BookmarkCommand_DeleteBookmarkSeparator)
        {
            if (NS_FAILED(rv = deleteBookmarkItem(src, aArguments, loop)))
                return rv;
        }
        else if (aCommand == kNC_BookmarkCommand_SetNewBookmarkFolder)
        {
            rv = setFolderHint(src, kNC_NewBookmarkFolder);
            if (NS_FAILED(rv))  return rv;
            break;
        }
        else if (aCommand == kNC_BookmarkCommand_SetPersonalToolbarFolder)
        {
            rv = setFolderHint(src, kNC_PersonalToolbarFolder);
            if (NS_FAILED(rv))  return rv;
            break;
        }
        else if (aCommand == kNC_BookmarkCommand_SetNewSearchFolder)
        {
            rv = setFolderHint(src, kNC_NewSearchFolder);
            if (NS_FAILED(rv))  return rv;
            break;
        }
        else if (aCommand == kNC_BookmarkCommand_Import)
        {
            rv = importBookmarks(aArguments);
            if (NS_FAILED(rv))  return rv;
            break;
        }
        else if (aCommand == kNC_BookmarkCommand_Export)
        {
            rv = exportBookmarks(aArguments);
            if (NS_FAILED(rv))  return rv;
            break;
        }
    }

    mDirty = PR_TRUE;

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 316 of file nsBookmarksService.h.

                                {
        return mInner->EndUpdateBatch();
    }

Here is the caller graph for this function:

Definition at line 4991 of file nsBookmarksService.cpp.

{
    nsresult rv;

    // First we see if the user has set a pref for the location of the 
    // bookmarks file.
    nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
    if (NS_SUCCEEDED(rv))
    {
        nsCOMPtr<nsISupportsString> prefVal;
        rv = prefBranch->GetComplexValue("browser.bookmarks.file",
                                         NS_GET_IID(nsISupportsString),
                                         getter_AddRefs(prefVal));      
        if (NS_SUCCEEDED(rv))
        {
            nsAutoString bookmarksFile;
            prefVal->GetData(bookmarksFile); // more efficient than ToString
            rv = NS_NewLocalFile(bookmarksFile, PR_TRUE,
                                 getter_AddRefs(mBookmarksFile));

            if (NS_SUCCEEDED(rv))
            {
                return NS_OK;
            }
        }
    }


    // Otherwise, we look for bookmarks.html in the current profile
    // directory using the magic directory service.
    rv = NS_GetSpecialDirectory(NS_APP_BOOKMARKS_50_FILE, (nsIFile **)(nsILocalFile **)getter_AddRefs(mBookmarksFile));
    NS_ENSURE_SUCCESS(rv, rv);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsBookmarksService::ExamineBookmarkSchedule ( nsIRDFResource theBookmark,
PRBool examineFlag 
) [protected]

Definition at line 1800 of file nsBookmarksService.cpp.

{
    examineFlag = PR_FALSE;
    
    nsresult    rv = NS_OK;

    nsCOMPtr<nsIRDFNode>    scheduleNode;
    if (NS_FAILED(rv = mInner->GetTarget(theBookmark, kWEB_Schedule, PR_TRUE,
        getter_AddRefs(scheduleNode))) || (rv == NS_RDF_NO_VALUE))
        return rv;
    
    nsCOMPtr<nsIRDFLiteral> scheduleLiteral = do_QueryInterface(scheduleNode);
    if (!scheduleLiteral)   return NS_ERROR_NO_INTERFACE;
    
    const PRUnichar     *scheduleUni = nsnull;
    if (NS_FAILED(rv = scheduleLiteral->GetValueConst(&scheduleUni)))
        return rv;
    if (!scheduleUni)   return NS_ERROR_NULL_POINTER;

    nsAutoString        schedule(scheduleUni);
    if (schedule.Length() < 1)  return NS_ERROR_UNEXPECTED;

    // convert the current date/time from microseconds (PRTime) to seconds
    // Note: don't change now64, as its used later in the function
    PRTime      now64 = PR_Now(), temp64, million;
    LL_I2L(million, PR_USEC_PER_SEC);
    LL_DIV(temp64, now64, million);
    PRInt32     now32;
    LL_L2I(now32, temp64);

    PRExplodedTime  nowInfo;
    PR_ExplodeTime(now64, PR_LocalTimeParameters, &nowInfo);
    
    // XXX Do we need to do this?
    PR_NormalizeTime(&nowInfo, PR_LocalTimeParameters);

    nsAutoString    dayNum;
    dayNum.AppendInt(nowInfo.tm_wday, 10);

    // a schedule string has the following format:
    // Check Monday, Tuesday, and Friday | 9 AM thru 5 PM | every five minutes | change bookmark icon
    // 125|9-17|5|icon

    nsAutoString    notificationMethod;
    PRInt32     startHour = -1, endHour = -1, duration = -1;

    // should we be checking today?
    PRInt32     slashOffset;
    if ((slashOffset = schedule.FindChar(PRUnichar('|'))) >= 0)
    {
        nsAutoString    daySection;
        schedule.Left(daySection, slashOffset);
        schedule.Cut(0, slashOffset+1);
        if (daySection.Find(dayNum) >= 0)
        {
            // ok, we should be checking today.  Within hour range?
            if ((slashOffset = schedule.FindChar(PRUnichar('|'))) >= 0)
            {
                nsAutoString    hourRange;
                schedule.Left(hourRange, slashOffset);
                schedule.Cut(0, slashOffset+1);

                // now have the "hour-range" segment of the string
                // such as "9-17" or "9-12" from the examples above
                PRInt32     dashOffset;
                if ((dashOffset = hourRange.FindChar(PRUnichar('-'))) >= 1)
                {
                    nsAutoString    startStr, endStr;

                    hourRange.Right(endStr, hourRange.Length() - dashOffset - 1);
                    hourRange.Left(startStr, dashOffset);

                    PRInt32     errorCode2 = 0;
                    startHour = startStr.ToInteger(&errorCode2);
                    if (errorCode2) startHour = -1;
                    endHour = endStr.ToInteger(&errorCode2);
                    if (errorCode2) endHour = -1;
                    
                    if ((startHour >=0) && (endHour >=0))
                    {
                        if ((slashOffset = schedule.FindChar(PRUnichar('|'))) >= 0)
                        {
                            nsAutoString    durationStr;
                            schedule.Left(durationStr, slashOffset);
                            schedule.Cut(0, slashOffset+1);

                            // get duration
                            PRInt32     errorCode = 0;
                            duration = durationStr.ToInteger(&errorCode);
                            if (errorCode)  duration = -1;
                            
                            // what's left is the notification options
                            notificationMethod = schedule;
                        }
                    }
                }
            }
        }
    }
        

#ifdef  DEBUG_BOOKMARK_PING_OUTPUT
    char *methodStr = ToNewCString(notificationMethod);
    if (methodStr)
    {
        printf("Start Hour: %d    End Hour: %d    Duration: %d mins    Method: '%s'\n",
            startHour, endHour, duration, methodStr);
        delete [] methodStr;
        methodStr = nsnull;
    }
#endif

    if ((startHour <= nowInfo.tm_hour) && (endHour >= nowInfo.tm_hour) &&
        (duration >= 1) && (!notificationMethod.IsEmpty()))
    {
        // OK, we're with the start/end time range, check the duration
        // against the last time we've "pinged" the server (if ever)

        examineFlag = PR_TRUE;

        nsCOMPtr<nsIRDFNode>    pingNode;
        if (NS_SUCCEEDED(rv = mInner->GetTarget(theBookmark, kWEB_LastPingDate,
            PR_TRUE, getter_AddRefs(pingNode))) && (rv != NS_RDF_NO_VALUE))
        {
            nsCOMPtr<nsIRDFDate>    pingLiteral = do_QueryInterface(pingNode);
            if (pingLiteral)
            {
                PRInt64     lastPing;
                if (NS_SUCCEEDED(rv = pingLiteral->GetValue(&lastPing)))
                {
                    PRInt64     diff64, sixty;
                    LL_SUB(diff64, now64, lastPing);
                    
                    // convert from milliseconds to seconds
                    LL_DIV(diff64, diff64, million);
                    // convert from seconds to minutes
                    LL_I2L(sixty, 60L);
                    LL_DIV(diff64, diff64, sixty);

                    PRInt32     diff32;
                    LL_L2I(diff32, diff64);
                    if (diff32 < duration)
                    {
                        examineFlag = PR_FALSE;

#ifdef  DEBUG_BOOKMARK_PING_OUTPUT
                        printf("Skipping URL, its too soon.\n");
#endif
                    }
                }
            }
        }
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4793 of file nsBookmarksService.cpp.

{
    // look for #URL which is the file path to export
    nsCOMPtr<nsIRDFNode> node;
    nsresult rv = getArgumentN(aArguments, kNC_URL, 0, getter_AddRefs(node));
    NS_ENSURE_SUCCESS(rv, rv);
    nsCOMPtr<nsIRDFLiteral> literal = do_QueryInterface(node, &rv);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_NO_INTERFACE);
    const PRUnichar* pathUni = nsnull;
    literal->GetValueConst(&pathUni);
    NS_ENSURE_TRUE(pathUni, NS_ERROR_NULL_POINTER);

    // determine file type to export; default to HTML unless told otherwise
    const PRUnichar* format = EmptyString().get();
    rv = getArgumentN(aArguments, kRDF_type, 0, getter_AddRefs(node));
    if (NS_SUCCEEDED(rv))
    {
        literal = do_QueryInterface(node, &rv);
        NS_ENSURE_SUCCESS(rv, NS_ERROR_NO_INTERFACE);
        literal->GetValueConst(&format);
        NS_ENSURE_TRUE(format, NS_ERROR_NULL_POINTER);
    }

    nsCOMPtr<nsILocalFile> file;
    rv = NS_NewLocalFile(nsDependentString(pathUni), PR_TRUE, getter_AddRefs(file));
    NS_ENSURE_SUCCESS(rv, rv);

    if (NS_LITERAL_STRING("RDF").Equals(format, nsCaseInsensitiveStringComparator()))
    {
        nsCOMPtr<nsIURI> uri;
        nsresult rv = NS_NewFileURI(getter_AddRefs(uri), file);
        NS_ENSURE_SUCCESS(rv, rv);

        rv = SerializeBookmarks(uri);
    }
    else
    {
        // write 'em out
        rv = WriteBookmarks(file, mInner, kNC_BookmarksRoot);
    }

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsBookmarksService::FireTimer ( nsITimer aTimer,
void aClosure 
) [static, protected]

Definition at line 2016 of file nsBookmarksService.cpp.

{
    nsBookmarksService *bmks = NS_STATIC_CAST(nsBookmarksService *, aClosure);
    if (!bmks)  return;
    nsresult            rv;

    if (bmks->mDirty)
    {
        bmks->Flush();
    }

    if (bmks->busySchedule == PR_FALSE)
    {
        nsCOMPtr<nsIRDFResource>    bookmark;
        if (NS_SUCCEEDED(rv = bmks->GetBookmarkToPing(getter_AddRefs(bookmark))) && (bookmark))
        {
            bmks->busyResource = bookmark;

            nsAutoString url;
            rv = bmks->GetURLFromResource(bookmark, url);
            if (NS_FAILED(rv))
                return;

#ifdef  DEBUG_BOOKMARK_PING_OUTPUT
            printf("nsBookmarksService::FireTimer - Pinging '%s'\n",
                   NS_ConvertUCS2toUTF8(url).get());
#endif

            nsCOMPtr<nsIURI>    uri;
            if (NS_SUCCEEDED(rv = NS_NewURI(getter_AddRefs(uri), url)))
            {
                nsCOMPtr<nsIChannel>    channel;
                if (NS_SUCCEEDED(rv = NS_NewChannel(getter_AddRefs(channel), uri, nsnull)))
                {
                    channel->SetLoadFlags(nsIRequest::VALIDATE_ALWAYS);
                    nsCOMPtr<nsIHttpChannel>    httpChannel = do_QueryInterface(channel);
                    if (httpChannel)
                    {
                        bmks->htmlSize = 0;
                        httpChannel->SetRequestMethod(NS_LITERAL_CSTRING("HEAD"));
                        if (NS_SUCCEEDED(rv = channel->AsyncOpen(bmks, nsnull)))
                        {
                            bmks->busySchedule = PR_TRUE;
                        }
                    }
                }
            }
        }
    }
#ifdef  DEBUG_BOOKMARK_PING_OUTPUT
    else
    {
        printf("nsBookmarksService::FireTimer - busy pinging.\n");
    }
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4390 of file nsBookmarksService.cpp.

Here is the call graph for this function:

Definition at line 4380 of file nsBookmarksService.cpp.

{
#if defined(XP_WIN) || defined(XP_MAC) || defined(XP_MACOSX)
    HandleSystemBookmarks(kNC_SystemBookmarksStaticRoot);
#endif
  
    return mInner->GetAllResources(aResult);
}

Here is the call graph for this function:

nsresult nsBookmarksService::getArgumentN ( nsISupportsArray arguments,
nsIRDFResource res,
PRInt32  offset,
nsIRDFNode **  argValue 
) [protected]

Definition at line 4461 of file nsBookmarksService.cpp.

{
    nsresult        rv;
    PRUint32        loop, numArguments;

    *argValue = nsnull;

    if (NS_FAILED(rv = arguments->Count(&numArguments)))    return rv;

    // format is argument, value, argument, value, ... [you get the idea]
    // multiple arguments can be the same, by the way, thus the "offset"
    for (loop = 0; loop < numArguments; loop += 2)
    {
        nsCOMPtr<nsIRDFResource> src = do_QueryElementAt(arguments, loop, &rv);
        if (!src) return rv;
        
        if (src == res)
        {
            if (offset > 0)
            {
                --offset;
                continue;
            }

            nsCOMPtr<nsIRDFNode> val = do_QueryElementAt(arguments, loop + 1,
                                                         &rv);
            if (!val) return rv;

            *argValue = val;
            NS_ADDREF(*argValue);
            return NS_OK;
        }
    }
    return NS_ERROR_INVALID_ARG;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1957 of file nsBookmarksService.cpp.

{
    nsresult    rv = NS_OK;

    *theBookmark = nsnull;

    nsCOMPtr<nsISimpleEnumerator>   srcList;
    if (NS_FAILED(rv = GetSources(kWEB_ScheduleActive, kTrueLiteral, PR_TRUE, getter_AddRefs(srcList))))
        return rv;

    nsCOMPtr<nsISupportsArray>  bookmarkList;
    if (NS_FAILED(rv = NS_NewISupportsArray(getter_AddRefs(bookmarkList))))
        return rv;

    // build up a list of potential bookmarks to check
    PRBool  hasMoreSrcs = PR_TRUE;
    while(NS_SUCCEEDED(rv = srcList->HasMoreElements(&hasMoreSrcs))
        && (hasMoreSrcs == PR_TRUE))
    {
        nsCOMPtr<nsISupports>   aSrc;
        if (NS_FAILED(rv = srcList->GetNext(getter_AddRefs(aSrc))))
            break;
        nsCOMPtr<nsIRDFResource>    aSource = do_QueryInterface(aSrc);
        if (!aSource)   continue;

        // does the bookmark have a schedule, and if so,
        // are we within its bounds for checking the URL?

        PRBool  examineFlag = PR_FALSE;
        if (NS_FAILED(rv = ExamineBookmarkSchedule(aSource, examineFlag))
            || (examineFlag == PR_FALSE))   continue;

        bookmarkList->AppendElement(aSource);
    }

    // pick a random entry from the list of bookmarks to check
    PRUint32    numBookmarks;
    if (NS_SUCCEEDED(rv = bookmarkList->Count(&numBookmarks)) && (numBookmarks > 0))
    {
        PRInt32     randomNum;
        LL_L2I(randomNum, PR_Now());
        PRUint32    randomBookmark = (numBookmarks-1) % randomNum;

        nsCOMPtr<nsISupports>   iSupports;
        if (NS_SUCCEEDED(rv = bookmarkList->GetElementAt(randomBookmark,
            getter_AddRefs(iSupports))))
        {
            nsCOMPtr<nsIRDFResource>    aBookmark = do_QueryInterface(iSupports);
            if (aBookmark)
            {
                *theBookmark = aBookmark;
                NS_ADDREF(*theBookmark);
            }
        }
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsBookmarksService::getFolderViaHint ( nsIRDFResource src,
PRBool  fallbackFlag,
nsIRDFResource **  folder 
) [protected]

Definition at line 4710 of file nsBookmarksService.cpp.

{
    if (!folder)    return NS_ERROR_UNEXPECTED;
    *folder = nsnull;
    if (!objType)   return NS_ERROR_UNEXPECTED;

    nsresult            rv;
    nsCOMPtr<nsIRDFResource>    oldSource;
    if (NS_FAILED(rv = mInner->GetSource(kNC_FolderType, objType, PR_TRUE, getter_AddRefs(oldSource))))
        return rv;

    if ((rv != NS_RDF_NO_VALUE) && (oldSource))
    {
        PRBool isBookmarkedFlag = PR_FALSE;
        if (NS_SUCCEEDED(rv = IsBookmarkedResource(oldSource, &isBookmarkedFlag)) &&
            isBookmarkedFlag) {
            *folder = oldSource;
        }
    }

    // if we couldn't find a real "New Internet Search Folder", fallback to looking for
    // a "New Bookmark Folder", and if can't find that, then default to the bookmarks root
    if ((!(*folder)) && (fallbackFlag == PR_TRUE) && (objType == kNC_NewSearchFolder))
    {
        rv = getFolderViaHint(kNC_NewBookmarkFolder, fallbackFlag, folder);
    }

    if (!(*folder))
    {
        // fallback to some well-known defaults
        if (objType == kNC_NewBookmarkFolder || objType == kNC_NewSearchFolder)
        {
            *folder = kNC_BookmarksRoot;
        }
        else if (objType == kNC_PersonalToolbarFolder)
        {
            *folder = kNC_PersonalToolbarFolder;
        }
    }

    NS_IF_ADDREF(*folder);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsBookmarksService::getLocaleString ( const char *  key,
nsString str 
) [protected]

Definition at line 1779 of file nsBookmarksService.cpp.

{
    PRUnichar   *keyUni = nsnull;
    nsAutoString    keyStr;
    keyStr.AssignWithConversion(key);

    nsresult    rv = NS_RDF_NO_VALUE;
    if (mBundle && (NS_SUCCEEDED(rv = mBundle->GetStringFromName(keyStr.get(), &keyUni)))
        && (keyUni))
    {
        str = keyUni;
        NS_Free(keyUni);
    }
    else
    {
        str.Truncate();
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHOD nsBookmarksService::GetSource ( nsIRDFResource property,
nsIRDFNode target,
PRBool  tv,
nsIRDFResource **  source 
) [inline]

Definition at line 229 of file nsBookmarksService.h.

    {
        return mInner->GetSource(property, target, tv, source);
    }

Here is the call graph for this function:

NS_IMETHOD nsBookmarksService::GetSources ( nsIRDFResource property,
nsIRDFNode target,
PRBool  tv,
nsISimpleEnumerator **  sources 
) [inline]

Definition at line 237 of file nsBookmarksService.h.

    {
        return mInner->GetSources(property, target, tv, sources);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 3610 of file nsBookmarksService.cpp.

{
    *aType = nsnull;
    nsresult rv = mInner->GetTarget(aNode, kRDF_type, PR_TRUE, aType);
    if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE))
    {
        // if we didn't match anything in the graph, synthesize its type
        // (which is either a bookmark or a bookmark folder, since everything
        // else is annotated)
        PRBool isContainer = PR_FALSE;
        PRBool isBookmarkedFlag = PR_FALSE;
        (void)gRDFC->IsSeq(mInner, aNode, &isContainer);

        if (isContainer)
        {
            *aType =  kNC_Folder;
        }
        else if (NS_SUCCEEDED(rv = IsBookmarkedResource(aNode,
                                                        &isBookmarkedFlag)) && (isBookmarkedFlag == PR_TRUE))
        {
            *aType = kNC_Bookmark;
        }
#ifdef XP_BEOS
        else
        {
            //solution for BeOS - bookmarks are stored as file attributes. 
            *aType = kNC_URL;
        }
#endif
        NS_IF_ADDREF(*aType);
    }
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4005 of file nsBookmarksService.cpp.

{
    *aTarget = nsnull;

    nsresult    rv;

    if (aTruthValue && (aProperty == kRDF_type))
    {
        rv = GetSynthesizedType(aSource, aTarget);
        return rv;
    }
    else if (aTruthValue && isBookmarkCommand(aSource) && (aProperty == kNC_Name))
    {
        nsAutoString    name;
        if (aSource == kNC_BookmarkCommand_NewBookmark)
            getLocaleString("NewBookmark", name);
        else if (aSource == kNC_BookmarkCommand_NewFolder)
            getLocaleString("NewFolder", name);
        else if (aSource == kNC_BookmarkCommand_NewSeparator)
            getLocaleString("NewSeparator", name);
        else if (aSource == kNC_BookmarkCommand_DeleteBookmark)
            getLocaleString("DeleteBookmark", name);
        else if (aSource == kNC_BookmarkCommand_DeleteBookmarkFolder)
            getLocaleString("DeleteFolder", name);
        else if (aSource == kNC_BookmarkCommand_DeleteBookmarkSeparator)
            getLocaleString("DeleteSeparator", name);
        else if (aSource == kNC_BookmarkCommand_SetNewBookmarkFolder)
            getLocaleString("SetNewBookmarkFolder", name);
        else if (aSource == kNC_BookmarkCommand_SetPersonalToolbarFolder)
            getLocaleString("SetPersonalToolbarFolder", name);
        else if (aSource == kNC_BookmarkCommand_SetNewSearchFolder)
            getLocaleString("SetNewSearchFolder", name);
        else if (aSource == kNC_BookmarkCommand_Import)
            getLocaleString("Import", name);
        else if (aSource == kNC_BookmarkCommand_Export)
            getLocaleString("Export", name);

        if (!name.IsEmpty())
        {
            *aTarget = nsnull;
            nsCOMPtr<nsIRDFLiteral> literal;
            if (NS_FAILED(rv = gRDF->GetLiteral(name.get(), getter_AddRefs(literal))))
                return rv;
            *aTarget = literal;
            NS_IF_ADDREF(*aTarget);
            return rv;
        }
    }
    else if (aProperty == kNC_Icon)
    {
        rv = ProcessCachedBookmarkIcon(aSource, nsnull, aTarget);
        return rv;
    }

    rv = mInner->GetTarget(aSource, aProperty, aTruthValue, aTarget);
    return rv;
}

Here is the call graph for this function:

NS_IMETHOD nsBookmarksService::GetTargets ( nsIRDFResource source,
nsIRDFResource property,
PRBool  tv,
nsISimpleEnumerator **  targets 
) [inline]

Definition at line 250 of file nsBookmarksService.h.

    {
        return mInner->GetTargets(source, property, tv, targets);
    }

Here is the call graph for this function:

nsresult nsBookmarksService::GetTextForNode ( nsIRDFNode aNode,
nsString aResult 
) [protected]

Definition at line 5786 of file nsBookmarksService.cpp.

{
    nsresult        rv;
    nsIRDFResource  *resource;
    nsIRDFLiteral   *literal;
    nsIRDFDate      *dateLiteral;
    nsIRDFInt       *intLiteral;

    if (! aNode)
    {
        aResult.Truncate();
        rv = NS_OK;
    }
    else if (NS_SUCCEEDED(rv = aNode->QueryInterface(NS_GET_IID(nsIRDFResource), (void**) &resource)))
    {
        const char  *p = nsnull;
        if (NS_SUCCEEDED(rv = resource->GetValueConst( &p )) && (p))
        {
            aResult.AssignWithConversion(p);
        }
        NS_RELEASE(resource);
    }
    else if (NS_SUCCEEDED(rv = aNode->QueryInterface(NS_GET_IID(nsIRDFDate), (void**) &dateLiteral)))
    {
    PRInt64     theDate, million;
        if (NS_SUCCEEDED(rv = dateLiteral->GetValue( &theDate )))
        {
            LL_I2L(million, PR_USEC_PER_SEC);
            LL_DIV(theDate, theDate, million);          // convert from microseconds (PRTime) to seconds
            PRInt32     now32;
            LL_L2I(now32, theDate);
            aResult.Truncate();
            aResult.AppendInt(now32, 10);
        }
        NS_RELEASE(dateLiteral);
    }
    else if (NS_SUCCEEDED(rv = aNode->QueryInterface(NS_GET_IID(nsIRDFInt), (void**) &intLiteral)))
    {
        PRInt32     theInt;
        aResult.Truncate();
        if (NS_SUCCEEDED(rv = intLiteral->GetValue( &theInt )))
        {
            aResult.AppendInt(theInt, 10);
        }
        NS_RELEASE(intLiteral);
    }
    else if (NS_SUCCEEDED(rv = aNode->QueryInterface(NS_GET_IID(nsIRDFLiteral), (void**) &literal)))
    {
        const PRUnichar     *p = nsnull;
        if (NS_SUCCEEDED(rv = literal->GetValueConst( &p )) && (p))
        {
            aResult = p;
        }
        NS_RELEASE(literal);
    }
    else
    {
        NS_ERROR("not a resource or a literal");
        rv = NS_ERROR_UNEXPECTED;
    }

    return rv;
}

Here is the caller graph for this function:

Definition at line 3979 of file nsBookmarksService.cpp.

{
    *aURI = nsCRT::strdup("rdf:bookmarks");
    if (! *aURI)
        return NS_ERROR_OUT_OF_MEMORY;

    return NS_OK;
}
nsresult nsBookmarksService::GetURLFromResource ( nsIRDFResource aResource,
nsAString &  aURL 
) [protected]

Definition at line 2902 of file nsBookmarksService.cpp.

{
    NS_ENSURE_ARG(aResource);

    nsCOMPtr<nsIRDFNode> urlNode;
    nsresult rv = mInner->GetTarget(aResource, kNC_URL, PR_TRUE, getter_AddRefs(urlNode));
    if (NS_FAILED(rv))
        return rv;

    if (urlNode) {
        nsCOMPtr<nsIRDFLiteral> urlLiteral = do_QueryInterface(urlNode, &rv);
        if (NS_FAILED(rv))
            return rv;

        const PRUnichar* url = nsnull;
        rv = urlLiteral->GetValueConst(&url);
        if (NS_FAILED(rv))
            return rv;

        aURL.Assign(url);
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4349 of file nsBookmarksService.cpp.

{
#if defined(XP_WIN) || defined(XP_MAC) || defined(XP_MACOSX)
    HandleSystemBookmarks(aNode);
#endif

    return mInner->HasArcIn(aNode, aArc, _retval);
}

Definition at line 4359 of file nsBookmarksService.cpp.

{
#if defined(XP_WIN) || defined(XP_MAC) || defined(XP_MACOSX)
    HandleSystemBookmarks(aSource);
#endif
  
    return mInner->HasArcOut(aSource, aArc, _retval);
}
NS_IMETHODIMP nsBookmarksService::HasAssertion ( nsIRDFResource source,
nsIRDFResource property,
nsIRDFNode target,
PRBool  tv,
PRBool hasAssertion 
)

Definition at line 4311 of file nsBookmarksService.cpp.

{
#if defined(XP_WIN) || defined(XP_MAC) || defined(XP_MACOSX)
    HandleSystemBookmarks(source);
#endif

    return mInner->HasAssertion(source, property, target, tv, hasAssertion);
}

Here is the call graph for this function:

Definition at line 4756 of file nsBookmarksService.cpp.

{
    // look for #URL which is the file path to import
    nsresult rv;
    nsCOMPtr<nsIRDFNode> aNode;
    rv = getArgumentN(aArguments, kNC_URL, 0, getter_AddRefs(aNode));
    NS_ENSURE_SUCCESS(rv, rv);
    nsCOMPtr<nsIRDFLiteral> pathLiteral = do_QueryInterface(aNode, &rv);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_NO_INTERFACE);
    const PRUnichar *pathUni = nsnull;
    pathLiteral->GetValueConst(&pathUni);
    NS_ENSURE_TRUE(pathUni, NS_ERROR_NULL_POINTER);

    nsCOMPtr<nsILocalFile> file;
    rv = NS_NewLocalFile(nsDependentString(pathUni), PR_TRUE, getter_AddRefs(file));
    NS_ENSURE_SUCCESS(rv, rv);
    PRBool isFile;
    rv = file->IsFile(&isFile);
    NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && isFile, NS_ERROR_UNEXPECTED);

    // figure out where to add the imported bookmarks
    nsCOMPtr<nsIRDFResource> newBookmarkFolder;
    rv = getFolderViaHint(kNC_NewBookmarkFolder, PR_TRUE, 
                          getter_AddRefs(newBookmarkFolder));
    NS_ENSURE_SUCCESS(rv, rv);

    // read 'em in
    BookmarkParser parser;
    parser.Init(file, mInner, PR_TRUE);

    // Note: can't Begin|EndUpdateBatch() this as notifications are required
    parser.Parse(newBookmarkFolder, kNC_Bookmark);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1629 of file nsBookmarksService.cpp.

{
    nsresult rv;
    rv = bm_AddRefGlobals();
    if (NS_FAILED(rv))  return rv;

    mNetService = do_GetService(kIOServiceCID, &rv);
    if (NS_FAILED(rv))  return rv;

    // create cache service/session, ignoring errors
    mCacheService = do_GetService(kCacheServiceCID, &rv);
    if (NS_SUCCEEDED(rv))
    {
        rv = mCacheService->CreateSession("HTTP", nsICache::STORE_ANYWHERE,
            nsICache::STREAM_BASED, getter_AddRefs(mCacheSession));
    }

    mTransactionManager = do_CreateInstance(NS_TRANSACTIONMANAGER_CONTRACTID, &rv);
    if (NS_FAILED(rv)) return rv;

    /* create a URL for the string resource file */
    nsCOMPtr<nsIURI> uri;
    mNetService->NewURI(bookmark_properties, nsnull, nsnull,
                        getter_AddRefs(uri));
    if (uri)
    {
        /* create a bundle for the localization */
        nsCOMPtr<nsIStringBundleService> stringService =
                do_GetService(kStringBundleServiceCID);
        if (stringService)
        {
            nsCAutoString spec;
            uri->GetSpec(spec);
            if (!spec.IsEmpty())
            {
                stringService->CreateBundle(spec.get(), getter_AddRefs(mBundle));
            }
        }
    }

    nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
    if (NS_SUCCEEDED(rv))
    {
        // get browser icon prefs
        PRInt32 toolbarIcons = 0;
        prefBranch->GetIntPref("browser.chrome.load_toolbar_icons", &toolbarIcons);
        if (toolbarIcons > 0) {
              prefBranch->GetBoolPref("browser.chrome.site_icons", &mBrowserIcons);
              mAlwaysLoadIcons = (toolbarIcons > 1);
        } else
              mAlwaysLoadIcons = mBrowserIcons = PR_FALSE;
        
        // determine what the name of the Personal Toolbar Folder is...
        // first from user preference, then string bundle, then hard-coded default
        nsXPIDLCString prefValue;
        rv = prefBranch->GetCharPref("custtoolbar.personal_toolbar_folder", getter_Copies(prefValue));
        if (NS_SUCCEEDED(rv) && !prefValue.IsEmpty())
        {
            CopyUTF8toUTF16(prefValue, mPersonalToolbarName);
        }

        if (mPersonalToolbarName.IsEmpty())
        {
            // rjc note: always try to get the string bundle (see above) before trying this
            rv = mBundle->GetStringFromName(NS_LITERAL_STRING("DefaultPersonalToolbarFolder").get(), 
                                            getter_Copies(mPersonalToolbarName));
            if (NS_FAILED(rv) || mPersonalToolbarName.IsEmpty()) {
              // no preference, so fallback to a well-known name
              mPersonalToolbarName.AssignLiteral("Personal Toolbar Folder");
            }
        }
    }

    // Gets the default name for NC:BookmarksRoot
    // if the user has more than one profile: always include the profile name
    // otherwise, include the profile name only if it is not named 'default'
    // the profile "default" is not localizable and arises when there is no ns4.x install
    nsresult             useProfile;
    nsCOMPtr<nsIProfile> profileService(do_GetService(NS_PROFILE_CONTRACTID,&useProfile));
    if (NS_SUCCEEDED(useProfile))
    {
        nsXPIDLString        currentProfileName;
    
        useProfile = profileService->GetCurrentProfile(getter_Copies(currentProfileName));
        if (NS_SUCCEEDED(useProfile))
        {
            const PRUnichar *param[1] = {currentProfileName.get()};
            useProfile = mBundle->FormatStringFromName(NS_LITERAL_STRING("bookmarks_root").get(),
                                                    param, 1, getter_Copies(mBookmarksRootName));
            if (NS_SUCCEEDED(useProfile))
            {
                PRInt32 profileCount;
                useProfile = profileService->GetProfileCount(&profileCount);
                if (NS_SUCCEEDED(useProfile) && profileCount == 1)
                {
                    ToLowerCase(currentProfileName);
                    if (currentProfileName.EqualsLiteral("default"))
                        useProfile = NS_ERROR_FAILURE;
                }
            }
        }
    }

    if (NS_FAILED(useProfile))
    {
        rv = mBundle->GetStringFromName(NS_LITERAL_STRING("bookmarks_default_root").get(),
                                        getter_Copies(mBookmarksRootName));
        if (NS_FAILED(rv) || mBookmarksRootName.IsEmpty()) {
            mBookmarksRootName.AssignLiteral("Bookmarks");
        }
    }

    // Register as an observer of profile changes
    nsCOMPtr<nsIObserverService> observerService = 
             do_GetService("@mozilla.org/observer-service;1", &rv);
    NS_ASSERTION(observerService, "Could not get observer service.");
    if (observerService) {
        observerService->AddObserver(this, "profile-before-change", PR_TRUE);
        observerService->AddObserver(this, "profile-after-change", PR_TRUE);
    }

    rv = initDatasource();
    if (NS_FAILED(rv))
        return rv;

    /* timer initialization */
    busyResource = nsnull;

    if (!mTimer)
    {
        busySchedule = PR_FALSE;
        mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
        NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create a timer");
        if (NS_FAILED(rv)) return rv;
        mTimer->InitWithFuncCallback(nsBookmarksService::FireTimer, this, BOOKMARK_TIMEOUT, 
                                     nsITimer::TYPE_REPEATING_SLACK);
        // Note: don't addref "this" as we'll cancel the timer in the nsBookmarkService destructor
    }

    // register this as a named data source with the RDF
    // service. Do this *last*, because if Init() fails, then the
    // object will be destroyed (leaving the RDF service with a
    // dangling pointer).
    rv = gRDF->RegisterDataSource(this, PR_FALSE);
    if (NS_FAILED(rv)) return rv;

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 5108 of file nsBookmarksService.cpp.

{
    // the profile manager might call Readbookmarks() in certain circumstances
    // so we need to forget about any previous bookmarks
    NS_IF_RELEASE(mInner);

    // don't change this to an xml-ds, it will cause serious perf problems
    nsresult rv = CallCreateInstance(kRDFInMemoryDataSourceCID, &mInner);
    if (NS_FAILED(rv)) return rv;

    rv = mInner->AddObserver(this);
    if (NS_FAILED(rv)) return rv;

    rv = gRDFC->MakeSeq(mInner, kNC_BookmarksTopRoot, nsnull);
    NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to make NC:BookmarksTopRoot a sequence");
    if (NS_FAILED(rv)) return rv;

    rv = gRDFC->MakeSeq(mInner, kNC_BookmarksRoot, nsnull);
    NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to make NC:BookmarksRoot a sequence");
    if (NS_FAILED(rv)) return rv;

    // Make sure bookmark's root has the correct type
    rv = mInner->Assert(kNC_BookmarksTopRoot, kRDF_type, kNC_Folder, PR_TRUE);
    if (NS_FAILED(rv)) return rv;

    rv = mInner->Assert(kNC_BookmarksRoot, kRDF_type, kNC_Folder, PR_TRUE);
    if (NS_FAILED(rv)) return rv;

    // Insert NC:BookmarksRoot in NC:BookmarksTopRoot
    nsCOMPtr<nsIRDFContainer> container(do_CreateInstance(kRDFContainerCID, &rv));
    if (NS_FAILED(rv)) return rv;
    rv = container->Init(mInner, kNC_BookmarksTopRoot);
    if (NS_FAILED(rv)) return rv;
    rv = container->AppendElement(kNC_BookmarksRoot);

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsBookmarksService::insertBookmarkItem ( nsIRDFResource aRelativeNode,
nsISupportsArray aArguments,
nsIRDFResource aItemType 
) [protected]

Inserts a bookmark item of the given type adjacent to the node specified with aRelativeNode.

Creation parameters are given in aArguments.

Definition at line 4503 of file nsBookmarksService.cpp.

{
    nsresult rv;
    const PRInt32 kParentArgumentIndex = 0;
  
    nsCOMPtr<nsIRDFResource> rParent;

    if (aRelativeNode == kNC_BookmarksRoot)
        rParent = aRelativeNode;
    else
    {
        nsCOMPtr<nsIRDFNode> parentNode;
        rv = getArgumentN(aArguments, kNC_Parent, kParentArgumentIndex, getter_AddRefs(parentNode));
        if (NS_FAILED(rv)) return rv;
        rParent = do_QueryInterface(parentNode, &rv);
        if (NS_FAILED(rv)) return rv;
    }

    nsCOMPtr<nsIRDFContainer> container(do_CreateInstance("@mozilla.org/rdf/container;1", &rv));
    if (NS_FAILED(rv)) return rv;

    rv = container->Init(this, rParent);
    if (NS_FAILED(rv)) return rv;

    PRInt32 relNodeIdx = 0;
    if (aRelativeNode != kNC_BookmarksRoot) {
        // Find the position of the relative node, so we can create this item 
        // adjacent to it.
        rv = container->IndexOf(aRelativeNode, &relNodeIdx);
        if (NS_FAILED(rv)) return rv;

        // If the item isn't in the container, just append to the container.
        if (relNodeIdx == -1) {
            rv = container->GetCount(&relNodeIdx);
            if (NS_FAILED(rv)) return rv;
        }
    }

    nsAutoString itemName;
  
    // If a creation name was supplied, use it. 
    if (aItemType == kNC_Bookmark || aItemType == kNC_Folder) {
        nsCOMPtr<nsIRDFNode> nameNode;
        getArgumentN(aArguments, kNC_Name, kParentArgumentIndex, getter_AddRefs(nameNode));
        nsCOMPtr<nsIRDFLiteral> nameLiteral;
        nameLiteral = do_QueryInterface(nameNode);
        if (nameLiteral) {
            const PRUnichar* uName = nsnull;
            nameLiteral->GetValueConst(&uName);
            if (uName) 
                itemName = uName;
        }
    }

    if (itemName.IsEmpty())
    {
        // Retrieve a default name from the bookmark properties file.
        if (aItemType == kNC_Bookmark) 
            getLocaleString("NewBookmark", itemName);
        else if (aItemType == kNC_Folder) 
            getLocaleString("NewFolder", itemName);
    }

    nsCOMPtr<nsIRDFResource> newResource;
  
    // Retrieve the URL from the arguments list. 
    if (aItemType == kNC_Bookmark || aItemType == kNC_Folder)
    {
        nsCOMPtr<nsIRDFNode> urlNode;
        getArgumentN(aArguments, kNC_URL, kParentArgumentIndex, getter_AddRefs(urlNode));
        nsCOMPtr<nsIRDFLiteral> bookmarkURILiteral(do_QueryInterface(urlNode));
        if (bookmarkURILiteral)
        {
            const PRUnichar* uURL = nsnull;
            bookmarkURILiteral->GetValueConst(&uURL);
            if (uURL)
            {
                rv = gRDF->GetUnicodeResource(nsDependentString(uURL), getter_AddRefs(newResource));
                if (NS_FAILED(rv)) return rv;
            }
        }
    }

    if (!newResource)
    {
        // We're a folder, or some other type of anonymous resource.
        rv = gRDF->GetAnonymousResource(getter_AddRefs(newResource));
        if (NS_FAILED(rv)) return rv;
    }

    if (aItemType == kNC_Folder)
    {
        // Make Sequences for Folders.
        rv = gRDFC->MakeSeq(mInner, newResource, nsnull);
        if (NS_FAILED(rv)) return rv;
    }

    // Assert Name arc
    if (!itemName.IsEmpty())
    {
        nsCOMPtr<nsIRDFLiteral> nameLiteral;
        rv = gRDF->GetLiteral(itemName.get(), getter_AddRefs(nameLiteral));
        if (NS_FAILED(rv)) return rv;
        rv = mInner->Assert(newResource, kNC_Name, nameLiteral, PR_TRUE);
        if (NS_FAILED(rv)) return rv;
    }

    // Assert type arc
    rv = mInner->Assert(newResource, kRDF_type, aItemType, PR_TRUE);
    if (NS_FAILED(rv)) return rv;

    // XXX - investigate asserting date as a resource with a raw date value for
    //       lookup, and a Name arc with a pretty display name, e.g. "Saturday"
  
    // Convert the current date/time from microseconds (PRTime) to seconds.
    nsCOMPtr<nsIRDFDate> dateLiteral;
    rv = gRDF->GetDateLiteral(PR_Now(), getter_AddRefs(dateLiteral));
    if (NS_FAILED(rv)) return rv;
    rv = mInner->Assert(newResource, kNC_BookmarkAddDate, dateLiteral, PR_TRUE);
    if (NS_FAILED(rv)) return rv;

    // Add to container. 
    rv = container->InsertElementAt(newResource, !relNodeIdx ? 1 : relNodeIdx, PR_TRUE);
  
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsBookmarksService::InsertResource ( nsIRDFResource aResource,
nsIRDFResource aParentFolder,
PRInt32  aIndex 
) [protected]
NS_IMETHODIMP nsBookmarksService::IsCommandEnabled ( nsISupportsArray aSources,
nsIRDFResource aCommand,
nsISupportsArray aArguments,
PRBool aResult 
)

Definition at line 4452 of file nsBookmarksService.cpp.

Definition at line 5147 of file nsBookmarksService.cpp.

{
    nsresult    rv;

    rv = initDatasource();
    if (NS_FAILED(rv)) return NS_OK;

    rv = EnsureBookmarksFile();

    // Lack of Bookmarks file is non-fatal
    if (NS_FAILED(rv)) return NS_OK;

    PRBool foundIERoot = PR_FALSE;

    nsCOMPtr<nsIPrefService> prefSvc(do_GetService(NS_PREFSERVICE_CONTRACTID));
    nsCOMPtr<nsIPrefBranch> bookmarksPrefs;
    if (prefSvc)
        prefSvc->GetBranch("browser.bookmarks.", getter_AddRefs(bookmarksPrefs));

#ifdef DEBUG_varga
    PRTime now;
#if defined(XP_MAC)
    Microseconds((UnsignedWide *)&now);
#else
    now = PR_Now();
#endif
    printf("Start reading in bookmarks.html\n");
#endif
  
    // System Bookmarks Strategy
    //
    // * By default, we do a one-off import of system bookmarks when the browser 
    //   is run for the first time. This creates a hierarchy of bona-fide Mozilla
    //   bookmarks that is fully manipulable by the user but is not a live view.
    //
    // * As an option, the user can enable a "live view" of his or her system
    //   bookmarks which are not user manipulable but does update automatically.

    // Determine whether or not the user wishes to see the live view of system
    // bookmarks. This is controlled by the 
    //
    //   browser.bookmarks.import_system_favorites
    //
    // pref. See bug 22642 for details. 
    //
    PRBool useDynamicSystemBookmarks;
#ifdef XP_BEOS
    // always dynamic in BeOS
    useDynamicSystemBookmarks = PR_TRUE;
#else
    useDynamicSystemBookmarks = PR_FALSE;
    if (bookmarksPrefs)
        bookmarksPrefs->GetBoolPref("import_system_favorites", &useDynamicSystemBookmarks);
#endif

    nsCAutoString bookmarksURICString;

#if defined(XP_WIN) || defined(XP_BEOS)
    nsCOMPtr<nsIFile> systemBookmarksFolder;

#if defined(XP_WIN)
    rv = NS_GetSpecialDirectory(NS_WIN_FAVORITES_DIR, getter_AddRefs(systemBookmarksFolder));
#elif defined(XP_BEOS)
    rv = NS_GetSpecialDirectory(NS_BEOS_SETTINGS_DIR, getter_AddRefs(systemBookmarksFolder));

    if (NS_SUCCEEDED(rv))
        rv = systemBookmarksFolder->AppendNative(NS_LITERAL_CSTRING("NetPositive"));
   
    if (NS_SUCCEEDED(rv))
        rv = systemBookmarksFolder->AppendNative(NS_LITERAL_CSTRING("Bookmarks"));
#endif

    if (NS_SUCCEEDED(rv))
    {
        nsCOMPtr<nsIURI> bookmarksURI;
        rv = NS_NewFileURI(getter_AddRefs(bookmarksURI), systemBookmarksFolder);

        if (NS_SUCCEEDED(rv))
            rv = bookmarksURI->GetSpec(bookmarksURICString);
    }
#elif defined(XP_MAC) || defined(XP_MACOSX)
    bookmarksURICString.AssignLiteral(kURINC_IEFavoritesRoot);
#endif

    nsCOMPtr<nsIRDFResource> systemFolderResource;
    if (!bookmarksURICString.IsEmpty())
        gRDF->GetResource(bookmarksURICString,
                          getter_AddRefs(systemFolderResource));

    // scope the stream to get the open/close automatically.
    {
        BookmarkParser parser;
        parser.Init(mBookmarksFile, mInner);
        if (useDynamicSystemBookmarks && !bookmarksURICString.IsEmpty())
        {
            parser.SetIEFavoritesRoot(bookmarksURICString);
            parser.ParserFoundIEFavoritesRoot(&foundIERoot);
        }

        BeginUpdateBatch();
        parser.Parse(kNC_BookmarksRoot, kNC_Bookmark);
        EndUpdateBatch();
        
        PRBool foundPTFolder = PR_FALSE;
        parser.ParserFoundPersonalToolbarFolder(&foundPTFolder);
        // try to ensure that we end up with a personal toolbar folder
        if ((foundPTFolder == PR_FALSE) && (!mPersonalToolbarName.IsEmpty()))
        {
            nsCOMPtr<nsIRDFLiteral>   ptNameLiteral;
            rv = gRDF->GetLiteral(mPersonalToolbarName.get(), getter_AddRefs(ptNameLiteral));
            if (NS_SUCCEEDED(rv))
            {
                nsCOMPtr<nsIRDFResource>    ptSource;
                rv = mInner->GetSource(kNC_Name, ptNameLiteral, PR_TRUE, getter_AddRefs(ptSource));
                if (NS_FAILED(rv)) return rv;
        
                if ((rv != NS_RDF_NO_VALUE) && (ptSource))
                    setFolderHint(ptSource, kNC_PersonalToolbarFolder);
            }
        }

      // Sets the default bookmarks root name.
      nsCOMPtr<nsIRDFLiteral> brNameLiteral;
      rv = gRDF->GetLiteral(mBookmarksRootName.get(), getter_AddRefs(brNameLiteral));
      if (NS_SUCCEEDED(rv))
          mInner->Assert(kNC_BookmarksRoot, kNC_Name, brNameLiteral, PR_TRUE);

    } // <-- scope the stream to get the open/close automatically.

    // Now append the one-time-per-profile empty "Full" System Bookmarks Root. 
    // When the user opens this folder for the first time, system bookmarks are 
    // imported into this folder. A pref is used to keep track of whether or 
    // not to perform this operation. 
#if defined(XP_WIN) || defined(XP_MAC) || defined(XP_MACOSX)
    PRBool addedStaticRoot = PR_FALSE;
    if (bookmarksPrefs)
        bookmarksPrefs->GetBoolPref("added_static_root", 
                                    &addedStaticRoot);

    // Add the root that System bookmarks are imported into as real bookmarks. This is 
    // only done once. 
    if (!addedStaticRoot && systemFolderResource)
    {
        nsCOMPtr<nsIRDFContainer> rootContainer(do_CreateInstance(kRDFContainerCID, &rv));
        if (NS_FAILED(rv)) return rv;

        rv = rootContainer->Init(this, kNC_BookmarksRoot);
        if (NS_FAILED(rv)) return rv;

        rv = mInner->Assert(kNC_SystemBookmarksStaticRoot, kRDF_type, kNC_Folder, PR_TRUE);
        if (NS_FAILED(rv)) return rv;

        nsAutoString importedStaticTitle;
        getLocaleString("ImportedIEStaticFavorites", importedStaticTitle);

        nsCOMPtr<nsIRDFLiteral> staticTitleLiteral;
        rv = gRDF->GetLiteral(importedStaticTitle.get(), getter_AddRefs(staticTitleLiteral));
        if (NS_FAILED(rv)) return rv;

        rv = mInner->Assert(kNC_SystemBookmarksStaticRoot, kNC_Name, staticTitleLiteral, PR_TRUE);
        if (NS_FAILED(rv)) return rv;

        rv = rootContainer->AppendElement(kNC_SystemBookmarksStaticRoot);
        if (NS_FAILED(rv)) return rv;

        // If the user has not specifically asked for the Dynamic bookmarks root 
        // via the pref, remove it from an existing bookmarks file as it serves
        // only to add confusion. 
        if (!useDynamicSystemBookmarks)
        {
            nsCOMPtr<nsIRDFContainer> container(do_CreateInstance(kRDFContainerCID, &rv));
            if (NS_FAILED(rv)) return rv;

            rv = container->Init(this, kNC_BookmarksRoot);
            if (NS_FAILED(rv)) return rv;
      
            rv = container->RemoveElement(systemFolderResource, PR_TRUE);
            if (NS_FAILED(rv)) return rv;
        }

        bookmarksPrefs->SetBoolPref("added_static_root", PR_TRUE);
    }
#endif

    // Add the dynamic system bookmarks root if the user has asked for it
    // by setting the pref. 
    if (useDynamicSystemBookmarks)
    {
#if defined(XP_MAC) || defined(XP_MACOSX)
        // if the IE Favorites root isn't somewhere in bookmarks.html, add it
        if (!foundIERoot)
        {
            nsCOMPtr<nsIRDFContainer> bookmarksRoot(do_CreateInstance(kRDFContainerCID, &rv));
            if (NS_FAILED(rv)) return rv;

            rv = bookmarksRoot->Init(this, kNC_BookmarksRoot);
            if (NS_FAILED(rv)) return rv;

            rv = bookmarksRoot->AppendElement(kNC_IEFavoritesRoot);
            if (NS_FAILED(rv)) return rv;

            // make sure IE Favorites root folder has the proper type     
            rv = mInner->Assert(kNC_IEFavoritesRoot, kRDF_type, kNC_IEFavoriteFolder, PR_TRUE);
            if (NS_FAILED(rv)) return rv;
        }
#elif defined(XP_WIN) || defined(XP_BEOS)
        if (systemFolderResource)
        {
            nsAutoString systemBookmarksFolderTitle;
#ifdef XP_BEOS
            getLocaleString("ImportedNetPositiveBookmarks", systemBookmarksFolderTitle);
#else
            getLocaleString("ImportedIEFavorites", systemBookmarksFolderTitle);
#endif

            nsCOMPtr<nsIRDFLiteral>   systemFolderTitleLiteral;
            rv = gRDF->GetLiteral(systemBookmarksFolderTitle.get(), 
                                  getter_AddRefs(systemFolderTitleLiteral));
            if (NS_SUCCEEDED(rv) && systemFolderTitleLiteral)
                rv = mInner->Assert(systemFolderResource, kNC_Name, 
                                    systemFolderTitleLiteral, PR_TRUE);
    
            // if the IE Favorites root isn't somewhere in bookmarks.html, add it
            if (!foundIERoot)
            {
                nsCOMPtr<nsIRDFContainer> container(do_CreateInstance(kRDFContainerCID, &rv));
                if (NS_FAILED(rv)) return rv;

                rv = container->Init(this, kNC_BookmarksRoot);
                if (NS_FAILED(rv)) return rv;

                rv = container->AppendElement(systemFolderResource);
                if (NS_FAILED(rv)) return rv;
            }
        }
#endif
    }

#ifdef DEBUG_varga
    PRTime      now2;
#if defined(XP_MAC)
    Microseconds((UnsignedWide *)&now2);
#else
    now2 = PR_Now();
#endif
    PRUint64    loadTime64;
    LL_SUB(loadTime64, now2, now);
    PRUint32    loadTime32;
    LL_L2UI(loadTime32, loadTime64);
    printf("Finished reading in bookmarks.html  (%u microseconds)\n", loadTime32);
#endif

    return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsBookmarksService::Move ( nsIRDFResource aOldSource,
nsIRDFResource aNewSource,
nsIRDFResource aProperty,
nsIRDFNode aTarget 
)

Definition at line 4291 of file nsBookmarksService.cpp.

{
    nsresult    rv = NS_RDF_ASSERTION_REJECTED;

    if (CanAccept(aNewSource, aProperty, aTarget))
    {
        rv = mInner->Move(aOldSource, aNewSource, aProperty, aTarget);
        if (NS_FAILED(rv))
            return rv;

        UpdateBookmarkLastModifiedDate(aOldSource);
        UpdateBookmarkLastModifiedDate(aNewSource);
    }
    return rv;
}

Here is the call graph for this function:

nsresult nsBookmarksService::ProcessCachedBookmarkIcon ( nsIRDFResource aSource,
const PRUnichar iconURL,
nsIRDFNode **  aTarget 
) [protected]

Definition at line 4067 of file nsBookmarksService.cpp.

{
    *aTarget = nsnull;

    if (!mBrowserIcons)
    {
        return NS_RDF_NO_VALUE;
    }

    // if it is in fact a bookmark or favorite (but NOT a folder, or a separator, etc)...

    nsCOMPtr<nsIRDFNode> nodeType;
    GetSynthesizedType(aSource, getter_AddRefs(nodeType));
    if ((nodeType != kNC_Bookmark) && (nodeType != kNC_IEFavorite))
    {
        return NS_RDF_NO_VALUE;
    }

    nsresult rv;
    nsCAutoString path;
    nsCOMPtr<nsIRDFNode>    oldIconNode;

    // if we have a new icon URL, save it away into our internal graph
    if (iconURL)
    {
        path.AssignWithConversion(iconURL);

        nsCOMPtr<nsIRDFLiteral> iconLiteral;
        if (NS_FAILED(rv = gRDF->GetLiteral(iconURL, getter_AddRefs(iconLiteral))))
        {
            return rv;
        }

        rv = mInner->GetTarget(aSource, kNC_Icon, PR_TRUE, getter_AddRefs(oldIconNode));
        if (NS_SUCCEEDED(rv) && (rv != NS_RDF_NO_VALUE) && (oldIconNode))
        {
            (void)mInner->Unassert(aSource, kNC_Icon, oldIconNode);
        }
        (void)mInner->Assert(aSource, kNC_Icon, iconLiteral, PR_TRUE);

        mDirty = PR_TRUE;
    }
    else
    {
        // otherwise, just check and see if we have an internal icon reference
        rv = mInner->GetTarget(aSource, kNC_Icon, PR_TRUE, getter_AddRefs(oldIconNode));
    }
    
    if (oldIconNode)
    {
        nsCOMPtr<nsIRDFLiteral> tempLiteral = do_QueryInterface(oldIconNode);
        if (tempLiteral)
        {
            const PRUnichar *uni = nsnull;
            tempLiteral->GetValueConst(&uni);
            if (uni)    path.AssignWithConversion(uni);
        }
    }

    PRBool forceLoad = mAlwaysLoadIcons;

    // if no internal icon reference, try and synthesize a URL
    if (path.IsEmpty())
    {
        const char  *uri;
        forceLoad = PR_FALSE;
        if (NS_FAILED(rv = aSource->GetValueConst( &uri )))
        {
            return rv;
        }

        nsCOMPtr<nsIURI>    nsURI;
        if (NS_FAILED(rv = mNetService->NewURI(nsDependentCString(uri), nsnull, nsnull, getter_AddRefs(nsURI))))
        {
            return rv;
        }
        
        // only allow http/https URLs for favicon
        PRBool  isHTTP = PR_FALSE;
        nsURI->SchemeIs("http", &isHTTP);
        if (!isHTTP)
        {
            nsURI->SchemeIs("https", &isHTTP);
        }
        if (!isHTTP)
        {
            return NS_RDF_NO_VALUE;
        }

        nsCAutoString prePath;
        if (NS_FAILED(rv = nsURI->GetPrePath(prePath)))
        {
            return rv;
        }
        path.Assign(prePath);
        path.Append("/favicon.ico");
    }

    if (!forceLoad) {
        // only return favicon reference if its in the cache
        // (that is, never go out onto the net)
        if (!mCacheSession)
        {
            return NS_RDF_NO_VALUE;
        }
        nsCOMPtr<nsICacheEntryDescriptor> entry;
        rv = mCacheSession->OpenCacheEntry(path, nsICache::ACCESS_READ,
                                           nsICache::NON_BLOCKING, getter_AddRefs(entry));
        if (NS_FAILED(rv) || (!entry))
        {
            return NS_RDF_NO_VALUE;
        }
        if (entry) 
        {
            PRUint32 expTime;
            entry->GetExpirationTime(&expTime);
            if (expTime != PR_UINT32_MAX)
                entry->SetExpirationTime(PR_UINT32_MAX);
        }
        entry->Close();
    }

    // ok, have a cached icon entry, so return the URL's associated favicon
    nsAutoString litStr;
    litStr.AssignWithConversion(path.get());
    nsCOMPtr<nsIRDFLiteral> literal;
    if (NS_FAILED(rv = gRDF->GetLiteral(litStr.get(), getter_AddRefs(literal))))
    {
        return rv;
    }
    *aTarget = literal;
    NS_IF_ADDREF(*aTarget);
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4338 of file nsBookmarksService.cpp.

{
    if (! aObserver)
        return NS_ERROR_NULL_POINTER;

    mObservers.RemoveObject(aObserver);

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 5744 of file nsBookmarksService.cpp.

{
    NS_ASSERTION(aURI, "null ptr");

    nsresult rv;
    nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(aURI, &rv);
    if (NS_FAILED(rv)) return rv;

    nsCOMPtr<nsIFile> file;
    rv = fileURL->GetFile(getter_AddRefs(file));
    if (NS_FAILED(rv)) return rv;

    // if file doesn't exist, create it
    (void)file->Create(nsIFile::NORMAL_FILE_TYPE, 0666);

    nsCOMPtr<nsIOutputStream> out;
    rv = NS_NewLocalFileOutputStream(getter_AddRefs(out), file);
    if (NS_FAILED(rv)) return rv;

    nsCOMPtr<nsIOutputStream> bufferedOut;
    rv = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOut), out, 4096);
    if (NS_FAILED(rv)) return rv;

    nsCOMPtr<nsIRDFXMLSerializer> serializer =
        do_CreateInstance("@mozilla.org/rdf/xml-serializer;1", &rv);
    if (NS_FAILED(rv)) return rv;

    rv = serializer->Init(this);
    if (NS_FAILED(rv)) return rv;

    nsCOMPtr<nsIRDFXMLSource> source = do_QueryInterface(serializer);
    if (! source)
        return NS_ERROR_FAILURE;

    return source->Serialize(bufferedOut);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4660 of file nsBookmarksService.cpp.

{
    nsresult            rv;
    nsCOMPtr<nsISimpleEnumerator>   srcList;
    if (NS_FAILED(rv = GetSources(kNC_FolderType, objType, PR_TRUE, getter_AddRefs(srcList))))
        return rv;

    PRBool  hasMoreSrcs = PR_TRUE;
    while(NS_SUCCEEDED(rv = srcList->HasMoreElements(&hasMoreSrcs))
        && (hasMoreSrcs == PR_TRUE))
    {
        nsCOMPtr<nsISupports>   aSrc;
        if (NS_FAILED(rv = srcList->GetNext(getter_AddRefs(aSrc))))
            break;
        nsCOMPtr<nsIRDFResource>    aSource = do_QueryInterface(aSrc);
        if (!aSource)   continue;

        // if folder is already marked, nothing left to do
        if (aSource.get() == newSource)   return NS_OK;

        if (NS_FAILED(rv = mInner->Unassert(aSource, kNC_FolderType, objType)))
            continue;
    }

    // If not setting a new Personal Toolbar Folder, just assert new type, and
    // then done.
    if (objType != kNC_PersonalToolbarFolder) {
        rv = mInner->Assert(newSource, kNC_FolderType, objType, PR_TRUE);

        mDirty = PR_TRUE;
        return rv;
    }

    // If setting a new Personal Toolbar Folder, we need to work some magic!
    BeginUpdateBatch();
    rv = SetNewPersonalToolbarFolder(newSource);
    EndUpdateBatch();
    if (NS_FAILED(rv))
        return rv;

    rv = mInner->Assert(kNC_PersonalToolbarFolder, kNC_FolderType, objType, PR_TRUE);
    if (NS_FAILED(rv))
        return rv;

    mDirty = PR_TRUE;

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 3043 of file nsBookmarksService.cpp.

{
    nsCOMPtr<nsIRDFResource> tempResource;
    nsresult rv = gRDF->GetAnonymousResource(getter_AddRefs(tempResource));
    if (NS_FAILED(rv))
        return rv;

    rv = CopyResource(kNC_PersonalToolbarFolder, tempResource);
    if (NS_FAILED(rv))
        return rv;

    rv = CopyResource(aFolder, kNC_PersonalToolbarFolder);
    if (NS_FAILED(rv))
        return rv;

    return CopyResource(tempResource, aFolder);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsBookmarksService::Sort ( nsIRDFResource aFolder,
nsIRDFResource aProperty,
PRInt32  aDirection,
PRBool  aFoldersFirst,
PRBool  aRecurse 
) [protected]

Definition at line 2744 of file nsBookmarksService.cpp.

{
    nsresult rv;
    nsCOMPtr<nsIRDFContainer> container =
        do_CreateInstance("@mozilla.org/rdf/container;1", &rv);
    if (NS_FAILED(rv))
        return rv;

    rv = container->Init(mInner, aFolder);
    if (NS_FAILED(rv))
        return rv;

    nsCOMPtr<nsISimpleEnumerator> elements;
    rv = container->GetElements(getter_AddRefs(elements));
    if (NS_FAILED(rv))
        return rv;

    ElementArray elementArray;

    PRBool hasMore = PR_FALSE;
    while (NS_SUCCEEDED(rv = elements->HasMoreElements(&hasMore)) &&
           hasMore) {
        nsCOMPtr<nsISupports> supports;
        rv = elements->GetNext(getter_AddRefs(supports));
        if (NS_FAILED(rv))
            return rv;

        nsCOMPtr<nsIRDFResource> element = do_QueryInterface(supports, &rv);
        if (NS_FAILED(rv))
            return rv;

        nsCOMPtr<nsIRDFNode> node;
        rv = mInner->GetTarget(element, aProperty, PR_TRUE, getter_AddRefs(node));
        if (NS_FAILED(rv))
            return rv;

        if (!node) {
            if (aProperty == kNC_BookmarkAddDate ||
                aProperty == kWEB_LastModifiedDate ||
                aProperty == kWEB_LastVisitDate) {
                node = do_QueryInterface(kEmptyDate);
            }
            else {
                node = do_QueryInterface(kEmptyLiteral);
            }
        }

        PRBool isContainer;
        rv = gRDFC->IsContainer(mInner, element, &isContainer);
        if (NS_FAILED(rv))
            return rv;

        PRBool isGroup;
        rv = mInner->HasAssertion(element, kNC_FolderGroup, kTrueLiteral,
                                  PR_TRUE, &isGroup);
        if (NS_FAILED(rv))
            return rv;

        ElementInfo* elementInfo = new ElementInfo(element, node,
                                                   isContainer && !isGroup);
        if (!elementInfo)
            return NS_ERROR_OUT_OF_MEMORY;

        elementArray.AppendElement(elementInfo);

        if (isContainer && aRecurse) {
            rv = Sort(element, aProperty, aDirection, aFoldersFirst, aRecurse);
            if (NS_FAILED(rv))
                return rv;
        }
    }

    SortInfo sortInfo(aDirection, aFoldersFirst);
    elementArray.Sort(Compare, &sortInfo);

    // XXXvarga If we ever make it so that ordinals are guaranteed to be unique,
    // the code below can be significantly simplified.
    for (PRInt32 j = elementArray.Count() - 1; j >= 0; --j) {
        ElementInfo* elementInfo = elementArray[j];

        PRInt32 oldIndex;
        rv = gRDFC->IndexOf(mInner, aFolder, elementInfo->mElement, &oldIndex);
        if (NS_FAILED(rv))
            return rv;

        // The old index is 1 based.
        if (oldIndex != j + 1) {
            nsCOMPtr<nsIRDFResource> oldOrdinal;
            rv = gRDFC->IndexToOrdinalResource(oldIndex, getter_AddRefs(oldOrdinal));
            if (NS_FAILED(rv))
                return rv;

            nsCOMPtr<nsIRDFResource> newOrdinal;
            rv = gRDFC->IndexToOrdinalResource(j + 1, getter_AddRefs(newOrdinal));
            if (NS_FAILED(rv))
                return rv;

            // We need to find the correct element for the old ordinal,
            // it happens that there are two elements with the same ordinal.
            nsCOMPtr<nsISimpleEnumerator> elements;
            rv = mInner->GetTargets(aFolder, oldOrdinal, PR_TRUE,
                                    getter_AddRefs(elements));

            PRBool hasMore = PR_FALSE;
            while (NS_SUCCEEDED(rv = elements->HasMoreElements(&hasMore)) &&
                   hasMore) {
                nsCOMPtr<nsISupports> supports;
                rv = elements->GetNext(getter_AddRefs(supports));
                if (NS_FAILED(rv))
                    return rv;

                nsCOMPtr<nsIRDFNode> element = do_QueryInterface(supports);
                if (element == elementInfo->mElement) {
                    rv = mInner->Unassert(aFolder, oldOrdinal, element);
                    if (NS_FAILED(rv))
                        return rv;

                    rv = mInner->Assert(aFolder, newOrdinal, element, PR_TRUE);
                    if (NS_FAILED(rv))
                        return rv;
                    break;
                }
            }
        }
    }

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 4246 of file nsBookmarksService.cpp.

{
    nsresult rv = NS_RDF_ASSERTION_REJECTED;

    if (CanAccept(aSource, aProperty, aTarget)) {
        rv = mInner->Unassert(aSource, aProperty, aTarget);
        if (NS_FAILED(rv))
            return rv;

        UpdateBookmarkLastModifiedDate(aSource);

        if (aProperty == kWEB_Schedule) {
            AnnotateBookmarkSchedule(aSource, PR_FALSE);
        }
    }

    return rv;
}

Here is the call graph for this function:

Definition at line 3645 of file nsBookmarksService.cpp.

{
    nsCOMPtr<nsIRDFDate>    now;
    nsresult        rv;

    if (NS_SUCCEEDED(rv = gRDF->GetDateLiteral(PR_Now(), getter_AddRefs(now))))
    {
        nsCOMPtr<nsIRDFNode>    lastMod;

        // Note: always use mInner!! Otherwise, could get into an infinite loop
        // due to Assert/Change calling UpdateBookmarkLastModifiedDate()

        if (NS_SUCCEEDED(rv = mInner->GetTarget(aSource, kWEB_LastModifiedDate, PR_TRUE,
            getter_AddRefs(lastMod))) && (rv != NS_RDF_NO_VALUE))
        {
            rv = mInner->Change(aSource, kWEB_LastModifiedDate, lastMod, now);
        }
        else
        {
            rv = mInner->Assert(aSource, kWEB_LastModifiedDate, now, PR_TRUE);
        }
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsBookmarksService::WriteBookmarkProperties ( nsIRDFDataSource ds,
nsIOutputStream strm,
nsIRDFResource node,
nsIRDFResource property,
const char *  htmlAttrib,
PRBool  isFirst 
) [protected]

Definition at line 5851 of file nsBookmarksService.cpp.

{
    nsresult  rv;
    PRUint32  dummy;

    nsCOMPtr<nsIRDFNode>    node;
    if (NS_SUCCEEDED(rv = ds->GetTarget(child, property, PR_TRUE, getter_AddRefs(node)))
        && (rv != NS_RDF_NO_VALUE))
    {
        nsAutoString    literalString;
        if (NS_SUCCEEDED(rv = GetTextForNode(node, literalString)))
        {
            if (property == kNC_URL) {
                // Now do properly replace %22's; this is particularly important for javascript: URLs
                PRInt32 offset;
                while ((offset = literalString.FindChar('\"')) >= 0) {
                    literalString.Cut(offset, 1);
                    literalString.Insert(NS_LITERAL_STRING("%22"), offset);
                }
            }

            char        *attribute = ToNewUTF8String(literalString);
            if (nsnull != attribute)
            {
                if (isFirst == PR_FALSE)
                {
                    rv |= strm->Write(kSpaceStr, sizeof(kSpaceStr)-1, &dummy);
                }

                if (property == kNC_Description)
                {
                    if (!literalString.IsEmpty())
                    {
                        char *escapedAttrib = nsEscapeHTML(attribute);
                        if (escapedAttrib)
                        {
                            rv |= strm->Write(htmlAttrib, strlen(htmlAttrib), &dummy);
                            rv |= strm->Write(escapedAttrib, strlen(escapedAttrib), &dummy);
                            rv |= strm->Write(kNL, sizeof(kNL)-1, &dummy);

                            NS_Free(escapedAttrib);
                            escapedAttrib = nsnull;
                        }
                    }
                }
                else
                {
                    rv |= strm->Write(htmlAttrib, strlen(htmlAttrib), &dummy);
                    rv |= strm->Write(attribute, strlen(attribute), &dummy);
                    rv |= strm->Write(kQuoteStr, sizeof(kQuoteStr)-1, &dummy);
                }
                NS_Free(attribute);
                attribute = nsnull;
            }
        }
    }
    if (NS_FAILED(rv))
        return NS_ERROR_UNEXPECTED;
    
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsBookmarksService::WriteBookmarks ( nsIFile bookmarksFile,
nsIRDFDataSource ds,
nsIRDFResource root 
) [protected]

Definition at line 5413 of file nsBookmarksService.cpp.

{
    if (!aBookmarksFile || !aDataSource || !aRoot)
        return NS_ERROR_NULL_POINTER;

    // get a safe output stream, so we don't clobber the bookmarks file unless
    // all the writes succeeded.
    nsCOMPtr<nsIOutputStream> out;
    nsresult rv = NS_NewSafeLocalFileOutputStream(getter_AddRefs(out),
                                                  aBookmarksFile,
                                                  -1,
                                                  /*octal*/ 0600);
    if (NS_FAILED(rv)) return rv;

    // We need a buffered output stream for performance.
    // See bug 202477.
    nsCOMPtr<nsIOutputStream> strm;
    rv = NS_NewBufferedOutputStream(getter_AddRefs(strm), out, 4096);
    if (NS_FAILED(rv)) return rv;

    PRUint32 dummy;
    strm->Write(kFileIntro, sizeof(kFileIntro)-1, &dummy);

    nsCOMArray<nsIRDFResource> parentArray;
    rv = WriteBookmarksContainer(aDataSource, strm, aRoot, 0, parentArray);

    // All went ok. Maybe except for problems in Write(), but the stream detects
    // that for us
    nsCOMPtr<nsISafeOutputStream> safeStream = do_QueryInterface(strm);
    NS_ASSERTION(safeStream, "expected a safe output stream!");
    if (NS_SUCCEEDED(rv) && safeStream)
        rv = safeStream->Finish();

    if (NS_FAILED(rv)) {
        NS_WARNING("failed to save bookmarks file! possible dataloss");
        return rv;
    }

    mDirty = PR_FALSE;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsBookmarksService::WriteBookmarksContainer ( nsIRDFDataSource ds,
nsIOutputStream strm,
nsIRDFResource container,
PRInt32  level,
nsCOMArray< nsIRDFResource > &  parentArray 
) [protected]

Definition at line 5473 of file nsBookmarksService.cpp.

{
    // rv is used for various functions
    nsresult rv;

    nsCOMPtr<nsIRDFContainer> container =
            do_CreateInstance(kRDFContainerCID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCAutoString   indentation;

    for (PRInt32 loop=0; loop<level; loop++)
        indentation.Append(kIndent, sizeof(kIndent)-1);

    PRUint32 dummy;
    rv = strm->Write(indentation.get(), indentation.Length(), &dummy);
    rv |= strm->Write(kBookmarkIntro, sizeof(kBookmarkIntro)-1, &dummy);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_UNEXPECTED);

    rv = container->Init(ds, parent);
    if (NS_SUCCEEDED(rv) && (parentArray.IndexOfObject(parent) < 0))
    {
        // Note: once we've added something into the parentArray, don't "return" out
        //       of this function without removing it from the parentArray!
        parentArray.InsertObjectAt(parent, 0);

        nsCOMPtr<nsISimpleEnumerator>   children;
        if (NS_SUCCEEDED(rv = container->GetElements(getter_AddRefs(children))))
        {
            PRBool  more = PR_TRUE;
            while (more == PR_TRUE)
            {
                if (NS_FAILED(rv = children->HasMoreElements(&more)))   break;
                if (more != PR_TRUE)    break;

                nsCOMPtr<nsISupports>   iSupports;                  
                if (NS_FAILED(rv = children->GetNext(getter_AddRefs(iSupports))))   break;

                nsCOMPtr<nsIRDFResource>    child = do_QueryInterface(iSupports);
                if (!child) break;

                PRBool  isContainer = PR_FALSE;
                if (child.get() != kNC_IEFavoritesRoot)
                {
                    rv = gRDFC->IsContainer(ds, child, &isContainer);
                    if (NS_FAILED(rv)) break;
                }

                nsCOMPtr<nsIRDFNode>    nameNode;
                nsAutoString        nameString;
                nsCAutoString       name;
                rv = ds->GetTarget(child, kNC_Name, PR_TRUE, getter_AddRefs(nameNode));
                if (NS_SUCCEEDED(rv) && nameNode)
                {
                    nsCOMPtr<nsIRDFLiteral> nameLiteral = do_QueryInterface(nameNode);
                    if (nameLiteral)
                    {
                        const PRUnichar *title = nsnull;
                        if (NS_SUCCEEDED(rv = nameLiteral->GetValueConst(&title)))
                        {
                            nameString = title;
                            AppendUTF16toUTF8(nameString, name);
                        }
                    }
                }

                rv = strm->Write(indentation.get(), indentation.Length(), &dummy);
                rv |= strm->Write(kIndent, sizeof(kIndent)-1, &dummy);
                if (NS_FAILED(rv)) break;

                if (isContainer == PR_TRUE)
                {
                    rv = strm->Write(kContainerIntro, sizeof(kContainerIntro)-1, &dummy);
                    // output ADD_DATE
                    rv |= WriteBookmarkProperties(ds, strm, child, kNC_BookmarkAddDate, kAddDateEquals, PR_FALSE);

                    // output LAST_MODIFIED
                    rv |= WriteBookmarkProperties(ds, strm, child, kWEB_LastModifiedDate, kLastModifiedEquals, PR_FALSE);
                    if (NS_FAILED(rv)) break;

                    // output various special folder hints
                    PRBool  hasType = PR_FALSE;
                    if (NS_SUCCEEDED(rv = mInner->HasAssertion(child, kNC_FolderType, kNC_NewBookmarkFolder,
                                                               PR_TRUE, &hasType)) && (hasType == PR_TRUE))
                    {
                        rv = strm->Write(kSpaceStr, sizeof(kSpaceStr)-1, &dummy);
                        rv |= strm->Write(kNewBookmarkFolderEquals, sizeof(kNewBookmarkFolderEquals)-1, &dummy);
                        rv |= strm->Write(kTrueEnd, sizeof(kTrueEnd)-1, &dummy);
                        if (NS_FAILED(rv)) break;
                    }
                    if (NS_SUCCEEDED(rv = mInner->HasAssertion(child, kNC_FolderType, kNC_NewSearchFolder,
                                                               PR_TRUE, &hasType)) && (hasType == PR_TRUE))
                    {
                        rv = strm->Write(kSpaceStr, sizeof(kSpaceStr)-1, &dummy);
                        rv |= strm->Write(kNewSearchFolderEquals, sizeof(kNewSearchFolderEquals)-1, &dummy);
                        rv |= strm->Write(kTrueEnd, sizeof(kTrueEnd)-1, &dummy);
                        if (NS_FAILED(rv)) break;
                    }
                    if (NS_SUCCEEDED(rv = mInner->HasAssertion(child, kNC_FolderType, kNC_PersonalToolbarFolder,
                                                               PR_TRUE, &hasType)) && (hasType == PR_TRUE))
                    {
                        rv = strm->Write(kSpaceStr, sizeof(kSpaceStr)-1, &dummy);
                        rv |= strm->Write(kPersonalToolbarFolderEquals, sizeof(kPersonalToolbarFolderEquals)-1, &dummy);
                        rv |= strm->Write(kTrueEnd, sizeof(kTrueEnd)-1, &dummy);
                        if (NS_FAILED(rv)) break;
                    }

                    if (NS_SUCCEEDED(rv = mInner->HasArcOut(child, kNC_FolderGroup, &hasType)) && 
                        (hasType == PR_TRUE))
                    {
                        rv = strm->Write(kSpaceStr, sizeof(kSpaceStr)-1, &dummy);
                        rv |= strm->Write(kFolderGroupEquals, sizeof(kFolderGroupEquals)-1, &dummy);
                        rv |= strm->Write(kTrueEnd, sizeof(kTrueEnd)-1, &dummy);
                        if (NS_FAILED(rv)) break;
                    }

                    // output ID
                    const char  *id = nsnull;
                    rv = child->GetValueConst(&id);
                    if (NS_SUCCEEDED(rv) && (id))
                    {
                        rv = strm->Write(kSpaceStr, sizeof(kSpaceStr)-1, &dummy);
                        rv |= strm->Write(kIDEquals, sizeof(kIDEquals)-1, &dummy);
                        rv |= strm->Write(id, strlen(id), &dummy);
                        rv |= strm->Write(kQuoteStr, sizeof(kQuoteStr)-1, &dummy);
                        if (NS_FAILED(rv)) break;
                    }
          
                    rv = strm->Write(kCloseAngle, sizeof(kCloseAngle)-1, &dummy);
          
                    // output title
                    if (!name.IsEmpty())
                    {
                        // see bug #65098
                        char *escapedAttrib = nsEscapeHTML(name.get());
                        if (escapedAttrib)
                        {
                            rv |= strm->Write(escapedAttrib, strlen(escapedAttrib), &dummy);
                            NS_Free(escapedAttrib);
                        }
                    }
                    rv |= strm->Write(kCloseH3, sizeof(kCloseH3)-1, &dummy);

                    // output description (if one exists)
                    rv |= WriteBookmarkProperties(ds, strm, child, kNC_Description, kOpenDD, PR_TRUE);

                    rv |= WriteBookmarksContainer(ds, strm, child, level+1, parentArray);
                }
                else
                {
                    const char  *url = nsnull;
                    if (NS_SUCCEEDED(rv = child->GetValueConst(&url)) && (url))
                    {
                        nsCAutoString   uri(url);

                        PRBool      isBookmarkSeparator = PR_FALSE;
                        if (NS_SUCCEEDED(mInner->HasAssertion(child, kRDF_type,
                                                              kNC_BookmarkSeparator, PR_TRUE, &isBookmarkSeparator)) &&
                            (isBookmarkSeparator == PR_TRUE) )
                        {
                            // its a separator
                            rv = strm->Write(kHROpen, sizeof(kHROpen)-1, &dummy);

                            // output NAME
                            rv |= WriteBookmarkProperties(ds, strm, child, kNC_Name, kNameEquals, PR_FALSE);

                            rv |= strm->Write(kAngleNL, sizeof(kAngleNL)-1, &dummy);
                            if (NS_FAILED(rv)) break;
                        }
                        else
                        {
                            rv = strm->Write(kDTOpen, sizeof(kDTOpen)-1, &dummy);

                            // output URL
                            rv |= WriteBookmarkProperties(ds, strm, child, kNC_URL, kHREFEquals, PR_FALSE);

                            // output ADD_DATE
                            rv |= WriteBookmarkProperties(ds, strm, child, kNC_BookmarkAddDate, kAddDateEquals, PR_FALSE);

                            // output LAST_VISIT
                            rv |= WriteBookmarkProperties(ds, strm, child, kWEB_LastVisitDate, kLastVisitEquals, PR_FALSE);

                            // output LAST_MODIFIED
                            rv |= WriteBookmarkProperties(ds, strm, child, kWEB_LastModifiedDate, kLastModifiedEquals, PR_FALSE);

                            // output SHORTCUTURL
                            rv |= WriteBookmarkProperties(ds, strm, child, kNC_ShortcutURL, kShortcutURLEquals, PR_FALSE);

                            // output kNC_Icon
                            rv |= WriteBookmarkProperties(ds, strm, child, kNC_Icon, kIconEquals, PR_FALSE);

                            // output SCHEDULE
                            rv |= WriteBookmarkProperties(ds, strm, child, kWEB_Schedule, kScheduleEquals, PR_FALSE);

                            // output LAST_PING
                            rv |= WriteBookmarkProperties(ds, strm, child, kWEB_LastPingDate, kLastPingEquals, PR_FALSE);

                            // output PING_ETAG
                            rv |= WriteBookmarkProperties(ds, strm, child, kWEB_LastPingETag, kPingETagEquals, PR_FALSE);

                            // output PING_LAST_MODIFIED
                            rv |= WriteBookmarkProperties(ds, strm, child, kWEB_LastPingModDate, kPingLastModEquals, PR_FALSE);

                            // output LAST_CHARSET
                            rv |= WriteBookmarkProperties(ds, strm, child, kWEB_LastCharset, kLastCharsetEquals, PR_FALSE);

                            // output PING_CONTENT_LEN
                            rv |= WriteBookmarkProperties(ds, strm, child, kWEB_LastPingContentLen, kPingContentLenEquals, PR_FALSE);

                            // output PING_STATUS
                            rv |= WriteBookmarkProperties(ds, strm, child, kWEB_Status, kPingStatusEquals, PR_FALSE);
                            if (NS_FAILED(rv)) break;
                            
                            // output ID
                            const char  *id = nsnull;
                            rv = child->GetValueConst(&id);
                            if (NS_SUCCEEDED(rv) && (id))
                            {
                                rv = strm->Write(kSpaceStr, sizeof(kSpaceStr)-1, &dummy);
                                rv |= strm->Write(kIDEquals, sizeof(kIDEquals)-1, &dummy);
                                rv |= strm->Write(id, strlen(id), &dummy);
                                rv |= strm->Write(kQuoteStr, sizeof(kQuoteStr)-1, &dummy);
                                if (NS_FAILED(rv)) break;
                            }

                            rv = strm->Write(kCloseAngle, sizeof(kCloseAngle)-1, &dummy);

                            // output title
                            if (!name.IsEmpty())
                            {
                                // Note: we escape the title due to security issues;
                                //       see bug # 13197 for details
                                char *escapedAttrib = nsEscapeHTML(name.get());
                                if (escapedAttrib)
                                {
                                    rv |= strm->Write(escapedAttrib,
                                                       strlen(escapedAttrib),
                                                       &dummy);
                                    NS_Free(escapedAttrib);
                                    escapedAttrib = nsnull;
                                }
                            }

                            rv |= strm->Write(kAClose, sizeof(kAClose)-1, &dummy);
                            
                            // output description (if one exists)
                            rv |= WriteBookmarkProperties(ds, strm, child, kNC_Description, kOpenDD, PR_TRUE);
                        }
                    }
                }

                if (NS_FAILED(rv))  break;
            }
        }

        // cleanup: remove current parent element from parentArray
        parentArray.RemoveObjectAt(0);
    }

    rv |= strm->Write(indentation.get(), indentation.Length(), &dummy);
    rv |= strm->Write(kBookmarkClose, sizeof(kBookmarkClose)-1, &dummy);

    NS_ENSURE_SUCCESS(rv, NS_ERROR_UNEXPECTED);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 83 of file nsBookmarksService.h.

Definition at line 100 of file nsBookmarksService.h.

Definition at line 93 of file nsBookmarksService.h.

Definition at line 99 of file nsBookmarksService.h.

Definition at line 91 of file nsBookmarksService.h.

Definition at line 96 of file nsBookmarksService.h.

Definition at line 98 of file nsBookmarksService.h.

Definition at line 85 of file nsBookmarksService.h.

Definition at line 88 of file nsBookmarksService.h.

Definition at line 89 of file nsBookmarksService.h.

Definition at line 97 of file nsBookmarksService.h.

Definition at line 82 of file nsBookmarksService.h.

Definition at line 87 of file nsBookmarksService.h.

Definition at line 84 of file nsBookmarksService.h.

Definition at line 95 of file nsBookmarksService.h.

Definition at line 86 of file nsBookmarksService.h.

Definition at line 90 of file nsBookmarksService.h.

Definition at line 94 of file nsBookmarksService.h.


The documentation for this class was generated from the following files: