Chromium Code Reviews| 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/dom_distiller_viewer_source.h" | 5 #include "components/dom_distiller/content/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 |
| 11 #include "base/logging.h" | |
| 12 #include "base/memory/ref_counted_memory.h" | 11 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 15 #include "base/metrics/user_metrics.h" | 14 #include "base/metrics/user_metrics.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 17 #include "components/dom_distiller/core/distilled_page_prefs.h" | 16 #include "components/dom_distiller/core/distilled_page_prefs.h" |
| 18 #include "components/dom_distiller/core/dom_distiller_service.h" | 17 #include "components/dom_distiller/core/dom_distiller_service.h" |
| 18 #include "components/dom_distiller/core/feedback_reporter.h" | |
| 19 #include "components/dom_distiller/core/task_tracker.h" | 19 #include "components/dom_distiller/core/task_tracker.h" |
| 20 #include "components/dom_distiller/core/url_constants.h" | 20 #include "components/dom_distiller/core/url_constants.h" |
| 21 #include "components/dom_distiller/core/viewer.h" | 21 #include "components/dom_distiller/core/viewer.h" |
| 22 #include "content/public/browser/navigation_details.h" | 22 #include "content/public/browser/navigation_details.h" |
| 23 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
| 24 #include "content/public/browser/render_frame_host.h" | 24 #include "content/public/browser/render_frame_host.h" |
| 25 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
| 26 #include "content/public/browser/user_metrics.h" | 26 #include "content/public/browser/user_metrics.h" |
| 27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/browser/web_contents_observer.h" | 28 #include "content/public/browser/web_contents_observer.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 if (!render_frame_host) return; | 301 if (!render_frame_host) return; |
| 302 content::RenderViewHost* render_view_host = | 302 content::RenderViewHost* render_view_host = |
| 303 render_frame_host->GetRenderViewHost(); | 303 render_frame_host->GetRenderViewHost(); |
| 304 DCHECK(render_view_host); | 304 DCHECK(render_view_host); |
| 305 CHECK_EQ(0, render_view_host->GetEnabledBindings()); | 305 CHECK_EQ(0, render_view_host->GetEnabledBindings()); |
| 306 | 306 |
| 307 if (kViewerCssPath == path) { | 307 if (kViewerCssPath == path) { |
| 308 std::string css = viewer::GetCss(); | 308 std::string css = viewer::GetCss(); |
| 309 callback.Run(base::RefCountedString::TakeString(&css)); | 309 callback.Run(base::RefCountedString::TakeString(&css)); |
| 310 return; | 310 return; |
| 311 } | 311 } else if (kViewerJsPath == path) { |
| 312 if (kViewerJsPath == path) { | |
| 313 std::string js = viewer::GetJavaScript(); | 312 std::string js = viewer::GetJavaScript(); |
| 314 callback.Run(base::RefCountedString::TakeString(&js)); | 313 callback.Run(base::RefCountedString::TakeString(&js)); |
| 315 return; | 314 return; |
| 316 } | 315 } else if (kViewerViewOriginalPath == path) { |
| 317 if (kViewerViewOriginalPath == path) { | |
| 318 content::RecordAction(base::UserMetricsAction("DomDistiller_ViewOriginal")); | 316 content::RecordAction(base::UserMetricsAction("DomDistiller_ViewOriginal")); |
| 319 callback.Run(NULL); | 317 callback.Run(NULL); |
| 320 return; | 318 return; |
| 319 } else if (kFeedbackBad == path) { | |
| 320 FeedbackReporter::ReportQuality(false); | |
|
wychen
2015/04/27 21:18:49
Do we need "callback.Run(NULL)" like kViewerViewOr
cjhopman
2015/04/27 21:22:57
Yeah, probably. Otherwise these gets will just be
mdjones
2015/04/27 22:09:02
CL fixing this issue: https://codereview.chromium.
| |
| 321 return; | |
| 322 } else if (kFeedbackGood == path) { | |
| 323 FeedbackReporter::ReportQuality(true); | |
| 324 return; | |
| 321 } | 325 } |
| 322 content::WebContents* web_contents = | 326 content::WebContents* web_contents = |
| 323 content::WebContents::FromRenderFrameHost(render_frame_host); | 327 content::WebContents::FromRenderFrameHost(render_frame_host); |
| 324 DCHECK(web_contents); | 328 DCHECK(web_contents); |
| 325 // An empty |path| is invalid, but guard against it. If not empty, assume | 329 // An empty |path| is invalid, but guard against it. If not empty, assume |
| 326 // |path| starts with '?', which is stripped away. | 330 // |path| starts with '?', which is stripped away. |
| 327 const std::string path_after_query_separator = | 331 const std::string path_after_query_separator = |
| 328 path.size() > 0 ? path.substr(1) : ""; | 332 path.size() > 0 ? path.substr(1) : ""; |
| 329 RequestViewerHandle* request_viewer_handle = new RequestViewerHandle( | 333 RequestViewerHandle* request_viewer_handle = new RequestViewerHandle( |
| 330 web_contents, scheme_, path_after_query_separator, callback, | 334 web_contents, scheme_, path_after_query_separator, callback, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 const net::URLRequest* request, | 369 const net::URLRequest* request, |
| 366 std::string* path) const { | 370 std::string* path) const { |
| 367 } | 371 } |
| 368 | 372 |
| 369 std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc() | 373 std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc() |
| 370 const { | 374 const { |
| 371 return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;"; | 375 return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;"; |
| 372 } | 376 } |
| 373 | 377 |
| 374 } // namespace dom_distiller | 378 } // namespace dom_distiller |
| OLD | NEW |