Commit 64e205c3 authored by Kyle Milka's avatar Kyle Milka Committed by Commit Bot

Set NTP custom background

When the user selects a background image actually update the
page background. The choice of background is stored in Preferences.
A new preference is added for this purpose: kNTPCustomBackgroundURL.
This is exposed to the NTP javascript through ThemeBackgroundInfo.
Add a NewTabPageBinding to update these preferences when an
image is selected by propagating the change to the InstantService
where the browser profile is available. The InstantService then
notifies all New Tab Pages of the change.

Bug: 839152
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ib6f74f1f3e9dda6a3352833662db373ec1358769
Reviewed-on: https://chromium-review.googlesource.com/1081651
Commit-Queue: Kyle Milka <kmilka@chromium.org>
Reviewed-by: default avatarEmily Stark <estark@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565320}
parent 3c0a8288
...@@ -287,6 +287,10 @@ ...@@ -287,6 +287,10 @@
#include "chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_util.h" #include "chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_util.h"
#endif #endif
#if !defined(OS_ANDROID)
#include "chrome/browser/search/instant_service.h"
#endif
#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
#include "chrome/browser/ui/startup/default_browser_prompt.h" #include "chrome/browser/ui/startup/default_browser_prompt.h"
#endif #endif
...@@ -610,6 +614,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { ...@@ -610,6 +614,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
browser_sync::ForeignSessionHandler::RegisterProfilePrefs(registry); browser_sync::ForeignSessionHandler::RegisterProfilePrefs(registry);
first_run::RegisterProfilePrefs(registry); first_run::RegisterProfilePrefs(registry);
InstantService::RegisterProfilePrefs(registry);
gcm::GCMChannelStatusSyncer::RegisterProfilePrefs(registry); gcm::GCMChannelStatusSyncer::RegisterProfilePrefs(registry);
gcm::RegisterProfilePrefs(registry); gcm::RegisterProfilePrefs(registry);
StartupBrowserCreator::RegisterProfilePrefs(registry); StartupBrowserCreator::RegisterProfilePrefs(registry);
......
...@@ -161,6 +161,7 @@ customBackgrounds.showCollectionSelectionDialog = function() { ...@@ -161,6 +161,7 @@ customBackgrounds.showCollectionSelectionDialog = function() {
customBackgrounds.showImageSelectionDialog = function(dialogTitle) { customBackgrounds.showImageSelectionDialog = function(dialogTitle) {
var backButton = $(customBackgrounds.IDS.BACK); var backButton = $(customBackgrounds.IDS.BACK);
var dailyRefresh = $(customBackgrounds.IDS.REFRESH_TOGGLE); var dailyRefresh = $(customBackgrounds.IDS.REFRESH_TOGGLE);
var doneButton = $(customBackgrounds.IDS.DONE);
var overlay = $(customBackgrounds.IDS.OVERLAY); var overlay = $(customBackgrounds.IDS.OVERLAY);
var selectedTile = null; var selectedTile = null;
var tileContainer = $(customBackgrounds.IDS.TILES); var tileContainer = $(customBackgrounds.IDS.TILES);
...@@ -176,6 +177,7 @@ customBackgrounds.showImageSelectionDialog = function(dialogTitle) { ...@@ -176,6 +177,7 @@ customBackgrounds.showImageSelectionDialog = function(dialogTitle) {
tile.classList.add(customBackgrounds.CLASSES.COLLECTION_TILE); tile.classList.add(customBackgrounds.CLASSES.COLLECTION_TILE);
tile.style.backgroundImage = 'url(' + coll_img[i].imageUrl + ')'; tile.style.backgroundImage = 'url(' + coll_img[i].imageUrl + ')';
tile.id = 'img_tile_' + i; tile.id = 'img_tile_' + i;
tile.dataset.url = coll_img[i].imageUrl;
tile.onclick = function(event) { tile.onclick = function(event) {
var tile = event.target; var tile = event.target;
...@@ -199,11 +201,22 @@ customBackgrounds.showImageSelectionDialog = function(dialogTitle) { ...@@ -199,11 +201,22 @@ customBackgrounds.showImageSelectionDialog = function(dialogTitle) {
if (selectedTile) { if (selectedTile) {
selectedTile.classList.remove( selectedTile.classList.remove(
customBackgrounds.CLASSES.COLLECTION_SELECTED); customBackgrounds.CLASSES.COLLECTION_SELECTED);
selectedTile = null;
} }
$(customBackgrounds.IDS.DONE) $(customBackgrounds.IDS.DONE)
.classList.add(customBackgrounds.CLASSES.DONE_AVAILABLE); .classList.add(customBackgrounds.CLASSES.DONE_AVAILABLE);
}; };
doneButton.onclick = function(event) {
if (!selectedTile)
return;
overlay.classList.remove(customBackgrounds.CLASSES.SHOW_OVERLAY);
window.chrome.embeddedSearch.newTabPage.setBackgroundURL(
selectedTile.dataset.url);
customBackgrounds.resetSelectionDialog();
};
backButton.onclick = function(event) { backButton.onclick = function(event) {
customBackgrounds.resetSelectionDialog(); customBackgrounds.resetSelectionDialog();
customBackgrounds.showCollectionSelectionDialog(); customBackgrounds.showCollectionSelectionDialog();
...@@ -213,7 +226,7 @@ customBackgrounds.showImageSelectionDialog = function(dialogTitle) { ...@@ -213,7 +226,7 @@ customBackgrounds.showImageSelectionDialog = function(dialogTitle) {
/** /**
* Display dialog with various options for custom background source. * Display dialog with various options for custom background source.
*/ */
customBackgrounds.initBackgroundOptionDialog = function() { customBackgrounds.initCustomBackgrounds = function() {
var editDialogOverlay = $(customBackgrounds.IDS.EDIT_BG_OVERLAY); var editDialogOverlay = $(customBackgrounds.IDS.EDIT_BG_OVERLAY);
$(customBackgrounds.IDS.CONNECT_GOOGLE_PHOTOS_TEXT).textContent = $(customBackgrounds.IDS.CONNECT_GOOGLE_PHOTOS_TEXT).textContent =
...@@ -233,7 +246,6 @@ customBackgrounds.initBackgroundOptionDialog = function() { ...@@ -233,7 +246,6 @@ customBackgrounds.initBackgroundOptionDialog = function() {
$(customBackgrounds.IDS.CONNECT_GOOGLE_PHOTOS).hidden = true; $(customBackgrounds.IDS.CONNECT_GOOGLE_PHOTOS).hidden = true;
$(customBackgrounds.IDS.DEFAULT_WALLPAPERS).hidden = false; $(customBackgrounds.IDS.DEFAULT_WALLPAPERS).hidden = false;
$(customBackgrounds.IDS.UPLOAD_IMAGE).hidden = true; $(customBackgrounds.IDS.UPLOAD_IMAGE).hidden = true;
$(customBackgrounds.IDS.RESTORE_DEFAULT).hidden = true;
$(customBackgrounds.IDS.DEFAULT_WALLPAPERS).onclick = function() { $(customBackgrounds.IDS.DEFAULT_WALLPAPERS).onclick = function() {
$(customBackgrounds.IDS.EDIT_BG_OVERLAY) $(customBackgrounds.IDS.EDIT_BG_OVERLAY)
...@@ -244,6 +256,12 @@ customBackgrounds.initBackgroundOptionDialog = function() { ...@@ -244,6 +256,12 @@ customBackgrounds.initBackgroundOptionDialog = function() {
} }
}; };
$(customBackgrounds.IDS.RESTORE_DEFAULT).onclick = function() {
$(customBackgrounds.IDS.EDIT_BG_OVERLAY)
.classList.remove(customBackgrounds.CLASSES.SHOW_OVERLAY);
window.chrome.embeddedSearch.newTabPage.setBackgroundURL('');
};
editDialogOverlay.classList.add(customBackgrounds.CLASSES.SHOW_OVERLAY); editDialogOverlay.classList.add(customBackgrounds.CLASSES.SHOW_OVERLAY);
}; };
......
...@@ -301,6 +301,9 @@ function renderTheme() { ...@@ -301,6 +301,9 @@ function renderTheme() {
updateThemeAttribution(info.attributionUrl, info.imageHorizontalAlignment); updateThemeAttribution(info.attributionUrl, info.imageHorizontalAlignment);
setCustomThemeStyle(info); setCustomThemeStyle(info);
$(customBackgrounds.IDS.RESTORE_DEFAULT).hidden =
!(info.imageUrl && info.imageUrl.length > 0);
if (configData.isGooglePage) { if (configData.isGooglePage) {
$('edit-bg').hidden = $('edit-bg').hidden =
!configData.isCustomBackgroundsEnabled || !info.usingDefaultTheme; !configData.isCustomBackgroundsEnabled || !info.usingDefaultTheme;
...@@ -318,7 +321,7 @@ function renderTheme() { ...@@ -318,7 +321,7 @@ function renderTheme() {
document.body.appendChild(collScript); document.body.appendChild(collScript);
}; };
if (configData.isCustomBackgroundsEnabled && info.usingDefaultTheme) if (configData.isCustomBackgroundsEnabled && info.usingDefaultTheme)
customBackgrounds.initBackgroundOptionDialog(); customBackgrounds.initCustomBackgrounds();
} }
} }
......
...@@ -13,14 +13,21 @@ ...@@ -13,14 +13,21 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/instant_io_context.h" #include "chrome/browser/search/instant_io_context.h"
#include "chrome/browser/search/instant_service_observer.h" #include "chrome/browser/search/instant_service_observer.h"
#include "chrome/browser/search/local_ntp_source.h"
#include "chrome/browser/search/most_visited_iframe_source.h" #include "chrome/browser/search/most_visited_iframe_source.h"
#include "chrome/browser/search/search.h" #include "chrome/browser/search/search.h"
#include "chrome/browser/search/thumbnail_source.h" #include "chrome/browser/search/thumbnail_source.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/thumbnails/thumbnail_list_source.h" #include "chrome/browser/thumbnails/thumbnail_list_source.h"
#include "chrome/browser/ui/webui/favicon_source.h" #include "chrome/browser/ui/webui/favicon_source.h"
#include "chrome/browser/ui/webui/theme_source.h" #include "chrome/browser/ui/webui/theme_source.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/search.mojom.h" #include "chrome/common/search.mojom.h"
#include "chrome/grit/theme_resources.h" #include "chrome/grit/theme_resources.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/search/search.h" #include "components/search/search.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
...@@ -28,10 +35,6 @@ ...@@ -28,10 +35,6 @@
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/url_data_source.h" #include "content/public/browser/url_data_source.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
#include "chrome/browser/search/local_ntp_source.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
InstantService::InstantService(Profile* profile) : profile_(profile) { InstantService::InstantService(Profile* profile) : profile_(profile) {
// The initialization below depends on a typical set of browser threads. Skip // The initialization below depends on a typical set of browser threads. Skip
...@@ -125,9 +128,9 @@ void InstantService::UndoAllMostVisitedDeletions() { ...@@ -125,9 +128,9 @@ void InstantService::UndoAllMostVisitedDeletions() {
} }
} }
void InstantService::UpdateThemeInfo() { void InstantService::UpdateThemeInfo(bool force_update) {
// Initialize |theme_info_| if necessary. // Initialize |theme_info_| if necessary.
if (!theme_info_) { if (!theme_info_ || force_update) {
BuildThemeInfo(); BuildThemeInfo();
} }
NotifyAboutThemeInfo(); NotifyAboutThemeInfo();
...@@ -146,6 +149,17 @@ void InstantService::SendNewTabPageURLToRenderer( ...@@ -146,6 +149,17 @@ void InstantService::SendNewTabPageURLToRenderer(
} }
} }
void InstantService::SetCustomBackgroundURL(const GURL& url) {
PrefService* pref_service_ = profile_->GetPrefs();
if (url.is_empty()) {
pref_service_->ClearPref(prefs::kNTPCustomBackgroundURL);
} else {
pref_service_->SetString(prefs::kNTPCustomBackgroundURL, url.spec());
}
UpdateThemeInfo(true);
}
void InstantService::Shutdown() { void InstantService::Shutdown() {
process_ids_.clear(); process_ids_.clear();
...@@ -337,4 +351,15 @@ void InstantService::BuildThemeInfo() { ...@@ -337,4 +351,15 @@ void InstantService::BuildThemeInfo() {
theme_info_->has_attribution = theme_info_->has_attribution =
theme_provider.HasCustomImage(IDR_THEME_NTP_ATTRIBUTION); theme_provider.HasCustomImage(IDR_THEME_NTP_ATTRIBUTION);
} }
// User has set a custom background image.
GURL custom_background_url(
profile_->GetPrefs()->GetString(prefs::kNTPCustomBackgroundURL));
if (custom_background_url.is_valid()) {
theme_info_->custom_background_url = custom_background_url;
}
}
void InstantService::RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterStringPref(prefs::kNTPCustomBackgroundURL, std::string());
} }
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "components/ntp_tiles/most_visited_sites.h" #include "components/ntp_tiles/most_visited_sites.h"
#include "components/ntp_tiles/ntp_tile.h" #include "components/ntp_tiles/ntp_tile.h"
#include "components/prefs/pref_registry_simple.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -58,6 +59,9 @@ class InstantService : public KeyedService, ...@@ -58,6 +59,9 @@ class InstantService : public KeyedService,
void AddObserver(InstantServiceObserver* observer); void AddObserver(InstantServiceObserver* observer);
void RemoveObserver(InstantServiceObserver* observer); void RemoveObserver(InstantServiceObserver* observer);
// Register prefs associated with the NTP.
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
#if defined(UNIT_TEST) #if defined(UNIT_TEST)
int GetInstantProcessCount() const { int GetInstantProcessCount() const {
return process_ids_.size(); return process_ids_.size();
...@@ -81,7 +85,7 @@ class InstantService : public KeyedService, ...@@ -81,7 +85,7 @@ class InstantService : public KeyedService,
// //
// TODO(kmadhusu): Invoking this from InstantController shouldn't be // TODO(kmadhusu): Invoking this from InstantController shouldn't be
// necessary. Investigate more and remove this from here. // necessary. Investigate more and remove this from here.
void UpdateThemeInfo(); void UpdateThemeInfo(bool force_update);
// Invoked by the InstantController to update most visited items details for // Invoked by the InstantController to update most visited items details for
// NTP. // NTP.
...@@ -90,6 +94,9 @@ class InstantService : public KeyedService, ...@@ -90,6 +94,9 @@ class InstantService : public KeyedService,
// Sends the current NTP URL to a renderer process. // Sends the current NTP URL to a renderer process.
void SendNewTabPageURLToRenderer(content::RenderProcessHost* rph); void SendNewTabPageURLToRenderer(content::RenderProcessHost* rph);
// Invoked when a custom background is selected on the NTP.
void SetCustomBackgroundURL(const GURL& url);
private: private:
friend class InstantExtendedTest; friend class InstantExtendedTest;
friend class InstantUnitTestBase; friend class InstantUnitTestBase;
......
...@@ -37,9 +37,12 @@ ...@@ -37,9 +37,12 @@
#include "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/grit/browser_resources.h" #include "chrome/grit/browser_resources.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/search_terms_data.h" #include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/search_engines/template_url_service_observer.h" #include "components/search_engines/template_url_service_observer.h"
...@@ -206,8 +209,10 @@ std::string GetConfigData(bool is_google, const GURL& google_base_url) { ...@@ -206,8 +209,10 @@ std::string GetConfigData(bool is_google, const GURL& google_base_url) {
config_data.SetBoolean("isMDIconsEnabled", features::IsMDIconsEnabled()); config_data.SetBoolean("isMDIconsEnabled", features::IsMDIconsEnabled());
config_data.SetBoolean("isCustomBackgroundsEnabled", if (is_google) {
features::IsCustomBackgroundsEnabled()); config_data.SetBoolean("isCustomBackgroundsEnabled",
features::IsCustomBackgroundsEnabled());
}
// Serialize the dictionary. // Serialize the dictionary.
std::string js_text; std::string js_text;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/search/background/ntp_background_service_observer.h" #include "chrome/browser/search/background/ntp_background_service_observer.h"
#include "chrome/browser/search/one_google_bar/one_google_bar_service_observer.h" #include "chrome/browser/search/one_google_bar/one_google_bar_service_observer.h"
#include "components/prefs/pref_registry_simple.h"
#include "content/public/browser/url_data_source.h" #include "content/public/browser/url_data_source.h"
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
......
...@@ -93,7 +93,7 @@ void InstantController::UpdateInfoForInstantTab() { ...@@ -93,7 +93,7 @@ void InstantController::UpdateInfoForInstantTab() {
InstantService* instant_service = InstantService* instant_service =
InstantServiceFactory::GetForProfile(profile_); InstantServiceFactory::GetForProfile(profile_);
if (instant_service) { if (instant_service) {
instant_service->UpdateThemeInfo(); instant_service->UpdateThemeInfo(false);
instant_service->UpdateMostVisitedItemsInfo(); instant_service->UpdateMostVisitedItemsInfo();
} }
} }
...@@ -261,6 +261,13 @@ void SearchIPCRouter::HistorySyncCheck(int page_seq_no, ...@@ -261,6 +261,13 @@ void SearchIPCRouter::HistorySyncCheck(int page_seq_no,
std::move(callback).Run(result); std::move(callback).Run(result);
} }
void SearchIPCRouter::SetCustomBackgroundURL(const GURL& url) {
if (!policy_->ShouldProcessSetCustomBackgroundURL())
return;
delegate_->OnSetCustomBackgroundURL(url);
}
void SearchIPCRouter::set_delegate_for_testing(Delegate* delegate) { void SearchIPCRouter::set_delegate_for_testing(Delegate* delegate) {
DCHECK(delegate); DCHECK(delegate);
delegate_ = delegate; delegate_ = delegate;
......
...@@ -79,6 +79,9 @@ class SearchIPCRouter : public content::WebContentsObserver, ...@@ -79,6 +79,9 @@ class SearchIPCRouter : public content::WebContentsObserver,
// Called when the EmbeddedSearch wants to verify that history sync is // Called when the EmbeddedSearch wants to verify that history sync is
// enabled. // enabled.
virtual bool HistorySyncCheck() = 0; virtual bool HistorySyncCheck() = 0;
// Called when a custom background is selected on the NTP.
virtual void OnSetCustomBackgroundURL(const GURL& url) = 0;
}; };
// An interface to be implemented by consumers of SearchIPCRouter objects to // An interface to be implemented by consumers of SearchIPCRouter objects to
...@@ -102,6 +105,7 @@ class SearchIPCRouter : public content::WebContentsObserver, ...@@ -102,6 +105,7 @@ class SearchIPCRouter : public content::WebContentsObserver,
virtual bool ShouldSendOmniboxFocusChanged() = 0; virtual bool ShouldSendOmniboxFocusChanged() = 0;
virtual bool ShouldSendMostVisitedItems() = 0; virtual bool ShouldSendMostVisitedItems() = 0;
virtual bool ShouldSendThemeBackgroundInfo() = 0; virtual bool ShouldSendThemeBackgroundInfo() = 0;
virtual bool ShouldProcessSetCustomBackgroundURL() = 0;
}; };
// Creates chrome::mojom::EmbeddedSearchClient connections on request. // Creates chrome::mojom::EmbeddedSearchClient connections on request.
...@@ -165,7 +169,7 @@ class SearchIPCRouter : public content::WebContentsObserver, ...@@ -165,7 +169,7 @@ class SearchIPCRouter : public content::WebContentsObserver,
ChromeIdentityCheckCallback callback) override; ChromeIdentityCheckCallback callback) override;
void HistorySyncCheck(int page_seq_no, void HistorySyncCheck(int page_seq_no,
HistorySyncCheckCallback callback) override; HistorySyncCheckCallback callback) override;
void SetCustomBackgroundURL(const GURL& url) override;
void set_embedded_search_client_factory_for_testing( void set_embedded_search_client_factory_for_testing(
std::unique_ptr<EmbeddedSearchClientFactory> factory) { std::unique_ptr<EmbeddedSearchClientFactory> factory) {
embedded_search_client_factory_ = std::move(factory); embedded_search_client_factory_ = std::move(factory);
......
...@@ -71,3 +71,7 @@ bool SearchIPCRouterPolicyImpl::ShouldSendMostVisitedItems() { ...@@ -71,3 +71,7 @@ bool SearchIPCRouterPolicyImpl::ShouldSendMostVisitedItems() {
bool SearchIPCRouterPolicyImpl::ShouldSendThemeBackgroundInfo() { bool SearchIPCRouterPolicyImpl::ShouldSendThemeBackgroundInfo() {
return !is_incognito_ && search::IsInstantNTP(web_contents_); return !is_incognito_ && search::IsInstantNTP(web_contents_);
} }
bool SearchIPCRouterPolicyImpl::ShouldProcessSetCustomBackgroundURL() {
return !is_incognito_ && search::IsInstantNTP(web_contents_);
}
...@@ -39,6 +39,7 @@ class SearchIPCRouterPolicyImpl : public SearchIPCRouter::Policy { ...@@ -39,6 +39,7 @@ class SearchIPCRouterPolicyImpl : public SearchIPCRouter::Policy {
bool ShouldSendOmniboxFocusChanged() override; bool ShouldSendOmniboxFocusChanged() override;
bool ShouldSendMostVisitedItems() override; bool ShouldSendMostVisitedItems() override;
bool ShouldSendThemeBackgroundInfo() override; bool ShouldSendThemeBackgroundInfo() override;
bool ShouldProcessSetCustomBackgroundURL() override;
// Used by unit tests. // Used by unit tests.
void set_is_incognito(bool is_incognito) { void set_is_incognito(bool is_incognito) {
......
...@@ -69,6 +69,7 @@ class MockSearchIPCRouterDelegate : public SearchIPCRouter::Delegate { ...@@ -69,6 +69,7 @@ class MockSearchIPCRouterDelegate : public SearchIPCRouter::Delegate {
MOCK_METHOD1(PasteIntoOmnibox, void(const base::string16&)); MOCK_METHOD1(PasteIntoOmnibox, void(const base::string16&));
MOCK_METHOD1(ChromeIdentityCheck, bool(const base::string16& identity)); MOCK_METHOD1(ChromeIdentityCheck, bool(const base::string16& identity));
MOCK_METHOD0(HistorySyncCheck, bool()); MOCK_METHOD0(HistorySyncCheck, bool());
MOCK_METHOD1(OnSetCustomBackgroundURL, void(const GURL& url));
}; };
class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy { class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy {
...@@ -83,6 +84,7 @@ class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy { ...@@ -83,6 +84,7 @@ class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy {
MOCK_METHOD1(ShouldProcessPasteIntoOmnibox, bool(bool)); MOCK_METHOD1(ShouldProcessPasteIntoOmnibox, bool(bool));
MOCK_METHOD0(ShouldProcessChromeIdentityCheck, bool()); MOCK_METHOD0(ShouldProcessChromeIdentityCheck, bool());
MOCK_METHOD0(ShouldProcessHistorySyncCheck, bool()); MOCK_METHOD0(ShouldProcessHistorySyncCheck, bool());
MOCK_METHOD0(ShouldProcessSetCustomBackgroundURL, bool());
MOCK_METHOD1(ShouldSendSetInputInProgress, bool(bool)); MOCK_METHOD1(ShouldSendSetInputInProgress, bool(bool));
MOCK_METHOD0(ShouldSendOmniboxFocusChanged, bool()); MOCK_METHOD0(ShouldSendOmniboxFocusChanged, bool());
MOCK_METHOD0(ShouldSendMostVisitedItems, bool()); MOCK_METHOD0(ShouldSendMostVisitedItems, bool());
...@@ -584,3 +586,29 @@ TEST_F(SearchIPCRouterTest, DoNotSendThemeBackgroundInfoMsg) { ...@@ -584,3 +586,29 @@ TEST_F(SearchIPCRouterTest, DoNotSendThemeBackgroundInfoMsg) {
EXPECT_CALL(*mock_embedded_search_client(), ThemeChanged(_)).Times(0); EXPECT_CALL(*mock_embedded_search_client(), ThemeChanged(_)).Times(0);
GetSearchIPCRouter().SendThemeBackgroundInfo(ThemeBackgroundInfo()); GetSearchIPCRouter().SendThemeBackgroundInfo(ThemeBackgroundInfo());
} }
TEST_F(SearchIPCRouterTest, ProcessSetCustomBackgroundURLMsg) {
NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
SetupMockDelegateAndPolicy();
MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
GURL bg_url("www.foo.com");
EXPECT_CALL(*mock_delegate(), OnSetCustomBackgroundURL(bg_url)).Times(1);
EXPECT_CALL(*policy, ShouldProcessSetCustomBackgroundURL())
.Times(1)
.WillOnce(Return(true));
GetSearchIPCRouter().SetCustomBackgroundURL(bg_url);
}
TEST_F(SearchIPCRouterTest, IgnoreSetCustomBackgroundURLMsg) {
NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
SetupMockDelegateAndPolicy();
MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
GURL bg_url("www.foo.com");
EXPECT_CALL(*mock_delegate(), OnSetCustomBackgroundURL(bg_url)).Times(0);
EXPECT_CALL(*policy, ShouldProcessSetCustomBackgroundURL())
.Times(1)
.WillOnce(Return(false));
GetSearchIPCRouter().SetCustomBackgroundURL(bg_url);
}
...@@ -352,6 +352,11 @@ bool SearchTabHelper::HistorySyncCheck() { ...@@ -352,6 +352,11 @@ bool SearchTabHelper::HistorySyncCheck() {
return IsHistorySyncEnabled(profile()); return IsHistorySyncEnabled(profile());
} }
void SearchTabHelper::OnSetCustomBackgroundURL(const GURL& url) {
if (instant_service_)
instant_service_->SetCustomBackgroundURL(url);
}
const OmniboxView* SearchTabHelper::GetOmniboxView() const { const OmniboxView* SearchTabHelper::GetOmniboxView() const {
Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
if (!browser) if (!browser)
......
...@@ -104,6 +104,7 @@ class SearchTabHelper : public content::WebContentsObserver, ...@@ -104,6 +104,7 @@ class SearchTabHelper : public content::WebContentsObserver,
void PasteIntoOmnibox(const base::string16& text) override; void PasteIntoOmnibox(const base::string16& text) override;
bool ChromeIdentityCheck(const base::string16& identity) override; bool ChromeIdentityCheck(const base::string16& identity) override;
bool HistorySyncCheck() override; bool HistorySyncCheck() override;
void OnSetCustomBackgroundURL(const GURL& url) override;
// Overridden from InstantServiceObserver: // Overridden from InstantServiceObserver:
void ThemeInfoChanged(const ThemeBackgroundInfo& theme_info) override; void ThemeInfoChanged(const ThemeBackgroundInfo& theme_info) override;
......
...@@ -66,6 +66,7 @@ class MockSearchIPCRouterDelegate : public SearchIPCRouter::Delegate { ...@@ -66,6 +66,7 @@ class MockSearchIPCRouterDelegate : public SearchIPCRouter::Delegate {
MOCK_METHOD1(PasteIntoOmnibox, void(const base::string16&)); MOCK_METHOD1(PasteIntoOmnibox, void(const base::string16&));
MOCK_METHOD1(ChromeIdentityCheck, bool(const base::string16& identity)); MOCK_METHOD1(ChromeIdentityCheck, bool(const base::string16& identity));
MOCK_METHOD0(HistorySyncCheck, bool()); MOCK_METHOD0(HistorySyncCheck, bool());
MOCK_METHOD1(OnSetCustomBackgroundURL, void(const GURL& url));
}; };
class MockEmbeddedSearchClientFactory class MockEmbeddedSearchClientFactory
......
...@@ -61,6 +61,7 @@ IPC_STRUCT_TRAITS_END() ...@@ -61,6 +61,7 @@ IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(ThemeBackgroundInfo) IPC_STRUCT_TRAITS_BEGIN(ThemeBackgroundInfo)
IPC_STRUCT_TRAITS_MEMBER(using_default_theme) IPC_STRUCT_TRAITS_MEMBER(using_default_theme)
IPC_STRUCT_TRAITS_MEMBER(custom_background_url)
IPC_STRUCT_TRAITS_MEMBER(background_color) IPC_STRUCT_TRAITS_MEMBER(background_color)
IPC_STRUCT_TRAITS_MEMBER(text_color) IPC_STRUCT_TRAITS_MEMBER(text_color)
IPC_STRUCT_TRAITS_MEMBER(link_color) IPC_STRUCT_TRAITS_MEMBER(link_color)
......
...@@ -2564,6 +2564,9 @@ const char kAutoplayAllowed[] = "media.autoplay_allowed"; ...@@ -2564,6 +2564,9 @@ const char kAutoplayAllowed[] = "media.autoplay_allowed";
// Holds URL patterns that specify URLs that will be allowed to autoplay. // Holds URL patterns that specify URLs that will be allowed to autoplay.
const char kAutoplayWhitelist[] = "media.autoplay_whitelist"; const char kAutoplayWhitelist[] = "media.autoplay_whitelist";
// Holds URL for New Tab Page custom background
const char kNTPCustomBackgroundURL[] = "new_tab_page.custom_background_url";
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
} // namespace prefs } // namespace prefs
...@@ -906,6 +906,7 @@ extern const char kWebDriverOverridesIncompatiblePolicies[]; ...@@ -906,6 +906,7 @@ extern const char kWebDriverOverridesIncompatiblePolicies[];
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
extern const char kAutoplayAllowed[]; extern const char kAutoplayAllowed[];
extern const char kAutoplayWhitelist[]; extern const char kAutoplayWhitelist[];
extern const char kNTPCustomBackgroundURL[];
#endif #endif
} // namespace prefs } // namespace prefs
......
...@@ -70,6 +70,9 @@ interface EmbeddedSearch { ...@@ -70,6 +70,9 @@ interface EmbeddedSearch {
// The Instant page asks for Chrome identity check against |identity|. // The Instant page asks for Chrome identity check against |identity|.
ChromeIdentityCheck(int32 page_seq_no, mojo_base.mojom.String16 identity) ChromeIdentityCheck(int32 page_seq_no, mojo_base.mojom.String16 identity)
=> (bool identity_match); => (bool identity_match);
// Updates the NTP custom background preferences.
SetCustomBackgroundURL(url.mojom.Url url);
}; };
[Native] [Native]
......
...@@ -23,6 +23,7 @@ bool RGBAColor::operator==(const RGBAColor& rhs) const { ...@@ -23,6 +23,7 @@ bool RGBAColor::operator==(const RGBAColor& rhs) const {
ThemeBackgroundInfo::ThemeBackgroundInfo() ThemeBackgroundInfo::ThemeBackgroundInfo()
: using_default_theme(true), : using_default_theme(true),
custom_background_url(std::string()),
background_color(), background_color(),
text_color(), text_color(),
link_color(), link_color(),
...@@ -33,26 +34,25 @@ ThemeBackgroundInfo::ThemeBackgroundInfo() ...@@ -33,26 +34,25 @@ ThemeBackgroundInfo::ThemeBackgroundInfo()
image_vertical_alignment(THEME_BKGRND_IMAGE_ALIGN_CENTER), image_vertical_alignment(THEME_BKGRND_IMAGE_ALIGN_CENTER),
image_tiling(THEME_BKGRND_IMAGE_NO_REPEAT), image_tiling(THEME_BKGRND_IMAGE_NO_REPEAT),
has_attribution(false), has_attribution(false),
logo_alternate(false) { logo_alternate(false) {}
}
ThemeBackgroundInfo::~ThemeBackgroundInfo() { ThemeBackgroundInfo::~ThemeBackgroundInfo() {
} }
bool ThemeBackgroundInfo::operator==(const ThemeBackgroundInfo& rhs) const { bool ThemeBackgroundInfo::operator==(const ThemeBackgroundInfo& rhs) const {
return using_default_theme == rhs.using_default_theme && return using_default_theme == rhs.using_default_theme &&
background_color == rhs.background_color && custom_background_url == rhs.custom_background_url &&
text_color == rhs.text_color && background_color == rhs.background_color &&
link_color == rhs.link_color && text_color == rhs.text_color && link_color == rhs.link_color &&
text_color_light == rhs.text_color_light && text_color_light == rhs.text_color_light &&
header_color == rhs.header_color && header_color == rhs.header_color &&
section_border_color == rhs.section_border_color && section_border_color == rhs.section_border_color &&
theme_id == rhs.theme_id && theme_id == rhs.theme_id &&
image_horizontal_alignment == rhs.image_horizontal_alignment && image_horizontal_alignment == rhs.image_horizontal_alignment &&
image_vertical_alignment == rhs.image_vertical_alignment && image_vertical_alignment == rhs.image_vertical_alignment &&
image_tiling == rhs.image_tiling && image_tiling == rhs.image_tiling &&
has_attribution == rhs.has_attribution && has_attribution == rhs.has_attribution &&
logo_alternate == rhs.logo_alternate; logo_alternate == rhs.logo_alternate;
} }
InstantMostVisitedItem::InstantMostVisitedItem() InstantMostVisitedItem::InstantMostVisitedItem()
......
...@@ -66,6 +66,9 @@ struct ThemeBackgroundInfo { ...@@ -66,6 +66,9 @@ struct ThemeBackgroundInfo {
// True if the default theme is selected. // True if the default theme is selected.
bool using_default_theme; bool using_default_theme;
// Url of the custom background selected by the user.
GURL custom_background_url;
// The theme background color in RGBA format always valid. // The theme background color in RGBA format always valid.
RGBAColor background_color; RGBAColor background_color;
......
...@@ -314,6 +314,10 @@ void SearchBox::UndoAllMostVisitedDeletions() { ...@@ -314,6 +314,10 @@ void SearchBox::UndoAllMostVisitedDeletions() {
embedded_search_service_->UndoAllMostVisitedDeletions(page_seq_no_); embedded_search_service_->UndoAllMostVisitedDeletions(page_seq_no_);
} }
void SearchBox::SetCustomBackgroundURL(const GURL& background_url) {
embedded_search_service_->SetCustomBackgroundURL(background_url);
}
void SearchBox::UndoMostVisitedDeletion( void SearchBox::UndoMostVisitedDeletion(
InstantRestrictedID most_visited_item_id) { InstantRestrictedID most_visited_item_id) {
GURL url = GetURLForMostVisitedItem(most_visited_item_id); GURL url = GetURLForMostVisitedItem(most_visited_item_id);
......
...@@ -119,6 +119,9 @@ class SearchBox : public content::RenderFrameObserver, ...@@ -119,6 +119,9 @@ class SearchBox : public content::RenderFrameObserver,
// Sends UndoMostVisitedDeletion to the browser. // Sends UndoMostVisitedDeletion to the browser.
void UndoMostVisitedDeletion(InstantRestrictedID most_visited_item_id); void UndoMostVisitedDeletion(InstantRestrictedID most_visited_item_id);
// Updates the NTP custom background preferences.
void SetCustomBackgroundURL(const GURL& background_url);
bool is_focused() const { return is_focused_; } bool is_focused() const { return is_focused_; }
bool is_input_in_progress() const { return is_input_in_progress_; } bool is_input_in_progress() const { return is_input_in_progress_; }
bool is_key_capture_enabled() const { return is_key_capture_enabled_; } bool is_key_capture_enabled() const { return is_key_capture_enabled_; }
......
...@@ -73,6 +73,7 @@ const char kCSSBackgroundColorFormat[] = "rgba(%d,%d,%d,%s)"; ...@@ -73,6 +73,7 @@ const char kCSSBackgroundColorFormat[] = "rgba(%d,%d,%d,%s)";
const char kCSSBackgroundPositionCenter[] = "center"; const char kCSSBackgroundPositionCenter[] = "center";
const char kCSSBackgroundPositionLeft[] = "left"; const char kCSSBackgroundPositionLeft[] = "left";
const char kCSSBackgroundPositionTop[] = "top"; const char kCSSBackgroundPositionTop[] = "top";
const char kCSSBackgroundPositionTopCover[] = "top/cover";
const char kCSSBackgroundPositionRight[] = "right"; const char kCSSBackgroundPositionRight[] = "right";
const char kCSSBackgroundPositionBottom[] = "bottom"; const char kCSSBackgroundPositionBottom[] = "bottom";
...@@ -330,6 +331,17 @@ v8::Local<v8::Object> GenerateThemeBackgroundInfo( ...@@ -330,6 +331,17 @@ v8::Local<v8::Object> GenerateThemeBackgroundInfo(
} }
} }
if (theme_info.using_default_theme &&
!theme_info.custom_background_url.is_empty()) {
builder.Set("imageUrl",
"url('" + theme_info.custom_background_url.spec() + "')");
builder.Set("imageTiling", std::string(kCSSBackgroundRepeatNo));
builder.Set("imageHorizontalAlignment",
std::string(kCSSBackgroundPositionLeft));
builder.Set("imageVerticalAlignment",
std::string(kCSSBackgroundPositionTopCover));
}
return builder.Build(); return builder.Build();
} }
...@@ -576,6 +588,7 @@ class NewTabPageBindings : public gin::Wrappable<NewTabPageBindings> { ...@@ -576,6 +588,7 @@ class NewTabPageBindings : public gin::Wrappable<NewTabPageBindings> {
int tile_source, int tile_source,
int tile_type, int tile_type,
v8::Local<v8::Value> data_generation_time); v8::Local<v8::Value> data_generation_time);
static void SetCustomBackgroundURL(const std::string& background_url);
DISALLOW_COPY_AND_ASSIGN(NewTabPageBindings); DISALLOW_COPY_AND_ASSIGN(NewTabPageBindings);
}; };
...@@ -611,7 +624,9 @@ gin::ObjectTemplateBuilder NewTabPageBindings::GetObjectTemplateBuilder( ...@@ -611,7 +624,9 @@ gin::ObjectTemplateBuilder NewTabPageBindings::GetObjectTemplateBuilder(
.SetMethod("logMostVisitedImpression", .SetMethod("logMostVisitedImpression",
&NewTabPageBindings::LogMostVisitedImpression) &NewTabPageBindings::LogMostVisitedImpression)
.SetMethod("logMostVisitedNavigation", .SetMethod("logMostVisitedNavigation",
&NewTabPageBindings::LogMostVisitedNavigation); &NewTabPageBindings::LogMostVisitedNavigation)
.SetMethod("setBackgroundURL",
&NewTabPageBindings::SetCustomBackgroundURL);
} }
// static // static
...@@ -808,6 +823,14 @@ void NewTabPageBindings::LogMostVisitedNavigation( ...@@ -808,6 +823,14 @@ void NewTabPageBindings::LogMostVisitedNavigation(
} }
} }
// static
void NewTabPageBindings::SetCustomBackgroundURL(
const std::string& background_url) {
SearchBox* search_box = GetSearchBoxForCurrentContext();
GURL url(background_url);
search_box->SetCustomBackgroundURL(url);
}
} // namespace } // namespace
// static // static
......
...@@ -7,9 +7,11 @@ ...@@ -7,9 +7,11 @@
<script>window.localNTPUnitTest = true;</script> <script>window.localNTPUnitTest = true;</script>
<link rel="stylesheet" href="chrome-search://local-ntp/local-ntp.css"></link> <link rel="stylesheet" href="chrome-search://local-ntp/local-ntp.css"></link>
<link rel="stylesheet" href="chrome-search://local-ntp/voice.css"></link> <link rel="stylesheet" href="chrome-search://local-ntp/voice.css"></link>
<link rel="stylesheet" href="chrome-search://local-ntp/custom-backgrounds.css"></link>
<script src="chrome-search://local-ntp/local-ntp.js" charset="utf-8"></script> <script src="chrome-search://local-ntp/local-ntp.js" charset="utf-8"></script>
<script src="chrome-search://local-ntp/voice.js" charset="utf-8"></script> <script src="chrome-search://local-ntp/voice.js" charset="utf-8"></script>
<script src="chrome-search://local-ntp/config.js" charset="utf-8"></script> <script src="chrome-search://local-ntp/config.js" charset="utf-8"></script>
<script src="chrome-search://local-ntp/custom-backgrounds.js" charset="utf-8"></script>
<script src="test_utils.js" charset="utf-8"></script> <script src="test_utils.js" charset="utf-8"></script>
<script src="local_ntp_browsertest.js" charset="utf-8"></script> <script src="local_ntp_browsertest.js" charset="utf-8"></script>
<template id="local-ntp-template"> <template id="local-ntp-template">
......
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