Chromium Code Reviews| Index: extensions/browser/extension_function.cc |
| diff --git a/extensions/browser/extension_function.cc b/extensions/browser/extension_function.cc |
| index e734dee7e8699e31f7f27ca9e813a853eeb2bc05..a44d4b2406e8e35aad52b9f0e9213c2521dce27e 100644 |
| --- a/extensions/browser/extension_function.cc |
| +++ b/extensions/browser/extension_function.cc |
| @@ -13,6 +13,7 @@ |
| #include "base/metrics/histogram_macros.h" |
| #include "base/metrics/sparse_histogram.h" |
| #include "base/synchronization/lock.h" |
| +#include "content/common/service_worker/service_worker_types.h" |
| #include "content/public/browser/notification_source.h" |
| #include "content/public/browser/notification_types.h" |
| #include "content/public/browser/render_frame_host.h" |
| @@ -470,12 +471,15 @@ void ExtensionFunction::OnRespondingLater(ResponseValue value) { |
| UIThreadExtensionFunction::UIThreadExtensionFunction() |
| : context_(nullptr), |
| render_frame_host_(nullptr), |
| - is_from_service_worker_(false), |
| + service_worker_version_id_(content::kInvalidServiceWorkerVersionId), |
| delegate_(nullptr) {} |
| UIThreadExtensionFunction::~UIThreadExtensionFunction() { |
| - if (dispatcher() && render_frame_host()) |
| - dispatcher()->OnExtensionFunctionCompleted(extension()); |
| + if (dispatcher() && (render_frame_host() || IsFromServiceWorker())) { |
| + dispatcher()->OnExtensionFunctionCompleted(extension(), |
| + service_worker_version_id_); |
| + } |
| + |
| // The extension function should always respond to avoid leaks in the |
| // renderer, dangling callbacks, etc. The exception is if the system is |
| // shutting down. |
| @@ -521,10 +525,14 @@ void UIThreadExtensionFunction::Destruct() const { |
| BrowserThread::DeleteOnUIThread::Destruct(this); |
| } |
| +bool UIThreadExtensionFunction::IsFromServiceWorker() const { |
|
michaeln
2016/09/24 01:46:51
style nit: maybe inline and rename is_from_service
lazyboy
2016/09/27 21:26:45
Done.
|
| + return content::kInvalidServiceWorkerVersionId != service_worker_version_id_; |
| +} |
| + |
| void UIThreadExtensionFunction::SetRenderFrameHost( |
| content::RenderFrameHost* render_frame_host) { |
| // An extension function from Service Worker does not have a RenderFrameHost. |
| - if (is_from_service_worker_) { |
| + if (IsFromServiceWorker()) { |
| DCHECK(!render_frame_host); |
| return; |
| } |