| 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 "components/dom_distiller/content/browser/distiller_javascript_utils.h" | 14 #include "components/dom_distiller/content/browser/distiller_javascript_utils.h" |
| 14 #include "components/dom_distiller/content/browser/distiller_ui_handle.h" | 15 #include "components/dom_distiller/content/browser/distiller_ui_handle.h" |
| 15 #include "components/dom_distiller/content/browser/dom_distiller_viewer_source.h
" | 16 #include "components/dom_distiller/content/browser/dom_distiller_viewer_source.h
" |
| 16 #include "components/dom_distiller/core/dom_distiller_switches.h" | 17 #include "components/dom_distiller/core/dom_distiller_switches.h" |
| 17 #include "components/dom_distiller/core/url_constants.h" | 18 #include "components/dom_distiller/core/url_constants.h" |
| 18 | 19 |
| 19 #if defined(OS_ANDROID) | 20 #if defined(OS_ANDROID) |
| 20 #include "chrome/browser/android/dom_distiller/distiller_ui_handle_android.h" | 21 #include "chrome/browser/android/dom_distiller/distiller_ui_handle_android.h" |
| 21 #endif // defined(OS_ANDROID) | 22 #endif // defined(OS_ANDROID) |
| 22 | 23 |
| 23 void RegisterDomDistillerViewerSource(Profile* profile) { | 24 void RegisterDomDistillerViewerSource(Profile* profile) { |
| 24 const base::CommandLine& command_line = | 25 const base::CommandLine& command_line = |
| 25 *base::CommandLine::ForCurrentProcess(); | 26 *base::CommandLine::ForCurrentProcess(); |
| 26 if (command_line.HasSwitch(switches::kEnableDomDistiller)) { | 27 if (command_line.HasSwitch(switches::kEnableDomDistiller) || |
| 28 !command_line.HasSwitch(switches::kDisablePrintPreviewSimplify)) { |
| 27 dom_distiller::DomDistillerServiceFactory* dom_distiller_service_factory = | 29 dom_distiller::DomDistillerServiceFactory* dom_distiller_service_factory = |
| 28 dom_distiller::DomDistillerServiceFactory::GetInstance(); | 30 dom_distiller::DomDistillerServiceFactory::GetInstance(); |
| 29 // The LazyDomDistillerService deletes itself when the profile is destroyed. | 31 // The LazyDomDistillerService deletes itself when the profile is destroyed. |
| 30 dom_distiller::LazyDomDistillerService* lazy_service = | 32 dom_distiller::LazyDomDistillerService* lazy_service = |
| 31 new dom_distiller::LazyDomDistillerService( | 33 new dom_distiller::LazyDomDistillerService( |
| 32 profile, dom_distiller_service_factory); | 34 profile, dom_distiller_service_factory); |
| 33 scoped_ptr<dom_distiller::DistillerUIHandle> ui_handle; | 35 scoped_ptr<dom_distiller::DistillerUIHandle> ui_handle; |
| 34 | 36 |
| 35 #if defined(OS_ANDROID) | 37 #if defined(OS_ANDROID) |
| 36 ui_handle.reset( | 38 ui_handle.reset( |
| 37 new dom_distiller::android::DistillerUIHandleAndroid()); | 39 new dom_distiller::android::DistillerUIHandleAndroid()); |
| 38 #endif // defined(OS_ANDROID) | 40 #endif // defined(OS_ANDROID) |
| 39 | 41 |
| 40 // Set the JavaScript world ID. | 42 // Set the JavaScript world ID. |
| 41 if (!dom_distiller::DistillerJavaScriptWorldIdIsSet()) { | 43 if (!dom_distiller::DistillerJavaScriptWorldIdIsSet()) { |
| 42 dom_distiller::SetDistillerJavaScriptWorldId( | 44 dom_distiller::SetDistillerJavaScriptWorldId( |
| 43 chrome::ISOLATED_WORLD_ID_CHROME_INTERNAL); | 45 chrome::ISOLATED_WORLD_ID_CHROME_INTERNAL); |
| 44 } | 46 } |
| 45 | 47 |
| 46 content::URLDataSource::Add( | 48 content::URLDataSource::Add( |
| 47 profile, | 49 profile, |
| 48 new dom_distiller::DomDistillerViewerSource( | 50 new dom_distiller::DomDistillerViewerSource( |
| 49 lazy_service, dom_distiller::kDomDistillerScheme, | 51 lazy_service, dom_distiller::kDomDistillerScheme, |
| 50 ui_handle.Pass())); | 52 ui_handle.Pass())); |
| 51 } | 53 } |
| 52 } | 54 } |
| OLD | NEW |