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

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

Issue 14081014: Identity API: Change WebAuthFlow to use <webview> instead of a normal browser pop-up. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: chrome.identity side-by-side with chrome.experimental.identity Created 7 years, 7 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/experimental_identity_api.h" 5 #include "chrome/browser/extensions/api/identity/experimental_identity_api.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 error_ = identity_constants::kOffTheRecord; 262 error_ = identity_constants::kOffTheRecord;
263 return false; 263 return false;
264 } 264 }
265 265
266 scoped_ptr<identity_exp::LaunchWebAuthFlow::Params> params( 266 scoped_ptr<identity_exp::LaunchWebAuthFlow::Params> params(
267 identity_exp::LaunchWebAuthFlow::Params::Create(*args_)); 267 identity_exp::LaunchWebAuthFlow::Params::Create(*args_));
268 EXTENSION_FUNCTION_VALIDATE(params.get()); 268 EXTENSION_FUNCTION_VALIDATE(params.get());
269 const identity_exp::ExperimentalWebAuthFlowDetails& details = params->details; 269 const identity_exp::ExperimentalWebAuthFlowDetails& details = params->details;
270 270
271 GURL auth_url(params->details.url); 271 GURL auth_url(params->details.url);
272 WebAuthFlow::Mode mode = 272 ExperimentalWebAuthFlow::Mode mode =
273 params->details.interactive && *params->details.interactive ? 273 params->details.interactive && *params->details.interactive ?
274 WebAuthFlow::INTERACTIVE : WebAuthFlow::SILENT; 274 ExperimentalWebAuthFlow::INTERACTIVE : ExperimentalWebAuthFlow::SILENT;
275 275
276 // Set up acceptable target URLs. (Includes chrome-extension scheme 276 // Set up acceptable target URLs. (Includes chrome-extension scheme
277 // for this version of the API.) 277 // for this version of the API.)
278 InitFinalRedirectURLPrefixes(GetExtension()->id()); 278 InitFinalRedirectURLPrefixes(GetExtension()->id());
279 279
280 // The bounds attributes are optional, but using 0 when they're not available 280 // The bounds attributes are optional, but using 0 when they're not available
281 // does the right thing. 281 // does the right thing.
282 gfx::Rect initial_bounds; 282 gfx::Rect initial_bounds;
283 if (details.width) 283 if (details.width)
284 initial_bounds.set_width(*details.width); 284 initial_bounds.set_width(*details.width);
285 if (details.height) 285 if (details.height)
286 initial_bounds.set_height(*details.height); 286 initial_bounds.set_height(*details.height);
287 if (details.left) 287 if (details.left)
288 initial_bounds.set_x(*details.left); 288 initial_bounds.set_x(*details.left);
289 if (details.top) 289 if (details.top)
290 initial_bounds.set_y(*details.top); 290 initial_bounds.set_y(*details.top);
291 291
292 AddRef(); // Balanced in OnAuthFlowSuccess/Failure. 292 AddRef(); // Balanced in OnAuthFlowSuccess/Failure.
293 293
294 Browser* current_browser = this->GetCurrentBrowser(); 294 Browser* current_browser = this->GetCurrentBrowser();
295 chrome::HostDesktopType host_desktop_type = current_browser ? 295 chrome::HostDesktopType host_desktop_type = current_browser ?
296 current_browser->host_desktop_type() : chrome::GetActiveDesktop(); 296 current_browser->host_desktop_type() : chrome::GetActiveDesktop();
297 auth_flow_.reset(new WebAuthFlow( 297 auth_flow_.reset(new ExperimentalWebAuthFlow(
298 this, profile(), auth_url, mode, initial_bounds, 298 this, profile(), auth_url, mode, initial_bounds,
299 host_desktop_type)); 299 host_desktop_type));
300 auth_flow_->Start(); 300 auth_flow_->Start();
301 return true; 301 return true;
302 } 302 }
303 303
304 bool ExperimentalIdentityLaunchWebAuthFlowFunction::IsFinalRedirectURL( 304 bool ExperimentalIdentityLaunchWebAuthFlowFunction::IsFinalRedirectURL(
305 const GURL& url) const { 305 const GURL& url) const {
306 std::vector<GURL>::const_iterator iter; 306 std::vector<GURL>::const_iterator iter;
307 for (iter = final_prefixes_.begin(); iter != final_prefixes_.end(); ++iter) { 307 for (iter = final_prefixes_.begin(); iter != final_prefixes_.end(); ++iter) {
308 if (url.GetWithEmptyPath() == *iter) { 308 if (url.GetWithEmptyPath() == *iter) {
309 return true; 309 return true;
310 } 310 }
311 } 311 }
312 return false; 312 return false;
313 } 313 }
314 314
315 void ExperimentalIdentityLaunchWebAuthFlowFunction:: 315 void ExperimentalIdentityLaunchWebAuthFlowFunction::
316 InitFinalRedirectURLPrefixes(const std::string& extension_id) { 316 InitFinalRedirectURLPrefixes(const std::string& extension_id) {
317 final_prefixes_.push_back(Extension::GetBaseURLFromExtensionId(extension_id)); 317 final_prefixes_.push_back(Extension::GetBaseURLFromExtensionId(extension_id));
318 final_prefixes_.push_back(GURL(base::StringPrintf( 318 final_prefixes_.push_back(GURL(base::StringPrintf(
319 kChromiumDomainRedirectUrlPattern, extension_id.c_str()))); 319 kChromiumDomainRedirectUrlPattern, extension_id.c_str())));
320 } 320 }
321 321
322 void ExperimentalIdentityLaunchWebAuthFlowFunction::OnAuthFlowFailure( 322 void ExperimentalIdentityLaunchWebAuthFlowFunction::OnAuthFlowFailure(
323 WebAuthFlow::Failure failure) { 323 ExperimentalWebAuthFlow::Failure failure) {
324 switch (failure) { 324 switch (failure) {
325 case WebAuthFlow::WINDOW_CLOSED: 325 case ExperimentalWebAuthFlow::WINDOW_CLOSED:
326 error_ = identity_constants::kUserRejected; 326 error_ = identity_constants::kUserRejected;
327 break; 327 break;
328 case WebAuthFlow::INTERACTION_REQUIRED: 328 case ExperimentalWebAuthFlow::INTERACTION_REQUIRED:
329 error_ = identity_constants::kInteractionRequired; 329 error_ = identity_constants::kInteractionRequired;
330 break; 330 break;
331 default: 331 default:
332 NOTREACHED() << "Unexpected error from web auth flow: " << failure; 332 NOTREACHED() << "Unexpected error from web auth flow: " << failure;
333 error_ = identity_constants::kInvalidRedirect; 333 error_ = identity_constants::kInvalidRedirect;
334 break; 334 break;
335 } 335 }
336 SendResponse(false); 336 SendResponse(false);
337 Release(); // Balanced in RunImpl. 337 Release(); // Balanced in RunImpl.
338 } 338 }
339 339
340 void ExperimentalIdentityLaunchWebAuthFlowFunction::OnAuthFlowURLChange( 340 void ExperimentalIdentityLaunchWebAuthFlowFunction::OnAuthFlowURLChange(
341 const GURL& redirect_url) { 341 const GURL& redirect_url) {
342 if (IsFinalRedirectURL(redirect_url)) { 342 if (IsFinalRedirectURL(redirect_url)) {
343 SetResult(Value::CreateStringValue(redirect_url.spec())); 343 SetResult(Value::CreateStringValue(redirect_url.spec()));
344 SendResponse(true); 344 SendResponse(true);
345 Release(); // Balanced in RunImpl. 345 Release(); // Balanced in RunImpl.
346 } 346 }
347 } 347 }
348 348
349 void ExperimentalIdentityLaunchWebAuthFlowFunction:: 349 void ExperimentalIdentityLaunchWebAuthFlowFunction::
350 InitFinalRedirectURLPrefixesForTest(const std::string& extension_id) { 350 InitFinalRedirectURLPrefixesForTest(const std::string& extension_id) {
351 final_prefixes_.clear(); 351 final_prefixes_.clear();
352 InitFinalRedirectURLPrefixes(extension_id); 352 InitFinalRedirectURLPrefixes(extension_id);
353 } 353 }
354 354
355 } // namespace extensions 355 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698