forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Device provider for chrome://inspect that connects to DevTools bridge…
… (components/devtools_bridge). It hosts a WebContents to run WebRTC and GCD related code BUG=383418 Review URL: https://codereview.chromium.org/746663002 Cr-Commit-Position: refs/heads/master@{#306755}
- Loading branch information
Showing
18 changed files
with
314 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
chrome/browser/devtools/device/webrtc/background_worker.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE HTML> | ||
<!-- | ||
-- Copyright 2014 The Chromium Authors. All rights reserved. | ||
-- Use of this source code is governed by a BSD-style license that can be | ||
-- found in the LICENSE file. | ||
--> | ||
<html> | ||
<head> | ||
<script src="js/webrtc_device_provider.js"></script> | ||
</head> | ||
</html> |
14 changes: 14 additions & 0 deletions
14
chrome/browser/devtools/device/webrtc/js/webrtc_device_provider.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
/** | ||
* @constructor | ||
*/ | ||
function WebRTCDeviceProvider() { | ||
} | ||
|
||
addEventListener('DOMContentLoaded', function() { | ||
window.WebRTCDeviceProvider.instance = new WebRTCDeviceProvider(); | ||
chrome.send('loaded'); | ||
}, false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<grit latest_public_release="0" current_release="1"> | ||
<outputs> | ||
<output filename="grit/webrtc_device_provider_resources.h" type="rc_header"> | ||
<emit emit_type='prepend'></emit> | ||
</output> | ||
<output filename="grit/webrtc_device_provider_resources_map.cc" type="resource_file_map_source" /> | ||
<output filename="grit/webrtc_device_provider_resources_map.h" type="resource_map_header" /> | ||
<output filename="webrtc_device_provider_resources.pak" type="data_package" /> | ||
</outputs> | ||
<release seq="1"> | ||
<includes> | ||
<include name="IDR_BACKGROUND_WORKER_HTML" file="background_worker.html" flattenhtml="false" allowexternalscript="true" type="BINDATA" /> | ||
<include name="IDR_WEBRTC_DEVICE_PROVIDER_JS" file="js/webrtc_device_provider.js" type="BINDATA" /> | ||
</includes> | ||
</release> | ||
</grit> |
115 changes: 115 additions & 0 deletions
115
chrome/browser/devtools/device/webrtc/webrtc_device_provider.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/devtools/device/webrtc/webrtc_device_provider.h" | ||
|
||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/common/url_constants.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "content/public/browser/web_ui_data_source.h" | ||
#include "content/public/browser/web_ui_message_handler.h" | ||
#include "grit/webrtc_device_provider_resources_map.h" | ||
#include "ui/base/page_transition_types.h" | ||
|
||
const char kBackgroundWorkerURL[] = | ||
"chrome://webrtc-device-provider/background_worker.html"; | ||
|
||
namespace { | ||
|
||
class MessageHandler : public content::WebUIMessageHandler { | ||
public: | ||
explicit MessageHandler(WebRTCDeviceProvider* owner); | ||
|
||
void RegisterMessages() override; | ||
|
||
private: | ||
void HandleLoaded(const base::ListValue* args); | ||
|
||
WebRTCDeviceProvider* const owner_; | ||
}; | ||
|
||
// MessageHandler ------------------------------------------------------------- | ||
|
||
MessageHandler::MessageHandler( | ||
WebRTCDeviceProvider* owner) : owner_(owner) { | ||
} | ||
|
||
void MessageHandler::RegisterMessages() { | ||
web_ui()->RegisterMessageCallback( | ||
"loaded", | ||
base::Bind(&MessageHandler::HandleLoaded, base::Unretained(this))); | ||
} | ||
|
||
void MessageHandler::HandleLoaded( | ||
const base::ListValue* args) { | ||
if (!owner_) | ||
return; | ||
// TODO(serya): implement | ||
} | ||
|
||
} // namespace | ||
|
||
// WebRTCDeviceProvider::WebUI ------------------------------------------------ | ||
|
||
WebRTCDeviceProvider::WebUI::WebUI(content::WebUI* web_ui) | ||
: content::WebUIController(web_ui) { | ||
Profile* profile = Profile::FromWebUI(web_ui); | ||
|
||
content::WebUIDataSource* source = content::WebUIDataSource::Create( | ||
chrome::kChromeUIWebRTCDeviceProviderHost); | ||
|
||
for (size_t i = 0; i < kWebrtcDeviceProviderResourcesSize; i++) { | ||
source->AddResourcePath(kWebrtcDeviceProviderResources[i].name, | ||
kWebrtcDeviceProviderResources[i].value); | ||
} | ||
|
||
// Sets a stub message handler. If web contents was created by | ||
// WebRTCDeviceProvider message callbacks will be overridden by | ||
// a real implementation. | ||
web_ui->AddMessageHandler(new MessageHandler(nullptr)); | ||
|
||
content::WebUIDataSource::Add(profile, source); | ||
} | ||
|
||
WebRTCDeviceProvider::WebUI::~WebUI() { | ||
} | ||
|
||
// WebRTCDeviceProvider ------------------------------------------------------- | ||
|
||
WebRTCDeviceProvider::WebRTCDeviceProvider(content::BrowserContext* context) { | ||
background_worker_.reset(content::WebContents::Create( | ||
content::WebContents::CreateParams(context))); | ||
|
||
// TODO(serya): Make sure background_worker_ destructed before profile. | ||
GURL url(kBackgroundWorkerURL); | ||
|
||
DCHECK_EQ(chrome::kChromeUIWebRTCDeviceProviderHost, url.host()); | ||
|
||
background_worker_->GetController().LoadURL( | ||
url, | ||
content::Referrer(), | ||
ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | ||
std::string()); | ||
|
||
background_worker_->GetWebUI()->AddMessageHandler( | ||
new MessageHandler(this)); | ||
} | ||
|
||
WebRTCDeviceProvider::~WebRTCDeviceProvider() { | ||
} | ||
|
||
void WebRTCDeviceProvider::QueryDevices(const SerialsCallback& callback) { | ||
// TODO(serya): Implement | ||
} | ||
|
||
void WebRTCDeviceProvider::QueryDeviceInfo(const std::string& serial, | ||
const DeviceInfoCallback& callback) { | ||
// TODO(serya): Implement | ||
} | ||
|
||
void WebRTCDeviceProvider::OpenSocket(const std::string& serial, | ||
const std::string& socket_name, | ||
const SocketCallback& callback) { | ||
// TODO(serya): Implement | ||
} |
51 changes: 51 additions & 0 deletions
51
chrome/browser/devtools/device/webrtc/webrtc_device_provider.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_DEVTOOLS_DEVICE_WEBRTC_WEBRTC_DEVICE_PROVIDER_H_ | ||
#define CHROME_BROWSER_DEVTOOLS_DEVICE_WEBRTC_WEBRTC_DEVICE_PROVIDER_H_ | ||
|
||
#include "chrome/browser/devtools/device/android_device_manager.h" | ||
#include "content/public/browser/web_ui_controller.h" | ||
|
||
namespace content { | ||
class BrowserContext; | ||
class WebUI; | ||
} | ||
|
||
// Provides access to remote DevTools targets over WebRTC data channel and GCD. | ||
class WebRTCDeviceProvider final : public AndroidDeviceManager::DeviceProvider { | ||
public: | ||
/** | ||
* Provides resources for provider's background worker. Background worker | ||
* is a windowless page that implements most of functionality of the | ||
* provider. It sandboxes WebRTC connections with remote devices and other | ||
* provider implementation details. | ||
*/ | ||
class WebUI : public content::WebUIController { | ||
public: | ||
explicit WebUI(content::WebUI* web_ui); | ||
~WebUI() override; | ||
}; | ||
|
||
explicit WebRTCDeviceProvider(content::BrowserContext* context); | ||
|
||
// AndroidDeviceManager::DeviceProvider implementation. | ||
void QueryDevices(const SerialsCallback& callback) override; | ||
|
||
void QueryDeviceInfo(const std::string& serial, | ||
const DeviceInfoCallback& callback) override; | ||
|
||
void OpenSocket(const std::string& serial, | ||
const std::string& socket_name, | ||
const SocketCallback& callback) override; | ||
|
||
private: | ||
~WebRTCDeviceProvider() override; | ||
|
||
scoped_ptr<content::WebContents> background_worker_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(WebRTCDeviceProvider); | ||
}; | ||
|
||
#endif // CHROME_BROWSER_DEVTOOLS_DEVICE_WEBRTC_WEBRTC_DEVICE_PROVIDER_H_ |
30 changes: 30 additions & 0 deletions
30
chrome/browser/devtools/device/webrtc/webrtc_device_provider_browsertest.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
/** | ||
* Test fixture for WebRTCDeviceProvider. | ||
* @constructor | ||
* @extends {testing.Test} | ||
*/ | ||
function WebRTCDeviceProviderBrowserTest() {} | ||
|
||
WebRTCDeviceProviderBrowserTest.prototype = { | ||
__proto__: testing.Test.prototype, | ||
|
||
/** | ||
* Browse to the worker. | ||
*/ | ||
browsePreload: 'chrome://webrtc-device-provider/background_worker.html', | ||
|
||
preLoad: function() { | ||
this.makeAndRegisterMockHandler(['loaded']); | ||
this.mockHandler.expects(once()).loaded(); | ||
}, | ||
|
||
isAsync: true, | ||
}; | ||
|
||
TEST_F('WebRTCDeviceProviderBrowserTest', 'TestLoads', function() { | ||
testDone(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
chrome/browser/devtools/webrtc_device_provider_resources.gyp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright 2014 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
{ | ||
'targets': [ | ||
{ | ||
# GN version: //chrome/browser/devtools:webrtc_device_provider_resources | ||
'target_name': 'webrtc_device_provider_resources', | ||
'type': 'none', | ||
'variables': { | ||
'grit_out_dir': '<(SHARED_INTERMEDIATE_DIR)/chrome', | ||
}, | ||
'actions': [ | ||
{ | ||
'action_name': 'generate_webrtc_device_provider_resources', | ||
'variables': { | ||
'grit_grd_file': 'device/webrtc/resources.grd', | ||
}, | ||
'includes': [ '../../../build/grit_action.gypi' ], | ||
}, | ||
], | ||
'includes': [ '../../../build/grit_target.gypi' ], | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.