OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #import "chrome/browser/ui/cocoa/extensions/windowed_install_dialog_controller.h " | |
6 | |
7 #import "base/mac/sdk_forward_declarations.h" | |
8 #include "base/message_loop/message_loop.h" | |
9 #include "base/strings/sys_string_conversions.h" | |
10 #import "chrome/browser/ui/cocoa/extensions/extension_install_view_controller.h" | |
11 #include "ui/base/cocoa/window_size_constants.h" | |
12 | |
13 @interface WindowedInstallController | |
14 : NSWindowController <NSWindowDelegate> { | |
Robert Sesek
2013/12/03 14:47:53
nit: no space before <
tapted
2013/12/03 23:11:47
Done.
| |
15 @private | |
16 base::scoped_nsobject<ExtensionInstallViewController> installViewController_; | |
17 WindowedInstallDialogController* dialogController_; // Weak. Owns us. | |
18 } | |
19 | |
20 @property(readonly, nonatomic) ExtensionInstallViewController* viewController; | |
21 | |
22 - (id)initWithNavigator:(content::PageNavigator*)navigator | |
23 delegate:(WindowedInstallDialogController*)delegate | |
24 prompt:(const ExtensionInstallPrompt::Prompt&)prompt; | |
25 | |
26 @end | |
27 | |
28 WindowedInstallDialogController::WindowedInstallDialogController( | |
29 const ExtensionInstallPrompt::ShowParams& show_params, | |
30 ExtensionInstallPrompt::Delegate* delegate, | |
31 const ExtensionInstallPrompt::Prompt& prompt) : delegate_(delegate) { | |
Robert Sesek
2013/12/03 14:47:53
nit: I'd put the initializer list on its own line,
tapted
2013/12/03 23:11:47
Done.
| |
32 install_controller_.reset([[WindowedInstallController alloc] | |
33 initWithNavigator:show_params.navigator | |
34 delegate:this | |
35 prompt:prompt]); | |
36 [[install_controller_ window] makeKeyAndOrderFront:nil]; | |
37 } | |
38 | |
39 WindowedInstallDialogController::~WindowedInstallDialogController() { | |
40 DCHECK(!install_controller_); | |
41 DCHECK(!delegate_); | |
42 } | |
43 | |
44 void WindowedInstallDialogController::OnWindowClosing() { | |
45 install_controller_.reset(); | |
46 if (delegate_) { | |
47 delegate_->InstallUIAbort(false); | |
48 delegate_ = NULL; | |
49 } | |
50 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | |
51 } | |
52 | |
53 ExtensionInstallViewController* | |
54 WindowedInstallDialogController::GetViewController() { | |
55 return [install_controller_ viewController]; | |
56 } | |
57 | |
58 void WindowedInstallDialogController::InstallUIProceed() { | |
59 delegate_->InstallUIProceed(); | |
60 delegate_ = NULL; | |
61 [[install_controller_ window] close]; | |
62 } | |
63 | |
64 void WindowedInstallDialogController::InstallUIAbort(bool user_initiated) { | |
65 delegate_->InstallUIAbort(user_initiated); | |
66 delegate_ = NULL; | |
67 [[install_controller_ window] close]; | |
68 } | |
69 | |
70 @implementation WindowedInstallController | |
71 | |
72 - (id)initWithNavigator:(content::PageNavigator*)navigator | |
73 delegate:(WindowedInstallDialogController*)delegate | |
74 prompt:(const ExtensionInstallPrompt::Prompt&)prompt { | |
75 base::scoped_nsobject<NSWindow> controlledPanel( | |
76 [[NSPanel alloc] initWithContentRect:ui::kWindowSizeDeterminedLater | |
77 styleMask:NSTitledWindowMask | |
78 backing:NSBackingStoreBuffered | |
79 defer:NO]); | |
80 if ((self = [super initWithWindow:controlledPanel])) { | |
81 dialogController_ = delegate; | |
82 installViewController_.reset([[ExtensionInstallViewController alloc] | |
83 initWithNavigator:navigator | |
84 delegate:delegate | |
85 prompt:prompt]); | |
86 NSWindow* window = [self window]; | |
87 | |
88 // Ensure the window does not display behind the app launcher window, and is | |
89 // otherwise hard to lose behind other windows (since it is not modal). | |
90 [window setLevel:NSDockWindowLevel]; | |
91 | |
92 // Animate the window when ordered in, the same way as an NSAlert. | |
93 if ([window respondsToSelector:@selector(setAnimationBehavior:)]) | |
94 [window setAnimationBehavior:NSWindowAnimationBehaviorAlertPanel]; | |
95 | |
96 [window setTitle:base::SysUTF16ToNSString(prompt.GetDialogTitle())]; | |
97 NSRect viewFrame = [[installViewController_ view] frame]; | |
98 [window setFrame:[window frameRectForContentRect:viewFrame] | |
99 display:NO]; | |
100 [window setContentView:[installViewController_ view]]; | |
101 [window setDelegate:self]; | |
102 [window center]; | |
103 } | |
104 return self; | |
105 } | |
106 | |
107 - (ExtensionInstallViewController*)viewController { | |
108 return installViewController_; | |
109 } | |
110 | |
111 - (void)windowWillClose:(NSNotification*)notification { | |
112 [[self window] setDelegate:nil]; | |
113 dialogController_->OnWindowClosing(); | |
114 } | |
115 | |
116 @end | |
OLD | NEW |