Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(604)

Side by Side Diff: chrome/browser/extensions/api/terminal/terminal_extension_helper.cc

Issue 9317013: Add a centralized mechanism for whitelisting access to extension permissions. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: . Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/terminal/terminal_extension_helper.h" 5 #include "chrome/browser/extensions/api/terminal/terminal_extension_helper.h"
6 6
7 #include "chrome/browser/extensions/extension_service.h" 7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/common/extensions/extension.h"
9 10
10 namespace { 11 namespace {
11 12
12 const char* kAllowedExtensionIds[] = { 13 const char kCroshExtensionEntryPoint[] = "/html/crosh.html";
13 // Keep official app first, so GetTerminalExtensionID checks it first.
14 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App
15 "okddffdblfhhnmhodogpojmfkjmhinfp", // test SSH/Crosh Client
16 };
17 14
18 const char kExtensionSchema[] = "chrome-extension://"; 15 const Extension* GetTerminalExtension(Profile* profile) {
19 const char kCroshExtensionEntryPoint[] = "/html/crosh.html"; 16 static const char* kPossibleAppIds[] = {
17 extension_misc::kHTermAppId,
18 extension_misc::kHTermDevAppId
19 };
20
21 // The production app should be first in the list.
22 DCHECK_EQ(kPossibleAppIds[0], extension_misc::kHTermAppId);
23
24 ExtensionService* service = profile->GetExtensionService();
25 for (size_t x = 0; x < arraysize(kPossibleAppIds); ++x) {
26 const Extension* extension = service->GetExtensionById(
27 kPossibleAppIds[x], false);
28 if (extension)
29 return extension;
30 }
31
32 return NULL;
33 }
20 34
21 } // namespace 35 } // namespace
22 36
23 // Allow component and whitelisted extensions. 37 GURL TerminalExtensionHelper::GetCroshExtensionURL(Profile* profile) {
24 bool TerminalExtensionHelper::AllowAccessToExtension( 38 const Extension* extension = GetTerminalExtension(profile);
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) 39 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(); 40 return GURL();
47 41
48 std::string crosh_url_str(kExtensionSchema); 42 return extension->GetResourceURL(kCroshExtensionEntryPoint);
49 crosh_url_str.append(extension_id);
50 crosh_url_str.append(kCroshExtensionEntryPoint);
51 return GURL(crosh_url_str);
52 } 43 }
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698