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