Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce chrome://location-internals UI
This page is added to help troubleshoot geolocation issues. It will include 1. A button to start / stop navigator.geolocation.watchPosition 2. log WifiData, PositionCache and other useful information from GeolocationProviderImpl. This will lead to faster resolution of issues and a better user experience. Bug: 1110995 Change-Id: I2ea7d3ae9988869a952a03f877b78177e98a43be Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4468750 Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org> Commit-Queue: Alvin Ji <alvinji@chromium.org> Cr-Commit-Position: refs/heads/main@{#1149979}
- Loading branch information
Alvin Ji
authored and
Chromium LUCI CQ
committed
May 26, 2023
1 parent
86f8ba8
commit a527278
Showing
22 changed files
with
371 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2023 The Chromium Authors | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
import("//ui/webui/resources/tools/build_webui.gni") | ||
|
||
build_webui("build") { | ||
grd_prefix = "location_internals" | ||
static_files = [ | ||
"location_internals.css", | ||
"location_internals.html", | ||
] | ||
|
||
non_web_component_files = [ "location_internals.ts" ] | ||
|
||
ts_deps = [ "//ui/webui/resources/js:build_ts" ] | ||
|
||
ts_composite = true | ||
} |
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,4 @@ | ||
monorail: { | ||
component: "Blink>Geolocation" | ||
} | ||
team_email: "device-dev@chromium.org" |
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 @@ | ||
file://content/browser/geolocation/OWNERS |
29 changes: 29 additions & 0 deletions
29
chrome/browser/resources/location_internals/location_internals.css
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,29 @@ | ||
/* Copyright 2023 The Chromium Authors | ||
* Use of this source code is governed by a BSD-style license that can be | ||
* found in the LICENSE file. */ | ||
|
||
#container { | ||
display: flex; | ||
justify-content: space-around; | ||
padding-inline-end: 20px; | ||
padding-inline-start: 20px; | ||
} | ||
|
||
table { | ||
border-collapse: collapse; | ||
font-family: arial, sans-serif; | ||
margin-top: 20px; | ||
} | ||
|
||
table caption { | ||
font-size: 18px; | ||
font-weight: bold; | ||
text-align: start; | ||
} | ||
|
||
td, | ||
th { | ||
border: 1px solid #ddd; | ||
padding: 8px; | ||
text-align: start; | ||
} |
48 changes: 48 additions & 0 deletions
48
chrome/browser/resources/location_internals/location_internals.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,48 @@ | ||
<!doctype html> | ||
<html dir="$i18n{textdirection}" lang="$i18n{language}"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>Location Internals</title> | ||
<link rel="stylesheet" href="chrome://resources/css/text_defaults.css"> | ||
<link rel="stylesheet" href="location_internals.css"> | ||
</head> | ||
|
||
<body> | ||
<h2 class="header">Location Internals</h2> | ||
<header class="page-header"> | ||
<button id="watch-btn">Start Watching Position</button> | ||
</header> | ||
<div id="container"> | ||
|
||
<table id="watch-position"> | ||
<caption>WatchPosition</caption> | ||
<thead> | ||
<tr> | ||
<th>Timestamp</th> | ||
<th>Position</th> | ||
<th>Accuracy</th> | ||
<th>Altitude</th> | ||
<th>AltitudeAccuracy</th> | ||
<th>Heading</th> | ||
<th>Speed</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td id="watch-position-timestamp"></td> | ||
<td id="watch-position-position"></td> | ||
<td id="watch-position-accuracy"></td> | ||
<td id="watch-position-altitude"></td> | ||
<td id="watch-position-altitude-accuracy"></td> | ||
<td id="watch-position-heading"></td> | ||
<td id="watch-position-speed"></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
</div> | ||
<script type="module" src="location_internals.js"></script> | ||
</body> | ||
|
||
</html> |
79 changes: 79 additions & 0 deletions
79
chrome/browser/resources/location_internals/location_internals.ts
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,79 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import {assert} from 'chrome://resources/js/assert_ts.js'; | ||
import {getRequiredElement} from 'chrome://resources/js/util_ts.js'; | ||
|
||
let watchButton: HTMLElement; | ||
let watchTable: HTMLElement; | ||
let watchId: number = -1; | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
watchButton = getRequiredElement<HTMLElement>('watch-btn'); | ||
watchTable = getRequiredElement<HTMLElement>('watch-position'); | ||
watchButton.addEventListener('click', () => { | ||
if (watchId === -1) { | ||
watchId = navigator.geolocation.watchPosition(logSuccess, logError, { | ||
enableHighAccuracy: true, | ||
timeout: 5000, | ||
maximumAge: 0, | ||
}); | ||
watchButton.textContent = 'Stop Watching Position'; | ||
} else { | ||
navigator.geolocation.clearWatch(watchId); | ||
watchId = -1; | ||
watchButton.textContent = 'Start Watching Position'; | ||
} | ||
}); | ||
}); | ||
|
||
function logSuccess(position: GeolocationPosition) { | ||
assert(watchTable); | ||
const timeCell = getRequiredElement<HTMLElement>('watch-position-timestamp'); | ||
const positionCell = | ||
getRequiredElement<HTMLElement>('watch-position-position'); | ||
|
||
timeCell.textContent = new Date(position.timestamp).toLocaleString(); | ||
positionCell.textContent = | ||
`${position.coords.latitude} ° , ${position.coords.longitude} ° `; | ||
|
||
if (position.coords.accuracy) { | ||
const accuracyCell = | ||
getRequiredElement<HTMLElement>('watch-position-accuracy'); | ||
accuracyCell.textContent = position.coords.accuracy.toString(); | ||
} | ||
|
||
if (position.coords.altitude) { | ||
const altitudeCell = | ||
getRequiredElement<HTMLElement>('watch-position-altitude'); | ||
altitudeCell.textContent = position.coords.altitude.toString(); | ||
} | ||
|
||
if (position.coords.altitudeAccuracy) { | ||
const altitudeAccuracyCell = | ||
getRequiredElement<HTMLElement>('watch-position-altitude-accuracy'); | ||
altitudeAccuracyCell.textContent = | ||
position.coords.altitudeAccuracy.toString(); | ||
} | ||
|
||
if (position.coords.heading) { | ||
const headingCell = | ||
getRequiredElement<HTMLElement>('watch-position-heading'); | ||
headingCell.textContent = position.coords.heading.toString(); | ||
} | ||
|
||
if (position.coords.speed) { | ||
const speedCell = getRequiredElement<HTMLElement>('watch-position-speed'); | ||
speedCell.textContent = position.coords.speed.toString(); | ||
} | ||
} | ||
|
||
function logError(error: GeolocationPositionError) { | ||
assert(watchTable); | ||
const timeCell = getRequiredElement<HTMLElement>('watch-position-timestamp'); | ||
const positionCell = | ||
getRequiredElement<HTMLElement>('watch-position-position'); | ||
timeCell.textContent = new Date().toLocaleString(); | ||
positionCell.textContent = `${error.message}, code: ${error.code}`; | ||
} |
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
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,4 @@ | ||
monorail: { | ||
component: "Blink>Geolocation" | ||
} | ||
team_email: "device-dev@chromium.org" |
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,4 @@ | ||
file://content/browser/geolocation/OWNERS | ||
|
||
per-file *.mojom=set noparent | ||
per-file *.mojom=file://ipc/SECURITY_OWNERS |
30 changes: 30 additions & 0 deletions
30
chrome/browser/ui/webui/location_internals/location_internals_ui.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,30 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// 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/location_internals/location_internals_ui.h" | ||
|
||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/ui/webui/webui_util.h" | ||
#include "chrome/common/url_constants.h" | ||
#include "chrome/grit/location_internals_resources.h" | ||
#include "chrome/grit/location_internals_resources_map.h" | ||
#include "content/public/browser/web_ui_data_source.h" | ||
#include "services/network/public/mojom/content_security_policy.mojom.h" | ||
#include "ui/resources/grit/webui_resources.h" | ||
|
||
LocationInternalsUI::LocationInternalsUI(content::WebUI* web_ui) | ||
: ui::MojoWebUIController(web_ui) { | ||
// Set up the chrome://location-internals source. | ||
content::WebUIDataSource* source = content::WebUIDataSource::CreateAndAdd( | ||
Profile::FromWebUI(web_ui), chrome::kChromeUILocationInternalsHost); | ||
|
||
webui::SetupWebUIDataSource(source, | ||
base::make_span(kLocationInternalsResources, | ||
kLocationInternalsResourcesSize), | ||
IDR_LOCATION_INTERNALS_LOCATION_INTERNALS_HTML); | ||
} | ||
|
||
LocationInternalsUI::~LocationInternalsUI() = default; | ||
|
||
WEB_UI_CONTROLLER_TYPE_IMPL(LocationInternalsUI) |
25 changes: 25 additions & 0 deletions
25
chrome/browser/ui/webui/location_internals/location_internals_ui.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,25 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// 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_LOCATION_INTERNALS_LOCATION_INTERNALS_UI_H_ | ||
#define CHROME_BROWSER_UI_WEBUI_LOCATION_INTERNALS_LOCATION_INTERNALS_UI_H_ | ||
|
||
#include "mojo/public/cpp/bindings/pending_receiver.h" | ||
#include "ui/webui/mojo_web_ui_controller.h" | ||
|
||
// The WebUI for chrome://location-internals | ||
class LocationInternalsUI : public ui::MojoWebUIController { | ||
public: | ||
explicit LocationInternalsUI(content::WebUI* web_ui); | ||
|
||
LocationInternalsUI(const LocationInternalsUI&) = delete; | ||
LocationInternalsUI& operator=(const LocationInternalsUI&) = delete; | ||
|
||
~LocationInternalsUI() override; | ||
|
||
private: | ||
WEB_UI_CONTROLLER_TYPE_DECL(); | ||
}; | ||
|
||
#endif // CHROME_BROWSER_UI_WEBUI_LOCATION_INTERNALS_LOCATION_INTERNALS_UI_H_ |
19 changes: 19 additions & 0 deletions
19
chrome/browser/ui/webui/location_internals/location_internals_ui_browsertest.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,19 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/common/webui_url_constants.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "chrome/test/base/ui_test_utils.h" | ||
#include "content/public/test/browser_test.h" | ||
#include "content/public/test/browser_test_utils.h" | ||
#include "url/gurl.h" | ||
|
||
using LocationInternalsUIBrowserTest = InProcessBrowserTest; | ||
|
||
IN_PROC_BROWSER_TEST_F(LocationInternalsUIBrowserTest, | ||
OpenLocationInternalsWebUI) { | ||
ASSERT_TRUE(ui_test_utils::NavigateToURL( | ||
browser(), | ||
GURL(content::GetWebUIURL(chrome::kChromeUILocationInternalsHost)))); | ||
} |
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
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.