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

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

Issue 1049483003: [Extensions] Update extensions UI to observe events and add test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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());
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
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 developer::ExtensionState state = developer::EXTENSION_STATE_ENABLED;
370 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_);
371 const Extension* extension = registry->enabled_extensions().GetByID(id);
Dan Beam 2015/04/06 23:53:12 nit: this is easier for me to read: const Extensi
Devlin 2015/04/07 16:07:54 As you wish.
372 if (!extension &&
373 (extension = registry->disabled_extensions().GetByID(id)) != nullptr) {
374 state = developer::EXTENSION_STATE_DISABLED;
375 } else if (!extension &&
376 (extension =
377 registry->terminated_extensions().GetByID(id)) != nullptr) {
378 state = developer::EXTENSION_STATE_TERMINATED;
379 }
380 scoped_ptr<api::developer_private::ExtensionInfo> info;
381 if (extension)
382 info = CreateExtensionInfo(*extension, state);
383 return info.Pass();
384 }
385
368 ExtensionInfoGenerator::ExtensionInfoList 386 ExtensionInfoGenerator::ExtensionInfoList
369 ExtensionInfoGenerator::CreateExtensionsInfo(bool include_disabled, 387 ExtensionInfoGenerator::CreateExtensionsInfo(bool include_disabled,
370 bool include_terminated) { 388 bool include_terminated) {
371 std::vector<linked_ptr<developer::ExtensionInfo>> list; 389 std::vector<linked_ptr<developer::ExtensionInfo>> list;
372 auto add_to_list = [this, &list](const ExtensionSet& extensions, 390 auto add_to_list = [this, &list](const ExtensionSet& extensions,
373 developer::ExtensionState state) { 391 developer::ExtensionState state) {
374 for (const scoped_refptr<const Extension>& extension : extensions) { 392 for (const scoped_refptr<const Extension>& extension : extensions) {
375 if (ui_util::ShouldDisplayInExtensionSettings(extension.get(), 393 if (ui_util::ShouldDisplayInExtensionSettings(extension.get(),
376 browser_context_)) { 394 browser_context_)) {
377 scoped_ptr<developer::ExtensionInfo> info = 395 scoped_ptr<developer::ExtensionInfo> info =
(...skipping 12 matching lines...) Expand all
390 } 408 }
391 if (include_terminated) { 409 if (include_terminated) {
392 add_to_list(registry->terminated_extensions(), 410 add_to_list(registry->terminated_extensions(),
393 developer::EXTENSION_STATE_TERMINATED); 411 developer::EXTENSION_STATE_TERMINATED);
394 } 412 }
395 413
396 return list; 414 return list;
397 } 415 }
398 416
399 } // namespace extensions 417 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698