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

Unified Diff: chrome/browser/ui/cocoa/extensions/extension_action_platform_delegate_cocoa.mm

Issue 703443002: Move more extension action cocoa logic into the platform delegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dc_toolbar_abstract_extension_action
Patch Set: Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/extensions/extension_action_platform_delegate_cocoa.mm
diff --git a/chrome/browser/ui/cocoa/extensions/extension_action_platform_delegate_cocoa.mm b/chrome/browser/ui/cocoa/extensions/extension_action_platform_delegate_cocoa.mm
index 74c784c286e62944d9879f554701d4952330b0bc..66ba9c8a1fc0bad7fc8bcd7a3737e2c1fba318e3 100644
--- a/chrome/browser/ui/cocoa/extensions/extension_action_platform_delegate_cocoa.mm
+++ b/chrome/browser/ui/cocoa/extensions/extension_action_platform_delegate_cocoa.mm
@@ -4,10 +4,37 @@
#import "chrome/browser/ui/cocoa/extensions/extension_action_platform_delegate_cocoa.h"
+#include <string>
+#include <utility>
+
+#include "base/logging.h"
+#include "chrome/browser/extensions/extension_action.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_window.h"
+#import "chrome/browser/ui/cocoa/extensions/extension_action_context_menu_controller.h"
#import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h"
#import "chrome/browser/ui/cocoa/toolbar/toolbar_action_view_delegate_cocoa.h"
+#include "chrome/common/extensions/api/extension_action/action_info.h"
+#include "content/public/browser/notification_details.h"
+#include "content/public/browser/notification_source.h"
+#include "extensions/browser/notification_types.h"
#include "extensions/common/extension.h"
+namespace {
+
+// Returns the notification to listen to for activation for a particular
+// |extension_action|.
+int GetNotificationTypeForAction(const ExtensionAction& extension_action) {
+ if (extension_action.action_type() == extensions::ActionInfo::TYPE_BROWSER)
+ return extensions::NOTIFICATION_EXTENSION_COMMAND_BROWSER_ACTION_MAC;
+
+ // We should only have page and browser action types.
+ DCHECK_EQ(extensions::ActionInfo::TYPE_PAGE, extension_action.action_type());
+ return extensions::NOTIFICATION_EXTENSION_COMMAND_PAGE_ACTION_MAC;
+}
+
+} // namespace
+
// static
scoped_ptr<ExtensionActionPlatformDelegate>
ExtensionActionPlatformDelegate::Create(
@@ -38,6 +65,22 @@ void ExtensionActionPlatformDelegateCocoa::RegisterCommand() {
}
void ExtensionActionPlatformDelegateCocoa::OnDelegateSet() {
+ if (controller_->extension()->ShowConfigureContextMenus()) {
+ menuController_.reset([[ExtensionActionContextMenuController alloc]
+ initWithExtension:controller_->extension()
+ browser:controller_->browser()
+ extensionAction:controller_->extension_action()]);
+ GetDelegateCocoa()->SetContextMenuController(menuController_.get());
+ }
+
+ registrar_.Add(
+ this,
+ extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
+ content::Source<Profile>(controller_->browser()->profile()));
+ registrar_.Add(
+ this,
+ GetNotificationTypeForAction(*controller_->extension_action()),
+ content::Source<Profile>(controller_->browser()->profile()));
}
bool ExtensionActionPlatformDelegateCocoa::IsShowingPopup() const {
@@ -46,14 +89,15 @@ bool ExtensionActionPlatformDelegateCocoa::IsShowingPopup() const {
void ExtensionActionPlatformDelegateCocoa::CloseActivePopup() {
ExtensionPopupController* popup = [ExtensionPopupController popup];
- if (popup)
+ if (popup && ![popup isClosing])
[popup close];
}
void ExtensionActionPlatformDelegateCocoa::CloseOwnPopup() {
ExtensionPopupController* popup = GetPopup();
DCHECK(popup);
- [popup close];
+ if (popup && ![popup isClosing])
+ [popup close];
}
bool ExtensionActionPlatformDelegateCocoa::ShowPopupWithUrl(
@@ -81,3 +125,33 @@ ExtensionPopupController* ExtensionActionPlatformDelegateCocoa::GetPopup()
return popup && [popup extensionId] == controller_->extension()->id() ?
popup : nil;
}
+
+void ExtensionActionPlatformDelegateCocoa::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ switch (type) {
+ case extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE:
+ CloseActivePopup();
+ break;
+ case extensions::NOTIFICATION_EXTENSION_COMMAND_BROWSER_ACTION_MAC:
+ case extensions::NOTIFICATION_EXTENSION_COMMAND_PAGE_ACTION_MAC: {
Avi (use Gerrit) 2014/11/03 22:04:00 Not for this CL, but why don't we collapse these?
Devlin 2014/11/03 22:07:28 I can't think of a reason to not (since extensions
+ DCHECK_EQ(type,
+ GetNotificationTypeForAction(*controller_->extension_action()));
+ std::pair<const std::string, gfx::NativeWindow>* payload =
+ content::Details<std::pair<const std::string, gfx::NativeWindow> >(
+ details).ptr();
+ const std::string& extension_id = payload->first;
+ gfx::NativeWindow window = payload->second;
+ if (window == controller_->browser()->window()->GetNativeWindow() &&
+ extension_id == controller_->extension()->id() &&
+ controller_->IsEnabled(
+ controller_->view_delegate()->GetCurrentWebContents())) {
+ controller_->ExecuteAction(true);
+ }
+ break;
+ }
+ default:
+ NOTREACHED() << L"Unexpected notification";
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698