bool nsWindowsShellService::IsDefaultClientVista(uint16_t aApps, bool* aIsDefaultClient) { IApplicationAssociationRegistration* pAAR; HRESULT hr = CoCreateInstance (CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC, IID_IApplicationAssociationRegistration, (void**)&pAAR); if (SUCCEEDED(hr)) { BOOL isDefaultMail = true; BOOL isDefaultNews = true; if (aApps & nsIShellService::MAIL) pAAR->QueryAppIsDefaultAll(AL_EFFECTIVE, APP_REG_NAME_MAIL, &isDefaultMail); if (aApps & nsIShellService::NEWS) pAAR->QueryAppIsDefaultAll(AL_EFFECTIVE, APP_REG_NAME_NEWS, &isDefaultNews); *aIsDefaultClient = isDefaultNews && isDefaultMail; pAAR->Release(); return true; } return false; }
bool nsWindowsShellService::IsDefaultClientVista(PRUint16 aApps, bool* aIsDefaultClient) { #if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_LONGHORN IApplicationAssociationRegistration* pAAR; HRESULT hr = CoCreateInstance (CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC, IID_IApplicationAssociationRegistration, (void**)&pAAR); if (SUCCEEDED(hr)) { BOOL isDefaultMail = true; BOOL isDefaultNews = true; if (aApps & nsIShellService::MAIL) pAAR->QueryAppIsDefaultAll(AL_EFFECTIVE, APP_REG_NAME_MAIL, &isDefaultMail); if (aApps & nsIShellService::NEWS) pAAR->QueryAppIsDefaultAll(AL_EFFECTIVE, APP_REG_NAME_NEWS, &isDefaultNews); *aIsDefaultClient = isDefaultNews && isDefaultMail; pAAR->Release(); return PR_TRUE; } #endif return PR_FALSE; }
PRBool nsWindowsShellService::IsDefaultClientVista(PRUint16 aApps, PRBool* aIsDefaultClient) { #if !defined(MOZ_DISABLE_VISTA_SDK_REQUIREMENTS) IApplicationAssociationRegistration* pAAR; HRESULT hr = CoCreateInstance (CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC, IID_IApplicationAssociationRegistration, (void**)&pAAR); if (SUCCEEDED(hr)) { PRBool isDefaultMail = PR_TRUE; PRBool isDefaultNews = PR_TRUE; if (aApps & nsIShellService::MAIL) pAAR->QueryAppIsDefaultAll(AL_EFFECTIVE, APP_REG_NAME_MAIL, &isDefaultMail); if (aApps & nsIShellService::NEWS) pAAR->QueryAppIsDefaultAll(AL_EFFECTIVE, APP_REG_NAME_NEWS, &isDefaultNews); *aIsDefaultClient = isDefaultNews && isDefaultMail; pAAR->Release(); return PR_TRUE; } #endif return PR_FALSE; }
bool IsDefaultBrowser() { IApplicationAssociationRegistration* pAAR; HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC, IID_IApplicationAssociationRegistration, (void**)&pAAR); 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 false; } // 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; }
void RegisterQAppAssociation::registerAssociation(const QString &assocName, AssociationType type) { if (isVistaOrNewer()) { // Vista and newer IApplicationAssociationRegistration* pAAR; HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC, __uuidof(IApplicationAssociationRegistration), (void**)&pAAR); if (SUCCEEDED(hr)) { switch (type) { case FileAssociation: hr = pAAR->SetAppAsDefault(_appRegisteredName.toStdWString().c_str(), assocName.toStdWString().c_str(), AT_FILEEXTENSION); break; case UrlAssociation: { QSettings regCurrentUserRoot("HKEY_CURRENT_USER", QSettings::NativeFormat); QString currentUrlDefault = regCurrentUserRoot.value("Software/Microsoft/Windows/Shell/Associations/UrlAssociations/" + assocName + "/UserChoice/Progid").toString(); hr = pAAR->SetAppAsDefault(_appRegisteredName.toStdWString().c_str(), assocName.toStdWString().c_str(), AT_URLPROTOCOL); if (SUCCEEDED(hr) && !currentUrlDefault.isEmpty() && currentUrlDefault != _urlAssocHash.value(assocName)) { regCurrentUserRoot.setValue("Software/Classes" + assocName + "/shell/open/command/backup_progid", currentUrlDefault); } } break; default: break; } pAAR->Release(); } } else { // Older than Vista QSettings regUserRoot(_UserRootKey, QSettings::NativeFormat); regUserRoot.beginGroup("Software/Classes"); QSettings regClassesRoot("HKEY_CLASSES_ROOT", QSettings::NativeFormat); switch (type) { case FileAssociation: { QString progId = _fileAssocHash.value(assocName); createProgId(progId); QString currentDefault = regClassesRoot.value(assocName + "/Default").toString(); if (!currentDefault.isEmpty() && currentDefault != progId && regUserRoot.value(assocName + "/backup_val").toString() != progId) { regUserRoot.setValue(assocName + "/backup_val", currentDefault); } regUserRoot.setValue(assocName + "/.", progId); } break; case UrlAssociation: { QString progId = _urlAssocHash.value(assocName); createProgId(progId); QString currentDefault = regClassesRoot.value(assocName + "/shell/open/command/Default").toString(); QString command = "\"" + _appPath + "\" \"%1\""; if (!currentDefault.isEmpty() && currentDefault != command && regUserRoot.value(assocName + "/shell/open/command/backup_val").toString() != command) { regUserRoot.setValue(assocName + "/shell/open/command/backup_val", currentDefault); } regUserRoot.setValue(assocName + "/shell/open/command/.", command); regUserRoot.setValue(assocName + "/URL Protocol", ""); break; } default: break; } regUserRoot.endGroup(); } }