OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/developer_private/extension_info_generat or.h" | 5 #include "chrome/browser/extensions/api/developer_private/extension_info_generat or.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/extensions/api/developer_private/inspectable_views_find er.h" | 8 #include "chrome/browser/extensions/api/developer_private/inspectable_views_find er.h" |
9 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 9 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
10 #include "chrome/browser/extensions/error_console/error_console.h" | 10 #include "chrome/browser/extensions/error_console/error_console.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 type = developer::EXTENSION_TYPE_SHARED_MODULE; | 64 type = developer::EXTENSION_TYPE_SHARED_MODULE; |
65 break; | 65 break; |
66 default: | 66 default: |
67 NOTREACHED(); | 67 NOTREACHED(); |
68 } | 68 } |
69 return type; | 69 return type; |
70 } | 70 } |
71 | 71 |
72 // Populates the common fields of an extension error. | 72 // Populates the common fields of an extension error. |
73 template <typename ErrorType> | 73 template <typename ErrorType> |
74 void PopulateErrorBase(const ExtensionError& error, | 74 void PopulateErrorBase(const ExtensionError& error, ErrorType* out) { |
75 ErrorType* out) { | |
76 CHECK(out); | 75 CHECK(out); |
77 out->type = error.type() == ExtensionError::MANIFEST_ERROR ? | 76 out->type = error.type() == ExtensionError::MANIFEST_ERROR ? |
78 developer::ERROR_TYPE_MANIFEST : developer::ERROR_TYPE_RUNTIME; | 77 developer::ERROR_TYPE_MANIFEST : developer::ERROR_TYPE_RUNTIME; |
79 out->extension_id = error.extension_id(); | 78 out->extension_id = error.extension_id(); |
80 out->from_incognito = error.from_incognito(); | 79 out->from_incognito = error.from_incognito(); |
81 out->source = base::UTF16ToUTF8(error.source()); | 80 out->source = base::UTF16ToUTF8(error.source()); |
82 out->message = base::UTF16ToUTF8(error.message()); | 81 out->message = base::UTF16ToUTF8(error.message()); |
82 out->id = error.id(); | |
83 } | 83 } |
84 | 84 |
85 // Given a ManifestError object, converts it into its developer_private | |
86 // counterpart. | |
87 linked_ptr<developer::ManifestError> ConstructManifestError( | 85 linked_ptr<developer::ManifestError> ConstructManifestError( |
88 const ManifestError& error) { | 86 const ManifestError& error) { |
89 linked_ptr<developer::ManifestError> result(new developer::ManifestError()); | 87 linked_ptr<developer::ManifestError> result(new developer::ManifestError()); |
90 PopulateErrorBase(error, result.get()); | 88 PopulateErrorBase(error, result.get()); |
91 result->manifest_key = base::UTF16ToUTF8(error.manifest_key()); | 89 result->manifest_key = base::UTF16ToUTF8(error.manifest_key()); |
92 if (!error.manifest_specific().empty()) { | 90 if (!error.manifest_specific().empty()) { |
93 result->manifest_specific.reset( | 91 result->manifest_specific.reset( |
94 new std::string(base::UTF16ToUTF8(error.manifest_specific()))); | 92 new std::string(base::UTF16ToUTF8(error.manifest_specific()))); |
95 } | 93 } |
96 return result; | 94 return result; |
97 } | 95 } |
98 | 96 |
99 // Given a RuntimeError object, converts it into its developer_private | |
100 // counterpart. | |
101 linked_ptr<developer::RuntimeError> ConstructRuntimeError( | 97 linked_ptr<developer::RuntimeError> ConstructRuntimeError( |
102 const RuntimeError& error) { | 98 const RuntimeError& error) { |
103 linked_ptr<developer::RuntimeError> result(new developer::RuntimeError()); | 99 linked_ptr<developer::RuntimeError> result(new developer::RuntimeError()); |
104 PopulateErrorBase(error, result.get()); | 100 PopulateErrorBase(error, result.get()); |
105 switch (error.level()) { | 101 switch (error.level()) { |
106 case logging::LOG_INFO: | 102 case logging::LOG_INFO: |
107 result->severity = developer::ERROR_LEVEL_LOG; | 103 result->severity = developer::ERROR_LEVEL_LOG; |
108 break; | 104 break; |
109 case logging::LOG_WARNING: | 105 case logging::LOG_WARNING: |
110 result->severity = developer::ERROR_LEVEL_WARN; | 106 result->severity = developer::ERROR_LEVEL_WARN; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 | 352 |
357 info->version = extension.GetVersionForDisplay(); | 353 info->version = extension.GetVersionForDisplay(); |
358 | 354 |
359 if (state != developer::EXTENSION_STATE_TERMINATED) { | 355 if (state != developer::EXTENSION_STATE_TERMINATED) { |
360 info->views = InspectableViewsFinder(profile, nullptr). | 356 info->views = InspectableViewsFinder(profile, nullptr). |
361 GetViewsForExtension(extension, is_enabled); | 357 GetViewsForExtension(extension, is_enabled); |
362 } | 358 } |
363 return info.Pass(); | 359 return info.Pass(); |
364 } | 360 } |
365 | 361 |
362 scoped_ptr<api::developer_private::ExtensionInfo> | |
363 ExtensionInfoGenerator::CreateExtensionInfo(const std::string& id) { | |
364 developer::ExtensionState state = developer::EXTENSION_STATE_ENABLED; | |
365 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_); | |
366 const Extension* extension = registry->enabled_extensions().GetByID(id); | |
367 if (!extension && | |
368 (extension = registry->disabled_extensions().GetByID(id)) != nullptr) { | |
Dan Beam
2015/03/31 00:33:49
:_(
Devlin
2015/03/31 16:17:50
Why sad face? I think it actually makes sense, as
Dan Beam
2015/04/22 21:02:37
eh, it's all awkward. whatevs.
| |
369 state = developer::EXTENSION_STATE_DISABLED; | |
370 } else if (!extension && | |
371 (extension = | |
372 registry->terminated_extensions().GetByID(id)) != nullptr) { | |
373 state = developer::EXTENSION_STATE_TERMINATED; | |
374 } | |
375 scoped_ptr<api::developer_private::ExtensionInfo> info; | |
376 if (extension) | |
377 info = CreateExtensionInfo(*extension, state); | |
378 return info.Pass(); | |
379 } | |
380 | |
366 ExtensionInfoGenerator::ExtensionInfoList | 381 ExtensionInfoGenerator::ExtensionInfoList |
367 ExtensionInfoGenerator::CreateExtensionsInfo(bool include_disabled, | 382 ExtensionInfoGenerator::CreateExtensionsInfo(bool include_disabled, |
368 bool include_terminated) { | 383 bool include_terminated) { |
369 std::vector<linked_ptr<developer::ExtensionInfo>> list; | 384 std::vector<linked_ptr<developer::ExtensionInfo>> list; |
370 auto add_to_list = [this, &list](const ExtensionSet& extensions, | 385 auto add_to_list = [this, &list](const ExtensionSet& extensions, |
371 developer::ExtensionState state) { | 386 developer::ExtensionState state) { |
372 for (const scoped_refptr<const Extension>& extension : extensions) { | 387 for (const scoped_refptr<const Extension>& extension : extensions) { |
373 if (ui_util::ShouldDisplayInExtensionSettings(extension.get(), | 388 if (ui_util::ShouldDisplayInExtensionSettings(extension.get(), |
374 browser_context_)) { | 389 browser_context_)) { |
375 scoped_ptr<developer::ExtensionInfo> info = | 390 scoped_ptr<developer::ExtensionInfo> info = |
(...skipping 12 matching lines...) Expand all Loading... | |
388 } | 403 } |
389 if (include_terminated) { | 404 if (include_terminated) { |
390 add_to_list(registry->terminated_extensions(), | 405 add_to_list(registry->terminated_extensions(), |
391 developer::EXTENSION_STATE_TERMINATED); | 406 developer::EXTENSION_STATE_TERMINATED); |
392 } | 407 } |
393 | 408 |
394 return list; | 409 return list; |
395 } | 410 } |
396 | 411 |
397 } // namespace extensions | 412 } // namespace extensions |
OLD | NEW |