Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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/devtools/device/webrtc/webrtc_device_provider.h" | |
| 6 | |
| 7 #include "chrome/browser/ui/browser.h" | |
| 8 #include "chrome/common/url_constants.h" | |
| 9 #include "content/public/browser/web_contents.h" | |
| 10 #include "content/public/browser/web_ui_data_source.h" | |
| 11 #include "content/public/browser/web_ui_message_handler.h" | |
| 12 #include "grit/webrtc_device_provider_resources_map.h" | |
| 13 #include "ui/base/page_transition_types.h" | |
| 14 | |
| 15 class WebRTCDeviceProvider::MessageHandler | |
| 16 : public content::WebUIMessageHandler { | |
| 17 public: | |
| 18 void RegisterMessages() override; | |
| 19 | |
| 20 private: | |
| 21 void HandleLoaded(const base::ListValue* args); | |
| 22 }; | |
| 23 | |
| 24 // WebRTCDeviceProvider::WebUI | |
| 25 WebRTCDeviceProvider::WebUI::WebUI(content::WebUI* web_ui) | |
| 26 : content::WebUIController(web_ui), | |
| 27 handler_(new MessageHandler) { | |
| 28 Profile* profile = Profile::FromWebUI(web_ui); | |
| 29 | |
| 30 content::WebUIDataSource* source = content::WebUIDataSource::Create( | |
| 31 chrome::kChromeUIWebRTCDeviceProviderHost); | |
| 32 | |
| 33 for (size_t i = 0; i < kWebrtcDeviceProviderResourcesSize; i++) { | |
| 34 source->AddResourcePath(kWebrtcDeviceProviderResources[i].name, | |
| 35 kWebrtcDeviceProviderResources[i].value); | |
| 36 } | |
| 37 | |
| 38 web_ui->AddMessageHandler(handler_.get()); | |
| 39 | |
| 40 content::WebUIDataSource::Add(profile, source); | |
| 41 } | |
| 42 | |
| 43 WebRTCDeviceProvider::WebUI::~WebUI() {} | |
| 44 | |
| 45 // WebRTCDeviceProvider::MessageHandler | |
| 46 | |
| 47 void WebRTCDeviceProvider::MessageHandler::RegisterMessages() { | |
| 48 web_ui()->RegisterMessageCallback( | |
| 49 "loaded", | |
| 50 base::Bind(&MessageHandler::HandleLoaded, base::Unretained(this))); | |
| 51 } | |
| 52 | |
| 53 void WebRTCDeviceProvider::MessageHandler::HandleLoaded( | |
| 54 const base::ListValue* args) { | |
| 55 } | |
| 56 | |
| 57 // WebRTCDeviceProvider | |
| 58 | |
| 59 WebRTCDeviceProvider::WebRTCDeviceProvider(content::BrowserContext* context) { | |
| 60 background_worker_.reset(content::WebContents::Create( | |
| 61 content::WebContents::CreateParams(context))); | |
| 62 | |
| 63 // TODO(serya): Make sure background_worker_ destructed before profile. | |
| 64 | |
| 65 background_worker_->GetController().LoadURL( | |
| 66 GURL(chrome::kChromeUIWebRTCDeviceProviderURL), | |
|
dgozman
2014/11/27 14:50:03
Let's make this a local constant.
SeRya
2014/11/27 17:23:01
Done.
| |
| 67 content::Referrer(), | |
| 68 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
| 69 std::string()); | |
| 70 | |
| 71 handler_ = static_cast<WebUI*>( | |
| 72 background_worker_->GetWebUI()->GetController())->handler_.get(); | |
| 73 } | |
| 74 | |
| 75 WebRTCDeviceProvider::~WebRTCDeviceProvider() {} | |
| 76 | |
| 77 void WebRTCDeviceProvider::QueryDevices(const SerialsCallback& callback) { | |
| 78 // TODO(serya): Implement | |
| 79 } | |
| 80 | |
| 81 void WebRTCDeviceProvider::QueryDeviceInfo(const std::string& serial, | |
| 82 const DeviceInfoCallback& callback) { | |
| 83 // TODO(serya): Implement | |
| 84 } | |
| 85 | |
| 86 void WebRTCDeviceProvider::OpenSocket(const std::string& serial, | |
| 87 const std::string& socket_name, | |
| 88 const SocketCallback& callback) { | |
| 89 // TODO(serya): Implement | |
| 90 } | |
| OLD | NEW |