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 "base/string_util.h" |
7 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/extensions/crx_installer.h" |
8 #include "chrome/browser/extensions/extension_prefs.h" | 11 #include "chrome/browser/extensions/extension_prefs.h" |
9 #include "chrome/browser/extensions/extensions_service.h" | 12 #include "chrome/browser/extensions/extensions_service.h" |
10 #include "chrome/browser/sync/profile_sync_service.h" | 13 #include "chrome/browser/sync/profile_sync_service.h" |
| 14 #include "chrome/browser/tab_contents/tab_contents.h" |
| 15 #include "chrome/common/extensions/extension_constants.h" |
| 16 #include "net/base/escape.h" |
| 17 |
| 18 namespace { |
| 19 |
| 20 const char* install_base_url = extension_urls::kGalleryUpdateHttpsUrl; |
| 21 |
| 22 } |
11 | 23 |
12 static bool IsWebStoreURL(const GURL& url) { | 24 static bool IsWebStoreURL(const GURL& url) { |
13 GURL store_url(Extension::ChromeStoreURL()); | 25 GURL store_url(Extension::ChromeStoreURL()); |
14 if (!url.is_valid() || !store_url.is_valid()) { | 26 if (!url.is_valid() || !store_url.is_valid()) { |
15 return false; | 27 return false; |
16 } | 28 } |
17 return store_url.GetOrigin() == url.GetOrigin(); | 29 |
| 30 // Ignore port. It may be set on |url| during tests, but cannot be set on |
| 31 // ChromeStoreURL. |
| 32 return store_url.scheme() == url.scheme() && |
| 33 store_url.host() == url.host(); |
| 34 } |
| 35 |
| 36 // static |
| 37 void InstallFunction::SetTestingInstallBaseUrl( |
| 38 const char* testing_install_base_url) { |
| 39 install_base_url = testing_install_base_url; |
| 40 } |
| 41 |
| 42 bool InstallFunction::RunImpl() { |
| 43 if (!IsWebStoreURL(source_url())) |
| 44 return false; |
| 45 |
| 46 std::string id; |
| 47 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id)); |
| 48 EXTENSION_FUNCTION_VALIDATE(Extension::IdIsValid(id)); |
| 49 |
| 50 std::vector<std::string> params; |
| 51 params.push_back("id=" + id); |
| 52 params.push_back("lang=" + g_browser_process->GetApplicationLocale()); |
| 53 params.push_back("uc"); |
| 54 std::string url_string = install_base_url; |
| 55 |
| 56 GURL url(url_string + "?response=redirect&x=" + |
| 57 EscapeQueryParamValue(JoinString(params, '&'), true)); |
| 58 DCHECK(url.is_valid()); |
| 59 |
| 60 // Cleared in ~CrxInstaller(). |
| 61 CrxInstaller::SetWhitelistedInstallId(id); |
| 62 |
| 63 // The download url for the given |id| is now contained in |url|. We |
| 64 // navigate the current (calling) tab to this url which will result in a |
| 65 // download starting. Once completed it will go through the normal extension |
| 66 // install flow. The above call to SetWhitelistedInstallId will bypass the |
| 67 // normal permissions install dialog. |
| 68 NavigationController& controller = |
| 69 dispatcher()->delegate()->associated_tab_contents()->controller(); |
| 70 controller.LoadURL(url, source_url(), PageTransition::LINK); |
| 71 |
| 72 return true; |
18 } | 73 } |
19 | 74 |
20 bool GetSyncLoginFunction::RunImpl() { | 75 bool GetSyncLoginFunction::RunImpl() { |
21 if (!IsWebStoreURL(source_url())) | 76 if (!IsWebStoreURL(source_url())) |
22 return false; | 77 return false; |
23 ProfileSyncService* sync_service = profile_->GetProfileSyncService(); | 78 ProfileSyncService* sync_service = profile_->GetProfileSyncService(); |
24 string16 username = sync_service->GetAuthenticatedUsername(); | 79 string16 username = sync_service->GetAuthenticatedUsername(); |
25 result_.reset(Value::CreateStringValue(username)); | 80 result_.reset(Value::CreateStringValue(username)); |
26 return true; | 81 return true; |
27 } | 82 } |
(...skipping 15 matching lines...) Expand all Loading... |
43 bool SetStoreLoginFunction::RunImpl() { | 98 bool SetStoreLoginFunction::RunImpl() { |
44 if (!IsWebStoreURL(source_url())) | 99 if (!IsWebStoreURL(source_url())) |
45 return false; | 100 return false; |
46 std::string login; | 101 std::string login; |
47 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &login)); | 102 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &login)); |
48 ExtensionsService* service = profile_->GetExtensionsService(); | 103 ExtensionsService* service = profile_->GetExtensionsService(); |
49 ExtensionPrefs* prefs = service->extension_prefs(); | 104 ExtensionPrefs* prefs = service->extension_prefs(); |
50 prefs->SetWebStoreLogin(login); | 105 prefs->SetWebStoreLogin(login); |
51 return true; | 106 return true; |
52 } | 107 } |
OLD | NEW |