Skip to content

Commit bde44fb

Browse files
committed
Backed out 3 changesets (bug 1883476, bug 1826375) for causing windows build bustages. CLOSED TREE
Backed out changeset bc8bdcfbcd9c (bug 1883476) Backed out changeset 7d6333da6d31 (bug 1826375) Backed out changeset f5f32253c79c (bug 1826375)
1 parent f2129be commit bde44fb

24 files changed

+2626
-10
lines changed

browser/app/profile/firefox.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ pref("browser.shell.checkDefaultPDF", true);
295295
// Will be set to `true` if the user indicates that they don't want to be asked
296296
// again about Firefox being their default PDF handler any more.
297297
pref("browser.shell.checkDefaultPDF.silencedByUser", false);
298+
// URL to navigate to when launching Firefox after accepting the Windows Default
299+
// Browser Agent "Set Firefox as default" call to action.
300+
pref("browser.shell.defaultBrowserAgent.thanksURL", "https://www.mozilla.org/%LOCALE%/firefox/set-as-default/thanks/");
298301
#endif
299302

300303

browser/components/BrowserContentHandler.sys.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,29 @@ nsDefaultCommandLineHandler.prototype = {
14571457
console.error(e);
14581458
}
14591459

1460+
if (
1461+
AppConstants.platform == "win" &&
1462+
cmdLine.handleFlag("to-handle-default-browser-agent", false)
1463+
) {
1464+
// The Default Browser Agent launches Firefox in response to a Windows
1465+
// native notification, but it does so in a non-standard manner.
1466+
Services.telemetry.setEventRecordingEnabled(
1467+
"browser.launched_to_handle",
1468+
true
1469+
);
1470+
Glean.browserLaunchedToHandle.systemNotification.record({
1471+
name: "default-browser-agent",
1472+
});
1473+
1474+
let thanksURI = Services.io.newURI(
1475+
Services.urlFormatter.formatURLPref(
1476+
"browser.shell.defaultBrowserAgent.thanksURL"
1477+
)
1478+
);
1479+
urilist.push(thanksURI);
1480+
principalList.push(lazy.gSystemPrincipal);
1481+
}
1482+
14601483
if (cmdLine.findFlag("screenshot", true) != -1) {
14611484
// Shouldn't have to push principal here with the screenshot flag
14621485
lazy.HeadlessShell.handleCmdLineArgs(

browser/components/tests/browser/browser.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,8 @@ skip-if = ["os == 'mac'"]
3333

3434
["browser_startup_homepage.js"]
3535

36+
["browser_system_notification_telemetry.js"]
37+
run-if = ["os == 'win'"]
38+
3639
["browser_to_handle_telemetry.js"]
3740
run-if = ["os == 'win'"]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* Any copyright is dedicated to the Public Domain.
2+
http://creativecommons.org/publicdomain/zero/1.0/ */
3+
4+
"use strict";
5+
6+
async function handleCommandLine(args, state) {
7+
let newWinPromise;
8+
let target = Services.urlFormatter.formatURLPref(
9+
"browser.shell.defaultBrowserAgent.thanksURL"
10+
);
11+
12+
const EXISTING_FILE = Cc["@mozilla.org/file/local;1"].createInstance(
13+
Ci.nsIFile
14+
);
15+
EXISTING_FILE.initWithPath(getTestFilePath("dummy.pdf"));
16+
17+
if (state == Ci.nsICommandLine.STATE_INITIAL_LAUNCH) {
18+
newWinPromise = BrowserTestUtils.waitForNewWindow({
19+
url: target, // N.b.: trailing slashes matter when matching.
20+
});
21+
}
22+
23+
let cmdLineHandler = Cc["@mozilla.org/browser/final-clh;1"].getService(
24+
Ci.nsICommandLineHandler
25+
);
26+
27+
let fakeCmdLine = Cu.createCommandLine(args, EXISTING_FILE.parent, state);
28+
cmdLineHandler.handle(fakeCmdLine);
29+
30+
if (newWinPromise) {
31+
let newWin = await newWinPromise;
32+
await BrowserTestUtils.closeWindow(newWin);
33+
} else {
34+
BrowserTestUtils.removeTab(gBrowser.selectedTab);
35+
}
36+
}
37+
38+
// Launching from the WDBA should open the "thanks" page and should send a
39+
// telemetry event.
40+
add_task(async function test_launched_to_handle_default_browser_agent() {
41+
await handleCommandLine(
42+
["-to-handle-default-browser-agent"],
43+
Ci.nsICommandLine.STATE_INITIAL_LAUNCH
44+
);
45+
46+
TelemetryTestUtils.assertEvents(
47+
[{ extra: { name: "default-browser-agent" } }],
48+
{
49+
category: "browser.launched_to_handle",
50+
method: "system_notification",
51+
object: "toast",
52+
}
53+
);
54+
});

browser/config/mozconfigs/win32/mingwclang

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ac_add_options --enable-disk-remnant-avoidance
3232
ac_add_options --disable-webrtc # Bug 1393901
3333
ac_add_options --disable-geckodriver # Bug 1489320
3434
ac_add_options --disable-update-agent # Bug 1561797
35-
ac_add_options --disable-default-browser-agent # Relies on toast notifications which don't build on mingw.
35+
ac_add_options --disable-default-browser-agent # WinToast does not build on mingw
3636
ac_add_options --disable-notification-server # Toast notifications don't build on mingw.
3737

3838
# Find our toolchain

browser/config/mozconfigs/win64/mingwclang

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ac_add_options --enable-disk-remnant-avoidance
3232
ac_add_options --disable-webrtc # Bug 1393901
3333
ac_add_options --disable-geckodriver # Bug 1489320
3434
ac_add_options --disable-update-agent # Bug 1561797
35-
ac_add_options --disable-default-browser-agent # Relies on toast notifications which don't build on mingw.
35+
ac_add_options --disable-default-browser-agent # WinToast does not build on mingw
3636
ac_add_options --disable-notification-server # Toast notifications don't build on mingw.
3737

3838
# Find our toolchain

third_party/WinToast/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2016 Mohammed Boujemaoui Boulaghmoudi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
diff --git a/src/wintoastlib.cpp b/src/wintoastlib.cpp
2+
index 0895ff7..ac8d5cf 100644
3+
--- a/src/wintoastlib.cpp
4+
+++ b/src/wintoastlib.cpp
5+
@@ -213,8 +213,8 @@ namespace Util {
6+
}
7+
8+
9+
- inline HRESULT defaultShellLinksDirectory(_In_ WCHAR* path, _In_ DWORD nSize = MAX_PATH) {
10+
- DWORD written = GetEnvironmentVariableW(L"APPDATA", path, nSize);
11+
+ inline HRESULT commonShellLinksDirectory(_In_ const WCHAR* baseEnv, _In_ WCHAR* path, _In_ DWORD nSize) {
12+
+ DWORD written = GetEnvironmentVariableW(baseEnv, path, nSize);
13+
HRESULT hr = written > 0 ? S_OK : E_INVALIDARG;
14+
if (SUCCEEDED(hr)) {
15+
errno_t result = wcscat_s(path, nSize, DEFAULT_SHELL_LINKS_PATH);
16+
@@ -224,8 +224,8 @@ namespace Util {
17+
return hr;
18+
}
19+
20+
- inline HRESULT defaultShellLinkPath(const std::wstring& appname, _In_ WCHAR* path, _In_ DWORD nSize = MAX_PATH) {
21+
- HRESULT hr = defaultShellLinksDirectory(path, nSize);
22+
+ inline HRESULT commonShellLinkPath(_In_ const WCHAR* baseEnv, const std::wstring& appname, _In_ WCHAR* path, _In_ DWORD nSize) {
23+
+ HRESULT hr = commonShellLinksDirectory(baseEnv, path, nSize);
24+
if (SUCCEEDED(hr)) {
25+
const std::wstring appLink(appname + DEFAULT_LINK_FORMAT);
26+
errno_t result = wcscat_s(path, nSize, appLink.c_str());
27+
@@ -235,6 +235,13 @@ namespace Util {
28+
return hr;
29+
}
30+
31+
+ inline HRESULT defaultUserShellLinkPath(const std::wstring& appname, _In_ WCHAR* path, _In_ DWORD nSize = MAX_PATH) {
32+
+ return commonShellLinkPath(L"APPDATA", appname, path, nSize);
33+
+ }
34+
+
35+
+ inline HRESULT defaultSystemShellLinkPath(const std::wstring& appname, _In_ WCHAR* path, _In_ DWORD nSize = MAX_PATH) {
36+
+ return commonShellLinkPath(L"PROGRAMDATA", appname, path, nSize);
37+
+ }
38+
39+
inline PCWSTR AsString(ComPtr<IXmlDocument> &xmlDocument) {
40+
HSTRING xml;
41+
@@ -523,12 +530,19 @@ const std::wstring& WinToast::appUserModelId() const {
42+
43+
HRESULT WinToast::validateShellLinkHelper(_Out_ bool& wasChanged) {
44+
WCHAR path[MAX_PATH] = { L'\0' };
45+
- Util::defaultShellLinkPath(_appName, path);
46+
+ Util::defaultUserShellLinkPath(_appName, path);
47+
// Check if the file exist
48+
DWORD attr = GetFileAttributesW(path);
49+
if (attr >= 0xFFFFFFF) {
50+
- DEBUG_MSG("Error, shell link not found. Try to create a new one in: " << path);
51+
- return E_FAIL;
52+
+ // The shortcut may be in the system Start Menu.
53+
+ WCHAR systemPath[MAX_PATH] = { L'\0' };
54+
+ Util::defaultSystemShellLinkPath(_appName, systemPath);
55+
+ attr = GetFileAttributesW(systemPath);
56+
+ if (attr >= 0xFFFFFFF) {
57+
+ DEBUG_MSG("Error, shell link not found. Try to create a new one in: " << path);
58+
+ return E_FAIL;
59+
+ }
60+
+ wcscpy(path, systemPath);
61+
}
62+
63+
// Let's load the file as shell link to validate.
64+
@@ -543,7 +557,7 @@ HRESULT WinToast::validateShellLinkHelper(_Out_ bool& wasChanged) {
65+
ComPtr<IPersistFile> persistFile;
66+
hr = shellLink.As(&persistFile);
67+
if (SUCCEEDED(hr)) {
68+
- hr = persistFile->Load(path, STGM_READWRITE);
69+
+ hr = persistFile->Load(path, STGM_READ);
70+
if (SUCCEEDED(hr)) {
71+
ComPtr<IPropertyStore> propertyStore;
72+
hr = shellLink.As(&propertyStore);
73+
@@ -583,7 +597,7 @@ HRESULT WinToast::validateShellLinkHelper(_Out_ bool& wasChanged) {
74+
HRESULT WinToast::createShellLinkHelper() {
75+
WCHAR exePath[MAX_PATH]{L'\0'};
76+
WCHAR slPath[MAX_PATH]{L'\0'};
77+
- Util::defaultShellLinkPath(_appName, slPath);
78+
+ Util::defaultUserShellLinkPath(_appName, slPath);
79+
Util::defaultExecutablePath(exePath);
80+
ComPtr<IShellLinkW> shellLink;
81+
HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink));
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
diff --git a/src/wintoastlib.cpp b/src/wintoastlib.cpp
2+
index 0895ff7..52de554 100644
3+
--- a/src/wintoastlib.cpp
4+
+++ b/src/wintoastlib.cpp
5+
@@ -391,6 +391,10 @@ void WinToast::setAppUserModelId(_In_ const std::wstring& aumi) {
6+
DEBUG_MSG(L"Default App User Model Id: " << _aumi.c_str());
7+
}
8+
9+
+void WinToast::setShortcutPolicy(_In_ ShortcutPolicy shortcutPolicy) {
10+
+ _shortcutPolicy = shortcutPolicy;
11+
+}
12+
+
13+
bool WinToast::isCompatible() {
14+
DllImporter::initialize();
15+
return !((DllImporter::SetCurrentProcessExplicitAppUserModelID == nullptr)
16+
@@ -492,10 +496,12 @@ bool WinToast::initialize(_Out_ WinToastError* error) {
17+
return false;
18+
}
19+
20+
- if (createShortcut() < 0) {
21+
- setError(error, WinToastError::ShellLinkNotCreated);
22+
- DEBUG_MSG(L"Error while attaching the AUMI to the current proccess =(");
23+
- return false;
24+
+ if (_shortcutPolicy != SHORTCUT_POLICY_IGNORE) {
25+
+ if (createShortcut() < 0) {
26+
+ setError(error, WinToastError::ShellLinkNotCreated);
27+
+ DEBUG_MSG(L"Error while attaching the AUMI to the current proccess =(");
28+
+ return false;
29+
+ }
30+
}
31+
32+
if (FAILED(DllImporter::SetCurrentProcessExplicitAppUserModelID(_aumi.c_str()))) {
33+
@@ -555,18 +561,23 @@ HRESULT WinToast::validateShellLinkHelper(_Out_ bool& wasChanged) {
34+
hr = DllImporter::PropVariantToString(appIdPropVar, AUMI, MAX_PATH);
35+
wasChanged = false;
36+
if (FAILED(hr) || _aumi != AUMI) {
37+
- // AUMI Changed for the same app, let's update the current value! =)
38+
- wasChanged = true;
39+
- PropVariantClear(&appIdPropVar);
40+
- hr = InitPropVariantFromString(_aumi.c_str(), &appIdPropVar);
41+
- if (SUCCEEDED(hr)) {
42+
- hr = propertyStore->SetValue(PKEY_AppUserModel_ID, appIdPropVar);
43+
+ if (_shortcutPolicy == SHORTCUT_POLICY_REQUIRE_CREATE) {
44+
+ // AUMI Changed for the same app, let's update the current value! =)
45+
+ wasChanged = true;
46+
+ PropVariantClear(&appIdPropVar);
47+
+ hr = InitPropVariantFromString(_aumi.c_str(), &appIdPropVar);
48+
if (SUCCEEDED(hr)) {
49+
- hr = propertyStore->Commit();
50+
- if (SUCCEEDED(hr) && SUCCEEDED(persistFile->IsDirty())) {
51+
- hr = persistFile->Save(path, TRUE);
52+
+ hr = propertyStore->SetValue(PKEY_AppUserModel_ID, appIdPropVar);
53+
+ if (SUCCEEDED(hr)) {
54+
+ hr = propertyStore->Commit();
55+
+ if (SUCCEEDED(hr) && SUCCEEDED(persistFile->IsDirty())) {
56+
+ hr = persistFile->Save(path, TRUE);
57+
+ }
58+
}
59+
}
60+
+ } else {
61+
+ // Not allowed to touch the shortcut to fix the AUMI
62+
+ hr = E_FAIL;
63+
}
64+
}
65+
PropVariantClear(&appIdPropVar);
66+
@@ -581,6 +592,10 @@ HRESULT WinToast::validateShellLinkHelper(_Out_ bool& wasChanged) {
67+
68+
69+
HRESULT WinToast::createShellLinkHelper() {
70+
+ if (_shortcutPolicy != SHORTCUT_POLICY_REQUIRE_CREATE) {
71+
+ return E_FAIL;
72+
+ }
73+
+
74+
WCHAR exePath[MAX_PATH]{L'\0'};
75+
WCHAR slPath[MAX_PATH]{L'\0'};
76+
Util::defaultShellLinkPath(_appName, slPath);
77+
diff --git a/src/wintoastlib.h b/src/wintoastlib.h
78+
index 68b1cb1..dc8d745 100644
79+
--- a/src/wintoastlib.h
80+
+++ b/src/wintoastlib.h
81+
@@ -173,6 +173,16 @@ namespace WinToastLib {
82+
SHORTCUT_CREATE_FAILED = -4
83+
};
84+
85+
+ enum ShortcutPolicy {
86+
+ /* Don't check, create, or modify a shortcut. */
87+
+ SHORTCUT_POLICY_IGNORE = 0,
88+
+ /* Require a shortcut with matching AUMI, don't create or modify an existing one. */
89+
+ SHORTCUT_POLICY_REQUIRE_NO_CREATE = 1,
90+
+ /* Require a shortcut with matching AUMI, create if missing, modify if not matching.
91+
+ * This is the default. */
92+
+ SHORTCUT_POLICY_REQUIRE_CREATE = 2,
93+
+ };
94+
+
95+
WinToast(void);
96+
virtual ~WinToast();
97+
static WinToast* instance();
98+
@@ -194,10 +204,12 @@ namespace WinToastLib {
99+
const std::wstring& appUserModelId() const;
100+
void setAppUserModelId(_In_ const std::wstring& aumi);
101+
void setAppName(_In_ const std::wstring& appName);
102+
+ void setShortcutPolicy(_In_ ShortcutPolicy policy);
103+
104+
protected:
105+
bool _isInitialized{false};
106+
bool _hasCoInitialized{false};
107+
+ ShortcutPolicy _shortcutPolicy{SHORTCUT_POLICY_REQUIRE_CREATE};
108+
std::wstring _appName{};
109+
std::wstring _aumi{};
110+
std::map<INT64, ComPtr<IToastNotification>> _buffer{};

third_party/WinToast/moz.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Version of this schema
2+
schema: 1
3+
4+
# Manual Update can be done with:
5+
# cd third_pary/WinToast
6+
# wget https://raw.githubusercontent.com/mohabouje/WinToast/master/src/wintoastlib.cpp
7+
# wget https://raw.githubusercontent.com/mohabouje/WinToast/master/src/wintoastlib.h
8+
# patch -p2 < moz-check-system-shortcut.patch
9+
# patch -p2 < moz-disable-create-shortcut.patch
10+
# patch -p2 < upstream-add-toast-scenario.patch
11+
12+
bugzilla:
13+
# Bugzilla product and component for this directory and subdirectories
14+
product: Toolkit
15+
component: "General"
16+
17+
# Document the source of externally hosted code
18+
origin:
19+
20+
# Short name of the package/library
21+
name: WinToast
22+
23+
description: WinToast is a lightly library written in C++ which brings a complete integration of the modern toast notifications of Windows 8 & Windows 10.
24+
25+
# Full URL for the package's homepage/etc
26+
# Usually different from repository url
27+
url: https://github.com/mohabouje/WinToast
28+
29+
# Human-readable identifier for this version/release
30+
# Generally "version NNN", "tag SSS", "bookmark SSS"
31+
release: commit 09227c72f16ccefc36e9d430dea3b435346dbcbc
32+
33+
# The package's license, where possible using the mnemonic from
34+
# https://spdx.org/licenses/
35+
# Multiple licenses can be specified (as a YAML list)
36+
# A "LICENSE" file must exist containing the full license text
37+
license: MIT

0 commit comments

Comments
 (0)