diff options
-rw-r--r-- | chrome/browser/browser.cc | 1 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_unittest.cc | 1 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 61 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.h | 27 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui_uitest.cc | 38 | ||||
-rw-r--r-- | chrome/browser/dom_ui/tips_handler.cc | 11 | ||||
-rw-r--r-- | chrome/browser/resources/new_new_tab.css | 1 | ||||
-rw-r--r-- | chrome/browser/resources/new_new_tab.js | 24 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents_unittest.cc | 4 | ||||
-rw-r--r-- | chrome/common/pref_names.cc | 5 | ||||
-rw-r--r-- | chrome/common/pref_names.h | 1 |
11 files changed, 158 insertions, 16 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 6b2a24b..51c7764 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1920,6 +1920,7 @@ void Browser::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterBooleanPref(prefs::kWebAppCreateInQuickLaunchBar, true); prefs->RegisterBooleanPref(prefs::kUseVerticalTabs, false); prefs->RegisterBooleanPref(prefs::kEnableTranslate, true); + prefs->RegisterIntegerPref(prefs::kNTPPromoViewsRemaining, 5); } // static diff --git a/chrome/browser/dom_ui/dom_ui_unittest.cc b/chrome/browser/dom_ui/dom_ui_unittest.cc index 51f5e1e..8c00663 100644 --- a/chrome/browser/dom_ui/dom_ui_unittest.cc +++ b/chrome/browser/dom_ui/dom_ui_unittest.cc @@ -84,6 +84,7 @@ class DOMUITest : public RenderViewHostTestHarness { // TabContents when we first navigate to a DOM UI page, then to a standard // non-DOM-UI page. TEST_F(DOMUITest, DOMUIToStandard) { + profile_->CreateBookmarkModel(true); DoNavigationTest(contents(), 1); // Test the case where we're not doing the initial navigation. This is diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index 6d2bdde..d367db3 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -15,7 +15,9 @@ #include "base/i18n/rtl.h" #include "base/singleton.h" #include "base/thread.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/browser.h" +#include "chrome/browser/browser_window.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/dom_ui/app_launcher_handler.h" #include "chrome/browser/dom_ui/dom_ui_theme_source.h" @@ -24,6 +26,7 @@ #include "chrome/browser/dom_ui/ntp_resource_cache.h" #include "chrome/browser/dom_ui/shown_sections_handler.h" #include "chrome/browser/dom_ui/tips_handler.h" +#include "chrome/browser/importer/importer_data_types.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" @@ -38,6 +41,11 @@ #include "chrome/common/url_constants.h" #include "grit/generated_resources.h" +#if defined(OS_WIN) +#include "chrome/browser/views/importer_view.h" +#include "views/window/window.h" +#endif + namespace { // The number of recent bookmarks we show. @@ -429,6 +437,43 @@ void NewTabPageSetHomePageHandler::HandleSetHomePage( dom_ui_->CallJavascriptFunction(L"onHomePageSet", list_value); } +/////////////////////////////////////////////////////////////////////////////// +// NewTabPageImportBookmarksHandler +class NewTabPageImportBookmarksHandler : public DOMMessageHandler { + public: + NewTabPageImportBookmarksHandler() {} + virtual ~NewTabPageImportBookmarksHandler() {} + + // DOMMessageHandler implementation. + virtual void RegisterMessages(); + + // Callback for "importBookmarks". + void HandleImportBookmarks(const Value* value); + private: + + DISALLOW_COPY_AND_ASSIGN(NewTabPageImportBookmarksHandler); +}; + +void NewTabPageImportBookmarksHandler::RegisterMessages() { + dom_ui_->RegisterMessageCallback("importBookmarks", NewCallback( + this, &NewTabPageImportBookmarksHandler::HandleImportBookmarks)); +} + +void NewTabPageImportBookmarksHandler::HandleImportBookmarks( + const Value* value) { + Browser* browser = NULL; + TabContentsDelegate* delegate = dom_ui_->tab_contents()->delegate(); + if (delegate) + browser = delegate->GetBrowser(); + DCHECK(browser); +#if defined(OS_WIN) + views::Window::CreateChromeWindow( + browser->window()->GetNativeHandle(), + gfx::Rect(), + new ImporterView(dom_ui_->GetProfile(), importer::FAVORITES))->Show(); +#endif +} + } // namespace /////////////////////////////////////////////////////////////////////////////// @@ -454,6 +499,10 @@ NewTabUI::NewTabUI(TabContents* contents) static bool first_view = true; if (first_view) { + Profile* profile = GetProfile(); + profile->GetPrefs()->SetInteger(prefs::kNTPPromoViewsRemaining, + profile->GetPrefs()->GetInteger(prefs::kNTPPromoViewsRemaining) - 1); + profile->GetBookmarkModel()->AddObserver(this); first_view = false; } @@ -476,6 +525,7 @@ NewTabUI::NewTabUI(TabContents* contents) } AddMessageHandler((new NewTabPageSetHomePageHandler())->Attach(this)); + AddMessageHandler((new NewTabPageImportBookmarksHandler())->Attach(this)); } // Initializing the CSS and HTML can require some CPU, so do it after @@ -500,6 +550,9 @@ NewTabUI::NewTabUI(TabContents* contents) } NewTabUI::~NewTabUI() { + BookmarkModel* bookmark_model = GetProfile()->GetBookmarkModel(); + if (bookmark_model) + bookmark_model->RemoveObserver(this); } void NewTabUI::RenderViewCreated(RenderViewHost* render_view_host) { @@ -510,6 +563,14 @@ void NewTabUI::RenderViewReused(RenderViewHost* render_view_host) { render_view_host->set_paint_observer(new PaintTimer); } +void NewTabUI::BookmarkNodeAdded(BookmarkModel* model, + const BookmarkNode* parent, + int index) { + // Stop showing the promo, and no longer observe the bookmark model. + GetProfile()->GetPrefs()->SetInteger(prefs::kNTPPromoViewsRemaining, 0); + GetProfile()->GetBookmarkModel()->RemoveObserver(this); +} + void NewTabUI::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { diff --git a/chrome/browser/dom_ui/new_tab_ui.h b/chrome/browser/dom_ui/new_tab_ui.h index e8a7b4f..7598764 100644 --- a/chrome/browser/dom_ui/new_tab_ui.h +++ b/chrome/browser/dom_ui/new_tab_ui.h @@ -8,6 +8,7 @@ #include <string> #include "base/gtest_prod_util.h" +#include "chrome/browser/bookmarks/bookmark_model_observer.h" #include "chrome/browser/dom_ui/dom_ui.h" #include "chrome/browser/dom_ui/chrome_url_data_manager.h" #include "chrome/common/notification_registrar.h" @@ -19,7 +20,8 @@ class Profile; // The TabContents used for the New Tab page. class NewTabUI : public DOMUI, - public NotificationObserver { + public NotificationObserver, + public BookmarkModelObserver { public: explicit NewTabUI(TabContents* manager); ~NewTabUI(); @@ -29,6 +31,29 @@ class NewTabUI : public DOMUI, virtual void RenderViewCreated(RenderViewHost* render_view_host); virtual void RenderViewReused(RenderViewHost* render_view_host); + // Overridden from BookmarkModelObserver so we can remove the promo for + // importing bookmarks if the user adds a bookmark in any way. + virtual void BookmarkNodeAdded(BookmarkModel* model, + const BookmarkNode* parent, + int index); + + // These methods must be overridden so that the NTP can be a + // BookmarkModelObserver. + virtual void Loaded(BookmarkModel* model) {} + virtual void BookmarkModelBeingDeleted(BookmarkModel* model) {} + virtual void BookmarkNodeMoved(BookmarkModel* model, + const BookmarkNode* old_parent, int old_index, + const BookmarkNode* new_parent, int new_index) {} + virtual void BookmarkNodeRemoved(BookmarkModel* model, + const BookmarkNode* parent, int old_index, + const BookmarkNode* node) {} + virtual void BookmarkNodeChanged(BookmarkModel* model, + const BookmarkNode* node) {} + virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, + const BookmarkNode* node) {} + virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, + const BookmarkNode* node) {} + static void RegisterUserPrefs(PrefService* prefs); static void MigrateUserPrefs(PrefService* prefs, int old_pref_version, int new_pref_version); diff --git a/chrome/browser/dom_ui/new_tab_ui_uitest.cc b/chrome/browser/dom_ui/new_tab_ui_uitest.cc index 39f41e2..67dd4b5 100644 --- a/chrome/browser/dom_ui/new_tab_ui_uitest.cc +++ b/chrome/browser/dom_ui/new_tab_ui_uitest.cc @@ -161,6 +161,42 @@ TEST_F(NewTabUITest, HomePageLink) { bool is_home_page; ASSERT_TRUE(browser->GetBooleanPreference(prefs::kHomePageIsNewTabPage, - &is_home_page)); + &is_home_page)); ASSERT_TRUE(is_home_page); } + +TEST_F(NewTabUITest, PromoLink) { +#if defined(OS_WIN) + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(browser.get()); + + // Bring up a new tab page. + ASSERT_TRUE(browser->RunCommand(IDC_NEW_TAB)); + int load_time; + ASSERT_TRUE(automation()->WaitForInitialNewTabUILoad(&load_time)); + + scoped_refptr<TabProxy> tab = browser->GetActiveTab(); + ASSERT_TRUE(tab.get()); + + // Test "import bookmarks" promo. + bool result; + ASSERT_TRUE(tab->ExecuteAndExtractBool(L"", + L"window.domAutomationController.send(" + L"(function() {" + L" tipCache = [{\"set_promo_tip\":" + L"\"<button class='link'>Import</button> bookmarks\"}];" + L" renderTip();" + L" var e = document.createEvent('Event');" + L" e.initEvent('click', true, true);" + L" var el = document.querySelector('#tip-line button');" + L" el.dispatchEvent(e);" + L" return true;" + L"})()" + L")", + &result)); + + ASSERT_TRUE(result); +#endif + // TODO(mirandac): Ensure that we showed the import bookmarks dialog. + // Remove check for OS_WIN after implemented in Mac and Linux. +} diff --git a/chrome/browser/dom_ui/tips_handler.cc b/chrome/browser/dom_ui/tips_handler.cc index 1a7b59c..6a8a2f4f 100644 --- a/chrome/browser/dom_ui/tips_handler.cc +++ b/chrome/browser/dom_ui/tips_handler.cc @@ -54,6 +54,17 @@ void TipsHandler::HandleGetTips(const Value* content) { } } + // If the user has just started using Chrome with a fresh profile, send only + // the "Import bookmarks" promo until the user has either seen it five times + // or added or imported bookmarks. + if (current_prefs->GetInteger(prefs::kNTPPromoViewsRemaining) > 0) { + SendTip(WideToUTF8(l10n_util::GetStringF(IDS_IMPORT_BOOKMARKS_PROMO, + std::wstring(L"<button class='link'>"), + std::wstring(L"</button>"))), + L"set_promo_tip", 0); + return; + } + if (tips_cache_ != NULL && !tips_cache_->empty()) { if (tips_cache_->GetInteger( WebResourceService::kCurrentTipPrefName, ¤t_tip_index) && diff --git a/chrome/browser/resources/new_new_tab.css b/chrome/browser/resources/new_new_tab.css index a201da6..b842877 100644 --- a/chrome/browser/resources/new_new_tab.css +++ b/chrome/browser/resources/new_new_tab.css @@ -281,6 +281,7 @@ html[dir=rtl] .item { #tip-line button { /* We do not want a trailing single word from a link on the last line */ white-space: nowrap; + padding: 0; } #option-button { diff --git a/chrome/browser/resources/new_new_tab.js b/chrome/browser/resources/new_new_tab.js index 5728d58..0274b9b7 100644 --- a/chrome/browser/resources/new_new_tab.js +++ b/chrome/browser/resources/new_new_tab.js @@ -27,6 +27,12 @@ function createTip(data) { homepageButton.textContent = data[0].set_homepage_tip; homepageButton.addEventListener('click', setAsHomePageLinkClicked); return homepageButton; + } else if (data[0].set_promo_tip) { + var promoMessage = document.createElement('span'); + promoMessage.innerHTML = data[0].set_promo_tip; + var promoButton = promoMessage.querySelector('button'); + promoButton.addEventListener('click', importBookmarksLinkClicked); + return promoMessage; } else { try { return parseHtmlSubset(data[0].tip_html_text); @@ -441,14 +447,6 @@ function hideNotification() { actionLink.blur(); } -function showFirstRunNotification() { - showNotification(localStrings.getString('firstrunnotification'), - localStrings.getString('closefirstrunnotification'), - null, 30000); - var notificationElement = $('notification'); - notification.classList.add('first-run'); -} - /** * This handles the option menu. * @param {Element} button The button element. @@ -852,6 +850,11 @@ function setAsHomePageLinkClicked(e) { e.preventDefault(); } +function importBookmarksLinkClicked(e) { + chrome.send('importBookmarks'); + e.preventDefault(); +} + function onHomePageSet(data) { showNotification(data[0], data[1]); // Removes the "make this my home page" tip. @@ -931,11 +934,6 @@ function mostVisitedPages(data, firstRun) { mostVisited.ensureSmallGridCorrect(); document.body.classList.remove('loading'); }, 1); - - // Only show the first run notification if first run. - if (firstRun) { - showFirstRunNotification(); - } } // Log clicked links from the tips section. diff --git a/chrome/browser/tab_contents/web_contents_unittest.cc b/chrome/browser/tab_contents/web_contents_unittest.cc index ba0d171..1ece79f 100644 --- a/chrome/browser/tab_contents/web_contents_unittest.cc +++ b/chrome/browser/tab_contents/web_contents_unittest.cc @@ -43,7 +43,9 @@ static void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params, // Subclass the TestingProfile so that it can return certain services we need. class TabContentsTestingProfile : public TestingProfile { public: - TabContentsTestingProfile() : TestingProfile() { } + TabContentsTestingProfile() : TestingProfile() { + CreateBookmarkModel(false); + } virtual PrefService* GetPrefs() { if (!prefs_.get()) { diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index b65a3da..c605887b 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -440,6 +440,11 @@ const wchar_t kUseCustomChromeFrame[] = L"browser.custom_chrome_frame"; // done directly from the omnibox should be shown. const wchar_t kShowOmniboxSearchHint[] = L"browser.show_omnibox_search_hint"; +// Int which specifies how many times left to show a promotional message on the +// NTP. This value decrements each time the NTP is shown for the first time +// in a session. +const wchar_t kNTPPromoViewsRemaining[] = L"browser.ntp.promo_remaining"; + // The list of origins which are allowed|denied to show desktop notifications. const wchar_t kDesktopNotificationDefaultContentSetting[] = L"profile.notifications_default_content_setting"; diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 7dfc8ff..9ccc2bd 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -170,6 +170,7 @@ extern const wchar_t kShowUpdatePromotionInfoBar[]; #endif extern const wchar_t kUseCustomChromeFrame[]; extern const wchar_t kShowOmniboxSearchHint[]; +extern const wchar_t kNTPPromoViewsRemaining[]; extern const wchar_t kDesktopNotificationDefaultContentSetting[]; extern const wchar_t kDesktopNotificationAllowedOrigins[]; extern const wchar_t kDesktopNotificationDeniedOrigins[]; |