Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / developer_private / developer_private_mangle.cc
blob073df5b777523dde01c9215644afb108a1cfaa1a
1 // Copyright 2015 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/developer_private/developer_private_mangle.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h"
9 #include "chrome/common/extensions/api/developer_private.h"
10 #include "extensions/browser/extension_error.h"
11 #include "extensions/common/constants.h"
13 namespace extensions {
14 namespace developer_private_mangle {
16 linked_ptr<api::developer_private::ItemInfo> MangleExtensionInfo(
17 const api::developer_private::ExtensionInfo& info) {
18 linked_ptr<api::developer_private::ItemInfo> result(
19 new api::developer_private::ItemInfo());
20 result->id = info.id;
21 result->name = info.name;
22 result->version = info.version;
23 result->description = info.description;
24 result->may_disable = info.user_may_modify;
25 result->enabled =
26 info.state == api::developer_private::EXTENSION_STATE_ENABLED;
27 switch (info.type) {
28 case api::developer_private::EXTENSION_TYPE_HOSTED_APP:
29 result->type = api::developer_private::ITEM_TYPE_HOSTED_APP;
30 result->is_app = true;
31 break;
32 case api::developer_private::EXTENSION_TYPE_PLATFORM_APP:
33 result->type = api::developer_private::ITEM_TYPE_PACKAGED_APP;
34 result->is_app = true;
35 break;
36 case api::developer_private::EXTENSION_TYPE_LEGACY_PACKAGED_APP:
37 result->type = api::developer_private::ITEM_TYPE_LEGACY_PACKAGED_APP;
38 result->is_app = true;
39 break;
40 case api::developer_private::EXTENSION_TYPE_EXTENSION:
41 result->type = api::developer_private::ITEM_TYPE_EXTENSION;
42 result->is_app = false;
43 break;
44 case api::developer_private::EXTENSION_TYPE_THEME:
45 result->type = api::developer_private::ITEM_TYPE_THEME;
46 result->is_app = false;
47 break;
48 case api::developer_private::EXTENSION_TYPE_SHARED_MODULE:
49 // Old api doesn't account for this.
50 break;
51 default:
52 NOTREACHED();
54 result->allow_file_access = info.file_access.is_active;
55 result->wants_file_access = info.file_access.is_enabled;
57 result->icon_url = info.icon_url;
59 result->incognito_enabled = info.incognito_access.is_active;
60 result->allow_incognito = info.incognito_access.is_enabled;
62 result->is_unpacked =
63 info.location == api::developer_private::LOCATION_UNPACKED;
64 result->allow_reload = result->is_unpacked;
65 result->terminated =
66 info.state == api::developer_private::EXTENSION_STATE_TERMINATED;
68 if (info.path)
69 result->path.reset(new std::string(*info.path));
70 if (info.options_page)
71 result->options_url.reset(new std::string(info.options_page->url));
72 if (info.launch_url)
73 result->app_launch_url.reset(new std::string(*info.launch_url));
74 if (!info.home_page.url.empty())
75 result->homepage_url.reset(new std::string(info.home_page.url));
76 result->update_url.reset(new std::string(info.update_url));
77 for (const std::string& str_warning : info.install_warnings) {
78 scoped_ptr<api::developer_private::InstallWarning> warning(
79 new api::developer_private::InstallWarning());
80 warning->message = str_warning;
81 result->install_warnings.push_back(make_linked_ptr(warning.release()));
83 for (const linked_ptr<api::developer_private::ManifestError>& error :
84 info.manifest_errors) {
85 CHECK(error.get());
86 scoped_ptr<base::DictionaryValue> value = error->ToValue();
87 value->SetInteger("type", static_cast<int>(ExtensionError::MANIFEST_ERROR));
88 value->SetInteger("level", static_cast<int>(logging::LOG_WARNING));
89 result->manifest_errors.push_back(make_linked_ptr(value.release()));
91 for (const linked_ptr<api::developer_private::RuntimeError>& error :
92 info.runtime_errors) {
93 CHECK(error.get());
94 scoped_ptr<base::DictionaryValue> value = error->ToValue();
95 value->SetInteger("type", static_cast<int>(ExtensionError::RUNTIME_ERROR));
96 logging::LogSeverity severity = logging::LOG_INFO;
97 if (error->severity == api::developer_private::ERROR_LEVEL_WARN)
98 severity = logging::LOG_WARNING;
99 else if (error->severity == api::developer_private::ERROR_LEVEL_ERROR)
100 severity = logging::LOG_ERROR;
101 value->SetInteger("level", static_cast<int>(severity));
102 result->runtime_errors.push_back(make_linked_ptr(value.release()));
104 result->offline_enabled = info.offline_enabled;
105 for (const linked_ptr<api::developer_private::ExtensionView>& view :
106 info.views) {
107 linked_ptr<api::developer_private::ItemInspectView> view_copy(
108 new api::developer_private::ItemInspectView());
109 GURL url(view->url);
110 if (url.scheme() == kExtensionScheme) {
111 // No leading slash.
112 view_copy->path = url.path().substr(1);
113 } else {
114 // For live pages, use the full URL.
115 view_copy->path = url.spec();
117 view_copy->render_process_id = view->render_process_id;
118 view_copy->render_view_id = view->render_view_id;
119 view_copy->incognito = view->incognito;
120 view_copy->generated_background_page =
121 view_copy->path == kGeneratedBackgroundPageFilename;
122 result->views.push_back(view_copy);
125 return result;
128 } // namespace developer_private_mangle
129 } // namespace extensions