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

Side by Side Diff: chrome/browser/chromeos/bluetooth/bluetooth_pairing_dialog.cc

Issue 2684793004: [Harmony] Harmonize Bluetooth dialogs. (Closed)
Patch Set: . Created 3 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/chromeos/bluetooth/bluetooth_pairing_dialog.h" 5 #include "chrome/browser/chromeos/bluetooth/bluetooth_pairing_dialog.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "ash/public/cpp/shell_window_ids.h" 9 #include "ash/public/cpp/shell_window_ids.h"
10 #include "ash/shell.h"
10 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
11 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/ui/ash/ash_util.h"
12 #include "chrome/browser/ui/browser_dialogs.h" 15 #include "chrome/browser/ui/browser_dialogs.h"
13 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
14 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
15 #include "device/bluetooth/bluetooth_device.h" 18 #include "device/bluetooth/bluetooth_device.h"
19 #include "services/ui/public/cpp/property_type_converters.h"
20 #include "services/ui/public/interfaces/window_manager.mojom.h"
16 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/gfx/geometry/size.h" 22 #include "ui/gfx/geometry/size.h"
23 #include "ui/views/controls/webview/web_dialog_view.h"
24 #include "ui/views/widget/widget.h"
18 25
19 using content::WebContents; 26 using content::WebContents;
20 using content::WebUIMessageHandler; 27 using content::WebUIMessageHandler;
21 28
22 namespace chromeos { 29 namespace chromeos {
23 30
24 namespace { 31 namespace {
25 32
26 // Default width/height ratio of screen size. 33 // Default width/height ratio of screen size.
27 const int kDefaultWidth = 480; 34 const int kDefaultWidth = 480;
28 const int kDefaultHeight = 280; 35 const int kDefaultHeight = 280;
29 36
30 } // namespace 37 } // namespace
31 38
32 /////////////////////////////////////////////////////////////////////////////// 39 ///////////////////////////////////////////////////////////////////////////////
33 // BluetoothPairingDialog, public: 40 // BluetoothPairingDialog, public:
34 41
35 BluetoothPairingDialog::BluetoothPairingDialog( 42 BluetoothPairingDialog::BluetoothPairingDialog(
36 const device::BluetoothDevice* device) 43 const device::BluetoothDevice* device)
37 : webui_(nullptr) { 44 : webui_(nullptr) {
38 device_data_.SetString("address", device->GetAddress()); 45 device_data_.SetString("address", device->GetAddress());
39 device_data_.SetString("name", device->GetNameForDisplay()); 46 device_data_.SetString("name", device->GetNameForDisplay());
40 device_data_.SetBoolean("paired", device->IsPaired()); 47 device_data_.SetBoolean("paired", device->IsPaired());
41 device_data_.SetBoolean("connected", device->IsConnected()); 48 device_data_.SetBoolean("connected", device->IsConnected());
42 } 49 }
43 50
44 BluetoothPairingDialog::~BluetoothPairingDialog() { 51 BluetoothPairingDialog::~BluetoothPairingDialog() {
45 } 52 }
46 53
47 void BluetoothPairingDialog::ShowInContainer(int container_id) { 54 void BluetoothPairingDialog::ShowInContainer(int container_id,
55 views::WebDialogView* view) {
48 // Dialog must be in a modal window container. 56 // Dialog must be in a modal window container.
49 DCHECK(container_id == ash::kShellWindowId_SystemModalContainer || 57 DCHECK(container_id == ash::kShellWindowId_SystemModalContainer ||
50 container_id == ash::kShellWindowId_LockSystemModalContainer); 58 container_id == ash::kShellWindowId_LockSystemModalContainer);
51 59
52 // Bluetooth settings are currently stored on the device, accessible for 60 views::Widget* widget = new views::Widget;
James Cook 2017/02/09 15:18:02 This block of code looks mostly copied from System
xdai1 2017/02/09 22:58:28 I don't think they're same. Actually this block of
53 // everyone who uses the machine. As such we can use the active user profile. 61 views::Widget::InitParams params(
54 chrome::ShowWebDialogInContainer( 62 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
55 container_id, ProfileManager::GetActiveUserProfile(), this); 63 params.delegate = view;
64 if (chrome::IsRunningInMash()) {
65 using ui::mojom::WindowManager;
66 params.mus_properties[WindowManager::kContainerId_InitProperty] =
67 mojo::ConvertTo<std::vector<uint8_t>>(container_id);
68 } else {
69 params.parent = ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(),
70 container_id);
71 }
72 widget->Init(params);
73
74 // Observer is needed for ChromeVox extension to send messages between content
75 // and background scripts.
76 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
77 view->web_contents());
78
79 widget->Show();
56 } 80 }
57 81
58 /////////////////////////////////////////////////////////////////////////////// 82 ///////////////////////////////////////////////////////////////////////////////
59 // LoginWebDialog, protected: 83 // LoginWebDialog, protected:
60 84
61 ui::ModalType BluetoothPairingDialog::GetDialogModalType() const { 85 ui::ModalType BluetoothPairingDialog::GetDialogModalType() const {
62 return ui::MODAL_TYPE_SYSTEM; 86 return ui::MODAL_TYPE_SYSTEM;
63 } 87 }
64 88
65 base::string16 BluetoothPairingDialog::GetDialogTitle() const { 89 base::string16 BluetoothPairingDialog::GetDialogTitle() const {
(...skipping 28 matching lines...) Expand all
94 void BluetoothPairingDialog::OnDialogClosed(const std::string& json_retval) { 118 void BluetoothPairingDialog::OnDialogClosed(const std::string& json_retval) {
95 delete this; 119 delete this;
96 } 120 }
97 121
98 void BluetoothPairingDialog::OnCloseContents(WebContents* source, 122 void BluetoothPairingDialog::OnCloseContents(WebContents* source,
99 bool* out_close_dialog) { 123 bool* out_close_dialog) {
100 *out_close_dialog = true; 124 *out_close_dialog = true;
101 } 125 }
102 126
103 bool BluetoothPairingDialog::ShouldShowDialogTitle() const { 127 bool BluetoothPairingDialog::ShouldShowDialogTitle() const {
104 return true; 128 return false;
105 } 129 }
106 130
107 bool BluetoothPairingDialog::HandleContextMenu( 131 bool BluetoothPairingDialog::HandleContextMenu(
108 const content::ContextMenuParams& params) { 132 const content::ContextMenuParams& params) {
109 // Disable context menu. 133 // Disable context menu.
110 return true; 134 return true;
111 } 135 }
112 136
113 } // namespace chromeos 137 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698