Chromium Code Reviews| Index: components/dom_distiller/content/browser/distillability_driver.cc |
| diff --git a/components/dom_distiller/content/browser/distillability_driver.cc b/components/dom_distiller/content/browser/distillability_driver.cc |
| index 413e90786855d8bbc557ae9653ba4aaf93db8b33..d6c109a6ddd1509dd40e43a317a1eb93390d0933 100644 |
| --- a/components/dom_distiller/content/browser/distillability_driver.cc |
| +++ b/components/dom_distiller/content/browser/distillability_driver.cc |
| @@ -25,7 +25,10 @@ class DistillabilityServiceImpl : public mojom::DistillabilityService { |
| : binding_(this, std::move(request)), |
| distillability_driver_(distillability_driver) {} |
| - ~DistillabilityServiceImpl() override {} |
| + ~DistillabilityServiceImpl() override { |
| + if (!distillability_driver_) return; |
| + distillability_driver_->SetNeedsMojoSetup(); |
| + } |
| void NotifyIsDistillable(bool is_distillable, bool is_last_update) override { |
| if (!distillability_driver_) return; |
| @@ -40,6 +43,7 @@ class DistillabilityServiceImpl : public mojom::DistillabilityService { |
| DistillabilityDriver::DistillabilityDriver( |
| content::WebContents* web_contents) |
| : content::WebContentsObserver(web_contents), |
| + mojo_needs_setup_(true), |
| weak_factory_(this) { |
| if (!web_contents) return; |
| SetupMojoService(web_contents->GetMainFrame()); |
| @@ -66,11 +70,20 @@ void DistillabilityDriver::OnDistillability( |
| m_delegate_.Run(distillable, is_last); |
| } |
| +void DistillabilityDriver::SetNeedsMojoSetup() { |
| + mojo_needs_setup_ = true; |
| +} |
| + |
| void DistillabilityDriver::RenderFrameHostChanged( |
| content::RenderFrameHost* old_host, |
| content::RenderFrameHost* new_host) { |
| + // This method is invoked if a if any of the active RenderFrameHosts is |
|
wychen
2016/07/08 23:10:20
This line need some fixes.
mdjones
2016/07/11 15:50:44
Done.
|
| + // swapped. Only add the mojo service to the main frame host. |
| + if (!web_contents() || web_contents()->GetMainFrame() != new_host) return; |
| + |
| // If the RenderFrameHost changes (this will happen if the user navigates to |
| // or from a native page), the service needs to be attached to that host. |
| + mojo_needs_setup_ = true; |
| SetupMojoService(new_host); |
| // Clean up the service on the old host if possible. |
| if (!old_host) return; |
| @@ -86,11 +99,15 @@ void DistillabilityDriver::DidStartProvisionalLoadForFrame( |
| void DistillabilityDriver::SetupMojoService( |
| content::RenderFrameHost* frame_host) { |
| - if (!frame_host || !frame_host->GetInterfaceRegistry()) return; |
| + if (!frame_host || !frame_host->GetInterfaceRegistry() |
| + || !mojo_needs_setup_) { |
| + return; |
| + } |
| frame_host->GetInterfaceRegistry()->AddInterface( |
| base::Bind(&DistillabilityDriver::CreateDistillabilityService, |
| weak_factory_.GetWeakPtr())); |
| + mojo_needs_setup_ = false; |
| } |
| } // namespace dom_distiller |