summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api/developer_private/developer_private_mangle.cc
blob: 073df5b777523dde01c9215644afb108a1cfaa1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/extensions/api/developer_private/developer_private_mangle.h"

#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "chrome/common/extensions/api/developer_private.h"
#include "extensions/browser/extension_error.h"
#include "extensions/common/constants.h"

namespace extensions {
namespace developer_private_mangle {

linked_ptr<api::developer_private::ItemInfo> MangleExtensionInfo(
    const api::developer_private::ExtensionInfo& info) {
  linked_ptr<api::developer_private::ItemInfo> result(
      new api::developer_private::ItemInfo());
  result->id = info.id;
  result->name = info.name;
  result->version = info.version;
  result->description = info.description;
  result->may_disable = info.user_may_modify;
  result->enabled =
      info.state == api::developer_private::EXTENSION_STATE_ENABLED;
  switch (info.type) {
    case api::developer_private::EXTENSION_TYPE_HOSTED_APP:
      result->type = api::developer_private::ITEM_TYPE_HOSTED_APP;
      result->is_app = true;
      break;
    case api::developer_private::EXTENSION_TYPE_PLATFORM_APP:
      result->type = api::developer_private::ITEM_TYPE_PACKAGED_APP;
      result->is_app = true;
      break;
    case api::developer_private::EXTENSION_TYPE_LEGACY_PACKAGED_APP:
      result->type = api::developer_private::ITEM_TYPE_LEGACY_PACKAGED_APP;
      result->is_app = true;
      break;
    case api::developer_private::EXTENSION_TYPE_EXTENSION:
      result->type = api::developer_private::ITEM_TYPE_EXTENSION;
      result->is_app = false;
      break;
    case api::developer_private::EXTENSION_TYPE_THEME:
      result->type = api::developer_private::ITEM_TYPE_THEME;
      result->is_app = false;
      break;
    case api::developer_private::EXTENSION_TYPE_SHARED_MODULE:
      // Old api doesn't account for this.
      break;
    default:
      NOTREACHED();
  }
  result->allow_file_access = info.file_access.is_active;
  result->wants_file_access = info.file_access.is_enabled;

  result->icon_url = info.icon_url;

  result->incognito_enabled = info.incognito_access.is_active;
  result->allow_incognito = info.incognito_access.is_enabled;

  result->is_unpacked =
      info.location == api::developer_private::LOCATION_UNPACKED;
  result->allow_reload = result->is_unpacked;
  result->terminated =
      info.state == api::developer_private::EXTENSION_STATE_TERMINATED;

  if (info.path)
    result->path.reset(new std::string(*info.path));
  if (info.options_page)
    result->options_url.reset(new std::string(info.options_page->url));
  if (info.launch_url)
    result->app_launch_url.reset(new std::string(*info.launch_url));
  if (!info.home_page.url.empty())
    result->homepage_url.reset(new std::string(info.home_page.url));
  result->update_url.reset(new std::string(info.update_url));
  for (const std::string& str_warning : info.install_warnings) {
    scoped_ptr<api::developer_private::InstallWarning> warning(
        new api::developer_private::InstallWarning());
    warning->message = str_warning;
    result->install_warnings.push_back(make_linked_ptr(warning.release()));
  }
  for (const linked_ptr<api::developer_private::ManifestError>& error :
           info.manifest_errors) {
    CHECK(error.get());
    scoped_ptr<base::DictionaryValue> value = error->ToValue();
    value->SetInteger("type", static_cast<int>(ExtensionError::MANIFEST_ERROR));
    value->SetInteger("level", static_cast<int>(logging::LOG_WARNING));
    result->manifest_errors.push_back(make_linked_ptr(value.release()));
  }
  for (const linked_ptr<api::developer_private::RuntimeError>& error :
           info.runtime_errors) {
    CHECK(error.get());
    scoped_ptr<base::DictionaryValue> value = error->ToValue();
    value->SetInteger("type", static_cast<int>(ExtensionError::RUNTIME_ERROR));
    logging::LogSeverity severity = logging::LOG_INFO;
    if (error->severity == api::developer_private::ERROR_LEVEL_WARN)
      severity = logging::LOG_WARNING;
    else if (error->severity == api::developer_private::ERROR_LEVEL_ERROR)
      severity = logging::LOG_ERROR;
    value->SetInteger("level", static_cast<int>(severity));
    result->runtime_errors.push_back(make_linked_ptr(value.release()));
  }
  result->offline_enabled = info.offline_enabled;
  for (const linked_ptr<api::developer_private::ExtensionView>& view :
           info.views) {
    linked_ptr<api::developer_private::ItemInspectView> view_copy(
        new api::developer_private::ItemInspectView());
    GURL url(view->url);
    if (url.scheme() == kExtensionScheme) {
      // No leading slash.
      view_copy->path = url.path().substr(1);
    } else {
      // For live pages, use the full URL.
      view_copy->path = url.spec();
    }
    view_copy->render_process_id = view->render_process_id;
    view_copy->render_view_id = view->render_view_id;
    view_copy->incognito = view->incognito;
    view_copy->generated_background_page =
        view_copy->path == kGeneratedBackgroundPageFilename;
    result->views.push_back(view_copy);
  }

  return result;
}

}  // namespace developer_private_mangle
}  // namespace extensions