Skip to content
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

Update Geolocation permission bubble #23278

Merged
merged 19 commits into from
May 8, 2024
Merged

Conversation

simonhong
Copy link
Member

@simonhong simonhong commented Apr 25, 2024

fix brave/brave-browser#16897

Added more information to users for getting precise location.
With passed enableHighAccuracy, permission bubble could give more precise info.

When page requests current position w/o highAccuracy, below bubble should shown.
[Type A]
image

When page requests current position with highAccuracy, we have two types of bubble.
When os location service is enabled, below bubble is shown
[Type B]
image
When os location service is disabled, this is shown.
[Type C]
image

Resolves

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

GeolocationPermissionRequestBrowserTest.SetEnabledHighAccuracyTest
LocalizationUtilTest.GetLocalizedResourceUTF16StringWithPlaceholders

NOTE: geolocation permission bubble is not changed on Linux

  1. Launch browser and open inspector with any tabs
  2. Run navigator.geolocation.getCurrentPosition(() => {}, () => {}, { enableHighAccuracy : false });
  3. check Type A bubble is shown
  4. Dismiss bubble and reset permission state if needed
  5. Disable OS location service
  6. Run navigator.geolocation.getCurrentPosition(() => {}, () => {}, { enableHighAccuracy : true });
  7. Chek Type B bubble is shown
  8. Dismiss bubble and reset permission state if needed
  9. Enable OS location service (On macOS, brave should be enabled also)
  10. Run navigator.geolocation.getCurrentPosition(() => {}, () => {}, { enableHighAccuracy : true });
  11. Check Type C bubble is shown

@simonhong simonhong self-assigned this Apr 25, 2024
@simonhong simonhong added the CI/skip Do not run CI builds (except noplatform) label Apr 25, 2024
@simonhong simonhong force-pushed the geolocation_permission_prompt branch 2 times, most recently from 296ad10 to d3f8d1e Compare April 25, 2024 07:45
@simonhong simonhong changed the title Update Geolocation permission dialog Update Geolocation permission bubble Apr 26, 2024
@simonhong simonhong force-pushed the geolocation_permission_prompt branch from d3f8d1e to 7fda375 Compare April 26, 2024 07:08
@simonhong simonhong force-pushed the geolocation_permission_prompt branch 2 times, most recently from a33f5d5 to b8053f4 Compare April 29, 2024 01:18
@simonhong
Copy link
Member Author

simonhong commented Apr 29, 2024

If permission bubble knows about whether web site requested geolocation with high accuracy or not,
it would be helpful to give more precise info(warning) to users about geolocation permission request from web site.

Renderer uses Geolocation mojo interface(geolocation.mojom) and it's used from WebContentsImpl.
It means, it's in contents layer internal implementation so it's hard to get about high accuracy info from client layer.
Instead of touching WebContents, Geolocation, GeolocationContext interface and etc, it would be more simple
to have separated mojo interface to simply passing it from renderer to browser process.

@simonhong simonhong removed the CI/skip Do not run CI builds (except noplatform) label Apr 29, 2024
@simonhong simonhong force-pushed the geolocation_permission_prompt branch 2 times, most recently from b806613 to 13a8954 Compare April 30, 2024 01:06
@simonhong simonhong added the CI/skip Do not run CI builds (except noplatform) label Apr 30, 2024
@simonhong simonhong force-pushed the geolocation_permission_prompt branch 3 times, most recently from 5e8c3e9 to 00613e0 Compare April 30, 2024 07:02
@simonhong
Copy link
Member Author

simonhong commented Apr 30, 2024

PermissionPromptBubbleOneOriginViewTest.AccessibleTitleDoesNotMentionTooManyPermissions is failed in PR builder but it's ok on local build. checking. => Fixed. Browser could be null in some unit tests.

@simonhong simonhong removed the CI/skip Do not run CI builds (except noplatform) label Apr 30, 2024
@simonhong simonhong force-pushed the geolocation_permission_prompt branch 5 times, most recently from 657dd2c to 55e3e34 Compare May 1, 2024 04:10
@simonhong simonhong marked this pull request as ready for review May 1, 2024 05:03
@simonhong simonhong requested review from a team as code owners May 1, 2024 05:03
@simonhong simonhong force-pushed the geolocation_permission_prompt branch from dd5d9ab to e4ad5fa Compare May 7, 2024 03:21
@simonhong simonhong force-pushed the geolocation_permission_prompt branch from 280d448 to 98f92e0 Compare May 7, 2024 07:03
</message>
<message name="IDS_GEOLOCATION_PERMISSION_BUBBLE_HIGH_ACCURACY_WITHOUT_LOCATION_SERVICE_LABEL" desc="The text for geolocation permission bubble with high accuracy">
This site has requested your <ph name="PART_ONE">$1</ph>precise location<ph name="PART_ONE_END">$2</ph>. Brave will only able to provide <ph name="PART_TWO">$3</ph>general location<ph name="PART_TWO_END">$4</ph> data due to <ph name="PART_THREE">$5</ph>Location Services<ph name="PART_THREE_END">$6</ph> being disabled. <ph name="PART_FOUR">$7</ph>Learn more<ph name="PART_FOUR_END">$8</ph>
</message>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of using placeholders like so, but maybe that's not the best way, I'm not sure.

IDS_GEOLOCATION_PERMISSION_BUBBLE_REQUESTED_LOCATION_TYPE_LABEL:
This site has requested your <ph name="LOCATION_TYPE">$1<ex>general location</ex></ph>. <ph name="LEARN_MORE">$2<ex>Learn more</ex></ph>.

IDS_GEOLOCATION_PERMISSION_BUBBLE_LOCATION_TYPE_GENERAL desc="Used as a placeholder replacement in IDS_GEOLOCATION_PERMISSION_BUBBLE_REQUESTED_LOCATION_TYPE_LABEL":
general location

IDS_GEOLOCATION_PERMISSION_BUBBLE_LOCATION_TYPE_PRECISE desc="Used as a placeholder replacement in IDS_GEOLOCATION_PERMISSION_BUBBLE_REQUESTED_LOCATION_TYPE_LABEL":
precise location

IDS_GEOLOCATION_PERMISSION_BUBBLE_REQUESTED_LOCATION_TYPE_WITHOUT_LOCATION_SERVICE_LABEL:
Brave will only able to provide <ph name="LOCATION_TYPE">$1<ex>general location</ex></ph> data due to <ph name="LOCATION_SERVICES">$2<ex>Location Services</ex></ph> being disabled. <ph name="LEARN_MORE">$2<ex>Learn more</ex></ph>

IDS_GEOLOCATION_PERMISSION_BUBBLE_LOCATION_SERVICES:
Location Services


export_class_attribute_blink = "CORE_EXPORT"
export_define_blink = "BLINK_CORE_IMPLEMENTATION=1"
export_header_blink = "third_party/blink/renderer/core/core_export.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove these export variables and add brave_geolocation_permission_blink directly into blink core via brave_blink_renderer_core_deps.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed via 17ba984 but it seems above defines are needed.
Got build failure w/o them.

Copy link
Contributor

github-actions bot commented May 7, 2024

[puLL-Merge] - brave/brave-core@23278

Description

This PR adds more detailed informational text to the geolocation permission request dialog. The text varies depending on if the user has requested high accuracy location and if the system location services are enabled. It also includes a "Learn more" link to platform-specific documentation about location services.

Changes

Changes

  • app/brave_generated_resources.grd: Added new string resources for the geolocation permission dialog text with placeholders.
  • browser/brave_content_browser_client.cc: Registered the BraveGeolocationPermission interface.
  • browser/brave_tab_helpers.cc: Created the BraveGeolocationPermissionTabHelper for each web contents.
  • browser/ui/BUILD.gn: Added build targets for the new geolocation permission code.
  • browser/ui/geolocation/brave_geolocation_browsertest.cc: Added a browser test for the BraveGeolocationPermissionTabHelper.
  • browser/ui/geolocation/brave_geolocation_permission_tab_helper.cc and browser/ui/geolocation/brave_geolocation_permission_tab_helper.h: Implemented the tab helper to track if high accuracy was requested by the page.
  • browser/ui/geolocation/geolocation_utils_*.cc: Added platform-specific code to check if the system location services are enabled.
  • chromium_src/chrome/browser/ui/views/permissions/permission_prompt_bubble_base_view.cc: Modified the permission dialog to include the new geolocation text.
  • components/brave_geolocation_permission/common/: Added a new Mojo interface for the renderer to communicate to the browser if high accuracy is requested.

Security Hotspots

  1. Low: The IsSystemLocationSettingEnabled functions make platform-specific system calls to check location service status. Ensure the implementations cannot be abused.
  2. Low: The new text in the permission dialog includes a link to an external site. Ensure the URL is safe and controlled by Brave.
  3. Low: The renderer uses Mojo to notify the browser of high accuracy requests. Ensure this cannot be abused by a compromised renderer.

The changes overall look safe and well-contained. The main security consideration is ensuring the platform-specific code cannot enable location access improperly. The Mojo usage also warrants a careful review, but follows established patterns. Adding tests is good to see for a user-facing change like this.

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried the different states - each worked great 😄👍

Nice cleanup on the placeholders too - thanks @goodov for the help

@simonhong simonhong merged commit 219f661 into master May 8, 2024
19 checks passed
@simonhong simonhong deleted the geolocation_permission_prompt branch May 8, 2024 00:35
@github-actions github-actions bot added this to the 1.67.x - Nightly milestone May 8, 2024
@simonhong
Copy link
Member Author

It's finally fixed. thanks all for great review!

@rishiraj88
Copy link

Great thanks to you, @simonhong , for taking this humongous activity up. It has been as huge to fix as useful it is to end-users.

@@ -797,6 +797,10 @@
You're viewing a WebTorrent page
</message>

<message name="IDS_TEST_STRING_FOR_PLACEHOLDERS" desc="Only for test purpose. Don't need to translate">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonhong, you can use translateable="false" attribute in the future if the string doesn't need to be translated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add permission for location service to help improve geolocation accuracy
5 participants