Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / terminal / terminal_extension_helper.cc
blobef3a2014ae61bc2463aeec291429e3f1a350d373
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.
5 #include "chrome/browser/extensions/api/terminal/terminal_extension_helper.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/common/extensions/extension_constants.h"
9 #include "extensions/browser/extension_registry.h"
10 #include "extensions/common/extension.h"
12 namespace extensions {
14 namespace {
16 const char kCroshExtensionEntryPoint[] = "/html/crosh.html";
18 const Extension* GetTerminalExtension(Profile* profile) {
19 // Search order for terminal extensions.
20 // We prefer hterm-dev, then hterm, then the builtin crosh extension.
21 static const char* const kPossibleAppIds[] = {
22 extension_misc::kHTermDevAppId,
23 extension_misc::kHTermAppId,
24 extension_misc::kCroshBuiltinAppId,
27 // The hterm-dev should be first in the list.
28 DCHECK_EQ(kPossibleAppIds[0], extension_misc::kHTermDevAppId);
30 const ExtensionSet& extensions =
31 ExtensionRegistry::Get(profile)->enabled_extensions();
32 for (size_t i = 0; i < arraysize(kPossibleAppIds); ++i) {
33 const extensions::Extension* extension =
34 extensions.GetByID(kPossibleAppIds[i]);
35 if (extension)
36 return extension;
39 return NULL;
42 } // namespace
44 GURL TerminalExtensionHelper::GetCroshExtensionURL(Profile* profile) {
45 GURL url;
46 const extensions::Extension* extension = GetTerminalExtension(profile);
47 if (extension)
48 url = extension->GetResourceURL(kCroshExtensionEntryPoint);
49 return url;
52 } // namespace extensions