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

Side by Side Diff: chrome/browser/extensions/api/management/management_api.cc

Issue 11747025: Run the JSON Schema Compiler's bundle compilation on JSON files. Previously it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: restore missing registrations Created 7 years, 11 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 | Annotate | Revision Log
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/management/management_api.h" 5 #include "chrome/browser/extensions/api/management/management_api.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } // namespace 214 } // namespace
215 215
216 ExtensionService* ExtensionManagementFunction::service() { 216 ExtensionService* ExtensionManagementFunction::service() {
217 return profile()->GetExtensionService(); 217 return profile()->GetExtensionService();
218 } 218 }
219 219
220 ExtensionService* AsyncExtensionManagementFunction::service() { 220 ExtensionService* AsyncExtensionManagementFunction::service() {
221 return profile()->GetExtensionService(); 221 return profile()->GetExtensionService();
222 } 222 }
223 223
224 bool GetAllExtensionsFunction::RunImpl() { 224 bool ManagementGetAllFunction::RunImpl() {
225 ExtensionInfoList extensions; 225 ExtensionInfoList extensions;
226 ExtensionSystem* system = ExtensionSystem::Get(profile()); 226 ExtensionSystem* system = ExtensionSystem::Get(profile());
227 227
228 AddExtensionInfo(*service()->extensions(), system, &extensions); 228 AddExtensionInfo(*service()->extensions(), system, &extensions);
229 AddExtensionInfo(*service()->disabled_extensions(), system, &extensions); 229 AddExtensionInfo(*service()->disabled_extensions(), system, &extensions);
230 AddExtensionInfo(*service()->terminated_extensions(), system, &extensions); 230 AddExtensionInfo(*service()->terminated_extensions(), system, &extensions);
231 231
232 results_ = management::GetAll::Results::Create(extensions); 232 results_ = management::GetAll::Results::Create(extensions);
233 return true; 233 return true;
234 } 234 }
235 235
236 bool GetExtensionByIdFunction::RunImpl() { 236 bool ManagementGetFunction::RunImpl() {
237 scoped_ptr<management::Get::Params> params( 237 scoped_ptr<management::Get::Params> params(
238 management::Get::Params::Create(*args_)); 238 management::Get::Params::Create(*args_));
239 EXTENSION_FUNCTION_VALIDATE(params.get()); 239 EXTENSION_FUNCTION_VALIDATE(params.get());
240 240
241 const Extension* extension = service()->GetExtensionById(params->id, true); 241 const Extension* extension = service()->GetExtensionById(params->id, true);
242 if (!extension) { 242 if (!extension) {
243 error_ = ErrorUtils::FormatErrorMessage(keys::kNoExtensionError, 243 error_ = ErrorUtils::FormatErrorMessage(keys::kNoExtensionError,
244 params->id); 244 params->id);
245 return false; 245 return false;
246 } 246 }
247 247
248 scoped_ptr<management::ExtensionInfo> info = CreateExtensionInfo( 248 scoped_ptr<management::ExtensionInfo> info = CreateExtensionInfo(
249 *extension, ExtensionSystem::Get(profile())); 249 *extension, ExtensionSystem::Get(profile()));
250 results_ = management::Get::Results::Create(*info); 250 results_ = management::Get::Results::Create(*info);
251 251
252 return true; 252 return true;
253 } 253 }
254 254
255 bool GetPermissionWarningsByIdFunction::RunImpl() { 255 bool ManagementGetPermissionWarningsByIdFunction::RunImpl() {
256 scoped_ptr<management::GetPermissionWarningsById::Params> params( 256 scoped_ptr<management::GetPermissionWarningsById::Params> params(
257 management::GetPermissionWarningsById::Params::Create(*args_)); 257 management::GetPermissionWarningsById::Params::Create(*args_));
258 EXTENSION_FUNCTION_VALIDATE(params.get()); 258 EXTENSION_FUNCTION_VALIDATE(params.get());
259 259
260 const Extension* extension = service()->GetExtensionById(params->id, true); 260 const Extension* extension = service()->GetExtensionById(params->id, true);
261 if (!extension) { 261 if (!extension) {
262 error_ = ErrorUtils::FormatErrorMessage(keys::kNoExtensionError, 262 error_ = ErrorUtils::FormatErrorMessage(keys::kNoExtensionError,
263 params->id); 263 params->id);
264 return false; 264 return false;
265 } 265 }
266 266
267 std::vector<std::string> warnings = CreateWarningsList(extension); 267 std::vector<std::string> warnings = CreateWarningsList(extension);
268 results_ = management::GetPermissionWarningsById::Results::Create(warnings); 268 results_ = management::GetPermissionWarningsById::Results::Create(warnings);
269 return true; 269 return true;
270 } 270 }
271 271
272 namespace { 272 namespace {
273 273
274 // This class helps GetPermissionWarningsByManifestFunction manage 274 // This class helps ManagementGetPermissionWarningsByManifestFunction manage
275 // sending manifest JSON strings to the utility process for parsing. 275 // sending manifest JSON strings to the utility process for parsing.
276 class SafeManifestJSONParser : public UtilityProcessHostClient { 276 class SafeManifestJSONParser : public UtilityProcessHostClient {
277 public: 277 public:
278 SafeManifestJSONParser(GetPermissionWarningsByManifestFunction* client, 278 SafeManifestJSONParser(
279 const std::string& manifest) 279 ManagementGetPermissionWarningsByManifestFunction* client,
280 const std::string& manifest)
280 : client_(client), 281 : client_(client),
281 manifest_(manifest) {} 282 manifest_(manifest) {}
282 283
283 void Start() { 284 void Start() {
284 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 285 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
285 BrowserThread::PostTask( 286 BrowserThread::PostTask(
286 BrowserThread::IO, 287 BrowserThread::IO,
287 FROM_HERE, 288 FROM_HERE,
288 base::Bind(&SafeManifestJSONParser::StartWorkOnIOThread, this)); 289 base::Bind(&SafeManifestJSONParser::StartWorkOnIOThread, this));
289 } 290 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 if (error_.empty() && parsed_manifest_.get()) 341 if (error_.empty() && parsed_manifest_.get())
341 client_->OnParseSuccess(parsed_manifest_.release()); 342 client_->OnParseSuccess(parsed_manifest_.release());
342 else 343 else
343 client_->OnParseFailure(error_); 344 client_->OnParseFailure(error_);
344 } 345 }
345 346
346 private: 347 private:
347 ~SafeManifestJSONParser() {} 348 ~SafeManifestJSONParser() {}
348 349
349 // The client who we'll report results back to. 350 // The client who we'll report results back to.
350 GetPermissionWarningsByManifestFunction* client_; 351 ManagementGetPermissionWarningsByManifestFunction* client_;
351 352
352 // Data to parse. 353 // Data to parse.
353 std::string manifest_; 354 std::string manifest_;
354 355
355 // Results of parsing. 356 // Results of parsing.
356 scoped_ptr<DictionaryValue> parsed_manifest_; 357 scoped_ptr<DictionaryValue> parsed_manifest_;
357 358
358 std::string error_; 359 std::string error_;
359 }; 360 };
360 361
361 } // namespace 362 } // namespace
362 363
363 bool GetPermissionWarningsByManifestFunction::RunImpl() { 364 bool ManagementGetPermissionWarningsByManifestFunction::RunImpl() {
364 scoped_ptr<management::GetPermissionWarningsByManifest::Params> params( 365 scoped_ptr<management::GetPermissionWarningsByManifest::Params> params(
365 management::GetPermissionWarningsByManifest::Params::Create(*args_)); 366 management::GetPermissionWarningsByManifest::Params::Create(*args_));
366 EXTENSION_FUNCTION_VALIDATE(params.get()); 367 EXTENSION_FUNCTION_VALIDATE(params.get());
367 368
368 scoped_refptr<SafeManifestJSONParser> parser = 369 scoped_refptr<SafeManifestJSONParser> parser =
369 new SafeManifestJSONParser(this, params->manifest_str); 370 new SafeManifestJSONParser(this, params->manifest_str);
370 parser->Start(); 371 parser->Start();
371 372
372 // Matched with a Release() in OnParseSuccess/Failure(). 373 // Matched with a Release() in OnParseSuccess/Failure().
373 AddRef(); 374 AddRef();
374 375
375 // Response is sent async in OnParseSuccess/Failure(). 376 // Response is sent async in OnParseSuccess/Failure().
376 return true; 377 return true;
377 } 378 }
378 379
379 void GetPermissionWarningsByManifestFunction::OnParseSuccess( 380 void ManagementGetPermissionWarningsByManifestFunction::OnParseSuccess(
380 DictionaryValue* parsed_manifest) { 381 DictionaryValue* parsed_manifest) {
381 CHECK(parsed_manifest); 382 CHECK(parsed_manifest);
382 383
383 scoped_refptr<Extension> extension = Extension::Create( 384 scoped_refptr<Extension> extension = Extension::Create(
384 FilePath(), Extension::INVALID, *parsed_manifest, Extension::NO_FLAGS, 385 FilePath(), Extension::INVALID, *parsed_manifest, Extension::NO_FLAGS,
385 &error_); 386 &error_);
386 if (!extension.get()) { 387 if (!extension.get()) {
387 OnParseFailure(keys::kExtensionCreateError); 388 OnParseFailure(keys::kExtensionCreateError);
388 return; 389 return;
389 } 390 }
390 391
391 std::vector<std::string> warnings = CreateWarningsList(extension); 392 std::vector<std::string> warnings = CreateWarningsList(extension);
392 results_ = management::GetPermissionWarningsByManifest::Results::Create( 393 results_ = management::GetPermissionWarningsByManifest::Results::Create(
393 warnings); 394 warnings);
394 SendResponse(true); 395 SendResponse(true);
395 396
396 // Matched with AddRef() in RunImpl(). 397 // Matched with AddRef() in RunImpl().
397 Release(); 398 Release();
398 } 399 }
399 400
400 void GetPermissionWarningsByManifestFunction::OnParseFailure( 401 void ManagementGetPermissionWarningsByManifestFunction::OnParseFailure(
401 const std::string& error) { 402 const std::string& error) {
402 error_ = error; 403 error_ = error;
403 SendResponse(false); 404 SendResponse(false);
404 405
405 // Matched with AddRef() in RunImpl(). 406 // Matched with AddRef() in RunImpl().
406 Release(); 407 Release();
407 } 408 }
408 409
409 bool LaunchAppFunction::RunImpl() { 410 bool ManagementLaunchAppFunction::RunImpl() {
410 scoped_ptr<management::LaunchApp::Params> params( 411 scoped_ptr<management::LaunchApp::Params> params(
411 management::LaunchApp::Params::Create(*args_)); 412 management::LaunchApp::Params::Create(*args_));
412 EXTENSION_FUNCTION_VALIDATE(params.get()); 413 EXTENSION_FUNCTION_VALIDATE(params.get());
413 const Extension* extension = service()->GetExtensionById(params->id, true); 414 const Extension* extension = service()->GetExtensionById(params->id, true);
414 if (!extension) { 415 if (!extension) {
415 error_ = ErrorUtils::FormatErrorMessage(keys::kNoExtensionError, 416 error_ = ErrorUtils::FormatErrorMessage(keys::kNoExtensionError,
416 params->id); 417 params->id);
417 return false; 418 return false;
418 } 419 }
419 if (!extension->is_app()) { 420 if (!extension->is_app()) {
(...skipping 11 matching lines...) Expand all
431 application_launch::OpenApplication(application_launch::LaunchParams( 432 application_launch::OpenApplication(application_launch::LaunchParams(
432 profile(), extension, launch_container, NEW_FOREGROUND_TAB)); 433 profile(), extension, launch_container, NEW_FOREGROUND_TAB));
433 #if !defined(OS_ANDROID) 434 #if !defined(OS_ANDROID)
434 AppLauncherHandler::RecordAppLaunchType( 435 AppLauncherHandler::RecordAppLaunchType(
435 extension_misc::APP_LAUNCH_EXTENSION_API); 436 extension_misc::APP_LAUNCH_EXTENSION_API);
436 #endif 437 #endif
437 438
438 return true; 439 return true;
439 } 440 }
440 441
441 SetEnabledFunction::SetEnabledFunction() { 442 ManagementSetEnabledFunction::ManagementSetEnabledFunction() {
442 } 443 }
443 444
444 SetEnabledFunction::~SetEnabledFunction() { 445 ManagementSetEnabledFunction::~ManagementSetEnabledFunction() {
445 } 446 }
446 447
447 bool SetEnabledFunction::RunImpl() { 448 bool ManagementSetEnabledFunction::RunImpl() {
448 scoped_ptr<management::SetEnabled::Params> params( 449 scoped_ptr<management::SetEnabled::Params> params(
449 management::SetEnabled::Params::Create(*args_)); 450 management::SetEnabled::Params::Create(*args_));
450 EXTENSION_FUNCTION_VALIDATE(params.get()); 451 EXTENSION_FUNCTION_VALIDATE(params.get());
451 452
452 extension_id_ = params->id; 453 extension_id_ = params->id;
453 454
454 const Extension* extension = service()->GetInstalledExtension(extension_id_); 455 const Extension* extension = service()->GetInstalledExtension(extension_id_);
455 if (!extension) { 456 if (!extension) {
456 error_ = ErrorUtils::FormatErrorMessage( 457 error_ = ErrorUtils::FormatErrorMessage(
457 keys::kNoExtensionError, extension_id_); 458 keys::kNoExtensionError, extension_id_);
(...skipping 24 matching lines...) Expand all
482 return true; 483 return true;
483 } 484 }
484 service()->EnableExtension(extension_id_); 485 service()->EnableExtension(extension_id_);
485 } else if (currently_enabled && !params->enabled) { 486 } else if (currently_enabled && !params->enabled) {
486 service()->DisableExtension(extension_id_, Extension::DISABLE_USER_ACTION); 487 service()->DisableExtension(extension_id_, Extension::DISABLE_USER_ACTION);
487 } 488 }
488 489
489 BrowserThread::PostTask( 490 BrowserThread::PostTask(
490 BrowserThread::UI, 491 BrowserThread::UI,
491 FROM_HERE, 492 FROM_HERE,
492 base::Bind(&SetEnabledFunction::SendResponse, this, true)); 493 base::Bind(&ManagementSetEnabledFunction::SendResponse, this, true));
493 494
494 return true; 495 return true;
495 } 496 }
496 497
497 void SetEnabledFunction::InstallUIProceed() { 498 void ManagementSetEnabledFunction::InstallUIProceed() {
498 service()->EnableExtension(extension_id_); 499 service()->EnableExtension(extension_id_);
499 SendResponse(true); 500 SendResponse(true);
500 Release(); 501 Release();
501 } 502 }
502 503
503 void SetEnabledFunction::InstallUIAbort(bool user_initiated) { 504 void ManagementSetEnabledFunction::InstallUIAbort(bool user_initiated) {
504 error_ = keys::kUserDidNotReEnableError; 505 error_ = keys::kUserDidNotReEnableError;
505 SendResponse(false); 506 SendResponse(false);
506 Release(); 507 Release();
507 } 508 }
508 509
509 UninstallFunction::UninstallFunction() { 510 ManagementUninstallFunction::ManagementUninstallFunction() {
510 } 511 }
511 512
512 UninstallFunction::~UninstallFunction() { 513 ManagementUninstallFunction::~ManagementUninstallFunction() {
513 } 514 }
514 515
515 bool UninstallFunction::RunImpl() { 516 bool ManagementUninstallFunction::RunImpl() {
516 scoped_ptr<management::Uninstall::Params> params( 517 scoped_ptr<management::Uninstall::Params> params(
517 management::Uninstall::Params::Create(*args_)); 518 management::Uninstall::Params::Create(*args_));
518 EXTENSION_FUNCTION_VALIDATE(params.get()); 519 EXTENSION_FUNCTION_VALIDATE(params.get());
519 520
520 extension_id_ = params->id; 521 extension_id_ = params->id;
521 522
522 bool show_confirm_dialog = false; 523 bool show_confirm_dialog = false;
523 if (params->options.get() && params->options->show_confirm_dialog.get()) 524 if (params->options.get() && params->options->show_confirm_dialog.get())
524 show_confirm_dialog = *params->options->show_confirm_dialog; 525 show_confirm_dialog = *params->options->show_confirm_dialog;
525 526
(...skipping 21 matching lines...) Expand all
547 Finish(true); 548 Finish(true);
548 } 549 }
549 } else { 550 } else {
550 Finish(auto_confirm_for_test == PROCEED); 551 Finish(auto_confirm_for_test == PROCEED);
551 } 552 }
552 553
553 return true; 554 return true;
554 } 555 }
555 556
556 // static 557 // static
557 void UninstallFunction::SetAutoConfirmForTest(bool should_proceed) { 558 void ManagementUninstallFunction::SetAutoConfirmForTest(bool should_proceed) {
558 auto_confirm_for_test = should_proceed ? PROCEED : ABORT; 559 auto_confirm_for_test = should_proceed ? PROCEED : ABORT;
559 } 560 }
560 561
561 void UninstallFunction::Finish(bool should_uninstall) { 562 void ManagementUninstallFunction::Finish(bool should_uninstall) {
562 if (should_uninstall) { 563 if (should_uninstall) {
563 bool success = service()->UninstallExtension( 564 bool success = service()->UninstallExtension(
564 extension_id_, 565 extension_id_,
565 false, /* external uninstall */ 566 false, /* external uninstall */
566 NULL); 567 NULL);
567 568
568 // TODO set error_ if !success 569 // TODO set error_ if !success
569 SendResponse(success); 570 SendResponse(success);
570 } else { 571 } else {
571 error_ = ErrorUtils::FormatErrorMessage( 572 error_ = ErrorUtils::FormatErrorMessage(
572 keys::kUninstallCanceledError, extension_id_); 573 keys::kUninstallCanceledError, extension_id_);
573 SendResponse(false); 574 SendResponse(false);
574 } 575 }
575 576
576 } 577 }
577 578
578 void UninstallFunction::ExtensionUninstallAccepted() { 579 void ManagementUninstallFunction::ExtensionUninstallAccepted() {
579 Finish(true); 580 Finish(true);
580 Release(); 581 Release();
581 } 582 }
582 583
583 void UninstallFunction::ExtensionUninstallCanceled() { 584 void ManagementUninstallFunction::ExtensionUninstallCanceled() {
584 Finish(false); 585 Finish(false);
585 Release(); 586 Release();
586 } 587 }
587 588
588 ExtensionManagementEventRouter::ExtensionManagementEventRouter(Profile* profile) 589 ExtensionManagementEventRouter::ExtensionManagementEventRouter(Profile* profile)
589 : profile_(profile) { 590 : profile_(profile) {
590 int types[] = { 591 int types[] = {
591 chrome::NOTIFICATION_EXTENSION_INSTALLED, 592 chrome::NOTIFICATION_EXTENSION_INSTALLED,
592 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, 593 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
593 chrome::NOTIFICATION_EXTENSION_LOADED, 594 chrome::NOTIFICATION_EXTENSION_LOADED,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 673
673 void ExtensionManagementAPI::Shutdown() { 674 void ExtensionManagementAPI::Shutdown() {
674 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); 675 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
675 } 676 }
676 677
677 void ExtensionManagementAPI::OnListenerAdded( 678 void ExtensionManagementAPI::OnListenerAdded(
678 const extensions::EventListenerInfo& details) { 679 const extensions::EventListenerInfo& details) {
679 management_event_router_.reset(new ExtensionManagementEventRouter(profile_)); 680 management_event_router_.reset(new ExtensionManagementEventRouter(profile_));
680 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); 681 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
681 } 682 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698