-
Notifications
You must be signed in to change notification settings - Fork 341
Switch to using Path URL Strategy #3585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e9accca
b8f89a9
8a55831
c83dcd9
43d31ab
31e134c
d96e5b6
a47458b
182a06f
e958e73
0aee389
fcfd4a7
8f71d21
facf6e2
737e87b
ea2b177
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
void usePathUrlStrategy() { | ||
// No-op. URL Strategies are only supported for web. | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'noop.dart' if (dart.library.html) 'web.dart'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import 'package:flutter_web_plugins/flutter_web_plugins.dart'; | ||
|
||
void usePathUrlStrategy() { | ||
setUrlStrategy(PathUrlStrategy()); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2019 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. | ||
|
||
/// Extracts the current DevTools page from the given [url]. | ||
String extractCurrentPageFromUrl(String url) { | ||
// The url can be in one of two forms: | ||
// - /page?uri=xxx | ||
// - /?page=xxx&uri=yyy (original formats IDEs may use) | ||
// Use the path in preference to &page= as it's the one DevTools is updating | ||
final uri = Uri.parse(url); | ||
return uri.path == '/' | ||
? uri.queryParameters['page'] ?? '' | ||
: uri.path.substring(1); | ||
} | ||
|
||
/// Maps DevTools URLs in the original fragment format onto the equivalent URLs | ||
/// in the new URL format. | ||
/// | ||
/// Returns `null` if [url] is not a legacy URL. | ||
String? mapLegacyUrl(String url) { | ||
final uri = Uri.parse(url); | ||
// Old formats include: | ||
// http://localhost:123/#/inspector?uri=ws://... | ||
// http://localhost:123/#/?page=inspector&uri=ws://... | ||
final isRootRequest = uri.path == '/' || uri.path.endsWith('/devtools/'); | ||
if (isRootRequest && uri.fragment.isNotEmpty) { | ||
final basePath = uri.path; | ||
// Convert the URL by removing the fragment separator. | ||
final newUrl = url | ||
// Handle localhost:123/#/inspector?uri=xxx | ||
.replaceFirst('/#/', '/') | ||
// Handle localhost:123/#?page=inspector&uri=xxx | ||
.replaceFirst('/#', ''); | ||
|
||
// Move page names from the querystring into the path. | ||
var newUri = Uri.parse(newUrl); | ||
final page = newUri.queryParameters['page']; | ||
if (newUri.path == basePath && page != null) { | ||
final newParams = {...newUri.queryParameters}..remove('page'); | ||
newUri = newUri.replace( | ||
path: '$basePath$page', | ||
queryParameters: newParams, | ||
); | ||
} | ||
return newUri.toString(); | ||
} | ||
|
||
return null; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2019 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 'package:devtools_app/src/primitives/url_utils.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('url utils', () { | ||
group('extractCurrentPageFromUrl', () { | ||
test('parses the current page from the path', () { | ||
final page = | ||
extractCurrentPageFromUrl('http://localhost:9000/inspector?uri=x'); | ||
expect(page, 'inspector'); | ||
}); | ||
|
||
test('parses the current page from the query string', () { | ||
final page = extractCurrentPageFromUrl( | ||
'http://localhost:9000/?uri=x&page=inspector&theme=dark', | ||
); | ||
expect(page, 'inspector'); | ||
}); | ||
|
||
test( | ||
'parses the current page from the path even if query string is populated', | ||
() { | ||
final page = extractCurrentPageFromUrl( | ||
'http://localhost:9000/memory?uri=x&page=inspector&theme=dark', | ||
); | ||
expect(page, 'memory'); | ||
}); | ||
}); | ||
|
||
group('mapLegacyUrl', () { | ||
for (final prefix in [ | ||
'http://localhost:123', | ||
'http://localhost:123/authToken=/devtools' | ||
]) { | ||
group(' with $prefix prefix', () { | ||
test('does not map new-style URLs', () { | ||
expect(mapLegacyUrl('$prefix'), isNull); | ||
expect(mapLegacyUrl('$prefix/'), isNull); | ||
expect(mapLegacyUrl('$prefix/foo?uri=ws://foo'), isNull); | ||
expect(mapLegacyUrl('$prefix?uri=ws://foo'), isNull); | ||
expect(mapLegacyUrl('$prefix/?uri=ws://foo'), isNull); | ||
expect(mapLegacyUrl('$prefix/?uri=ws://foo#'), isNull); | ||
}); | ||
|
||
test('maps legacy URIs with page names in path', () { | ||
expect( | ||
mapLegacyUrl('$prefix/#/inspector?foo=bar'), | ||
'$prefix/inspector?foo=bar', | ||
); | ||
}); | ||
|
||
test('maps legacy URIs with page names in querystring', () { | ||
expect( | ||
mapLegacyUrl('$prefix/#/?page=inspector&foo=bar'), | ||
'$prefix/inspector?foo=bar', | ||
); | ||
}); | ||
|
||
test('maps legacy URIs with no page names', () { | ||
expect( | ||
mapLegacyUrl('$prefix/#/?foo=bar'), | ||
'$prefix/?foo=bar', | ||
); | ||
}); | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
const dartSdkUrl = | ||
'org-dartlang-sdk:///third_party/dart/sdk/lib/async/zone.dart'; | ||
const flutterUrl = | ||
'file:///path/to/flutter/packages/flutter/lib/src/widgets/binding.dart'; | ||
const flutterUrlFromNonFlutterDir = | ||
'file:///path/to/non-flutter/packages/flutter/lib/src/widgets/binding.dart'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<!-- Note: This tag is replaced when served through DDS! --> | ||
<base href="/"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @elliette wanted to get your input on changes to this file to verify that this shouldn't have any effects on serving DevTools in g3 or with DDR / the Dart DevTools extension. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks safe to me! None of the serving logic should care about the base URL. |
||
|
||
<title></title> | ||
<link href="favicon.png" rel="icon" sizes="64x64"> | ||
|
@@ -41,18 +43,6 @@ | |
if (!supportsES6Classes()) { | ||
window.location.href = '/unsupported-browser.html'; | ||
} | ||
|
||
// Handle URLs that pass all variables directly on a querystring without | ||
// the fragment (for ex. VS Code while it has some encoding bugs preventing | ||
// building the correct URLs using fragments | ||
// https://github.com/microsoft/vscode/issues/85930). | ||
if (window.location.search && window.location.search.length > 1) { | ||
// Ensure each component is encoded, because if the URI contains / slashes | ||
// Flutter will split on them and try to push multiple routes. | ||
const params = new URLSearchParams(unescape(window.location.search)); | ||
params.forEach(function(v, k) { params.set(k, encodeURIComponent(v)) }); | ||
window.location.replace(window.location.origin + '/#/?' + params.toString()); | ||
} | ||
</script> | ||
</head> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will need to be applied to the google3 main file. I'll take an action item to do this when this change is rolled into g3.