[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / extensions / extension_install_dialog_controller.mm
blobc8edfc8d8a01794cfb1a968fd40fe330a55aff55
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"
7 #include "base/bind.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"
19 namespace {
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);
28     return;
29   }
31   new ExtensionInstallDialogController(show_params, delegate, prompt);
34 }  // namespace
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
42                delegate:this
43                  prompt:prompt]);
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();
60   delegate_ = NULL;
61   constrained_window_->CloseWebContentsModalDialog();
64 void ExtensionInstallDialogController::InstallUIAbort(bool user_initiated) {
65   delegate_->InstallUIAbort(user_initiated);
66   delegate_ = NULL;
67   constrained_window_->CloseWebContentsModalDialog();
70 void ExtensionInstallDialogController::OnConstrainedWindowClosed(
71     ConstrainedWindowMac* window) {
72   if (delegate_)
73     delegate_->InstallUIAbort(false);
74   base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
77 // static
78 ExtensionInstallPrompt::ShowDialogCallback
79 ExtensionInstallPrompt::GetDefaultShowDialogCallback() {
80   return base::Bind(&ShowExtensionInstallDialogImpl);