Skip to content

Commit ceee0d7

Browse files
authored
Remove gcm_sender_id / manifest.json related code (#2088)
It was deprecated three years ago. developers.google.com/web/updates/2016/07/web-push-interop-wins
1 parent 2907439 commit ceee0d7

File tree

3 files changed

+1
-172
lines changed

3 files changed

+1
-172
lines changed

packages/messaging/src/controllers/window-controller.ts

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,9 @@ import {
3737
} from '../models/worker-page-message';
3838
import { BaseController } from './base-controller';
3939

40-
interface ManifestContent {
41-
// eslint-disable-next-line camelcase
42-
gcm_sender_id: string;
43-
}
44-
4540
export class WindowController extends BaseController {
4641
private registrationToUse: ServiceWorkerRegistration | null = null;
4742
private publicVapidKeyToUse: Uint8Array | null = null;
48-
private manifestCheckPromise: Promise<void> | null = null;
4943

5044
private messageObserver: Observer<object> | null = null;
5145
// @ts-ignore: Unused variable error, this is not implemented yet.
@@ -72,23 +66,6 @@ export class WindowController extends BaseController {
7266
this.setupSWMessageListener_();
7367
}
7468

75-
/**
76-
* This method returns an FCM token if it can be generated.
77-
* The return promise will reject if the browser doesn't support
78-
* FCM, if permission is denied for notifications or it's not
79-
* possible to generate a token.
80-
*
81-
* @return Returns a promise that resolves to an FCM token or null if
82-
* permission isn't granted.
83-
*/
84-
async getToken(): Promise<string | null> {
85-
if (!this.manifestCheckPromise) {
86-
this.manifestCheckPromise = manifestCheck();
87-
}
88-
await this.manifestCheckPromise;
89-
return super.getToken();
90-
}
91-
9269
/**
9370
* Request permission if it is not currently granted
9471
*
@@ -324,38 +301,3 @@ export class WindowController extends BaseController {
324301
);
325302
}
326303
}
327-
328-
/**
329-
* The method checks that a manifest is defined and has the correct GCM
330-
* sender ID.
331-
* @return Returns a promise that resolves if the manifest matches
332-
* our required sender ID
333-
*/
334-
// Exported for testing
335-
export async function manifestCheck(): Promise<void> {
336-
const manifestTag = document.querySelector<HTMLAnchorElement>(
337-
'link[rel="manifest"]'
338-
);
339-
340-
if (!manifestTag) {
341-
return;
342-
}
343-
344-
let manifestContent: ManifestContent;
345-
try {
346-
const response = await fetch(manifestTag.href);
347-
manifestContent = await response.json();
348-
} catch (e) {
349-
// If the download or parsing fails allow check.
350-
// We only want to error if we KNOW that the gcm_sender_id is incorrect.
351-
return;
352-
}
353-
354-
if (!manifestContent || !manifestContent.gcm_sender_id) {
355-
return;
356-
}
357-
358-
if (manifestContent.gcm_sender_id !== '103953800507') {
359-
throw errorFactory.create(ErrorCode.INCORRECT_GCM_SENDER_ID);
360-
}
361-
}

packages/messaging/src/models/errors.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export const enum ErrorCode {
2222
AVAILABLE_IN_SW = 'only-available-in-sw',
2323
SHOULD_BE_INHERITED = 'should-be-overriden',
2424
BAD_SENDER_ID = 'bad-sender-id',
25-
INCORRECT_GCM_SENDER_ID = 'incorrect-gcm-sender-id',
2625
PERMISSION_DEFAULT = 'permission-default',
2726
PERMISSION_BLOCKED = 'permission-blocked',
2827
UNSUPPORTED_BROWSER = 'unsupported-browser',
@@ -131,9 +130,6 @@ export const ERROR_MAP: ErrorMap<ErrorCode> = {
131130
[ErrorCode.NO_SW_IN_REG]:
132131
'Even though the service worker registration was ' +
133132
'successful, there was a problem accessing the service worker itself.',
134-
[ErrorCode.INCORRECT_GCM_SENDER_ID]:
135-
"Please change your web app manifest's " +
136-
"'gcm_sender_id' value to '103953800507' to use Firebase messaging.",
137133
[ErrorCode.BAD_SCOPE]:
138134
'The service worker scope must be a string with at ' +
139135
'least one character.',

packages/messaging/test/window-controller.test.ts

Lines changed: 1 addition & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ import * as sinon from 'sinon';
2020
import { makeFakeApp } from './testing-utils/make-fake-app';
2121
import { makeFakeSWReg } from './testing-utils/make-fake-sw-reg';
2222

23-
import {
24-
manifestCheck,
25-
WindowController
26-
} from '../src/controllers/window-controller';
23+
import { WindowController } from '../src/controllers/window-controller';
2724
import { base64ToArrayBuffer } from '../src/helpers/base64-to-array-buffer';
2825
import { DEFAULT_PUBLIC_VAPID_KEY } from '../src/models/fcm-details';
2926

@@ -48,112 +45,6 @@ describe('Firebase Messaging > *WindowController', () => {
4845
return cleanup();
4946
});
5047

51-
describe('manifestCheck()', () => {
52-
it("should resolve when the tag isn't defined", () => {
53-
sandbox
54-
.stub(document, 'querySelector')
55-
.withArgs('link[rel="manifest"]')
56-
.returns(null);
57-
58-
return manifestCheck();
59-
});
60-
61-
it('should fetch the manifest if defined and resolve when no gcm_sender_id', () => {
62-
sandbox
63-
.stub(document, 'querySelector')
64-
.withArgs('link[rel="manifest"]')
65-
.returns({
66-
href: 'https://firebase.io/messaging/example'
67-
} as any);
68-
69-
sandbox
70-
.stub(window, 'fetch')
71-
.withArgs('https://firebase.io/messaging/example')
72-
.returns(
73-
Promise.resolve({
74-
json: () => {
75-
return {};
76-
}
77-
} as any)
78-
);
79-
80-
return manifestCheck();
81-
});
82-
83-
it('should fetch the manifest if defined and resolve with expected gcm_sender_id', () => {
84-
sandbox
85-
.stub(document, 'querySelector')
86-
.withArgs('link[rel="manifest"]')
87-
.returns({
88-
href: 'https://firebase.io/messaging/example'
89-
} as any);
90-
91-
sandbox
92-
.stub(window, 'fetch')
93-
.withArgs('https://firebase.io/messaging/example')
94-
.returns(
95-
Promise.resolve({
96-
json: () => {
97-
return {
98-
// eslint-disable-next-line camelcase
99-
gcm_sender_id: '103953800507'
100-
};
101-
}
102-
} as any)
103-
);
104-
105-
return manifestCheck();
106-
});
107-
108-
it('should fetch the manifest if defined and reject when using wrong gcm_sender_id', () => {
109-
sandbox
110-
.stub(document, 'querySelector')
111-
.withArgs('link[rel="manifest"]')
112-
.returns({
113-
href: 'https://firebase.io/messaging/example'
114-
} as any);
115-
116-
sandbox
117-
.stub(window, 'fetch')
118-
.withArgs('https://firebase.io/messaging/example')
119-
.returns(
120-
Promise.resolve({
121-
json: () => {
122-
return {
123-
// eslint-disable-next-line camelcase
124-
gcm_sender_id: 'incorrect-sender-id'
125-
};
126-
}
127-
} as any)
128-
);
129-
130-
return manifestCheck().then(
131-
() => {
132-
throw new Error('Expected error to be thrown.');
133-
},
134-
err => {
135-
expect(err.code).to.equal('messaging/incorrect-gcm-sender-id');
136-
}
137-
);
138-
});
139-
140-
it('should fetch the manifest and resolve if the request fails', () => {
141-
sandbox
142-
.stub(document, 'querySelector')
143-
.withArgs('link[rel="manifest"]')
144-
.returns({
145-
href: 'https://firebase.io/messaging/example'
146-
} as any);
147-
148-
sandbox
149-
.stub(window, 'fetch')
150-
.withArgs('https://firebase.io/messaging/example')
151-
.returns(Promise.reject(new Error('Injected Failure.')));
152-
153-
return manifestCheck();
154-
});
155-
});
156-
15748
describe('requestPermission', () => {
15849
it('should resolve if the permission is already granted', () => {
15950
sandbox.stub(Notification as any, 'permission').value('granted');

0 commit comments

Comments
 (0)