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 using content::WebContents; | |
Mihai Parparita -not on Chrome
2012/05/08 21:33:30
These two using statements can be removed.
Munjal (Google)
2012/05/11 18:53:33
Done.
| |
17 using content::WebContentsDelegate; | |
18 | |
16 namespace extensions { | 19 namespace extensions { |
17 | 20 |
18 namespace { | 21 namespace { |
19 | 22 |
20 const char kInvalidClientId[] = "Invalid OAuth2 Client ID."; | 23 const char kInvalidClientId[] = "Invalid OAuth2 Client ID."; |
21 const char kInvalidScopes[] = "Invalid OAuth2 scopes."; | 24 const char kInvalidScopes[] = "Invalid OAuth2 scopes."; |
25 const char kUrlFieldRequired[] = "Missing required field: url"; | |
26 const char kInvalidRedirect[] = "Did not redirect to the right URL."; | |
22 | 27 |
23 } // namespace | 28 } // namespace |
24 | 29 |
25 GetAuthTokenFunction::GetAuthTokenFunction() {} | 30 GetAuthTokenFunction::GetAuthTokenFunction() {} |
26 GetAuthTokenFunction::~GetAuthTokenFunction() {} | 31 GetAuthTokenFunction::~GetAuthTokenFunction() {} |
27 | 32 |
28 bool GetAuthTokenFunction::RunImpl() { | 33 bool GetAuthTokenFunction::RunImpl() { |
29 const Extension* extension = GetExtension(); | 34 const Extension* extension = GetExtension(); |
30 Extension::OAuth2Info oauth2_info = extension->oauth2_info(); | 35 Extension::OAuth2Info oauth2_info = extension->oauth2_info(); |
31 | 36 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 Release(); // Balanced in RunImpl. | 68 Release(); // Balanced in RunImpl. |
64 } | 69 } |
65 | 70 |
66 void GetAuthTokenFunction::OnMintTokenFailure( | 71 void GetAuthTokenFunction::OnMintTokenFailure( |
67 const GoogleServiceAuthError& error) { | 72 const GoogleServiceAuthError& error) { |
68 error_ = error.ToString(); | 73 error_ = error.ToString(); |
69 SendResponse(false); | 74 SendResponse(false); |
70 Release(); // Balanced in RunImpl. | 75 Release(); // Balanced in RunImpl. |
71 } | 76 } |
72 | 77 |
78 LaunchAuthFlowFunction::LaunchAuthFlowFunction() {} | |
79 LaunchAuthFlowFunction::~LaunchAuthFlowFunction() {} | |
80 | |
81 bool LaunchAuthFlowFunction::RunImpl() { | |
82 DictionaryValue* arg1 = NULL; | |
83 std::string url; | |
84 | |
85 if (!args_.get() || | |
86 !args_->GetDictionary(0, &arg1) || | |
87 !arg1->GetString("url", &url)) { | |
88 error_ = kUrlFieldRequired; | |
89 return false; | |
90 } | |
91 | |
92 AddRef(); // Balanced in OnAuthFlowSuccess/Failed. | |
93 GURL auth_url(url); | |
94 auth_flow_.reset(new ExtensionAuthFlow( | |
95 this, profile(), GetExtension()->id(), auth_url)); | |
96 auth_flow_->Start(); | |
97 return true; | |
98 } | |
99 | |
100 void LaunchAuthFlowFunction::OnAuthFlowSuccess( | |
101 const std::string& redirect_url) { | |
102 result_.reset(Value::CreateStringValue(redirect_url)); | |
103 SendResponse(true); | |
104 Release(); // Balanced in RunImpl. | |
105 } | |
106 | |
107 void LaunchAuthFlowFunction::OnAuthFlowFailure() { | |
108 error_ = kInvalidRedirect; | |
109 SendResponse(false); | |
110 Release(); // Balanced in RunImpl. | |
111 } | |
112 | |
73 } // namespace extensions | 113 } // namespace extensions |
OLD | NEW |