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

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

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

Powered by Google App Engine
This is Rietveld 408576698