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