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 |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 return scheme_ + "://"; | 261 return scheme_ + "://"; |
262 } | 262 } |
263 | 263 |
264 void DomDistillerViewerSource::StartDataRequest( | 264 void DomDistillerViewerSource::StartDataRequest( |
265 const std::string& path, | 265 const std::string& path, |
266 int render_process_id, | 266 int render_process_id, |
267 int render_frame_id, | 267 int render_frame_id, |
268 const content::URLDataSource::GotDataCallback& callback) { | 268 const content::URLDataSource::GotDataCallback& callback) { |
269 content::RenderFrameHost* render_frame_host = | 269 content::RenderFrameHost* render_frame_host = |
270 content::RenderFrameHost::FromID(render_process_id, render_frame_id); | 270 content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
271 DCHECK(render_frame_host); | 271 if (!render_frame_host) return; |
272 content::RenderViewHost* render_view_host = | 272 content::RenderViewHost* render_view_host = |
273 render_frame_host->GetRenderViewHost(); | 273 render_frame_host->GetRenderViewHost(); |
274 DCHECK(render_view_host); | 274 DCHECK(render_view_host); |
275 CHECK_EQ(0, render_view_host->GetEnabledBindings()); | 275 CHECK_EQ(0, render_view_host->GetEnabledBindings()); |
276 | 276 |
277 if (kViewerCssPath == path) { | 277 if (kViewerCssPath == path) { |
278 std::string css = viewer::GetCss(); | 278 std::string css = viewer::GetCss(); |
279 callback.Run(base::RefCountedString::TakeString(&css)); | 279 callback.Run(base::RefCountedString::TakeString(&css)); |
280 return; | 280 return; |
281 } | 281 } |
282 if (kViewerJsPath == path) { | 282 if (kViewerJsPath == path) { |
283 std::string js = viewer::GetJavaScript(); | 283 std::string js = viewer::GetJavaScript(); |
284 callback.Run(base::RefCountedString::TakeString(&js)); | 284 callback.Run(base::RefCountedString::TakeString(&js)); |
285 return; | 285 return; |
286 } | 286 } |
287 if (kViewerViewOriginalPath == path) { | 287 if (kViewerViewOriginalPath == path) { |
288 content::RecordAction(base::UserMetricsAction("DomDistiller_ViewOriginal")); | 288 content::RecordAction(base::UserMetricsAction("DomDistiller_ViewOriginal")); |
289 callback.Run(NULL); | 289 callback.Run(NULL); |
290 return; | 290 return; |
291 } | 291 } |
292 content::WebContents* web_contents = | 292 content::WebContents* web_contents = |
293 content::WebContents::FromRenderFrameHost( | 293 content::WebContents::FromRenderFrameHost(render_frame_host); |
294 content::RenderFrameHost::FromID(render_process_id, | |
295 render_frame_id)); | |
296 DCHECK(web_contents); | 294 DCHECK(web_contents); |
297 // An empty |path| is invalid, but guard against it. If not empty, assume | 295 // An empty |path| is invalid, but guard against it. If not empty, assume |
298 // |path| starts with '?', which is stripped away. | 296 // |path| starts with '?', which is stripped away. |
299 const std::string path_after_query_separator = | 297 const std::string path_after_query_separator = |
300 path.size() > 0 ? path.substr(1) : ""; | 298 path.size() > 0 ? path.substr(1) : ""; |
301 RequestViewerHandle* request_viewer_handle = new RequestViewerHandle( | 299 RequestViewerHandle* request_viewer_handle = new RequestViewerHandle( |
302 web_contents, scheme_, path_after_query_separator, callback, | 300 web_contents, scheme_, path_after_query_separator, callback, |
303 dom_distiller_service_->GetDistilledPagePrefs()); | 301 dom_distiller_service_->GetDistilledPagePrefs()); |
304 scoped_ptr<ViewerHandle> viewer_handle = viewer::CreateViewRequest( | 302 scoped_ptr<ViewerHandle> viewer_handle = viewer::CreateViewRequest( |
305 dom_distiller_service_, path, request_viewer_handle, | 303 dom_distiller_service_, path, request_viewer_handle, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 const net::URLRequest* request, | 342 const net::URLRequest* request, |
345 std::string* path) const { | 343 std::string* path) const { |
346 } | 344 } |
347 | 345 |
348 std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc() | 346 std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc() |
349 const { | 347 const { |
350 return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;"; | 348 return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;"; |
351 } | 349 } |
352 | 350 |
353 } // namespace dom_distiller | 351 } // namespace dom_distiller |
OLD | NEW |