This CL:
a. Move DeviceConnectionType into WebContents and rename it to CapabilityType
b. Merge all IsConnectedToXXX() functions into a single IsCapabilityActive() function
c. Rename OnDeviceConnectionTypesChanged() method to OnCapabilityTypesChanged().
Bug: 372836924
Change-Id: Ib8be8821dff459c3788aeeb0fc4921f3996ec069
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5938280
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Commit-Queue: Yifan Luo <lyf@chromium.org>
Reviewed-by: Matt Reynolds <mattreynolds@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1372240}
This is needed to implement a freezing opt-out as described at
go/tab-freezing-on-energy-saver-prd.
Implementation details:
- WebContentsObserver::OnIsConnectedToUsbDeviceChanged() and
WebContentsObserver::OnIsConnectedToBluetoothDeviceChanged() are
replaced with
WebContentsObserver::OnDeviceConnectionTypesChanged(), which is
invoked when the connection types used by a WebContents change
(USB, Bluetooth, HID and serial). This avoids an explosion of the
number of observer methods as more device connection types need
to be tracked by performance policies.
- Hid Device and Serial Port usage are tracked in
PageLiveStateDecorator, alongside USB Device and Bluetooth device
usage.
- In a separate CL, we'll use the new properties as Page Freezing
opt-outs.
Bug: 325954772
Change-Id: I5d9df041f7cb45309f3eb69cb9b6ad59f35d64b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5847688
Reviewed-by: Matt Reynolds <mattreynolds@chromium.org>
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Commit-Queue: Francois Pierre Doray <fdoray@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1356468}
This change ensures that protected USB interfaces are inaccessible in
isolated contexts unless the 'kUnrestrictedUsb' feature is enabled and
appropriate permissions are granted.
Bug: 40783010
Change-Id: I2656817535952a0426ee1a8ee6dc701343b00203
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5808013
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Alvin Ji <alvinji@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1347545}
NOTREACHED() has turned [[noreturn]] so the former macro isn't needed
anymore.
This does not attempt to do a rewrite of any surrounding code, like:
if (!foo) {
NOTREACHED();
}
to CHECK(foo);
Those transforms take a non-trivial amount of time (and there are
thousands of instances). Cleanup can be left as an exercise for the
reader.
NO_IFTTT=No-op-rename migration.
Bug: 40580068
Change-Id: I068c5fdce9dc4c352d8bdd62bb3cd2c0a2d59659
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5782602
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Peter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1342096}
Destroying a UsbDeviceClient decrements `connection_count_`, so
`connection_count_` must outlive any `UsbDeviceClient`s owned by the
`WebUsbServiceImpl`. This previously went undetected, even though it is
considered UB; MSan's use-after-dtor diagnostic catches this type of
error.
Bug: 40222690
Change-Id: Ifed80c34347fd1245dbc4113f5264cc1c5d2953f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5577050
Reviewed-by: Ken Rockot <rockot@google.com>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1307780}
The changes of this CL are made using the following script.
```
target_directory="content/browser"
replace_string_in_files() {
old_string="$1"
new_string="$2"
find "$target_directory" -type f \( -name "*.cc" -o -name "*.h" \) \
-exec sed -i '' "s/$old_string/$new_string/g" {} +
}
delete_include() {
find "$target_directory" \( -name "*.h" -o -name "*.cc" \) -print0 | while IFS= read -r -d '' file; do
grep -v '#include "base/strings/string_piece.h"' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
done
}
add_include() {
find "$target_directory" \( -name "*.h" -o -name "*.cc" \) -print0 | while IFS= read -r -d '' file; do
local include_added=false
local tempfile=$(mktemp)
if grep -qE 'std::(string|u16string)_view' "$file"; then
while IFS= read -r line; do
echo "$line" >> "$tempfile"
if [[ $line =~ ^\s*#include ]]; then
if ! $include_added; then
echo "#include <string_view>" >> "$tempfile"
include_added=true
fi
fi
done < "$file"
mv "$tempfile" "$file"
if $include_added; then
echo "Added #include <string_view> after the first include line in $file"
else
echo "No include line found in $file"
fi
else
echo "std::string_view not found in $file"
fi
done
}
replace_string_in_files "base::StringPiece16" "std::u16string_view"
replace_string_in_files "base::StringPiece" "std::string_view"
delete_include
add_include
```
Replaced base::StringPiece16 with std::u16string_view
Replaced base::StringPiece with std::string_view
Removed header "base/strings/string_piece.h"
Added header "<string_view>" where applicable
Bug: 40506050
Change-Id: I2bc22c79dd9a0c839745afe065123f7a53c4a5ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5401117
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: Mike West <mkwst@chromium.org>
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Reviewed-by: Will Harris <wfh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1281746}
The WebExposedIsolationLevel is set in SiteInfo with potential values
KNonIsolated, kMaybeIsolated and kMaybeIsolatedApplication. The
latter two are always converted to kIsolated and kIsolatedApplication when
passed to the content/ embedder. It does not make sense to keep the
kMaybe* values as there is no place in the code that differentiates
between kMaybeIsolated and kIsolated or kMaybeIsolatedApplication and
kIsolatedApplication.
Change-Id: I71760683c6b2bb87356a836b630b8c3f008752ef
Bug: 325990061
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5301350
Auto-Submit: Camille Lamy <clamy@chromium.org>
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Robbie McElrath <rmcelrath@chromium.org>
Reviewed-by: Alex Moshchuk <alexmos@chromium.org>
Commit-Queue: Camille Lamy <clamy@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1270096}
This change list completes ServiceWorkerUsbDelegateObserver and makes it
responsible to keep track what ServiceWorkerRegistration should respond
to USB events and wake up the service worker if it is not in running
state.
Bug: 1446487
Change-Id: Ibadd754f302d6ab5eb42f7df0ecb46ba46226a7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4804134
Auto-Submit: Juan Garza Sanchez <juangarza@chromium.org>
Commit-Queue: Juan Garza Sanchez <juangarza@chromium.org>
Reviewed-by: Jack Hsieh <chengweih@chromium.org>
Commit-Queue: Jack Hsieh <chengweih@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1188062}
This change introduces ServiceWorkerUsbDelegateObserver as a broker
between UsbDelegate and WebUsbService. It is not covered in this CL yet,
but this class is set to be responsible to keep track what
ServiceWorkerRegistration should respond to USB events and wake up the
service worker if it is not in running state. The full functionality
will be completed by the following CL.
Bug: 1446487
Change-Id: I1ab8809ec816ed3ad5c4cf55d0bd3521452a41c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4763985
Reviewed-by: Yoshisato Yanagisawa <yyanagisawa@chromium.org>
Reviewed-by: Jack Hsieh <chengweih@chromium.org>
Commit-Queue: Juan Garza Sanchez <juangarza@chromium.org>
Auto-Submit: Juan Garza Sanchez <juangarza@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1187996}
WebUSB grants per-origin device access which is scoped to a
profile. These permissions should be scoped to a
StoragePartition, as this currently allows access granted in a regular
tab to be inappropriately shared with a webview which navigates to
content from the same origin.
Since webviews don't have a means of requesting USB access anyway, we
now just explicitly deny permissions for them. We also guard against
scenarios involving accidental permission sharing to a non-default
StoragePartition. Isolated Web Apps, due to their unique origin, do not
present an issue with this cross-StoragePartition sharing and are
excluded.
Bug: 1462709
Change-Id: Icfe56d36c2f120c95f8a8cbf4aa22a3cd597fc27
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4735893
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Auto-Submit: Kevin McNee <mcnee@chromium.org>
Reviewed-by: Alex Moshchuk <alexmos@chromium.org>
Commit-Queue: Alex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1178753}
The change is part of the change list chain for
go/usb-hid-extension-permission-ux that we need to show an icon to have
users aware Chrome is accessing USB device(s) and create a notification
to notify users that an extension just opens a connection to a USB
device.
This changelist adds IncrementConnectionCount and
DecrementConnectionCount methods for UsbDelegate so that
content::WebUsbServiceImpl can use these methods to notify the delegate
active connections created/removed by the WebUsbServiceImpl.
Bug: 1303193
Change-Id: I9296f125805062e1b0a045cf04913a58e59984b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4663771
Commit-Queue: Jack Hsieh <chengweih@chromium.org>
Reviewed-by: Jack Hsieh <chengweih@chromium.org>
Auto-Submit: Juan Garza Sanchez <juangarza@chromium.org>
Reviewed-by: Alexander Timin <altimin@chromium.org>
Reviewed-by: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1169921}
The tests in //content/browser/usb/usb_browsertest.cc were flaky because
they expected HasDevicePermission() to be called exactly once when
calling getDevices(). The problem is that the creation of a USBDevice
object in Blink calls WebUsbService::GetDevice() to open a Mojo
connection to that device which will perform another permission check.
The fix is to not expect a particular number of calls but instead track
calls to requestDevice() and forget() in the tests so that the actual
expected permission state is known.
Change-Id: I271deff462d4a5c6d18d9a2a23f0f24c0117dcc0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4437793
Commit-Queue: Sina Firoozabadi <sinafirooz@chromium.org>
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Sina Firoozabadi <sinafirooz@chromium.org>
Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1132092}
In order to migrate to using the underlying CSP wildcard matching logic
(even if we don't expand the wildcard options available) we need to
prevent opaque origins from ending up in the allowlist as CSP matching
does not support them. This isn't a big issue as the only origin that
can be opaque is `self`, so we can just split that out in the policy
itself as an optional datatype.
This touches a lot of code, but is heavily tested and the new DCHECKS in
OriginWithPossibleWildcards should ensure self was properly moved.
This CL is part of a series:
(1) Ban opaque origins from OriginWithPossibleWildcard
(2) Switch to using underlying CSP data type
(3) Use CSP parsing and comparison paths
Bug: 1418009
Change-Id: Ib35511b741f3168d9f28618fcb3eb8b8f3eb8f2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4317285
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Auto-Submit: Ari Chivukula <arichiv@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Ian Clelland <iclelland@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1120662}
Mojo doesn't support a void type (issue 1220106) but we can emulate one
with an enum that has only one defined value. This change adds a new
UsbOpenDeviceResult union which is either a UsbOpenDeviceSuccess or a
UsbOpenDeviceError.
Change-Id: If158c1dd52315fd1bf51062a4b8e64a3ed967a84
Bug: None
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4234077
Reviewed-by: Ken Rockot <rockot@google.com>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1105463}
Some times tests need to replace the ContentBrowserClient. This
is often done by subclassing ContentBrowserClient and replacing
ContentBrowserClient during test execution. This is problematic
as certain things (such as RegisterBrowserInterfaceBindersForFrame)
are provided by ShellContentBrowserClient, and if not present
result in bad behavior (killing the renderer), which leads to flake.
To fix this problem this patch does the following:
. Moves ContentBrowserTestShellContentBrowserClient to its own
header and renames it to
ContentBrowserTestContentBrowserClient.
. makes SetBrowserClientForTesting() CHECK in content_browsertests.
. changes all browsertests to use
ContentBrowserTestContentBrowserClient.
. Changes ShellContentBrowserClient so that it sets the browser
client when called the second time (effectively what
SetBrowserClientForTesting() does).
Bug: 1406282
Change-Id: Ieaa7cfa09a53e9618b963d6cc4b931226d2c799e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4222392
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1102490}
This CL moves the implementation of the blink::mojom::WebUsbService
mojo interface from the embedder layer to the content layer.
Ownership of the UsbDelegate is moved from WebUsbServiceImpl to
the ContentBrowserClient which now has a GetUsbDelegate method.
Previously, the lifetime of WebUsbServiceImpl was managed by
FrameUsbServices. Now it is a self-owned DocumentUserData with
the same lifetime.
Previously, UsbTabHelper managed the connected USB device state.
Now WebContentsImpl manages this state and clients observe
WebContents directly.
Browser tests (//chrome/browser/usb/usb_browsertest.cc) and unit
tests (//chrome/browser/usb/web_usb_service_impl_unittest.cc) are
moved to //content but the embedder-specific versions of the tests
are retained as chrome_usb_browsertest.cc and
chrome_usb_delegate_unittest.cc.
Bug: 991759, 1220314
Change-Id: I2ed528acc6dbc5667ae22b9219a1320226792a40
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3671829
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Dana Fried <dfried@chromium.org>
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Reviewed-by: Brandon Jones <bajones@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1036771}