1 // Copyright (c) 2012 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/extension_install_dialog_controller.h"
8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_finder.h"
12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
13 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_window.h"
14 #import "chrome/browser/ui/cocoa/extensions/extension_install_view_controller.h"
15 #import "chrome/browser/ui/cocoa/extensions/windowed_install_dialog_controller.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "content/public/browser/web_contents.h"
21 void ShowExtensionInstallDialogImpl(
22 const ExtensionInstallPrompt::ShowParams& show_params,
23 ExtensionInstallPrompt::Delegate* delegate,
24 const ExtensionInstallPrompt::Prompt& prompt) {
25 // These objects will delete themselves when the dialog closes.
26 if (!show_params.parent_web_contents) {
27 new WindowedInstallDialogController(show_params, delegate, prompt);
31 new ExtensionInstallDialogController(show_params, delegate, prompt);
36 ExtensionInstallDialogController::ExtensionInstallDialogController(
37 const ExtensionInstallPrompt::ShowParams& show_params,
38 ExtensionInstallPrompt::Delegate* delegate,
39 const ExtensionInstallPrompt::Prompt& prompt) : delegate_(delegate) {
40 view_controller_.reset([[ExtensionInstallViewController alloc]
41 initWithNavigator:show_params.navigator
45 base::scoped_nsobject<NSWindow> window([[ConstrainedWindowCustomWindow alloc]
46 initWithContentRect:[[view_controller_ view] bounds]]);
47 [[window contentView] addSubview:[view_controller_ view]];
49 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet(
50 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window]);
51 constrained_window_.reset(new ConstrainedWindowMac(
52 this, show_params.parent_web_contents, sheet));
55 ExtensionInstallDialogController::~ExtensionInstallDialogController() {
58 void ExtensionInstallDialogController::InstallUIProceed() {
59 delegate_->InstallUIProceed();
61 constrained_window_->CloseWebContentsModalDialog();
64 void ExtensionInstallDialogController::InstallUIAbort(bool user_initiated) {
65 delegate_->InstallUIAbort(user_initiated);
67 constrained_window_->CloseWebContentsModalDialog();
70 void ExtensionInstallDialogController::OnConstrainedWindowClosed(
71 ConstrainedWindowMac* window) {
73 delegate_->InstallUIAbort(false);
74 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
78 ExtensionInstallPrompt::ShowDialogCallback
79 ExtensionInstallPrompt::GetDefaultShowDialogCallback() {
80 return base::Bind(&ShowExtensionInstallDialogImpl);