Bug 1602195: Show site specific browsers as separate taskbar entries on windows. r=mhowell

Gives a site specific browser window a custom model ID and adds the same model
ID to its shortcut. This makes the window appear distinct from the rest of
Firefox's windows in the taskbar and allows for pinning the new entry to the
taskbar.

Differential Revision: https://phabricator.services.mozilla.com/D56780
This commit is contained in:
Dave Townsend
2019-12-18 22:01:40 +00:00
parent 9487a03add
commit eb784a9ee1
4 changed files with 46 additions and 2 deletions

View File

@@ -9,5 +9,7 @@ interface nsIFile;
[scriptable, uuid(fb9b59db-5a91-4e67-92b6-35e7d6e6d3fd)] [scriptable, uuid(fb9b59db-5a91-4e67-92b6-35e7d6e6d3fd)]
interface nsIWindowsShellService : nsISupports interface nsIWindowsShellService : nsISupports
{ {
void createShortcut(in nsIFile aBinary, in Array<AString> aArguments, in AString aDescription, in nsIFile aIconFile, in nsIFile aTarget); void createShortcut(in nsIFile aBinary, in Array<AString> aArguments,
in AString aDescription, in nsIFile aIconFile, in AString aAppUserModelId,
in nsIFile aTarget);
}; };

View File

@@ -29,6 +29,8 @@
#include "windows.h" #include "windows.h"
#include "shellapi.h" #include "shellapi.h"
#include <propvarutil.h>
#include <propkey.h>
#ifdef _WIN32_WINNT #ifdef _WIN32_WINNT
# undef _WIN32_WINNT # undef _WIN32_WINNT
@@ -701,7 +703,9 @@ NS_IMETHODIMP
nsWindowsShellService::CreateShortcut(nsIFile* aBinary, nsWindowsShellService::CreateShortcut(nsIFile* aBinary,
const nsTArray<nsString>& aArguments, const nsTArray<nsString>& aArguments,
const nsAString& aDescription, const nsAString& aDescription,
nsIFile* aIconFile, nsIFile* aTarget) { nsIFile* aIconFile,
const nsAString& aAppUserModelId,
nsIFile* aTarget) {
NS_ENSURE_ARG(aBinary); NS_ENSURE_ARG(aBinary);
NS_ENSURE_ARG(aTarget); NS_ENSURE_ARG(aTarget);
@@ -730,6 +734,25 @@ nsWindowsShellService::CreateShortcut(nsIFile* aBinary,
link->SetIconLocation(icon.get(), 0); link->SetIconLocation(icon.get(), 0);
} }
if (!aAppUserModelId.IsEmpty()) {
RefPtr<IPropertyStore> propStore;
hr = link->QueryInterface(IID_IPropertyStore, getter_AddRefs(propStore));
NS_ENSURE_HRESULT(hr, NS_ERROR_FAILURE);
PROPVARIANT pv;
if (FAILED(InitPropVariantFromString(
PromiseFlatString(aAppUserModelId).get(), &pv))) {
return NS_ERROR_FAILURE;
}
hr = propStore->SetValue(PKEY_AppUserModel_ID, pv);
PropVariantClear(&pv);
NS_ENSURE_HRESULT(hr, NS_ERROR_FAILURE);
hr = propStore->Commit();
NS_ENSURE_HRESULT(hr, NS_ERROR_FAILURE);
}
RefPtr<IPersistFile> persist; RefPtr<IPersistFile> persist;
hr = link->QueryInterface(IID_IPersistFile, getter_AddRefs(persist)); hr = link->QueryInterface(IID_IPersistFile, getter_AddRefs(persist));
NS_ENSURE_HRESULT(hr, NS_ERROR_FAILURE); NS_ENSURE_HRESULT(hr, NS_ERROR_FAILURE);

View File

@@ -25,12 +25,24 @@ const uiUtils = Cc["@mozilla.org/windows-ui-utils;1"].getService(
Ci.nsIWindowsUIUtils Ci.nsIWindowsUIUtils
); );
const taskbar = Cc["@mozilla.org/windows-taskbar;1"].getService(
Ci.nsIWinTaskbar
);
const File = Components.Constructor( const File = Components.Constructor(
"@mozilla.org/file/local;1", "@mozilla.org/file/local;1",
Ci.nsIFile, Ci.nsIFile,
"initWithPath" "initWithPath"
); );
function buildGroupId(id) {
try {
return `${taskbar.defaultGroupId}.ssb.${id}`;
} catch (e) {
return `Firefox.ssb.${id}`;
}
}
const WindowsSupport = { const WindowsSupport = {
/** /**
* Installs an SSB by creating a shortcut to launch it on the user's desktop. * Installs an SSB by creating a shortcut to launch it on the user's desktop.
@@ -71,6 +83,7 @@ const WindowsSupport = {
["-profile", OS.Constants.Path.profileDir, "-start-ssb", ssb.id], ["-profile", OS.Constants.Path.profileDir, "-start-ssb", ssb.id],
ssb.name, ssb.name,
iconFile, iconFile,
buildGroupId(ssb.id),
new File(link) new File(link)
); );
}, },
@@ -141,5 +154,7 @@ const WindowsSupport = {
if (icons[0] || icons[1]) { if (icons[0] || icons[1]) {
uiUtils.setWindowIcon(window, icons[0], icons[1]); uiUtils.setWindowIcon(window, icons[0], icons[1]);
} }
taskbar.setGroupIdForWindow(window, buildGroupId(ssb.id));
}, },
}; };

View File

@@ -29,6 +29,10 @@ XPCOMUtils.defineLazyModuleGetters(this, {
AppConstants: "resource://gre/modules/AppConstants.jsm", AppConstants: "resource://gre/modules/AppConstants.jsm",
}); });
let xreDirProvider = Cc["@mozilla.org/xre/directory-provider;1"].getService(
Ci.nsIXREDirProvider
);
const SSB_STORE_PREFIX = "ssb:"; const SSB_STORE_PREFIX = "ssb:";
const uri = spec => Services.io.newURI(spec); const uri = spec => Services.io.newURI(spec);