Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/ui/webui/welcome_handler.cc

Issue 2338213007: Adding JS and C++ handlers for events on new Welcome page. (Closed)
Patch Set: Further comments from anthonyvd Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/welcome_handler.h"
6
7 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
8 #include "chrome/browser/signin/signin_manager_factory.h"
9 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/browser_navigator.h"
11 #include "chrome/browser/ui/profile_chooser_constants.h"
12 #include "chrome/common/url_constants.h"
13 #include "components/signin/core/browser/signin_manager.h"
14 #include "components/signin/core/browser/signin_metrics.h"
15 #include "ui/base/page_transition_types.h"
16
17 WelcomeHandler::WelcomeHandler(content::WebUI* web_ui)
18 : profile_(Profile::FromWebUI(web_ui)),
19 browser_(chrome::FindBrowserWithWebContents(web_ui->GetWebContents())),
20 oauth2_token_service_(
21 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)),
22 result_(WelcomeResult::DEFAULT) {
23 oauth2_token_service_->AddObserver(this);
michaelpg 2016/09/23 18:46:35 According to its comments, this service will be nu
tmartino 2016/09/26 23:10:15 Done. Added an early exit to welcome_ui.cc constru
24 }
25
26 WelcomeHandler::~WelcomeHandler() {
27 oauth2_token_service_->RemoveObserver(this);
28 // TODO(tmartino): Log to UMA according to WelcomeResult.
29 }
30
31 // Override from OAuth2TokenService::Observer. Occurs when a new auth token is
32 // available.
33 void WelcomeHandler::OnRefreshTokenAvailable(const std::string& account_id) {
34 result_ = WelcomeResult::SIGNED_IN;
35 GoToNewTabPage();
36 }
37
38 // Handles backend events necessary when user clicks "Sign in."
39 void WelcomeHandler::HandleActivateSignIn(const base::ListValue* args) {
40 if (SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()) {
41 // In general, this page isn't shown to signed-in users; however, if one
42 // should arrive here, then opening the sign-in dialog will likely lead
43 // to a crash. Thus, we just act like sign-in was "successful" and whisk
44 // them away to the NTP instead.
45 GoToNewTabPage();
46 } else {
47 browser_->ShowModalSigninWindow(
48 profiles::BubbleViewMode::BUBBLE_VIEW_MODE_GAIA_SIGNIN,
49 signin_metrics::AccessPoint::ACCESS_POINT_START_PAGE);
50 }
51 }
52
53 // Handles backend events necessary when user clicks "No thanks."
54 void WelcomeHandler::HandleUserDecline(const base::ListValue* args) {
55 result_ = WelcomeResult::DECLINED;
56 GoToNewTabPage();
57 }
58
59 // Override from WebUIMessageHandler.
60 void WelcomeHandler::RegisterMessages() {
61 web_ui()->RegisterMessageCallback(
62 "handleActivateSignIn", base::Bind(&WelcomeHandler::HandleActivateSignIn,
63 base::Unretained(this)));
64 web_ui()->RegisterMessageCallback(
65 "handleUserDecline",
66 base::Bind(&WelcomeHandler::HandleUserDecline, base::Unretained(this)));
67 }
68
69 void WelcomeHandler::GoToNewTabPage() {
70 chrome::NavigateParams params(browser_, GURL(chrome::kChromeUINewTabURL),
71 ui::PageTransition::PAGE_TRANSITION_LINK);
72 chrome::Navigate(&params);
73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698