refactor: remove ServiceWorker APIs from WebContents (#16717)
This commit is contained in:
parent
3aa8ec0818
commit
f303caa87c
6 changed files with 0 additions and 103 deletions
|
@ -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<util::Promise> promise,
|
||||
const SkBitmap& bitmap) {
|
||||
|
@ -1450,41 +1435,6 @@ void WebContents::InspectServiceWorker() {
|
|||
}
|
||||
}
|
||||
|
||||
void OnServiceWorkerCheckDone(scoped_refptr<util::Promise> promise,
|
||||
content::ServiceWorkerCapability capability) {
|
||||
promise->Resolve(capability !=
|
||||
content::ServiceWorkerCapability::NO_SERVICE_WORKER);
|
||||
}
|
||||
|
||||
v8::Local<v8::Promise> WebContents::HasServiceWorker() {
|
||||
scoped_refptr<util::Promise> 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<void(bool)>& 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)
|
||||
|
|
|
@ -162,8 +162,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
void InspectElement(int x, int y);
|
||||
void InspectSharedWorker();
|
||||
void InspectServiceWorker();
|
||||
v8::Local<v8::Promise> HasServiceWorker();
|
||||
void UnregisterServiceWorker(const base::Callback<void(bool)>&);
|
||||
void SetIgnoreMenuShortcuts(bool ignore);
|
||||
void SetAudioMuted(bool muted);
|
||||
bool IsAudioMuted();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<Boolean>` - 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.
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue