summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r--chrome/browser/dom_ui/foreign_session_handler.cc63
-rw-r--r--chrome/browser/dom_ui/foreign_session_handler.h3
-rw-r--r--chrome/browser/dom_ui/ntp_resource_cache.cc2
-rw-r--r--chrome/browser/dom_ui/options/sync_options_handler.cc2
4 files changed, 47 insertions, 23 deletions
diff --git a/chrome/browser/dom_ui/foreign_session_handler.cc b/chrome/browser/dom_ui/foreign_session_handler.cc
index a341f47..e35d8e5 100644
--- a/chrome/browser/dom_ui/foreign_session_handler.cc
+++ b/chrome/browser/dom_ui/foreign_session_handler.cc
@@ -35,24 +35,30 @@ void ForeignSessionHandler::RegisterMessages() {
void ForeignSessionHandler::Init() {
registrar_.Add(this, NotificationType::SYNC_CONFIGURE_DONE,
- NotificationService::AllSources());
+ NotificationService::AllSources());
registrar_.Add(this, NotificationType::FOREIGN_SESSION_UPDATED,
- NotificationService::AllSources());
- registrar_.Add(this, NotificationType::FOREIGN_SESSION_DELETED,
- NotificationService::AllSources());
+ NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::FOREIGN_SESSION_DISABLED,
+ NotificationService::AllSources());
}
void ForeignSessionHandler::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
- if (type != NotificationType::SYNC_CONFIGURE_DONE &&
- type != NotificationType::FOREIGN_SESSION_UPDATED &&
- type != NotificationType::FOREIGN_SESSION_DELETED) {
- NOTREACHED();
- return;
- }
ListValue list_value;
- HandleGetForeignSessions(&list_value);
+ switch (type.value) {
+ case NotificationType::SYNC_CONFIGURE_DONE:
+ case NotificationType::FOREIGN_SESSION_UPDATED:
+ HandleGetForeignSessions(&list_value);
+ break;
+ case NotificationType::FOREIGN_SESSION_DISABLED:
+ // Calling foreignSessions with empty list will automatically hide
+ // foreign session section.
+ dom_ui_->CallJavascriptFunction(L"foreignSessions", list_value);
+ break;
+ default:
+ NOTREACHED();
+ }
}
SessionModelAssociator* ForeignSessionHandler::GetModelAssociator() {
@@ -106,36 +112,49 @@ void ForeignSessionHandler::OpenForeignSession(
void ForeignSessionHandler::GetForeignSessions(
SessionModelAssociator* associator) {
- ScopedVector<ForeignSession> windows;
- associator->GetSessionDataFromSyncModel(&windows.get());
+ ScopedVector<ForeignSession> clients;
+ if (!associator->GetSessionData(&clients.get())) {
+ LOG(ERROR) << "ForeignSessionHandler failed to get session data from"
+ "SessionModelAssociator.";
+ return;
+ }
int added_count = 0;
- ListValue list_value;
+ ListValue client_list;
for (std::vector<ForeignSession*>::const_iterator i =
- windows.begin(); i != windows.end() &&
+ clients->begin(); i != clients->end() &&
added_count < kMaxSessionsToShow; ++i) {
ForeignSession* foreign_session = *i;
std::vector<TabRestoreService::Entry*> entries;
dom_ui_->GetProfile()->GetTabRestoreService()->CreateEntriesFromWindows(
&foreign_session->windows, &entries);
+ scoped_ptr<ListValue> window_list(new ListValue());
for (std::vector<TabRestoreService::Entry*>::const_iterator it =
entries.begin(); it != entries.end(); ++it) {
TabRestoreService::Entry* entry = *it;
- scoped_ptr<DictionaryValue> value(new DictionaryValue());
+ scoped_ptr<DictionaryValue> window_data(new DictionaryValue());
if (entry->type == TabRestoreService::WINDOW &&
ValueHelper::WindowToValue(
- *static_cast<TabRestoreService::Window*>(entry), value.get())) {
+ *static_cast<TabRestoreService::Window*>(entry),
+ window_data.get())) {
// The javascript checks if the session id is a valid session id,
// when rendering session information to the new tab page, and it
// sends the sessionTag back when we need to restore a session.
- value->SetString("sessionTag", foreign_session->foreign_tession_tag);
- value->SetInteger("sessionId", entry->id);
- list_value.Append(value.release()); // Give ownership to |list_value|.
+
+ // TODO(zea): sessionTag is per client, it might be better per window.
+ window_data->SetString("sessionTag",
+ foreign_session->foreign_tession_tag);
+ window_data->SetInteger("sessionId", entry->id);
+
+ // Give ownership to |list_value|.
+ window_list->Append(window_data.release());
}
}
added_count++;
+
+ // Give ownership to |client_list|
+ client_list.Append(window_list.release());
}
- dom_ui_->CallJavascriptFunction(L"foreignSessions", list_value);
+ dom_ui_->CallJavascriptFunction(L"foreignSessions", client_list);
}
} // namespace browser_sync
-
diff --git a/chrome/browser/dom_ui/foreign_session_handler.h b/chrome/browser/dom_ui/foreign_session_handler.h
index 1c4751d..6532205 100644
--- a/chrome/browser/dom_ui/foreign_session_handler.h
+++ b/chrome/browser/dom_ui/foreign_session_handler.h
@@ -6,6 +6,8 @@
#define CHROME_BROWSER_DOM_UI_FOREIGN_SESSION_HANDLER_H_
#pragma once
+#include <vector>
+
#include "chrome/browser/dom_ui/dom_ui.h"
#include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sync/glue/session_model_associator.h"
@@ -59,4 +61,3 @@ class ForeignSessionHandler : public DOMMessageHandler,
} // namespace browser_sync
#endif // CHROME_BROWSER_DOM_UI_FOREIGN_SESSION_HANDLER_H_
-
diff --git a/chrome/browser/dom_ui/ntp_resource_cache.cc b/chrome/browser/dom_ui/ntp_resource_cache.cc
index dca2917..c2e7add 100644
--- a/chrome/browser/dom_ui/ntp_resource_cache.cc
+++ b/chrome/browser/dom_ui/ntp_resource_cache.cc
@@ -245,6 +245,8 @@ void NTPResourceCache::CreateNewTabHTML() {
l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED));
localized_strings.SetString("closedwindowsingle",
l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_SINGLE));
+ localized_strings.SetString("foreignsessions",
+ l10n_util::GetStringUTF16(IDS_SYNC_DATATYPE_SESSIONS));
localized_strings.SetString("closedwindowmultiple",
l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_MULTIPLE));
localized_strings.SetString("attributionintro",
diff --git a/chrome/browser/dom_ui/options/sync_options_handler.cc b/chrome/browser/dom_ui/options/sync_options_handler.cc
index 7c19a59..de6c5bf 100644
--- a/chrome/browser/dom_ui/options/sync_options_handler.cc
+++ b/chrome/browser/dom_ui/options/sync_options_handler.cc
@@ -52,6 +52,8 @@ void SyncOptionsHandler::GetLocalizedValues(
l10n_util::GetStringUTF16(IDS_SYNC_DATATYPE_THEMES));
localized_strings->SetString("syncapps",
l10n_util::GetStringUTF16(IDS_SYNC_DATATYPE_APPS));
+ localized_strings->SetString("syncsessions",
+ l10n_util::GetStringUTF16(IDS_SYNC_DATATYPE_SESSIONS));
}
void SyncOptionsHandler::Initialize() {