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

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

Issue 2005443002: Implement bluetooth chooser for Chrome Apps on Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor_chooser_bubble_ui_cocoa
Patch Set: rebase and address comments Created 4 years, 6 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
(Empty)
1 // Copyright 2016 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.
4
5 #import "chrome/browser/ui/cocoa/extensions/chooser_dialog_cocoa.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/threading/thread_task_runner_handle.h"
11 #include "chrome/browser/extensions/chrome_extension_chooser_dialog.h"
12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h"
13 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi ndow.h"
14 #import "chrome/browser/ui/cocoa/extensions/chooser_dialog_cocoa_controller.h"
15 #include "components/web_modal/web_contents_modal_dialog_manager.h"
16
17 ChooserDialogCocoa::ChooserDialogCocoa(content::WebContents* web_contents,
18 ChooserController* chooser_controller)
19 : web_contents_(web_contents), chooser_controller_(chooser_controller) {
20 DCHECK(web_contents_);
21 DCHECK(chooser_controller_);
22 chooser_controller_->set_observer(this);
23 chooser_dialog_cocoa_controller_.reset([[ChooserDialogCocoaController alloc]
24 initWithChooserDialogCocoa:this
25 chooserController:chooser_controller_]);
26 }
27
28 ChooserDialogCocoa::~ChooserDialogCocoa() {}
29
30 void ChooserDialogCocoa::OnConstrainedWindowClosed(
31 ConstrainedWindowMac* window) {
32 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
33 }
34
35 void ChooserDialogCocoa::OnOptionsInitialized() {
36 if (chooser_dialog_cocoa_controller_)
37 [chooser_dialog_cocoa_controller_ onOptionsInitialized];
38 }
39
40 void ChooserDialogCocoa::OnOptionAdded(size_t index) {
41 if (chooser_dialog_cocoa_controller_)
42 [chooser_dialog_cocoa_controller_ onOptionAdded:index];
43 }
44
45 void ChooserDialogCocoa::OnOptionRemoved(size_t index) {
46 if (chooser_dialog_cocoa_controller_)
47 [chooser_dialog_cocoa_controller_ onOptionRemoved:index];
48 }
49
50 void ChooserDialogCocoa::ShowDialog() {
51 base::scoped_nsobject<NSWindow> window([[ConstrainedWindowCustomWindow alloc]
52 initWithContentRect:[[chooser_dialog_cocoa_controller_ view] bounds]]);
53 [[window contentView] addSubview:[chooser_dialog_cocoa_controller_ view]];
54 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet(
55 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window]);
56 constrained_window_ =
57 CreateAndShowWebModalDialogMac(this, web_contents_, sheet);
58 }
59
60 void ChooserDialogCocoa::Dismissed() {
61 if (constrained_window_)
62 constrained_window_->CloseWebContentsModalDialog();
63 }
64
65 void ChromeExtensionChooserDialog::ShowDialog(
66 ChooserController* chooser_controller) const {
67 web_modal::WebContentsModalDialogManager* manager =
68 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents());
69 if (manager) {
70 // These objects will delete themselves when the dialog closes.
71 ChooserDialogCocoa* chooser_dialog =
72 new ChooserDialogCocoa(web_contents(), chooser_controller);
73 chooser_dialog->ShowDialog();
74 }
75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698