OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/api/terminal/terminal_extension_helper.h" |
| 6 |
| 7 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
| 9 |
| 10 namespace { |
| 11 |
| 12 const char* kAllowedExtensionIds[] = { |
| 13 // Keep official app first, so GetTerminalExtensionID checks it first. |
| 14 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App |
| 15 "okddffdblfhhnmhodogpojmfkjmhinfp", // test SSH/Crosh Client |
| 16 }; |
| 17 |
| 18 const char kExtensionSchema[] = "chrome-extension://"; |
| 19 const char kCroshExtensionEntryPoint[] = "/html/crosh.html"; |
| 20 |
| 21 } // namespace |
| 22 |
| 23 // Allow component and whitelisted extensions. |
| 24 bool TerminalExtensionHelper::AllowAccessToExtension( |
| 25 Profile* profile, |
| 26 const std::string& extension_id) { |
| 27 ExtensionService* service = profile->GetExtensionService(); |
| 28 const Extension* extension = service->GetExtensionById(extension_id, false); |
| 29 |
| 30 if (!extension) |
| 31 return false; |
| 32 |
| 33 if (extension->location() == Extension::COMPONENT) |
| 34 return true; |
| 35 |
| 36 for (size_t i = 0; i < arraysize(kAllowedExtensionIds); i++) { |
| 37 if (extension->id() == kAllowedExtensionIds[i]) |
| 38 return true; |
| 39 } |
| 40 return false; |
| 41 } |
| 42 |
| 43 GURL TerminalExtensionHelper::GetCroshExtensionURL(Profile* profile) { |
| 44 const char* extension_id = GetTerminalExtensionId(profile); |
| 45 if (!extension_id) |
| 46 return GURL(); |
| 47 |
| 48 std::string crosh_url_str(kExtensionSchema); |
| 49 crosh_url_str.append(extension_id); |
| 50 crosh_url_str.append(kCroshExtensionEntryPoint); |
| 51 return GURL(crosh_url_str); |
| 52 } |
| 53 |
| 54 const char* TerminalExtensionHelper::GetTerminalExtensionId(Profile* profile) { |
| 55 ExtensionService* service = profile->GetExtensionService(); |
| 56 for (size_t i = 0; i < arraysize(kAllowedExtensionIds); i++) { |
| 57 if (service->GetExtensionById(kAllowedExtensionIds[i], false) != 0) |
| 58 return kAllowedExtensionIds[i]; |
| 59 } |
| 60 return NULL; |
| 61 } |
OLD | NEW |