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

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

Powered by Google App Engine
This is Rietveld 408576698