| 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> | |
| 8 #include <string> | 7 #include <string> |
| 9 #include <vector> | 8 #include <vector> |
| 10 | 9 |
| 11 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
| 12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 14 #include "base/metrics/user_metrics.h" | 13 #include "base/metrics/user_metrics.h" |
| 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "components/dom_distiller/content/browser/distiller_javascript_service_
impl.h" | 17 #include "components/dom_distiller/content/browser/distiller_javascript_service_
impl.h" |
| 17 #include "components/dom_distiller/content/browser/distiller_javascript_utils.h" | 18 #include "components/dom_distiller/content/browser/distiller_javascript_utils.h" |
| 18 #include "components/dom_distiller/content/browser/external_feedback_reporter.h" | 19 #include "components/dom_distiller/content/browser/external_feedback_reporter.h" |
| 19 #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" |
| 20 #include "components/dom_distiller/core/distilled_page_prefs.h" | 21 #include "components/dom_distiller/core/distilled_page_prefs.h" |
| 21 #include "components/dom_distiller/core/dom_distiller_request_view_base.h" | 22 #include "components/dom_distiller/core/dom_distiller_request_view_base.h" |
| 22 #include "components/dom_distiller/core/dom_distiller_service.h" | 23 #include "components/dom_distiller/core/dom_distiller_service.h" |
| 23 #include "components/dom_distiller/core/experiments.h" | 24 #include "components/dom_distiller/core/experiments.h" |
| 24 #include "components/dom_distiller/core/feedback_reporter.h" | 25 #include "components/dom_distiller/core/feedback_reporter.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 105 |
| 105 DomDistillerViewerSource::RequestViewerHandle::~RequestViewerHandle() { | 106 DomDistillerViewerSource::RequestViewerHandle::~RequestViewerHandle() { |
| 106 distilled_page_prefs_->RemoveObserver(this); | 107 distilled_page_prefs_->RemoveObserver(this); |
| 107 } | 108 } |
| 108 | 109 |
| 109 void DomDistillerViewerSource::RequestViewerHandle::SendJavaScript( | 110 void DomDistillerViewerSource::RequestViewerHandle::SendJavaScript( |
| 110 const std::string& buffer) { | 111 const std::string& buffer) { |
| 111 if (waiting_for_page_ready_) { | 112 if (waiting_for_page_ready_) { |
| 112 buffer_ += buffer; | 113 buffer_ += buffer; |
| 113 } else { | 114 } else { |
| 115 DCHECK(buffer_.empty()); |
| 114 if (web_contents()) { | 116 if (web_contents()) { |
| 115 RunIsolatedJavaScript(web_contents()->GetMainFrame(), buffer); | 117 RunIsolatedJavaScript(web_contents()->GetMainFrame(), buffer); |
| 116 } | 118 } |
| 117 } | 119 } |
| 118 } | 120 } |
| 119 | 121 |
| 120 void DomDistillerViewerSource::RequestViewerHandle::DidNavigateMainFrame( | 122 void DomDistillerViewerSource::RequestViewerHandle::DidNavigateMainFrame( |
| 121 const content::LoadCommittedDetails& details, | 123 const content::LoadCommittedDetails& details, |
| 122 const content::FrameNavigateParams& params) { | 124 const content::FrameNavigateParams& params) { |
| 123 const GURL& navigation = details.entry->GetURL(); | 125 const GURL& navigation = details.entry->GetURL(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 147 // any pending data stored in |buffer_| is released. | 149 // any pending data stored in |buffer_| is released. |
| 148 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 150 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 149 } | 151 } |
| 150 | 152 |
| 151 void DomDistillerViewerSource::RequestViewerHandle::DidFinishLoad( | 153 void DomDistillerViewerSource::RequestViewerHandle::DidFinishLoad( |
| 152 content::RenderFrameHost* render_frame_host, | 154 content::RenderFrameHost* render_frame_host, |
| 153 const GURL& validated_url) { | 155 const GURL& validated_url) { |
| 154 if (render_frame_host->GetParent()) { | 156 if (render_frame_host->GetParent()) { |
| 155 return; | 157 return; |
| 156 } | 158 } |
| 159 |
| 160 // No SendJavaScript() calls allowed before |buffer_| is run and cleared. |
| 157 waiting_for_page_ready_ = false; | 161 waiting_for_page_ready_ = false; |
| 158 if (!buffer_.empty()) { | 162 if (!buffer_.empty()) { |
| 159 RunIsolatedJavaScript(web_contents()->GetMainFrame(), buffer_); | 163 RunIsolatedJavaScript(web_contents()->GetMainFrame(), buffer_); |
| 160 buffer_.clear(); | 164 buffer_.clear(); |
| 161 } | 165 } |
| 162 if (IsErrorPage()) { | 166 // No need to Cancel() here. |
| 163 Cancel(); // This will cause the object to clean itself up. | |
| 164 } | |
| 165 } | 167 } |
| 166 | 168 |
| 167 DomDistillerViewerSource::DomDistillerViewerSource( | 169 DomDistillerViewerSource::DomDistillerViewerSource( |
| 168 DomDistillerServiceInterface* dom_distiller_service, | 170 DomDistillerServiceInterface* dom_distiller_service, |
| 169 const std::string& scheme, | 171 const std::string& scheme, |
| 170 scoped_ptr<ExternalFeedbackReporter> external_reporter) | 172 scoped_ptr<ExternalFeedbackReporter> external_reporter) |
| 171 : scheme_(scheme), | 173 : scheme_(scheme), |
| 172 dom_distiller_service_(dom_distiller_service), | 174 dom_distiller_service_(dom_distiller_service), |
| 173 external_feedback_reporter_(external_reporter.Pass()) { | 175 external_feedback_reporter_(external_reporter.Pass()) { |
| 174 } | 176 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 195 CHECK_EQ(0, render_view_host->GetEnabledBindings()); | 197 CHECK_EQ(0, render_view_host->GetEnabledBindings()); |
| 196 | 198 |
| 197 if (kViewerCssPath == path) { | 199 if (kViewerCssPath == path) { |
| 198 std::string css = viewer::GetCss(); | 200 std::string css = viewer::GetCss(); |
| 199 callback.Run(base::RefCountedString::TakeString(&css)); | 201 callback.Run(base::RefCountedString::TakeString(&css)); |
| 200 return; | 202 return; |
| 201 } else if (kViewerViewOriginalPath == path) { | 203 } else if (kViewerViewOriginalPath == path) { |
| 202 content::RecordAction(base::UserMetricsAction("DomDistiller_ViewOriginal")); | 204 content::RecordAction(base::UserMetricsAction("DomDistiller_ViewOriginal")); |
| 203 callback.Run(NULL); | 205 callback.Run(NULL); |
| 204 return; | 206 return; |
| 207 } else if (base::StartsWith(path, kViewerSaveFontScalingPath, |
| 208 base::CompareCase::SENSITIVE)) { |
| 209 double scale = 1.0; |
| 210 if (base::StringToDouble( |
| 211 path.substr(strlen(kViewerSaveFontScalingPath)), &scale)) { |
| 212 dom_distiller_service_->GetDistilledPagePrefs()->SetFontScaling(scale); |
| 213 } |
| 205 } | 214 } |
| 206 content::WebContents* web_contents = | 215 content::WebContents* web_contents = |
| 207 content::WebContents::FromRenderFrameHost(render_frame_host); | 216 content::WebContents::FromRenderFrameHost(render_frame_host); |
| 208 DCHECK(web_contents); | 217 DCHECK(web_contents); |
| 209 // An empty |path| is invalid, but guard against it. If not empty, assume | 218 // An empty |path| is invalid, but guard against it. If not empty, assume |
| 210 // |path| starts with '?', which is stripped away. | 219 // |path| starts with '?', which is stripped away. |
| 211 const std::string path_after_query_separator = | 220 const std::string path_after_query_separator = |
| 212 path.size() > 0 ? path.substr(1) : ""; | 221 path.size() > 0 ? path.substr(1) : ""; |
| 213 RequestViewerHandle* request_viewer_handle = | 222 RequestViewerHandle* request_viewer_handle = |
| 214 new RequestViewerHandle(web_contents, scheme_, path_after_query_separator, | 223 new RequestViewerHandle(web_contents, scheme_, path_after_query_separator, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc() | 285 std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc() |
| 277 const { | 286 const { |
| 278 return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;"; | 287 return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;"; |
| 279 } | 288 } |
| 280 | 289 |
| 281 std::string DomDistillerViewerSource::GetContentSecurityPolicyFrameSrc() const { | 290 std::string DomDistillerViewerSource::GetContentSecurityPolicyFrameSrc() const { |
| 282 return "frame-src *;"; | 291 return "frame-src *;"; |
| 283 } | 292 } |
| 284 | 293 |
| 285 } // namespace dom_distiller | 294 } // namespace dom_distiller |
| OLD | NEW |