blob: a4d2efa58a28af49f80ab47a0cab2fd8688cf7d2 [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
#include "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_window.h"
#import "chrome/browser/ui/cocoa/extensions/extension_install_view_controller.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "content/public/browser/web_contents.h"
namespace {
void ShowExtensionInstallDialogImpl(
const ExtensionInstallPrompt::ShowParams& show_params,
ExtensionInstallPrompt::Delegate* delegate,
const ExtensionInstallPrompt::Prompt& prompt) {
if (!show_params.parent_web_contents) {
// TODO(sail): Add support for showing the dialog without a parent window.
NOTIMPLEMENTED();
return;
}
// This object will delete itself when the dialog closes.
new ExtensionInstallDialogController(show_params, delegate, prompt);
}
} // namespace
ExtensionInstallDialogController::ExtensionInstallDialogController(
const ExtensionInstallPrompt::ShowParams& show_params,
ExtensionInstallPrompt::Delegate* delegate,
const ExtensionInstallPrompt::Prompt& prompt) : delegate_(delegate) {
view_controller_.reset([[ExtensionInstallViewController alloc]
initWithNavigator:show_params.navigator
delegate:this
prompt:prompt]);
base::scoped_nsobject<NSWindow> window([[ConstrainedWindowCustomWindow alloc]
initWithContentRect:[[view_controller_ view] bounds]]);
[[window contentView] addSubview:[view_controller_ view]];
base::scoped_nsobject<CustomConstrainedWindowSheet> sheet(
[[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window]);
constrained_window_.reset(new ConstrainedWindowMac(
this, show_params.parent_web_contents, sheet));
}
ExtensionInstallDialogController::~ExtensionInstallDialogController() {
}
void ExtensionInstallDialogController::InstallUIProceed() {
delegate_->InstallUIProceed();
delegate_ = NULL;
constrained_window_->CloseWebContentsModalDialog();
}
void ExtensionInstallDialogController::InstallUIAbort(bool user_initiated) {
delegate_->InstallUIAbort(user_initiated);
delegate_ = NULL;
constrained_window_->CloseWebContentsModalDialog();
}
void ExtensionInstallDialogController::OnConstrainedWindowClosed(
ConstrainedWindowMac* window) {
if (delegate_)
delegate_->InstallUIAbort(false);
base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
}
// static
ExtensionInstallPrompt::ShowDialogCallback
ExtensionInstallPrompt::GetDefaultShowDialogCallback() {
return base::Bind(&ShowExtensionInstallDialogImpl);
}