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

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: merge TerminalPrivate api changes 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 // 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"; 13 const char kCroshExtensionEntryPoint[] = "/html/crosh.html";
20 14
21 } // namespace 15 } // namespace
22 16
23 // Allow component and whitelisted extensions. 17 GURL TerminalExtensionHelper::GetCroshExtensionURL(Profile* profile) {
24 bool TerminalExtensionHelper::AllowAccessToExtension(
25 Profile* profile,
26 const std::string& extension_id) {
27 ExtensionService* service = profile->GetExtensionService(); 18 ExtensionService* service = profile->GetExtensionService();
28 const Extension* extension = service->GetExtensionById(extension_id, false); 19 const Extension* extension =
29 20 service->GetExtensionById(extension_misc::kHTermAppId, false);
jstritar 2012/02/01 16:09:51 Do you ever really need to fall back to the test e
tbarzic 2012/02/01 18:32:44 Yeah,we'll need to fallback occasionally; test ext
30 if (!extension) 21 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) {
jstritar 2012/02/01 16:09:51 What does Crosh stand for? Chrome shell? Just wond
tbarzic 2012/02/01 18:32:44 It's chrome os shell
44 const char* extension_id = GetTerminalExtensionId(profile);
45 if (!extension_id)
46 return GURL(); 22 return GURL();
47 23
48 std::string crosh_url_str(kExtensionSchema); 24 return extension->GetResourceURL(kCroshExtensionEntryPoint);
49 crosh_url_str.append(extension_id);
50 crosh_url_str.append(kCroshExtensionEntryPoint);
51 return GURL(crosh_url_str);
52 } 25 }
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