• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "chrome/common/extensions/extension_constants.h"
10 #include "extensions/common/extension.h"
11 
12 namespace {
13 
14 const char kCroshExtensionEntryPoint[] = "/html/crosh.html";
15 
GetTerminalExtension(Profile * profile)16 const extensions::Extension* GetTerminalExtension(Profile* profile) {
17   // Search order for terminal extensions.
18   // We prefer hterm-dev, then hterm, then the builtin crosh extension.
19   static const char* kPossibleAppIds[] = {
20     extension_misc::kHTermDevAppId,
21     extension_misc::kHTermAppId,
22     extension_misc::kCroshBuiltinAppId,
23   };
24 
25   // The hterm-dev should be first in the list.
26   DCHECK_EQ(kPossibleAppIds[0], extension_misc::kHTermDevAppId);
27 
28   ExtensionService* service = profile->GetExtensionService();
29   for (size_t x = 0; x < arraysize(kPossibleAppIds); ++x) {
30     const extensions::Extension* extension = service->GetExtensionById(
31         kPossibleAppIds[x], false);
32     if (extension)
33       return extension;
34   }
35 
36   return NULL;
37 }
38 
39 }  // namespace
40 
41 namespace extensions {
42 
GetCroshExtensionURL(Profile * profile)43 GURL TerminalExtensionHelper::GetCroshExtensionURL(Profile* profile) {
44   const extensions::Extension* extension = GetTerminalExtension(profile);
45   if (!extension)
46     return GURL();
47 
48   return extension->GetResourceURL(kCroshExtensionEntryPoint);
49 }
50 
51 }  // namespace extensions
52