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 <[email protected]>
Reviewed-by: Emily Stark <[email protected]>
Reviewed-by: Bernhard Bauer <[email protected]>
Reviewed-by: Marc Treib <[email protected]>
Cr-Commit-Position: refs/heads/master@{#565320}
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index f576ea66..c2ceff2 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -287,6 +287,10 @@
#include "chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_util.h"
#endif
+#if !defined(OS_ANDROID)
+#include "chrome/browser/search/instant_service.h"
+#endif
+
#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
#include "chrome/browser/ui/startup/default_browser_prompt.h"
#endif
@@ -610,6 +614,7 @@
#if !defined(OS_ANDROID)
browser_sync::ForeignSessionHandler::RegisterProfilePrefs(registry);
first_run::RegisterProfilePrefs(registry);
+ InstantService::RegisterProfilePrefs(registry);
gcm::GCMChannelStatusSyncer::RegisterProfilePrefs(registry);
gcm::RegisterProfilePrefs(registry);
StartupBrowserCreator::RegisterProfilePrefs(registry);
diff --git a/chrome/browser/resources/local_ntp/custom_backgrounds.js b/chrome/browser/resources/local_ntp/custom_backgrounds.js
index f6c2dc5d..07b77e2 100644
--- a/chrome/browser/resources/local_ntp/custom_backgrounds.js
+++ b/chrome/browser/resources/local_ntp/custom_backgrounds.js
@@ -161,6 +161,7 @@
customBackgrounds.showImageSelectionDialog = function(dialogTitle) {
var backButton = $(customBackgrounds.IDS.BACK);
var dailyRefresh = $(customBackgrounds.IDS.REFRESH_TOGGLE);
+ var doneButton = $(customBackgrounds.IDS.DONE);
var overlay = $(customBackgrounds.IDS.OVERLAY);
var selectedTile = null;
var tileContainer = $(customBackgrounds.IDS.TILES);
@@ -176,6 +177,7 @@
tile.classList.add(customBackgrounds.CLASSES.COLLECTION_TILE);
tile.style.backgroundImage = 'url(' + coll_img[i].imageUrl + ')';
tile.id = 'img_tile_' + i;
+ tile.dataset.url = coll_img[i].imageUrl;
tile.onclick = function(event) {
var tile = event.target;
@@ -199,11 +201,22 @@
if (selectedTile) {
selectedTile.classList.remove(
customBackgrounds.CLASSES.COLLECTION_SELECTED);
+ selectedTile = null;
}
$(customBackgrounds.IDS.DONE)
.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) {
customBackgrounds.resetSelectionDialog();
customBackgrounds.showCollectionSelectionDialog();
@@ -213,7 +226,7 @@
/**
* Display dialog with various options for custom background source.
*/
-customBackgrounds.initBackgroundOptionDialog = function() {
+customBackgrounds.initCustomBackgrounds = function() {
var editDialogOverlay = $(customBackgrounds.IDS.EDIT_BG_OVERLAY);
$(customBackgrounds.IDS.CONNECT_GOOGLE_PHOTOS_TEXT).textContent =
@@ -233,7 +246,6 @@
$(customBackgrounds.IDS.CONNECT_GOOGLE_PHOTOS).hidden = true;
$(customBackgrounds.IDS.DEFAULT_WALLPAPERS).hidden = false;
$(customBackgrounds.IDS.UPLOAD_IMAGE).hidden = true;
- $(customBackgrounds.IDS.RESTORE_DEFAULT).hidden = true;
$(customBackgrounds.IDS.DEFAULT_WALLPAPERS).onclick = function() {
$(customBackgrounds.IDS.EDIT_BG_OVERLAY)
@@ -244,6 +256,12 @@
}
};
+ $(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);
};
diff --git a/chrome/browser/resources/local_ntp/local_ntp.js b/chrome/browser/resources/local_ntp/local_ntp.js
index cf2ba5d0..d09bd0db 100644
--- a/chrome/browser/resources/local_ntp/local_ntp.js
+++ b/chrome/browser/resources/local_ntp/local_ntp.js
@@ -301,6 +301,9 @@
updateThemeAttribution(info.attributionUrl, info.imageHorizontalAlignment);
setCustomThemeStyle(info);
+ $(customBackgrounds.IDS.RESTORE_DEFAULT).hidden =
+ !(info.imageUrl && info.imageUrl.length > 0);
+
if (configData.isGooglePage) {
$('edit-bg').hidden =
!configData.isCustomBackgroundsEnabled || !info.usingDefaultTheme;
@@ -318,7 +321,7 @@
document.body.appendChild(collScript);
};
if (configData.isCustomBackgroundsEnabled && info.usingDefaultTheme)
- customBackgrounds.initBackgroundOptionDialog();
+ customBackgrounds.initCustomBackgrounds();
}
}
diff --git a/chrome/browser/search/instant_service.cc b/chrome/browser/search/instant_service.cc
index 9ff5b85..8f85ca0 100644
--- a/chrome/browser/search/instant_service.cc
+++ b/chrome/browser/search/instant_service.cc
@@ -13,14 +13,21 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/instant_io_context.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/search.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/ui/webui/favicon_source.h"
#include "chrome/browser/ui/webui/theme_source.h"
+#include "chrome/common/pref_names.h"
#include "chrome/common/search.mojom.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 "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
@@ -28,10 +35,6 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/url_data_source.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) {
// The initialization below depends on a typical set of browser threads. Skip
@@ -125,9 +128,9 @@
}
}
-void InstantService::UpdateThemeInfo() {
+void InstantService::UpdateThemeInfo(bool force_update) {
// Initialize |theme_info_| if necessary.
- if (!theme_info_) {
+ if (!theme_info_ || force_update) {
BuildThemeInfo();
}
NotifyAboutThemeInfo();
@@ -146,6 +149,17 @@
}
}
+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() {
process_ids_.clear();
@@ -337,4 +351,15 @@
theme_info_->has_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());
}
diff --git a/chrome/browser/search/instant_service.h b/chrome/browser/search/instant_service.h
index 3bca026e..561a3e47d 100644
--- a/chrome/browser/search/instant_service.h
+++ b/chrome/browser/search/instant_service.h
@@ -20,6 +20,7 @@
#include "components/keyed_service/core/keyed_service.h"
#include "components/ntp_tiles/most_visited_sites.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_registrar.h"
#include "url/gurl.h"
@@ -58,6 +59,9 @@
void AddObserver(InstantServiceObserver* observer);
void RemoveObserver(InstantServiceObserver* observer);
+ // Register prefs associated with the NTP.
+ static void RegisterProfilePrefs(PrefRegistrySimple* registry);
+
#if defined(UNIT_TEST)
int GetInstantProcessCount() const {
return process_ids_.size();
@@ -81,7 +85,7 @@
//
// TODO(kmadhusu): Invoking this from InstantController shouldn't be
// 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
// NTP.
@@ -90,6 +94,9 @@
// Sends the current NTP URL to a renderer process.
void SendNewTabPageURLToRenderer(content::RenderProcessHost* rph);
+ // Invoked when a custom background is selected on the NTP.
+ void SetCustomBackgroundURL(const GURL& url);
+
private:
friend class InstantExtendedTest;
friend class InstantUnitTestBase;
diff --git a/chrome/browser/search/local_ntp_source.cc b/chrome/browser/search/local_ntp_source.cc
index 7f206101..2d276550 100644
--- a/chrome/browser/search/local_ntp_source.cc
+++ b/chrome/browser/search/local_ntp_source.cc
@@ -37,9 +37,12 @@
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/browser_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/template_url_service.h"
#include "components/search_engines/template_url_service_observer.h"
@@ -206,8 +209,10 @@
config_data.SetBoolean("isMDIconsEnabled", features::IsMDIconsEnabled());
- config_data.SetBoolean("isCustomBackgroundsEnabled",
- features::IsCustomBackgroundsEnabled());
+ if (is_google) {
+ config_data.SetBoolean("isCustomBackgroundsEnabled",
+ features::IsCustomBackgroundsEnabled());
+ }
// Serialize the dictionary.
std::string js_text;
diff --git a/chrome/browser/search/local_ntp_source.h b/chrome/browser/search/local_ntp_source.h
index 746d6f11..d2868de 100644
--- a/chrome/browser/search/local_ntp_source.h
+++ b/chrome/browser/search/local_ntp_source.h
@@ -17,6 +17,7 @@
#include "build/build_config.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 "components/prefs/pref_registry_simple.h"
#include "content/public/browser/url_data_source.h"
#if defined(OS_ANDROID)
diff --git a/chrome/browser/ui/search/instant_controller.cc b/chrome/browser/ui/search/instant_controller.cc
index 95705d98..59f94859 100644
--- a/chrome/browser/ui/search/instant_controller.cc
+++ b/chrome/browser/ui/search/instant_controller.cc
@@ -93,7 +93,7 @@
InstantService* instant_service =
InstantServiceFactory::GetForProfile(profile_);
if (instant_service) {
- instant_service->UpdateThemeInfo();
+ instant_service->UpdateThemeInfo(false);
instant_service->UpdateMostVisitedItemsInfo();
}
}
diff --git a/chrome/browser/ui/search/search_ipc_router.cc b/chrome/browser/ui/search/search_ipc_router.cc
index 521b8ec..d9a8d33 100644
--- a/chrome/browser/ui/search/search_ipc_router.cc
+++ b/chrome/browser/ui/search/search_ipc_router.cc
@@ -261,6 +261,13 @@
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) {
DCHECK(delegate);
delegate_ = delegate;
diff --git a/chrome/browser/ui/search/search_ipc_router.h b/chrome/browser/ui/search/search_ipc_router.h
index f5df5f5..8bad37b 100644
--- a/chrome/browser/ui/search/search_ipc_router.h
+++ b/chrome/browser/ui/search/search_ipc_router.h
@@ -79,6 +79,9 @@
// Called when the EmbeddedSearch wants to verify that history sync is
// enabled.
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
@@ -102,6 +105,7 @@
virtual bool ShouldSendOmniboxFocusChanged() = 0;
virtual bool ShouldSendMostVisitedItems() = 0;
virtual bool ShouldSendThemeBackgroundInfo() = 0;
+ virtual bool ShouldProcessSetCustomBackgroundURL() = 0;
};
// Creates chrome::mojom::EmbeddedSearchClient connections on request.
@@ -165,7 +169,7 @@
ChromeIdentityCheckCallback callback) override;
void HistorySyncCheck(int page_seq_no,
HistorySyncCheckCallback callback) override;
-
+ void SetCustomBackgroundURL(const GURL& url) override;
void set_embedded_search_client_factory_for_testing(
std::unique_ptr<EmbeddedSearchClientFactory> factory) {
embedded_search_client_factory_ = std::move(factory);
diff --git a/chrome/browser/ui/search/search_ipc_router_policy_impl.cc b/chrome/browser/ui/search/search_ipc_router_policy_impl.cc
index 773971da..44c6986 100644
--- a/chrome/browser/ui/search/search_ipc_router_policy_impl.cc
+++ b/chrome/browser/ui/search/search_ipc_router_policy_impl.cc
@@ -71,3 +71,7 @@
bool SearchIPCRouterPolicyImpl::ShouldSendThemeBackgroundInfo() {
return !is_incognito_ && search::IsInstantNTP(web_contents_);
}
+
+bool SearchIPCRouterPolicyImpl::ShouldProcessSetCustomBackgroundURL() {
+ return !is_incognito_ && search::IsInstantNTP(web_contents_);
+}
diff --git a/chrome/browser/ui/search/search_ipc_router_policy_impl.h b/chrome/browser/ui/search/search_ipc_router_policy_impl.h
index 108b243..3524234e 100644
--- a/chrome/browser/ui/search/search_ipc_router_policy_impl.h
+++ b/chrome/browser/ui/search/search_ipc_router_policy_impl.h
@@ -39,6 +39,7 @@
bool ShouldSendOmniboxFocusChanged() override;
bool ShouldSendMostVisitedItems() override;
bool ShouldSendThemeBackgroundInfo() override;
+ bool ShouldProcessSetCustomBackgroundURL() override;
// Used by unit tests.
void set_is_incognito(bool is_incognito) {
diff --git a/chrome/browser/ui/search/search_ipc_router_unittest.cc b/chrome/browser/ui/search/search_ipc_router_unittest.cc
index 7564478..a5f9517 100644
--- a/chrome/browser/ui/search/search_ipc_router_unittest.cc
+++ b/chrome/browser/ui/search/search_ipc_router_unittest.cc
@@ -69,6 +69,7 @@
MOCK_METHOD1(PasteIntoOmnibox, void(const base::string16&));
MOCK_METHOD1(ChromeIdentityCheck, bool(const base::string16& identity));
MOCK_METHOD0(HistorySyncCheck, bool());
+ MOCK_METHOD1(OnSetCustomBackgroundURL, void(const GURL& url));
};
class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy {
@@ -83,6 +84,7 @@
MOCK_METHOD1(ShouldProcessPasteIntoOmnibox, bool(bool));
MOCK_METHOD0(ShouldProcessChromeIdentityCheck, bool());
MOCK_METHOD0(ShouldProcessHistorySyncCheck, bool());
+ MOCK_METHOD0(ShouldProcessSetCustomBackgroundURL, bool());
MOCK_METHOD1(ShouldSendSetInputInProgress, bool(bool));
MOCK_METHOD0(ShouldSendOmniboxFocusChanged, bool());
MOCK_METHOD0(ShouldSendMostVisitedItems, bool());
@@ -584,3 +586,29 @@
EXPECT_CALL(*mock_embedded_search_client(), ThemeChanged(_)).Times(0);
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);
+}
diff --git a/chrome/browser/ui/search/search_tab_helper.cc b/chrome/browser/ui/search/search_tab_helper.cc
index 7dae88c7..ea37437 100644
--- a/chrome/browser/ui/search/search_tab_helper.cc
+++ b/chrome/browser/ui/search/search_tab_helper.cc
@@ -352,6 +352,11 @@
return IsHistorySyncEnabled(profile());
}
+void SearchTabHelper::OnSetCustomBackgroundURL(const GURL& url) {
+ if (instant_service_)
+ instant_service_->SetCustomBackgroundURL(url);
+}
+
const OmniboxView* SearchTabHelper::GetOmniboxView() const {
Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
if (!browser)
diff --git a/chrome/browser/ui/search/search_tab_helper.h b/chrome/browser/ui/search/search_tab_helper.h
index 090cb0b..e54676c 100644
--- a/chrome/browser/ui/search/search_tab_helper.h
+++ b/chrome/browser/ui/search/search_tab_helper.h
@@ -104,6 +104,7 @@
void PasteIntoOmnibox(const base::string16& text) override;
bool ChromeIdentityCheck(const base::string16& identity) override;
bool HistorySyncCheck() override;
+ void OnSetCustomBackgroundURL(const GURL& url) override;
// Overridden from InstantServiceObserver:
void ThemeInfoChanged(const ThemeBackgroundInfo& theme_info) override;
diff --git a/chrome/browser/ui/search/search_tab_helper_unittest.cc b/chrome/browser/ui/search/search_tab_helper_unittest.cc
index 9759a00..f07b779 100644
--- a/chrome/browser/ui/search/search_tab_helper_unittest.cc
+++ b/chrome/browser/ui/search/search_tab_helper_unittest.cc
@@ -66,6 +66,7 @@
MOCK_METHOD1(PasteIntoOmnibox, void(const base::string16&));
MOCK_METHOD1(ChromeIdentityCheck, bool(const base::string16& identity));
MOCK_METHOD0(HistorySyncCheck, bool());
+ MOCK_METHOD1(OnSetCustomBackgroundURL, void(const GURL& url));
};
class MockEmbeddedSearchClientFactory
diff --git a/chrome/common/instant_struct_traits.h b/chrome/common/instant_struct_traits.h
index 2d4ce865..d841649 100644
--- a/chrome/common/instant_struct_traits.h
+++ b/chrome/common/instant_struct_traits.h
@@ -61,6 +61,7 @@
IPC_STRUCT_TRAITS_BEGIN(ThemeBackgroundInfo)
IPC_STRUCT_TRAITS_MEMBER(using_default_theme)
+ IPC_STRUCT_TRAITS_MEMBER(custom_background_url)
IPC_STRUCT_TRAITS_MEMBER(background_color)
IPC_STRUCT_TRAITS_MEMBER(text_color)
IPC_STRUCT_TRAITS_MEMBER(link_color)
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index b4a9b32d..de63f0e 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -2564,6 +2564,9 @@
// Holds URL patterns that specify URLs that will be allowed to autoplay.
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)
} // namespace prefs
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 23eb6f7..5503595 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -906,6 +906,7 @@
#if !defined(OS_ANDROID)
extern const char kAutoplayAllowed[];
extern const char kAutoplayWhitelist[];
+extern const char kNTPCustomBackgroundURL[];
#endif
} // namespace prefs
diff --git a/chrome/common/search.mojom b/chrome/common/search.mojom
index 02b2928..468a3d5d 100644
--- a/chrome/common/search.mojom
+++ b/chrome/common/search.mojom
@@ -70,6 +70,9 @@
// The Instant page asks for Chrome identity check against |identity|.
ChromeIdentityCheck(int32 page_seq_no, mojo_base.mojom.String16 identity)
=> (bool identity_match);
+
+ // Updates the NTP custom background preferences.
+ SetCustomBackgroundURL(url.mojom.Url url);
};
[Native]
diff --git a/chrome/common/search/instant_types.cc b/chrome/common/search/instant_types.cc
index e23140f0..ab13649 100644
--- a/chrome/common/search/instant_types.cc
+++ b/chrome/common/search/instant_types.cc
@@ -23,6 +23,7 @@
ThemeBackgroundInfo::ThemeBackgroundInfo()
: using_default_theme(true),
+ custom_background_url(std::string()),
background_color(),
text_color(),
link_color(),
@@ -33,26 +34,25 @@
image_vertical_alignment(THEME_BKGRND_IMAGE_ALIGN_CENTER),
image_tiling(THEME_BKGRND_IMAGE_NO_REPEAT),
has_attribution(false),
- logo_alternate(false) {
-}
+ logo_alternate(false) {}
ThemeBackgroundInfo::~ThemeBackgroundInfo() {
}
bool ThemeBackgroundInfo::operator==(const ThemeBackgroundInfo& rhs) const {
return using_default_theme == rhs.using_default_theme &&
- background_color == rhs.background_color &&
- text_color == rhs.text_color &&
- link_color == rhs.link_color &&
- text_color_light == rhs.text_color_light &&
- header_color == rhs.header_color &&
- section_border_color == rhs.section_border_color &&
- theme_id == rhs.theme_id &&
- image_horizontal_alignment == rhs.image_horizontal_alignment &&
- image_vertical_alignment == rhs.image_vertical_alignment &&
- image_tiling == rhs.image_tiling &&
- has_attribution == rhs.has_attribution &&
- logo_alternate == rhs.logo_alternate;
+ custom_background_url == rhs.custom_background_url &&
+ background_color == rhs.background_color &&
+ text_color == rhs.text_color && link_color == rhs.link_color &&
+ text_color_light == rhs.text_color_light &&
+ header_color == rhs.header_color &&
+ section_border_color == rhs.section_border_color &&
+ theme_id == rhs.theme_id &&
+ image_horizontal_alignment == rhs.image_horizontal_alignment &&
+ image_vertical_alignment == rhs.image_vertical_alignment &&
+ image_tiling == rhs.image_tiling &&
+ has_attribution == rhs.has_attribution &&
+ logo_alternate == rhs.logo_alternate;
}
InstantMostVisitedItem::InstantMostVisitedItem()
diff --git a/chrome/common/search/instant_types.h b/chrome/common/search/instant_types.h
index de22bb1..817a7c4 100644
--- a/chrome/common/search/instant_types.h
+++ b/chrome/common/search/instant_types.h
@@ -66,6 +66,9 @@
// True if the default theme is selected.
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.
RGBAColor background_color;
diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc
index 6ffd0c3..f7e90218 100644
--- a/chrome/renderer/searchbox/searchbox.cc
+++ b/chrome/renderer/searchbox/searchbox.cc
@@ -314,6 +314,10 @@
embedded_search_service_->UndoAllMostVisitedDeletions(page_seq_no_);
}
+void SearchBox::SetCustomBackgroundURL(const GURL& background_url) {
+ embedded_search_service_->SetCustomBackgroundURL(background_url);
+}
+
void SearchBox::UndoMostVisitedDeletion(
InstantRestrictedID most_visited_item_id) {
GURL url = GetURLForMostVisitedItem(most_visited_item_id);
diff --git a/chrome/renderer/searchbox/searchbox.h b/chrome/renderer/searchbox/searchbox.h
index 2f7394d3..f50b31a 100644
--- a/chrome/renderer/searchbox/searchbox.h
+++ b/chrome/renderer/searchbox/searchbox.h
@@ -119,6 +119,9 @@
// Sends UndoMostVisitedDeletion to the browser.
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_input_in_progress() const { return is_input_in_progress_; }
bool is_key_capture_enabled() const { return is_key_capture_enabled_; }
diff --git a/chrome/renderer/searchbox/searchbox_extension.cc b/chrome/renderer/searchbox/searchbox_extension.cc
index c6de9ea..3cb5ed9 100644
--- a/chrome/renderer/searchbox/searchbox_extension.cc
+++ b/chrome/renderer/searchbox/searchbox_extension.cc
@@ -73,6 +73,7 @@
const char kCSSBackgroundPositionCenter[] = "center";
const char kCSSBackgroundPositionLeft[] = "left";
const char kCSSBackgroundPositionTop[] = "top";
+const char kCSSBackgroundPositionTopCover[] = "top/cover";
const char kCSSBackgroundPositionRight[] = "right";
const char kCSSBackgroundPositionBottom[] = "bottom";
@@ -330,6 +331,17 @@
}
}
+ 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();
}
@@ -576,6 +588,7 @@
int tile_source,
int tile_type,
v8::Local<v8::Value> data_generation_time);
+ static void SetCustomBackgroundURL(const std::string& background_url);
DISALLOW_COPY_AND_ASSIGN(NewTabPageBindings);
};
@@ -611,7 +624,9 @@
.SetMethod("logMostVisitedImpression",
&NewTabPageBindings::LogMostVisitedImpression)
.SetMethod("logMostVisitedNavigation",
- &NewTabPageBindings::LogMostVisitedNavigation);
+ &NewTabPageBindings::LogMostVisitedNavigation)
+ .SetMethod("setBackgroundURL",
+ &NewTabPageBindings::SetCustomBackgroundURL);
}
// static
@@ -808,6 +823,14 @@
}
}
+// static
+void NewTabPageBindings::SetCustomBackgroundURL(
+ const std::string& background_url) {
+ SearchBox* search_box = GetSearchBoxForCurrentContext();
+ GURL url(background_url);
+ search_box->SetCustomBackgroundURL(url);
+}
+
} // namespace
// static
diff --git a/chrome/test/data/local_ntp/local_ntp_browsertest.html b/chrome/test/data/local_ntp/local_ntp_browsertest.html
index 0d0d9757..4254091 100644
--- a/chrome/test/data/local_ntp/local_ntp_browsertest.html
+++ b/chrome/test/data/local_ntp/local_ntp_browsertest.html
@@ -7,9 +7,11 @@
<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/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/voice.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="local_ntp_browsertest.js" charset="utf-8"></script>
<template id="local-ntp-template">