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

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

Issue 1092953004: [Extensions] Update developerPrivate API to use base-64 data urls for icons (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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/developer_private_api. h" 5 #include "chrome/browser/extensions/api/developer_private/developer_private_api. h"
6 6
7 #include "base/base64.h"
8 #include "base/bind.h" 7 #include "base/bind.h"
9 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
10 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
11 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/devtools/devtools_window.h" 14 #include "chrome/browser/devtools/devtools_window.h"
16 #include "chrome/browser/extensions/api/developer_private/developer_private_mang le.h" 15 #include "chrome/browser/extensions/api/developer_private/developer_private_mang le.h"
17 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" 16 #include "chrome/browser/extensions/api/developer_private/entry_picker.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #include "extensions/browser/error_map.h" 53 #include "extensions/browser/error_map.h"
55 #include "extensions/browser/extension_error.h" 54 #include "extensions/browser/extension_error.h"
56 #include "extensions/browser/extension_prefs.h" 55 #include "extensions/browser/extension_prefs.h"
57 #include "extensions/browser/extension_registry.h" 56 #include "extensions/browser/extension_registry.h"
58 #include "extensions/browser/extension_system.h" 57 #include "extensions/browser/extension_system.h"
59 #include "extensions/browser/file_highlighter.h" 58 #include "extensions/browser/file_highlighter.h"
60 #include "extensions/browser/management_policy.h" 59 #include "extensions/browser/management_policy.h"
61 #include "extensions/browser/notification_types.h" 60 #include "extensions/browser/notification_types.h"
62 #include "extensions/browser/warning_service.h" 61 #include "extensions/browser/warning_service.h"
63 #include "extensions/common/constants.h" 62 #include "extensions/common/constants.h"
64 #include "extensions/common/extension_resource.h"
65 #include "extensions/common/extension_set.h" 63 #include "extensions/common/extension_set.h"
66 #include "extensions/common/feature_switch.h" 64 #include "extensions/common/feature_switch.h"
67 #include "extensions/common/install_warning.h" 65 #include "extensions/common/install_warning.h"
68 #include "extensions/common/manifest.h" 66 #include "extensions/common/manifest.h"
69 #include "extensions/common/manifest_handlers/icons_handler.h"
70 #include "extensions/common/manifest_handlers/options_page_info.h" 67 #include "extensions/common/manifest_handlers/options_page_info.h"
71 #include "extensions/common/permissions/permissions_data.h" 68 #include "extensions/common/permissions/permissions_data.h"
72 #include "extensions/grit/extensions_browser_resources.h" 69 #include "extensions/grit/extensions_browser_resources.h"
73 #include "storage/browser/fileapi/external_mount_points.h" 70 #include "storage/browser/fileapi/external_mount_points.h"
74 #include "storage/browser/fileapi/file_system_context.h" 71 #include "storage/browser/fileapi/file_system_context.h"
75 #include "storage/browser/fileapi/file_system_operation.h" 72 #include "storage/browser/fileapi/file_system_operation.h"
76 #include "storage/browser/fileapi/file_system_operation_runner.h" 73 #include "storage/browser/fileapi/file_system_operation_runner.h"
77 #include "storage/browser/fileapi/isolated_context.h" 74 #include "storage/browser/fileapi/isolated_context.h"
78 #include "ui/base/l10n/l10n_util.h" 75 #include "ui/base/l10n/l10n_util.h"
79 #include "ui/base/resource/resource_bundle.h"
80 76
81 namespace extensions { 77 namespace extensions {
82 78
83 namespace developer_private = api::developer_private; 79 namespace developer = api::developer_private;
84 80
85 namespace { 81 namespace {
86 82
87 const char kNoSuchExtensionError[] = "No such extension."; 83 const char kNoSuchExtensionError[] = "No such extension.";
88 const char kCannotModifyPolicyExtensionError[] = 84 const char kCannotModifyPolicyExtensionError[] =
89 "Cannot modify the extension by policy."; 85 "Cannot modify the extension by policy.";
90 const char kRequiresUserGestureError[] = 86 const char kRequiresUserGestureError[] =
91 "This action requires a user gesture."; 87 "This action requires a user gesture.";
92 const char kCouldNotShowSelectFileDialogError[] = 88 const char kCouldNotShowSelectFileDialogError[] =
93 "Could not show a file chooser."; 89 "Could not show a file chooser.";
(...skipping 10 matching lines...) Expand all
104 const char kNoOptionsPageForExtensionError[] = 100 const char kNoOptionsPageForExtensionError[] =
105 "Extension does not have an options page."; 101 "Extension does not have an options page.";
106 102
107 const char kUnpackedAppsFolder[] = "apps_target"; 103 const char kUnpackedAppsFolder[] = "apps_target";
108 const char kManifestFile[] = "manifest.json"; 104 const char kManifestFile[] = "manifest.json";
109 105
110 ExtensionService* GetExtensionService(content::BrowserContext* context) { 106 ExtensionService* GetExtensionService(content::BrowserContext* context) {
111 return ExtensionSystem::Get(context)->extension_service(); 107 return ExtensionSystem::Get(context)->extension_service();
112 } 108 }
113 109
114 GURL GetImageURLFromData(const std::string& contents) {
115 std::string contents_base64;
116 base::Base64Encode(contents, &contents_base64);
117
118 // TODO(dvh): make use of content::kDataScheme. Filed as crbug/297301.
119 const char kDataURLPrefix[] = "data:;base64,";
120 return GURL(kDataURLPrefix + contents_base64);
121 }
122
123 GURL GetDefaultImageURL(developer_private::ItemType type) {
124 int icon_resource_id;
125 switch (type) {
126 case developer::ITEM_TYPE_LEGACY_PACKAGED_APP:
127 case developer::ITEM_TYPE_HOSTED_APP:
128 case developer::ITEM_TYPE_PACKAGED_APP:
129 icon_resource_id = IDR_APP_DEFAULT_ICON;
130 break;
131 default:
132 icon_resource_id = IDR_EXTENSION_DEFAULT_ICON;
133 break;
134 }
135
136 return GetImageURLFromData(
137 ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
138 icon_resource_id, ui::SCALE_FACTOR_100P).as_string());
139 }
140
141 // TODO(dvh): This code should be refactored and moved to
142 // extensions::ImageLoader. Also a resize should be performed to avoid
143 // potential huge URLs: crbug/297298.
144 GURL ToDataURL(const base::FilePath& path, developer_private::ItemType type) {
145 std::string contents;
146 if (path.empty() || !base::ReadFileToString(path, &contents))
147 return GetDefaultImageURL(type);
148
149 return GetImageURLFromData(contents);
150 }
151
152 void BroadcastItemStateChanged(content::BrowserContext* browser_context,
153 developer::EventType event_type,
154 const std::string& item_id) {
155 developer::EventData event_data;
156 event_data.event_type = event_type;
157 event_data.item_id = item_id;
158 event_data.extension_info =
159 ExtensionInfoGenerator(browser_context).CreateExtensionInfo(item_id);
160
161 scoped_ptr<base::ListValue> args(new base::ListValue());
162 args->Append(event_data.ToValue().release());
163 scoped_ptr<Event> event(new Event(
164 developer_private::OnItemStateChanged::kEventName, args.Pass()));
165 EventRouter::Get(browser_context)->BroadcastEvent(event.Pass());
166 }
167
168 std::string ReadFileToString(const base::FilePath& path) { 110 std::string ReadFileToString(const base::FilePath& path) {
169 std::string data; 111 std::string data;
170 ignore_result(base::ReadFileToString(path, &data)); 112 ignore_result(base::ReadFileToString(path, &data));
171 return data; 113 return data;
172 } 114 }
173 115
174 bool UserCanModifyExtensionConfiguration( 116 bool UserCanModifyExtensionConfiguration(
175 const Extension* extension, 117 const Extension* extension,
176 content::BrowserContext* browser_context, 118 content::BrowserContext* browser_context,
177 std::string* error) { 119 std::string* error) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 : profile_(Profile::FromBrowserContext(context)) { 181 : profile_(Profile::FromBrowserContext(context)) {
240 RegisterNotifications(); 182 RegisterNotifications();
241 } 183 }
242 184
243 DeveloperPrivateEventRouter::DeveloperPrivateEventRouter(Profile* profile) 185 DeveloperPrivateEventRouter::DeveloperPrivateEventRouter(Profile* profile)
244 : extension_registry_observer_(this), 186 : extension_registry_observer_(this),
245 error_console_observer_(this), 187 error_console_observer_(this),
246 process_manager_observer_(this), 188 process_manager_observer_(this),
247 app_window_registry_observer_(this), 189 app_window_registry_observer_(this),
248 extension_action_api_observer_(this), 190 extension_action_api_observer_(this),
249 profile_(profile) { 191 profile_(profile),
192 event_router_(EventRouter::Get(profile_)),
193 weak_factory_(this) {
250 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); 194 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_));
251 error_console_observer_.Add(ErrorConsole::Get(profile)); 195 error_console_observer_.Add(ErrorConsole::Get(profile));
252 process_manager_observer_.Add(ProcessManager::Get(profile)); 196 process_manager_observer_.Add(ProcessManager::Get(profile));
253 app_window_registry_observer_.Add(AppWindowRegistry::Get(profile)); 197 app_window_registry_observer_.Add(AppWindowRegistry::Get(profile));
254 extension_action_api_observer_.Add(ExtensionActionAPI::Get(profile)); 198 extension_action_api_observer_.Add(ExtensionActionAPI::Get(profile));
255 } 199 }
256 200
257 DeveloperPrivateEventRouter::~DeveloperPrivateEventRouter() { 201 DeveloperPrivateEventRouter::~DeveloperPrivateEventRouter() {
258 } 202 }
259 203
260 void DeveloperPrivateEventRouter::AddExtensionId( 204 void DeveloperPrivateEventRouter::AddExtensionId(
261 const std::string& extension_id) { 205 const std::string& extension_id) {
262 extension_ids_.insert(extension_id); 206 extension_ids_.insert(extension_id);
263 } 207 }
264 208
265 void DeveloperPrivateEventRouter::RemoveExtensionId( 209 void DeveloperPrivateEventRouter::RemoveExtensionId(
266 const std::string& extension_id) { 210 const std::string& extension_id) {
267 extension_ids_.erase(extension_id); 211 extension_ids_.erase(extension_id);
268 } 212 }
269 213
270 void DeveloperPrivateEventRouter::OnExtensionLoaded( 214 void DeveloperPrivateEventRouter::OnExtensionLoaded(
271 content::BrowserContext* browser_context, 215 content::BrowserContext* browser_context,
272 const Extension* extension) { 216 const Extension* extension) {
273 DCHECK(profile_->IsSameProfile(Profile::FromBrowserContext(browser_context))); 217 DCHECK(profile_->IsSameProfile(Profile::FromBrowserContext(browser_context)));
274 BroadcastItemStateChanged( 218 BroadcastItemStateChanged(developer::EVENT_TYPE_LOADED, extension->id());
275 browser_context, developer::EVENT_TYPE_LOADED, extension->id());
276 } 219 }
277 220
278 void DeveloperPrivateEventRouter::OnExtensionUnloaded( 221 void DeveloperPrivateEventRouter::OnExtensionUnloaded(
279 content::BrowserContext* browser_context, 222 content::BrowserContext* browser_context,
280 const Extension* extension, 223 const Extension* extension,
281 UnloadedExtensionInfo::Reason reason) { 224 UnloadedExtensionInfo::Reason reason) {
282 DCHECK(profile_->IsSameProfile(Profile::FromBrowserContext(browser_context))); 225 DCHECK(profile_->IsSameProfile(Profile::FromBrowserContext(browser_context)));
283 BroadcastItemStateChanged( 226 BroadcastItemStateChanged(developer::EVENT_TYPE_UNLOADED, extension->id());
284 browser_context, developer::EVENT_TYPE_UNLOADED, extension->id());
285 } 227 }
286 228
287 void DeveloperPrivateEventRouter::OnExtensionWillBeInstalled( 229 void DeveloperPrivateEventRouter::OnExtensionWillBeInstalled(
288 content::BrowserContext* browser_context, 230 content::BrowserContext* browser_context,
289 const Extension* extension, 231 const Extension* extension,
290 bool is_update, 232 bool is_update,
291 bool from_ephemeral, 233 bool from_ephemeral,
292 const std::string& old_name) { 234 const std::string& old_name) {
293 DCHECK(profile_->IsSameProfile(Profile::FromBrowserContext(browser_context))); 235 DCHECK(profile_->IsSameProfile(Profile::FromBrowserContext(browser_context)));
294 BroadcastItemStateChanged( 236 BroadcastItemStateChanged(developer::EVENT_TYPE_INSTALLED, extension->id());
295 browser_context, developer::EVENT_TYPE_INSTALLED, extension->id());
296 } 237 }
297 238
298 void DeveloperPrivateEventRouter::OnExtensionUninstalled( 239 void DeveloperPrivateEventRouter::OnExtensionUninstalled(
299 content::BrowserContext* browser_context, 240 content::BrowserContext* browser_context,
300 const Extension* extension, 241 const Extension* extension,
301 extensions::UninstallReason reason) { 242 extensions::UninstallReason reason) {
302 DCHECK(profile_->IsSameProfile(Profile::FromBrowserContext(browser_context))); 243 DCHECK(profile_->IsSameProfile(Profile::FromBrowserContext(browser_context)));
303 BroadcastItemStateChanged( 244 BroadcastItemStateChanged(developer::EVENT_TYPE_UNINSTALLED, extension->id());
304 browser_context, developer::EVENT_TYPE_UNINSTALLED, extension->id());
305 } 245 }
306 246
307 void DeveloperPrivateEventRouter::OnErrorAdded(const ExtensionError* error) { 247 void DeveloperPrivateEventRouter::OnErrorAdded(const ExtensionError* error) {
308 // We don't want to handle errors thrown by extensions subscribed to these 248 // We don't want to handle errors thrown by extensions subscribed to these
309 // events (currently only the Apps Developer Tool), because doing so risks 249 // events (currently only the Apps Developer Tool), because doing so risks
310 // entering a loop. 250 // entering a loop.
311 if (extension_ids_.find(error->extension_id()) != extension_ids_.end()) 251 if (extension_ids_.find(error->extension_id()) != extension_ids_.end())
312 return; 252 return;
313 253
314 BroadcastItemStateChanged( 254 BroadcastItemStateChanged(developer::EVENT_TYPE_ERROR_ADDED,
315 profile_, developer::EVENT_TYPE_ERROR_ADDED, error->extension_id()); 255 error->extension_id());
316 } 256 }
317 257
318 void DeveloperPrivateEventRouter::OnExtensionFrameRegistered( 258 void DeveloperPrivateEventRouter::OnExtensionFrameRegistered(
319 const std::string& extension_id, 259 const std::string& extension_id,
320 content::RenderFrameHost* render_frame_host) { 260 content::RenderFrameHost* render_frame_host) {
321 BroadcastItemStateChanged( 261 BroadcastItemStateChanged(developer::EVENT_TYPE_VIEW_REGISTERED,
322 profile_, developer::EVENT_TYPE_VIEW_REGISTERED, extension_id); 262 extension_id);
323 } 263 }
324 264
325 void DeveloperPrivateEventRouter::OnExtensionFrameUnregistered( 265 void DeveloperPrivateEventRouter::OnExtensionFrameUnregistered(
326 const std::string& extension_id, 266 const std::string& extension_id,
327 content::RenderFrameHost* render_frame_host) { 267 content::RenderFrameHost* render_frame_host) {
328 BroadcastItemStateChanged( 268 BroadcastItemStateChanged(developer::EVENT_TYPE_VIEW_UNREGISTERED,
329 profile_, developer::EVENT_TYPE_VIEW_UNREGISTERED, extension_id); 269 extension_id);
330 } 270 }
331 271
332 void DeveloperPrivateEventRouter::OnAppWindowAdded(AppWindow* window) { 272 void DeveloperPrivateEventRouter::OnAppWindowAdded(AppWindow* window) {
333 BroadcastItemStateChanged( 273 BroadcastItemStateChanged(developer::EVENT_TYPE_VIEW_REGISTERED,
334 profile_, developer::EVENT_TYPE_VIEW_REGISTERED, window->extension_id()); 274 window->extension_id());
335 } 275 }
336 276
337 void DeveloperPrivateEventRouter::OnAppWindowRemoved(AppWindow* window) { 277 void DeveloperPrivateEventRouter::OnAppWindowRemoved(AppWindow* window) {
338 BroadcastItemStateChanged(profile_, 278 BroadcastItemStateChanged(developer::EVENT_TYPE_VIEW_UNREGISTERED,
339 developer::EVENT_TYPE_VIEW_UNREGISTERED,
340 window->extension_id()); 279 window->extension_id());
341 } 280 }
342 281
343 void DeveloperPrivateEventRouter::OnExtensionActionVisibilityChanged( 282 void DeveloperPrivateEventRouter::OnExtensionActionVisibilityChanged(
344 const std::string& extension_id, 283 const std::string& extension_id,
345 bool is_now_visible) { 284 bool is_now_visible) {
346 BroadcastItemStateChanged( 285 BroadcastItemStateChanged(developer::EVENT_TYPE_PREFS_CHANGED, extension_id);
347 profile_, developer::EVENT_TYPE_PREFS_CHANGED, extension_id); 286 }
287
288 void DeveloperPrivateEventRouter::BroadcastItemStateChanged(
289 developer::EventType event_type,
290 const std::string& extension_id) {
291 scoped_ptr<ExtensionInfoGenerator> info_generator(
292 new ExtensionInfoGenerator(profile_));
293 ExtensionInfoGenerator* info_generator_weak = info_generator.get();
294 info_generator_weak->CreateExtensionInfo(
295 extension_id,
296 base::Bind(&DeveloperPrivateEventRouter::BroadcastItemStateChangedHelper,
297 weak_factory_.GetWeakPtr(),
298 event_type,
299 extension_id,
300 base::Passed(info_generator.Pass())));
301 }
302
303 void DeveloperPrivateEventRouter::BroadcastItemStateChangedHelper(
304 developer::EventType event_type,
305 const std::string& extension_id,
306 scoped_ptr<ExtensionInfoGenerator> info_generator,
307 const ExtensionInfoGenerator::ExtensionInfoList& infos) {
308 DCHECK_LE(infos.size(), 1u);
309
310 developer::EventData event_data;
311 event_data.event_type = event_type;
312 event_data.item_id = extension_id;
313 scoped_ptr<base::DictionaryValue> dict = event_data.ToValue();
314
315 if (!infos.empty()) {
316 // Hack: Ideally, we would use event_data.extension_info to set the
317 // extension info, but since it's an optional field, it's implemented as a
318 // scoped ptr, and so ownership between that and the vector of linked ptrs
319 // here is, well, messy. Easier to just set it like this.
320 dict->SetWithoutPathExpansion("extensionInfo",
321 infos[0]->ToValue().release());
322 }
323
324 scoped_ptr<base::ListValue> args(new base::ListValue());
325 args->Append(dict.release());
326 scoped_ptr<Event> event(new Event(
327 developer::OnItemStateChanged::kEventName, args.Pass()));
328 event_router_->BroadcastEvent(event.Pass());
348 } 329 }
349 330
350 void DeveloperPrivateAPI::SetLastUnpackedDirectory(const base::FilePath& path) { 331 void DeveloperPrivateAPI::SetLastUnpackedDirectory(const base::FilePath& path) {
351 last_unpacked_directory_ = path; 332 last_unpacked_directory_ = path;
352 } 333 }
353 334
354 void DeveloperPrivateAPI::RegisterNotifications() { 335 void DeveloperPrivateAPI::RegisterNotifications() {
355 EventRouter::Get(profile_)->RegisterObserver( 336 EventRouter::Get(profile_)->RegisterObserver(
356 this, developer_private::OnItemStateChanged::kEventName); 337 this, developer::OnItemStateChanged::kEventName);
357 } 338 }
358 339
359 DeveloperPrivateAPI::~DeveloperPrivateAPI() {} 340 DeveloperPrivateAPI::~DeveloperPrivateAPI() {}
360 341
361 void DeveloperPrivateAPI::Shutdown() {} 342 void DeveloperPrivateAPI::Shutdown() {}
362 343
363 void DeveloperPrivateAPI::OnListenerAdded( 344 void DeveloperPrivateAPI::OnListenerAdded(
364 const EventListenerInfo& details) { 345 const EventListenerInfo& details) {
365 if (!developer_private_event_router_) { 346 if (!developer_private_event_router_) {
366 developer_private_event_router_.reset( 347 developer_private_event_router_.reset(
367 new DeveloperPrivateEventRouter(profile_)); 348 new DeveloperPrivateEventRouter(profile_));
368 } 349 }
369 350
370 developer_private_event_router_->AddExtensionId(details.extension_id); 351 developer_private_event_router_->AddExtensionId(details.extension_id);
371 } 352 }
372 353
373 void DeveloperPrivateAPI::OnListenerRemoved( 354 void DeveloperPrivateAPI::OnListenerRemoved(
374 const EventListenerInfo& details) { 355 const EventListenerInfo& details) {
375 if (!EventRouter::Get(profile_)->HasEventListener( 356 if (!EventRouter::Get(profile_)->HasEventListener(
376 developer_private::OnItemStateChanged::kEventName)) { 357 developer::OnItemStateChanged::kEventName)) {
377 developer_private_event_router_.reset(NULL); 358 developer_private_event_router_.reset(NULL);
378 } else { 359 } else {
379 developer_private_event_router_->RemoveExtensionId(details.extension_id); 360 developer_private_event_router_->RemoveExtensionId(details.extension_id);
380 } 361 }
381 } 362 }
382 363
383 namespace api { 364 namespace api {
384 365
385 DeveloperPrivateAPIFunction::~DeveloperPrivateAPIFunction() { 366 DeveloperPrivateAPIFunction::~DeveloperPrivateAPIFunction() {
386 } 367 }
(...skipping 17 matching lines...) Expand all
404 ExtensionSystem::Get(browser_context())->extension_service()->updater(); 385 ExtensionSystem::Get(browser_context())->extension_service()->updater();
405 if (updater) { 386 if (updater) {
406 ExtensionUpdater::CheckParams params; 387 ExtensionUpdater::CheckParams params;
407 params.install_immediately = true; 388 params.install_immediately = true;
408 updater->CheckNow(params); 389 updater->CheckNow(params);
409 } 390 }
410 return RespondNow(NoArguments()); 391 return RespondNow(NoArguments());
411 } 392 }
412 393
413 DeveloperPrivateGetExtensionsInfoFunction:: 394 DeveloperPrivateGetExtensionsInfoFunction::
395 DeveloperPrivateGetExtensionsInfoFunction() {
396 }
397
398 DeveloperPrivateGetExtensionsInfoFunction::
414 ~DeveloperPrivateGetExtensionsInfoFunction() { 399 ~DeveloperPrivateGetExtensionsInfoFunction() {
415 } 400 }
416 401
417 ExtensionFunction::ResponseAction 402 ExtensionFunction::ResponseAction
418 DeveloperPrivateGetExtensionsInfoFunction::Run() { 403 DeveloperPrivateGetExtensionsInfoFunction::Run() {
419 scoped_ptr<developer::GetExtensionsInfo::Params> params( 404 scoped_ptr<developer::GetExtensionsInfo::Params> params(
420 developer::GetExtensionsInfo::Params::Create(*args_)); 405 developer::GetExtensionsInfo::Params::Create(*args_));
421 EXTENSION_FUNCTION_VALIDATE(params); 406 EXTENSION_FUNCTION_VALIDATE(params);
422 407
423 bool include_disabled = true; 408 bool include_disabled = true;
424 bool include_terminated = true; 409 bool include_terminated = true;
425 if (params->options) { 410 if (params->options) {
426 if (params->options->include_disabled) 411 if (params->options->include_disabled)
427 include_disabled = *params->options->include_disabled; 412 include_disabled = *params->options->include_disabled;
428 if (params->options->include_terminated) 413 if (params->options->include_terminated)
429 include_terminated = *params->options->include_terminated; 414 include_terminated = *params->options->include_terminated;
430 } 415 }
431 416
432 std::vector<linked_ptr<developer::ExtensionInfo>> list = 417 info_generator_.reset(new ExtensionInfoGenerator(browser_context()));
433 ExtensionInfoGenerator(browser_context()). 418 info_generator_->CreateExtensionsInfo(
434 CreateExtensionsInfo(include_disabled, include_terminated); 419 include_disabled,
420 include_terminated,
421 base::Bind(&DeveloperPrivateGetExtensionsInfoFunction::OnInfosGenerated,
422 this /* refcounted */));
435 423
436 return RespondNow(ArgumentList( 424 return RespondLater();
437 developer::GetExtensionsInfo::Results::Create(list))); 425 }
426
427 void DeveloperPrivateGetExtensionsInfoFunction::OnInfosGenerated(
428 const ExtensionInfoGenerator::ExtensionInfoList& list) {
429 Respond(ArgumentList(developer::GetExtensionsInfo::Results::Create(list)));
438 } 430 }
439 431
440 DeveloperPrivateGetExtensionInfoFunction:: 432 DeveloperPrivateGetExtensionInfoFunction::
433 DeveloperPrivateGetExtensionInfoFunction() {
434 }
435
436 DeveloperPrivateGetExtensionInfoFunction::
441 ~DeveloperPrivateGetExtensionInfoFunction() { 437 ~DeveloperPrivateGetExtensionInfoFunction() {
442 } 438 }
443 439
444 ExtensionFunction::ResponseAction 440 ExtensionFunction::ResponseAction
445 DeveloperPrivateGetExtensionInfoFunction::Run() { 441 DeveloperPrivateGetExtensionInfoFunction::Run() {
446 scoped_ptr<developer::GetExtensionInfo::Params> params( 442 scoped_ptr<developer::GetExtensionInfo::Params> params(
447 developer::GetExtensionInfo::Params::Create(*args_)); 443 developer::GetExtensionInfo::Params::Create(*args_));
448 EXTENSION_FUNCTION_VALIDATE(params); 444 EXTENSION_FUNCTION_VALIDATE(params);
449 445
450 scoped_ptr<developer::ExtensionInfo> info = 446 info_generator_.reset(new ExtensionInfoGenerator(browser_context()));
451 ExtensionInfoGenerator(browser_context()).CreateExtensionInfo(params->id); 447 info_generator_->CreateExtensionInfo(
448 params->id,
449 base::Bind(&DeveloperPrivateGetExtensionInfoFunction::OnInfosGenerated,
450 this /* refcounted */));
452 451
453 if (!info) 452 return RespondLater();
454 return RespondNow(Error(kNoSuchExtensionError)); 453 }
455 454
456 return RespondNow(OneArgument(info->ToValue().release())); 455 void DeveloperPrivateGetExtensionInfoFunction::OnInfosGenerated(
456 const ExtensionInfoGenerator::ExtensionInfoList& list) {
457 DCHECK_EQ(1u, list.size());
458 const linked_ptr<developer::ExtensionInfo>& info = list[0];
459 Respond(info.get() ? OneArgument(info->ToValue().release()) :
not at google - send to devlin 2015/04/22 21:38:37 there is a version of OneArgument which takes a sc
Devlin 2015/04/23 19:17:21 Oh yeah, forgot I added that. Done.
460 Error(kNoSuchExtensionError));
457 } 461 }
458 462
459 DeveloperPrivateGetItemsInfoFunction::DeveloperPrivateGetItemsInfoFunction() {} 463 DeveloperPrivateGetItemsInfoFunction::DeveloperPrivateGetItemsInfoFunction() {}
460 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {} 464 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {}
461 465
462 ExtensionFunction::ResponseAction DeveloperPrivateGetItemsInfoFunction::Run() { 466 ExtensionFunction::ResponseAction DeveloperPrivateGetItemsInfoFunction::Run() {
463 scoped_ptr<developer::GetItemsInfo::Params> params( 467 scoped_ptr<developer::GetItemsInfo::Params> params(
464 developer::GetItemsInfo::Params::Create(*args_)); 468 developer::GetItemsInfo::Params::Create(*args_));
465 EXTENSION_FUNCTION_VALIDATE(params); 469 EXTENSION_FUNCTION_VALIDATE(params);
466 470
467 ExtensionSet items; 471 info_generator_.reset(new ExtensionInfoGenerator(browser_context()));
468 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context()); 472 info_generator_->CreateExtensionsInfo(
469 items.InsertAll(registry->enabled_extensions()); 473 params->include_disabled,
470 474 params->include_terminated,
471 if (params->include_disabled) 475 base::Bind(&DeveloperPrivateGetItemsInfoFunction::OnInfosGenerated,
472 items.InsertAll(registry->disabled_extensions()); 476 this /* refcounted */));
473 if (params->include_terminated)
474 items.InsertAll(registry->terminated_extensions());
475
476 std::map<std::string, ExtensionResource> resource_map;
477 for (const scoped_refptr<const Extension>& item : items) {
478 // Don't show component extensions and invisible apps.
479 if (ui_util::ShouldDisplayInExtensionSettings(item.get(),
480 browser_context())) {
481 resource_map[item->id()] =
482 IconsInfo::GetIconResource(item.get(),
483 extension_misc::EXTENSION_ICON_MEDIUM,
484 ExtensionIconSet::MATCH_BIGGER);
485 }
486 }
487
488 std::vector<linked_ptr<developer::ExtensionInfo>> list =
489 ExtensionInfoGenerator(browser_context()).
490 CreateExtensionsInfo(params->include_disabled,
491 params->include_terminated);
492
493 for (const linked_ptr<developer::ExtensionInfo>& info : list)
494 item_list_.push_back(developer_private_mangle::MangleExtensionInfo(*info));
495
496 content::BrowserThread::PostTask(
497 content::BrowserThread::FILE,
498 FROM_HERE,
499 base::Bind(&DeveloperPrivateGetItemsInfoFunction::GetIconsOnFileThread,
500 this,
501 resource_map));
502 477
503 return RespondLater(); 478 return RespondLater();
504 } 479 }
505 480
506 void DeveloperPrivateGetItemsInfoFunction::GetIconsOnFileThread( 481 void DeveloperPrivateGetItemsInfoFunction::OnInfosGenerated(
507 const std::map<std::string, ExtensionResource> resource_map) { 482 const ExtensionInfoGenerator::ExtensionInfoList& list) {
508 for (const linked_ptr<developer::ItemInfo>& item : item_list_) { 483 std::vector<linked_ptr<developer::ItemInfo>> item_list;
509 auto resource = resource_map.find(item->id); 484 for (const linked_ptr<developer::ExtensionInfo>& info : list)
510 if (resource != resource_map.end()) { 485 item_list.push_back(developer_private_mangle::MangleExtensionInfo(*info));
511 item->icon_url = ToDataURL(resource->second.GetFilePath(),
512 item->type).spec();
513 }
514 }
515 486
516 content::BrowserThread::PostTask( 487 Respond(ArgumentList(developer::GetItemsInfo::Results::Create(item_list)));
517 content::BrowserThread::UI,
518 FROM_HERE,
519 base::Bind(&DeveloperPrivateGetItemsInfoFunction::Finish, this));
520 }
521
522 void DeveloperPrivateGetItemsInfoFunction::Finish() {
523 Respond(ArgumentList(developer::GetItemsInfo::Results::Create(item_list_)));
524 } 488 }
525 489
526 DeveloperPrivateGetProfileConfigurationFunction:: 490 DeveloperPrivateGetProfileConfigurationFunction::
527 ~DeveloperPrivateGetProfileConfigurationFunction() { 491 ~DeveloperPrivateGetProfileConfigurationFunction() {
528 } 492 }
529 493
530 ExtensionFunction::ResponseAction 494 ExtensionFunction::ResponseAction
531 DeveloperPrivateGetProfileConfigurationFunction::Run() { 495 DeveloperPrivateGetProfileConfigurationFunction::Run() {
532 developer::ProfileInfo info; 496 developer::ProfileInfo info;
533 info.is_supervised = GetProfile()->IsSupervised(); 497 info.is_supervised = GetProfile()->IsSupervised();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 642
679 void DeveloperPrivateShowPermissionsDialogFunction::Finish() { 643 void DeveloperPrivateShowPermissionsDialogFunction::Finish() {
680 Respond(NoArguments()); 644 Respond(NoArguments());
681 } 645 }
682 646
683 DeveloperPrivateLoadUnpackedFunction::DeveloperPrivateLoadUnpackedFunction() 647 DeveloperPrivateLoadUnpackedFunction::DeveloperPrivateLoadUnpackedFunction()
684 : fail_quietly_(false) { 648 : fail_quietly_(false) {
685 } 649 }
686 650
687 ExtensionFunction::ResponseAction DeveloperPrivateLoadUnpackedFunction::Run() { 651 ExtensionFunction::ResponseAction DeveloperPrivateLoadUnpackedFunction::Run() {
688 scoped_ptr<developer_private::LoadUnpacked::Params> params( 652 scoped_ptr<developer::LoadUnpacked::Params> params(
689 developer_private::LoadUnpacked::Params::Create(*args_)); 653 developer::LoadUnpacked::Params::Create(*args_));
690 EXTENSION_FUNCTION_VALIDATE(params); 654 EXTENSION_FUNCTION_VALIDATE(params);
691 655
692 if (!ShowPicker( 656 if (!ShowPicker(
693 ui::SelectFileDialog::SELECT_FOLDER, 657 ui::SelectFileDialog::SELECT_FOLDER,
694 l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY), 658 l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY),
695 ui::SelectFileDialog::FileTypeInfo(), 659 ui::SelectFileDialog::FileTypeInfo(),
696 0 /* file_type_index */)) { 660 0 /* file_type_index */)) {
697 return RespondNow(Error(kCouldNotShowSelectFileDialogError)); 661 return RespondNow(Error(kCouldNotShowSelectFileDialogError));
698 } 662 }
699 663
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 // We explicitly show manifest.json in order to work around an issue in OSX 1337 // We explicitly show manifest.json in order to work around an issue in OSX
1374 // where opening the directory doesn't focus the Finder. 1338 // where opening the directory doesn't focus the Finder.
1375 platform_util::ShowItemInFolder(GetProfile(), 1339 platform_util::ShowItemInFolder(GetProfile(),
1376 extension->path().Append(kManifestFilename)); 1340 extension->path().Append(kManifestFilename));
1377 return RespondNow(NoArguments()); 1341 return RespondNow(NoArguments());
1378 } 1342 }
1379 1343
1380 } // namespace api 1344 } // namespace api
1381 1345
1382 } // namespace extensions 1346 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698