Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: components/dom_distiller/content/browser/dom_distiller_viewer_source.cc

Issue 1225183002: Font size in DomDistiller prefs syncs with local scaling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge master again Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 104
104 DomDistillerViewerSource::RequestViewerHandle::~RequestViewerHandle() { 105 DomDistillerViewerSource::RequestViewerHandle::~RequestViewerHandle() {
105 distilled_page_prefs_->RemoveObserver(this); 106 distilled_page_prefs_->RemoveObserver(this);
106 } 107 }
107 108
108 void DomDistillerViewerSource::RequestViewerHandle::SendJavaScript( 109 void DomDistillerViewerSource::RequestViewerHandle::SendJavaScript(
109 const std::string& buffer) { 110 const std::string& buffer) {
110 if (waiting_for_page_ready_) { 111 if (waiting_for_page_ready_) {
111 buffer_ += buffer; 112 buffer_ += buffer;
112 } else { 113 } else {
114 DCHECK(buffer_.empty());
113 if (web_contents()) { 115 if (web_contents()) {
114 RunIsolatedJavaScript(web_contents()->GetMainFrame(), buffer); 116 RunIsolatedJavaScript(web_contents()->GetMainFrame(), buffer);
115 } 117 }
116 } 118 }
117 } 119 }
118 120
119 void DomDistillerViewerSource::RequestViewerHandle::DidNavigateMainFrame( 121 void DomDistillerViewerSource::RequestViewerHandle::DidNavigateMainFrame(
120 const content::LoadCommittedDetails& details, 122 const content::LoadCommittedDetails& details,
121 const content::FrameNavigateParams& params) { 123 const content::FrameNavigateParams& params) {
122 const GURL& navigation = details.entry->GetURL(); 124 const GURL& navigation = details.entry->GetURL();
(...skipping 23 matching lines...) Expand all
146 // any pending data stored in |buffer_| is released. 148 // any pending data stored in |buffer_| is released.
147 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 149 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
148 } 150 }
149 151
150 void DomDistillerViewerSource::RequestViewerHandle::DidFinishLoad( 152 void DomDistillerViewerSource::RequestViewerHandle::DidFinishLoad(
151 content::RenderFrameHost* render_frame_host, 153 content::RenderFrameHost* render_frame_host,
152 const GURL& validated_url) { 154 const GURL& validated_url) {
153 if (render_frame_host->GetParent()) { 155 if (render_frame_host->GetParent()) {
154 return; 156 return;
155 } 157 }
158
159 // No SendJavaScript() calls allowed before |buffer_| is run and cleared.
156 waiting_for_page_ready_ = false; 160 waiting_for_page_ready_ = false;
157 if (!buffer_.empty()) { 161 if (!buffer_.empty()) {
158 RunIsolatedJavaScript(web_contents()->GetMainFrame(), buffer_); 162 RunIsolatedJavaScript(web_contents()->GetMainFrame(), buffer_);
159 buffer_.clear(); 163 buffer_.clear();
160 } 164 }
161 if (IsErrorPage()) { 165 // No need to Cancel() here.
162 Cancel(); // This will cause the object to clean itself up.
163 }
164 } 166 }
165 167
166 DomDistillerViewerSource::DomDistillerViewerSource( 168 DomDistillerViewerSource::DomDistillerViewerSource(
167 DomDistillerServiceInterface* dom_distiller_service, 169 DomDistillerServiceInterface* dom_distiller_service,
168 const std::string& scheme, 170 const std::string& scheme,
169 scoped_ptr<ExternalFeedbackReporter> external_reporter) 171 scoped_ptr<ExternalFeedbackReporter> external_reporter)
170 : scheme_(scheme), 172 : scheme_(scheme),
171 dom_distiller_service_(dom_distiller_service), 173 dom_distiller_service_(dom_distiller_service),
172 external_feedback_reporter_(external_reporter.Pass()) { 174 external_feedback_reporter_(external_reporter.Pass()) {
173 } 175 }
(...skipping 16 matching lines...) Expand all
190 return; 192 return;
191 content::RenderViewHost* render_view_host = 193 content::RenderViewHost* render_view_host =
192 render_frame_host->GetRenderViewHost(); 194 render_frame_host->GetRenderViewHost();
193 DCHECK(render_view_host); 195 DCHECK(render_view_host);
194 CHECK_EQ(0, render_view_host->GetEnabledBindings()); 196 CHECK_EQ(0, render_view_host->GetEnabledBindings());
195 197
196 if (kViewerCssPath == path) { 198 if (kViewerCssPath == path) {
197 std::string css = viewer::GetCss(); 199 std::string css = viewer::GetCss();
198 callback.Run(base::RefCountedString::TakeString(&css)); 200 callback.Run(base::RefCountedString::TakeString(&css));
199 return; 201 return;
202 } else if (base::StartsWith(path, kViewerSaveFontScalingPath,
203 base::CompareCase::SENSITIVE)) {
204 double scale = 1.0;
205 if (base::StringToDouble(
206 path.substr(strlen(kViewerSaveFontScalingPath)), &scale)) {
207 dom_distiller_service_->GetDistilledPagePrefs()->SetFontScaling(scale);
208 }
200 } 209 }
201 content::WebContents* web_contents = 210 content::WebContents* web_contents =
202 content::WebContents::FromRenderFrameHost(render_frame_host); 211 content::WebContents::FromRenderFrameHost(render_frame_host);
203 DCHECK(web_contents); 212 DCHECK(web_contents);
204 // An empty |path| is invalid, but guard against it. If not empty, assume 213 // An empty |path| is invalid, but guard against it. If not empty, assume
205 // |path| starts with '?', which is stripped away. 214 // |path| starts with '?', which is stripped away.
206 const std::string path_after_query_separator = 215 const std::string path_after_query_separator =
207 path.size() > 0 ? path.substr(1) : ""; 216 path.size() > 0 ? path.substr(1) : "";
208 RequestViewerHandle* request_viewer_handle = 217 RequestViewerHandle* request_viewer_handle =
209 new RequestViewerHandle(web_contents, scheme_, path_after_query_separator, 218 new RequestViewerHandle(web_contents, scheme_, path_after_query_separator,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc() 277 std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc()
269 const { 278 const {
270 return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;"; 279 return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;";
271 } 280 }
272 281
273 std::string DomDistillerViewerSource::GetContentSecurityPolicyFrameSrc() const { 282 std::string DomDistillerViewerSource::GetContentSecurityPolicyFrameSrc() const {
274 return "frame-src *;"; 283 return "frame-src *;";
275 } 284 }
276 285
277 } // namespace dom_distiller 286 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698