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> { |
| 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) |
| 32 : delegate_(delegate) { |
| 33 install_controller_.reset([[WindowedInstallController alloc] |
| 34 initWithNavigator:show_params.navigator |
| 35 delegate:this |
| 36 prompt:prompt]); |
| 37 [[install_controller_ window] makeKeyAndOrderFront:nil]; |
| 38 } |
| 39 |
| 40 WindowedInstallDialogController::~WindowedInstallDialogController() { |
| 41 DCHECK(!install_controller_); |
| 42 DCHECK(!delegate_); |
| 43 } |
| 44 |
| 45 void WindowedInstallDialogController::OnWindowClosing() { |
| 46 install_controller_.reset(); |
| 47 if (delegate_) { |
| 48 delegate_->InstallUIAbort(false); |
| 49 delegate_ = NULL; |
| 50 } |
| 51 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 52 } |
| 53 |
| 54 ExtensionInstallViewController* |
| 55 WindowedInstallDialogController::GetViewController() { |
| 56 return [install_controller_ viewController]; |
| 57 } |
| 58 |
| 59 void WindowedInstallDialogController::InstallUIProceed() { |
| 60 delegate_->InstallUIProceed(); |
| 61 delegate_ = NULL; |
| 62 [[install_controller_ window] close]; |
| 63 } |
| 64 |
| 65 void WindowedInstallDialogController::InstallUIAbort(bool user_initiated) { |
| 66 delegate_->InstallUIAbort(user_initiated); |
| 67 delegate_ = NULL; |
| 68 [[install_controller_ window] close]; |
| 69 } |
| 70 |
| 71 @implementation WindowedInstallController |
| 72 |
| 73 - (id)initWithNavigator:(content::PageNavigator*)navigator |
| 74 delegate:(WindowedInstallDialogController*)delegate |
| 75 prompt:(const ExtensionInstallPrompt::Prompt&)prompt { |
| 76 base::scoped_nsobject<NSWindow> controlledPanel( |
| 77 [[NSPanel alloc] initWithContentRect:ui::kWindowSizeDeterminedLater |
| 78 styleMask:NSTitledWindowMask |
| 79 backing:NSBackingStoreBuffered |
| 80 defer:NO]); |
| 81 if ((self = [super initWithWindow:controlledPanel])) { |
| 82 dialogController_ = delegate; |
| 83 installViewController_.reset([[ExtensionInstallViewController alloc] |
| 84 initWithNavigator:navigator |
| 85 delegate:delegate |
| 86 prompt:prompt]); |
| 87 NSWindow* window = [self window]; |
| 88 |
| 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). |
| 91 [window setLevel:NSDockWindowLevel]; |
| 92 |
| 93 // Animate the window when ordered in, the same way as an NSAlert. |
| 94 if ([window respondsToSelector:@selector(setAnimationBehavior:)]) |
| 95 [window setAnimationBehavior:NSWindowAnimationBehaviorAlertPanel]; |
| 96 |
| 97 [window setTitle:base::SysUTF16ToNSString(prompt.GetDialogTitle())]; |
| 98 NSRect viewFrame = [[installViewController_ view] frame]; |
| 99 [window setFrame:[window frameRectForContentRect:viewFrame] |
| 100 display:NO]; |
| 101 [window setContentView:[installViewController_ view]]; |
| 102 [window setDelegate:self]; |
| 103 [window center]; |
| 104 } |
| 105 return self; |
| 106 } |
| 107 |
| 108 - (ExtensionInstallViewController*)viewController { |
| 109 return installViewController_; |
| 110 } |
| 111 |
| 112 - (void)windowWillClose:(NSNotification*)notification { |
| 113 [[self window] setDelegate:nil]; |
| 114 dialogController_->OnWindowClosing(); |
| 115 } |
| 116 |
| 117 @end |
OLD | NEW |