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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/windowed_install_dialog_controller.mm

Issue 313203004: Make ExtensionInstallPrompt::Prompt ref-counted (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Latest master for CQ Created 6 years, 6 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #import "chrome/browser/ui/cocoa/extensions/windowed_install_dialog_controller.h " 5 #import "chrome/browser/ui/cocoa/extensions/windowed_install_dialog_controller.h "
6 6
7 #import "base/mac/sdk_forward_declarations.h" 7 #import "base/mac/sdk_forward_declarations.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #import "chrome/browser/ui/cocoa/extensions/extension_install_view_controller.h" 10 #import "chrome/browser/ui/cocoa/extensions/extension_install_view_controller.h"
11 #include "ui/base/cocoa/window_size_constants.h" 11 #include "ui/base/cocoa/window_size_constants.h"
12 12
13 @interface WindowedInstallController 13 @interface WindowedInstallController
14 : NSWindowController<NSWindowDelegate> { 14 : NSWindowController<NSWindowDelegate> {
15 @private 15 @private
16 base::scoped_nsobject<ExtensionInstallViewController> installViewController_; 16 base::scoped_nsobject<ExtensionInstallViewController> installViewController_;
17 WindowedInstallDialogController* dialogController_; // Weak. Owns us. 17 WindowedInstallDialogController* dialogController_; // Weak. Owns us.
18 } 18 }
19 19
20 @property(readonly, nonatomic) ExtensionInstallViewController* viewController; 20 @property(readonly, nonatomic) ExtensionInstallViewController* viewController;
21 21
22 - (id)initWithNavigator:(content::PageNavigator*)navigator 22 - (id)initWithNavigator:(content::PageNavigator*)navigator
23 delegate:(WindowedInstallDialogController*)delegate 23 delegate:(WindowedInstallDialogController*)delegate
24 prompt:(const ExtensionInstallPrompt::Prompt&)prompt; 24 prompt:(scoped_refptr<ExtensionInstallPrompt::Prompt>)prompt;
25 25
26 @end 26 @end
27 27
28 WindowedInstallDialogController::WindowedInstallDialogController( 28 WindowedInstallDialogController::WindowedInstallDialogController(
29 const ExtensionInstallPrompt::ShowParams& show_params, 29 const ExtensionInstallPrompt::ShowParams& show_params,
30 ExtensionInstallPrompt::Delegate* delegate, 30 ExtensionInstallPrompt::Delegate* delegate,
31 const ExtensionInstallPrompt::Prompt& prompt) 31 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt)
32 : delegate_(delegate) { 32 : delegate_(delegate) {
33 install_controller_.reset([[WindowedInstallController alloc] 33 install_controller_.reset([[WindowedInstallController alloc]
34 initWithNavigator:show_params.navigator 34 initWithNavigator:show_params.navigator
35 delegate:this 35 delegate:this
36 prompt:prompt]); 36 prompt:prompt]);
37 [[install_controller_ window] makeKeyAndOrderFront:nil]; 37 [[install_controller_ window] makeKeyAndOrderFront:nil];
38 } 38 }
39 39
40 WindowedInstallDialogController::~WindowedInstallDialogController() { 40 WindowedInstallDialogController::~WindowedInstallDialogController() {
41 DCHECK(!install_controller_); 41 DCHECK(!install_controller_);
(...skipping 23 matching lines...) Expand all
65 void WindowedInstallDialogController::InstallUIAbort(bool user_initiated) { 65 void WindowedInstallDialogController::InstallUIAbort(bool user_initiated) {
66 delegate_->InstallUIAbort(user_initiated); 66 delegate_->InstallUIAbort(user_initiated);
67 delegate_ = NULL; 67 delegate_ = NULL;
68 [[install_controller_ window] close]; 68 [[install_controller_ window] close];
69 } 69 }
70 70
71 @implementation WindowedInstallController 71 @implementation WindowedInstallController
72 72
73 - (id)initWithNavigator:(content::PageNavigator*)navigator 73 - (id)initWithNavigator:(content::PageNavigator*)navigator
74 delegate:(WindowedInstallDialogController*)delegate 74 delegate:(WindowedInstallDialogController*)delegate
75 prompt:(const ExtensionInstallPrompt::Prompt&)prompt { 75 prompt:(scoped_refptr<ExtensionInstallPrompt::Prompt>)prompt {
76 base::scoped_nsobject<NSWindow> controlledPanel( 76 base::scoped_nsobject<NSWindow> controlledPanel(
77 [[NSPanel alloc] initWithContentRect:ui::kWindowSizeDeterminedLater 77 [[NSPanel alloc] initWithContentRect:ui::kWindowSizeDeterminedLater
78 styleMask:NSTitledWindowMask 78 styleMask:NSTitledWindowMask
79 backing:NSBackingStoreBuffered 79 backing:NSBackingStoreBuffered
80 defer:NO]); 80 defer:NO]);
81 if ((self = [super initWithWindow:controlledPanel])) { 81 if ((self = [super initWithWindow:controlledPanel])) {
82 dialogController_ = delegate; 82 dialogController_ = delegate;
83 installViewController_.reset([[ExtensionInstallViewController alloc] 83 installViewController_.reset([[ExtensionInstallViewController alloc]
84 initWithNavigator:navigator 84 initWithNavigator:navigator
85 delegate:delegate 85 delegate:delegate
86 prompt:prompt]); 86 prompt:prompt]);
87 NSWindow* window = [self window]; 87 NSWindow* window = [self window];
88 88
89 // Ensure the window does not display behind the app launcher window, and is 89 // Ensure the window does not display behind the app launcher window, and is
90 // otherwise hard to lose behind other windows (since it is not modal). 90 // otherwise hard to lose behind other windows (since it is not modal).
91 [window setLevel:NSDockWindowLevel]; 91 [window setLevel:NSDockWindowLevel];
92 92
93 // Animate the window when ordered in, the same way as an NSAlert. 93 // Animate the window when ordered in, the same way as an NSAlert.
94 if ([window respondsToSelector:@selector(setAnimationBehavior:)]) 94 if ([window respondsToSelector:@selector(setAnimationBehavior:)])
95 [window setAnimationBehavior:NSWindowAnimationBehaviorAlertPanel]; 95 [window setAnimationBehavior:NSWindowAnimationBehaviorAlertPanel];
96 96
97 [window setTitle:base::SysUTF16ToNSString(prompt.GetDialogTitle())]; 97 [window setTitle:base::SysUTF16ToNSString(prompt->GetDialogTitle())];
98 NSRect viewFrame = [[installViewController_ view] frame]; 98 NSRect viewFrame = [[installViewController_ view] frame];
99 [window setFrame:[window frameRectForContentRect:viewFrame] 99 [window setFrame:[window frameRectForContentRect:viewFrame]
100 display:NO]; 100 display:NO];
101 [window setContentView:[installViewController_ view]]; 101 [window setContentView:[installViewController_ view]];
102 [window setDelegate:self]; 102 [window setDelegate:self];
103 [window center]; 103 [window center];
104 } 104 }
105 return self; 105 return self;
106 } 106 }
107 107
108 - (ExtensionInstallViewController*)viewController { 108 - (ExtensionInstallViewController*)viewController {
109 return installViewController_; 109 return installViewController_;
110 } 110 }
111 111
112 - (void)windowWillClose:(NSNotification*)notification { 112 - (void)windowWillClose:(NSNotification*)notification {
113 [[self window] setDelegate:nil]; 113 [[self window] setDelegate:nil];
114 dialogController_->OnWindowClosing(); 114 dialogController_->OnWindowClosing();
115 } 115 }
116 116
117 @end 117 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698