| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/dom_distiller/content/browser/distillability_driver.h" | 5 #include "components/dom_distiller/content/browser/distillability_driver.h" |
| 6 | 6 |
| 7 #include "content/public/browser/render_frame_host.h" | 7 #include "content/public/browser/render_frame_host.h" |
| 8 #include "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" |
| 9 #include "content/public/browser/web_contents_observer.h" | 9 #include "content/public/browser/web_contents_observer.h" |
| 10 #include "content/public/browser/web_contents_user_data.h" | 10 #include "content/public/browser/web_contents_user_data.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 content::RenderFrameHost* old_host, | 78 content::RenderFrameHost* old_host, |
| 79 content::RenderFrameHost* new_host) { | 79 content::RenderFrameHost* new_host) { |
| 80 // This method is invoked if any of the active RenderFrameHosts are swapped. | 80 // This method is invoked if any of the active RenderFrameHosts are swapped. |
| 81 // Only add the mojo service to the main frame host. | 81 // Only add the mojo service to the main frame host. |
| 82 if (!web_contents() || web_contents()->GetMainFrame() != new_host) return; | 82 if (!web_contents() || web_contents()->GetMainFrame() != new_host) return; |
| 83 | 83 |
| 84 // If the RenderFrameHost changes (this will happen if the user navigates to | 84 // If the RenderFrameHost changes (this will happen if the user navigates to |
| 85 // or from a native page), the service needs to be attached to that host. | 85 // or from a native page), the service needs to be attached to that host. |
| 86 mojo_needs_setup_ = true; | 86 mojo_needs_setup_ = true; |
| 87 SetupMojoService(new_host); | 87 SetupMojoService(new_host); |
| 88 // Clean up the service on the old host if possible. | |
| 89 if (!old_host || !old_host->GetInterfaceRegistry()) return; | |
| 90 old_host->GetInterfaceRegistry() | |
| 91 ->RemoveInterface<mojom::DistillabilityService>(); | |
| 92 } | 88 } |
| 93 | 89 |
| 94 void DistillabilityDriver::DidStartProvisionalLoadForFrame( | 90 void DistillabilityDriver::DidStartProvisionalLoadForFrame( |
| 95 content::RenderFrameHost* render_frame_host, const GURL& validated_url, | 91 content::RenderFrameHost* render_frame_host, const GURL& validated_url, |
| 96 bool is_error_page, bool is_iframe_srcdoc) { | 92 bool is_error_page, bool is_iframe_srcdoc) { |
| 97 SetupMojoService(render_frame_host); | 93 SetupMojoService(render_frame_host); |
| 98 } | 94 } |
| 99 | 95 |
| 100 void DistillabilityDriver::SetupMojoService( | 96 void DistillabilityDriver::SetupMojoService( |
| 101 content::RenderFrameHost* frame_host) { | 97 content::RenderFrameHost* frame_host) { |
| 102 if (!frame_host || !frame_host->GetInterfaceRegistry() | 98 if (!frame_host || !frame_host->GetInterfaceRegistry() |
| 103 || !mojo_needs_setup_) { | 99 || !mojo_needs_setup_) { |
| 104 return; | 100 return; |
| 105 } | 101 } |
| 106 | 102 |
| 107 frame_host->GetInterfaceRegistry()->AddInterface( | 103 frame_host->GetInterfaceRegistry()->AddInterface( |
| 108 base::Bind(&DistillabilityDriver::CreateDistillabilityService, | 104 base::Bind(&DistillabilityDriver::CreateDistillabilityService, |
| 109 weak_factory_.GetWeakPtr())); | 105 weak_factory_.GetWeakPtr())); |
| 110 mojo_needs_setup_ = false; | 106 mojo_needs_setup_ = false; |
| 111 } | 107 } |
| 112 | 108 |
| 113 } // namespace dom_distiller | 109 } // namespace dom_distiller |
| OLD | NEW |