fix: reject with error when url not loaded (#16571)

* fix: reject with error when url not loaded

* improve descriptive spec naming
This commit is contained in:
Shelley Vohr 2019-01-28 14:42:36 -08:00 committed by GitHub
parent 138ba53511
commit a25f82c91f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View file

@ -1444,12 +1444,17 @@ v8::Local<v8::Promise> WebContents::HasServiceWorker() {
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(
web_contents()->GetLastCommittedURL(),
web_contents()->GetLastCommittedURL(),
base::BindOnce(&OnServiceWorkerCheckDone, promise));
url, url, base::BindOnce(&OnServiceWorkerCheckDone, promise));
return promise->GetHandle();
}