| OLD | NEW |
| 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/extension_action/extension_action_api.h" | 5 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/extensions/active_script_controller.h" | 10 #include "chrome/browser/extensions/active_script_controller.h" |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 !ExtensionActionAPI::Get(GetProfile())->ShowExtensionActionPopup( | 620 !ExtensionActionAPI::Get(GetProfile())->ShowExtensionActionPopup( |
| 621 extension_.get(), browser, false)) { | 621 extension_.get(), browser, false)) { |
| 622 error_ = kOpenPopupError; | 622 error_ = kOpenPopupError; |
| 623 return false; | 623 return false; |
| 624 } | 624 } |
| 625 | 625 |
| 626 // Even if this is for an incognito window, we want to use the normal profile. | 626 // Even if this is for an incognito window, we want to use the normal profile. |
| 627 // If the extension is spanning, then extension hosts are created with the | 627 // If the extension is spanning, then extension hosts are created with the |
| 628 // original profile, and if it's split, then we know the api call came from | 628 // original profile, and if it's split, then we know the api call came from |
| 629 // the right profile. | 629 // the right profile. |
| 630 registrar_.Add(this, | 630 registrar_.Add(this, NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD, |
| 631 NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | |
| 632 content::Source<Profile>(profile)); | 631 content::Source<Profile>(profile)); |
| 633 | 632 |
| 634 // Set a timeout for waiting for the notification that the popup is loaded. | 633 // Set a timeout for waiting for the notification that the popup is loaded. |
| 635 // Waiting is required so that the popup view can be retrieved by the custom | 634 // Waiting is required so that the popup view can be retrieved by the custom |
| 636 // bindings for the response callback. It's also needed to keep this function | 635 // bindings for the response callback. It's also needed to keep this function |
| 637 // instance around until a notification is observed. | 636 // instance around until a notification is observed. |
| 638 base::MessageLoopForUI::current()->PostDelayedTask( | 637 base::MessageLoopForUI::current()->PostDelayedTask( |
| 639 FROM_HERE, | 638 FROM_HERE, |
| 640 base::Bind(&BrowserActionOpenPopupFunction::OpenPopupTimedOut, this), | 639 base::Bind(&BrowserActionOpenPopupFunction::OpenPopupTimedOut, this), |
| 641 base::TimeDelta::FromSeconds(10)); | 640 base::TimeDelta::FromSeconds(10)); |
| 642 return true; | 641 return true; |
| 643 } | 642 } |
| 644 | 643 |
| 645 void BrowserActionOpenPopupFunction::OpenPopupTimedOut() { | 644 void BrowserActionOpenPopupFunction::OpenPopupTimedOut() { |
| 646 if (response_sent_) | 645 if (response_sent_) |
| 647 return; | 646 return; |
| 648 | 647 |
| 649 DVLOG(1) << "chrome.browserAction.openPopup did not show a popup."; | 648 DVLOG(1) << "chrome.browserAction.openPopup did not show a popup."; |
| 650 error_ = kOpenPopupError; | 649 error_ = kOpenPopupError; |
| 651 SendResponse(false); | 650 SendResponse(false); |
| 652 response_sent_ = true; | 651 response_sent_ = true; |
| 653 } | 652 } |
| 654 | 653 |
| 655 void BrowserActionOpenPopupFunction::Observe( | 654 void BrowserActionOpenPopupFunction::Observe( |
| 656 int type, | 655 int type, |
| 657 const content::NotificationSource& source, | 656 const content::NotificationSource& source, |
| 658 const content::NotificationDetails& details) { | 657 const content::NotificationDetails& details) { |
| 659 DCHECK_EQ(NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, type); | 658 DCHECK_EQ(NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD, type); |
| 660 if (response_sent_) | 659 if (response_sent_) |
| 661 return; | 660 return; |
| 662 | 661 |
| 663 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 662 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
| 664 if (host->extension_host_type() != VIEW_TYPE_EXTENSION_POPUP || | 663 if (host->extension_host_type() != VIEW_TYPE_EXTENSION_POPUP || |
| 665 host->extension()->id() != extension_->id()) | 664 host->extension()->id() != extension_->id()) |
| 666 return; | 665 return; |
| 667 | 666 |
| 668 SendResponse(true); | 667 SendResponse(true); |
| 669 response_sent_ = true; | 668 response_sent_ = true; |
| 670 registrar_.RemoveAll(); | 669 registrar_.RemoveAll(); |
| 671 } | 670 } |
| 672 | 671 |
| 673 } // namespace extensions | 672 } // namespace extensions |
| OLD | NEW |