mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-05 05:30:29 +00:00
Bug 872012 - Get default browser's path from the association when launching on the desktop. r=jmathies
This commit is contained in:
parent
c366ed8bab
commit
97c862423c
@ -37,6 +37,9 @@ static const WCHAR* kFirefoxExe = L"firefox.exe";
|
||||
static const WCHAR* kMetroFirefoxExe = L"firefox.exe";
|
||||
static const WCHAR* kDefaultMetroBrowserIDPathKey = L"FirefoxURL";
|
||||
|
||||
static bool GetDesktopBrowserPath(CStringW& aPathBuffer);
|
||||
static bool GetDefaultBrowserPath(CStringW& aPathBuffer);
|
||||
|
||||
template <class T>void SafeRelease(T **ppT)
|
||||
{
|
||||
if (*ppT) {
|
||||
@ -278,38 +281,49 @@ public:
|
||||
|
||||
bool IsDefaultBrowser()
|
||||
{
|
||||
bool result = false;
|
||||
IApplicationAssociationRegistration* pAAR;
|
||||
HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration,
|
||||
NULL,
|
||||
CLSCTX_INPROC,
|
||||
IID_IApplicationAssociationRegistration,
|
||||
(void**)&pAAR);
|
||||
if (SUCCEEDED(hr)) {
|
||||
BOOL res;
|
||||
hr = pAAR->QueryAppIsDefaultAll(AL_EFFECTIVE,
|
||||
APP_REG_NAME,
|
||||
&res);
|
||||
Log(L"QueryAppIsDefaultAll: %d", res);
|
||||
if (!res)
|
||||
return false;
|
||||
// Make sure the Prog ID matches what we have
|
||||
LPWSTR registeredApp;
|
||||
hr = pAAR->QueryCurrentDefault(L"http", AT_URLPROTOCOL, AL_EFFECTIVE,
|
||||
®isteredApp);
|
||||
Log(L"QueryCurrentDefault: %X", hr);
|
||||
if (SUCCEEDED(hr)) {
|
||||
Log(L"registeredApp=%s", registeredApp);
|
||||
result = !wcsicmp(registeredApp, kDefaultMetroBrowserIDPathKey);
|
||||
CoTaskMemFree(registeredApp);
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
if (FAILED(hr))
|
||||
return false;
|
||||
|
||||
BOOL res = FALSE;
|
||||
hr = pAAR->QueryAppIsDefaultAll(AL_EFFECTIVE,
|
||||
APP_REG_NAME,
|
||||
&res);
|
||||
Log(L"QueryAppIsDefaultAll: %d", res);
|
||||
if (!res) {
|
||||
pAAR->Release();
|
||||
return result;
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
// Make sure the Prog ID matches what we have
|
||||
LPWSTR registeredApp;
|
||||
hr = pAAR->QueryCurrentDefault(L"http", AT_URLPROTOCOL, AL_EFFECTIVE,
|
||||
®isteredApp);
|
||||
pAAR->Release();
|
||||
Log(L"QueryCurrentDefault: %X", hr);
|
||||
if (FAILED(hr))
|
||||
return false;
|
||||
|
||||
Log(L"registeredApp=%s", registeredApp);
|
||||
bool result = !wcsicmp(registeredApp, kDefaultMetroBrowserIDPathKey);
|
||||
CoTaskMemFree(registeredApp);
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
// If the registry points another browser's path,
|
||||
// activating the Metro browser will fail. So fallback to the desktop.
|
||||
CStringW selfPath;
|
||||
GetDesktopBrowserPath(selfPath);
|
||||
selfPath.MakeLower();
|
||||
CStringW browserPath;
|
||||
GetDefaultBrowserPath(browserPath);
|
||||
browserPath.MakeLower();
|
||||
|
||||
return selfPath == browserPath;
|
||||
}
|
||||
private:
|
||||
~CExecuteCommandVerb()
|
||||
@ -375,6 +389,32 @@ static bool GetDesktopBrowserPath(CStringW& aPathBuffer)
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Retrieve the current default browser's path.
|
||||
*
|
||||
* @aPathBuffer Buffer to fill
|
||||
*/
|
||||
static bool GetDefaultBrowserPath(CStringW& aPathBuffer)
|
||||
{
|
||||
WCHAR buffer[MAX_PATH];
|
||||
DWORD length = MAX_PATH;
|
||||
|
||||
if (FAILED(AssocQueryStringW(ASSOCF_NOTRUNCATE | ASSOCF_INIT_IGNOREUNKNOWN,
|
||||
ASSOCSTR_EXECUTABLE,
|
||||
kDefaultMetroBrowserIDPathKey, NULL,
|
||||
buffer, &length))) {
|
||||
Log(L"AssocQueryString failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// sanity check
|
||||
if (lstrcmpiW(PathFindFileNameW(buffer), kFirefoxExe))
|
||||
return false;
|
||||
|
||||
aPathBuffer = buffer;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Retrieve the app model id of the firefox metro browser.
|
||||
*
|
||||
@ -540,6 +580,8 @@ void CExecuteCommandVerb::LaunchDesktopBrowser()
|
||||
// be the browser exe or file.
|
||||
CStringW params;
|
||||
if (!IsTargetBrowser()) {
|
||||
// Fallback to the module path if it failed to get the default browser.
|
||||
GetDefaultBrowserPath(browserPath);
|
||||
params += "-url ";
|
||||
params += "\"";
|
||||
params += mTarget;
|
||||
|
Loading…
x
Reference in New Issue
Block a user