From 4d9f3098889307b469934bd774b1941598f848cb Mon Sep 17 00:00:00 2001 From: Tony Ganch Date: Wed, 21 Jun 2017 12:34:14 +0200 Subject: [PATCH] Fix HasServiceWorker check Revert cb2014f9e8ae0283e5f20d4e2167be1592228887. --- atom/browser/api/atom_api_web_contents.cc | 15 +++++++++++++-- atom/browser/api/atom_api_web_contents.h | 3 +-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index dd71a7b8b654..d9ef7a1de1df 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1238,14 +1238,25 @@ void WebContents::InspectServiceWorker() { } void WebContents::HasServiceWorker( - const base::Callback& callback) { + const base::Callback& callback) { auto context = GetServiceWorkerContext(web_contents()); if (!context) return; + struct WrappedCallback { + base::Callback callback_; + WrappedCallback(const base::Callback& callback) : callback_(callback) {} + void Run(content::ServiceWorkerCapability capability) { + callback_.Run(capability != content::ServiceWorkerCapability::NO_SERVICE_WORKER); + delete this; + } + }; + + auto wrapped_callback = new WrappedCallback(callback); + context->CheckHasServiceWorker(web_contents()->GetLastCommittedURL(), GURL::EmptyGURL(), - callback); + base::Bind(&WrappedCallback::Run, base::Unretained(wrapped_callback))); } void WebContents::UnregisterServiceWorker( diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 999ddef6e4f9..c67c4e0d859c 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -15,7 +15,6 @@ #include "atom/browser/ui/autofill_popup.h" #include "content/common/cursors/webcursor.h" #include "content/public/browser/keyboard_event_processing_result.h" -#include "content/public/browser/service_worker_context.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/common/favicon_url.h" #include "native_mate/handle.h" @@ -118,7 +117,7 @@ class WebContents : public mate::TrackableObject, void InspectElement(int x, int y); void InspectServiceWorker(); void HasServiceWorker( - const base::Callback&); + const base::Callback&); void UnregisterServiceWorker(const base::Callback&); void SetIgnoreMenuShortcuts(bool ignore); void SetAudioMuted(bool muted);