bluetooth_pairing_dialog.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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
3// found in the LICENSE file.
4
5#include "chrome/browser/chromeos/bluetooth/bluetooth_pairing_dialog.h"
6
7#include "base/json/json_writer.h"
8#include "chrome/browser/profiles/profile_manager.h"
9#include "chrome/browser/ui/browser_dialogs.h"
10#include "chrome/common/url_constants.h"
11#include "device/bluetooth/bluetooth_device.h"
12#include "grit/generated_resources.h"
13#include "ui/base/l10n/l10n_util.h"
14#include "ui/gfx/size.h"
15
16using content::WebContents;
17using content::WebUIMessageHandler;
18
19namespace chromeos {
20
21namespace {
22
23// Default width/height ratio of screen size.
24const int kDefaultWidth = 480;
25const int kDefaultHeight = 280;
26
27}  // namespace
28
29///////////////////////////////////////////////////////////////////////////////
30// BluetoothPairingDialog, public:
31
32BluetoothPairingDialog::BluetoothPairingDialog(
33    gfx::NativeWindow parent_window,
34    const device::BluetoothDevice* device)
35    : parent_window_(parent_window) {
36  device_data_.SetString("address", device->address());
37  device_data_.SetString("name", device->GetName());
38  device_data_.SetBoolean("paired", device->IsPaired());
39  device_data_.SetBoolean("bonded", device->IsBonded());
40  device_data_.SetBoolean("connected", device->IsConnected());
41}
42
43BluetoothPairingDialog::~BluetoothPairingDialog() {
44}
45
46void BluetoothPairingDialog::Show() {
47  chrome::ShowWebDialog(parent_window_,
48                        ProfileManager::GetDefaultProfile(),
49                        this);
50}
51
52///////////////////////////////////////////////////////////////////////////////
53// LoginWebDialog, protected:
54
55ui::ModalType BluetoothPairingDialog::GetDialogModalType() const {
56  return ui::MODAL_TYPE_SYSTEM;
57}
58
59string16 BluetoothPairingDialog::GetDialogTitle() const {
60  return l10n_util::GetStringUTF16(
61      IDS_OPTIONS_SETTINGS_BLUETOOTH_ADD_DEVICE_TITLE);
62}
63
64GURL BluetoothPairingDialog::GetDialogContentURL() const {
65  return GURL(chrome::kChromeUIBluetoothPairingURL);
66}
67
68void BluetoothPairingDialog::GetWebUIMessageHandlers(
69    std::vector<WebUIMessageHandler*>* handlers) const {
70}
71
72void BluetoothPairingDialog::GetDialogSize(gfx::Size* size) const {
73  size->SetSize(kDefaultWidth, kDefaultHeight);
74}
75
76std::string BluetoothPairingDialog::GetDialogArgs() const {
77  std::string data;
78  base::JSONWriter::Write(&device_data_, &data);
79  return data;
80}
81
82void BluetoothPairingDialog::OnDialogClosed(const std::string& json_retval) {
83  delete this;
84}
85
86void BluetoothPairingDialog::OnCloseContents(WebContents* source,
87                                             bool* out_close_dialog) {
88  if (out_close_dialog)
89    *out_close_dialog = true;
90}
91
92bool BluetoothPairingDialog::ShouldShowDialogTitle() const {
93  return true;
94}
95
96bool BluetoothPairingDialog::HandleContextMenu(
97    const content::ContextMenuParams& params) {
98  // Disable context menu.
99  return true;
100}
101
102}  // namespace chromeos
103