Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / extensions / api / developer_private / developer_private_mangle.cc
blobaa1bcdbda2157aa2a9481988a0a0a4e5ab914b67
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_enabled;
55 result->wants_file_access = info.file_access.is_active;
57 result->incognito_enabled = info.incognito_access.is_active;
58 result->allow_incognito = info.incognito_access.is_enabled;
60 result->is_unpacked =
61 info.location == api::developer_private::LOCATION_UNPACKED;
62 result->allow_reload = result->is_unpacked;
63 result->terminated =
64 info.state == api::developer_private::EXTENSION_STATE_TERMINATED;
66 if (info.path)
67 result->path.reset(new std::string(*info.path));
68 if (info.options_page)
69 result->options_url.reset(new std::string(info.options_page->url));
70 if (info.launch_url)
71 result->app_launch_url.reset(new std::string(*info.launch_url));
72 if (!info.home_page.url.empty())
73 result->homepage_url.reset(new std::string(info.home_page.url));
74 result->update_url.reset(new std::string(info.update_url));
75 for (const std::string& str_warning : info.install_warnings) {
76 scoped_ptr<api::developer_private::InstallWarning> warning(
77 new api::developer_private::InstallWarning());
78 warning->message = str_warning;
79 result->install_warnings.push_back(make_linked_ptr(warning.release()));
81 for (const linked_ptr<api::developer_private::ManifestError>& error :
82 info.manifest_errors) {
83 CHECK(error.get());
84 scoped_ptr<base::DictionaryValue> value = error->ToValue();
85 value->SetInteger("type", static_cast<int>(ExtensionError::MANIFEST_ERROR));
86 value->SetInteger("level", static_cast<int>(logging::LOG_WARNING));
87 result->manifest_errors.push_back(make_linked_ptr(value.release()));
89 for (const linked_ptr<api::developer_private::RuntimeError>& error :
90 info.runtime_errors) {
91 CHECK(error.get());
92 scoped_ptr<base::DictionaryValue> value = error->ToValue();
93 value->SetInteger("type", static_cast<int>(ExtensionError::RUNTIME_ERROR));
94 logging::LogSeverity severity = logging::LOG_INFO;
95 if (error->severity == api::developer_private::ERROR_LEVEL_WARN)
96 severity = logging::LOG_WARNING;
97 else if (error->severity == api::developer_private::ERROR_LEVEL_ERROR)
98 severity = logging::LOG_ERROR;
99 value->SetInteger("level", static_cast<int>(severity));
100 result->runtime_errors.push_back(make_linked_ptr(value.release()));
102 result->offline_enabled = info.offline_enabled;
103 for (const linked_ptr<api::developer_private::ExtensionView>& view :
104 info.views) {
105 linked_ptr<api::developer_private::ItemInspectView> view_copy(
106 new api::developer_private::ItemInspectView());
107 GURL url(view->url);
108 if (url.scheme() == kExtensionScheme) {
109 // No leading slash.
110 view_copy->path = url.path().substr(1);
111 } else {
112 // For live pages, use the full URL.
113 view_copy->path = url.spec();
115 view_copy->render_process_id = view->render_process_id;
116 view_copy->render_view_id = view->render_view_id;
117 view_copy->incognito = view->incognito;
118 view_copy->generated_background_page =
119 view_copy->path == kGeneratedBackgroundPageFilename;
120 result->views.push_back(view_copy);
123 return result;
126 } // namespace developer_private_mangle
127 } // namespace extensions