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.h" | |
| 13 #include "grit/webrtc_device_provider_resources_map.h" | |
| 14 #include "ui/base/page_transition_types.h" | |
| 15 | |
| 16 class WebRTCDeviceProvider::MessageHandler | |
|
dgozman
2014/11/27 13:45:27
This class needs a pointer to device provider to d
SeRya
2014/11/27 14:15:08
Sure. Will be added on first use.
| |
| 17 : public content::WebUIMessageHandler { | |
| 18 public: | |
| 19 void RegisterMessages() override; | |
| 20 | |
| 21 private: | |
| 22 void HandleLoaded(const base::ListValue* args); | |
| 23 }; | |
| 24 | |
| 25 // WebRTCDeviceProvider::WebUI | |
| 26 WebRTCDeviceProvider::WebUI::WebUI(content::WebUI* web_ui) | |
| 27 : content::WebUIController(web_ui), | |
| 28 handler_(new MessageHandler) { | |
| 29 Profile* profile = Profile::FromWebUI(web_ui); | |
| 30 | |
| 31 content::WebUIDataSource* source = content::WebUIDataSource::Create( | |
| 32 chrome::kChromeUIWebRTCDeviceProviderHost); | |
| 33 | |
| 34 for (size_t i = 0; i < kWebrtcDeviceProviderResourcesSize; i++) { | |
| 35 source->AddResourcePath(kWebrtcDeviceProviderResources[i].name, | |
| 36 kWebrtcDeviceProviderResources[i].value); | |
| 37 } | |
| 38 source->SetDefaultResource(IDR_BACKGROUND_WORKER_HTML); | |
| 39 | |
| 40 web_ui->AddMessageHandler(handler_.get()); | |
| 41 | |
| 42 content::WebUIDataSource::Add(profile, source); | |
| 43 } | |
| 44 | |
| 45 WebRTCDeviceProvider::WebUI::~WebUI() {} | |
| 46 | |
| 47 // WebRTCDeviceProvider::MessageHandler | |
| 48 | |
| 49 void WebRTCDeviceProvider::MessageHandler::RegisterMessages() { | |
| 50 web_ui()->RegisterMessageCallback( | |
| 51 "loaded", | |
| 52 base::Bind(&MessageHandler::HandleLoaded, base::Unretained(this))); | |
| 53 } | |
| 54 | |
| 55 void WebRTCDeviceProvider::MessageHandler::HandleLoaded( | |
| 56 const base::ListValue* args) { | |
| 57 } | |
| 58 | |
| 59 // WebRTCDeviceProvider | |
| 60 | |
| 61 WebRTCDeviceProvider::WebRTCDeviceProvider(content::BrowserContext* context) { | |
| 62 background_worker_.reset(content::WebContents::Create( | |
| 63 content::WebContents::CreateParams(context))); | |
| 64 | |
| 65 // TODO(serya): Make sure background_worker_ destructed before profile. | |
| 66 | |
| 67 background_worker_->GetController().LoadURL( | |
| 68 GURL(chrome::kChromeUIWebRTCDeviceProviderURL), | |
|
dgozman
2014/11/27 13:45:27
I think the |SetDefaultResource()| call allows you
SeRya
2014/11/27 14:15:08
Let's remove SetDefaultResource with webrtc_device
SeRya
2014/11/27 14:15:08
Lets remove SetDefaultResource. This URL is not in
| |
| 69 content::Referrer(), | |
| 70 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
| 71 std::string()); | |
| 72 | |
| 73 handler_ = static_cast<WebUI*>( | |
|
dgozman
2014/11/27 13:45:27
Why don't you just AddMessageHandler from here ins
SeRya
2014/11/27 14:15:08
Problem is the following. If I manually type the U
| |
| 74 background_worker_->GetWebUI()->GetController())->handler_.get(); | |
| 75 } | |
| 76 | |
| 77 WebRTCDeviceProvider::~WebRTCDeviceProvider() {} | |
| 78 | |
| 79 void WebRTCDeviceProvider::QueryDevices(const SerialsCallback& callback) { | |
| 80 // TODO(serya): Implement | |
| 81 } | |
| 82 | |
| 83 void WebRTCDeviceProvider::QueryDeviceInfo(const std::string& serial, | |
| 84 const DeviceInfoCallback& callback) { | |
| 85 // TODO(serya): Implement | |
| 86 } | |
| 87 | |
| 88 void WebRTCDeviceProvider::OpenSocket(const std::string& serial, | |
| 89 const std::string& socket_name, | |
| 90 const SocketCallback& callback) { | |
| 91 // TODO(serya): Implement | |
| 92 } | |
| OLD | NEW |