| 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" |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 } | 418 } |
| 419 } | 419 } |
| 420 | 420 |
| 421 void ExtensionFunction::OnRespondingLater(ResponseValue value) { | 421 void ExtensionFunction::OnRespondingLater(ResponseValue value) { |
| 422 SendResponse(value->Apply()); | 422 SendResponse(value->Apply()); |
| 423 } | 423 } |
| 424 | 424 |
| 425 UIThreadExtensionFunction::UIThreadExtensionFunction() | 425 UIThreadExtensionFunction::UIThreadExtensionFunction() |
| 426 : context_(nullptr), | 426 : context_(nullptr), |
| 427 render_frame_host_(nullptr), | 427 render_frame_host_(nullptr), |
| 428 delegate_(nullptr) { | 428 is_from_service_worker_(false), |
| 429 } | 429 delegate_(nullptr) {} |
| 430 | 430 |
| 431 UIThreadExtensionFunction::~UIThreadExtensionFunction() { | 431 UIThreadExtensionFunction::~UIThreadExtensionFunction() { |
| 432 if (dispatcher() && render_frame_host()) | 432 if (dispatcher() && render_frame_host()) |
| 433 dispatcher()->OnExtensionFunctionCompleted(extension()); | 433 dispatcher()->OnExtensionFunctionCompleted(extension()); |
| 434 } | 434 } |
| 435 | 435 |
| 436 UIThreadExtensionFunction* | 436 UIThreadExtensionFunction* |
| 437 UIThreadExtensionFunction::AsUIThreadExtensionFunction() { | 437 UIThreadExtensionFunction::AsUIThreadExtensionFunction() { |
| 438 return this; | 438 return this; |
| 439 } | 439 } |
| 440 | 440 |
| 441 bool UIThreadExtensionFunction::OnMessageReceived(const IPC::Message& message) { | 441 bool UIThreadExtensionFunction::OnMessageReceived(const IPC::Message& message) { |
| 442 return false; | 442 return false; |
| 443 } | 443 } |
| 444 | 444 |
| 445 void UIThreadExtensionFunction::Destruct() const { | 445 void UIThreadExtensionFunction::Destruct() const { |
| 446 BrowserThread::DeleteOnUIThread::Destruct(this); | 446 BrowserThread::DeleteOnUIThread::Destruct(this); |
| 447 } | 447 } |
| 448 | 448 |
| 449 content::RenderViewHost* | 449 content::RenderViewHost* |
| 450 UIThreadExtensionFunction::render_view_host_do_not_use() const { | 450 UIThreadExtensionFunction::render_view_host_do_not_use() const { |
| 451 return render_frame_host_ ? render_frame_host_->GetRenderViewHost() : nullptr; | 451 return render_frame_host_ ? render_frame_host_->GetRenderViewHost() : nullptr; |
| 452 } | 452 } |
| 453 | 453 |
| 454 void UIThreadExtensionFunction::SetRenderFrameHost( | 454 void UIThreadExtensionFunction::SetRenderFrameHost( |
| 455 content::RenderFrameHost* render_frame_host) { | 455 content::RenderFrameHost* render_frame_host) { |
| 456 // An extension function from Service Worker does not have a RenderFrameHost. | 456 // An extension function from Service Worker does not have a RenderFrameHost. |
| 457 if (!render_frame_host) | 457 if (is_from_service_worker_) { |
| 458 DCHECK(!render_frame_host); |
| 458 return; | 459 return; |
| 460 } |
| 461 |
| 459 DCHECK_NE(render_frame_host_ == nullptr, render_frame_host == nullptr); | 462 DCHECK_NE(render_frame_host_ == nullptr, render_frame_host == nullptr); |
| 460 render_frame_host_ = render_frame_host; | 463 render_frame_host_ = render_frame_host; |
| 461 tracker_.reset( | 464 tracker_.reset( |
| 462 render_frame_host ? new RenderFrameHostTracker(this) : nullptr); | 465 render_frame_host ? new RenderFrameHostTracker(this) : nullptr); |
| 463 } | 466 } |
| 464 | 467 |
| 465 content::WebContents* UIThreadExtensionFunction::GetAssociatedWebContents() { | 468 content::WebContents* UIThreadExtensionFunction::GetAssociatedWebContents() { |
| 466 content::WebContents* web_contents = NULL; | 469 content::WebContents* web_contents = NULL; |
| 467 if (dispatcher()) | 470 if (dispatcher()) |
| 468 web_contents = dispatcher()->GetAssociatedWebContents(); | 471 web_contents = dispatcher()->GetAssociatedWebContents(); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() { | 575 ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() { |
| 573 return RespondNow(RunSync() ? ArgumentList(std::move(results_)) | 576 return RespondNow(RunSync() ? ArgumentList(std::move(results_)) |
| 574 : Error(error_)); | 577 : Error(error_)); |
| 575 } | 578 } |
| 576 | 579 |
| 577 // static | 580 // static |
| 578 bool SyncIOThreadExtensionFunction::ValidationFailure( | 581 bool SyncIOThreadExtensionFunction::ValidationFailure( |
| 579 SyncIOThreadExtensionFunction* function) { | 582 SyncIOThreadExtensionFunction* function) { |
| 580 return false; | 583 return false; |
| 581 } | 584 } |
| OLD | NEW |