diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 3752fb02f4ff..bb77450ab4ab 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -240,21 +240,6 @@ namespace api { namespace { -content::ServiceWorkerContext* GetServiceWorkerContext( - content::WebContents* web_contents) { - auto* context = web_contents->GetBrowserContext(); - auto* site_instance = web_contents->GetSiteInstance(); - if (!context || !site_instance) - return nullptr; - - auto* storage_partition = - content::BrowserContext::GetStoragePartition(context, site_instance); - if (!storage_partition) - return nullptr; - - return storage_partition->GetServiceWorkerContext(); -} - // Called when CapturePage is done. void OnCapturePageDone(scoped_refptr promise, const SkBitmap& bitmap) { @@ -1450,41 +1435,6 @@ void WebContents::InspectServiceWorker() { } } -void OnServiceWorkerCheckDone(scoped_refptr promise, - content::ServiceWorkerCapability capability) { - promise->Resolve(capability != - content::ServiceWorkerCapability::NO_SERVICE_WORKER); -} - -v8::Local WebContents::HasServiceWorker() { - scoped_refptr promise = new util::Promise(isolate()); - auto* context = GetServiceWorkerContext(web_contents()); - if (!context) { - promise->RejectWithErrorMessage("Unable to get ServiceWorker context."); - return promise->GetHandle(); - } - - GURL url = web_contents()->GetLastCommittedURL(); - if (!url.is_valid()) { - promise->RejectWithErrorMessage("URL invalid or not yet loaded."); - return promise->GetHandle(); - } - - context->CheckHasServiceWorker( - url, url, base::BindOnce(&OnServiceWorkerCheckDone, promise)); - - return promise->GetHandle(); -} - -void WebContents::UnregisterServiceWorker( - const base::Callback& callback) { - auto* context = GetServiceWorkerContext(web_contents()); - if (!context) - return; - context->UnregisterServiceWorker(web_contents()->GetLastCommittedURL(), - callback); -} - void WebContents::SetIgnoreMenuShortcuts(bool ignore) { auto* web_preferences = WebContentsPreferences::From(web_contents()); DCHECK(web_preferences); @@ -2191,9 +2141,6 @@ void WebContents::BuildPrototype(v8::Isolate* isolate, .SetMethod("getLastWebPreferences", &WebContents::GetLastWebPreferences) .SetMethod("_isRemoteModuleEnabled", &WebContents::IsRemoteModuleEnabled) .SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow) - .SetMethod("hasServiceWorker", &WebContents::HasServiceWorker) - .SetMethod("unregisterServiceWorker", - &WebContents::UnregisterServiceWorker) .SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker) .SetMethod("inspectSharedWorker", &WebContents::InspectSharedWorker) #if BUILDFLAG(ENABLE_PRINTING) diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 14c0646323cd..af8d5aa25669 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -162,8 +162,6 @@ class WebContents : public mate::TrackableObject, void InspectElement(int x, int y); void InspectSharedWorker(); void InspectServiceWorker(); - v8::Local HasServiceWorker(); - void UnregisterServiceWorker(const base::Callback&); void SetIgnoreMenuShortcuts(bool ignore); void SetAudioMuted(bool muted); bool IsAudioMuted(); diff --git a/docs/api/promisification.md b/docs/api/promisification.md index 6981796697f2..1bdb99bc2f5a 100644 --- a/docs/api/promisification.md +++ b/docs/api/promisification.md @@ -29,7 +29,6 @@ When a majority of affected functions are migrated, this flag will be enabled by - [ses.getBlobData(identifier, callback)](https://github.com/electron/electron/blob/master/docs/api/session.md#getBlobData) - [ses.clearAuthCache(options[, callback])](https://github.com/electron/electron/blob/master/docs/api/session.md#clearAuthCache) - [contents.executeJavaScript(code[, userGesture, callback])](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#executeJavaScript) -- [contents.unregisterServiceWorker(callback)](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#unregisterServiceWorker) - [contents.print([options], [callback])](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#print) - [contents.printToPDF(options, callback)](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#printToPDF) - [contents.savePage(fullPath, saveType, callback)](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#savePage) @@ -55,4 +54,3 @@ When a majority of affected functions are migrated, this flag will be enabled by - [webviewTag.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/webview-tag.md#capturePage) - [win.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/browser-window.md#capturePage) - [desktopCapturer.getSources(options, callback)](https://github.com/electron/electron/blob/master/docs/api/desktop-capturer.md#getSources) -- [contents.hasServiceWorker(callback)](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#hasServiceWorker) diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 5aed4e2899ea..4b78c54b3e51 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -1156,29 +1156,6 @@ that stores data of the snapshot. Omitting `rect` will capture the whole visible Captures a snapshot of the page within `rect`. Omitting `rect` will capture the whole visible page. -#### `contents.hasServiceWorker(callback)` - -* `callback` Function - * `hasWorker` Boolean - -Checks if any ServiceWorker is registered and returns a boolean as -response to `callback`. - -**[Deprecated Soon](promisification.md)** - -#### `contents.hasServiceWorker()` - -Returns `Promise` - Resolves with a boolean depending on whether or not the current `webContents` has a registered ServiceWorker - -#### `contents.unregisterServiceWorker(callback)` - -* `callback` Function - * `success` Boolean - -Unregisters any ServiceWorker if present and returns a boolean as -response to `callback` when the JS promise is fulfilled or false -when the JS promise is rejected. - #### `contents.getPrinters()` Get the system printer list. diff --git a/lib/browser/api/web-contents.js b/lib/browser/api/web-contents.js index 782fbaf16c55..ebf5d65b6dc8 100644 --- a/lib/browser/api/web-contents.js +++ b/lib/browser/api/web-contents.js @@ -386,7 +386,6 @@ WebContents.prototype._init = function () { this.setMaxListeners(0) this.capturePage = deprecate.promisify(this.capturePage) - this.hasServiceWorker = deprecate.promisify(this.hasServiceWorker) // Dispatch IPC messages to the ipc module. this.on('-ipc-message', function (event, internal, channel, args) { diff --git a/spec/api-web-contents-spec.js b/spec/api-web-contents-spec.js index 139dc7678aaa..84730ceb007b 100644 --- a/spec/api-web-contents-spec.js +++ b/spec/api-web-contents-spec.js @@ -228,28 +228,6 @@ describe('webContents module', () => { }) }) - describe('ServiceWorker APIs', () => { - it('can successfully check for presence of a ServiceWorker', async () => { - await w.loadFile(path.join(fixtures, 'api', 'service-worker', 'service-worker.html')) - const hasSW = await w.webContents.hasServiceWorker() - expect(hasSW).to.be.true() - }) - - it('throws properly for invalid url', async () => { - const promise = w.webContents.hasServiceWorker() - return expect(promise).to.be.eventually.rejectedWith(Error, 'URL invalid or not yet loaded.') - }) - - it('can successfully check for presence of a ServiceWorker (callback)', (done) => { - w.loadFile(path.join(fixtures, 'api', 'service-worker', 'service-worker.html')).then(() => { - w.webContents.hasServiceWorker(hasSW => { - expect(hasSW).to.be.true() - done() - }) - }) - }) - }) - describe('isCurrentlyAudible() API', () => { it('returns whether audio is playing', async () => { const webContents = remote.getCurrentWebContents()