| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/dom_distiller_viewer_source.h
" | 5 #include "components/dom_distiller/content/browser/dom_distiller_viewer_source.h
" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 CHECK_EQ(0, render_view_host->GetEnabledBindings()); | 195 CHECK_EQ(0, render_view_host->GetEnabledBindings()); |
| 196 | 196 |
| 197 if (kViewerCssPath == path) { | 197 if (kViewerCssPath == path) { |
| 198 std::string css = viewer::GetCss(); | 198 std::string css = viewer::GetCss(); |
| 199 callback.Run(base::RefCountedString::TakeString(&css)); | 199 callback.Run(base::RefCountedString::TakeString(&css)); |
| 200 return; | 200 return; |
| 201 } else if (kViewerViewOriginalPath == path) { | 201 } else if (kViewerViewOriginalPath == path) { |
| 202 content::RecordAction(base::UserMetricsAction("DomDistiller_ViewOriginal")); | 202 content::RecordAction(base::UserMetricsAction("DomDistiller_ViewOriginal")); |
| 203 callback.Run(NULL); | 203 callback.Run(NULL); |
| 204 return; | 204 return; |
| 205 } else if (kFeedbackBad == path) { | |
| 206 FeedbackReporter::ReportQuality(false); | |
| 207 callback.Run(NULL); | |
| 208 if (!external_feedback_reporter_) | |
| 209 return; | |
| 210 content::WebContents* contents = | |
| 211 content::WebContents::FromRenderFrameHost(render_frame_host); | |
| 212 external_feedback_reporter_->ReportExternalFeedback( | |
| 213 contents, contents->GetURL(), false); | |
| 214 return; | |
| 215 } else if (kFeedbackGood == path) { | |
| 216 FeedbackReporter::ReportQuality(true); | |
| 217 callback.Run(NULL); | |
| 218 return; | |
| 219 } | 205 } |
| 220 content::WebContents* web_contents = | 206 content::WebContents* web_contents = |
| 221 content::WebContents::FromRenderFrameHost(render_frame_host); | 207 content::WebContents::FromRenderFrameHost(render_frame_host); |
| 222 DCHECK(web_contents); | 208 DCHECK(web_contents); |
| 223 // An empty |path| is invalid, but guard against it. If not empty, assume | 209 // An empty |path| is invalid, but guard against it. If not empty, assume |
| 224 // |path| starts with '?', which is stripped away. | 210 // |path| starts with '?', which is stripped away. |
| 225 const std::string path_after_query_separator = | 211 const std::string path_after_query_separator = |
| 226 path.size() > 0 ? path.substr(1) : ""; | 212 path.size() > 0 ? path.substr(1) : ""; |
| 227 RequestViewerHandle* request_viewer_handle = | 213 RequestViewerHandle* request_viewer_handle = |
| 228 new RequestViewerHandle(web_contents, scheme_, path_after_query_separator, | 214 new RequestViewerHandle(web_contents, scheme_, path_after_query_separator, |
| 229 dom_distiller_service_->GetDistilledPagePrefs()); | 215 dom_distiller_service_->GetDistilledPagePrefs()); |
| 230 scoped_ptr<ViewerHandle> viewer_handle = viewer::CreateViewRequest( | 216 scoped_ptr<ViewerHandle> viewer_handle = viewer::CreateViewRequest( |
| 231 dom_distiller_service_, path, request_viewer_handle, | 217 dom_distiller_service_, path, request_viewer_handle, |
| 232 web_contents->GetContainerBounds().size()); | 218 web_contents->GetContainerBounds().size()); |
| 233 | 219 |
| 234 GURL current_url(url_utils::GetValueForKeyInUrlPathQuery(path, kUrlKey)); | 220 GURL current_url(url_utils::GetValueForKeyInUrlPathQuery(path, kUrlKey)); |
| 235 std::string unsafe_page_html = viewer::GetUnsafeArticleTemplateHtml( | 221 std::string unsafe_page_html = viewer::GetUnsafeArticleTemplateHtml( |
| 236 url_utils::GetOriginalUrlFromDistillerUrl(current_url).spec(), | 222 url_utils::GetOriginalUrlFromDistillerUrl(current_url).spec(), |
| 237 dom_distiller_service_->GetDistilledPagePrefs()->GetTheme(), | 223 dom_distiller_service_->GetDistilledPagePrefs()->GetTheme(), |
| 238 dom_distiller_service_->GetDistilledPagePrefs()->GetFontFamily()); | 224 dom_distiller_service_->GetDistilledPagePrefs()->GetFontFamily()); |
| 239 | 225 |
| 240 // Add mojo service for JavaScript functionality. This is the receiving end | 226 // Add mojo service for JavaScript functionality. This is the receiving end |
| 241 // of this particular service. | 227 // of this particular service. |
| 242 render_frame_host->GetServiceRegistry()->AddService( | 228 render_frame_host->GetServiceRegistry()->AddService( |
| 243 base::Bind(&CreateDistillerJavaScriptService)); | 229 base::Bind(&CreateDistillerJavaScriptService, |
| 230 render_frame_host, |
| 231 external_feedback_reporter_.get())); |
| 244 | 232 |
| 245 // Tell the renderer that this is currently a distilled page. | 233 // Tell the renderer that this is currently a distilled page. |
| 246 DistillerPageNotifierServicePtr page_notifier_service; | 234 DistillerPageNotifierServicePtr page_notifier_service; |
| 247 render_frame_host->GetServiceRegistry()->ConnectToRemoteService( | 235 render_frame_host->GetServiceRegistry()->ConnectToRemoteService( |
| 248 mojo::GetProxy(&page_notifier_service)); | 236 mojo::GetProxy(&page_notifier_service)); |
| 249 DCHECK(page_notifier_service); | 237 DCHECK(page_notifier_service); |
| 250 page_notifier_service->NotifyIsDistillerPage(); | 238 page_notifier_service->NotifyIsDistillerPage(); |
| 251 | 239 |
| 252 if (viewer_handle) { | 240 if (viewer_handle) { |
| 253 // The service returned a |ViewerHandle| and guarantees it will call | 241 // The service returned a |ViewerHandle| and guarantees it will call |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc() | 276 std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc() |
| 289 const { | 277 const { |
| 290 return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;"; | 278 return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;"; |
| 291 } | 279 } |
| 292 | 280 |
| 293 std::string DomDistillerViewerSource::GetContentSecurityPolicyFrameSrc() const { | 281 std::string DomDistillerViewerSource::GetContentSecurityPolicyFrameSrc() const { |
| 294 return "frame-src *;"; | 282 return "frame-src *;"; |
| 295 } | 283 } |
| 296 | 284 |
| 297 } // namespace dom_distiller | 285 } // namespace dom_distiller |
| OLD | NEW |