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

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

Issue 1097603003: Remove knowledge of USB devices from permission prompt implementations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Initialize delegate_ to nullptr. Created 5 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/device_permissions_dialog_controller .h" 5 #import "chrome/browser/ui/cocoa/extensions/device_permissions_dialog_controller .h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
11 #include "chrome/browser/extensions/api/chrome_device_permissions_prompt.h" 11 #include "chrome/browser/extensions/api/chrome_device_permissions_prompt.h"
12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.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" 13 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi ndow.h"
14 #import "chrome/browser/ui/cocoa/extensions/device_permissions_view_controller.h " 14 #import "chrome/browser/ui/cocoa/extensions/device_permissions_view_controller.h "
15 #include "device/usb/usb_device.h" 15 #include "device/usb/usb_device.h"
16 16
17 using extensions::DevicePermissionsPrompt; 17 using extensions::DevicePermissionsPrompt;
18 18
19 DevicePermissionsDialogController::DevicePermissionsDialogController( 19 DevicePermissionsDialogController::DevicePermissionsDialogController(
20 content::WebContents* web_contents, 20 content::WebContents* web_contents,
21 DevicePermissionsPrompt::Delegate* delegate,
22 scoped_refptr<DevicePermissionsPrompt::Prompt> prompt) 21 scoped_refptr<DevicePermissionsPrompt::Prompt> prompt)
23 : delegate_(delegate), prompt_(prompt) { 22 : prompt_(prompt) {
24 view_controller_.reset( 23 view_controller_.reset(
25 [[DevicePermissionsViewController alloc] initWithDelegate:this 24 [[DevicePermissionsViewController alloc] initWithController:this
26 prompt:prompt]); 25 prompt:prompt]);
27 26
28 prompt_->SetObserver(this); 27 prompt_->SetObserver(this);
29 28
30 base::scoped_nsobject<NSWindow> window([[ConstrainedWindowCustomWindow alloc] 29 base::scoped_nsobject<NSWindow> window([[ConstrainedWindowCustomWindow alloc]
31 initWithContentRect:[[view_controller_ view] bounds]]); 30 initWithContentRect:[[view_controller_ view] bounds]]);
32 [[window contentView] addSubview:[view_controller_ view]]; 31 [[window contentView] addSubview:[view_controller_ view]];
33 32
34 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( 33 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet(
35 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window]); 34 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window]);
36 constrained_window_.reset( 35 constrained_window_.reset(
37 new ConstrainedWindowMac(this, web_contents, sheet)); 36 new ConstrainedWindowMac(this, web_contents, sheet));
38 } 37 }
39 38
40 DevicePermissionsDialogController::~DevicePermissionsDialogController() { 39 DevicePermissionsDialogController::~DevicePermissionsDialogController() {
41 prompt_->SetObserver(nullptr); 40 prompt_->SetObserver(nullptr);
42 } 41 }
43 42
44 void DevicePermissionsDialogController::OnUsbDevicesChosen( 43 void DevicePermissionsDialogController::Dismissed() {
45 const std::vector<scoped_refptr<device::UsbDevice>>& devices) {
46 delegate_->OnUsbDevicesChosen(devices);
47 delegate_ = nullptr;
48 constrained_window_->CloseWebContentsModalDialog(); 44 constrained_window_->CloseWebContentsModalDialog();
49 } 45 }
50 46
51 void DevicePermissionsDialogController::OnDevicesChanged() { 47 void DevicePermissionsDialogController::OnDevicesChanged() {
52 [view_controller_ devicesChanged]; 48 [view_controller_ devicesChanged];
53 } 49 }
54 50
55 void DevicePermissionsDialogController::OnConstrainedWindowClosed( 51 void DevicePermissionsDialogController::OnConstrainedWindowClosed(
56 ConstrainedWindowMac* window) { 52 ConstrainedWindowMac* window) {
57 if (delegate_) { 53 prompt_->Dismissed();
58 std::vector<scoped_refptr<device::UsbDevice>> empty;
59 delegate_->OnUsbDevicesChosen(empty);
60 }
61 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); 54 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
62 } 55 }
63 56
64 void ChromeDevicePermissionsPrompt::ShowDialog() { 57 void ChromeDevicePermissionsPrompt::ShowDialog() {
65 // These objects will delete themselves when the dialog closes. 58 // These objects will delete themselves when the dialog closes.
66 new DevicePermissionsDialogController(web_contents(), delegate(), prompt()); 59 new DevicePermissionsDialogController(web_contents(), prompt());
67 } 60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698