Skip to content

Commit

Permalink
Device provider for chrome://inspect that connects to DevTools bridge…
Browse files Browse the repository at this point in the history
… (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
serya authored and Commit bot committed Dec 4, 2014
1 parent 06c1b21 commit 91af3ad
Show file tree
Hide file tree
Showing 18 changed files with 314 additions and 10 deletions.
6 changes: 4 additions & 2 deletions chrome/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -351,18 +351,20 @@ repack("packed_extra_resources") {
if (!is_ios && !is_android) {
# New paks should be added here by default.
sources += [
"$root_gen_dir/webkit/devtools_resources.pak",
"$root_gen_dir/chrome/component_extension_resources.pak",
"$root_gen_dir/chrome/options_resources.pak",
"$root_gen_dir/chrome/quota_internals_resources.pak",
"$root_gen_dir/chrome/sync_file_system_internals_resources.pak",
"$root_gen_dir/chrome/webrtc_device_provider_resources.pak",
"$root_gen_dir/webkit/devtools_resources.pak",
]
deps += [
"//content/browser/devtools:devtools_resources",
"//chrome/browser/devtools:webrtc_device_provider_resources",
"//chrome/browser/resources:component_extension_resources",
"//chrome/browser/resources:options_resources",
"//chrome/browser/resources:quota_internals_resources",
"//chrome/browser/resources:sync_file_system_internals_resources",
"//content/browser/devtools:devtools_resources",
]
}
if (!is_ios) {
Expand Down
34 changes: 27 additions & 7 deletions chrome/browser/devtools/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

if (!is_android) {
import("//tools/grit/grit_rule.gni")
}

action("devtools_protocol_constants") {
script = "devtools_protocol_constants_generator.py"

Expand Down Expand Up @@ -61,19 +65,24 @@ static_library("devtools") {

if (!is_android) {
deps += [
"//chrome:extra_resources",
"//chrome:resources",
"//chrome:strings",
"//chrome/app/theme:theme_resources",
"//chrome/common/extensions/api",
"//chrome/common/extensions/api:api_registration",
"//chrome:extra_resources",
"//chrome:resources",
"//chrome:strings",
"//net:http_server",
"//skia",
"//third_party/icu",
"//third_party/leveldatabase",
"//third_party/libusb",
":webrtc_device_provider_resources",
]
sources += [
"browser_list_tabcontents_provider.cc",
"browser_list_tabcontents_provider.h",
"chrome_devtools_manager_delegate.cc",
"chrome_devtools_manager_delegate.h",
"device/adb/adb_client_socket.cc",
"device/adb/adb_client_socket.h",
"device/adb/adb_device_info_query.cc",
Expand All @@ -83,6 +92,8 @@ static_library("devtools") {
"device/android_device_manager.cc",
"device/android_device_manager.h",
"device/android_web_socket.cc",
"device/webrtc/webrtc_device_provider.cc",
"device/webrtc/webrtc_device_provider.h",
"device/devtools_android_bridge.cc",
"device/devtools_android_bridge.h",
"device/port_forwarding_controller.cc",
Expand All @@ -97,10 +108,6 @@ static_library("devtools") {
"device/usb/android_usb_socket.h",
"device/usb/usb_device_provider.cc",
"device/usb/usb_device_provider.h",
"browser_list_tabcontents_provider.cc",
"browser_list_tabcontents_provider.h",
"chrome_devtools_manager_delegate.cc",
"chrome_devtools_manager_delegate.h",
"devtools_contents_resizing_strategy.cc",
"devtools_contents_resizing_strategy.h",
"devtools_embedder_message_dispatcher.cc",
Expand All @@ -124,3 +131,16 @@ static_library("devtools") {
]
}
}

if (!is_android) {
# GYP version: chrome/browser/devtools/webrtc_device_provider_resources.gyp:webrtc_device_provider_resources
grit("webrtc_device_provider_resources") {
source = "device/webrtc/resources.grd"
output_dir = "$root_gen_dir/chrome"
outputs = [
"grit/webrtc_device_provider_resources_map.cc",
"grit/webrtc_device_provider_resources_map.h",
"webrtc_device_provider_resources.pak",
]
}
}
11 changes: 11 additions & 0 deletions chrome/browser/devtools/device/webrtc/background_worker.html
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 chrome/browser/devtools/device/webrtc/js/webrtc_device_provider.js
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);
17 changes: 17 additions & 0 deletions chrome/browser/devtools/device/webrtc/resources.grd
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 chrome/browser/devtools/device/webrtc/webrtc_device_provider.cc
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 chrome/browser/devtools/device/webrtc/webrtc_device_provider.h
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_
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();
});
2 changes: 1 addition & 1 deletion chrome/browser/devtools/devtools_targets_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ static void CallOnTarget(
const DevToolsTargetsUIHandler::TargetCallback& callback,
DevToolsAndroidBridge* bridge,
scoped_refptr<DevToolsAndroidBridge::RemotePage> page) {
callback.Run(page.get() ? bridge->CreatePageTarget(page) : nullptr);
callback.Run(bridge && page.get() ? bridge->CreatePageTarget(page) : nullptr);
}

void AdbTargetsUIHandler::Open(
Expand Down
26 changes: 26 additions & 0 deletions chrome/browser/devtools/webrtc_device_provider_resources.gyp
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' ],
},
]
}
4 changes: 4 additions & 0 deletions chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
#if defined(OS_ANDROID) || defined(OS_IOS)
#include "chrome/browser/ui/webui/net_export_ui.h"
#else
#include "chrome/browser/devtools/device/webrtc/webrtc_device_provider.h"
#include "chrome/browser/ui/webui/devtools_ui.h"
#include "chrome/browser/ui/webui/inspect_ui.h"
#endif
Expand Down Expand Up @@ -452,6 +453,9 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
return &NewWebUI<InlineLoginUI>;
if (url.SchemeIs(content::kChromeDevToolsScheme))
return &NewWebUI<DevToolsUI>;
if (url.host() == chrome::kChromeUIWebRTCDeviceProviderHost)
return &NewWebUI<WebRTCDeviceProvider::WebUI>;

// chrome://inspect isn't supported on Android nor iOS. Page debugging is
// handled by a remote devtools on the host machine, and other elements, i.e.
// extensions aren't supported.
Expand Down
Loading

0 comments on commit 91af3ad

Please sign in to comment.