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 const char kBackgroundWorkerURL[] = | |
| 16 "chrome://webrtc-device-provider/background_worker.html"; | |
| 17 | |
| 18 class WebRTCDeviceProvider::MessageHandler | |
| 19 : public content::WebUIMessageHandler { | |
| 20 public: | |
| 21 explicit MessageHandler(WebRTCDeviceProvider* owner); | |
| 22 | |
| 23 void RegisterMessages() override; | |
| 24 | |
| 25 private: | |
| 26 void HandleLoaded(const base::ListValue* args); | |
| 27 | |
| 28 WebRTCDeviceProvider* const owner_; | |
| 29 }; | |
| 30 | |
| 31 // WebRTCDeviceProvider::WebUI | |
| 32 WebRTCDeviceProvider::WebUI::WebUI(content::WebUI* web_ui) | |
| 33 : content::WebUIController(web_ui) { | |
| 34 Profile* profile = Profile::FromWebUI(web_ui); | |
| 35 | |
| 36 content::WebUIDataSource* source = content::WebUIDataSource::Create( | |
| 37 chrome::kChromeUIWebRTCDeviceProviderHost); | |
| 38 | |
| 39 for (size_t i = 0; i < kWebrtcDeviceProviderResourcesSize; i++) { | |
| 40 source->AddResourcePath(kWebrtcDeviceProviderResources[i].name, | |
| 41 kWebrtcDeviceProviderResources[i].value); | |
| 42 } | |
| 43 | |
| 44 // Sets a stub message handler. If web contents was created by | |
| 45 // WebRTCDeviceProvider message callbacks will be overridden by | |
| 46 // a real implementation. | |
| 47 web_ui->AddMessageHandler(new MessageHandler(NULL)); | |
|
dgozman
2014/11/28 12:58:06
nit: nullptr
SeRya
2014/11/28 13:07:16
Done.
| |
| 48 | |
| 49 content::WebUIDataSource::Add(profile, source); | |
| 50 } | |
| 51 | |
| 52 WebRTCDeviceProvider::WebUI::~WebUI() { | |
| 53 } | |
| 54 | |
| 55 // WebRTCDeviceProvider::MessageHandler | |
| 56 WebRTCDeviceProvider::MessageHandler::MessageHandler( | |
| 57 WebRTCDeviceProvider* owner) : owner_(owner) { | |
| 58 } | |
| 59 | |
| 60 void WebRTCDeviceProvider::MessageHandler::RegisterMessages() { | |
| 61 web_ui()->RegisterMessageCallback( | |
| 62 "loaded", | |
| 63 base::Bind(&MessageHandler::HandleLoaded, base::Unretained(this))); | |
| 64 } | |
| 65 | |
| 66 void WebRTCDeviceProvider::MessageHandler::HandleLoaded( | |
| 67 const base::ListValue* args) { | |
| 68 if (!owner_) | |
| 69 return; | |
| 70 // TODO(serya): implement | |
| 71 } | |
| 72 | |
| 73 // WebRTCDeviceProvider | |
| 74 | |
| 75 WebRTCDeviceProvider::WebRTCDeviceProvider(content::BrowserContext* context) { | |
| 76 background_worker_.reset(content::WebContents::Create( | |
| 77 content::WebContents::CreateParams(context))); | |
| 78 | |
| 79 // TODO(serya): Make sure background_worker_ destructed before profile. | |
| 80 GURL url(kBackgroundWorkerURL); | |
| 81 | |
| 82 DCHECK_EQ(chrome::kChromeUIWebRTCDeviceProviderHost, url.host()); | |
| 83 | |
| 84 background_worker_->GetController().LoadURL( | |
| 85 url, | |
| 86 content::Referrer(), | |
| 87 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
| 88 std::string()); | |
| 89 | |
| 90 background_worker_->GetWebUI()->AddMessageHandler( | |
| 91 new MessageHandler(this)); | |
| 92 } | |
| 93 | |
| 94 WebRTCDeviceProvider::~WebRTCDeviceProvider() { | |
| 95 } | |
| 96 | |
| 97 void WebRTCDeviceProvider::QueryDevices(const SerialsCallback& callback) { | |
| 98 // TODO(serya): Implement | |
| 99 } | |
| 100 | |
| 101 void WebRTCDeviceProvider::QueryDeviceInfo(const std::string& serial, | |
| 102 const DeviceInfoCallback& callback) { | |
| 103 // TODO(serya): Implement | |
| 104 } | |
| 105 | |
| 106 void WebRTCDeviceProvider::OpenSocket(const std::string& serial, | |
| 107 const std::string& socket_name, | |
| 108 const SocketCallback& callback) { | |
| 109 // TODO(serya): Implement | |
| 110 } | |
| OLD | NEW |