summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
diff options
context:
space:
mode:
authoridana@chromium.org <idana@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-17 23:03:21 +0000
committeridana@chromium.org <idana@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-17 23:03:21 +0000
commit386afa320189f08ab18b453863d6cc6a758b06d1 (patch)
tree7e5ce37fdbf63daf478f2b178b2c8d2e47e150fe /chrome/browser/dom_ui
parentd9810a805d4e4626bf2ec9dc805e5643a801d3d9 (diff)
downloadchromium_src-386afa320189f08ab18b453863d6cc6a758b06d1.zip
chromium_src-386afa320189f08ab18b453863d6cc6a758b06d1.tar.gz
chromium_src-386afa320189f08ab18b453863d6cc6a758b06d1.tar.bz2
Made the Sync UI work in the New New tab page.
There are no significant logic changes except the addition of a link which points to the web ui. BUG=none Review URL: http://codereview.chromium.org/172007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23591 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r--chrome/browser/dom_ui/new_tab_page_sync_handler.cc126
-rw-r--r--chrome/browser/dom_ui/new_tab_page_sync_handler.h9
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.cc17
3 files changed, 83 insertions, 69 deletions
diff --git a/chrome/browser/dom_ui/new_tab_page_sync_handler.cc b/chrome/browser/dom_ui/new_tab_page_sync_handler.cc
index 83bca5e..d903f28 100644
--- a/chrome/browser/dom_ui/new_tab_page_sync_handler.cc
+++ b/chrome/browser/dom_ui/new_tab_page_sync_handler.cc
@@ -20,10 +20,9 @@
#include "net/base/cookie_monster.h"
#include "net/url_request/url_request_context.h"
-// XPath expression for finding our p13n iframe.
-static const wchar_t* kP13nIframeXpath = L"//iframe[@id='p13n']";
-
-namespace Personalization {
+// TODO(idana): the following code was originally copied from
+// toolbar_importer.h/cc and it needs to be moved to a common Google Accounts
+// utility.
// A simple pair of fields that identify a set of Google cookies, used to
// filter from a larger set.
@@ -65,14 +64,13 @@ bool IsGoogleGAIACookieInstalled() {
return false;
}
-} // namespace Personalization
-
NewTabPageSyncHandler::NewTabPageSyncHandler() : sync_service_(NULL),
- waiting_for_initial_page_load_(true) {
+ waiting_for_initial_page_load_(true) {
}
NewTabPageSyncHandler::~NewTabPageSyncHandler() {
- sync_service_->RemoveObserver(this);
+ if (sync_service_)
+ sync_service_->RemoveObserver(this);
}
DOMMessageHandler* NewTabPageSyncHandler::Attach(DOMUI* dom_ui) {
@@ -87,32 +85,44 @@ void NewTabPageSyncHandler::RegisterMessages() {
NewCallback(this, &NewTabPageSyncHandler::HandleGetSyncMessage));
dom_ui_->RegisterMessageCallback("SyncLinkClicked",
NewCallback(this, &NewTabPageSyncHandler::HandleSyncLinkClicked));
- dom_ui_->RegisterMessageCallback("ResizeP13N",
- NewCallback(this, &NewTabPageSyncHandler::HandleResizeP13N));
}
-void NewTabPageSyncHandler::HandleResizeP13N(const Value* value) {
- // We just want to call back in to the new tab page on behalf of our
- // same-origin-policy crippled iframe, to tell it to resize the container.
- dom_ui_->CallJavascriptFunction(L"resizeP13N", *value);
+void NewTabPageSyncHandler::HandleGetSyncMessage(const Value* value) {
+ waiting_for_initial_page_load_ = false;
+ BuildAndSendSyncStatus();
+}
+
+void NewTabPageSyncHandler::HideSyncStatusSection() {
+ SendSyncMessageToPage(SyncStatusUIHelper::PRE_SYNCED, std::string(),
+ std::string());
}
void NewTabPageSyncHandler::BuildAndSendSyncStatus() {
DCHECK(!waiting_for_initial_page_load_);
+ // Hide the sync status section if sync is disabled entirely.
+ if (!sync_service_) {
+ HideSyncStatusSection();
+ return;
+ }
+
+ // We show the sync promotion if sync has not been enabled and the user is
+ // logged in to Google Accounts. If the user is not signed in to GA, we
+ // should hide the sync status section entirely.
if (!sync_service_->HasSyncSetupCompleted() &&
!sync_service_->SetupInProgress()) {
- // Clear the page status, without showing the promotion or sync ui.
- // TODO(timsteele): This is fine, but if the page is refreshed or another
- // NTP is opened, we could end up showing the promo again. Not sure this is
- // desired if the user already signed up once and disabled.
- FundamentalValue value(0);
- dom_ui_->CallJavascriptFunction(L"resizeP13N", value);
+ if (IsGoogleGAIACookieInstalled()) {
+ SendSyncMessageToPage(SyncStatusUIHelper::PRE_SYNCED, kSyncPromotionMsg,
+ kStartNowLinkText);
+ } else {
+ HideSyncStatusSection();
+ }
return;
}
- // There are currently three supported "sync statuses" for the NTP, from
- // the users perspective:
+ // Once sync has been enabled, the supported "sync statuses" for the NNTP
+ // from the user's perspective are:
+ //
// "Synced to foo@gmail.com", when we are successfully authenticated and
// connected to a sync server.
// "Sync error", when we can't authenticate or establish a connection with
@@ -126,29 +136,14 @@ void NewTabPageSyncHandler::BuildAndSendSyncStatus() {
SendSyncMessageToPage(type, WideToUTF8(status_msg), WideToUTF8(link_text));
}
-void NewTabPageSyncHandler::HandleGetSyncMessage(const Value* value) {
- waiting_for_initial_page_load_ = false;
-
- if (!sync_service_->HasSyncSetupCompleted() &&
- !sync_service_->SetupInProgress()) {
- if (Personalization::IsGoogleGAIACookieInstalled()) {
- // Sync has not been enabled, and the user has logged in to GAIA.
- SendSyncMessageToPage(SyncStatusUIHelper::PRE_SYNCED, kSyncPromotionMsg,
- kStartNowLinkText);
- }
- return;
- }
-
- BuildAndSendSyncStatus();
-}
-
void NewTabPageSyncHandler::HandleSyncLinkClicked(const Value* value) {
DCHECK(!waiting_for_initial_page_load_);
+ DCHECK(sync_service_);
if (sync_service_->HasSyncSetupCompleted()) {
- // User clicked 'Login again' link to re-authenticate.
+ // User clicked the 'Login again' link to re-authenticate.
sync_service_->ShowLoginDialog();
} else {
- // User clicked "Start now" link to begin syncing.
+ // User clicked the 'Start now' link to begin syncing.
ProfileSyncService::SyncEvent(ProfileSyncService::START_FROM_NTP);
sync_service_->EnableForUser();
}
@@ -163,16 +158,19 @@ void NewTabPageSyncHandler::OnStateChanged() {
void NewTabPageSyncHandler::SendSyncMessageToPage(
SyncStatusUIHelper::MessageType type, std::string msg,
- const std::string& linktext) {
+ std::string linktext) {
DictionaryValue value;
- std::string title, msgtype;
+ std::string msgtype;
+ std::string title = kSyncSectionTitle;
+ std::string linkurl;
switch (type) {
case SyncStatusUIHelper::PRE_SYNCED:
- title = kSyncSectionTitle;
msgtype = "presynced";
break;
case SyncStatusUIHelper::SYNCED:
msgtype = "synced";
+ linktext = kSyncViewOnlineLinkLabel;
+ linkurl = kSyncViewOnlineLinkUrl;
msg = msg.substr(0, msg.find(WideToUTF8(kLastSyncedLabel)));
break;
case SyncStatusUIHelper::SYNC_ERROR:
@@ -181,20 +179,34 @@ void NewTabPageSyncHandler::SendSyncMessageToPage(
break;
}
- value.SetString(L"title", title);
- value.SetString(L"msg", msg);
- value.SetString(L"msgtype", msgtype);
- if (!linktext.empty())
- value.SetString(L"linktext", linktext);
- else
- value.SetBoolean(L"linktext", false);
-
- std::string json;
- JSONWriter::Write(&value, false, &json);
- std::wstring javascript = std::wstring(L"renderSyncMessage") +
- L"(" + UTF8ToWide(json) + L");";
- RenderViewHost* rvh = dom_ui_->tab_contents()->render_view_host();
- rvh->ExecuteJavascriptInWebFrame(kP13nIframeXpath, javascript);
+ // If there is no message to show, we should hide the sync section
+ // altogether.
+ if (msg.empty()) {
+ value.SetBoolean(L"syncsectionisvisible", false);
+ } else {
+ value.SetBoolean(L"syncsectionisvisible", true);
+ value.SetString(L"msg", msg);
+ value.SetString(L"title", title);
+ value.SetString(L"msgtype", msgtype);
+ if (linktext.empty()) {
+ value.SetBoolean(L"linkisvisible", false);
+ } else {
+ value.SetBoolean(L"linkisvisible", true);
+ value.SetString(L"linktext", linktext);
+
+ // The only time we set the URL is when the user is synced and we need to
+ // show a link to a web interface (e.g. http://docs.google.com). When we
+ // set that URL, HandleSyncLinkClicked won't be called when the user
+ // clicks on the link.
+ if (linkurl.empty()) {
+ value.SetBoolean(L"linkurlisset", false);
+ } else {
+ value.SetBoolean(L"linkurlisset", true);
+ value.SetString(L"linkurl", linkurl);
+ }
+ }
+ }
+ dom_ui_->CallJavascriptFunction(L"syncMessageChanged", value);
}
#endif // CHROME_PERSONALIZATION
diff --git a/chrome/browser/dom_ui/new_tab_page_sync_handler.h b/chrome/browser/dom_ui/new_tab_page_sync_handler.h
index 2f50a2a..5931684 100644
--- a/chrome/browser/dom_ui/new_tab_page_sync_handler.h
+++ b/chrome/browser/dom_ui/new_tab_page_sync_handler.h
@@ -31,22 +31,23 @@ class NewTabPageSyncHandler : public DOMMessageHandler,
void HandleGetSyncMessage(const Value* value);
// Callback for "SyncLinkClicked".
void HandleSyncLinkClicked(const Value* value);
- // Callback for "ResizeP13N"
- void HandleResizeP13N(const Value* value);
// ProfileSyncServiceObserver
virtual void OnStateChanged();
private:
- // Helper to invoke |renderSyncMessage| JS function on the new tab page.
+ // Helper to invoke the |syncMessageChanged| JS function on the new tab page.
void SendSyncMessageToPage(SyncStatusUIHelper::MessageType type,
- std::string msg, const std::string& linktext);
+ std::string msg, std::string linktext);
// Helper to query the sync service and figure out what to send to
// the page, and send it via SendSyncMessageToPage.
// NOTE: precondition: sync must be enabled.
void BuildAndSendSyncStatus();
+ // Helper to send a message to the NNTP which hides the sync section.
+ void HideSyncStatusSection();
+
// Cached pointer to ProfileSyncService.
ProfileSyncService* sync_service_;
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc
index b3e246e..0504352 100644
--- a/chrome/browser/dom_ui/new_tab_ui.cc
+++ b/chrome/browser/dom_ui/new_tab_ui.cc
@@ -24,6 +24,7 @@
#include "chrome/browser/dom_ui/dom_ui_theme_source.h"
#include "chrome/browser/dom_ui/downloads_dom_handler.h"
#include "chrome/browser/dom_ui/history_ui.h"
+#include "chrome/browser/dom_ui/new_tab_page_sync_handler.h"
#include "chrome/browser/dom_ui/shown_sections_handler.h"
#include "chrome/browser/dom_ui/tips_handler.h"
#include "chrome/browser/history/page_usage_data.h"
@@ -36,9 +37,6 @@
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/sessions/tab_restore_service.h"
-#ifdef CHROME_PERSONALIZATION
-#include "chrome/browser/sync/personalization.h"
-#endif
#include "chrome/browser/user_data_manager.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/jstemplate_builder.h"
@@ -344,6 +342,13 @@ void NewTabHTMLSource::StartDataRequest(const std::string& path,
localized_strings.SetString(L"closefirstrunnotification",
l10n_util::GetString(IDS_NEW_TAB_CLOSE_FIRST_RUN_NOTIFICATION));
+ // Don't initiate the sync related message passing with the page if the sync
+ // code is not present.
+ if (profile_->GetProfileSyncService())
+ localized_strings.SetString(L"syncispresent", "true");
+ else
+ localized_strings.SetString(L"syncispresent", "false");
+
SetFontAndTextDirection(&localized_strings);
// Let the tab know whether it's the first tab being viewed.
@@ -356,10 +361,6 @@ void NewTabHTMLSource::StartDataRequest(const std::string& path,
Animation::ShouldRenderRichAnimation() ? L"true" : L"false";
localized_strings.SetString(L"anim", anim);
-#ifdef CHROME_PERSONALIZATION
- localized_strings.SetString(L"p13nsrc", Personalization::GetNewTabSource());
-#endif
-
// In case we have the new new tab page enabled we first try to read the file
// provided on the command line. If that fails we just get the resource from
// the resource bundle.
@@ -1552,7 +1553,7 @@ NewTabUI::NewTabUI(TabContents* contents)
#ifdef CHROME_PERSONALIZATION
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableSync)) {
- AddMessageHandler(Personalization::CreateNewTabPageHandler(this));
+ AddMessageHandler((new NewTabPageSyncHandler())->Attach(this));
}
#endif