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

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: Forward Declarations 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/profiles/profile.h"
8 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
9 #include "chrome/browser/signin/signin_manager_factory.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/browser_navigator.h"
13 #include "chrome/browser/ui/profile_chooser_constants.h"
14 #include "chrome/common/url_constants.h"
15 #include "components/signin/core/browser/signin_manager.h"
16 #include "components/signin/core/browser/signin_metrics.h"
17 #include "ui/base/page_transition_types.h"
18
19 WelcomeHandler::WelcomeHandler(content::WebUI* web_ui)
20 : profile_(Profile::FromWebUI(web_ui)),
21 browser_(chrome::FindBrowserWithWebContents(web_ui->GetWebContents())),
22 oauth2_token_service_(
23 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)),
24 result_(WelcomeResult::DEFAULT) {
25 oauth2_token_service_->AddObserver(this);
26 }
27
28 WelcomeHandler::~WelcomeHandler() {
29 oauth2_token_service_->RemoveObserver(this);
30 // TODO(tmartino): Log to UMA according to WelcomeResult.
31 }
32
33 // Override from OAuth2TokenService::Observer. Occurs when a new auth token is
34 // available.
35 void WelcomeHandler::OnRefreshTokenAvailable(const std::string& account_id) {
36 result_ = WelcomeResult::SIGNED_IN;
37 GoToNewTabPage();
38 }
39
40 // Handles backend events necessary when user clicks "Sign in."
41 void WelcomeHandler::HandleActivateSignIn(const base::ListValue* args) {
42 if (SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()) {
43 // In general, this page isn't shown to signed-in users; however, if one
44 // should arrive here, then opening the sign-in dialog will likely lead
45 // to a crash. Thus, we just act like sign-in was "successful" and whisk
46 // them away to the NTP instead.
47 GoToNewTabPage();
48 } else {
49 browser_->ShowModalSigninWindow(
50 profiles::BubbleViewMode::BUBBLE_VIEW_MODE_GAIA_SIGNIN,
51 signin_metrics::AccessPoint::ACCESS_POINT_START_PAGE);
52 }
53 }
54
55 // Handles backend events necessary when user clicks "No thanks."
56 void WelcomeHandler::HandleUserDecline(const base::ListValue* args) {
57 result_ = WelcomeResult::DECLINED;
58 GoToNewTabPage();
59 }
60
61 // Override from WebUIMessageHandler.
62 void WelcomeHandler::RegisterMessages() {
63 web_ui()->RegisterMessageCallback(
64 "handleActivateSignIn", base::Bind(&WelcomeHandler::HandleActivateSignIn,
65 base::Unretained(this)));
66 web_ui()->RegisterMessageCallback(
67 "handleUserDecline",
68 base::Bind(&WelcomeHandler::HandleUserDecline, base::Unretained(this)));
69 }
70
71 void WelcomeHandler::GoToNewTabPage() {
72 chrome::NavigateParams params(browser_, GURL(chrome::kChromeUINewTabURL),
73 ui::PageTransition::PAGE_TRANSITION_LINK);
74 chrome::Navigate(&params);
75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698