Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(594)

Side by Side Diff: chrome/browser/ui/cocoa/extensions/windowed_install_dialog_controller.mm

Issue 1534123002: [Extensions] Migrate ExtensionInstallPrompt::Delegate to be a callback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/extensions/windowed_install_dialog_controller.h " 5 #import "chrome/browser/ui/cocoa/extensions/windowed_install_dialog_controller.h "
6 6
7 #import "base/callback_helpers.h"
7 #import "base/mac/sdk_forward_declarations.h" 8 #import "base/mac/sdk_forward_declarations.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
9 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
10 #include "chrome/browser/extensions/extension_install_prompt_show_params.h" 11 #include "chrome/browser/extensions/extension_install_prompt_show_params.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #import "chrome/browser/ui/cocoa/extensions/extension_install_view_controller.h" 13 #import "chrome/browser/ui/cocoa/extensions/extension_install_view_controller.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
14 #include "ui/base/cocoa/window_size_constants.h" 15 #include "ui/base/cocoa/window_size_constants.h"
15 16
16 @interface WindowedInstallController 17 @interface WindowedInstallController
17 : NSWindowController<NSWindowDelegate> { 18 : NSWindowController<NSWindowDelegate> {
18 @private 19 @private
19 base::scoped_nsobject<ExtensionInstallViewController> installViewController_; 20 base::scoped_nsobject<ExtensionInstallViewController> installViewController_;
20 WindowedInstallDialogController* dialogController_; // Weak. Owns us. 21 WindowedInstallDialogController* dialogController_; // Weak. Owns us.
21 } 22 }
22 23
23 @property(readonly, nonatomic) ExtensionInstallViewController* viewController; 24 @property(readonly, nonatomic) ExtensionInstallViewController* viewController;
24 25
25 - (id)initWithProfile:(Profile*)profile 26 - (id)initWithProfile:(Profile*)profile
26 navigator:(content::PageNavigator*)navigator 27 navigator:(content::PageNavigator*)navigator
27 delegate:(WindowedInstallDialogController*)delegate 28 delegate:(WindowedInstallDialogController*)delegate
28 prompt:(scoped_ptr<ExtensionInstallPrompt::Prompt>)prompt; 29 prompt:(scoped_ptr<ExtensionInstallPrompt::Prompt>)prompt;
29 30
30 @end 31 @end
31 32
32 WindowedInstallDialogController::WindowedInstallDialogController( 33 WindowedInstallDialogController::WindowedInstallDialogController(
33 ExtensionInstallPromptShowParams* show_params, 34 ExtensionInstallPromptShowParams* show_params,
34 ExtensionInstallPrompt::Delegate* delegate, 35 const ExtensionInstallPrompt::DoneCallback& done_callback,
35 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt) 36 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt)
36 : delegate_(delegate) { 37 : done_callback_(done_callback) {
37 install_controller_.reset([[WindowedInstallController alloc] 38 install_controller_.reset([[WindowedInstallController alloc]
38 initWithProfile:show_params->profile() 39 initWithProfile:show_params->profile()
39 navigator:show_params->GetParentWebContents() 40 navigator:show_params->GetParentWebContents()
40 delegate:this 41 delegate:this
41 prompt:prompt.Pass()]); 42 prompt:prompt.Pass()]);
42 [[install_controller_ window] makeKeyAndOrderFront:nil]; 43 [[install_controller_ window] makeKeyAndOrderFront:nil];
43 } 44 }
44 45
45 WindowedInstallDialogController::~WindowedInstallDialogController() { 46 WindowedInstallDialogController::~WindowedInstallDialogController() {
46 DCHECK(!install_controller_); 47 DCHECK(!install_controller_);
47 DCHECK(!delegate_); 48 DCHECK(done_callback_.is_null());
48 } 49 }
49 50
50 void WindowedInstallDialogController::OnWindowClosing() { 51 void WindowedInstallDialogController::OnWindowClosing() {
51 install_controller_.reset(); 52 install_controller_.reset();
52 if (delegate_) { 53 if (!done_callback_.is_null()) {
53 delegate_->InstallUIAbort(false); 54 base::ResetAndReturn(&done_callback_).Run(
54 delegate_ = NULL; 55 ExtensionInstallPrompt::Result::ABORTED);
55 } 56 }
56 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 57 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
57 } 58 }
58 59
59 ExtensionInstallViewController* 60 ExtensionInstallViewController*
60 WindowedInstallDialogController::GetViewController() { 61 WindowedInstallDialogController::GetViewController() {
61 return [install_controller_ viewController]; 62 return [install_controller_ viewController];
62 } 63 }
63 64
64 void WindowedInstallDialogController::InstallUIProceed() { 65 void WindowedInstallDialogController::OnOkButtonClicked() {
65 delegate_->InstallUIProceed(); 66 base::ResetAndReturn(&done_callback_).Run(
66 delegate_ = NULL; 67 ExtensionInstallPrompt::Result::ACCEPTED);
67 [[install_controller_ window] close]; 68 [[install_controller_ window] close];
68 } 69 }
69 70
70 void WindowedInstallDialogController::InstallUIAbort(bool user_initiated) { 71 void WindowedInstallDialogController::OnCancelButtonClicked() {
71 delegate_->InstallUIAbort(user_initiated); 72 base::ResetAndReturn(&done_callback_).Run(
72 delegate_ = NULL; 73 ExtensionInstallPrompt::Result::USER_CANCELED);
73 [[install_controller_ window] close]; 74 [[install_controller_ window] close];
74 } 75 }
75 76
77 void WindowedInstallDialogController::OnStoreLinkClicked() {
78 base::ResetAndReturn(&done_callback_).Run(
79 ExtensionInstallPrompt::Result::USER_CANCELED);
80 [[install_controller_ window] close];
81 }
82
76 @implementation WindowedInstallController 83 @implementation WindowedInstallController
77 84
78 - (id)initWithProfile:(Profile*)profile 85 - (id)initWithProfile:(Profile*)profile
79 navigator:(content::PageNavigator*)navigator 86 navigator:(content::PageNavigator*)navigator
80 delegate:(WindowedInstallDialogController*)delegate 87 delegate:(WindowedInstallDialogController*)delegate
81 prompt:(scoped_ptr<ExtensionInstallPrompt::Prompt>)prompt { 88 prompt:(scoped_ptr<ExtensionInstallPrompt::Prompt>)prompt {
82 base::scoped_nsobject<NSWindow> controlledPanel( 89 base::scoped_nsobject<NSWindow> controlledPanel(
83 [[NSPanel alloc] initWithContentRect:ui::kWindowSizeDeterminedLater 90 [[NSPanel alloc] initWithContentRect:ui::kWindowSizeDeterminedLater
84 styleMask:NSTitledWindowMask 91 styleMask:NSTitledWindowMask
85 backing:NSBackingStoreBuffered 92 backing:NSBackingStoreBuffered
(...skipping 30 matching lines...) Expand all
116 - (ExtensionInstallViewController*)viewController { 123 - (ExtensionInstallViewController*)viewController {
117 return installViewController_; 124 return installViewController_;
118 } 125 }
119 126
120 - (void)windowWillClose:(NSNotification*)notification { 127 - (void)windowWillClose:(NSNotification*)notification {
121 [[self window] setDelegate:nil]; 128 [[self window] setDelegate:nil];
122 dialogController_->OnWindowClosing(); 129 dialogController_->OnWindowClosing();
123 } 130 }
124 131
125 @end 132 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698