Chromium Code Reviews| 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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 567 } | 567 } |
| 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 use_json_(false), | |
| 577 reply_message_(reply_message), | 578 reply_message_(reply_message), |
| 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 use_json_(true), | |
| 590 reply_message_(reply_message), | |
| 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: { |
|
dennis_jeffrey
2011/11/22 23:32:16
Is there a reason this block is enclosed in braces
kkania
2011/11/23 17:31:23
I need the brace because I am defining a new var i
| |
| 610 extension_ = content::Details<const Extension>(details).ptr(); | 627 const Extension* loaded_extension = |
| 628 content::Details<const Extension>(details).ptr(); | |
| 629 // Only track internal extension loads. | |
| 630 if (loaded_extension->location() != Extension::INTERNAL) | |
| 631 return; | |
| 632 extension_ = loaded_extension; | |
| 611 if (!DidExtensionHostsStopLoading(manager_)) | 633 if (!DidExtensionHostsStopLoading(manager_)) |
| 612 return; | 634 return; |
| 613 // For some reason, the background ExtensionHost is not yet | 635 // For some reason, the background ExtensionHost is not yet |
| 614 // created at this point so just checking whether all ExtensionHosts | 636 // created at this point so just checking whether all ExtensionHosts |
| 615 // are loaded is not sufficient. If background page is not ready, | 637 // are loaded is not sufficient. If background page is not ready, |
| 616 // we wait for NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING. | 638 // we wait for NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING. |
| 617 if (!service_->IsBackgroundPageReady(extension_)) | 639 if (!service_->IsBackgroundPageReady(extension_)) |
| 618 return; | 640 return; |
| 619 break; | 641 break; |
| 642 } | |
| 620 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: | 643 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: |
| 621 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: | 644 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: |
| 622 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: | 645 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: |
| 623 break; | 646 break; |
| 624 default: | 647 default: |
| 625 NOTREACHED(); | 648 NOTREACHED(); |
| 626 break; | 649 break; |
| 627 } | 650 } |
| 628 | 651 |
| 629 if (id_ == AutomationMsg_InstallExtension::ID) { | 652 if (use_json_) { |
| 630 // A handle of zero indicates an error. | 653 DictionaryValue* dict = new DictionaryValue(); |
| 631 int extension_handle = 0; | 654 dict->SetString("id", extension_->id()); |
| 632 if (extension_) | 655 AutomationJSONReply(automation_, reply_message_.release()) |
| 633 extension_handle = automation_->AddExtension(extension_); | 656 .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 { | 657 } else { |
| 639 NOTREACHED(); | 658 if (id_ == AutomationMsg_InstallExtension::ID) { |
| 640 LOG(ERROR) << "Cannot write reply params for unknown message id."; | 659 // A handle of zero indicates an error. |
| 660 int extension_handle = 0; | |
| 661 if (extension_) | |
| 662 extension_handle = automation_->AddExtension(extension_); | |
| 663 AutomationMsg_InstallExtension::WriteReplyParams( | |
| 664 reply_message_.get(), extension_handle); | |
| 665 } else if (id_ == AutomationMsg_EnableExtension::ID) { | |
| 666 AutomationMsg_EnableExtension::WriteReplyParams( | |
| 667 reply_message_.get(), true); | |
| 668 } else { | |
| 669 LOG(ERROR) << "Cannot write reply params for unknown message id."; | |
| 670 } | |
| 671 automation_->Send(reply_message_.release()); | |
| 641 } | 672 } |
| 642 | |
| 643 automation_->Send(reply_message_.release()); | |
| 644 delete this; | 673 delete this; |
| 645 } | 674 } |
| 646 | 675 |
| 647 ExtensionUnloadNotificationObserver::ExtensionUnloadNotificationObserver() | 676 ExtensionUnloadNotificationObserver::ExtensionUnloadNotificationObserver() |
| 648 : did_receive_unload_notification_(false) { | 677 : did_receive_unload_notification_(false) { |
| 649 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 678 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 650 content::NotificationService::AllSources()); | 679 content::NotificationService::AllSources()); |
| 651 } | 680 } |
| 652 | 681 |
| 653 ExtensionUnloadNotificationObserver::~ExtensionUnloadNotificationObserver() { | 682 ExtensionUnloadNotificationObserver::~ExtensionUnloadNotificationObserver() { |
| (...skipping 2271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2925 if (automation_) { | 2954 if (automation_) { |
| 2926 AutomationJSONReply(automation_, reply_message_.release()) | 2955 AutomationJSONReply(automation_, reply_message_.release()) |
| 2927 .SendSuccess(NULL); | 2956 .SendSuccess(NULL); |
| 2928 } | 2957 } |
| 2929 delete this; | 2958 delete this; |
| 2930 } | 2959 } |
| 2931 } else { | 2960 } else { |
| 2932 NOTREACHED(); | 2961 NOTREACHED(); |
| 2933 } | 2962 } |
| 2934 } | 2963 } |
| OLD | NEW |