Chromium Code Reviews| Index: components/dom_distiller/content/browser/dom_distiller_viewer_source.cc |
| diff --git a/components/dom_distiller/content/browser/dom_distiller_viewer_source.cc b/components/dom_distiller/content/browser/dom_distiller_viewer_source.cc |
| index 8ae7f8ca262e909edf196c878d8ddf4ae86d0fee..8b64992dce6e7d59f4c5950ef7ae8dd58616db81 100644 |
| --- a/components/dom_distiller/content/browser/dom_distiller_viewer_source.cc |
| +++ b/components/dom_distiller/content/browser/dom_distiller_viewer_source.cc |
| @@ -32,6 +32,7 @@ |
| #include "components/dom_distiller/core/viewer.h" |
| #include "content/public/browser/navigation_details.h" |
| #include "content/public/browser/navigation_entry.h" |
| +#include "content/public/browser/navigation_handle.h" |
| #include "content/public/browser/render_frame_host.h" |
| #include "content/public/browser/render_view_host.h" |
| #include "content/public/browser/web_contents.h" |
| @@ -56,13 +57,13 @@ class DomDistillerViewerSource::RequestViewerHandle |
| RequestViewerHandle(content::WebContents* web_contents, |
| const std::string& expected_scheme, |
| const std::string& expected_request_path, |
| - DistilledPagePrefs* distilled_page_prefs); |
| + DistilledPagePrefs* distilled_page_prefs, |
| + DistillerUIHandle* ui_handle); |
| ~RequestViewerHandle() override; |
| // content::WebContentsObserver implementation: |
| - void DidNavigateMainFrame( |
| - const content::LoadCommittedDetails& details, |
| - const content::FrameNavigateParams& params) override; |
| + void DidFinishNavigation( |
| + content::NavigationHandle* navigation_handle) override; |
| void RenderProcessGone(base::TerminationStatus status) override; |
| void WebContentsDestroyed() override; |
| void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
| @@ -91,17 +92,24 @@ class DomDistillerViewerSource::RequestViewerHandle |
| // Temporary store of pending JavaScript if the page isn't ready to receive |
| // data from distillation. |
| std::string buffer_; |
| + |
| + // An object for accessing chrome-specific UI controls including external |
| + // feedback and opening the distiller settings. Guaranteed to outlive this |
| + // object. |
| + DistillerUIHandle* distiller_ui_handle_; |
| }; |
| DomDistillerViewerSource::RequestViewerHandle::RequestViewerHandle( |
| content::WebContents* web_contents, |
| const std::string& expected_scheme, |
| const std::string& expected_request_path, |
| - DistilledPagePrefs* distilled_page_prefs) |
| + DistilledPagePrefs* distilled_page_prefs, |
| + DistillerUIHandle* ui_handle) |
| : DomDistillerRequestViewBase(distilled_page_prefs), |
| expected_scheme_(expected_scheme), |
| expected_request_path_(expected_request_path), |
| - waiting_for_page_ready_(true) { |
| + waiting_for_page_ready_(true), |
| + distiller_ui_handle_(ui_handle) { |
| content::WebContentsObserver::Observe(web_contents); |
| distilled_page_prefs_->AddObserver(this); |
| } |
| @@ -122,13 +130,35 @@ void DomDistillerViewerSource::RequestViewerHandle::SendJavaScript( |
| } |
| } |
| -void DomDistillerViewerSource::RequestViewerHandle::DidNavigateMainFrame( |
| - const content::LoadCommittedDetails& details, |
| - const content::FrameNavigateParams& params) { |
| - const GURL& navigation = details.entry->GetURL(); |
| - if (details.is_in_page || (navigation.SchemeIs(expected_scheme_.c_str()) && |
| - expected_request_path_ == navigation.query())) { |
| +void DomDistillerViewerSource::RequestViewerHandle::DidFinishNavigation( |
| + content::NavigationHandle* navigation_handle) { |
| + const GURL& navigation = navigation_handle->GetURL(); |
| + bool expected_main_view_request = |
| + navigation.SchemeIs(expected_scheme_.c_str()) && |
| + expected_request_path_ == navigation.query(); |
| + if (navigation_handle->IsSamePage() || expected_main_view_request) { |
| // In-page navigations, as well as the main view request can be ignored. |
| + if (expected_main_view_request) { |
| + content::RenderFrameHost* render_frame_host = |
| + navigation_handle->GetRenderFrameHost(); |
| + content::RenderViewHost* render_view_host = |
| + render_frame_host->GetRenderViewHost(); |
| + CHECK_EQ(0, render_view_host->GetEnabledBindings()); |
| + |
| + // Add mojo service for JavaScript functionality. This is the receiving |
| + // end of this particular service. |
| + render_frame_host->GetInterfaceRegistry()->AddInterface( |
| + base::Bind(&CreateDistillerJavaScriptService, |
| + render_frame_host, |
| + distiller_ui_handle_)); |
| + |
| + // Tell the renderer that this is currently a distilled page. |
| + mojom::DistillerPageNotifierServicePtr page_notifier_service; |
| + render_frame_host->GetRemoteInterfaces()->GetInterface( |
| + &page_notifier_service); |
| + DCHECK(page_notifier_service); |
| + page_notifier_service->NotifyIsDistillerPage(); |
| + } |
| return; |
| } |
| @@ -195,18 +225,9 @@ std::string DomDistillerViewerSource::GetSource() const { |
| void DomDistillerViewerSource::StartDataRequest( |
|
nyquist
2016/09/19 22:26:59
Since you're changing which method we override, sh
jam
2016/09/19 22:43:23
sorry that was a bad merge, this change shouldn't
|
| const std::string& path, |
| - int render_process_id, |
| - int render_frame_id, |
| + const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
|
nyquist
2016/09/19 22:27:00
Does this require including content/public/browser
|
| const content::URLDataSource::GotDataCallback& callback) { |
| - content::RenderFrameHost* render_frame_host = |
| - content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
| - if (!render_frame_host) |
| - return; |
| - content::RenderViewHost* render_view_host = |
| - render_frame_host->GetRenderViewHost(); |
| - DCHECK(render_view_host); |
| - CHECK_EQ(0, render_view_host->GetEnabledBindings()); |
| - |
| + content::WebContents* web_contents = wc_getter.Run(); |
|
nyquist
2016/09/19 22:27:00
Are we guaranteed that the info used to create the
jam
2016/09/19 22:43:23
(it's removed in this patch now, but yes it's guar
|
| if (kViewerCssPath == path) { |
| std::string css = viewer::GetCss(); |
| callback.Run(base::RefCountedString::TakeString(&css)); |
| @@ -223,16 +244,15 @@ void DomDistillerViewerSource::StartDataRequest( |
| dom_distiller_service_->GetDistilledPagePrefs()->SetFontScaling(scale); |
| } |
| } |
| - content::WebContents* web_contents = |
| - content::WebContents::FromRenderFrameHost(render_frame_host); |
| - DCHECK(web_contents); |
| + |
| // An empty |path| is invalid, but guard against it. If not empty, assume |
| // |path| starts with '?', which is stripped away. |
| const std::string path_after_query_separator = |
| path.size() > 0 ? path.substr(1) : ""; |
| RequestViewerHandle* request_viewer_handle = |
| new RequestViewerHandle(web_contents, scheme_, path_after_query_separator, |
| - dom_distiller_service_->GetDistilledPagePrefs()); |
| + dom_distiller_service_->GetDistilledPagePrefs(), |
| + distiller_ui_handle_); |
| std::unique_ptr<ViewerHandle> viewer_handle = viewer::CreateViewRequest( |
| dom_distiller_service_, path, request_viewer_handle, |
| web_contents->GetContainerBounds().size()); |
| @@ -243,20 +263,6 @@ void DomDistillerViewerSource::StartDataRequest( |
| dom_distiller_service_->GetDistilledPagePrefs()->GetTheme(), |
| dom_distiller_service_->GetDistilledPagePrefs()->GetFontFamily()); |
| - // Add mojo service for JavaScript functionality. This is the receiving end |
| - // of this particular service. |
| - render_frame_host->GetInterfaceRegistry()->AddInterface( |
| - base::Bind(&CreateDistillerJavaScriptService, |
| - render_frame_host, |
| - distiller_ui_handle_.get())); |
| - |
| - // Tell the renderer that this is currently a distilled page. |
| - mojom::DistillerPageNotifierServicePtr page_notifier_service; |
| - render_frame_host->GetRemoteInterfaces()->GetInterface( |
| - &page_notifier_service); |
| - DCHECK(page_notifier_service); |
| - page_notifier_service->NotifyIsDistillerPage(); |
| - |
| if (viewer_handle) { |
| // The service returned a |ViewerHandle| and guarantees it will call |
| // the |RequestViewerHandle|, so passing ownership to it, to ensure the |