| 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/memory/ref_counted_memory.h" | 11 #include "base/memory/ref_counted_memory.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/metrics/user_metrics.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "components/dom_distiller/core/distilled_page_prefs.h" | 16 #include "components/dom_distiller/core/distilled_page_prefs.h" |
| 16 #include "components/dom_distiller/core/dom_distiller_service.h" | 17 #include "components/dom_distiller/core/dom_distiller_service.h" |
| 17 #include "components/dom_distiller/core/task_tracker.h" | 18 #include "components/dom_distiller/core/task_tracker.h" |
| 18 #include "components/dom_distiller/core/url_constants.h" | 19 #include "components/dom_distiller/core/url_constants.h" |
| 19 #include "components/dom_distiller/core/viewer.h" | 20 #include "components/dom_distiller/core/viewer.h" |
| 20 #include "content/public/browser/navigation_details.h" | 21 #include "content/public/browser/navigation_details.h" |
| 21 #include "content/public/browser/navigation_entry.h" | 22 #include "content/public/browser/navigation_entry.h" |
| 22 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
| 23 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 25 #include "content/public/browser/user_metrics.h" |
| 24 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/browser/web_contents_observer.h" | 27 #include "content/public/browser/web_contents_observer.h" |
| 26 #include "net/base/url_util.h" | 28 #include "net/base/url_util.h" |
| 27 #include "net/url_request/url_request.h" | 29 #include "net/url_request/url_request.h" |
| 28 | 30 |
| 29 namespace dom_distiller { | 31 namespace dom_distiller { |
| 30 | 32 |
| 31 // Handles receiving data asynchronously for a specific entry, and passing | 33 // Handles receiving data asynchronously for a specific entry, and passing |
| 32 // it along to the data callback for the data source. Lifetime matches that of | 34 // it along to the data callback for the data source. Lifetime matches that of |
| 33 // the current main frame's page in the Viewer instance. | 35 // the current main frame's page in the Viewer instance. |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 if (kViewerCssPath == path) { | 279 if (kViewerCssPath == path) { |
| 278 std::string css = viewer::GetCss(); | 280 std::string css = viewer::GetCss(); |
| 279 callback.Run(base::RefCountedString::TakeString(&css)); | 281 callback.Run(base::RefCountedString::TakeString(&css)); |
| 280 return; | 282 return; |
| 281 } | 283 } |
| 282 if (kViewerJsPath == path) { | 284 if (kViewerJsPath == path) { |
| 283 std::string js = viewer::GetJavaScript(); | 285 std::string js = viewer::GetJavaScript(); |
| 284 callback.Run(base::RefCountedString::TakeString(&js)); | 286 callback.Run(base::RefCountedString::TakeString(&js)); |
| 285 return; | 287 return; |
| 286 } | 288 } |
| 289 if (kViewerViewOriginalPath == path) { |
| 290 content::RecordAction(base::UserMetricsAction("DomDistiller_ViewOriginal")); |
| 291 callback.Run(NULL); |
| 292 return; |
| 293 } |
| 287 content::WebContents* web_contents = | 294 content::WebContents* web_contents = |
| 288 content::WebContents::FromRenderFrameHost( | 295 content::WebContents::FromRenderFrameHost( |
| 289 content::RenderFrameHost::FromID(render_process_id, | 296 content::RenderFrameHost::FromID(render_process_id, |
| 290 render_frame_id)); | 297 render_frame_id)); |
| 291 DCHECK(web_contents); | 298 DCHECK(web_contents); |
| 292 // An empty |path| is invalid, but guard against it. If not empty, assume | 299 // An empty |path| is invalid, but guard against it. If not empty, assume |
| 293 // |path| starts with '?', which is stripped away. | 300 // |path| starts with '?', which is stripped away. |
| 294 const std::string path_after_query_separator = | 301 const std::string path_after_query_separator = |
| 295 path.size() > 0 ? path.substr(1) : ""; | 302 path.size() > 0 ? path.substr(1) : ""; |
| 296 RequestViewerHandle* request_viewer_handle = new RequestViewerHandle( | 303 RequestViewerHandle* request_viewer_handle = new RequestViewerHandle( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 const net::URLRequest* request, | 346 const net::URLRequest* request, |
| 340 std::string* path) const { | 347 std::string* path) const { |
| 341 } | 348 } |
| 342 | 349 |
| 343 std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc() | 350 std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc() |
| 344 const { | 351 const { |
| 345 return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;"; | 352 return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;"; |
| 346 } | 353 } |
| 347 | 354 |
| 348 } // namespace dom_distiller | 355 } // namespace dom_distiller |
| OLD | NEW |