| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/webui/chromeos/emulator/device_emulator_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/emulator/device_emulator_ui.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | |
| 8 #include "base/values.h" | 7 #include "base/values.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_hand
ler.h" | 9 #include "chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_hand
ler.h" |
| 11 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
| 12 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/browser/web_ui.h" | 12 #include "content/public/browser/web_ui.h" |
| 14 #include "content/public/browser/web_ui_data_source.h" | 13 #include "content/public/browser/web_ui_data_source.h" |
| 15 #include "grit/browser_resources.h" | 14 #include "grit/browser_resources.h" |
| 16 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
| 17 | 16 |
| 18 namespace { | 17 namespace { |
| 19 | 18 |
| 20 // Create data source for chrome://device-emulator/. | 19 // Create data source for chrome://device-emulator/. |
| 21 content::WebUIDataSource* CreateDeviceEmulatorUIDataSource() { | 20 content::WebUIDataSource* CreateDeviceEmulatorUIDataSource() { |
| 22 content::WebUIDataSource* html = | 21 content::WebUIDataSource* html = |
| 23 content::WebUIDataSource::Create(chrome::kChromeUIDeviceEmulatorHost); | 22 content::WebUIDataSource::Create(chrome::kChromeUIDeviceEmulatorHost); |
| 24 | 23 |
| 25 html->SetJsonPath("strings.js"); | 24 // Add resources. |
| 25 html->AddResourcePath("audio_settings.html", |
| 26 IDR_DEVICE_EMULATOR_AUDIO_SETTINGS_HTML); |
| 27 html->AddResourcePath("audio_settings.js", |
| 28 IDR_DEVICE_EMULATOR_AUDIO_SETTINGS_JS); |
| 29 html->AddResourcePath("battery_settings.html", |
| 30 IDR_DEVICE_EMULATOR_BATTERY_SETTINGS_HTML); |
| 31 html->AddResourcePath("battery_settings.js", |
| 32 IDR_DEVICE_EMULATOR_BATTERY_SETTINGS_JS); |
| 33 html->AddResourcePath("bluetooth_settings.html", |
| 34 IDR_DEVICE_EMULATOR_BLUETOOTH_SETTINGS_HTML); |
| 35 html->AddResourcePath("bluetooth_settings.js", |
| 36 IDR_DEVICE_EMULATOR_BLUETOOTH_SETTINGS_JS); |
| 37 html->AddResourcePath("icons.html", IDR_DEVICE_EMULATOR_ICONS_HTML); |
| 38 html->AddResourcePath("device_emulator_pages.html", |
| 39 IDR_DEVICE_EMULATOR_PAGES_HTML); |
| 40 html->AddResourcePath("device_emulator_pages.js", |
| 41 IDR_DEVICE_EMULATOR_PAGES_JS); |
| 26 | 42 |
| 27 // Add resources. | 43 html->AddResourcePath("shared_styles.html", |
| 28 html->AddResourcePath("device_emulator.css", IDR_DEVICE_EMULATOR_CSS); | 44 IDR_DEVICE_EMULATOR_SHARED_STYLES_HTML); |
| 29 html->AddResourcePath("device_emulator.js", IDR_DEVICE_EMULATOR_JS); | 45 |
| 30 html->AddResourcePath("shared_styles.css", | |
| 31 IDR_DEVICE_EMULATOR_SHARED_STYLES_CSS); | |
| 32 html->AddResourcePath("audio_settings.html", IDR_AUDIO_SETTINGS_HTML); | |
| 33 html->AddResourcePath("audio_settings.js", IDR_AUDIO_SETTINGS_JS); | |
| 34 html->AddResourcePath("battery_settings.html", IDR_BATTERY_SETTINGS_HTML); | |
| 35 html->AddResourcePath("battery_settings.js", IDR_BATTERY_SETTINGS_JS); | |
| 36 html->AddResourcePath("bluetooth_settings.html", IDR_BLUETOOTH_SETTINGS_HTML); | |
| 37 html->AddResourcePath("bluetooth_settings.js", IDR_BLUETOOTH_SETTINGS_JS); | |
| 38 html->SetDefaultResource(IDR_DEVICE_EMULATOR_HTML); | 46 html->SetDefaultResource(IDR_DEVICE_EMULATOR_HTML); |
| 39 | 47 |
| 40 return html; | 48 return html; |
| 41 } | 49 } |
| 42 | 50 |
| 43 } // namespace | 51 } // namespace |
| 44 | 52 |
| 45 DeviceEmulatorUI::DeviceEmulatorUI(content::WebUI* web_ui) | 53 DeviceEmulatorUI::DeviceEmulatorUI(content::WebUI* web_ui) |
| 46 : WebUIController(web_ui) { | 54 : WebUIController(web_ui) { |
| 47 chromeos::DeviceEmulatorMessageHandler* handler = | 55 web_ui->AddMessageHandler(new chromeos::DeviceEmulatorMessageHandler()); |
| 48 new chromeos::DeviceEmulatorMessageHandler(); | |
| 49 handler->Init(); | |
| 50 web_ui->AddMessageHandler(handler); | |
| 51 | 56 |
| 52 content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(), | 57 content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(), |
| 53 CreateDeviceEmulatorUIDataSource()); | 58 CreateDeviceEmulatorUIDataSource()); |
| 54 } | 59 } |
| 55 | 60 |
| 56 DeviceEmulatorUI::~DeviceEmulatorUI() { | 61 DeviceEmulatorUI::~DeviceEmulatorUI() { |
| 57 } | 62 } |
| OLD | NEW |