OLD | NEW |
---|---|
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/identity_api.h" | 5 #include "chrome/browser/extensions/api/identity/identity_api.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 8 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
9 #include "chrome/browser/signin/token_service.h" | 9 #include "chrome/browser/signin/token_service.h" |
10 #include "chrome/browser/signin/token_service_factory.h" | 10 #include "chrome/browser/signin/token_service_factory.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 | 15 |
16 namespace extensions { | 16 namespace extensions { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 const char kInvalidClientId[] = "Invalid OAuth2 Client ID."; | 20 const char kInvalidClientId[] = "Invalid OAuth2 Client ID."; |
21 const char kInvalidScopes[] = "Invalid OAuth2 scopes."; | 21 const char kInvalidScopes[] = "Invalid OAuth2 scopes."; |
22 const char kUrlFieldRequired[] = "Missing required field: url"; | |
23 const char kInvalidRedirect[] = "Did not redirect to the right URL."; | |
22 | 24 |
23 } // namespace | 25 } // namespace |
24 | 26 |
25 GetAuthTokenFunction::GetAuthTokenFunction() {} | 27 GetAuthTokenFunction::GetAuthTokenFunction() {} |
26 GetAuthTokenFunction::~GetAuthTokenFunction() {} | 28 GetAuthTokenFunction::~GetAuthTokenFunction() {} |
27 | 29 |
28 bool GetAuthTokenFunction::RunImpl() { | 30 bool GetAuthTokenFunction::RunImpl() { |
29 const Extension* extension = GetExtension(); | 31 const Extension* extension = GetExtension(); |
30 Extension::OAuth2Info oauth2_info = extension->oauth2_info(); | 32 Extension::OAuth2Info oauth2_info = extension->oauth2_info(); |
31 | 33 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 Release(); // Balanced in RunImpl. | 65 Release(); // Balanced in RunImpl. |
64 } | 66 } |
65 | 67 |
66 void GetAuthTokenFunction::OnMintTokenFailure( | 68 void GetAuthTokenFunction::OnMintTokenFailure( |
67 const GoogleServiceAuthError& error) { | 69 const GoogleServiceAuthError& error) { |
68 error_ = error.ToString(); | 70 error_ = error.ToString(); |
69 SendResponse(false); | 71 SendResponse(false); |
70 Release(); // Balanced in RunImpl. | 72 Release(); // Balanced in RunImpl. |
71 } | 73 } |
72 | 74 |
75 LaunchWebAuthFlowFunction::LaunchWebAuthFlowFunction() {} | |
76 LaunchWebAuthFlowFunction::~LaunchWebAuthFlowFunction() {} | |
77 | |
78 bool LaunchWebAuthFlowFunction::RunImpl() { | |
79 DictionaryValue* arg1 = NULL; | |
80 std::string url; | |
81 | |
82 if (!args_.get() || | |
83 !args_->GetDictionary(0, &arg1) || | |
84 !arg1->GetString("url", &url)) { | |
85 error_ = kUrlFieldRequired; | |
86 return false; | |
87 } | |
88 | |
89 AddRef(); // Balanced in OnAuthFlowSuccess/Failed. | |
Mihai Parparita -not on Chrome
2012/05/14 20:59:39
Nit: "Failure" instead of "Failed"
Munjal (Google)
2012/05/15 00:55:20
Done.
| |
90 GURL auth_url(url); | |
91 auth_flow_.reset(new WebAuthFlow( | |
92 this, profile(), GetExtension()->id(), auth_url)); | |
93 auth_flow_->Start(); | |
94 return true; | |
95 } | |
96 | |
97 void LaunchWebAuthFlowFunction::OnAuthFlowSuccess( | |
98 const std::string& redirect_url) { | |
99 result_.reset(Value::CreateStringValue(redirect_url)); | |
100 SendResponse(true); | |
101 Release(); // Balanced in RunImpl. | |
102 } | |
103 | |
104 void LaunchWebAuthFlowFunction::OnAuthFlowFailure() { | |
105 error_ = kInvalidRedirect; | |
106 SendResponse(false); | |
107 Release(); // Balanced in RunImpl. | |
108 } | |
109 | |
73 } // namespace extensions | 110 } // namespace extensions |
OLD | NEW |