Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
32440ce1
Unverified
Commit
32440ce1
authored
Apr 05, 2021
by
Jenn Magder
Committed by
GitHub
Apr 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate tools chrome to null safety (#79801)
parent
e6fbdb63
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
31 deletions
+37
-31
chrome.dart
packages/flutter_tools/lib/src/web/chrome.dart
+37
-31
No files found.
packages/flutter_tools/lib/src/web/chrome.dart
View file @
32440ce1
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'dart:async'
;
import
'package:meta/meta.dart'
;
...
...
@@ -56,7 +54,7 @@ typedef BrowserFinder = String Function(Platform, FileSystem);
/// Does not verify whether the executable exists.
String
findChromeExecutable
(
Platform
platform
,
FileSystem
fileSystem
)
{
if
(
platform
.
environment
.
containsKey
(
kChromeEnvironment
))
{
return
platform
.
environment
[
kChromeEnvironment
];
return
platform
.
environment
[
kChromeEnvironment
]
!
;
}
if
(
platform
.
isLinux
)
{
return
kLinuxExecutable
;
...
...
@@ -67,9 +65,12 @@ String findChromeExecutable(Platform platform, FileSystem fileSystem) {
if
(
platform
.
isWindows
)
{
/// The possible locations where the chrome executable can be located on windows.
final
List
<
String
>
kWindowsPrefixes
=
<
String
>[
platform
.
environment
[
'LOCALAPPDATA'
],
platform
.
environment
[
'PROGRAMFILES'
],
platform
.
environment
[
'PROGRAMFILES(X86)'
],
if
(
platform
.
environment
.
containsKey
(
'LOCALAPPDATA'
))
platform
.
environment
[
'LOCALAPPDATA'
]!,
if
(
platform
.
environment
.
containsKey
(
'PROGRAMFILES'
))
platform
.
environment
[
'PROGRAMFILES'
]!,
if
(
platform
.
environment
.
containsKey
(
'PROGRAMFILES(X86)'
))
platform
.
environment
[
'PROGRAMFILES(X86)'
]!,
];
final
String
windowsPrefix
=
kWindowsPrefixes
.
firstWhere
((
String
prefix
)
{
if
(
prefix
==
null
)
{
...
...
@@ -88,14 +89,17 @@ String findChromeExecutable(Platform platform, FileSystem fileSystem) {
/// Does not verify whether the executable exists.
String
findEdgeExecutable
(
Platform
platform
,
FileSystem
fileSystem
)
{
if
(
platform
.
environment
.
containsKey
(
kEdgeEnvironment
))
{
return
platform
.
environment
[
kEdgeEnvironment
];
return
platform
.
environment
[
kEdgeEnvironment
]
!
;
}
if
(
platform
.
isWindows
)
{
/// The possible locations where the Edge executable can be located on windows.
final
List
<
String
>
kWindowsPrefixes
=
<
String
>[
platform
.
environment
[
'LOCALAPPDATA'
],
platform
.
environment
[
'PROGRAMFILES'
],
platform
.
environment
[
'PROGRAMFILES(X86)'
],
if
(
platform
.
environment
.
containsKey
(
'LOCALAPPDATA'
))
platform
.
environment
[
'LOCALAPPDATA'
]!,
if
(
platform
.
environment
.
containsKey
(
'PROGRAMFILES'
))
platform
.
environment
[
'PROGRAMFILES'
]!,
if
(
platform
.
environment
.
containsKey
(
'PROGRAMFILES(X86)'
))
platform
.
environment
[
'PROGRAMFILES(X86)'
]!,
];
final
String
windowsPrefix
=
kWindowsPrefixes
.
firstWhere
((
String
prefix
)
{
if
(
prefix
==
null
)
{
...
...
@@ -113,12 +117,12 @@ String findEdgeExecutable(Platform platform, FileSystem fileSystem) {
/// A launcher for Chromium browsers with devtools configured.
class
ChromiumLauncher
{
ChromiumLauncher
({
@
required
FileSystem
fileSystem
,
@
required
Platform
platform
,
@
required
ProcessManager
processManager
,
@
required
OperatingSystemUtils
operatingSystemUtils
,
@
required
BrowserFinder
browserFinder
,
@
required
Logger
logger
,
required
FileSystem
fileSystem
,
required
Platform
platform
,
required
ProcessManager
processManager
,
required
OperatingSystemUtils
operatingSystemUtils
,
required
BrowserFinder
browserFinder
,
required
Logger
logger
,
})
:
_fileSystem
=
fileSystem
,
_platform
=
platform
,
_processManager
=
processManager
,
...
...
@@ -162,9 +166,9 @@ class ChromiumLauncher {
/// [skipCheck] does not attempt to make a devtools connection before returning.
Future
<
Chromium
>
launch
(
String
url
,
{
bool
headless
=
false
,
int
debugPort
,
int
?
debugPort
,
bool
skipCheck
=
false
,
Directory
cacheDir
,
Directory
?
cacheDir
,
})
async
{
if
(
currentCompleter
.
isCompleted
)
{
throwToolExit
(
'Only one instance of chrome can be started.'
);
...
...
@@ -214,10 +218,10 @@ class ChromiumLauncher {
url
,
];
final
Process
process
=
await
_spawnChromiumProcess
(
args
);
final
Process
?
process
=
await
_spawnChromiumProcess
(
args
);
// When the process exits, copy the user settings back to the provided data-dir.
if
(
cacheDir
!=
null
)
{
if
(
process
!=
null
&&
cacheDir
!=
null
)
{
unawaited
(
process
.
exitCode
.
whenComplete
(()
{
_cacheUserSessionInformation
(
userDataDir
,
cacheDir
);
}));
...
...
@@ -231,7 +235,7 @@ class ChromiumLauncher {
),
skipCheck
);
}
Future
<
Process
>
_spawnChromiumProcess
(
List
<
String
>
args
)
async
{
Future
<
Process
?
>
_spawnChromiumProcess
(
List
<
String
>
args
)
async
{
// Keep attempting to launch the browser until one of:
// - Chrome launched successfully, in which case we just return from the loop.
// - The tool detected an unretriable Chrome error, in which case we throw ToolExit.
...
...
@@ -264,7 +268,8 @@ class ChromiumLauncher {
'Encountered glibc bug https://sourceware.org/bugzilla/show_bug.cgi?id=19329. '
'Will try launching browser again.'
,
);
return
null
;
// Return value unused.
return
''
;
}
_logger
.
printTrace
(
'Failed to launch browser. Command used to launch it:
${args.join(' ')}
'
);
throw
ToolExit
(
...
...
@@ -283,7 +288,8 @@ class ChromiumLauncher {
// launching more processes.
unawaited
(
process
.
exitCode
.
timeout
(
const
Duration
(
seconds:
1
),
onTimeout:
()
{
process
.
kill
();
return
null
;
// sigterm
return
15
;
}));
}
}
...
...
@@ -302,7 +308,7 @@ class ChromiumLauncher {
/// Note: more detailed docs of the Chrome user preferences store exists here:
/// https://www.chromium.org/developers/design-documents/preferences.
void
_cacheUserSessionInformation
(
Directory
userDataDir
,
Directory
cacheDir
)
{
final
Directory
targetChromeDefault
=
_fileSystem
.
directory
(
_fileSystem
.
path
.
join
(
cacheDir
?.
path
??
''
,
_chromeDefaultPath
));
final
Directory
targetChromeDefault
=
_fileSystem
.
directory
(
_fileSystem
.
path
.
join
(
cacheDir
.
path
,
_chromeDefaultPath
));
final
Directory
sourceChromeDefault
=
_fileSystem
.
directory
(
_fileSystem
.
path
.
join
(
userDataDir
.
path
,
_chromeDefaultPath
));
if
(
sourceChromeDefault
.
existsSync
())
{
targetChromeDefault
.
createSync
(
recursive:
true
);
...
...
@@ -315,7 +321,7 @@ class ChromiumLauncher {
}
}
final
File
targetPreferencesFile
=
_fileSystem
.
file
(
_fileSystem
.
path
.
join
(
cacheDir
?.
path
??
''
,
_preferencesPath
));
final
File
targetPreferencesFile
=
_fileSystem
.
file
(
_fileSystem
.
path
.
join
(
cacheDir
.
path
,
_preferencesPath
));
final
File
sourcePreferencesFile
=
_fileSystem
.
file
(
_fileSystem
.
path
.
join
(
userDataDir
.
path
,
_preferencesPath
));
if
(
sourcePreferencesFile
.
existsSync
())
{
...
...
@@ -330,7 +336,7 @@ class ChromiumLauncher {
/// Restore Chrome user information from a per-project cache into Chrome's
/// user data directory.
void
_restoreUserSessionInformation
(
Directory
cacheDir
,
Directory
userDataDir
)
{
final
Directory
sourceChromeDefault
=
_fileSystem
.
directory
(
_fileSystem
.
path
.
join
(
cacheDir
.
path
??
''
,
_chromeDefaultPath
));
final
Directory
sourceChromeDefault
=
_fileSystem
.
directory
(
_fileSystem
.
path
.
join
(
cacheDir
.
path
,
_chromeDefaultPath
));
final
Directory
targetChromeDefault
=
_fileSystem
.
directory
(
_fileSystem
.
path
.
join
(
userDataDir
.
path
,
_chromeDefaultPath
));
try
{
if
(
sourceChromeDefault
.
existsSync
())
{
...
...
@@ -367,18 +373,18 @@ class Chromium {
this
.
debugPort
,
this
.
chromeConnection
,
{
this
.
url
,
Process
process
,
@
required
ChromiumLauncher
chromiumLauncher
,
Process
?
process
,
required
ChromiumLauncher
chromiumLauncher
,
})
:
_process
=
process
,
_chromiumLauncher
=
chromiumLauncher
;
final
String
url
;
final
String
?
url
;
final
int
debugPort
;
final
Process
_process
;
final
Process
?
_process
;
final
ChromeConnection
chromeConnection
;
final
ChromiumLauncher
_chromiumLauncher
;
Future
<
int
>
get
onExit
=>
_process
.
exitCode
;
Future
<
int
?>
get
onExit
async
=>
_process
?
.
exitCode
;
Future
<
void
>
close
()
async
{
if
(
_chromiumLauncher
.
hasChromeInstance
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment