OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" | 5 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/string_split.h" | 11 #include "base/string_split.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/net/chrome_url_request_context.h" | 15 #include "chrome/browser/net/chrome_url_request_context.h" |
| 16 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/pref_names.h" |
17 #include "content/browser/renderer_host/render_view_host.h" | 19 #include "content/browser/renderer_host/render_view_host.h" |
18 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
19 #include "net/base/cookie_monster.h" | 21 #include "net/base/cookie_monster.h" |
20 #include "net/url_request/url_request_context.h" | 22 #include "net/url_request/url_request_context.h" |
21 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
22 | 24 |
23 // Default URL for the sync web interface. | 25 // Default URL for the sync web interface. |
24 // | 26 // |
25 // TODO(idana): when we figure out how we are going to allow third parties to | 27 // TODO(idana): when we figure out how we are going to allow third parties to |
26 // plug in their own sync engine, we should allow this value to be | 28 // plug in their own sync engine, we should allow this value to be |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 UTF16ToUTF8(status_msg), UTF16ToUTF8(link_text)); | 110 UTF16ToUTF8(status_msg), UTF16ToUTF8(link_text)); |
109 } | 111 } |
110 | 112 |
111 void NewTabPageSyncHandler::HandleSyncLinkClicked(const ListValue* args) { | 113 void NewTabPageSyncHandler::HandleSyncLinkClicked(const ListValue* args) { |
112 DCHECK(!waiting_for_initial_page_load_); | 114 DCHECK(!waiting_for_initial_page_load_); |
113 DCHECK(sync_service_); | 115 DCHECK(sync_service_); |
114 if (!sync_service_->IsSyncEnabled()) | 116 if (!sync_service_->IsSyncEnabled()) |
115 return; | 117 return; |
116 if (sync_service_->HasSyncSetupCompleted()) { | 118 if (sync_service_->HasSyncSetupCompleted()) { |
117 sync_service_->ShowErrorUI(); | 119 sync_service_->ShowErrorUI(); |
| 120 string16 user = UTF8ToUTF16(sync_service_->profile()->GetPrefs()->GetString( |
| 121 prefs::kGoogleServicesUsername)); |
118 DictionaryValue value; | 122 DictionaryValue value; |
119 value.SetString("syncEnabledMessage", | 123 value.SetString("syncEnabledMessage", |
120 l10n_util::GetStringFUTF16(IDS_SYNC_NTP_SYNCED_TO, | 124 l10n_util::GetStringFUTF16(IDS_SYNC_NTP_SYNCED_TO, |
121 sync_service_->GetAuthenticatedUsername())); | 125 user)); |
122 web_ui_->CallJavascriptFunction("syncAlreadyEnabled", value); | 126 web_ui_->CallJavascriptFunction("syncAlreadyEnabled", value); |
123 } else { | 127 } else { |
124 // User clicked the 'Start now' link to begin syncing. | 128 // User clicked the 'Start now' link to begin syncing. |
125 ProfileSyncService::SyncEvent(ProfileSyncService::START_FROM_NTP); | 129 ProfileSyncService::SyncEvent(ProfileSyncService::START_FROM_NTP); |
126 sync_service_->ShowLoginDialog(); | 130 sync_service_->ShowLoginDialog(); |
127 } | 131 } |
128 } | 132 } |
129 | 133 |
130 void NewTabPageSyncHandler::OnStateChanged() { | 134 void NewTabPageSyncHandler::OnStateChanged() { |
131 // Don't do anything if the page has not yet loaded. | 135 // Don't do anything if the page has not yet loaded. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 if (linkurl.empty()) { | 173 if (linkurl.empty()) { |
170 value.SetBoolean("linkurlisset", false); | 174 value.SetBoolean("linkurlisset", false); |
171 } else { | 175 } else { |
172 value.SetBoolean("linkurlisset", true); | 176 value.SetBoolean("linkurlisset", true); |
173 value.SetString("linkurl", linkurl); | 177 value.SetString("linkurl", linkurl); |
174 } | 178 } |
175 } | 179 } |
176 } | 180 } |
177 web_ui_->CallJavascriptFunction("syncMessageChanged", value); | 181 web_ui_->CallJavascriptFunction("syncMessageChanged", value); |
178 } | 182 } |
OLD | NEW |