| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/automation/automation_provider_observers.h" | 5 #include "chrome/browser/automation/automation_provider_observers.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 } | 568 } |
| 569 | 569 |
| 570 ExtensionReadyNotificationObserver::ExtensionReadyNotificationObserver( | 570 ExtensionReadyNotificationObserver::ExtensionReadyNotificationObserver( |
| 571 ExtensionProcessManager* manager, ExtensionService* service, | 571 ExtensionProcessManager* manager, ExtensionService* service, |
| 572 AutomationProvider* automation, int id, IPC::Message* reply_message) | 572 AutomationProvider* automation, int id, IPC::Message* reply_message) |
| 573 : manager_(manager), | 573 : manager_(manager), |
| 574 service_(service), | 574 service_(service), |
| 575 automation_(automation->AsWeakPtr()), | 575 automation_(automation->AsWeakPtr()), |
| 576 id_(id), | 576 id_(id), |
| 577 reply_message_(reply_message), | 577 reply_message_(reply_message), |
| 578 use_json_(false), |
| 578 extension_(NULL) { | 579 extension_(NULL) { |
| 580 Init(); |
| 581 } |
| 582 |
| 583 ExtensionReadyNotificationObserver::ExtensionReadyNotificationObserver( |
| 584 ExtensionProcessManager* manager, ExtensionService* service, |
| 585 AutomationProvider* automation, IPC::Message* reply_message) |
| 586 : manager_(manager), |
| 587 service_(service), |
| 588 automation_(automation->AsWeakPtr()), |
| 589 reply_message_(reply_message), |
| 590 use_json_(true), |
| 591 extension_(NULL) { |
| 592 Init(); |
| 593 } |
| 594 |
| 595 ExtensionReadyNotificationObserver::~ExtensionReadyNotificationObserver() { |
| 596 } |
| 597 |
| 598 void ExtensionReadyNotificationObserver::Init() { |
| 579 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 599 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
| 580 content::NotificationService::AllSources()); | 600 content::NotificationService::AllSources()); |
| 581 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 601 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 582 content::NotificationService::AllSources()); | 602 content::NotificationService::AllSources()); |
| 583 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, | 603 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, |
| 584 content::NotificationService::AllSources()); | 604 content::NotificationService::AllSources()); |
| 585 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, | 605 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
| 586 content::NotificationService::AllSources()); | 606 content::NotificationService::AllSources()); |
| 587 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, | 607 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
| 588 content::NotificationService::AllSources()); | 608 content::NotificationService::AllSources()); |
| 589 } | 609 } |
| 590 | 610 |
| 591 ExtensionReadyNotificationObserver::~ExtensionReadyNotificationObserver() { | |
| 592 } | |
| 593 | |
| 594 void ExtensionReadyNotificationObserver::Observe( | 611 void ExtensionReadyNotificationObserver::Observe( |
| 595 int type, const content::NotificationSource& source, | 612 int type, const content::NotificationSource& source, |
| 596 const content::NotificationDetails& details) { | 613 const content::NotificationDetails& details) { |
| 597 if (!automation_) { | 614 if (!automation_) { |
| 598 delete this; | 615 delete this; |
| 599 return; | 616 return; |
| 600 } | 617 } |
| 601 | 618 |
| 602 switch (type) { | 619 switch (type) { |
| 603 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: | 620 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: |
| 604 // Only continue on with this method if our extension has been loaded | 621 // Only continue on with this method if our extension has been loaded |
| 605 // and all the extension hosts have stopped loading. | 622 // and all the extension hosts have stopped loading. |
| 606 if (!extension_ || !DidExtensionHostsStopLoading(manager_)) | 623 if (!extension_ || !DidExtensionHostsStopLoading(manager_)) |
| 607 return; | 624 return; |
| 608 break; | 625 break; |
| 609 case chrome::NOTIFICATION_EXTENSION_LOADED: | 626 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
| 610 extension_ = content::Details<const Extension>(details).ptr(); | 627 const Extension* loaded_extension = |
| 628 content::Details<const Extension>(details).ptr(); |
| 629 // Only track an internal or unpacked extension load. |
| 630 Extension::Location location = loaded_extension->location(); |
| 631 if (location != Extension::INTERNAL && location != Extension::LOAD) |
| 632 return; |
| 633 extension_ = loaded_extension; |
| 611 if (!DidExtensionHostsStopLoading(manager_)) | 634 if (!DidExtensionHostsStopLoading(manager_)) |
| 612 return; | 635 return; |
| 613 // For some reason, the background ExtensionHost is not yet | 636 // For some reason, the background ExtensionHost is not yet |
| 614 // created at this point so just checking whether all ExtensionHosts | 637 // created at this point so just checking whether all ExtensionHosts |
| 615 // are loaded is not sufficient. If background page is not ready, | 638 // are loaded is not sufficient. If background page is not ready, |
| 616 // we wait for NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING. | 639 // we wait for NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING. |
| 617 if (!service_->IsBackgroundPageReady(extension_)) | 640 if (!service_->IsBackgroundPageReady(extension_)) |
| 618 return; | 641 return; |
| 619 break; | 642 break; |
| 643 } |
| 620 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: | 644 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: |
| 621 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: | 645 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: |
| 622 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: | 646 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: |
| 623 break; | 647 break; |
| 624 default: | 648 default: |
| 625 NOTREACHED(); | 649 NOTREACHED(); |
| 626 break; | 650 break; |
| 627 } | 651 } |
| 628 | 652 |
| 629 if (id_ == AutomationMsg_InstallExtension::ID) { | 653 if (use_json_) { |
| 630 // A handle of zero indicates an error. | 654 DictionaryValue dict; |
| 631 int extension_handle = 0; | 655 dict.SetString("id", extension_->id()); |
| 632 if (extension_) | 656 AutomationJSONReply(automation_, reply_message_.release()) |
| 633 extension_handle = automation_->AddExtension(extension_); | 657 .SendSuccess(&dict); |
| 634 AutomationMsg_InstallExtension::WriteReplyParams( | |
| 635 reply_message_.get(), extension_handle); | |
| 636 } else if (id_ == AutomationMsg_EnableExtension::ID) { | |
| 637 AutomationMsg_EnableExtension::WriteReplyParams(reply_message_.get(), true); | |
| 638 } else { | 658 } else { |
| 639 NOTREACHED(); | 659 if (id_ == AutomationMsg_InstallExtension::ID) { |
| 640 LOG(ERROR) << "Cannot write reply params for unknown message id."; | 660 // A handle of zero indicates an error. |
| 661 int extension_handle = 0; |
| 662 if (extension_) |
| 663 extension_handle = automation_->AddExtension(extension_); |
| 664 AutomationMsg_InstallExtension::WriteReplyParams( |
| 665 reply_message_.get(), extension_handle); |
| 666 } else if (id_ == AutomationMsg_EnableExtension::ID) { |
| 667 AutomationMsg_EnableExtension::WriteReplyParams( |
| 668 reply_message_.get(), true); |
| 669 } else { |
| 670 LOG(ERROR) << "Cannot write reply params for unknown message id."; |
| 671 } |
| 672 automation_->Send(reply_message_.release()); |
| 641 } | 673 } |
| 642 | |
| 643 automation_->Send(reply_message_.release()); | |
| 644 delete this; | 674 delete this; |
| 645 } | 675 } |
| 646 | 676 |
| 647 ExtensionUnloadNotificationObserver::ExtensionUnloadNotificationObserver() | 677 ExtensionUnloadNotificationObserver::ExtensionUnloadNotificationObserver() |
| 648 : did_receive_unload_notification_(false) { | 678 : did_receive_unload_notification_(false) { |
| 649 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 679 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 650 content::NotificationService::AllSources()); | 680 content::NotificationService::AllSources()); |
| 651 } | 681 } |
| 652 | 682 |
| 653 ExtensionUnloadNotificationObserver::~ExtensionUnloadNotificationObserver() { | 683 ExtensionUnloadNotificationObserver::~ExtensionUnloadNotificationObserver() { |
| (...skipping 2271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2925 if (automation_) { | 2955 if (automation_) { |
| 2926 AutomationJSONReply(automation_, reply_message_.release()) | 2956 AutomationJSONReply(automation_, reply_message_.release()) |
| 2927 .SendSuccess(NULL); | 2957 .SendSuccess(NULL); |
| 2928 } | 2958 } |
| 2929 delete this; | 2959 delete this; |
| 2930 } | 2960 } |
| 2931 } else { | 2961 } else { |
| 2932 NOTREACHED(); | 2962 NOTREACHED(); |
| 2933 } | 2963 } |
| 2934 } | 2964 } |
| OLD | NEW |