Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: chrome/browser/extensions/api/developer_private/extension_info_generator.cc

Issue 1016413004: [Extensions] Update Error Console UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Dan's Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 85 // Given a ManifestError object, converts it into its developer_private
86 // counterpart. 86 // counterpart.
87 linked_ptr<developer::ManifestError> ConstructManifestError( 87 linked_ptr<developer::ManifestError> ConstructManifestError(
88 const ManifestError& error) { 88 const ManifestError& error) {
89 linked_ptr<developer::ManifestError> result(new developer::ManifestError()); 89 linked_ptr<developer::ManifestError> result(new developer::ManifestError());
90 PopulateErrorBase(error, result.get()); 90 PopulateErrorBase(error, result.get());
91 result->manifest_key = base::UTF16ToUTF8(error.manifest_key()); 91 result->manifest_key = base::UTF16ToUTF8(error.manifest_key());
92 if (!error.manifest_specific().empty()) { 92 if (!error.manifest_specific().empty()) {
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 358
359 info->version = extension.GetVersionForDisplay(); 359 info->version = extension.GetVersionForDisplay();
360 360
361 if (state != developer::EXTENSION_STATE_TERMINATED) { 361 if (state != developer::EXTENSION_STATE_TERMINATED) {
362 info->views = InspectableViewsFinder(profile, nullptr). 362 info->views = InspectableViewsFinder(profile, nullptr).
363 GetViewsForExtension(extension, is_enabled); 363 GetViewsForExtension(extension, is_enabled);
364 } 364 }
365 return info.Pass(); 365 return info.Pass();
366 } 366 }
367 367
368 scoped_ptr<api::developer_private::ExtensionInfo>
369 ExtensionInfoGenerator::CreateExtensionInfo(const std::string& id) {
370 developer::ExtensionState state = developer::EXTENSION_STATE_ENABLED;
371 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_);
372 const Extension* extension = registry->enabled_extensions().GetByID(id);
373 if (!extension &&
374 (extension = registry->disabled_extensions().GetByID(id)) != nullptr) {
375 state = developer::EXTENSION_STATE_DISABLED;
376 } else if (!extension &&
377 (extension =
378 registry->terminated_extensions().GetByID(id)) != nullptr) {
Dan Beam 2015/04/22 21:02:37 mildly scary but ok...
379 state = developer::EXTENSION_STATE_TERMINATED;
380 }
381 scoped_ptr<api::developer_private::ExtensionInfo> info;
382 if (extension)
383 info = CreateExtensionInfo(*extension, state);
384 return info.Pass();
385 }
386
368 ExtensionInfoGenerator::ExtensionInfoList 387 ExtensionInfoGenerator::ExtensionInfoList
369 ExtensionInfoGenerator::CreateExtensionsInfo(bool include_disabled, 388 ExtensionInfoGenerator::CreateExtensionsInfo(bool include_disabled,
370 bool include_terminated) { 389 bool include_terminated) {
371 std::vector<linked_ptr<developer::ExtensionInfo>> list; 390 std::vector<linked_ptr<developer::ExtensionInfo>> list;
372 auto add_to_list = [this, &list](const ExtensionSet& extensions, 391 auto add_to_list = [this, &list](const ExtensionSet& extensions,
373 developer::ExtensionState state) { 392 developer::ExtensionState state) {
374 for (const scoped_refptr<const Extension>& extension : extensions) { 393 for (const scoped_refptr<const Extension>& extension : extensions) {
375 if (ui_util::ShouldDisplayInExtensionSettings(extension.get(), 394 if (ui_util::ShouldDisplayInExtensionSettings(extension.get(),
376 browser_context_)) { 395 browser_context_)) {
377 scoped_ptr<developer::ExtensionInfo> info = 396 scoped_ptr<developer::ExtensionInfo> info =
(...skipping 12 matching lines...) Expand all
390 } 409 }
391 if (include_terminated) { 410 if (include_terminated) {
392 add_to_list(registry->terminated_extensions(), 411 add_to_list(registry->terminated_extensions(),
393 developer::EXTENSION_STATE_TERMINATED); 412 developer::EXTENSION_STATE_TERMINATED);
394 } 413 }
395 414
396 return list; 415 return list;
397 } 416 }
398 417
399 } // namespace extensions 418 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698