Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/history_login_handler.h" | 5 #include "chrome/browser/ui/webui/history_login_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_finder.h" | 12 #include "chrome/browser/ui/browser_finder.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
| 14 #include "chrome/browser/ui/webui/md_history_ui.cc" | |
|
Dan Beam
2016/09/22 18:18:52
whoa whoa whoa, don't include a .cc
Dan Beam
2016/09/22 18:19:26
i accidentally did this the other day, btw, and it
lshang
2016/09/23 02:00:01
Definitely a typo! (o_O)!
| |
| 14 #include "chrome/browser/ui/webui/profile_info_watcher.h" | 15 #include "chrome/browser/ui/webui/profile_info_watcher.h" |
| 15 #include "components/signin/core/browser/signin_metrics.h" | 16 #include "components/signin/core/browser/signin_metrics.h" |
| 16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/browser/web_ui.h" | 18 #include "content/public/browser/web_ui.h" |
| 19 #include "content/public/browser/web_ui_data_source.h" | |
| 18 | 20 |
| 19 HistoryLoginHandler::HistoryLoginHandler() {} | 21 HistoryLoginHandler::HistoryLoginHandler() {} |
| 20 HistoryLoginHandler::~HistoryLoginHandler() {} | 22 HistoryLoginHandler::~HistoryLoginHandler() {} |
| 21 | 23 |
| 22 void HistoryLoginHandler::RegisterMessages() { | 24 void HistoryLoginHandler::RegisterMessages() { |
| 23 profile_info_watcher_.reset(new ProfileInfoWatcher( | 25 profile_info_watcher_.reset(new ProfileInfoWatcher( |
| 24 Profile::FromWebUI(web_ui()), | 26 Profile::FromWebUI(web_ui()), |
| 25 base::Bind(&HistoryLoginHandler::ProfileInfoChanged, | 27 base::Bind(&HistoryLoginHandler::ProfileInfoChanged, |
| 26 base::Unretained(this)))); | 28 base::Unretained(this)))); |
| 27 | 29 |
| 28 web_ui()->RegisterMessageCallback("otherDevicesInitialized", | 30 web_ui()->RegisterMessageCallback("otherDevicesInitialized", |
| 29 base::Bind(&HistoryLoginHandler::HandleOtherDevicesInitialized, | 31 base::Bind(&HistoryLoginHandler::HandleOtherDevicesInitialized, |
| 30 base::Unretained(this))); | 32 base::Unretained(this))); |
| 31 | 33 |
| 32 web_ui()->RegisterMessageCallback("startSignInFlow", | 34 web_ui()->RegisterMessageCallback("startSignInFlow", |
| 33 base::Bind(&HistoryLoginHandler::HandleStartSignInFlow, | 35 base::Bind(&HistoryLoginHandler::HandleStartSignInFlow, |
| 34 base::Unretained(this))); | 36 base::Unretained(this))); |
| 35 } | 37 } |
| 36 | 38 |
| 37 void HistoryLoginHandler::HandleOtherDevicesInitialized( | 39 void HistoryLoginHandler::HandleOtherDevicesInitialized( |
| 38 const base::ListValue* /*args*/) { | 40 const base::ListValue* /*args*/) { |
| 39 ProfileInfoChanged(); | 41 ProfileInfoChanged(); |
| 40 } | 42 } |
| 41 | 43 |
| 42 void HistoryLoginHandler::ProfileInfoChanged() { | 44 void HistoryLoginHandler::ProfileInfoChanged() { |
| 43 bool signed_in = !profile_info_watcher_->GetAuthenticatedUsername().empty(); | 45 bool signed_in = !profile_info_watcher_->GetAuthenticatedUsername().empty(); |
| 46 | |
| 47 // Update sign in state in data source so that LoadTimeData() returns updated | |
| 48 // value on page reload. | |
| 49 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 50 content::WebUIDataSource* data_source = CreateMdHistoryUIHTMLSource(profile); | |
|
Dan Beam
2016/09/22 18:18:53
CreateMdHistoryUIHTMLSource is private to the .cc
lshang
2016/09/23 02:00:01
Done. Removed changes in this file.
| |
| 51 content::WebUIDataSource::Add(profile, data_source); | |
| 52 data_source->AddBoolean("isUserSignedIn", signed_in); | |
| 53 | |
| 44 web_ui()->CallJavascriptFunctionUnsafe("updateSignInState", | 54 web_ui()->CallJavascriptFunctionUnsafe("updateSignInState", |
|
calamity
2016/09/22 08:16:28
Can we just update what we need to with this updat
Dan Beam
2016/09/22 18:18:52
yes, it's safe (AFAIK) to just call
data_source
lshang
2016/09/23 02:00:01
Yeah we should register a new message callback to
| |
| 45 base::FundamentalValue(signed_in)); | 55 base::FundamentalValue(signed_in)); |
| 46 } | 56 } |
| 47 | 57 |
| 48 void HistoryLoginHandler::HandleStartSignInFlow( | 58 void HistoryLoginHandler::HandleStartSignInFlow( |
| 49 const base::ListValue* /*args*/) { | 59 const base::ListValue* /*args*/) { |
| 50 Browser* browser = | 60 Browser* browser = |
| 51 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); | 61 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); |
| 52 browser->window()->ShowAvatarBubbleFromAvatarButton( | 62 browser->window()->ShowAvatarBubbleFromAvatarButton( |
| 53 BrowserWindow::AVATAR_BUBBLE_MODE_SIGNIN, | 63 BrowserWindow::AVATAR_BUBBLE_MODE_SIGNIN, |
| 54 signin::ManageAccountsParams(), | 64 signin::ManageAccountsParams(), |
| 55 signin_metrics::AccessPoint::ACCESS_POINT_RECENT_TABS); | 65 signin_metrics::AccessPoint::ACCESS_POINT_RECENT_TABS); |
| 56 } | 66 } |
| OLD | NEW |