2009-10-06 14:42:45 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-10-06 14:42:45 -07:00
|
|
|
|
|
|
|
#include "JumpListBuilder.h"
|
|
|
|
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsArrayUtils.h"
|
|
|
|
#include "nsIMutableArray.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
2010-05-14 17:23:14 -07:00
|
|
|
#include "WinTaskbar.h"
|
2011-09-06 12:11:28 -07:00
|
|
|
#include "nsDirectoryServiceUtils.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2011-09-06 12:11:28 -07:00
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "imgITools.h"
|
|
|
|
#include "nsStringStream.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2012-03-06 12:42:53 -08:00
|
|
|
#include "mozilla/LazyIdleThread.h"
|
|
|
|
|
2012-07-21 13:07:26 -07:00
|
|
|
#include "WinUtils.h"
|
|
|
|
|
2012-03-06 12:42:53 -08:00
|
|
|
// The amount of time, in milliseconds, that our IO thread will stay alive after the last event it processes.
|
|
|
|
#define DEFAULT_THREAD_TIMEOUT_MS 30000
|
2009-10-06 14:42:45 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kJumpListItemCID, NS_WIN_JUMPLISTITEM_CID);
|
|
|
|
static NS_DEFINE_CID(kJumpListLinkCID, NS_WIN_JUMPLISTLINK_CID);
|
|
|
|
static NS_DEFINE_CID(kJumpListShortcutCID, NS_WIN_JUMPLISTSHORTCUT_CID);
|
|
|
|
|
|
|
|
// defined in WinTaskbar.cpp
|
|
|
|
extern const wchar_t *gMozillaJumpListIDGeneric;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool JumpListBuilder::sBuildingList = false;
|
2011-09-06 12:11:28 -07:00
|
|
|
const char kPrefTaskbarEnabled[] = "browser.taskbar.lists.enabled";
|
2009-10-06 14:42:45 -07:00
|
|
|
|
2011-09-06 12:11:28 -07:00
|
|
|
NS_IMPL_ISUPPORTS2(JumpListBuilder, nsIJumpListBuilder, nsIObserver)
|
2009-10-06 14:42:45 -07:00
|
|
|
|
|
|
|
JumpListBuilder::JumpListBuilder() :
|
|
|
|
mMaxItems(0),
|
2011-10-01 19:16:19 -07:00
|
|
|
mHasCommit(false)
|
2009-10-06 14:42:45 -07:00
|
|
|
{
|
|
|
|
::CoInitialize(NULL);
|
|
|
|
|
|
|
|
CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
IID_ICustomDestinationList, getter_AddRefs(mJumpListMgr));
|
2011-09-06 12:11:28 -07:00
|
|
|
|
2012-03-06 12:42:53 -08:00
|
|
|
// Make a lazy thread for any IO
|
2012-06-12 10:06:20 -07:00
|
|
|
mIOThread = new LazyIdleThread(DEFAULT_THREAD_TIMEOUT_MS,
|
|
|
|
NS_LITERAL_CSTRING("Jump List"),
|
|
|
|
LazyIdleThread::ManualShutdown);
|
2011-09-06 12:11:28 -07:00
|
|
|
Preferences::AddStrongObserver(this, kPrefTaskbarEnabled);
|
2009-10-06 14:42:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JumpListBuilder::~JumpListBuilder()
|
|
|
|
{
|
2011-09-06 12:11:28 -07:00
|
|
|
mIOThread->Shutdown();
|
2011-09-06 12:11:28 -07:00
|
|
|
Preferences::RemoveObserver(this, kPrefTaskbarEnabled);
|
2009-10-06 14:42:45 -07:00
|
|
|
mJumpListMgr = nsnull;
|
|
|
|
::CoUninitialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute short available; */
|
|
|
|
NS_IMETHODIMP JumpListBuilder::GetAvailable(PRInt16 *aAvailable)
|
|
|
|
{
|
2011-10-01 19:16:19 -07:00
|
|
|
*aAvailable = false;
|
2009-10-06 14:42:45 -07:00
|
|
|
|
|
|
|
if (mJumpListMgr)
|
2011-10-01 19:16:19 -07:00
|
|
|
*aAvailable = true;
|
2009-10-06 14:42:45 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute boolean isListCommitted; */
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP JumpListBuilder::GetIsListCommitted(bool *aCommit)
|
2009-10-06 14:42:45 -07:00
|
|
|
{
|
|
|
|
*aCommit = mHasCommit;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute short maxItems; */
|
|
|
|
NS_IMETHODIMP JumpListBuilder::GetMaxListItems(PRInt16 *aMaxItems)
|
|
|
|
{
|
|
|
|
if (!mJumpListMgr)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
*aMaxItems = 0;
|
|
|
|
|
|
|
|
if (sBuildingList) {
|
|
|
|
*aMaxItems = mMaxItems;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
IObjectArray *objArray;
|
|
|
|
if (SUCCEEDED(mJumpListMgr->BeginList(&mMaxItems, IID_PPV_ARGS(&objArray)))) {
|
|
|
|
*aMaxItems = mMaxItems;
|
|
|
|
|
|
|
|
if (objArray)
|
|
|
|
objArray->Release();
|
|
|
|
|
|
|
|
mJumpListMgr->AbortList();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* boolean initListBuild(in nsIMutableArray removedItems); */
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP JumpListBuilder::InitListBuild(nsIMutableArray *removedItems, bool *_retval)
|
2009-10-06 14:42:45 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(removedItems);
|
|
|
|
|
2011-10-01 19:16:19 -07:00
|
|
|
*_retval = false;
|
2009-10-06 14:42:45 -07:00
|
|
|
|
|
|
|
if (!mJumpListMgr)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
if(sBuildingList)
|
|
|
|
AbortListBuild();
|
|
|
|
|
|
|
|
IObjectArray *objArray;
|
|
|
|
|
|
|
|
if (SUCCEEDED(mJumpListMgr->BeginList(&mMaxItems, IID_PPV_ARGS(&objArray)))) {
|
|
|
|
if (objArray) {
|
|
|
|
TransferIObjectArrayToIMutableArray(objArray, removedItems);
|
|
|
|
objArray->Release();
|
|
|
|
}
|
2011-09-06 12:11:28 -07:00
|
|
|
|
|
|
|
RemoveIconCacheForItems(removedItems);
|
|
|
|
|
2011-10-01 19:16:19 -07:00
|
|
|
sBuildingList = true;
|
|
|
|
*_retval = true;
|
2009-10-06 14:42:45 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-06 12:11:28 -07:00
|
|
|
// Ensures that we don't have old ICO files that aren't in our jump lists
|
|
|
|
// anymore left over in the cache.
|
|
|
|
nsresult JumpListBuilder::RemoveIconCacheForItems(nsIMutableArray *items)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(items);
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
PRUint32 length;
|
|
|
|
items->GetLength(&length);
|
|
|
|
for (PRUint32 i = 0; i < length; ++i) {
|
|
|
|
|
|
|
|
//Obtain an IJumpListItem and get the type
|
|
|
|
nsCOMPtr<nsIJumpListItem> item = do_QueryElementAt(items, i);
|
|
|
|
if (!item) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
PRInt16 type;
|
|
|
|
if (NS_FAILED(item->GetType(&type))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the item is a shortcut, remove its associated icon if any
|
|
|
|
if (type == nsIJumpListItem::JUMPLIST_ITEM_SHORTCUT) {
|
|
|
|
nsCOMPtr<nsIJumpListShortcut> shortcut = do_QueryInterface(item);
|
|
|
|
if (shortcut) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2011-09-06 12:11:28 -07:00
|
|
|
rv = shortcut->GetFaviconPageUri(getter_AddRefs(uri));
|
2011-09-06 12:11:28 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && uri) {
|
2011-09-06 12:11:28 -07:00
|
|
|
|
|
|
|
// The local file path is stored inside the nsIURI
|
|
|
|
// Get the nsIURI spec which stores the local path for the icon to remove
|
|
|
|
nsCAutoString spec;
|
|
|
|
nsresult rv = uri->GetSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> event
|
2012-07-21 13:07:26 -07:00
|
|
|
= new mozilla::widget::AsyncDeleteIconFromDisk(NS_ConvertUTF8toUTF16(spec));
|
2011-09-06 12:11:28 -07:00
|
|
|
mIOThread->Dispatch(event, NS_DISPATCH_NORMAL);
|
2011-09-06 12:11:28 -07:00
|
|
|
|
|
|
|
// The shortcut was generated from an IShellLinkW so IShellLinkW can
|
|
|
|
// only tell us what the original icon is and not the URI.
|
|
|
|
// So this field was used only temporarily as the actual icon file
|
|
|
|
// path. It should be cleared.
|
2011-09-06 12:11:28 -07:00
|
|
|
shortcut->SetFaviconPageUri(nsnull);
|
2011-09-06 12:11:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end for
|
2011-09-06 12:11:28 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
2011-09-06 12:11:28 -07:00
|
|
|
}
|
|
|
|
|
2011-09-06 12:11:28 -07:00
|
|
|
// Ensures that we have no old ICO files left in the jump list cache
|
|
|
|
nsresult JumpListBuilder::RemoveIconCacheForAllItems()
|
|
|
|
{
|
|
|
|
// Construct the path of our jump list cache
|
|
|
|
nsCOMPtr<nsIFile> jumpListCacheDir;
|
|
|
|
nsresult rv = NS_GetSpecialDirectory("ProfLDS",
|
|
|
|
getter_AddRefs(jumpListCacheDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-07-21 13:07:26 -07:00
|
|
|
rv = jumpListCacheDir->AppendNative(nsDependentCString(
|
|
|
|
mozilla::widget::FaviconHelper::kJumpListCacheDir));
|
2011-09-06 12:11:28 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> entries;
|
|
|
|
rv = jumpListCacheDir->GetDirectoryEntries(getter_AddRefs(entries));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Loop through each directory entry and remove all ICO files found
|
|
|
|
do {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasMore = false;
|
2011-09-06 12:11:28 -07:00
|
|
|
if (NS_FAILED(entries->HasMoreElements(&hasMore)) || !hasMore)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> supp;
|
|
|
|
if (NS_FAILED(entries->GetNext(getter_AddRefs(supp))))
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> currFile(do_QueryInterface(supp));
|
|
|
|
nsAutoString path;
|
|
|
|
if (NS_FAILED(currFile->GetPath(path)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
PRInt32 len = path.Length();
|
|
|
|
if (StringTail(path, 4).LowerCaseEqualsASCII(".ico")) {
|
|
|
|
// Check if the cached ICO file exists
|
2011-09-28 23:19:26 -07:00
|
|
|
bool exists;
|
2011-09-06 12:11:28 -07:00
|
|
|
if (NS_FAILED(currFile->Exists(&exists)) || !exists)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// We found an ICO file that exists, so we should remove it
|
2011-10-01 19:16:19 -07:00
|
|
|
currFile->Remove(false);
|
2011-09-06 12:11:28 -07:00
|
|
|
}
|
|
|
|
} while(true);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-06 14:42:45 -07:00
|
|
|
/* boolean addListToBuild(in short aCatType, [optional] in nsIArray items, [optional] in AString catName); */
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP JumpListBuilder::AddListToBuild(PRInt16 aCatType, nsIArray *items, const nsAString &catName, bool *_retval)
|
2009-10-06 14:42:45 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2011-10-01 19:16:19 -07:00
|
|
|
*_retval = false;
|
2009-10-06 14:42:45 -07:00
|
|
|
|
|
|
|
if (!mJumpListMgr)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
switch(aCatType) {
|
|
|
|
case nsIJumpListBuilder::JUMPLIST_CATEGORY_TASKS:
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(items);
|
|
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
nsRefPtr<IObjectCollection> collection;
|
|
|
|
hr = CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
IID_IObjectCollection, getter_AddRefs(collection));
|
|
|
|
if (FAILED(hr))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
// Build the list
|
|
|
|
PRUint32 length;
|
|
|
|
items->GetLength(&length);
|
|
|
|
for (PRUint32 i = 0; i < length; ++i) {
|
|
|
|
nsCOMPtr<nsIJumpListItem> item = do_QueryElementAt(items, i);
|
|
|
|
if (!item)
|
|
|
|
continue;
|
|
|
|
// Check for separators
|
|
|
|
if (IsSeparator(item)) {
|
|
|
|
nsRefPtr<IShellLinkW> link;
|
|
|
|
rv = JumpListSeparator::GetSeparator(link);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
collection->AddObject(link);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// These should all be ShellLinks
|
|
|
|
nsRefPtr<IShellLinkW> link;
|
2011-09-06 12:11:28 -07:00
|
|
|
rv = JumpListShortcut::GetShellLink(item, link, mIOThread);
|
2009-10-06 14:42:45 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
collection->AddObject(link);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need IObjectArray to submit
|
|
|
|
nsRefPtr<IObjectArray> pArray;
|
|
|
|
hr = collection->QueryInterface(IID_IObjectArray, getter_AddRefs(pArray));
|
|
|
|
if (FAILED(hr))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
// Add the tasks
|
|
|
|
hr = mJumpListMgr->AddUserTasks(pArray);
|
|
|
|
if (SUCCEEDED(hr))
|
2011-10-01 19:16:19 -07:00
|
|
|
*_retval = true;
|
2009-10-06 14:42:45 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsIJumpListBuilder::JUMPLIST_CATEGORY_RECENT:
|
|
|
|
{
|
|
|
|
if (SUCCEEDED(mJumpListMgr->AppendKnownCategory(KDC_RECENT)))
|
2011-10-01 19:16:19 -07:00
|
|
|
*_retval = true;
|
2009-10-06 14:42:45 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsIJumpListBuilder::JUMPLIST_CATEGORY_FREQUENT:
|
|
|
|
{
|
|
|
|
if (SUCCEEDED(mJumpListMgr->AppendKnownCategory(KDC_FREQUENT)))
|
2011-10-01 19:16:19 -07:00
|
|
|
*_retval = true;
|
2009-10-06 14:42:45 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsIJumpListBuilder::JUMPLIST_CATEGORY_CUSTOMLIST:
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(items);
|
|
|
|
|
|
|
|
if (catName.IsEmpty())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
nsRefPtr<IObjectCollection> collection;
|
|
|
|
hr = CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
IID_IObjectCollection, getter_AddRefs(collection));
|
|
|
|
if (FAILED(hr))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
PRUint32 length;
|
|
|
|
items->GetLength(&length);
|
|
|
|
for (PRUint32 i = 0; i < length; ++i) {
|
|
|
|
nsCOMPtr<nsIJumpListItem> item = do_QueryElementAt(items, i);
|
|
|
|
if (!item)
|
|
|
|
continue;
|
|
|
|
PRInt16 type;
|
|
|
|
if (NS_FAILED(item->GetType(&type)))
|
|
|
|
continue;
|
|
|
|
switch(type) {
|
|
|
|
case nsIJumpListItem::JUMPLIST_ITEM_SEPARATOR:
|
|
|
|
{
|
|
|
|
nsRefPtr<IShellLinkW> shellItem;
|
|
|
|
rv = JumpListSeparator::GetSeparator(shellItem);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
collection->AddObject(shellItem);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsIJumpListItem::JUMPLIST_ITEM_LINK:
|
|
|
|
{
|
|
|
|
nsRefPtr<IShellItem2> shellItem;
|
|
|
|
rv = JumpListLink::GetShellItem(item, shellItem);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
collection->AddObject(shellItem);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsIJumpListItem::JUMPLIST_ITEM_SHORTCUT:
|
|
|
|
{
|
|
|
|
nsRefPtr<IShellLinkW> shellItem;
|
2011-09-06 12:11:28 -07:00
|
|
|
rv = JumpListShortcut::GetShellLink(item, shellItem, mIOThread);
|
2009-10-06 14:42:45 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
collection->AddObject(shellItem);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need IObjectArray to submit
|
|
|
|
nsRefPtr<IObjectArray> pArray;
|
|
|
|
hr = collection->QueryInterface(IID_IObjectArray, (LPVOID*)&pArray);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
// Add the tasks
|
|
|
|
hr = mJumpListMgr->AppendCategory(catName.BeginReading(), pArray);
|
|
|
|
if (SUCCEEDED(hr))
|
2011-10-01 19:16:19 -07:00
|
|
|
*_retval = true;
|
2009-10-06 14:42:45 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* void abortListBuild(); */
|
|
|
|
NS_IMETHODIMP JumpListBuilder::AbortListBuild()
|
|
|
|
{
|
|
|
|
if (!mJumpListMgr)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
mJumpListMgr->AbortList();
|
2011-10-01 19:16:19 -07:00
|
|
|
sBuildingList = false;
|
2009-10-06 14:42:45 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* boolean commitListBuild(); */
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP JumpListBuilder::CommitListBuild(bool *_retval)
|
2009-10-06 14:42:45 -07:00
|
|
|
{
|
2011-10-01 19:16:19 -07:00
|
|
|
*_retval = false;
|
2009-10-06 14:42:45 -07:00
|
|
|
|
|
|
|
if (!mJumpListMgr)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
HRESULT hr = mJumpListMgr->CommitList();
|
2011-10-01 19:16:19 -07:00
|
|
|
sBuildingList = false;
|
2009-10-06 14:42:45 -07:00
|
|
|
|
|
|
|
// XXX We might want some specific error data here.
|
|
|
|
if (SUCCEEDED(hr)) {
|
2011-10-01 19:16:19 -07:00
|
|
|
*_retval = true;
|
|
|
|
mHasCommit = true;
|
2009-10-06 14:42:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* boolean deleteActiveList(); */
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP JumpListBuilder::DeleteActiveList(bool *_retval)
|
2009-10-06 14:42:45 -07:00
|
|
|
{
|
2011-10-01 19:16:19 -07:00
|
|
|
*_retval = false;
|
2009-10-06 14:42:45 -07:00
|
|
|
|
|
|
|
if (!mJumpListMgr)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
if(sBuildingList)
|
|
|
|
AbortListBuild();
|
|
|
|
|
2010-05-14 17:23:14 -07:00
|
|
|
nsAutoString uid;
|
|
|
|
if (!WinTaskbar::GetAppUserModelID(uid))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (SUCCEEDED(mJumpListMgr->DeleteList(uid.get())))
|
2011-10-01 19:16:19 -07:00
|
|
|
*_retval = true;
|
2009-10-06 14:42:45 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* internal */
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool JumpListBuilder::IsSeparator(nsCOMPtr<nsIJumpListItem>& item)
|
2009-10-06 14:42:45 -07:00
|
|
|
{
|
|
|
|
PRInt16 type;
|
|
|
|
item->GetType(&type);
|
|
|
|
if (NS_FAILED(item->GetType(&type)))
|
2011-10-01 19:16:19 -07:00
|
|
|
return false;
|
2009-10-06 14:42:45 -07:00
|
|
|
|
|
|
|
if (type == nsIJumpListItem::JUMPLIST_ITEM_SEPARATOR)
|
2011-10-01 19:16:19 -07:00
|
|
|
return true;
|
|
|
|
return false;
|
2009-10-06 14:42:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// TransferIObjectArrayToIMutableArray - used in converting removed items
|
|
|
|
// to our objects.
|
|
|
|
nsresult JumpListBuilder::TransferIObjectArrayToIMutableArray(IObjectArray *objArray, nsIMutableArray *removedItems)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(objArray);
|
|
|
|
NS_ENSURE_ARG_POINTER(removedItems);
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
PRUint32 count = 0;
|
|
|
|
objArray->GetCount(&count);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIJumpListItem> item;
|
|
|
|
|
|
|
|
for (PRUint32 idx = 0; idx < count; idx++) {
|
|
|
|
IShellLinkW * pLink = nsnull;
|
|
|
|
IShellItem * pItem = nsnull;
|
|
|
|
|
|
|
|
if (SUCCEEDED(objArray->GetAt(idx, IID_IShellLinkW, (LPVOID*)&pLink))) {
|
|
|
|
nsCOMPtr<nsIJumpListShortcut> shortcut =
|
|
|
|
do_CreateInstance(kJumpListShortcutCID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
rv = JumpListShortcut::GetJumpListShortcut(pLink, shortcut);
|
|
|
|
item = do_QueryInterface(shortcut);
|
|
|
|
}
|
|
|
|
else if (SUCCEEDED(objArray->GetAt(idx, IID_IShellItem, (LPVOID*)&pItem))) {
|
|
|
|
nsCOMPtr<nsIJumpListLink> link =
|
|
|
|
do_CreateInstance(kJumpListLinkCID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
rv = JumpListLink::GetJumpListLink(pItem, link);
|
|
|
|
item = do_QueryInterface(link);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pLink)
|
|
|
|
pLink->Release();
|
|
|
|
if (pItem)
|
|
|
|
pItem->Release();
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-10-01 19:16:19 -07:00
|
|
|
removedItems->AppendElement(item, false);
|
2009-10-06 14:42:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-06 12:11:28 -07:00
|
|
|
NS_IMETHODIMP JumpListBuilder::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
|
|
|
{
|
|
|
|
if (nsDependentString(aData).EqualsASCII(kPrefTaskbarEnabled)) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool enabled = Preferences::GetBool(kPrefTaskbarEnabled, true);
|
2011-09-06 12:11:28 -07:00
|
|
|
if (!enabled) {
|
2011-09-06 12:11:28 -07:00
|
|
|
|
2012-07-21 13:07:26 -07:00
|
|
|
nsCOMPtr<nsIRunnable> event =
|
|
|
|
new mozilla::widget::AsyncDeleteAllFaviconsFromDisk();
|
2011-09-06 12:11:28 -07:00
|
|
|
mIOThread->Dispatch(event, NS_DISPATCH_NORMAL);
|
2011-09-06 12:11:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-06 14:42:45 -07:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
|
|
|
|