-
Notifications
You must be signed in to change notification settings - Fork 900
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
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a512010
Update Geolocation permission dialog
simonhong 736f3f9
Consider enableHighAccuracy bit from web site
simonhong ed62798
Updated bubble text and added icon based on high accuracy state
simonhong 4dea3bf
WIP: Check location service status on macOS
simonhong 3373a2d
Fixing upstream test failure
simonhong a949006
Added platform guards
simonhong 7459f4b
Cleanup
simonhong a10895e
Added test
simonhong 2627f7d
Update browser/brave_content_browser_client.cc
simonhong 4532a5d
Fixed build failure on Android
simonhong 502dae7
Use kCLAuthorizationStatusAuthorizedAlways
simonhong 6b17233
Refactored to have separated api for handling placeholders in string
simonhong 79fe0d6
Removed geolocation.cc patch
simonhong e4b32f7
Updated learn more url constants
simonhong 9cb97cd
Updated IsSystemLocationSettingEnabled()
simonhong e4ad5fa
Updated strings desc
simonhong 98f92e0
fixup! Updated IsSystemLocationSettingEnabled()
simonhong 8ec14a5
Deleted GetStringFUTF16WithPlaceHolders()
simonhong 17ba984
Added brave_geolocation_permission_blink target via brave_blink_rende…
simonhong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
assert(!is_android) | ||
|
||
source_set("browser_tests") { | ||
testonly = true | ||
defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ] | ||
|
||
sources = [ "brave_geolocation_browsertest.cc" ] | ||
deps = [ | ||
"//base", | ||
"//brave/components/constants", | ||
"//chrome/browser", | ||
"//chrome/browser/ui", | ||
"//chrome/common:constants", | ||
"//chrome/test:test_support_ui", | ||
"//content/test:test_support", | ||
"//net:test_support", | ||
"//url", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include <string> | ||
|
||
#include "base/path_service.h" | ||
#include "brave/browser/ui/geolocation/brave_geolocation_permission_tab_helper.h" | ||
#include "brave/components/constants/brave_paths.h" | ||
#include "chrome/browser/ssl/cert_verifier_browser_test.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/browser/ui/browser_commands.h" | ||
#include "chrome/browser/ui/tabs/tab_strip_model.h" | ||
#include "chrome/common/chrome_paths.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "chrome/test/base/ui_test_utils.h" | ||
#include "content/public/test/browser_test.h" | ||
#include "content/public/test/browser_test_utils.h" | ||
#include "content/public/test/test_navigation_observer.h" | ||
#include "content/public/test/test_utils.h" | ||
#include "net/dns/mock_host_resolver.h" | ||
#include "url/gurl.h" | ||
|
||
class GeolocationPermissionRequestBrowserTest : public CertVerifierBrowserTest { | ||
public: | ||
GeolocationPermissionRequestBrowserTest() | ||
: https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {} | ||
|
||
void SetUpOnMainThread() override { | ||
CertVerifierBrowserTest::SetUpOnMainThread(); | ||
host_resolver()->AddRule("*", "127.0.0.1"); | ||
brave::RegisterPathProvider(); | ||
base::FilePath test_data_dir = | ||
base::PathService::CheckedGet(brave::DIR_TEST_DATA); | ||
https_server_.ServeFilesFromDirectory(test_data_dir); | ||
mock_cert_verifier()->set_default_result(net::OK); | ||
|
||
ASSERT_TRUE(https_server_.Start()); | ||
} | ||
|
||
content::WebContents* active_contents() { | ||
return browser()->tab_strip_model()->GetActiveWebContents(); | ||
} | ||
|
||
protected: | ||
net::EmbeddedTestServer https_server_; | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(GeolocationPermissionRequestBrowserTest, | ||
SetEnableHighAccuracyTest) { | ||
GURL url = https_server_.GetURL("a.com", "/simple.html"); | ||
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url)); | ||
|
||
auto* tab_helper = | ||
BraveGeolocationPermissionTabHelper::FromWebContents(active_contents()); | ||
EXPECT_FALSE(tab_helper->enable_high_accuracy()); | ||
|
||
const std::string get_current_position_js_with_high = | ||
"navigator.geolocation.getCurrentPosition(() => {}, () => {}, { " | ||
"enableHighAccuracy : true })"; | ||
ASSERT_EQ(nullptr, content::EvalJs(active_contents(), | ||
get_current_position_js_with_high)); | ||
content::RunAllTasksUntilIdle(); | ||
EXPECT_TRUE(tab_helper->enable_high_accuracy()); | ||
|
||
// Reload clear high_accuracy bit from tab helper. | ||
content::TestNavigationObserver observer(active_contents()); | ||
chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | ||
observer.Wait(); | ||
EXPECT_FALSE(tab_helper->enable_high_accuracy()); | ||
|
||
const std::string get_current_position_js_without_high = | ||
"navigator.geolocation.getCurrentPosition(() => {}, () => {}, { " | ||
"enableHighAccuracy : false })"; | ||
ASSERT_EQ(nullptr, content::EvalJs(active_contents(), | ||
get_current_position_js_without_high)); | ||
content::RunAllTasksUntilIdle(); | ||
EXPECT_FALSE(tab_helper->enable_high_accuracy()); | ||
} |
52 changes: 52 additions & 0 deletions
52
browser/ui/geolocation/brave_geolocation_permission_tab_helper.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/ui/geolocation/brave_geolocation_permission_tab_helper.h" | ||
|
||
#include <utility> | ||
|
||
#include "content/public/browser/navigation_handle.h" | ||
#include "content/public/browser/web_contents.h" | ||
|
||
BraveGeolocationPermissionTabHelper::BraveGeolocationPermissionTabHelper( | ||
content::WebContents* contents) | ||
: WebContentsObserver(contents), | ||
content::WebContentsUserData<BraveGeolocationPermissionTabHelper>( | ||
*contents), | ||
brave_geolocation_permission_receivers_(contents, this) {} | ||
|
||
BraveGeolocationPermissionTabHelper::~BraveGeolocationPermissionTabHelper() = | ||
default; | ||
|
||
// static | ||
void BraveGeolocationPermissionTabHelper::BindBraveGeolocationPermission( | ||
mojo::PendingAssociatedReceiver< | ||
geolocation::mojom::BraveGeolocationPermission> receiver, | ||
content::RenderFrameHost* rfh) { | ||
auto* web_contents = content::WebContents::FromRenderFrameHost(rfh); | ||
if (!web_contents) { | ||
return; | ||
} | ||
|
||
auto* tab_helper = | ||
BraveGeolocationPermissionTabHelper::FromWebContents(web_contents); | ||
if (!tab_helper) { | ||
return; | ||
} | ||
tab_helper->brave_geolocation_permission_receivers_.Bind(rfh, | ||
std::move(receiver)); | ||
} | ||
|
||
void BraveGeolocationPermissionTabHelper::PrimaryPageChanged( | ||
content::Page& page) { | ||
enable_high_accuracy_ = false; | ||
} | ||
|
||
void BraveGeolocationPermissionTabHelper::SetEnableHighAccuracy( | ||
bool enable_high_accuracy) { | ||
enable_high_accuracy_ = enable_high_accuracy; | ||
} | ||
|
||
WEB_CONTENTS_USER_DATA_KEY_IMPL(BraveGeolocationPermissionTabHelper); |
45 changes: 45 additions & 0 deletions
45
browser/ui/geolocation/brave_geolocation_permission_tab_helper.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_UI_GEOLOCATION_BRAVE_GEOLOCATION_PERMISSION_TAB_HELPER_H_ | ||
#define BRAVE_BROWSER_UI_GEOLOCATION_BRAVE_GEOLOCATION_PERMISSION_TAB_HELPER_H_ | ||
|
||
#include "brave/components/brave_geolocation_permission/common/brave_geolocation_permission.mojom.h" | ||
#include "content/public/browser/render_frame_host_receiver_set.h" | ||
#include "content/public/browser/web_contents_observer.h" | ||
#include "content/public/browser/web_contents_user_data.h" | ||
|
||
class BraveGeolocationPermissionTabHelper final | ||
: public content::WebContentsObserver, | ||
public geolocation::mojom::BraveGeolocationPermission, | ||
public content::WebContentsUserData<BraveGeolocationPermissionTabHelper> { | ||
public: | ||
explicit BraveGeolocationPermissionTabHelper(content::WebContents* contents); | ||
~BraveGeolocationPermissionTabHelper() override; | ||
|
||
static void BindBraveGeolocationPermission( | ||
mojo::PendingAssociatedReceiver< | ||
geolocation::mojom::BraveGeolocationPermission> receiver, | ||
content::RenderFrameHost* rfh); | ||
|
||
// content::WebContentsObserver | ||
void PrimaryPageChanged(content::Page& page) override; | ||
|
||
// geolocation::mojom::BraveGeolocationPermission overrides: | ||
void SetEnableHighAccuracy(bool high_accuracy) override; | ||
|
||
bool enable_high_accuracy() const { return enable_high_accuracy_; } | ||
|
||
WEB_CONTENTS_USER_DATA_KEY_DECL(); | ||
|
||
private: | ||
content::RenderFrameHostReceiverSet< | ||
geolocation::mojom::BraveGeolocationPermission> | ||
brave_geolocation_permission_receivers_; | ||
|
||
bool enable_high_accuracy_ = false; | ||
}; | ||
|
||
#endif // BRAVE_BROWSER_UI_GEOLOCATION_BRAVE_GEOLOCATION_PERMISSION_TAB_HELPER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_UI_GEOLOCATION_GEOLOCATION_UTILS_H_ | ||
#define BRAVE_BROWSER_UI_GEOLOCATION_GEOLOCATION_UTILS_H_ | ||
|
||
#include "base/functional/callback_forward.h" | ||
|
||
namespace geolocation { | ||
|
||
// Run |callback| with true when system location service is available to | ||
// applications. | ||
void IsSystemLocationSettingEnabled(base::OnceCallback<void(bool)> callback); | ||
|
||
bool CanGiveDetailedGeolocationRequestInfo(); | ||
|
||
} // namespace geolocation | ||
|
||
#endif // BRAVE_BROWSER_UI_GEOLOCATION_GEOLOCATION_UTILS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/ui/geolocation/geolocation_utils.h" | ||
|
||
#include "base/functional/callback.h" | ||
|
||
namespace geolocation { | ||
|
||
void IsSystemLocationSettingEnabled(base::OnceCallback<void(bool)> callback) {} | ||
|
||
bool CanGiveDetailedGeolocationRequestInfo() { | ||
return false; | ||
} | ||
|
||
} // namespace geolocation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/ui/geolocation/geolocation_utils.h" | ||
|
||
#import <CoreLocation/CoreLocation.h> | ||
|
||
#include <utility> | ||
|
||
#include "base/functional/callback.h" | ||
|
||
namespace geolocation { | ||
|
||
namespace { | ||
|
||
bool GetSystemLocationSettingEnabled() { | ||
// Service is off globally. | ||
if (![CLLocationManager locationServicesEnabled]) { | ||
return false; | ||
} | ||
|
||
if (@available(macOS 11.0, *)) { | ||
CLLocationManager* manager = [[CLLocationManager alloc] init]; | ||
if ([manager authorizationStatus] == | ||
kCLAuthorizationStatusAuthorizedAlways) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} // namespace | ||
|
||
void IsSystemLocationSettingEnabled(base::OnceCallback<void(bool)> callback) { | ||
std::move(callback).Run(GetSystemLocationSettingEnabled()); | ||
} | ||
|
||
bool CanGiveDetailedGeolocationRequestInfo() { | ||
if (@available(macOS 11.0, *)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} // namespace geolocation |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think these strings should use the usual placeholders which then can be used to get the offsets to style the message. It will be clearer for translation and easier for everyone to understand.
cc @mkarolin
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.
Added
Each part will be used to get offset in the string.
to the desc.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.
I was thinking of using placeholders like so, but maybe that's not the best way, I'm not sure.
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.
It was what I tried in the first and @mkarolin suggested another way for better localization - #19529 (comment)