diff options
author | smaslo@chromium.org <smaslo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-16 00:30:10 +0000 |
---|---|---|
committer | smaslo@chromium.org <smaslo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-16 00:30:10 +0000 |
commit | 6a5b0718e89a93ef5786bed8333d5a5056ad5478 (patch) | |
tree | d4186b28a9c577dcecfe9efc3aa0702b4057e71e /chrome/browser/dom_distiller | |
parent | cf72efdced52abcc1c389919b91c22891ca48492 (diff) | |
download | chromium_src-6a5b0718e89a93ef5786bed8333d5a5056ad5478.zip chromium_src-6a5b0718e89a93ef5786bed8333d5a5056ad5478.tar.gz chromium_src-6a5b0718e89a93ef5786bed8333d5a5056ad5478.tar.bz2 |
Theme Preferences for Distilled Pages
Adds support for allowing users to change the appearance of
distilled pages to different themes. The current themes are
light, dark and sepia.
The theme of the page is controlled by the CSS class of the
body element. When the page is loaded, this CSS class is set
by inserting the CSS class into the HTML. When a setting is
changed while a distilled page is open, the CSS class is set
by calling the JavaScript function useTheme which then updates
the body element's CSS class.
BUG=383630
Review URL: https://codereview.chromium.org/341563002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283303 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_distiller')
5 files changed, 59 insertions, 6 deletions
diff --git a/chrome/browser/dom_distiller/dom_distiller_service_factory.cc b/chrome/browser/dom_distiller/dom_distiller_service_factory.cc index 0d9d5e3..f249672 100644 --- a/chrome/browser/dom_distiller/dom_distiller_service_factory.cc +++ b/chrome/browser/dom_distiller/dom_distiller_service_factory.cc @@ -5,6 +5,7 @@ #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" #include "base/threading/sequenced_worker_pool.h" +#include "chrome/browser/profiles/profile.h" #include "components/dom_distiller/content/distiller_page_web_contents.h" #include "components/dom_distiller/core/article_entry.h" #include "components/dom_distiller/core/distiller.h" @@ -20,9 +21,13 @@ namespace dom_distiller { DomDistillerContextKeyedService::DomDistillerContextKeyedService( scoped_ptr<DomDistillerStoreInterface> store, scoped_ptr<DistillerFactory> distiller_factory, - scoped_ptr<DistillerPageFactory> distiller_page_factory) - : DomDistillerService(store.Pass(), distiller_factory.Pass(), - distiller_page_factory.Pass()) {} + scoped_ptr<DistillerPageFactory> distiller_page_factory, + scoped_ptr<DistilledPagePrefs> distilled_page_prefs) + : DomDistillerService(store.Pass(), + distiller_factory.Pass(), + distiller_page_factory.Pass(), + distilled_page_prefs.Pass()) { +} // static DomDistillerServiceFactory* DomDistillerServiceFactory::GetInstance() { @@ -72,11 +77,15 @@ KeyedService* DomDistillerServiceFactory::BuildServiceInstanceFor( } scoped_ptr<DistillerFactory> distiller_factory( new DistillerFactoryImpl(distiller_url_fetcher_factory.Pass(), options)); + scoped_ptr<DistilledPagePrefs> distilled_page_prefs( + new DistilledPagePrefs(Profile::FromBrowserContext(profile)->GetPrefs())); DomDistillerContextKeyedService* service = new DomDistillerContextKeyedService( dom_distiller_store.PassAs<DomDistillerStoreInterface>(), - distiller_factory.Pass(), distiller_page_factory.Pass()); + distiller_factory.Pass(), + distiller_page_factory.Pass(), + distilled_page_prefs.Pass()); return service; } diff --git a/chrome/browser/dom_distiller/dom_distiller_service_factory.h b/chrome/browser/dom_distiller/dom_distiller_service_factory.h index 78644b3..ee37659 100644 --- a/chrome/browser/dom_distiller/dom_distiller_service_factory.h +++ b/chrome/browser/dom_distiller/dom_distiller_service_factory.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_DOM_DISTILLER_DOM_DISTILLER_SERVICE_FACTORY_H_ #include "base/memory/singleton.h" +#include "components/dom_distiller/core/distilled_page_prefs.h" #include "components/dom_distiller/core/dom_distiller_service.h" #include "components/keyed_service/content/browser_context_keyed_service_factory.h" @@ -23,7 +24,8 @@ class DomDistillerContextKeyedService : public KeyedService, DomDistillerContextKeyedService( scoped_ptr<DomDistillerStoreInterface> store, scoped_ptr<DistillerFactory> distiller_factory, - scoped_ptr<DistillerPageFactory> distiller_page_factory); + scoped_ptr<DistillerPageFactory> distiller_page_factory, + scoped_ptr<DistilledPagePrefs> distilled_page_prefs); virtual ~DomDistillerContextKeyedService() {} private: diff --git a/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc b/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc index d36e45b..4640bc9 100644 --- a/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc +++ b/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc @@ -18,6 +18,7 @@ #include "chrome/test/base/ui_test_utils.h" #include "components/dom_distiller/content/dom_distiller_viewer_source.h" #include "components/dom_distiller/core/article_entry.h" +#include "components/dom_distiller/core/distilled_page_prefs.h" #include "components/dom_distiller/core/distiller.h" #include "components/dom_distiller/core/dom_distiller_service.h" #include "components/dom_distiller/core/dom_distiller_store.h" @@ -57,6 +58,10 @@ const char kGetContent[] = "window.domAutomationController.send(" "document.getElementById('content').innerHTML)"; +const char kGetBodyClass[] = + "window.domAutomationController.send(" + "document.body.className)"; + void AddEntry(const ArticleEntry& e, FakeDB<ArticleEntry>::EntryMap* map) { (*map)[e.entry_id()] = e; } @@ -99,7 +104,11 @@ class DomDistillerViewerSourceBrowserTest : public InProcessBrowserTest { CreateStoreWithFakeDB(fake_db, FakeDB<ArticleEntry>::EntryMap())), scoped_ptr<DistillerFactory>(distiller_factory_), - scoped_ptr<DistillerPageFactory>(distiller_page_factory_)); + scoped_ptr<DistillerPageFactory>(distiller_page_factory_), + scoped_ptr<DistilledPagePrefs>( + new DistilledPagePrefs( + Profile::FromBrowserContext( + context)->GetPrefs()))); fake_db->InitCallback(true); fake_db->LoadCallback(true); if (expect_distillation_) { @@ -321,4 +330,31 @@ IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, EXPECT_THAT(result, HasSubstr("Page 2 content")); } +IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, PrefChange) { + expect_distillation_ = true; + expect_distiller_page_ = true; + GURL view_url("http://www.example.com/1"); + content::WebContents* contents = + browser()->tab_strip_model()->GetActiveWebContents(); + const GURL url = url_utils::GetDistillerViewUrlFromUrl( + chrome::kDomDistillerScheme, view_url); + ViewSingleDistilledPage(url, "text/html"); + content::WaitForLoadStop(contents); + std::string result; + EXPECT_TRUE(content::ExecuteScriptAndExtractString( + contents, kGetBodyClass, &result)); + EXPECT_EQ("light", result); + + // Getting DistilledPagePrefs instance. + DistilledPagePrefs* distilled_page_prefs = + DomDistillerServiceFactory::GetForBrowserContext( + browser()->profile())->GetDistilledPagePrefs(); + + distilled_page_prefs->SetTheme(DistilledPagePrefs::DARK); + base::RunLoop().RunUntilIdle(); + EXPECT_TRUE(content::ExecuteScriptAndExtractString( + contents, kGetBodyClass, &result)); + EXPECT_EQ("dark", result); +} + } // namespace dom_distiller diff --git a/chrome/browser/dom_distiller/lazy_dom_distiller_service.cc b/chrome/browser/dom_distiller/lazy_dom_distiller_service.cc index 3e7e745..22c3c66 100644 --- a/chrome/browser/dom_distiller/lazy_dom_distiller_service.cc +++ b/chrome/browser/dom_distiller/lazy_dom_distiller_service.cc @@ -7,6 +7,7 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" #include "chrome/browser/profiles/profile.h" +#include "components/dom_distiller/core/distilled_page_prefs.h" #include "components/dom_distiller/core/distiller_page.h" #include "components/dom_distiller/core/dom_distiller_service.h" #include "content/public/browser/notification_source.h" @@ -93,4 +94,8 @@ void LazyDomDistillerService::RemoveObserver(DomDistillerObserver* observer) { instance()->RemoveObserver(observer); } +DistilledPagePrefs* LazyDomDistillerService::GetDistilledPagePrefs() { + return instance()->GetDistilledPagePrefs(); +} + } // namespace dom_distiller diff --git a/chrome/browser/dom_distiller/lazy_dom_distiller_service.h b/chrome/browser/dom_distiller/lazy_dom_distiller_service.h index d3ed5f4..d63e9f4 100644 --- a/chrome/browser/dom_distiller/lazy_dom_distiller_service.h +++ b/chrome/browser/dom_distiller/lazy_dom_distiller_service.h @@ -54,6 +54,7 @@ class LazyDomDistillerService : public DomDistillerServiceInterface, scoped_ptr<SourcePageHandle> handle) OVERRIDE; virtual void AddObserver(DomDistillerObserver* observer) OVERRIDE; virtual void RemoveObserver(DomDistillerObserver* observer) OVERRIDE; + virtual DistilledPagePrefs* GetDistilledPagePrefs() OVERRIDE; private: // Accessor method for the backing service instance. |