Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/browser/extension_function.h" | 5 #include "extensions/browser/extension_function.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/metrics/sparse_histogram.h" | 14 #include "base/metrics/sparse_histogram.h" |
| 15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 16 #include "content/common/service_worker/service_worker_types.h" | |
| 16 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
| 17 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
| 18 #include "content/public/browser/render_frame_host.h" | 19 #include "content/public/browser/render_frame_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/browser/web_contents_observer.h" | 21 #include "content/public/browser/web_contents_observer.h" |
| 21 #include "extensions/browser/extension_function_dispatcher.h" | 22 #include "extensions/browser/extension_function_dispatcher.h" |
| 22 #include "extensions/browser/extension_message_filter.h" | 23 #include "extensions/browser/extension_message_filter.h" |
| 23 #include "extensions/browser/extensions_browser_client.h" | 24 #include "extensions/browser/extensions_browser_client.h" |
| 24 #include "extensions/common/error_utils.h" | 25 #include "extensions/common/error_utils.h" |
| 25 #include "extensions/common/extension_api.h" | 26 #include "extensions/common/extension_api.h" |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 LogUma(success, timer_.Elapsed(), histogram_value_); | 464 LogUma(success, timer_.Elapsed(), histogram_value_); |
| 464 } | 465 } |
| 465 | 466 |
| 466 void ExtensionFunction::OnRespondingLater(ResponseValue value) { | 467 void ExtensionFunction::OnRespondingLater(ResponseValue value) { |
| 467 SendResponse(value->Apply()); | 468 SendResponse(value->Apply()); |
| 468 } | 469 } |
| 469 | 470 |
| 470 UIThreadExtensionFunction::UIThreadExtensionFunction() | 471 UIThreadExtensionFunction::UIThreadExtensionFunction() |
| 471 : context_(nullptr), | 472 : context_(nullptr), |
| 472 render_frame_host_(nullptr), | 473 render_frame_host_(nullptr), |
| 473 is_from_service_worker_(false), | 474 service_worker_version_id_(content::kInvalidServiceWorkerVersionId), |
| 474 delegate_(nullptr) {} | 475 delegate_(nullptr) {} |
| 475 | 476 |
| 476 UIThreadExtensionFunction::~UIThreadExtensionFunction() { | 477 UIThreadExtensionFunction::~UIThreadExtensionFunction() { |
| 477 if (dispatcher() && render_frame_host()) | 478 if (dispatcher() && (render_frame_host() || IsFromServiceWorker())) { |
| 478 dispatcher()->OnExtensionFunctionCompleted(extension()); | 479 dispatcher()->OnExtensionFunctionCompleted(extension(), |
| 480 service_worker_version_id_); | |
| 481 } | |
| 482 | |
| 479 // The extension function should always respond to avoid leaks in the | 483 // The extension function should always respond to avoid leaks in the |
| 480 // renderer, dangling callbacks, etc. The exception is if the system is | 484 // renderer, dangling callbacks, etc. The exception is if the system is |
| 481 // shutting down. | 485 // shutting down. |
| 482 // TODO(devlin): Duplicate this check in IOThreadExtensionFunction. It's | 486 // TODO(devlin): Duplicate this check in IOThreadExtensionFunction. It's |
| 483 // tricky because checking IsShuttingDown has to be called from the UI thread. | 487 // tricky because checking IsShuttingDown has to be called from the UI thread. |
| 484 extensions::ExtensionsBrowserClient* browser_client = | 488 extensions::ExtensionsBrowserClient* browser_client = |
| 485 extensions::ExtensionsBrowserClient::Get(); | 489 extensions::ExtensionsBrowserClient::Get(); |
| 486 DCHECK(!browser_client || browser_client->IsShuttingDown() || did_respond_ || | 490 DCHECK(!browser_client || browser_client->IsShuttingDown() || did_respond_ || |
| 487 ignore_all_did_respond_for_testing_do_not_use) | 491 ignore_all_did_respond_for_testing_do_not_use) |
| 488 << name_; | 492 << name_; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 514 } | 518 } |
| 515 | 519 |
| 516 bool UIThreadExtensionFunction::OnMessageReceived(const IPC::Message& message) { | 520 bool UIThreadExtensionFunction::OnMessageReceived(const IPC::Message& message) { |
| 517 return false; | 521 return false; |
| 518 } | 522 } |
| 519 | 523 |
| 520 void UIThreadExtensionFunction::Destruct() const { | 524 void UIThreadExtensionFunction::Destruct() const { |
| 521 BrowserThread::DeleteOnUIThread::Destruct(this); | 525 BrowserThread::DeleteOnUIThread::Destruct(this); |
| 522 } | 526 } |
| 523 | 527 |
| 528 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.
| |
| 529 return content::kInvalidServiceWorkerVersionId != service_worker_version_id_; | |
| 530 } | |
| 531 | |
| 524 void UIThreadExtensionFunction::SetRenderFrameHost( | 532 void UIThreadExtensionFunction::SetRenderFrameHost( |
| 525 content::RenderFrameHost* render_frame_host) { | 533 content::RenderFrameHost* render_frame_host) { |
| 526 // An extension function from Service Worker does not have a RenderFrameHost. | 534 // An extension function from Service Worker does not have a RenderFrameHost. |
| 527 if (is_from_service_worker_) { | 535 if (IsFromServiceWorker()) { |
| 528 DCHECK(!render_frame_host); | 536 DCHECK(!render_frame_host); |
| 529 return; | 537 return; |
| 530 } | 538 } |
| 531 | 539 |
| 532 DCHECK_NE(render_frame_host_ == nullptr, render_frame_host == nullptr); | 540 DCHECK_NE(render_frame_host_ == nullptr, render_frame_host == nullptr); |
| 533 render_frame_host_ = render_frame_host; | 541 render_frame_host_ = render_frame_host; |
| 534 tracker_.reset( | 542 tracker_.reset( |
| 535 render_frame_host ? new RenderFrameHostTracker(this) : nullptr); | 543 render_frame_host ? new RenderFrameHostTracker(this) : nullptr); |
| 536 } | 544 } |
| 537 | 545 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 616 | 624 |
| 617 ExtensionFunction::ResponseAction AsyncExtensionFunction::Run() { | 625 ExtensionFunction::ResponseAction AsyncExtensionFunction::Run() { |
| 618 return RunAsync() ? RespondLater() : RespondNow(Error(error_)); | 626 return RunAsync() ? RespondLater() : RespondNow(Error(error_)); |
| 619 } | 627 } |
| 620 | 628 |
| 621 // static | 629 // static |
| 622 bool AsyncExtensionFunction::ValidationFailure( | 630 bool AsyncExtensionFunction::ValidationFailure( |
| 623 AsyncExtensionFunction* function) { | 631 AsyncExtensionFunction* function) { |
| 624 return false; | 632 return false; |
| 625 } | 633 } |
| OLD | NEW |