-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Geolocation permission bubble (#23278)
* Update Geolocation permission dialog fix brave/brave-browser#16897 Added more information to users for getting precise location. --------- Co-authored-by: Brian Clifton <[email protected]>
- Loading branch information
Showing
20 changed files
with
677 additions
and
1 deletion.
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.