Bug 1522694: Add a toolkit level API for determining if this is the default instance of the application. r=mconley

This also switches around a few preprocessor lines to make more sense.

Differential Revision: https://phabricator.services.mozilla.com/D17557

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dave Townsend 2019-01-25 20:03:15 +00:00
parent 88359867bd
commit 26e0f46fb1
12 changed files with 84 additions and 28 deletions

View File

@ -15,6 +15,7 @@
#elif defined(MOZ_WIDGET_GTK)
# include "nsGNOMEShellService.h"
#endif
#include "nsIToolkitShellService.h"
#if defined(MOZ_WIDGET_COCOA)
# include "nsMacAttribution.h"
@ -51,16 +52,12 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsIEHistoryEnumerator)
#endif
NS_DEFINE_NAMED_CID(NS_BROWSERDIRECTORYPROVIDER_CID);
#if defined(XP_WIN)
NS_DEFINE_NAMED_CID(NS_SHELLSERVICE_CID);
#elif defined(MOZ_WIDGET_GTK)
#if defined(XP_WIN) || defined(MOZ_WIDGET_GTK) || defined(XP_MACOSX)
NS_DEFINE_NAMED_CID(NS_SHELLSERVICE_CID);
#endif
NS_DEFINE_NAMED_CID(NS_BROWSER_ABOUT_REDIRECTOR_CID);
#if defined(XP_WIN)
NS_DEFINE_NAMED_CID(NS_WINIEHISTORYENUMERATOR_CID);
#elif defined(XP_MACOSX)
NS_DEFINE_NAMED_CID(NS_SHELLSERVICE_CID);
#endif
#if defined(MOZ_WIDGET_COCOA)
NS_DEFINE_NAMED_CID(NS_MACATTRIBUTIONSERVICE_CID);
@ -73,12 +70,12 @@ static const mozilla::Module::CIDEntry kBrowserCIDs[] = {
{ &kNS_SHELLSERVICE_CID, false, nullptr, nsWindowsShellServiceConstructor },
#elif defined(MOZ_WIDGET_GTK)
{ &kNS_SHELLSERVICE_CID, false, nullptr, nsGNOMEShellServiceConstructor },
#elif defined(XP_MACOSX)
{ &kNS_SHELLSERVICE_CID, false, nullptr, nsMacShellServiceConstructor },
#endif
{ &kNS_BROWSER_ABOUT_REDIRECTOR_CID, false, nullptr, AboutRedirector::Create },
#if defined(XP_WIN)
{ &kNS_WINIEHISTORYENUMERATOR_CID, false, nullptr, nsIEHistoryEnumeratorConstructor },
#elif defined(XP_MACOSX)
{ &kNS_SHELLSERVICE_CID, false, nullptr, nsMacShellServiceConstructor },
#endif
#if defined(MOZ_WIDGET_COCOA)
{ &kNS_MACATTRIBUTIONSERVICE_CID, false, nullptr, nsMacAttributionServiceConstructor },
@ -90,10 +87,9 @@ static const mozilla::Module::CIDEntry kBrowserCIDs[] = {
static const mozilla::Module::ContractIDEntry kBrowserContracts[] = {
// clang-format off
{ NS_BROWSERDIRECTORYPROVIDER_CONTRACTID, &kNS_BROWSERDIRECTORYPROVIDER_CID },
#if defined(XP_WIN)
{ NS_SHELLSERVICE_CONTRACTID, &kNS_SHELLSERVICE_CID },
#elif defined(MOZ_WIDGET_GTK)
#if defined(XP_WIN) || defined(MOZ_WIDGET_GTK) || defined(XP_MACOSX)
{ NS_SHELLSERVICE_CONTRACTID, &kNS_SHELLSERVICE_CID },
{ NS_TOOLKITSHELLSERVICE_CONTRACTID, &kNS_SHELLSERVICE_CID },
#endif
{ NS_ABOUT_MODULE_CONTRACTID_PREFIX "blocked", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
{ NS_ABOUT_MODULE_CONTRACTID_PREFIX "certerror", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
@ -117,8 +113,6 @@ static const mozilla::Module::ContractIDEntry kBrowserContracts[] = {
{ NS_ABOUT_MODULE_CONTRACTID_PREFIX "pocket-signup", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
#if defined(XP_WIN)
{ NS_IEHISTORYENUMERATOR_CONTRACTID, &kNS_WINIEHISTORYENUMERATOR_CID },
#elif defined(XP_MACOSX)
{ NS_SHELLSERVICE_CONTRACTID, &kNS_SHELLSERVICE_CID },
#endif
#if defined(MOZ_WIDGET_COCOA)
{ NS_MACATTRIBUTIONSERVICE_CONTRACTID, &kNS_MACATTRIBUTIONSERVICE_CID },

View File

@ -23,28 +23,27 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
XPIDL_SOURCES += [
'nsIMacShellService.idl',
]
SOURCES += [
'nsMacShellService.cpp',
]
elif 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
XPIDL_SOURCES += [
'nsIGNOMEShellService.idl',
]
XPIDL_MODULE = 'shellservice'
if CONFIG['OS_ARCH'] == 'WINNT':
SOURCES += [
'nsGNOMEShellService.cpp',
]
elif CONFIG['OS_ARCH'] == 'WINNT':
SOURCES += [
'nsWindowsShellService.cpp',
]
LOCAL_INCLUDES += [
'../../../other-licenses/nsis/Contrib/CityHash/cityhash',
]
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
SOURCES += [
'nsMacShellService.cpp',
]
elif 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
SOURCES += [
'nsGNOMEShellService.cpp',
]
XPIDL_MODULE = 'shellservice'
if SOURCES:
FINAL_LIBRARY = 'browsercomps'

View File

@ -121,7 +121,8 @@ nsresult nsGNOMEShellService::Init() {
return appPath->GetNativePath(mAppPath);
}
NS_IMPL_ISUPPORTS(nsGNOMEShellService, nsIGNOMEShellService, nsIShellService)
NS_IMPL_ISUPPORTS(nsGNOMEShellService, nsIGNOMEShellService, nsIShellService,
nsIToolkitShellService)
bool nsGNOMEShellService::GetAppPathFromLauncher() {
gchar *tmp;

View File

@ -7,10 +7,12 @@
#define nsgnomeshellservice_h____
#include "nsIGNOMEShellService.h"
#include "nsToolkitShellService.h"
#include "nsString.h"
#include "mozilla/Attributes.h"
class nsGNOMEShellService final : public nsIGNOMEShellService {
class nsGNOMEShellService final : public nsIGNOMEShellService,
public nsToolkitShellService {
public:
nsGNOMEShellService() : mAppIsInPath(false) {}

View File

@ -37,7 +37,7 @@ using mozilla::dom::Element;
#define SAFARI_BUNDLE_IDENTIFIER "com.apple.Safari"
NS_IMPL_ISUPPORTS(nsMacShellService, nsIMacShellService, nsIShellService,
nsIWebProgressListener)
nsIToolkitShellService, nsIWebProgressListener)
NS_IMETHODIMP
nsMacShellService::IsDefaultBrowser(bool aForAllTypes,

View File

@ -6,12 +6,14 @@
#ifndef nsmacshellservice_h____
#define nsmacshellservice_h____
#include "nsToolkitShellService.h"
#include "nsIMacShellService.h"
#include "nsIWebProgressListener.h"
#include "nsIFile.h"
#include "nsCOMPtr.h"
class nsMacShellService : public nsIMacShellService,
public nsToolkitShellService,
public nsIWebProgressListener {
public:
nsMacShellService(){};

View File

@ -0,0 +1,22 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#ifndef nstoolkitshellservice_h____
#define nstoolkitshellservice_h____
#include "nsIToolkitShellService.h"
class nsToolkitShellService : public nsIToolkitShellService {
public:
NS_IMETHOD IsDefaultBrowser(bool aForAllTypes,
bool* aIsDefaultBrowser) = 0;
NS_IMETHODIMP IsDefaultApplication(bool* aIsDefaultBrowser) {
// Only care about the http(s) protocol. This only matters on Windows.
return IsDefaultBrowser(false, aIsDefaultBrowser);
}
};
#endif // nstoolkitshellservice_h____

View File

@ -66,7 +66,7 @@ using mozilla::IsWin8OrLater;
using namespace mozilla;
using namespace mozilla::widget;
NS_IMPL_ISUPPORTS(nsWindowsShellService, nsIShellService)
NS_IMPL_ISUPPORTS(nsWindowsShellService, nsIToolkitShellService, nsIShellService)
static nsresult OpenKeyForReading(HKEY aKeyRoot, const nsAString& aKeyName,
HKEY* aKey) {

View File

@ -8,12 +8,14 @@
#include "nscore.h"
#include "nsString.h"
#include "nsToolkitShellService.h"
#include "nsIShellService.h"
#include <windows.h>
#include <ole2.h>
class nsWindowsShellService : public nsIShellService {
class nsWindowsShellService : public nsIShellService,
public nsToolkitShellService {
virtual ~nsWindowsShellService();
public:

View File

@ -61,6 +61,7 @@ DIRS += [
'resistfingerprinting',
'securityreporter',
'sessionstore',
'shell',
'startup',
'statusfilter',
'telemetry',

View File

@ -0,0 +1,11 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
XPIDL_SOURCES += [
'nsIToolkitShellService.idl',
]
XPIDL_MODULE = 'toolkit_shell'

View File

@ -0,0 +1,22 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "nsISupports.idl"
[scriptable, uuid(9246cad6-926a-4c17-88b0-ecba8078d143)]
interface nsIToolkitShellService : nsISupports
{
/**
* Determines whether or not this application is the default for the operating
* system. It is up to the application to determine how to answer this
* question but it would typically involve checking if it is registered as the
* default handler for web protocols and/or file types.
*/
boolean isDefaultApplication();
};
%{ C++
#define NS_TOOLKITSHELLSERVICE_CONTRACTID "@mozilla.org/toolkit/shell-service;1"
%}