| 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 "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "content/public/browser/navigation_handle.h" |
| 8 #include "content/public/browser/render_frame_host.h" | 9 #include "content/public/browser/render_frame_host.h" |
| 9 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 10 #include "content/public/browser/web_contents_observer.h" | 11 #include "content/public/browser/web_contents_observer.h" |
| 11 #include "content/public/browser/web_contents_user_data.h" | 12 #include "content/public/browser/web_contents_user_data.h" |
| 12 #include "mojo/public/cpp/bindings/strong_binding.h" | 13 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 13 #include "services/service_manager/public/cpp/interface_registry.h" | 14 #include "services/service_manager/public/cpp/interface_registry.h" |
| 14 | 15 |
| 15 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | 16 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
| 16 dom_distiller::DistillabilityDriver); | 17 dom_distiller::DistillabilityDriver); |
| 17 | 18 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // This method is invoked if any of the active RenderFrameHosts are swapped. | 82 // This method is invoked if any of the active RenderFrameHosts are swapped. |
| 82 // Only add the mojo service to the main frame host. | 83 // Only add the mojo service to the main frame host. |
| 83 if (!web_contents() || web_contents()->GetMainFrame() != new_host) return; | 84 if (!web_contents() || web_contents()->GetMainFrame() != new_host) return; |
| 84 | 85 |
| 85 // If the RenderFrameHost changes (this will happen if the user navigates to | 86 // If the RenderFrameHost changes (this will happen if the user navigates to |
| 86 // or from a native page), the service needs to be attached to that host. | 87 // or from a native page), the service needs to be attached to that host. |
| 87 mojo_needs_setup_ = true; | 88 mojo_needs_setup_ = true; |
| 88 SetupMojoService(new_host); | 89 SetupMojoService(new_host); |
| 89 } | 90 } |
| 90 | 91 |
| 91 void DistillabilityDriver::DidStartProvisionalLoadForFrame( | 92 void DistillabilityDriver::ReadyToCommitNavigation( |
| 92 content::RenderFrameHost* render_frame_host, const GURL& validated_url, | 93 content::NavigationHandle* navigation_handle) { |
| 93 bool is_error_page) { | 94 if (!navigation_handle->IsSamePage()) |
| 94 SetupMojoService(render_frame_host); | 95 SetupMojoService(navigation_handle->GetRenderFrameHost()); |
| 95 } | 96 } |
| 96 | 97 |
| 97 void DistillabilityDriver::SetupMojoService( | 98 void DistillabilityDriver::SetupMojoService( |
| 98 content::RenderFrameHost* frame_host) { | 99 content::RenderFrameHost* frame_host) { |
| 99 if (!frame_host || !frame_host->GetInterfaceRegistry() | 100 if (!frame_host || !frame_host->GetInterfaceRegistry() |
| 100 || !mojo_needs_setup_) { | 101 || !mojo_needs_setup_) { |
| 101 return; | 102 return; |
| 102 } | 103 } |
| 103 | 104 |
| 104 frame_host->GetInterfaceRegistry()->AddInterface( | 105 frame_host->GetInterfaceRegistry()->AddInterface( |
| 105 base::Bind(&DistillabilityDriver::CreateDistillabilityService, | 106 base::Bind(&DistillabilityDriver::CreateDistillabilityService, |
| 106 weak_factory_.GetWeakPtr())); | 107 weak_factory_.GetWeakPtr())); |
| 107 mojo_needs_setup_ = false; | 108 mojo_needs_setup_ = false; |
| 108 } | 109 } |
| 109 | 110 |
| 110 } // namespace dom_distiller | 111 } // namespace dom_distiller |
| OLD | NEW |