| 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()); |
| 83 } | 82 } |
| 84 | 83 |
| 85 // Given a ManifestError object, converts it into its developer_private | 84 // Given a ManifestError object, converts it into its developer_private |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 357 |
| 359 info->version = extension.GetVersionForDisplay(); | 358 info->version = extension.GetVersionForDisplay(); |
| 360 | 359 |
| 361 if (state != developer::EXTENSION_STATE_TERMINATED) { | 360 if (state != developer::EXTENSION_STATE_TERMINATED) { |
| 362 info->views = InspectableViewsFinder(profile, nullptr). | 361 info->views = InspectableViewsFinder(profile, nullptr). |
| 363 GetViewsForExtension(extension, is_enabled); | 362 GetViewsForExtension(extension, is_enabled); |
| 364 } | 363 } |
| 365 return info.Pass(); | 364 return info.Pass(); |
| 366 } | 365 } |
| 367 | 366 |
| 367 scoped_ptr<api::developer_private::ExtensionInfo> |
| 368 ExtensionInfoGenerator::CreateExtensionInfo(const std::string& id) { |
| 369 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_); |
| 370 |
| 371 const Extension* enabled = registry->enabled_extensions().GetByID(id); |
| 372 if (enabled && |
| 373 ui_util::ShouldDisplayInExtensionSettings(enabled, browser_context_)) { |
| 374 return CreateExtensionInfo(*enabled, developer::EXTENSION_STATE_ENABLED); |
| 375 } |
| 376 |
| 377 const Extension* disabled = registry->disabled_extensions().GetByID(id); |
| 378 if (disabled && |
| 379 ui_util::ShouldDisplayInExtensionSettings(disabled, browser_context_)) { |
| 380 return CreateExtensionInfo(*disabled, developer::EXTENSION_STATE_DISABLED); |
| 381 } |
| 382 |
| 383 const Extension* terminated = registry->terminated_extensions().GetByID(id); |
| 384 if (terminated && |
| 385 ui_util::ShouldDisplayInExtensionSettings(terminated, browser_context_)) { |
| 386 return CreateExtensionInfo(*terminated, |
| 387 developer::EXTENSION_STATE_TERMINATED); |
| 388 } |
| 389 |
| 390 return scoped_ptr<api::developer_private::ExtensionInfo>(); |
| 391 } |
| 392 |
| 368 ExtensionInfoGenerator::ExtensionInfoList | 393 ExtensionInfoGenerator::ExtensionInfoList |
| 369 ExtensionInfoGenerator::CreateExtensionsInfo(bool include_disabled, | 394 ExtensionInfoGenerator::CreateExtensionsInfo(bool include_disabled, |
| 370 bool include_terminated) { | 395 bool include_terminated) { |
| 371 std::vector<linked_ptr<developer::ExtensionInfo>> list; | 396 std::vector<linked_ptr<developer::ExtensionInfo>> list; |
| 372 auto add_to_list = [this, &list](const ExtensionSet& extensions, | 397 auto add_to_list = [this, &list](const ExtensionSet& extensions, |
| 373 developer::ExtensionState state) { | 398 developer::ExtensionState state) { |
| 374 for (const scoped_refptr<const Extension>& extension : extensions) { | 399 for (const scoped_refptr<const Extension>& extension : extensions) { |
| 375 if (ui_util::ShouldDisplayInExtensionSettings(extension.get(), | 400 if (ui_util::ShouldDisplayInExtensionSettings(extension.get(), |
| 376 browser_context_)) { | 401 browser_context_)) { |
| 377 scoped_ptr<developer::ExtensionInfo> info = | 402 scoped_ptr<developer::ExtensionInfo> info = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 390 } | 415 } |
| 391 if (include_terminated) { | 416 if (include_terminated) { |
| 392 add_to_list(registry->terminated_extensions(), | 417 add_to_list(registry->terminated_extensions(), |
| 393 developer::EXTENSION_STATE_TERMINATED); | 418 developer::EXTENSION_STATE_TERMINATED); |
| 394 } | 419 } |
| 395 | 420 |
| 396 return list; | 421 return list; |
| 397 } | 422 } |
| 398 | 423 |
| 399 } // namespace extensions | 424 } // namespace extensions |
| OLD | NEW |