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 <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "components/dom_distiller/core/task_tracker.h" | 29 #include "components/dom_distiller/core/task_tracker.h" |
30 #include "components/dom_distiller/core/url_constants.h" | 30 #include "components/dom_distiller/core/url_constants.h" |
31 #include "components/dom_distiller/core/url_utils.h" | 31 #include "components/dom_distiller/core/url_utils.h" |
32 #include "components/dom_distiller/core/viewer.h" | 32 #include "components/dom_distiller/core/viewer.h" |
33 #include "content/public/browser/navigation_details.h" | 33 #include "content/public/browser/navigation_details.h" |
34 #include "content/public/browser/navigation_entry.h" | 34 #include "content/public/browser/navigation_entry.h" |
35 #include "content/public/browser/render_frame_host.h" | 35 #include "content/public/browser/render_frame_host.h" |
36 #include "content/public/browser/render_view_host.h" | 36 #include "content/public/browser/render_view_host.h" |
37 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
38 #include "content/public/browser/web_contents_observer.h" | 38 #include "content/public/browser/web_contents_observer.h" |
39 #include "content/public/common/service_registry.h" | |
40 #include "grit/components_strings.h" | 39 #include "grit/components_strings.h" |
41 #include "mojo/public/cpp/bindings/strong_binding.h" | 40 #include "mojo/public/cpp/bindings/strong_binding.h" |
42 #include "net/base/url_util.h" | 41 #include "net/base/url_util.h" |
43 #include "net/url_request/url_request.h" | 42 #include "net/url_request/url_request.h" |
| 43 #include "services/shell/public/cpp/interface_provider.h" |
| 44 #include "services/shell/public/cpp/interface_registry.h" |
44 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
45 | 46 |
46 namespace dom_distiller { | 47 namespace dom_distiller { |
47 | 48 |
48 // Handles receiving data asynchronously for a specific entry, and passing | 49 // Handles receiving data asynchronously for a specific entry, and passing |
49 // it along to the data callback for the data source. Lifetime matches that of | 50 // it along to the data callback for the data source. Lifetime matches that of |
50 // the current main frame's page in the Viewer instance. | 51 // the current main frame's page in the Viewer instance. |
51 class DomDistillerViewerSource::RequestViewerHandle | 52 class DomDistillerViewerSource::RequestViewerHandle |
52 : public DomDistillerRequestViewBase, | 53 : public DomDistillerRequestViewBase, |
53 public content::WebContentsObserver { | 54 public content::WebContentsObserver { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 web_contents->GetContainerBounds().size()); | 238 web_contents->GetContainerBounds().size()); |
238 | 239 |
239 GURL current_url(url_utils::GetValueForKeyInUrlPathQuery(path, kUrlKey)); | 240 GURL current_url(url_utils::GetValueForKeyInUrlPathQuery(path, kUrlKey)); |
240 std::string unsafe_page_html = viewer::GetUnsafeArticleTemplateHtml( | 241 std::string unsafe_page_html = viewer::GetUnsafeArticleTemplateHtml( |
241 url_utils::GetOriginalUrlFromDistillerUrl(current_url).spec(), | 242 url_utils::GetOriginalUrlFromDistillerUrl(current_url).spec(), |
242 dom_distiller_service_->GetDistilledPagePrefs()->GetTheme(), | 243 dom_distiller_service_->GetDistilledPagePrefs()->GetTheme(), |
243 dom_distiller_service_->GetDistilledPagePrefs()->GetFontFamily()); | 244 dom_distiller_service_->GetDistilledPagePrefs()->GetFontFamily()); |
244 | 245 |
245 // Add mojo service for JavaScript functionality. This is the receiving end | 246 // Add mojo service for JavaScript functionality. This is the receiving end |
246 // of this particular service. | 247 // of this particular service. |
247 render_frame_host->GetServiceRegistry()->AddService( | 248 render_frame_host->GetInterfaceRegistry()->AddInterface( |
248 base::Bind(&CreateDistillerJavaScriptService, | 249 base::Bind(&CreateDistillerJavaScriptService, |
249 render_frame_host, | 250 render_frame_host, |
250 distiller_ui_handle_.get())); | 251 distiller_ui_handle_.get())); |
251 | 252 |
252 // Tell the renderer that this is currently a distilled page. | 253 // Tell the renderer that this is currently a distilled page. |
253 mojom::DistillerPageNotifierServicePtr page_notifier_service; | 254 mojom::DistillerPageNotifierServicePtr page_notifier_service; |
254 render_frame_host->GetServiceRegistry()->ConnectToRemoteService( | 255 render_frame_host->GetRemoteInterfaces()->GetInterface( |
255 mojo::GetProxy(&page_notifier_service)); | 256 &page_notifier_service); |
256 DCHECK(page_notifier_service); | 257 DCHECK(page_notifier_service); |
257 page_notifier_service->NotifyIsDistillerPage(); | 258 page_notifier_service->NotifyIsDistillerPage(); |
258 | 259 |
259 if (viewer_handle) { | 260 if (viewer_handle) { |
260 // The service returned a |ViewerHandle| and guarantees it will call | 261 // The service returned a |ViewerHandle| and guarantees it will call |
261 // the |RequestViewerHandle|, so passing ownership to it, to ensure the | 262 // the |RequestViewerHandle|, so passing ownership to it, to ensure the |
262 // request is not cancelled. The |RequestViewerHandle| will delete itself | 263 // request is not cancelled. The |RequestViewerHandle| will delete itself |
263 // after receiving the callback. | 264 // after receiving the callback. |
264 request_viewer_handle->TakeViewerHandle(std::move(viewer_handle)); | 265 request_viewer_handle->TakeViewerHandle(std::move(viewer_handle)); |
265 } else { | 266 } else { |
(...skipping 28 matching lines...) Expand all Loading... |
294 std::string DomDistillerViewerSource::GetContentSecurityPolicyStyleSrc() | 295 std::string DomDistillerViewerSource::GetContentSecurityPolicyStyleSrc() |
295 const { | 296 const { |
296 return "style-src 'self' https://fonts.googleapis.com;"; | 297 return "style-src 'self' https://fonts.googleapis.com;"; |
297 } | 298 } |
298 | 299 |
299 std::string DomDistillerViewerSource::GetContentSecurityPolicyChildSrc() const { | 300 std::string DomDistillerViewerSource::GetContentSecurityPolicyChildSrc() const { |
300 return "child-src *;"; | 301 return "child-src *;"; |
301 } | 302 } |
302 | 303 |
303 } // namespace dom_distiller | 304 } // namespace dom_distiller |
OLD | NEW |