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

Unified Diff: chrome/browser/ui/cocoa/extensions/device_permissions_dialog_controller.mm

Issue 633793002: Prompt for granting permission to access USB devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename UsbDevicesChosen -> OnUsbDevicesChosen. Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/extensions/device_permissions_dialog_controller.mm
diff --git a/chrome/browser/ui/cocoa/extensions/device_permissions_dialog_controller.mm b/chrome/browser/ui/cocoa/extensions/device_permissions_dialog_controller.mm
new file mode 100644
index 0000000000000000000000000000000000000000..5bf1d3f5b7486a3ced69dfb8e071d2b9bada0479
--- /dev/null
+++ b/chrome/browser/ui/cocoa/extensions/device_permissions_dialog_controller.mm
@@ -0,0 +1,79 @@
+// Copyright 2014 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/device_permissions_dialog_controller.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/single_thread_task_runner.h"
+#include "base/thread_task_runner_handle.h"
+#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
+#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_window.h"
+#import "chrome/browser/ui/cocoa/extensions/device_permissions_view_controller.h"
+#include "device/usb/usb_device.h"
+
+using extensions::DevicePermissionsPrompt;
+
+namespace {
+
+void ShowDevicePermissionsDialogImpl(
+ content::WebContents* web_contents,
+ DevicePermissionsPrompt::Delegate* delegate,
+ scoped_refptr<DevicePermissionsPrompt::Prompt> prompt) {
+ // These objects will delete themselves when the dialog closes.
+ new DevicePermissionsDialogController(web_contents, delegate, prompt);
+}
+
+} // namespace
+
+DevicePermissionsDialogController::DevicePermissionsDialogController(
+ content::WebContents* web_contents,
+ DevicePermissionsPrompt::Delegate* delegate,
+ scoped_refptr<DevicePermissionsPrompt::Prompt> prompt)
+ : delegate_(delegate), prompt_(prompt) {
+ view_controller_.reset(
+ [[DevicePermissionsViewController alloc] initWithDelegate:this
+ prompt:prompt]);
+
+ prompt_->SetObserver(this);
+
+ 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, web_contents, sheet));
+}
+
+DevicePermissionsDialogController::~DevicePermissionsDialogController() {
+ prompt_->SetObserver(nullptr);
+}
+
+void DevicePermissionsDialogController::OnUsbDevicesChosen(
+ const std::vector<scoped_refptr<device::UsbDevice>>& devices) {
+ delegate_->OnUsbDevicesChosen(devices);
+ delegate_ = nullptr;
+ constrained_window_->CloseWebContentsModalDialog();
+}
+
+void DevicePermissionsDialogController::OnDevicesChanged() {
+ [view_controller_ devicesChanged];
+}
+
+void DevicePermissionsDialogController::OnConstrainedWindowClosed(
+ ConstrainedWindowMac* window) {
+ if (delegate_) {
+ std::vector<scoped_refptr<device::UsbDevice>> empty;
+ delegate_->OnUsbDevicesChosen(empty);
+ }
+ base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
+}
+
+// static
+DevicePermissionsPrompt::ShowDialogCallback
+DevicePermissionsPrompt::GetDefaultShowDialogCallback() {
+ return base::Bind(&ShowDevicePermissionsDialogImpl);
+}

Powered by Google App Engine
This is Rietveld 408576698