Commit 6e3ab0a5 authored by nyquist's avatar nyquist Committed by Commit bot

Add support for using DOM Distiller in incognito.

Currently the DOM Distiller does not work in incognito, since the source
for the chrome-distiller:// scheme has not been registered.

This CL moves the functionality for registering the scheme to a generic place
and it is now used by both ProfileImpl and by OffTheRecordProfile during
profile creation.

It also makes both the normal profile and the incognito profile use the same
instance of the DomDistillerService.

BUG=380036

Review URL: https://codereview.chromium.org/608653002

Cr-Commit-Position: refs/heads/master@{#296974}
parent afdaf434
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
#include "base/threading/sequenced_worker_pool.h" #include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "components/dom_distiller/content/distiller_page_web_contents.h" #include "components/dom_distiller/content/distiller_page_web_contents.h"
#include "components/dom_distiller/core/article_entry.h" #include "components/dom_distiller/core/article_entry.h"
...@@ -92,9 +93,8 @@ KeyedService* DomDistillerServiceFactory::BuildServiceInstanceFor( ...@@ -92,9 +93,8 @@ KeyedService* DomDistillerServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* DomDistillerServiceFactory::GetBrowserContextToUse( content::BrowserContext* DomDistillerServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const { content::BrowserContext* context) const {
// TODO(cjhopman): Do we want this to be // Makes normal profile and off-the-record profile use same service instance.
// GetBrowserContextRedirectedInIncognito? return chrome::GetBrowserContextRedirectedInIncognito(context);
return context;
} }
} // namespace dom_distiller } // namespace dom_distiller
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/dom_distiller/profile_utils.h"
#include "base/command_line.h"
#include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
#include "chrome/browser/dom_distiller/lazy_dom_distiller_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
#include "components/dom_distiller/content/dom_distiller_viewer_source.h"
#include "components/dom_distiller/core/url_constants.h"
void RegisterDomDistillerViewerSource(Profile* profile) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kEnableDomDistiller)) {
dom_distiller::DomDistillerServiceFactory* dom_distiller_service_factory =
dom_distiller::DomDistillerServiceFactory::GetInstance();
// The LazyDomDistillerService deletes itself when the profile is destroyed.
dom_distiller::LazyDomDistillerService* lazy_service =
new dom_distiller::LazyDomDistillerService(
profile, dom_distiller_service_factory);
content::URLDataSource::Add(
profile,
new dom_distiller::DomDistillerViewerSource(
lazy_service, dom_distiller::kDomDistillerScheme));
}
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_DOM_DISTILLER_PROFILE_UTILS_H_
#define CHROME_BROWSER_DOM_DISTILLER_PROFILE_UTILS_H_
#include "chrome/browser/profiles/profile.h"
// Setup URLDataSource for the chrome-distiller:// scheme for the given
// |profile|.
void RegisterDomDistillerViewerSource(Profile* profile);
#endif // CHROME_BROWSER_DOM_DISTILLER_PROFILE_UTILS_H_
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "chrome/browser/background/background_contents_service_factory.h" #include "chrome/browser/background/background_contents_service_factory.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/dom_distiller/profile_utils.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h" #include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/browser/download/download_service.h" #include "chrome/browser/download/download_service.h"
#include "chrome/browser/download/download_service_factory.h" #include "chrome/browser/download/download_service_factory.h"
...@@ -160,6 +161,10 @@ void OffTheRecordProfileImpl::Init() { ...@@ -160,6 +161,10 @@ void OffTheRecordProfileImpl::Init() {
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
base::Bind(&NotifyOTRProfileCreatedOnIOThread, profile_, this)); base::Bind(&NotifyOTRProfileCreatedOnIOThread, profile_, this));
#endif #endif
// The DomDistillerViewerSource is not a normal WebUI so it must be registered
// as a URLDataSource early.
RegisterDomDistillerViewerSource(this);
} }
OffTheRecordProfileImpl::~OffTheRecordProfileImpl() { OffTheRecordProfileImpl::~OffTheRecordProfileImpl() {
......
...@@ -34,8 +34,7 @@ ...@@ -34,8 +34,7 @@
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/cookie_settings.h" #include "chrome/browser/content_settings/cookie_settings.h"
#include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" #include "chrome/browser/dom_distiller/profile_utils.h"
#include "chrome/browser/dom_distiller/lazy_dom_distiller_service.h"
#include "chrome/browser/domain_reliability/service_factory.h" #include "chrome/browser/domain_reliability/service_factory.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h" #include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/browser/download/download_service.h" #include "chrome/browser/download/download_service.h"
...@@ -85,8 +84,6 @@ ...@@ -85,8 +84,6 @@
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_statistics_prefs.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_statistics_prefs.h"
#include "components/dom_distiller/content/dom_distiller_viewer_source.h"
#include "components/dom_distiller/core/url_constants.h"
#include "components/domain_reliability/monitor.h" #include "components/domain_reliability/monitor.h"
#include "components/domain_reliability/service.h" #include "components/domain_reliability/service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
...@@ -251,24 +248,6 @@ std::string ExitTypeToSessionTypePrefValue(Profile::ExitType type) { ...@@ -251,24 +248,6 @@ std::string ExitTypeToSessionTypePrefValue(Profile::ExitType type) {
return std::string(); return std::string();
} }
// Setup URLDataSource for the chrome-distiller:// scheme for the given
// |profile|.
void RegisterDomDistillerViewerSource(Profile* profile) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kEnableDomDistiller)) {
dom_distiller::DomDistillerServiceFactory* dom_distiller_service_factory =
dom_distiller::DomDistillerServiceFactory::GetInstance();
// The LazyDomDistillerService deletes itself when the profile is destroyed.
dom_distiller::LazyDomDistillerService* lazy_service =
new dom_distiller::LazyDomDistillerService(
profile, dom_distiller_service_factory);
content::URLDataSource::Add(
profile,
new dom_distiller::DomDistillerViewerSource(
lazy_service, dom_distiller::kDomDistillerScheme));
}
}
PrefStore* CreateExtensionPrefStore(Profile* profile, PrefStore* CreateExtensionPrefStore(Profile* profile,
bool incognito_pref_store) { bool incognito_pref_store) {
#if defined(ENABLE_EXTENSIONS) #if defined(ENABLE_EXTENSIONS)
......
...@@ -331,6 +331,8 @@ ...@@ -331,6 +331,8 @@
'browser/dom_distiller/dom_distiller_service_factory_android.h', 'browser/dom_distiller/dom_distiller_service_factory_android.h',
'browser/dom_distiller/lazy_dom_distiller_service.cc', 'browser/dom_distiller/lazy_dom_distiller_service.cc',
'browser/dom_distiller/lazy_dom_distiller_service.h', 'browser/dom_distiller/lazy_dom_distiller_service.h',
'browser/dom_distiller/profile_utils.cc',
'browser/dom_distiller/profile_utils.h',
'browser/dom_distiller/tab_utils.cc', 'browser/dom_distiller/tab_utils.cc',
'browser/dom_distiller/tab_utils.h', 'browser/dom_distiller/tab_utils.h',
'browser/dom_distiller/tab_utils_android.cc', 'browser/dom_distiller/tab_utils_android.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment