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

Side by Side Diff: chrome/browser/extensions/api/identity/gaia_web_auth_flow.cc

Issue 15897006: Identity API: switch WebAuthFlow dialog to component app (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase to ToT Created 7 years, 6 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/extensions/api/identity/gaia_web_auth_flow.h" 5 #include "chrome/browser/extensions/api/identity/gaia_web_auth_flow.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
11 #include "google_apis/gaia/gaia_urls.h" 11 #include "google_apis/gaia/gaia_urls.h"
12 #include "net/base/escape.h" 12 #include "net/base/escape.h"
13 13
14 namespace extensions { 14 namespace extensions {
15 15
16 GaiaWebAuthFlow::GaiaWebAuthFlow(Delegate* delegate, 16 GaiaWebAuthFlow::GaiaWebAuthFlow(Delegate* delegate,
17 Profile* profile, 17 Profile* profile,
18 chrome::HostDesktopType host_desktop_type,
19 const std::string& extension_id, 18 const std::string& extension_id,
20 const OAuth2Info& oauth2_info) 19 const OAuth2Info& oauth2_info)
21 : delegate_(delegate), 20 : delegate_(delegate),
22 profile_(profile), 21 profile_(profile) {
23 host_desktop_type_(host_desktop_type) {
24 const char kOAuth2RedirectPathFormat[] = "/%s#"; 22 const char kOAuth2RedirectPathFormat[] = "/%s#";
25 const char kOAuth2AuthorizeFormat[] = 23 const char kOAuth2AuthorizeFormat[] =
26 "%s?response_type=token&approval_prompt=force&authuser=0&" 24 "%s?response_type=token&approval_prompt=force&authuser=0&"
27 "client_id=%s&" 25 "client_id=%s&"
28 "scope=%s&" 26 "scope=%s&"
29 "origin=chrome-extension://%s/&" 27 "origin=chrome-extension://%s/&"
30 "redirect_uri=%s:/%s"; 28 "redirect_uri=%s:/%s";
31 29
32 std::vector<std::string> client_id_parts; 30 std::vector<std::string> client_id_parts;
33 base::SplitString(oauth2_info.client_id, '.', &client_id_parts); 31 base::SplitString(oauth2_info.client_id, '.', &client_id_parts);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 web_flow_ = CreateWebAuthFlow(merge_url); 70 web_flow_ = CreateWebAuthFlow(merge_url);
73 web_flow_->Start(); 71 web_flow_->Start();
74 } 72 }
75 73
76 void GaiaWebAuthFlow::OnUbertokenFailure(const GoogleServiceAuthError& error) { 74 void GaiaWebAuthFlow::OnUbertokenFailure(const GoogleServiceAuthError& error) {
77 delegate_->OnGaiaFlowFailure( 75 delegate_->OnGaiaFlowFailure(
78 GaiaWebAuthFlow::SERVICE_AUTH_ERROR, error, std::string()); 76 GaiaWebAuthFlow::SERVICE_AUTH_ERROR, error, std::string());
79 } 77 }
80 78
81 void GaiaWebAuthFlow::OnAuthFlowFailure(WebAuthFlow::Failure failure) { 79 void GaiaWebAuthFlow::OnAuthFlowFailure(WebAuthFlow::Failure failure) {
82 DCHECK(failure == WebAuthFlow::WINDOW_CLOSED); 80 GaiaWebAuthFlow::Failure gaia_failure;
81
82 switch (failure) {
83 case WebAuthFlow::WINDOW_CLOSED:
84 gaia_failure = GaiaWebAuthFlow::WINDOW_CLOSED;
85 break;
86 case WebAuthFlow::LOAD_FAILED:
87 gaia_failure = GaiaWebAuthFlow::LOAD_FAILED;
88 break;
89 default:
90 NOTREACHED() << "Unexpected error from web auth flow: " << failure;
91 gaia_failure = GaiaWebAuthFlow::LOAD_FAILED;
92 break;
93 }
94
83 delegate_->OnGaiaFlowFailure( 95 delegate_->OnGaiaFlowFailure(
84 GaiaWebAuthFlow::WINDOW_CLOSED, 96 gaia_failure,
85 GoogleServiceAuthError(GoogleServiceAuthError::NONE), 97 GoogleServiceAuthError(GoogleServiceAuthError::NONE),
86 std::string()); 98 std::string());
87 } 99 }
88 100
89 void GaiaWebAuthFlow::OnAuthFlowURLChange(const GURL& url) { 101 void GaiaWebAuthFlow::OnAuthFlowURLChange(const GURL& url) {
90 const char kOAuth2RedirectAccessTokenKey[] = "access_token"; 102 const char kOAuth2RedirectAccessTokenKey[] = "access_token";
91 const char kOAuth2RedirectErrorKey[] = "error"; 103 const char kOAuth2RedirectErrorKey[] = "error";
92 const char kOAuth2ExpiresInKey[] = "expires_in"; 104 const char kOAuth2ExpiresInKey[] = "expires_in";
93 105
94 // The format of the target URL is: 106 // The format of the target URL is:
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 std::string prefix(kRedirectPrefix); 156 std::string prefix(kRedirectPrefix);
145 157
146 if (StartsWithASCII(title, prefix, true)) { 158 if (StartsWithASCII(title, prefix, true)) {
147 GURL url(title.substr(prefix.length(), std::string::npos)); 159 GURL url(title.substr(prefix.length(), std::string::npos));
148 if (url.is_valid()) 160 if (url.is_valid())
149 OnAuthFlowURLChange(url); 161 OnAuthFlowURLChange(url);
150 } 162 }
151 } 163 }
152 164
153 scoped_ptr<WebAuthFlow> GaiaWebAuthFlow::CreateWebAuthFlow(GURL url) { 165 scoped_ptr<WebAuthFlow> GaiaWebAuthFlow::CreateWebAuthFlow(GURL url) {
154 gfx::Rect initial_bounds;
155 return scoped_ptr<WebAuthFlow>(new WebAuthFlow(this, 166 return scoped_ptr<WebAuthFlow>(new WebAuthFlow(this,
156 profile_, 167 profile_,
157 url, 168 url,
158 WebAuthFlow::INTERACTIVE, 169 WebAuthFlow::INTERACTIVE));
159 initial_bounds,
160 host_desktop_type_));
161 } 170 }
162 171
163 } // extensions 172 } // extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698