| 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 "chrome/browser/dom_distiller/profile_utils.h" | 5 #include "chrome/browser/dom_distiller/profile_utils.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" | 9 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" |
| 10 #include "chrome/browser/dom_distiller/lazy_dom_distiller_service.h" | 10 #include "chrome/browser/dom_distiller/lazy_dom_distiller_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/chrome_isolated_world_ids.h" | 12 #include "chrome/common/chrome_isolated_world_ids.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/features.h" |
| 14 #include "components/dom_distiller/content/browser/distiller_javascript_utils.h" | 15 #include "components/dom_distiller/content/browser/distiller_javascript_utils.h" |
| 15 #include "components/dom_distiller/content/browser/distiller_ui_handle.h" | 16 #include "components/dom_distiller/content/browser/distiller_ui_handle.h" |
| 16 #include "components/dom_distiller/content/browser/dom_distiller_viewer_source.h
" | 17 #include "components/dom_distiller/content/browser/dom_distiller_viewer_source.h
" |
| 17 #include "components/dom_distiller/core/dom_distiller_switches.h" | 18 #include "components/dom_distiller/core/dom_distiller_switches.h" |
| 18 #include "components/dom_distiller/core/url_constants.h" | 19 #include "components/dom_distiller/core/url_constants.h" |
| 19 | 20 |
| 20 #if defined(ENABLE_PRINT_PREVIEW) | 21 #if defined(ENABLE_PRINT_PREVIEW) |
| 21 #include "chrome/browser/ui/webui/print_preview/print_preview_distiller.h" | 22 #include "chrome/browser/ui/webui/print_preview/print_preview_distiller.h" |
| 22 #endif // defined(ENABLE_PRINT_PREVIEW) | 23 #endif // defined(ENABLE_PRINT_PREVIEW) |
| 23 | 24 |
| 24 #if defined(OS_ANDROID) | 25 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 25 #include "chrome/browser/android/dom_distiller/distiller_ui_handle_android.h" | 26 #include "chrome/browser/android/dom_distiller/distiller_ui_handle_android.h" |
| 26 #endif // defined(OS_ANDROID) | 27 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 27 | 28 |
| 28 void RegisterDomDistillerViewerSource(Profile* profile) { | 29 void RegisterDomDistillerViewerSource(Profile* profile) { |
| 29 bool enabled_distiller = base::CommandLine::ForCurrentProcess()->HasSwitch( | 30 bool enabled_distiller = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 30 switches::kEnableDomDistiller); | 31 switches::kEnableDomDistiller); |
| 31 #if defined(ENABLE_PRINT_PREVIEW) | 32 #if defined(ENABLE_PRINT_PREVIEW) |
| 32 if (PrintPreviewDistiller::IsEnabled()) | 33 if (PrintPreviewDistiller::IsEnabled()) |
| 33 enabled_distiller = true; | 34 enabled_distiller = true; |
| 34 #endif // defined(ENABLE_PRINT_PREVIEW) | 35 #endif // defined(ENABLE_PRINT_PREVIEW) |
| 35 | 36 |
| 36 if (enabled_distiller) { | 37 if (enabled_distiller) { |
| 37 dom_distiller::DomDistillerServiceFactory* dom_distiller_service_factory = | 38 dom_distiller::DomDistillerServiceFactory* dom_distiller_service_factory = |
| 38 dom_distiller::DomDistillerServiceFactory::GetInstance(); | 39 dom_distiller::DomDistillerServiceFactory::GetInstance(); |
| 39 // The LazyDomDistillerService deletes itself when the profile is destroyed. | 40 // The LazyDomDistillerService deletes itself when the profile is destroyed. |
| 40 dom_distiller::LazyDomDistillerService* lazy_service = | 41 dom_distiller::LazyDomDistillerService* lazy_service = |
| 41 new dom_distiller::LazyDomDistillerService( | 42 new dom_distiller::LazyDomDistillerService( |
| 42 profile, dom_distiller_service_factory); | 43 profile, dom_distiller_service_factory); |
| 43 scoped_ptr<dom_distiller::DistillerUIHandle> ui_handle; | 44 scoped_ptr<dom_distiller::DistillerUIHandle> ui_handle; |
| 44 | 45 |
| 45 #if defined(OS_ANDROID) | 46 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 46 ui_handle.reset( | 47 ui_handle.reset( |
| 47 new dom_distiller::android::DistillerUIHandleAndroid()); | 48 new dom_distiller::android::DistillerUIHandleAndroid()); |
| 48 #endif // defined(OS_ANDROID) | 49 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 49 | 50 |
| 50 // Set the JavaScript world ID. | 51 // Set the JavaScript world ID. |
| 51 if (!dom_distiller::DistillerJavaScriptWorldIdIsSet()) { | 52 if (!dom_distiller::DistillerJavaScriptWorldIdIsSet()) { |
| 52 dom_distiller::SetDistillerJavaScriptWorldId( | 53 dom_distiller::SetDistillerJavaScriptWorldId( |
| 53 chrome::ISOLATED_WORLD_ID_CHROME_INTERNAL); | 54 chrome::ISOLATED_WORLD_ID_CHROME_INTERNAL); |
| 54 } | 55 } |
| 55 | 56 |
| 56 content::URLDataSource::Add( | 57 content::URLDataSource::Add( |
| 57 profile, | 58 profile, |
| 58 new dom_distiller::DomDistillerViewerSource( | 59 new dom_distiller::DomDistillerViewerSource( |
| 59 lazy_service, dom_distiller::kDomDistillerScheme, | 60 lazy_service, dom_distiller::kDomDistillerScheme, |
| 60 ui_handle.Pass())); | 61 ui_handle.Pass())); |
| 61 } | 62 } |
| 62 } | 63 } |
| OLD | NEW |