OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/extension_webstore_private_api.h" | 5 #include "chrome/browser/extensions/extension_webstore_private_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/extensions/crx_installer.h" | 14 #include "chrome/browser/extensions/crx_installer.h" |
15 #include "chrome/browser/extensions/extension_prefs.h" | 15 #include "chrome/browser/extensions/extension_prefs.h" |
16 #include "chrome/browser/extensions/extensions_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/net/gaia/token_service.h" | 17 #include "chrome/browser/net/gaia/token_service.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/browser/sync/profile_sync_service.h" | 19 #include "chrome/browser/sync/profile_sync_service.h" |
20 #include "chrome/browser/tab_contents/tab_contents.h" | 20 #include "chrome/browser/tab_contents/tab_contents.h" |
21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/extensions/extension_constants.h" | 22 #include "chrome/common/extensions/extension_constants.h" |
23 #include "chrome/common/extensions/extension_error_utils.h" | 23 #include "chrome/common/extensions/extension_error_utils.h" |
24 #include "chrome/common/net/gaia/gaia_constants.h" | 24 #include "chrome/common/net/gaia/gaia_constants.h" |
25 #include "chrome/common/notification_service.h" | 25 #include "chrome/common/notification_service.h" |
26 #include "chrome/common/notification_type.h" | 26 #include "chrome/common/notification_type.h" |
(...skipping 24 matching lines...) Loading... |
51 } | 51 } |
52 | 52 |
53 BrowserSignin* GetBrowserSignin(Profile* profile) { | 53 BrowserSignin* GetBrowserSignin(Profile* profile) { |
54 if (test_signin) | 54 if (test_signin) |
55 return test_signin; | 55 return test_signin; |
56 else | 56 else |
57 return profile->GetBrowserSignin(); | 57 return profile->GetBrowserSignin(); |
58 } | 58 } |
59 | 59 |
60 bool IsWebStoreURL(Profile* profile, const GURL& url) { | 60 bool IsWebStoreURL(Profile* profile, const GURL& url) { |
61 ExtensionsService* service = profile->GetExtensionsService(); | 61 ExtensionService* service = profile->GetExtensionService(); |
62 const Extension* store = service->GetWebStoreApp(); | 62 const Extension* store = service->GetWebStoreApp(); |
63 if (!store) { | 63 if (!store) { |
64 NOTREACHED(); | 64 NOTREACHED(); |
65 return false; | 65 return false; |
66 } | 66 } |
67 return (service->GetExtensionByWebExtent(url) == store); | 67 return (service->GetExtensionByWebExtent(url) == store); |
68 } | 68 } |
69 | 69 |
70 // Helper to create a dictionary with login and token properties set from | 70 // Helper to create a dictionary with login and token properties set from |
71 // the appropriate values in the passed-in |profile|. | 71 // the appropriate values in the passed-in |profile|. |
(...skipping 106 matching lines...) Loading... |
178 bool GetBrowserLoginFunction::RunImpl() { | 178 bool GetBrowserLoginFunction::RunImpl() { |
179 if (!IsWebStoreURL(profile_, source_url())) | 179 if (!IsWebStoreURL(profile_, source_url())) |
180 return false; | 180 return false; |
181 result_.reset(CreateLoginResult(GetDefaultProfile(profile_))); | 181 result_.reset(CreateLoginResult(GetDefaultProfile(profile_))); |
182 return true; | 182 return true; |
183 } | 183 } |
184 | 184 |
185 bool GetStoreLoginFunction::RunImpl() { | 185 bool GetStoreLoginFunction::RunImpl() { |
186 if (!IsWebStoreURL(profile_, source_url())) | 186 if (!IsWebStoreURL(profile_, source_url())) |
187 return false; | 187 return false; |
188 ExtensionsService* service = profile_->GetExtensionsService(); | 188 ExtensionService* service = profile_->GetExtensionService(); |
189 ExtensionPrefs* prefs = service->extension_prefs(); | 189 ExtensionPrefs* prefs = service->extension_prefs(); |
190 std::string login; | 190 std::string login; |
191 if (prefs->GetWebStoreLogin(&login)) { | 191 if (prefs->GetWebStoreLogin(&login)) { |
192 result_.reset(Value::CreateStringValue(login)); | 192 result_.reset(Value::CreateStringValue(login)); |
193 } else { | 193 } else { |
194 result_.reset(Value::CreateStringValue(std::string())); | 194 result_.reset(Value::CreateStringValue(std::string())); |
195 } | 195 } |
196 return true; | 196 return true; |
197 } | 197 } |
198 | 198 |
199 bool SetStoreLoginFunction::RunImpl() { | 199 bool SetStoreLoginFunction::RunImpl() { |
200 if (!IsWebStoreURL(profile_, source_url())) | 200 if (!IsWebStoreURL(profile_, source_url())) |
201 return false; | 201 return false; |
202 std::string login; | 202 std::string login; |
203 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &login)); | 203 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &login)); |
204 ExtensionsService* service = profile_->GetExtensionsService(); | 204 ExtensionService* service = profile_->GetExtensionService(); |
205 ExtensionPrefs* prefs = service->extension_prefs(); | 205 ExtensionPrefs* prefs = service->extension_prefs(); |
206 prefs->SetWebStoreLogin(login); | 206 prefs->SetWebStoreLogin(login); |
207 return true; | 207 return true; |
208 } | 208 } |
209 | 209 |
210 PromptBrowserLoginFunction::PromptBrowserLoginFunction() | 210 PromptBrowserLoginFunction::PromptBrowserLoginFunction() |
211 : waiting_for_token_(false) {} | 211 : waiting_for_token_(false) {} |
212 | 212 |
213 PromptBrowserLoginFunction::~PromptBrowserLoginFunction() { | 213 PromptBrowserLoginFunction::~PromptBrowserLoginFunction() { |
214 } | 214 } |
(...skipping 100 matching lines...) Loading... |
315 } | 315 } |
316 | 316 |
317 DCHECK(waiting_for_token_); | 317 DCHECK(waiting_for_token_); |
318 | 318 |
319 result_.reset(CreateLoginResult(GetDefaultProfile(profile_))); | 319 result_.reset(CreateLoginResult(GetDefaultProfile(profile_))); |
320 SendResponse(true); | 320 SendResponse(true); |
321 | 321 |
322 // Matches the AddRef in RunImpl(). | 322 // Matches the AddRef in RunImpl(). |
323 Release(); | 323 Release(); |
324 } | 324 } |
OLD | NEW |