0
Commit Graph

36 Commits

Author SHA1 Message Date
Sandor «Alex» Major
e9545a72e6 Reland "Move PermissionsPolicyFeature from Blink to the Network service"
This is a reland of commit 1b851527a0

A new usage of `PermissionsPolicyFeature` appeared in the meantime.
Fixed in this CL.

Original change's description:
> Move `PermissionsPolicyFeature` from Blink to the Network service
>
> The network service is going to need access to the "storage-access"
> Permissions Policy. This is the first step of moving some of the
> Permissions Policy logic out of Blink to maintain a single
> implementation of https://w3c.github.io/webappsec-permissions-policy
> across Chromium.
>
> Tha main change here is moving the `PermissionsPolicyFeature` type from
> `blink.mojom` to `network.mojom`:
> https://crrev.com/c/6180431/7/services/network/public/mojom/permissions_policy/permissions_policy_feature.mojom
>
> Bug: 382291442
> Change-Id: Ib99fbd285031936dbf40d5f210816cc775c51dfa
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6180431
> Auto-Submit: Sandor «Alex» Major <sandormajor@chromium.org>
> Reviewed-by: Ari Chivukula <arichiv@chromium.org>
> Reviewed-by: Maks Orlovich <morlovich@chromium.org>
> Owners-Override: Rick Byers <rbyers@chromium.org>
> Reviewed-by: Rick Byers <rbyers@chromium.org>
> Commit-Queue: Sandor «Alex» Major <sandormajor@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1414133}

Bug: 382291442
Change-Id: I853b73f61ab7ecd807fc3d16cd2895c353ebd126
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6219635
Auto-Submit: Sandor «Alex» Major <sandormajor@chromium.org>
Owners-Override: Rick Byers <rbyers@chromium.org>
Reviewed-by: Ari Chivukula <arichiv@chromium.org>
Reviewed-by: Maks Orlovich <morlovich@chromium.org>
Reviewed-by: Rick Byers <rbyers@chromium.org>
Commit-Queue: Sandor «Alex» Major <sandormajor@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1414345}
2025-01-31 12:40:46 -08:00
Kevin McNee
4a02d170a9 Revert "Move PermissionsPolicyFeature from Blink to the Network service"
This reverts commit 1b851527a0.

Reason for revert: Broke the build https://ci.chromium.org/ui/p/chromium/builders/ci/Linux%20MSan%20Builder/86647/overview

Original change's description:
> Move `PermissionsPolicyFeature` from Blink to the Network service
>
> The network service is going to need access to the "storage-access"
> Permissions Policy. This is the first step of moving some of the
> Permissions Policy logic out of Blink to maintain a single
> implementation of https://w3c.github.io/webappsec-permissions-policy
> across Chromium.
>
> Tha main change here is moving the `PermissionsPolicyFeature` type from
> `blink.mojom` to `network.mojom`:
> https://crrev.com/c/6180431/7/services/network/public/mojom/permissions_policy/permissions_policy_feature.mojom
>
> Bug: 382291442
> Change-Id: Ib99fbd285031936dbf40d5f210816cc775c51dfa
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6180431
> Auto-Submit: Sandor «Alex» Major <sandormajor@chromium.org>
> Reviewed-by: Ari Chivukula <arichiv@chromium.org>
> Reviewed-by: Maks Orlovich <morlovich@chromium.org>
> Owners-Override: Rick Byers <rbyers@chromium.org>
> Reviewed-by: Rick Byers <rbyers@chromium.org>
> Commit-Queue: Sandor «Alex» Major <sandormajor@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1414133}

Bug: 382291442
Change-Id: I068a9cbfb77057ded4295dc214aee51bee8a503c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6219376
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Kevin McNee <mcnee@chromium.org>
Owners-Override: Kevin McNee <mcnee@google.com>
Cr-Commit-Position: refs/heads/main@{#1414150}
2025-01-31 08:22:14 -08:00
Sandor Major
1b851527a0 Move PermissionsPolicyFeature from Blink to the Network service
The network service is going to need access to the "storage-access"
Permissions Policy. This is the first step of moving some of the
Permissions Policy logic out of Blink to maintain a single
implementation of https://w3c.github.io/webappsec-permissions-policy
across Chromium.

Tha main change here is moving the `PermissionsPolicyFeature` type from
`blink.mojom` to `network.mojom`:
https://crrev.com/c/6180431/7/services/network/public/mojom/permissions_policy/permissions_policy_feature.mojom

Bug: 382291442
Change-Id: Ib99fbd285031936dbf40d5f210816cc775c51dfa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6180431
Auto-Submit: Sandor «Alex» Major <sandormajor@chromium.org>
Reviewed-by: Ari Chivukula <arichiv@chromium.org>
Reviewed-by: Maks Orlovich <morlovich@chromium.org>
Owners-Override: Rick Byers <rbyers@chromium.org>
Reviewed-by: Rick Byers <rbyers@chromium.org>
Commit-Queue: Sandor «Alex» Major <sandormajor@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1414133}
2025-01-31 07:48:32 -08:00
Patrick Monette
15442a11e7 Avoid including web_contents.h in web_contents_observer.h
A previous change added the CapabilityType as an inner enum of
WebContents which forced the inclusion of web_contents.h in
web_contents_observer.h.
See https://chromium-review.googlesource.com/c/chromium/src/+/5938280

This change moves the enum to its own file to avoid this as
web_contents.h is a huge header, making it worth to avoid including
when not needed.

Change-Id: I37fdf6c5443c242557a5c1c32fa1a7688fde8738
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6180166
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Eric Seckler <eseckler@chromium.org>
Reviewed-by: Andy Paicu <andypaicu@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1409875}
2025-01-22 12:09:31 -08:00
Ken Rockot
00c6363b50 Remove rockot@ from device-related OWNERS files
Bug: None
Change-Id: I3c4ea717f2e90c9fa185a2e1599a406227df9c8f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6042046
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Auto-Submit: Ken Rockot <rockot@google.com>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1386467}
2024-11-21 21:34:28 +00:00
Yifan Luo
7e675b750b Merge IsConnectedToXXX functions into one IsCapabilityActive function
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}
2024-10-22 19:19:07 +00:00
François Doray
e753bf906f [freezing] Track Hid and Serial port connections in Performance Manager.
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}
2024-09-17 15:03:08 +00:00
Alvin Ji
033821e6bd usb: Ensure protected interface classes are gate behind feature
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}
2024-08-27 19:20:01 +00:00
Peter Boström
01ab59ae08 Migrate NOTREACHED_NORETURN -> NOTREACHED
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}
2024-08-15 02:39:49 +00:00
Devon Loehr
dcb8b4693a Make implicit this capture explicit
When declaring a lambda with a value-capture default [=, ...], the
this pointer is implicitly captured by value as well. This results
in potentially-unintuitive behavior and has been deprecated in C++20.
It produces a warning in newer versions of clang
(https://reviews.llvm.org/D142639).

This CL makes the implicit captures explicit, preventing the warning.
It does not change the compiled code at all, since it's just removing
some syntactic sugar.

This CL implements the following LSC: go/implicit-this-capture-lsc

Bug: 351004963
Change-Id: I3c90d178794f4fc007c553c96cf2cbed4c1072e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5731072
Owners-Override: Nico Weber <thakis@chromium.org>
Reviewed-by: Alan Zhao <ayzhao@google.com>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Commit-Queue: Alan Zhao <ayzhao@google.com>
Reviewed-by: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1336226}
2024-08-01 20:17:28 +00:00
Daniel Cheng
db3aca6f13 WebUsbServiceImpl: destroy UsbDeviceClients before connection_count_
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}
2024-05-29 23:47:54 +00:00
Md Hasibul Hasan
a963a934b5 Convert base::StringPiece to std::string_view in content/browser
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}
2024-04-03 10:15:14 +00:00
Camille Lamy
c0cb90f93a Remove kMaybe* values from WebExposedIsolationLevel
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}
2024-03-08 09:43:06 +00:00
Andrew Rayskiy
f659903691 [base] Update Erase()/EraseIf() calls for std::vector<> in content/
They're now replaced with C++20 std::erase()/std::erase_if().

Bug: 40256229

Change-Id: Iec75c084d37bebbfcd31cfa2b44ea15f072f9658
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5324661
Reviewed-by: Kyle Charbonneau <kylechar@chromium.org>
Commit-Queue: Kyle Charbonneau <kylechar@chromium.org>
Auto-Submit: Andrew Rayskiy <greengrape@google.com>
Owners-Override: Kyle Charbonneau <kylechar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1265945}
2024-02-27 18:43:24 +00:00
Jeff Yoon
d1328c4408 [buganizer] Migrate DIR_METADATA in content/browser/
Migrate all metadata files for content/browser.

Verify components with http://b/components/{id} or at
go/chrome-on-buganizer-prod-components.

Bug: chromium:1518875
Change-Id: I555b9fe40952a5707e167b3dcbaf2858bbdf1f34
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5284095
Reviewed-by: Avi Drissman <avi@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1258966}
2024-02-11 19:24:26 +00:00
Arthur Sonzogni
c686e8f4fd Rename {absl => std}::optional in //content/
Automated patch, intended to be effectively a no-op.

Context:
https://groups.google.com/a/chromium.org/g/cxx/c/nBD_1LaanTc/m/ghh-ZZhWAwAJ?utm_medium=email&utm_source=footer

As of https://crrev.com/1204351, absl::optional is now a type alias for
std::optional. We should migrate toward it.

Script:
```
function replace {
  echo "Replacing $1 by $2"
  git grep -l "$1" \
    | cut -f1 -d: \
    | grep \
      -e "^content" \
    | sort \
    | uniq \
    | grep \
      -e "\.h" \
      -e "\.cc" \
      -e "\.mm" \
      -e "\.py" \
    | xargs sed -i "s/$1/$2/g"
}
replace "absl::make_optional" "std::make_optional"
replace "absl::optional" "std::optional"
replace "absl::nullopt" "std::nullopt"
replace "absl::in_place" "std::in_place"
replace "absl::in_place_t" "std::in_place_t"
replace "\"third_party\/abseil-cpp\/absl\/types\/optional.h\"" "<optional>"
git cl format
```

# Skipping unrelated "check_network_annotation" errors.
NOTRY=True

Bug: chromium:1500249
Change-Id: Icfd31a71d8faf63a2e8d5401127e7ee74cc1c413
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5185537
Auto-Submit: Arthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Owners-Override: Avi Drissman <avi@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1245739}
2024-01-11 08:36:37 +00:00
Alvin Ji
75cab1052a usb: Add usb-unrestricted to permission policy
This CL introduces "usb-unrestricted" permission and is used to gate
unrestricted USB feature. Originally, IWA's isolated frames only need
"usb" permission to claim protected class interface. With this CL, IWA's
isolated frames now need both "usb" + "usb-unrestricted" permissions to
claim it.

Design Doc: go/unrestricted-webusb-plan

Bug: 1236706
Change-Id: Ia0f225311f899a093e634ca6473e443f3436f744
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4917953
Reviewed-by: Alex Moshchuk <alexmos@chromium.org>
Reviewed-by: Matt Reynolds <mattreynolds@chromium.org>
Commit-Queue: Alvin Ji <alvinji@chromium.org>
Reviewed-by: Alvin Ji <alvinji@chromium.org>
Reviewed-by: Robbie McElrath <rmcelrath@chromium.org>
Reviewed-by: Kent Tamura <tkent@chromium.org>
Reviewed-by: Alex Rudenko <alexrudenko@chromium.org>
Reviewed-by: Daniel Vogelheim <vogelheim@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1230723}
2023-11-29 17:28:45 +00:00
Juan Garza Sanchez
1c7d8e85e7 usb: Support device events when service worker is inactive
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}
2023-08-24 22:45:51 +00:00
Juan Garza Sanchez
62cce615f1 usb: Introduce ServiceWorkerUsbDelegateObserver for WebUsbService
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}
2023-08-24 20:26:45 +00:00
Lei Zhang
74a8f53cb7 Remove ServiceWorkerVersion::GetEmbeddedWorkerForTesting()
Just use ServiceWorkerVersion::embedded_worker() instead.

Change-Id: I7318ce0c310563374567615392545da0c02ec081
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4772126
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Jack Hsieh <chengweih@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1183136}
2023-08-14 16:48:16 +00:00
Kevin McNee
9baa3da097 Don't share WebUSB permissions with webviews
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}
2023-08-03 00:38:59 +00:00
Juan Garza Sanchez
ef1f3a1235 usb: Keep WebUsb service worker alive during device's connection session
Keep the service worker alive during the device's connection session to
prevent it from being terminated due to inactivity.

Bug: 1303193
Change-Id: I3ee497e4a93b46181d83eee2beee12143ef01bb0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4680017
Commit-Queue: Jack Hsieh <chengweih@chromium.org>
Reviewed-by: Marijn Kruisselbrink <mek@chromium.org>
Auto-Submit: Juan Garza Sanchez <juangarza@chromium.org>
Reviewed-by: Jack Hsieh <chengweih@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1170678}
2023-07-14 20:35:49 +00:00
Juan Garza Sanchez
f2ce4178d7 usb: Add connection count tracking methods for UsbDelegate
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}
2023-07-13 14:36:47 +00:00
François Beaufort
19b0f58776 WebUSB: Add exclusionFilters to USBRequestDeviceOptions
This CL adds a new "exclusionFilters" option in
navigator.usb.requestDevice() options so that web developers can
exclude from the browser picker some devices that are known to not work
as expected.

Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
Spec:
- https://github.com/WICG/webusb/pull/233
- https://github.com/WICG/webusb/pull/235
Demo: https://usb-exclusion-filters.glitch.me/

Bug: 1455392
Change-Id: I1b61d9daae3e14accedb24e493ae656316427893
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4614682
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Fr <beaufort.francois@gmail.com>
Cr-Commit-Position: refs/heads/main@{#1161953}
2023-06-23 21:18:39 +00:00
Matt Reynolds
b2c3b7bbf2 Add mattreynolds@ and chengweih@ to WebUSB and chrome.usb OWNERS files
Bug: None
Change-Id: I37e40f74b3850eb7013e82464b4f29659310a1d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4548129
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Auto-Submit: Matt Reynolds <mattreynolds@chromium.org>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1146697}
2023-05-19 20:30:47 +00:00
Reilly Grant
0113e82b7c usb: Fix flaky content_browsertests
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}
2023-04-18 19:45:39 +00:00
Ari Chivukula
04f6ff7e5c [Permissions Policy + CSP] (1) Ban opaque origins from OriginWithPossibleWildcard
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}
2023-03-22 18:02:00 +00:00
Jack Hsieh
425ab488f2 usb: Reject using WebUSB API in an opaque origin
Rejects renderer's request of using WebUSB API when the top-level
document has an opaque origin.

Bug: 1375133
Change-Id: I1b449389e55ea8ead412ea9e87fc99971997b491
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4237626
Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org>
Commit-Queue: Jack Hsieh <chengweih@chromium.org>
Reviewed-by: Alex Moshchuk <alexmos@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1116595}
2023-03-13 21:19:03 +00:00
Reilly Grant
85af4a9a0d usb: Use Mojo union to separate device open success from error codes
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}
2023-02-15 02:46:17 +00:00
Scott Violet
9986199c3c content: makes content browsertests subclass test ContentBrowserClient
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}
2023-02-08 01:20:12 +00:00
Avi Drissman
adac219925 Update header includes for /base/functional in /content
bind.h, callback.h, callback_forward.h, and callback_helpers.h
moved into /base/functional/. Update the include paths to
directly include them in their new location.

Bug: 1364441
Change-Id: I32ec425b9c0e52ec4b50047bf3290fecc5c905ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4148554
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Owners-Override: Avi Drissman <avi@chromium.org>
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1091567}
2023-01-11 23:46:39 +00:00
Jack Hsieh
09798d08c9 Add chengweih@chromium.org to some device API owner files
Add chengweih@chromium.org to WebBluetooth, WebUSB and WebHID owner
files.

Bug: None
Change-Id: I87c7c6eba7952ea66ce851a251ba80ccb5f1d76d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4090553
Reviewed-by: Matt Reynolds <mattreynolds@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Jack Hsieh <chengweih@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1081306}
2022-12-09 04:05:51 +00:00
Jinho Bang
2c2803342c webusb: Create DOMException with V8ThrowDOMException
This CL is a part of chain of updates for replacing DOMException
constructors with V8ThrowDOMException.

Bug: 991544
Change-Id: Ic499a5f1a587feaf23ff2973c3b1abfdf653ebda
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3915991
Commit-Queue: Jinho Bang <zino@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1052780}
2022-09-29 02:18:23 +00:00
Matt Reynolds
4972fa03ed usb: Create WebUsbService with ServiceWorkerContextCore
In preparation for exposing WebUSB API to extension service workers,
refactor WebUsbService so it can be bound from a service worker
context.

Bug: 1322258
Change-Id: I34c3867fdb0a9b8daeee3b6b0d86b4d8f222b10e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3840462
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1052541}
2022-09-28 18:27:58 +00:00
Avi Drissman
4e1b7bc33d Update copyright headers in content/
The methodology used to generate this CL is documented in
https://crbug.com/1098010#c34.

No-Try: true
No-Presubmit: true
Bug: 1098010
Change-Id: I8c0f009d16350271f07d8e5e561085822cc9dd27
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3895935
Owners-Override: Avi Drissman <avi@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1047456}
2022-09-15 14:03:50 +00:00
Matt Reynolds
ed00ca7e74 usb: Move WebUsbServiceImpl to //content
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}
2022-08-18 20:56:20 +00:00