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