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

Unified Diff: chrome/browser/extensions/api/identity/identity_launch_web_auth_flow_function.cc

Issue 2654023005: Move impl of identity.LaunchWebAuthFlow() extension API to its own file (Closed)
Patch Set: Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/api/identity/identity_launch_web_auth_flow_function.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/identity/identity_launch_web_auth_flow_function.cc
diff --git a/chrome/browser/extensions/api/identity/identity_launch_web_auth_flow_function.cc b/chrome/browser/extensions/api/identity/identity_launch_web_auth_flow_function.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ca9beb7a86b2ea4a15d9cdca3d15800c56cd5115
--- /dev/null
+++ b/chrome/browser/extensions/api/identity/identity_launch_web_auth_flow_function.cc
@@ -0,0 +1,102 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/identity/identity_launch_web_auth_flow_function.h"
+
+#include "chrome/browser/extensions/api/identity/identity_api.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/extensions/api/identity.h"
+
+namespace extensions {
+
+namespace {
+
+static const char kChromiumDomainRedirectUrlPattern[] =
+ "https://%s.chromiumapp.org/";
+
+} // namespace
+
+namespace identity = api::identity;
+
+IdentityLaunchWebAuthFlowFunction::IdentityLaunchWebAuthFlowFunction() {}
+
+IdentityLaunchWebAuthFlowFunction::~IdentityLaunchWebAuthFlowFunction() {
+ if (auth_flow_)
+ auth_flow_.release()->DetachDelegateAndDelete();
+}
+
+bool IdentityLaunchWebAuthFlowFunction::RunAsync() {
+ if (GetProfile()->IsOffTheRecord()) {
+ error_ = identity_constants::kOffTheRecord;
+ return false;
+ }
+
+ std::unique_ptr<identity::LaunchWebAuthFlow::Params> params(
+ identity::LaunchWebAuthFlow::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ GURL auth_url(params->details.url);
+ WebAuthFlow::Mode mode =
+ params->details.interactive && *params->details.interactive ?
+ WebAuthFlow::INTERACTIVE : WebAuthFlow::SILENT;
+
+ // Set up acceptable target URLs. (Does not include chrome-extension
+ // scheme for this version of the API.)
+ InitFinalRedirectURLPrefix(extension()->id());
+
+ AddRef(); // Balanced in OnAuthFlowSuccess/Failure.
+
+ auth_flow_.reset(new WebAuthFlow(this, GetProfile(), auth_url, mode));
+ auth_flow_->Start();
+ return true;
+}
+
+void IdentityLaunchWebAuthFlowFunction::InitFinalRedirectURLPrefixForTest(
+ const std::string& extension_id) {
+ InitFinalRedirectURLPrefix(extension_id);
+}
+
+void IdentityLaunchWebAuthFlowFunction::InitFinalRedirectURLPrefix(
+ const std::string& extension_id) {
+ if (final_url_prefix_.is_empty()) {
+ final_url_prefix_ = GURL(base::StringPrintf(
+ kChromiumDomainRedirectUrlPattern, extension_id.c_str()));
+ }
+}
+
+void IdentityLaunchWebAuthFlowFunction::OnAuthFlowFailure(
+ WebAuthFlow::Failure failure) {
+ switch (failure) {
+ case WebAuthFlow::WINDOW_CLOSED:
+ error_ = identity_constants::kUserRejected;
+ break;
+ case WebAuthFlow::INTERACTION_REQUIRED:
+ error_ = identity_constants::kInteractionRequired;
+ break;
+ case WebAuthFlow::LOAD_FAILED:
+ error_ = identity_constants::kPageLoadFailure;
+ break;
+ default:
+ NOTREACHED() << "Unexpected error from web auth flow: " << failure;
+ error_ = identity_constants::kInvalidRedirect;
+ break;
+ }
+ SendResponse(false);
+ if (auth_flow_)
+ auth_flow_.release()->DetachDelegateAndDelete();
+ Release(); // Balanced in RunAsync.
+}
+
+void IdentityLaunchWebAuthFlowFunction::OnAuthFlowURLChange(
+ const GURL& redirect_url) {
+ if (redirect_url.GetWithEmptyPath() == final_url_prefix_) {
+ SetResult(base::MakeUnique<base::StringValue>(redirect_url.spec()));
+ SendResponse(true);
+ if (auth_flow_)
+ auth_flow_.release()->DetachDelegateAndDelete();
+ Release(); // Balanced in RunAsync.
+ }
+}
+
+} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/api/identity/identity_launch_web_auth_flow_function.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698