| 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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/metrics/user_metrics.h" | 13 #include "base/metrics/user_metrics.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "components/dom_distiller/content/browser/distiller_javascript_service_
impl.h" | 17 #include "components/dom_distiller/content/browser/distiller_javascript_service_
impl.h" |
| 18 #include "components/dom_distiller/content/browser/distiller_javascript_utils.h" | 18 #include "components/dom_distiller/content/browser/distiller_javascript_utils.h" |
| 19 #include "components/dom_distiller/content/browser/external_feedback_reporter.h" | 19 #include "components/dom_distiller/content/browser/distiller_ui_handle.h" |
| 20 #include "components/dom_distiller/content/common/distiller_page_notifier_servic
e.mojom.h" | 20 #include "components/dom_distiller/content/common/distiller_page_notifier_servic
e.mojom.h" |
| 21 #include "components/dom_distiller/core/distilled_page_prefs.h" | 21 #include "components/dom_distiller/core/distilled_page_prefs.h" |
| 22 #include "components/dom_distiller/core/dom_distiller_request_view_base.h" | 22 #include "components/dom_distiller/core/dom_distiller_request_view_base.h" |
| 23 #include "components/dom_distiller/core/dom_distiller_service.h" | 23 #include "components/dom_distiller/core/dom_distiller_service.h" |
| 24 #include "components/dom_distiller/core/experiments.h" | 24 #include "components/dom_distiller/core/experiments.h" |
| 25 #include "components/dom_distiller/core/feedback_reporter.h" | 25 #include "components/dom_distiller/core/feedback_reporter.h" |
| 26 #include "components/dom_distiller/core/task_tracker.h" | 26 #include "components/dom_distiller/core/task_tracker.h" |
| 27 #include "components/dom_distiller/core/url_constants.h" | 27 #include "components/dom_distiller/core/url_constants.h" |
| 28 #include "components/dom_distiller/core/url_utils.h" | 28 #include "components/dom_distiller/core/url_utils.h" |
| 29 #include "components/dom_distiller/core/viewer.h" | 29 #include "components/dom_distiller/core/viewer.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 if (!buffer_.empty()) { | 161 if (!buffer_.empty()) { |
| 162 RunIsolatedJavaScript(web_contents()->GetMainFrame(), buffer_); | 162 RunIsolatedJavaScript(web_contents()->GetMainFrame(), buffer_); |
| 163 buffer_.clear(); | 163 buffer_.clear(); |
| 164 } | 164 } |
| 165 // No need to Cancel() here. | 165 // No need to Cancel() here. |
| 166 } | 166 } |
| 167 | 167 |
| 168 DomDistillerViewerSource::DomDistillerViewerSource( | 168 DomDistillerViewerSource::DomDistillerViewerSource( |
| 169 DomDistillerServiceInterface* dom_distiller_service, | 169 DomDistillerServiceInterface* dom_distiller_service, |
| 170 const std::string& scheme, | 170 const std::string& scheme, |
| 171 scoped_ptr<ExternalFeedbackReporter> external_reporter) | 171 scoped_ptr<DistillerUIHandle> ui_handle) |
| 172 : scheme_(scheme), | 172 : scheme_(scheme), |
| 173 dom_distiller_service_(dom_distiller_service), | 173 dom_distiller_service_(dom_distiller_service), |
| 174 external_feedback_reporter_(external_reporter.Pass()) { | 174 distiller_ui_handle_(ui_handle.Pass()) { |
| 175 } | 175 } |
| 176 | 176 |
| 177 DomDistillerViewerSource::~DomDistillerViewerSource() { | 177 DomDistillerViewerSource::~DomDistillerViewerSource() { |
| 178 } | 178 } |
| 179 | 179 |
| 180 std::string DomDistillerViewerSource::GetSource() const { | 180 std::string DomDistillerViewerSource::GetSource() const { |
| 181 return scheme_ + "://"; | 181 return scheme_ + "://"; |
| 182 } | 182 } |
| 183 | 183 |
| 184 void DomDistillerViewerSource::StartDataRequest( | 184 void DomDistillerViewerSource::StartDataRequest( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 std::string unsafe_page_html = viewer::GetUnsafeArticleTemplateHtml( | 225 std::string unsafe_page_html = viewer::GetUnsafeArticleTemplateHtml( |
| 226 url_utils::GetOriginalUrlFromDistillerUrl(current_url).spec(), | 226 url_utils::GetOriginalUrlFromDistillerUrl(current_url).spec(), |
| 227 dom_distiller_service_->GetDistilledPagePrefs()->GetTheme(), | 227 dom_distiller_service_->GetDistilledPagePrefs()->GetTheme(), |
| 228 dom_distiller_service_->GetDistilledPagePrefs()->GetFontFamily()); | 228 dom_distiller_service_->GetDistilledPagePrefs()->GetFontFamily()); |
| 229 | 229 |
| 230 // Add mojo service for JavaScript functionality. This is the receiving end | 230 // Add mojo service for JavaScript functionality. This is the receiving end |
| 231 // of this particular service. | 231 // of this particular service. |
| 232 render_frame_host->GetServiceRegistry()->AddService( | 232 render_frame_host->GetServiceRegistry()->AddService( |
| 233 base::Bind(&CreateDistillerJavaScriptService, | 233 base::Bind(&CreateDistillerJavaScriptService, |
| 234 render_frame_host, | 234 render_frame_host, |
| 235 external_feedback_reporter_.get())); | 235 distiller_ui_handle_.get())); |
| 236 | 236 |
| 237 // Tell the renderer that this is currently a distilled page. | 237 // Tell the renderer that this is currently a distilled page. |
| 238 DistillerPageNotifierServicePtr page_notifier_service; | 238 DistillerPageNotifierServicePtr page_notifier_service; |
| 239 render_frame_host->GetServiceRegistry()->ConnectToRemoteService( | 239 render_frame_host->GetServiceRegistry()->ConnectToRemoteService( |
| 240 mojo::GetProxy(&page_notifier_service)); | 240 mojo::GetProxy(&page_notifier_service)); |
| 241 DCHECK(page_notifier_service); | 241 DCHECK(page_notifier_service); |
| 242 page_notifier_service->NotifyIsDistillerPage(); | 242 page_notifier_service->NotifyIsDistillerPage(); |
| 243 | 243 |
| 244 if (viewer_handle) { | 244 if (viewer_handle) { |
| 245 // The service returned a |ViewerHandle| and guarantees it will call | 245 // The service returned a |ViewerHandle| and guarantees it will call |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc() | 277 std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc() |
| 278 const { | 278 const { |
| 279 return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;"; | 279 return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;"; |
| 280 } | 280 } |
| 281 | 281 |
| 282 std::string DomDistillerViewerSource::GetContentSecurityPolicyFrameSrc() const { | 282 std::string DomDistillerViewerSource::GetContentSecurityPolicyFrameSrc() const { |
| 283 return "frame-src *;"; | 283 return "frame-src *;"; |
| 284 } | 284 } |
| 285 | 285 |
| 286 } // namespace dom_distiller | 286 } // namespace dom_distiller |
| OLD | NEW |