Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / extensions / windowed_install_dialog_controller.mm
blobd1128ab63e571fb568518f3550d579cba1d4c850
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.
5 #import "chrome/browser/ui/cocoa/extensions/windowed_install_dialog_controller.h"
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"
13 @interface WindowedInstallController
14     : NSWindowController<NSWindowDelegate> {
15  @private
16   base::scoped_nsobject<ExtensionInstallViewController> installViewController_;
17   WindowedInstallDialogController* dialogController_;  // Weak. Owns us.
20 @property(readonly, nonatomic) ExtensionInstallViewController* viewController;
22 - (id)initWithNavigator:(content::PageNavigator*)navigator
23                delegate:(WindowedInstallDialogController*)delegate
24                  prompt:(const ExtensionInstallPrompt::Prompt&)prompt;
26 @end
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];
40 WindowedInstallDialogController::~WindowedInstallDialogController() {
41   DCHECK(!install_controller_);
42   DCHECK(!delegate_);
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);
54 ExtensionInstallViewController*
55 WindowedInstallDialogController::GetViewController() {
56   return [install_controller_ viewController];
59 void WindowedInstallDialogController::InstallUIProceed() {
60   delegate_->InstallUIProceed();
61   delegate_ = NULL;
62   [[install_controller_ window] close];
65 void WindowedInstallDialogController::InstallUIAbort(bool user_initiated) {
66   delegate_->InstallUIAbort(user_initiated);
67   delegate_ = NULL;
68   [[install_controller_ window] close];
71 @implementation WindowedInstallController
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];
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];
93     // Animate the window when ordered in, the same way as an NSAlert.
94     if ([window respondsToSelector:@selector(setAnimationBehavior:)])
95       [window setAnimationBehavior:NSWindowAnimationBehaviorAlertPanel];
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;
108 - (ExtensionInstallViewController*)viewController {
109   return installViewController_;
112 - (void)windowWillClose:(NSNotification*)notification {
113   [[self window] setDelegate:nil];
114   dialogController_->OnWindowClosing();
117 @end