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

Unified Diff: trunk/src/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm

Issue 102163002: Revert 238283 "Infobar system refactor." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years 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: trunk/src/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm
===================================================================
--- trunk/src/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm (revision 238401)
+++ trunk/src/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm (working copy)
@@ -52,15 +52,21 @@
// A helper class to bridge the asynchronous Skia bitmap loading mechanism to
// the extension's button.
-class InfobarBridge {
+class InfobarBridge : public ExtensionInfoBarDelegate::DelegateObserver {
public:
explicit InfobarBridge(ExtensionInfoBarController* owner)
: owner_(owner),
delegate_([owner delegate]->AsExtensionInfoBarDelegate()),
weak_ptr_factory_(this) {
+ delegate_->set_observer(this);
LoadIcon();
}
+ virtual ~InfobarBridge() {
+ if (delegate_)
+ delegate_->set_observer(NULL);
+ }
+
// Load the Extension's icon image.
void LoadIcon() {
const extensions::Extension* extension = delegate_->extension_view_host()->
@@ -113,6 +119,11 @@
canvas->ExtractImageRep().sk_bitmap())];
}
+ // Overridden from ExtensionInfoBarDelegate::DelegateObserver:
+ virtual void OnDelegateDeleted() OVERRIDE {
+ delegate_ = NULL;
+ }
+
private:
// Weak. Owns us.
ExtensionInfoBarController* owner_;
@@ -128,11 +139,22 @@
@implementation ExtensionInfoBarController
-- (id)initWithInfoBar:(InfoBarCocoa*)infobar {
+- (id)initWithInfoBar:(InfoBarCocoa*)infobar
+ window:(NSWindow*)window {
if ((self = [super initWithInfoBar:infobar])) {
+ window_ = window;
dropdownButton_.reset([[MenuButton alloc] init]);
[dropdownButton_ setOpenMenuOnClick:YES];
+ extensions::ExtensionViewHost* extensionViewHost =
+ [self delegate]->AsExtensionInfoBarDelegate()->extension_view_host();
+ Browser* browser = chrome::FindBrowserWithWebContents(
+ [self infobar]->OwnerCocoa()->web_contents());
+ contextMenuController_.reset([[ExtensionActionContextMenuController alloc]
+ initWithExtension:extensionViewHost->extension()
+ browser:browser
+ extensionAction:NULL]);
+
base::scoped_nsobject<NSMenu> contextMenu(
[[NSMenu alloc] initWithTitle:@""]);
[contextMenu setDelegate:self];
@@ -202,15 +224,10 @@
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(adjustExtensionViewSize)
- name:NSViewFrameDidChangeNotification
- object:[self view]];
+ name:NSWindowDidResizeNotification
+ object:window_];
}
-- (void)infobarWillHide {
- [[dropdownButton_ menu] cancelTracking];
- [super infobarWillHide];
-}
-
- (void)infobarWillClose {
[self disablePopUpMenu:[dropdownButton_ menu]];
[super infobarWillClose];
@@ -229,7 +246,7 @@
- (void)adjustExtensionViewSize {
[extensionView_ setPostsFrameChangedNotifications:NO];
NSSize extensionViewSize = [extensionView_ frame].size;
- extensionViewSize.width = NSWidth([[self view] frame]);
+ extensionViewSize.width = NSWidth([window_ frame]);
extensionViewSize.height = [self clampedExtensionViewHeight];
[extensionView_ setFrameSize:extensionViewSize];
[extensionView_ setPostsFrameChangedNotifications:YES];
@@ -240,32 +257,20 @@
}
- (void)menuNeedsUpdate:(NSMenu*)menu {
- DCHECK([self isOwned]);
-
- if (!contextMenuController_) {
- extensions::ExtensionViewHost* extensionViewHost =
- [self delegate]->AsExtensionInfoBarDelegate()->extension_view_host();
- Browser* browser = chrome::FindBrowserWithWebContents(
- [self infobar]->OwnerCocoa()->web_contents());
- contextMenuController_.reset([[ExtensionActionContextMenuController alloc]
- initWithExtension:extensionViewHost->extension()
- browser:browser
- extensionAction:NULL]);
- }
-
[menu removeAllItems];
[contextMenuController_ populateMenu:menu];
}
@end
-// static
-scoped_ptr<InfoBar> ExtensionInfoBarDelegate::CreateInfoBar(
- scoped_ptr<ExtensionInfoBarDelegate> delegate) {
- scoped_ptr<InfoBarCocoa> infobar(
- new InfoBarCocoa(delegate.PassAs<InfoBarDelegate>()));
+InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarService* owner) {
+ scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(owner, this));
+ NSWindow* window =
+ [(NSView*)owner->web_contents()->GetView()->GetContentNativeView()
+ window];
base::scoped_nsobject<ExtensionInfoBarController> controller(
- [[ExtensionInfoBarController alloc] initWithInfoBar:infobar.get()]);
+ [[ExtensionInfoBarController alloc] initWithInfoBar:infobar.get()
+ window:window]);
infobar->set_controller(controller);
- return infobar.PassAs<InfoBar>();
+ return infobar.release();
}

Powered by Google App Engine
This is Rietveld 408576698