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/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/metrics/user_metrics.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/core/distilled_page_prefs.h" | 17 #include "components/dom_distiller/core/distilled_page_prefs.h" |
| 17 #include "components/dom_distiller/core/dom_distiller_request_view_base.h" | 18 #include "components/dom_distiller/core/dom_distiller_request_view_base.h" |
| 18 #include "components/dom_distiller/core/dom_distiller_service.h" | 19 #include "components/dom_distiller/core/dom_distiller_service.h" |
| 19 #include "components/dom_distiller/core/external_feedback_reporter.h" | 20 #include "components/dom_distiller/core/external_feedback_reporter.h" |
| 20 #include "components/dom_distiller/core/feedback_reporter.h" | 21 #include "components/dom_distiller/core/feedback_reporter.h" |
| 21 #include "components/dom_distiller/core/task_tracker.h" | 22 #include "components/dom_distiller/core/task_tracker.h" |
| 22 #include "components/dom_distiller/core/url_constants.h" | 23 #include "components/dom_distiller/core/url_constants.h" |
| 23 #include "components/dom_distiller/core/url_utils.h" | 24 #include "components/dom_distiller/core/url_utils.h" |
| 24 #include "components/dom_distiller/core/viewer.h" | 25 #include "components/dom_distiller/core/viewer.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 SendJavaScript(viewer::GetShowFeedbackFormJs()); | 158 SendJavaScript(viewer::GetShowFeedbackFormJs()); |
| 158 | 159 |
| 159 Cancel(); // This will cause the object to clean itself up. | 160 Cancel(); // This will cause the object to clean itself up. |
| 160 return; | 161 return; |
| 161 } | 162 } |
| 162 | 163 |
| 163 if (render_frame_host->GetParent()) { | 164 if (render_frame_host->GetParent()) { |
| 164 return; | 165 return; |
| 165 } | 166 } |
| 166 waiting_for_page_ready_ = false; | 167 waiting_for_page_ready_ = false; |
| 168 SendJavaScript(viewer::GetDistilledPageFontScalingJs( | |
| 169 distilled_page_prefs_->GetFontScaling())); | |
| 167 if (buffer_.empty()) { | 170 if (buffer_.empty()) { |
| 168 return; | 171 return; |
| 169 } | 172 } |
| 170 web_contents()->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16(buffer_)); | 173 web_contents()->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16(buffer_)); |
| 171 buffer_.clear(); | 174 buffer_.clear(); |
| 172 } | 175 } |
| 173 | 176 |
| 174 DomDistillerViewerSource::DomDistillerViewerSource( | 177 DomDistillerViewerSource::DomDistillerViewerSource( |
| 175 DomDistillerServiceInterface* dom_distiller_service, | 178 DomDistillerServiceInterface* dom_distiller_service, |
| 176 const std::string& scheme, | 179 const std::string& scheme, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 return; | 222 return; |
| 220 content::WebContents* contents = | 223 content::WebContents* contents = |
| 221 content::WebContents::FromRenderFrameHost(render_frame_host); | 224 content::WebContents::FromRenderFrameHost(render_frame_host); |
| 222 external_feedback_reporter_->ReportExternalFeedback( | 225 external_feedback_reporter_->ReportExternalFeedback( |
| 223 contents, contents->GetURL(), false); | 226 contents, contents->GetURL(), false); |
| 224 return; | 227 return; |
| 225 } else if (kFeedbackGood == path) { | 228 } else if (kFeedbackGood == path) { |
| 226 FeedbackReporter::ReportQuality(true); | 229 FeedbackReporter::ReportQuality(true); |
| 227 callback.Run(NULL); | 230 callback.Run(NULL); |
| 228 return; | 231 return; |
| 232 } else if (base::StartsWithASCII(path, kViewerSaveFontScalingPath, false)) { | |
| 233 std::stringstream ss; | |
| 234 ss << path.substr(strlen(kViewerSaveFontScalingPath)); | |
|
cjhopman
2015/07/17 20:28:04
This should probably use base::StringToDouble.
wychen
2015/07/31 21:03:37
Done.
| |
| 235 float scale; | |
| 236 ss >> scale; | |
| 237 dom_distiller_service_->GetDistilledPagePrefs()->SetFontScaling(scale); | |
| 238 callback.Run(NULL); | |
| 239 return; | |
| 229 } | 240 } |
| 230 content::WebContents* web_contents = | 241 content::WebContents* web_contents = |
| 231 content::WebContents::FromRenderFrameHost(render_frame_host); | 242 content::WebContents::FromRenderFrameHost(render_frame_host); |
| 232 DCHECK(web_contents); | 243 DCHECK(web_contents); |
| 233 // An empty |path| is invalid, but guard against it. If not empty, assume | 244 // An empty |path| is invalid, but guard against it. If not empty, assume |
| 234 // |path| starts with '?', which is stripped away. | 245 // |path| starts with '?', which is stripped away. |
| 235 const std::string path_after_query_separator = | 246 const std::string path_after_query_separator = |
| 236 path.size() > 0 ? path.substr(1) : ""; | 247 path.size() > 0 ? path.substr(1) : ""; |
| 237 RequestViewerHandle* request_viewer_handle = | 248 RequestViewerHandle* request_viewer_handle = |
| 238 new RequestViewerHandle(web_contents, scheme_, path_after_query_separator, | 249 new RequestViewerHandle(web_contents, scheme_, path_after_query_separator, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc() | 297 std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc() |
| 287 const { | 298 const { |
| 288 return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;"; | 299 return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;"; |
| 289 } | 300 } |
| 290 | 301 |
| 291 std::string DomDistillerViewerSource::GetContentSecurityPolicyFrameSrc() const { | 302 std::string DomDistillerViewerSource::GetContentSecurityPolicyFrameSrc() const { |
| 292 return "frame-src *;"; | 303 return "frame-src *;"; |
| 293 } | 304 } |
| 294 | 305 |
| 295 } // namespace dom_distiller | 306 } // namespace dom_distiller |
| OLD | NEW |