1 // Copyright (c) 2013 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/ui/webui/chromeos/bluetooth_pairing_ui.h" 6 7 #include "base/values.h" 8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h" 10 #include "chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.h" 11 #include "chrome/common/url_constants.h" 12 #include "content/public/browser/web_ui.h" 13 #include "content/public/browser/web_ui_data_source.h" 14 #include "grit/browser_resources.h" 15 16 using content::WebContents; 17 using content::WebUIMessageHandler; 18 19 namespace chromeos { 20 21 BluetoothPairingUI::BluetoothPairingUI(content::WebUI* web_ui) 22 : WebDialogUI(web_ui), 23 core_handler_(new options::CoreChromeOSOptionsHandler()), 24 bluetooth_handler_(new options::BluetoothOptionsHandler()) { 25 DictionaryValue localized_strings; 26 27 core_handler_->set_handlers_host(this); 28 core_handler_->GetLocalizedValues(&localized_strings); 29 web_ui->AddMessageHandler(core_handler_); 30 31 bluetooth_handler_->GetLocalizedValues(&localized_strings); 32 web_ui->AddMessageHandler(bluetooth_handler_); 33 34 content::WebUIDataSource* source = 35 content::WebUIDataSource::Create(chrome::kChromeUIBluetoothPairingHost); 36 source->SetUseJsonJSFormatV2(); 37 source->AddLocalizedStrings(localized_strings); 38 source->SetJsonPath("strings.js"); 39 source->SetDefaultResource(IDR_BLUETOOTH_PAIR_DEVICE_HTML); 40 source->DisableContentSecurityPolicy(); 41 42 Profile* profile = Profile::FromWebUI(web_ui); 43 content::WebUIDataSource::Add(profile, source); 44 } 45 46 BluetoothPairingUI::~BluetoothPairingUI() { 47 // Uninitialize all registered handlers. The base class owns them and it will 48 // eventually delete them. 49 core_handler_->Uninitialize(); 50 bluetooth_handler_->Uninitialize(); 51 } 52 53 void BluetoothPairingUI::InitializeHandlers() { 54 core_handler_->InitializeHandler(); 55 bluetooth_handler_->InitializeHandler(); 56 core_handler_->InitializePage(); 57 bluetooth_handler_->InitializePage(); 58 } 59 60 } // namespace chromeos 61