Commit 6010a89c authored by Regan Hsu's avatar Regan Hsu Committed by Commit Bot

[CrOS PhoneHub] Integrate fake phone with chrome://multidevice-internals

* New PhoneHub tab to chrome://multidevice-internals
* Adds a toggle that when flipped on, will cause a FakePhoneHubManager
  to be used instead.

Screenshot: https://screenshot.googleplex.com/7dimKet6oWrzeR4

Bug: 1106937
Change-Id: Ib2697abfaf15153b394689a804ff5ff73994ed15
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2380608Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Regan Hsu <hsuregan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802851}
parent ddbe089b
......@@ -11,14 +11,26 @@ js_type_check("closure_compile") {
":log_object",
":logging_tab",
":multidevice_internals",
":multidevice_logs_browser_proxy",
":multidevice_phonehub_browser_proxy",
":phonehub_tab",
":types",
]
}
js_library("phonehub_tab") {
deps = [ ":multidevice_phonehub_browser_proxy" ]
}
js_library("multidevice_phonehub_browser_proxy") {
deps = [ "//ui/webui/resources/js:cr.m" ]
}
js_library("multidevice_internals") {
deps = [
":log_object",
":logging_tab",
":phonehub_tab",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
"//ui/webui/resources/js:cr.m",
]
......@@ -61,6 +73,7 @@ html_to_js("web_components") {
"log_object.js",
"logging_tab.js",
"multidevice_internals.js",
"phonehub_tab.js",
"shared_style.js",
]
}
......@@ -33,4 +33,5 @@
<cr-tabs selected="{{selectedTabIndex_}}" tab-names="[[tabNames_]]"></cr-tabs>
<iron-pages selected="[[selectedTabIndex_]]">
<logging-tab></logging-tab>
<phonehub-tab></phonehub-tab>
</iron-pages>
......@@ -6,6 +6,7 @@ import 'chrome://resources/cr_elements/cr_tabs/cr_tabs.m.js';
import 'chrome://resources/polymer/v3_0/iron-location/iron-location.js';
import 'chrome://resources/polymer/v3_0/iron-pages/iron-pages.js';
import './logging_tab.js';
import './phonehub_tab.js';
import './shared_style.js';
import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
......@@ -33,7 +34,7 @@ Polymer({
/** @private */
tabNames_: {
type: Array,
value: () => ['Logs'],
value: () => ['Logs', 'PhoneHub'],
readonly: true,
},
......
......@@ -27,6 +27,10 @@
file="${root_gen_dir}\chrome\browser\resources\chromeos\multidevice_internals\logging_tab.js"
use_base_dir="false"
type="BINDATA"/>
<include name="IDR_MULTIDEVICE_INTERNALS_PHONEHUB_TAB_JS"
file="${root_gen_dir}\chrome\browser\resources\chromeos\multidevice_internals\phonehub_tab.js"
use_base_dir="false"
type="BINDATA"/>
<include name="IDR_MULTIDEVICE_INTERNALS_SHARED_STYLE_JS"
file="${root_gen_dir}\chrome\browser\resources\chromeos\multidevice_internals\shared_style.js"
use_base_dir="false"
......@@ -34,6 +38,9 @@
<include name="IDR_MULTIDEVICE_INTERNALS_MULTIDEVICE_LOGS_BROWSER_PROXY_JS"
file="multidevice_logs_browser_proxy.js"
type="BINDATA"/>
<include name="IDR_MULTIDEVICE_INTERNALS_MULTIDEVICE_PHONEHUB_BROWSER_PROXY_JS"
file="multidevice_phonehub_browser_proxy.js"
type="BINDATA"/>
<include name="IDR_MULTIDEVICE_INTERNALS_TYPES_JS"
file="types.js"
type="BINDATA"/>
......
// Copyright 2020 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.
import {addSingletonGetter} from 'chrome://resources/js/cr.m.js';
/**
* JavaScript hooks into the native WebUI handler for Phonehub tab.
*/
export class MultidevicePhoneHubBrowserProxy {
/**
* Enables or disables the FakePhoneHubManager.
* @param {boolean} enabled Whether to enable the fake phone hub manager.
*/
setFakePhoneHubManagerEnabled(enabled) {
return chrome.send('setFakePhoneHubManagerEnabled', [enabled]);
}
}
addSingletonGetter(MultidevicePhoneHubBrowserProxy);
<style include="cr-shared-style shared-style">
#container {
display: flex;
justify-content: center;
}
.row {
flex: 1;
}
cr-toggle {
margin: 5px;
}
</style>
<div id="container">
<div class="cr-row">
<div class="cr-padded-text">
Toggle on to use fake PhoneHub
</div>
<cr-toggle checked="{{shouldEnableFakePhoneHubManager_}}">
</cr-toggle>
</div>
</div>
// Copyright 2020 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.
import 'chrome://resources/cr_elements/cr_toggle/cr_toggle.m.js';
import 'chrome://resources/cr_elements/shared_style_css.m.js';
import './shared_style.js';
import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {MultidevicePhoneHubBrowserProxy} from './multidevice_phonehub_browser_proxy.js';
Polymer({
is: 'phonehub-tab',
_template: html`{__html_template__}`,
properties: {
shouldEnableFakePhoneHubManager_: {
type: Boolean,
value: false,
observer: 'onShouldEnableFakePhoneHubManagerChanged_'
},
},
/** @private {?MultidevicePhoneHubBrowserProxy}*/
browserProxy_: null,
/** @override */
created() {
this.browserProxy_ = MultidevicePhoneHubBrowserProxy.getInstance();
},
/** @private */
onShouldEnableFakePhoneHubManagerChanged_() {
this.browserProxy_.setFakePhoneHubManagerEnabled(
this.shouldEnableFakePhoneHubManager_);
},
});
......@@ -2317,6 +2317,8 @@ static_library("ui") {
"webui/chromeos/machine_learning/machine_learning_internals_ui.h",
"webui/chromeos/multidevice_internals/multidevice_internals_logs_handler.cc",
"webui/chromeos/multidevice_internals/multidevice_internals_logs_handler.h",
"webui/chromeos/multidevice_internals/multidevice_internals_phone_hub_handler.cc",
"webui/chromeos/multidevice_internals/multidevice_internals_phone_hub_handler.h",
"webui/chromeos/multidevice_internals/multidevice_internals_ui.cc",
"webui/chromeos/multidevice_internals/multidevice_internals_ui.h",
"webui/chromeos/multidevice_setup/multidevice_setup_dialog.cc",
......@@ -2549,6 +2551,7 @@ static_library("ui") {
"//chromeos/components/multidevice/debug_webui",
"//chromeos/components/multidevice/logging",
"//chromeos/components/phonehub",
"//chromeos/components/phonehub:debug",
"//chromeos/components/print_management",
"//chromeos/components/proximity_auth",
"//chromeos/components/quick_answers",
......
// Copyright 2020 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/ui/webui/chromeos/multidevice_internals/multidevice_internals_phone_hub_handler.h"
#include "ash/public/cpp/system_tray.h"
#include "chrome/browser/chromeos/phonehub/phone_hub_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chromeos/components/phonehub/fake_phone_hub_manager.h"
namespace chromeos {
namespace multidevice {
MultidevicePhoneHubHandler::MultidevicePhoneHubHandler() = default;
MultidevicePhoneHubHandler::~MultidevicePhoneHubHandler() {
if (fake_phone_hub_manager_)
SetSystemPhoneHubManagerEnabled();
}
void MultidevicePhoneHubHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"setFakePhoneHubManagerEnabled",
base::BindRepeating(
&MultidevicePhoneHubHandler::HandleSetFakePhoneHubManagerEnabled,
base::Unretained(this)));
}
void MultidevicePhoneHubHandler::SetSystemPhoneHubManagerEnabled() {
fake_phone_hub_manager_.reset();
Profile* profile = Profile::FromWebUI(web_ui());
chromeos::phonehub::PhoneHubManager* phone_hub_manager =
chromeos::phonehub::PhoneHubManagerFactory::GetForProfile(profile);
ash::SystemTray::Get()->SetPhoneHubManager(phone_hub_manager);
}
void MultidevicePhoneHubHandler::SetFakePhoneHubManagerEnabled() {
fake_phone_hub_manager_ = std::make_unique<phonehub::FakePhoneHubManager>();
ash::SystemTray::Get()->SetPhoneHubManager(fake_phone_hub_manager_.get());
}
void MultidevicePhoneHubHandler::HandleSetFakePhoneHubManagerEnabled(
const base::ListValue* args) {
AllowJavascript();
bool enabled = false;
CHECK(args->GetBoolean(0, &enabled));
if (enabled) {
SetFakePhoneHubManagerEnabled();
return;
}
SetSystemPhoneHubManagerEnabled();
}
} // namespace multidevice
} // namespace chromeos
// Copyright 2020 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_UI_WEBUI_CHROMEOS_MULTIDEVICE_INTERNALS_MULTIDEVICE_INTERNALS_PHONE_HUB_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_MULTIDEVICE_INTERNALS_MULTIDEVICE_INTERNALS_PHONE_HUB_HANDLER_H_
#include "content/public/browser/web_ui_message_handler.h"
namespace chromeos {
namespace phonehub {
class FakePhoneHubManager;
} // namespace phonehub
namespace multidevice {
// WebUIMessageHandler for chrome://multidevice-internals PhoneHub section.
class MultidevicePhoneHubHandler : public content::WebUIMessageHandler {
public:
MultidevicePhoneHubHandler();
MultidevicePhoneHubHandler(const MultidevicePhoneHubHandler&) = delete;
MultidevicePhoneHubHandler& operator=(const MultidevicePhoneHubHandler&) =
delete;
~MultidevicePhoneHubHandler() override;
// content::WebUIMessageHandler:
void RegisterMessages() override;
void OnJavascriptAllowed() override {}
void OnJavascriptDisallowed() override {}
private:
void SetSystemPhoneHubManagerEnabled();
void SetFakePhoneHubManagerEnabled();
void HandleSetFakePhoneHubManagerEnabled(const base::ListValue* args);
std::unique_ptr<phonehub::FakePhoneHubManager> fake_phone_hub_manager_;
};
} // namespace multidevice
} // namespace chromeos
#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_MULTIDEVICE_INTERNALS_MULTIDEVICE_INTERNALS_PHONE_HUB_HANDLER_H_
......@@ -7,6 +7,7 @@
#include "base/containers/span.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chromeos/multidevice_internals/multidevice_internals_logs_handler.h"
#include "chrome/browser/ui/webui/chromeos/multidevice_internals/multidevice_internals_phone_hub_handler.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/multidevice_internals_resources.h"
......@@ -39,6 +40,8 @@ MultideviceInternalsUI::MultideviceInternalsUI(content::WebUI* web_ui)
content::WebUIDataSource::Add(profile, html_source);
web_ui->AddMessageHandler(
std::make_unique<multidevice::MultideviceLogsHandler>());
web_ui->AddMessageHandler(
std::make_unique<multidevice::MultidevicePhoneHubHandler>());
}
MultideviceInternalsUI::~MultideviceInternalsUI() = default;
......
......@@ -67,9 +67,7 @@ static_library("phonehub") {
]
}
static_library("test_support") {
testonly = true
static_library("debug") {
sources = [
"fake_do_not_disturb_controller.cc",
"fake_do_not_disturb_controller.h",
......@@ -85,11 +83,25 @@ static_library("test_support") {
"fake_phone_hub_manager.h",
"fake_tether_controller.cc",
"fake_tether_controller.h",
]
public_deps = [ ":phonehub" ]
deps = [ "//base" ]
}
static_library("test_support") {
testonly = true
sources = [
"phone_model_test_util.cc",
"phone_model_test_util.h",
]
public_deps = [ ":phonehub" ]
public_deps = [
":debug",
":phonehub",
]
deps = [ "//base" ]
}
......@@ -110,6 +122,7 @@ source_set("unit_tests") {
]
deps = [
":debug",
":phonehub",
":test_support",
"//base",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment