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 officail 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(Profile* profile, | |
25 const std::string& extension_id) { | |
tbarzic
2012/01/27 23:16:50
This method is moved from terminal_private_api.cc
| |
26 ExtensionService* service = profile->GetExtensionService(); | |
27 const Extension* extension = service->GetExtensionById(extension_id, false); | |
28 | |
29 if (!extension) | |
30 return false; | |
31 | |
32 if (extension->location() == Extension::COMPONENT) | |
33 return true; | |
34 | |
35 for (size_t i = 0; i < arraysize(kAllowedExtensionIds); i++) { | |
36 if (extension->id() == kAllowedExtensionIds[i]) | |
37 return true; | |
38 } | |
39 return false; | |
40 } | |
41 | |
42 GURL TerminalExtensionHelper::GetCroshExtensionURL(Profile* profile) { | |
43 const char* extension_id = GetTerminalExtensionId(profile); | |
44 if (!extension_id) | |
45 return GURL(); | |
46 | |
47 std::string crosh_url_str(kExtensionSchema); | |
48 crosh_url_str.append(extension_id); | |
49 crosh_url_str.append(kCroshExtensionEntryPoint); | |
50 return GURL(crosh_url_str); | |
51 } | |
52 | |
53 const char* TerminalExtensionHelper::GetTerminalExtensionId(Profile* profile) { | |
54 ExtensionService* service = profile->GetExtensionService(); | |
55 for (size_t i = 0; i < arraysize(kAllowedExtensionIds); i++) { | |
56 if (service->GetExtensionById(kAllowedExtensionIds[i], false) != 0) | |
57 return kAllowedExtensionIds[i]; | |
58 } | |
59 return NULL; | |
60 } | |
OLD | NEW |