Rename {absl => std}::optional in //extensions/
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 "^extensions" \ | 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 ``` Bug: chromium:1500249 Change-Id: I4bf9b19df5f7d5fac08469580ab8f9078f601953 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5018002 Auto-Submit: Arthur Sonzogni <arthursonzogni@chromium.org> Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org> Reviewed-by: Reilly Grant <reillyg@chromium.org> Cr-Commit-Position: refs/heads/main@{#1225614}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
347eeabdca
commit
0b20ccad48
extensions
browser
api
alarms
app_current_window_internal
app_runtime
app_window
audio
automation_internal
automation_event_router.ccautomation_event_router.hautomation_event_router_interface.hautomation_internal_api.ccautomation_internal_api.h
bluetooth
bluetooth_api.hbluetooth_api_utils.ccbluetooth_apitest.ccbluetooth_private_api.ccbluetooth_private_api.hbluetooth_private_apitest.cc
bluetooth_low_energy
bluetooth_socket
clipboard
declarative
declarative_api.hdeclarative_rule_unittest.ccdeduping_factory_unittest.ccrules_cache_delegate.ccrules_cache_delegate.hrules_registry.ccrules_registry.h
declarative_net_request
action_tracker.ccaction_tracker.hcomposite_matcher.cccomposite_matcher.hcomposite_matcher_unittest.ccdeclarative_net_request_api.ccdeclarative_net_request_api.hdeclarative_net_request_prefs_helper.ccdeclarative_net_request_prefs_helper.hdeclarative_net_request_prefs_helper_unittest.ccextension_url_pattern_index_matcher.ccextension_url_pattern_index_matcher.hfile_sequence_helper.ccfile_sequence_helper.hfile_sequence_helper_unittest.cc
filter_list_converter
flat_ruleset_indexer.ccflat_ruleset_indexer_unittest.ccindexed_rule.ccindexed_rule.hindexed_rule_fuzzer.ccindexed_rule_unittest.ccinstall_index_helper.ccinstall_index_helper.hregex_rules_matcher.ccregex_rules_matcher.hrequest_action.ccrequest_action.hrequest_params.hrule_counts.ccrule_counts.hrules_monitor_service.ccrules_monitor_service.hruleset_install_pref.ccruleset_install_pref.hruleset_manager.ccruleset_manager.hruleset_matcher.ccruleset_matcher.hruleset_matcher_base.ccruleset_matcher_base.hruleset_matcher_unittest.cctest_utils.cctest_utils.hutils.ccutils.hdeclarative_webrequest
device_permissions_manager.ccdiagnostics
dns
execute_code_function.ccexecute_code_function.hfeedback_private
file_handlers
file_system
guest_view
hid
idle
lock_screen_data
management
media_perception_private
conversion_utils_unittest.ccmedia_perception_api_manager.ccmedia_perception_api_manager.hmedia_perception_private_api.cc
messaging
extension_message_port.ccextension_message_port.hmessage_port.ccmessage_port.hmessage_service.ccmessage_service_bindings.ccmessaging_api_message_filter.ccmessaging_delegate.ccmessaging_delegate.hnative_messaging_channel.h
metrics_private
networking_private
networking_private_api.ccnetworking_private_api.hnetworking_private_chromeos.ccnetworking_private_chromeos.hnetworking_private_chromeos_unittest.ccnetworking_private_delegate.hnetworking_private_lacros.ccnetworking_private_linux.ccnetworking_private_service_client.cc
offscreen
power
activity_reporter_delegate.hactivity_reporter_delegate_ash.ccactivity_reporter_delegate_ash.hactivity_reporter_delegate_lacros.ccactivity_reporter_delegate_lacros.hpower_api.cc
printer_provider
runtime
scripting
serial
socket
socket.ccsocket.hsocket_api.ccsocket_api.hsocket_apitest.cctcp_socket.cctcp_socket.htls_socket.cctls_socket.hudp_socket.ccudp_socket.h
sockets_tcp
sockets_tcp_server
sockets_tcp_server_api.ccsockets_tcp_server_api.hsockets_tcp_server_apitest.cctcp_server_socket_event_dispatcher.cctcp_server_socket_event_dispatcher.h
sockets_udp
storage
system_display
system_network
system_storage
test
usb
user_scripts
virtual_keyboard
virtual_keyboard_private
web_request
extension_web_request_event_router.ccextension_web_request_event_router.hupload_data_presenter.ccupload_data_presenter.hupload_data_presenter_unittest.ccweb_request_api.ccweb_request_api.hweb_request_api_helpers.ccweb_request_api_helpers.hweb_request_event_details.ccweb_request_event_details.hweb_request_info.ccweb_request_info.hweb_request_info_unittest.ccweb_request_permissions.ccweb_request_permissions.hweb_request_permissions_unittest.ccweb_request_proxying_url_loader_factory.ccweb_request_proxying_url_loader_factory.hweb_request_proxying_websocket.ccweb_request_proxying_websocket.hweb_request_proxying_webtransport.cc
webcam_private
app_window
background_script_executor.ccbackground_script_executor.hblob_reader.ccblob_reader.hblocklist_extension_prefs.cccomputed_hashes.cccomputed_hashes.hcomputed_hashes_unittest.cccontent_hash_reader.cccontent_verifier
content_verify_job_unittest.ccevent_listener_map.ccevent_listener_map.hevent_listener_map_unittest.ccevent_router.ccevent_router.hevent_router_unittest.ccevents
extension_api_frame_id_map.ccextension_creator.ccextension_creator.hextension_event_histogram_value_unittest.ccextension_frame_host.ccextension_frame_host.hextension_function.hextension_function_dispatcher.ccextension_function_histogram_value_unittest.ccextension_host_test_helper.hextension_prefs.ccextension_prefs.hextension_protocols.ccextension_registrar_unittest.ccextension_system.hextension_user_script_loader.ccextension_user_script_loader.hextension_util.ccextension_util.hextensions_browser_client.ccextensions_browser_client.hfile_reader.ccfile_reader.hfile_reader_unittest.ccguest_view
web_view
install
json_file_sanitizer.ccjson_file_sanitizer.hload_and_localize_file.ccload_and_localize_file.hmock_display_info_provider.ccmock_display_info_provider.hquota_service_unittest.ccrenderer_startup_helper.ccrenderer_startup_helper.hsandboxed_unpacker.ccsandboxed_unpacker.hsandboxed_unpacker_unittest.ccscript_executor.ccscript_injection_tracker.hservice_worker
service_worker_task_queue.ccservice_worker_task_queue.hstate_store.ccstate_store.hupdater
extension_downloader.ccextension_downloader.hextension_downloader_delegate.ccextension_downloader_delegate.hrequest_queue.hrequest_queue_impl.hsafe_manifest_parser.ccsafe_manifest_parser.hsafe_manifest_parser_unittest.ccupdate_data_provider.ccupdate_data_provider.hupdate_data_provider_unittest.ccupdate_service.ccupdate_service_unittest.cc
url_request_util.huser_script_loader.ccuser_script_loader.huser_script_manager.ccuser_script_manager.hverified_contents.cczipfile_installer.cczipfile_installer.hcommon
api
declarative_net_request
messaging
scripts_internal
sockets
features
file_util.ccfile_util.hfile_util_unittest.ccmanifest.ccmanifest.hmanifest_fuzzer.ccmanifest_handlers
action_handlers_handler.ccbackground_info.hcontent_scripts_handler.ccextension_action_handler_unittest.cckiosk_mode_info.cckiosk_mode_info.hweb_file_handlers_info.h
manifest_test.ccmanifest_test.hmanifest_unittest.ccmojom
event_dispatcher_mojom_traits.hmessage_port_mojom_traits.hpermission_set_mojom_traits.ccpermission_set_mojom_traits.h
permissions
url_pattern.ccurl_pattern.hurl_pattern_set.ccurl_pattern_unittest.ccutils
renderer
api
messaging
runtime_hooks_delegate.ccbindings
api_binding.ccapi_binding_js_util.ccapi_binding_js_util_unittest.ccapi_binding_test_util.ccapi_binding_unittest.ccapi_event_handler_unittest.ccapi_last_error.ccapi_last_error.hapi_last_error_unittest.ccapi_request_handler.ccapi_request_handler.hapi_request_handler_unittest.ccapi_response_validator_unittest.ccapi_signature.ccapi_signature.hapi_signature_unittest.ccargument_spec.ccargument_spec.hexception_handler_unittest.ccjs_runner.hreturns_async_builder.htest_js_runner.cc
dispatcher.ccdispatcher.hextension_js_runner.ccextension_js_runner.hextension_localization_throttle_unittest.ccextension_web_view_helper.ccextension_web_view_helper.hipc_message_sender.ccisolated_world_manager.ccisolated_world_manager.hnative_extension_bindings_system_unittest.ccprogrammatic_script_injector.ccprogrammatic_script_injector.hrenderer_extension_registry.ccrenderer_extension_registry.hscoped_web_frame.ccscript_context.ccscript_context_set.ccscript_injection.ccscript_injection.hscript_injection_manager.ccscript_injector.hservice_worker_data.ccservice_worker_data.huser_script_injector.ccuser_script_injector.hworker_thread_dispatcher.ccworker_thread_dispatcher.hshell
app
browser
test
test
@ -81,7 +81,7 @@ AlarmManager::AlarmList AlarmsFromValue(const std::string extension_id,
|
||||
Alarm alarm;
|
||||
alarm.js_alarm = alarms::Alarm::FromValue(alarm_value);
|
||||
if (alarm.js_alarm) {
|
||||
absl::optional<base::TimeDelta> delta =
|
||||
std::optional<base::TimeDelta> delta =
|
||||
base::ValueToTimeDelta(alarm_value.GetDict().Find(kAlarmGranularity));
|
||||
if (delta) {
|
||||
alarm.granularity = *delta;
|
||||
@ -334,7 +334,7 @@ void AlarmManager::WriteToStorage(const std::string& extension_id) {
|
||||
|
||||
void AlarmManager::ReadFromStorage(const std::string& extension_id,
|
||||
base::TimeDelta min_delay,
|
||||
absl::optional<base::Value> value) {
|
||||
std::optional<base::Value> value) {
|
||||
if (value && value->is_list()) {
|
||||
AlarmList alarm_states =
|
||||
AlarmsFromValue(extension_id, min_delay, value->GetList());
|
||||
|
@ -208,7 +208,7 @@ class AlarmManager : public BrowserContextKeyedAPI,
|
||||
void WriteToStorage(const std::string& extension_id);
|
||||
void ReadFromStorage(const std::string& extension_id,
|
||||
base::TimeDelta min_delay,
|
||||
absl::optional<base::Value> value);
|
||||
std::optional<base::Value> value);
|
||||
|
||||
// Set the timer to go off at the specified |time|, and set |next_poll_time|
|
||||
// appropriately.
|
||||
|
@ -104,7 +104,7 @@ AlarmsCreateFunction::AlarmsCreateFunction(base::Clock* clock)
|
||||
AlarmsCreateFunction::~AlarmsCreateFunction() = default;
|
||||
|
||||
ExtensionFunction::ResponseAction AlarmsCreateFunction::Run() {
|
||||
absl::optional<alarms::Create::Params> params =
|
||||
std::optional<alarms::Create::Params> params =
|
||||
alarms::Create::Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
@ -145,7 +145,7 @@ void AlarmsCreateFunction::Callback() {
|
||||
}
|
||||
|
||||
ExtensionFunction::ResponseAction AlarmsGetFunction::Run() {
|
||||
absl::optional<alarms::Get::Params> params =
|
||||
std::optional<alarms::Get::Params> params =
|
||||
alarms::Get::Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
@ -185,7 +185,7 @@ void AlarmsGetAllFunction::Callback(const AlarmList* alarms) {
|
||||
}
|
||||
|
||||
ExtensionFunction::ResponseAction AlarmsClearFunction::Run() {
|
||||
absl::optional<alarms::Clear::Params> params =
|
||||
std::optional<alarms::Clear::Params> params =
|
||||
alarms::Clear::Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
|
@ -9,9 +9,9 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/json/json_reader.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
@ -28,7 +28,6 @@
|
||||
#include "extensions/common/extension_messages.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
typedef extensions::api::alarms::Alarm JsAlarm;
|
||||
|
||||
@ -113,7 +112,7 @@ class ExtensionAlarmsTest : public ApiUnitTest {
|
||||
"[\"0\", {\"delayInMinutes\": 0}]",
|
||||
};
|
||||
for (size_t i = 0; i < num_alarms; ++i) {
|
||||
absl::optional<base::Value> result = RunFunctionAndReturnValue(
|
||||
std::optional<base::Value> result = RunFunctionAndReturnValue(
|
||||
new AlarmsCreateFunction(&test_clock_), kCreateArgs[i]);
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
@ -319,7 +318,7 @@ class ConsoleLogMessageLocalFrame : public content::FakeLocalFrame {
|
||||
|
||||
private:
|
||||
unsigned message_count_ = 0;
|
||||
absl::optional<blink::mojom::ConsoleMessageLevel> last_level_;
|
||||
std::optional<blink::mojom::ConsoleMessageLevel> last_level_;
|
||||
std::string last_message_;
|
||||
};
|
||||
|
||||
@ -349,7 +348,7 @@ TEST_F(ExtensionAlarmsTest, Get) {
|
||||
|
||||
// Get the default one.
|
||||
{
|
||||
absl::optional<base::Value> result =
|
||||
std::optional<base::Value> result =
|
||||
RunFunctionAndReturnValue(new AlarmsGetFunction(), "[null]");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_TRUE(result->is_dict());
|
||||
@ -362,7 +361,7 @@ TEST_F(ExtensionAlarmsTest, Get) {
|
||||
|
||||
// Get "7".
|
||||
{
|
||||
absl::optional<base::Value> result =
|
||||
std::optional<base::Value> result =
|
||||
RunFunctionAndReturnValue(new AlarmsGetFunction(), "[\"7\"]");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_TRUE(result->is_dict());
|
||||
@ -375,7 +374,7 @@ TEST_F(ExtensionAlarmsTest, Get) {
|
||||
|
||||
// Get a non-existent one.
|
||||
{
|
||||
absl::optional<base::Value> result =
|
||||
std::optional<base::Value> result =
|
||||
RunFunctionAndReturnValue(new AlarmsGetFunction(), "[\"nobody\"]");
|
||||
ASSERT_FALSE(result);
|
||||
}
|
||||
@ -384,7 +383,7 @@ TEST_F(ExtensionAlarmsTest, Get) {
|
||||
TEST_F(ExtensionAlarmsTest, GetAll) {
|
||||
// Test getAll with 0 alarms.
|
||||
{
|
||||
absl::optional<base::Value> result =
|
||||
std::optional<base::Value> result =
|
||||
RunFunctionAndReturnValue(new AlarmsGetAllFunction(), "[]");
|
||||
std::vector<JsAlarm> alarms = ToAlarmList(result);
|
||||
EXPECT_EQ(0u, alarms.size());
|
||||
@ -394,7 +393,7 @@ TEST_F(ExtensionAlarmsTest, GetAll) {
|
||||
CreateAlarms(2);
|
||||
|
||||
{
|
||||
absl::optional<base::Value> result =
|
||||
std::optional<base::Value> result =
|
||||
RunFunctionAndReturnValue(new AlarmsGetAllFunction(), "[null]");
|
||||
std::vector<JsAlarm> alarms = ToAlarmList(result);
|
||||
EXPECT_EQ(2u, alarms.size());
|
||||
@ -441,7 +440,7 @@ void ExtensionAlarmsTestClearGetAllAlarms1Callback(
|
||||
TEST_F(ExtensionAlarmsTest, Clear) {
|
||||
// Clear a non-existent one.
|
||||
{
|
||||
absl::optional<base::Value> result =
|
||||
std::optional<base::Value> result =
|
||||
RunFunctionAndReturnValue(new AlarmsClearFunction(), "[\"nobody\"]");
|
||||
ASSERT_TRUE(result->is_bool());
|
||||
EXPECT_FALSE(result->GetBool());
|
||||
@ -452,13 +451,13 @@ TEST_F(ExtensionAlarmsTest, Clear) {
|
||||
|
||||
// Clear all but the 0.001-minute alarm.
|
||||
{
|
||||
absl::optional<base::Value> result =
|
||||
std::optional<base::Value> result =
|
||||
RunFunctionAndReturnValue(new AlarmsClearFunction(), "[\"7\"]");
|
||||
ASSERT_TRUE(result->is_bool());
|
||||
EXPECT_TRUE(result->GetBool());
|
||||
}
|
||||
{
|
||||
absl::optional<base::Value> result =
|
||||
std::optional<base::Value> result =
|
||||
RunFunctionAndReturnValue(new AlarmsClearFunction(), "[\"0\"]");
|
||||
ASSERT_TRUE(result->is_bool());
|
||||
EXPECT_TRUE(result->GetBool());
|
||||
@ -490,7 +489,7 @@ void ExtensionAlarmsTestClearAllGetAllAlarms1Callback(
|
||||
TEST_F(ExtensionAlarmsTest, ClearAll) {
|
||||
// ClearAll with no alarms set.
|
||||
{
|
||||
absl::optional<base::Value> result =
|
||||
std::optional<base::Value> result =
|
||||
RunFunctionAndReturnValue(new AlarmsClearAllFunction(), "[]");
|
||||
ASSERT_TRUE(result->is_bool());
|
||||
EXPECT_TRUE(result->GetBool());
|
||||
|
@ -74,7 +74,7 @@ void GetBoundsFields(const Bounds& bounds_spec, gfx::Rect* bounds) {
|
||||
// Copy the constraint value from the API to our internal representation of
|
||||
// content size constraints. A value of zero resets the constraints. The insets
|
||||
// are used to transform window constraints to content constraints.
|
||||
void GetConstraintWidth(const absl::optional<int>& width,
|
||||
void GetConstraintWidth(const std::optional<int>& width,
|
||||
const gfx::Insets& insets,
|
||||
gfx::Size* size) {
|
||||
if (!width)
|
||||
@ -84,7 +84,7 @@ void GetConstraintWidth(const absl::optional<int>& width,
|
||||
: kUnboundedSize);
|
||||
}
|
||||
|
||||
void GetConstraintHeight(const absl::optional<int>& height,
|
||||
void GetConstraintHeight(const std::optional<int>& height,
|
||||
const gfx::Insets& insets,
|
||||
gfx::Size* size) {
|
||||
if (!height)
|
||||
@ -184,7 +184,7 @@ AppCurrentWindowInternalClearAttentionFunction::Run() {
|
||||
}
|
||||
|
||||
ExtensionFunction::ResponseAction AppCurrentWindowInternalShowFunction::Run() {
|
||||
absl::optional<Show::Params> params = Show::Params::Create(args());
|
||||
std::optional<Show::Params> params = Show::Params::Create(args());
|
||||
CHECK(params);
|
||||
if (params->focused && !*params->focused)
|
||||
window()->Show(AppWindow::SHOW_INACTIVE);
|
||||
@ -200,7 +200,7 @@ ExtensionFunction::ResponseAction AppCurrentWindowInternalHideFunction::Run() {
|
||||
|
||||
ExtensionFunction::ResponseAction
|
||||
AppCurrentWindowInternalSetBoundsFunction::Run() {
|
||||
absl::optional<SetBounds::Params> params = SetBounds::Params::Create(args());
|
||||
std::optional<SetBounds::Params> params = SetBounds::Params::Create(args());
|
||||
CHECK(params);
|
||||
|
||||
bounds::BoundsType bounds_type = bounds::GetBoundsType(params->bounds_type);
|
||||
@ -265,7 +265,7 @@ AppCurrentWindowInternalSetBoundsFunction::Run() {
|
||||
|
||||
ExtensionFunction::ResponseAction
|
||||
AppCurrentWindowInternalSetSizeConstraintsFunction::Run() {
|
||||
absl::optional<SetSizeConstraints::Params> params =
|
||||
std::optional<SetSizeConstraints::Params> params =
|
||||
SetSizeConstraints::Params::Create(args());
|
||||
CHECK(params);
|
||||
|
||||
@ -311,7 +311,7 @@ AppCurrentWindowInternalSetIconFunction::Run() {
|
||||
return RespondNow(Error(kDevChannelOnly));
|
||||
}
|
||||
|
||||
absl::optional<SetIcon::Params> params = SetIcon::Params::Create(args());
|
||||
std::optional<SetIcon::Params> params = SetIcon::Params::Create(args());
|
||||
CHECK(params);
|
||||
// The |icon_url| parameter may be a blob url (e.g. an image fetched with an
|
||||
// XMLHttpRequest) or a resource url.
|
||||
@ -328,7 +328,7 @@ AppCurrentWindowInternalSetShapeFunction::Run() {
|
||||
if (!window()->GetBaseWindow()->IsFrameless())
|
||||
return RespondNow(Error(kRequiresFramelessWindow));
|
||||
|
||||
absl::optional<SetShape::Params> params = SetShape::Params::Create(args());
|
||||
std::optional<SetShape::Params> params = SetShape::Params::Create(args());
|
||||
const Region& shape = params->region;
|
||||
|
||||
// Build the list of hit-test rects from the supplied list of rects.
|
||||
@ -358,7 +358,7 @@ AppCurrentWindowInternalSetAlwaysOnTopFunction::Run() {
|
||||
return RespondNow(Error(kAlwaysOnTopPermission));
|
||||
}
|
||||
|
||||
absl::optional<SetAlwaysOnTop::Params> params =
|
||||
std::optional<SetAlwaysOnTop::Params> params =
|
||||
SetAlwaysOnTop::Params::Create(args());
|
||||
CHECK(params);
|
||||
window()->SetAlwaysOnTop(params->always_on_top);
|
||||
@ -367,7 +367,7 @@ AppCurrentWindowInternalSetAlwaysOnTopFunction::Run() {
|
||||
|
||||
ExtensionFunction::ResponseAction
|
||||
AppCurrentWindowInternalSetVisibleOnAllWorkspacesFunction::Run() {
|
||||
absl::optional<SetVisibleOnAllWorkspaces::Params> params =
|
||||
std::optional<SetVisibleOnAllWorkspaces::Params> params =
|
||||
SetVisibleOnAllWorkspaces::Params::Create(args());
|
||||
CHECK(params);
|
||||
window()->GetBaseWindow()->SetVisibleOnAllWorkspaces(params->always_visible);
|
||||
@ -376,7 +376,7 @@ AppCurrentWindowInternalSetVisibleOnAllWorkspacesFunction::Run() {
|
||||
|
||||
ExtensionFunction::ResponseAction
|
||||
AppCurrentWindowInternalSetActivateOnPointerFunction::Run() {
|
||||
absl::optional<SetActivateOnPointer::Params> params =
|
||||
std::optional<SetActivateOnPointer::Params> params =
|
||||
SetActivateOnPointer::Params::Create(args());
|
||||
CHECK(params);
|
||||
window()->GetBaseWindow()->SetActivateOnPointer(params->activate_on_pointer);
|
||||
|
@ -174,7 +174,7 @@ void AppRuntimeEventRouter::DispatchOnLaunchedEvent(
|
||||
BrowserContext* context,
|
||||
const Extension* extension,
|
||||
extensions::AppLaunchSource source,
|
||||
absl::optional<app_runtime::LaunchData> launch_data) {
|
||||
std::optional<app_runtime::LaunchData> launch_data) {
|
||||
if (!launch_data) {
|
||||
launch_data.emplace();
|
||||
}
|
||||
@ -206,7 +206,7 @@ void AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries(
|
||||
const std::string& handler_id,
|
||||
const std::vector<EntryInfo>& entries,
|
||||
const std::vector<GrantedFileEntry>& file_entries,
|
||||
absl::optional<app_runtime::ActionData> action_data) {
|
||||
std::optional<app_runtime::ActionData> action_data) {
|
||||
app_runtime::LaunchSource source_enum = GetLaunchSourceEnum(source);
|
||||
|
||||
// TODO(sergeygs): Use the same way of creating an event (using the generated
|
||||
|
@ -5,12 +5,12 @@
|
||||
#ifndef EXTENSIONS_BROWSER_API_APP_RUNTIME_APP_RUNTIME_API_H_
|
||||
#define EXTENSIONS_BROWSER_API_APP_RUNTIME_APP_RUNTIME_API_H_
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/values.h"
|
||||
#include "extensions/common/constants.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
class GURL;
|
||||
|
||||
@ -42,7 +42,7 @@ class AppRuntimeEventRouter {
|
||||
content::BrowserContext* context,
|
||||
const Extension* extension,
|
||||
AppLaunchSource source,
|
||||
absl::optional<api::app_runtime::LaunchData> launch_data);
|
||||
std::optional<api::app_runtime::LaunchData> launch_data);
|
||||
|
||||
// Dispatches the onRestarted event to the given app, providing a list of
|
||||
// restored file entries from the previous run.
|
||||
@ -71,7 +71,7 @@ class AppRuntimeEventRouter {
|
||||
const std::string& handler_id,
|
||||
const std::vector<EntryInfo>& entries,
|
||||
const std::vector<GrantedFileEntry>& file_entries,
|
||||
absl::optional<api::app_runtime::ActionData> action_data);
|
||||
std::optional<api::app_runtime::ActionData> action_data);
|
||||
|
||||
// |handler_id| corresponds to the id of the url_handlers item
|
||||
// in the manifest that resulted in a match which triggered this launch.
|
||||
|
@ -94,8 +94,8 @@ namespace {
|
||||
|
||||
// If the same property is specified for the inner and outer bounds, raise an
|
||||
// error.
|
||||
bool CheckBoundsConflict(const absl::optional<int>& inner_property,
|
||||
const absl::optional<int>& outer_property,
|
||||
bool CheckBoundsConflict(const std::optional<int>& inner_property,
|
||||
const std::optional<int>& outer_property,
|
||||
const std::string& property_name,
|
||||
std::string* error) {
|
||||
if (inner_property && outer_property) {
|
||||
@ -143,7 +143,7 @@ ExtensionFunction::ResponseAction AppWindowCreateFunction::Run() {
|
||||
if (ExtensionsBrowserClient::Get()->IsShuttingDown())
|
||||
return RespondNow(Error(kUnknownErrorDoNotUse));
|
||||
|
||||
absl::optional<Create::Params> params = Create::Params::Create(args());
|
||||
std::optional<Create::Params> params = Create::Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
GURL url = extension()->GetResourceURL(params->url);
|
||||
@ -165,7 +165,7 @@ ExtensionFunction::ResponseAction AppWindowCreateFunction::Run() {
|
||||
// AppWindow::Create so we can set the opener at create time rather than
|
||||
// with a hack in AppWindowCustomBindings::GetView().
|
||||
AppWindow::CreateParams create_params;
|
||||
absl::optional<app_window::CreateWindowOptions>& options = params->options;
|
||||
std::optional<app_window::CreateWindowOptions>& options = params->options;
|
||||
if (options) {
|
||||
if (options->id) {
|
||||
// TODO(mek): use URL if no id specified?
|
||||
@ -473,9 +473,9 @@ bool AppWindowCreateFunction::GetBoundsSpec(
|
||||
// new API, the deprecated fields will be ignored - do not attempt to merge
|
||||
// them.
|
||||
|
||||
const absl::optional<app_window::BoundsSpecification>& inner_bounds =
|
||||
const std::optional<app_window::BoundsSpecification>& inner_bounds =
|
||||
options.inner_bounds;
|
||||
const absl::optional<app_window::BoundsSpecification>& outer_bounds =
|
||||
const std::optional<app_window::BoundsSpecification>& outer_bounds =
|
||||
options.outer_bounds;
|
||||
if (inner_bounds && outer_bounds) {
|
||||
if (!CheckBoundsConflict(inner_bounds->left, outer_bounds->left, "left",
|
||||
|
@ -108,7 +108,7 @@ void AudioAPI::OnDevicesChanged(const DeviceInfoList& devices) {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExtensionFunction::ResponseAction AudioGetDevicesFunction::Run() {
|
||||
absl::optional<audio::GetDevices::Params> params =
|
||||
std::optional<audio::GetDevices::Params> params =
|
||||
audio::GetDevices::Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
@ -137,7 +137,7 @@ void AudioGetDevicesFunction::OnResponse(
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExtensionFunction::ResponseAction AudioSetActiveDevicesFunction::Run() {
|
||||
absl::optional<audio::SetActiveDevices::Params> params =
|
||||
std::optional<audio::SetActiveDevices::Params> params =
|
||||
audio::SetActiveDevices::Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
@ -164,7 +164,7 @@ void AudioSetActiveDevicesFunction::OnResponse(bool success) {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExtensionFunction::ResponseAction AudioSetPropertiesFunction::Run() {
|
||||
absl::optional<audio::SetProperties::Params> params =
|
||||
std::optional<audio::SetProperties::Params> params =
|
||||
audio::SetProperties::Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
@ -195,7 +195,7 @@ void AudioSetPropertiesFunction::OnResponse(bool success) {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExtensionFunction::ResponseAction AudioSetMuteFunction::Run() {
|
||||
absl::optional<audio::SetMute::Params> params =
|
||||
std::optional<audio::SetMute::Params> params =
|
||||
audio::SetMute::Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
@ -222,7 +222,7 @@ void AudioSetMuteFunction::OnResponse(bool success) {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExtensionFunction::ResponseAction AudioGetMuteFunction::Run() {
|
||||
absl::optional<audio::GetMute::Params> params =
|
||||
std::optional<audio::GetMute::Params> params =
|
||||
audio::GetMute::Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
|
@ -97,7 +97,7 @@ void AudioServiceLacros::GetDevices(
|
||||
|
||||
auto crosapi_callback = base::BindOnce(
|
||||
[](base::OnceCallback<void(bool, DeviceInfoList)> extapi_callback,
|
||||
absl::optional<std::vector<crosapi::mojom::AudioDeviceInfoPtr>>
|
||||
std::optional<std::vector<crosapi::mojom::AudioDeviceInfoPtr>>
|
||||
crosapi_devices) {
|
||||
bool result_out = false;
|
||||
DeviceInfoList devices_out;
|
||||
|
@ -129,7 +129,7 @@ std::unique_ptr<api::audio::DeviceFilter> ConvertDeviceFilterFromMojom(
|
||||
auto result = std::make_unique<api::audio::DeviceFilter>();
|
||||
switch (filter->includedActiveState) {
|
||||
case crosapi::mojom::DeviceFilter::ActiveState::kUnset:
|
||||
result->is_active = absl::nullopt;
|
||||
result->is_active = std::nullopt;
|
||||
break;
|
||||
case crosapi::mojom::DeviceFilter::ActiveState::kInactive:
|
||||
result->is_active = false;
|
||||
|
@ -133,7 +133,7 @@ TEST(AudioServiceUtilsTest, ConvertDeviceFilterToMojomStreamTypes) {
|
||||
crosapi::mojom::DeviceFilterPtr result;
|
||||
auto input = std::make_unique<api::audio::DeviceFilter>();
|
||||
|
||||
input->stream_types = absl::nullopt;
|
||||
input->stream_types = std::nullopt;
|
||||
result = ConvertDeviceFilterToMojom(input.get());
|
||||
EXPECT_TRUE(result && !result->includedStreamTypes);
|
||||
|
||||
|
@ -135,7 +135,7 @@ void AutomationEventRouter::DispatchActionResult(
|
||||
|
||||
void AutomationEventRouter::DispatchGetTextLocationDataResult(
|
||||
const ui::AXActionData& data,
|
||||
const absl::optional<gfx::Rect>& rect) {
|
||||
const std::optional<gfx::Rect>& rect) {
|
||||
#if !BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
NOTREACHED_NORETURN();
|
||||
#else
|
||||
|
@ -108,7 +108,7 @@ class AutomationEventRouter
|
||||
content::BrowserContext* browser_context = nullptr) override;
|
||||
void DispatchGetTextLocationDataResult(
|
||||
const ui::AXActionData& data,
|
||||
const absl::optional<gfx::Rect>& rect) override;
|
||||
const std::optional<gfx::Rect>& rect) override;
|
||||
|
||||
// If a remote router is registered, then all events are directly forwarded to
|
||||
// it. The caller of this method is responsible for calling it again with
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef EXTENSIONS_BROWSER_API_AUTOMATION_INTERNAL_AUTOMATION_EVENT_ROUTER_INTERFACE_H_
|
||||
#define EXTENSIONS_BROWSER_API_AUTOMATION_INTERNAL_AUTOMATION_EVENT_ROUTER_INTERFACE_H_
|
||||
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
@ -12,7 +13,6 @@
|
||||
#include "extensions/common/api/automation_internal.h"
|
||||
#include "extensions/common/extension_id.h"
|
||||
#include "extensions/common/extension_messages.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace content {
|
||||
class BrowserContext;
|
||||
@ -49,7 +49,7 @@ class AutomationEventRouterInterface {
|
||||
// ax::mojom::Action::kGetTextLocation.
|
||||
virtual void DispatchGetTextLocationDataResult(
|
||||
const ui::AXActionData& data,
|
||||
const absl::optional<gfx::Rect>& rect) = 0;
|
||||
const std::optional<gfx::Rect>& rect) = 0;
|
||||
};
|
||||
|
||||
} // namespace extensions
|
||||
|
@ -460,18 +460,18 @@ class AutomationWebContentsObserver
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_IMPL(AutomationWebContentsObserver);
|
||||
|
||||
absl::optional<std::string> AutomationInternalEnableTreeFunction::EnableTree(
|
||||
std::optional<std::string> AutomationInternalEnableTreeFunction::EnableTree(
|
||||
const ui::AXTreeID& ax_tree_id,
|
||||
const ExtensionId& extension_id) {
|
||||
AutomationInternalApiDelegate* automation_api_delegate =
|
||||
ExtensionsAPIClient::Get()->GetAutomationInternalApiDelegate();
|
||||
if (automation_api_delegate->EnableTree(ax_tree_id))
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
content::RenderFrameHost* render_frame_host =
|
||||
content::RenderFrameHost::FromAXTreeID(ax_tree_id);
|
||||
if (!render_frame_host) {
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
content::WebContents* contents =
|
||||
@ -484,17 +484,17 @@ absl::optional<std::string> AutomationInternalEnableTreeFunction::EnableTree(
|
||||
contents->EnableWebContentsOnlyAccessibilityMode();
|
||||
}
|
||||
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
ExtensionFunction::ResponseAction AutomationInternalEnableTreeFunction::Run() {
|
||||
using api::automation_internal::EnableTree::Params;
|
||||
|
||||
absl::optional<Params> params = Params::Create(args());
|
||||
std::optional<Params> params = Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
ui::AXTreeID ax_tree_id = ui::AXTreeID::FromString(params->tree_id);
|
||||
absl::optional<std::string> error = EnableTree(ax_tree_id, extension_id());
|
||||
std::optional<std::string> error = EnableTree(ax_tree_id, extension_id());
|
||||
if (error) {
|
||||
return RespondNow(Error(error.value()));
|
||||
} else {
|
||||
@ -580,7 +580,7 @@ AutomationInternalPerformActionFunction::Run() {
|
||||
EXTENSION_FUNCTION_VALIDATE(automation_info && automation_info->interact);
|
||||
|
||||
using api::automation_internal::PerformAction::Params;
|
||||
absl::optional<Params> params = Params::Create(args());
|
||||
std::optional<Params> params = Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
int request_id = params->args.request_id.value_or(-1);
|
||||
|
@ -5,12 +5,12 @@
|
||||
#ifndef EXTENSIONS_BROWSER_API_AUTOMATION_INTERNAL_AUTOMATION_INTERNAL_API_H_
|
||||
#define EXTENSIONS_BROWSER_API_AUTOMATION_INTERNAL_AUTOMATION_INTERNAL_API_H_
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "content/public/browser/web_contents_user_data.h"
|
||||
#include "extensions/browser/extension_function.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace ui {
|
||||
struct AXActionData;
|
||||
@ -31,10 +31,10 @@ class AutomationInternalPerformActionFunction : public ExtensionFunction {
|
||||
~Result();
|
||||
// If there is a validation error then |automation_error| should be ignored.
|
||||
bool validation_success = false;
|
||||
// Assuming validation was successful, then a value of absl::nullopt
|
||||
// Assuming validation was successful, then a value of std::nullopt
|
||||
// implies success. Otherwise, the failure is described in the contained
|
||||
// string.
|
||||
absl::optional<std::string> automation_error;
|
||||
std::optional<std::string> automation_error;
|
||||
};
|
||||
|
||||
// Exposed to allow crosapi to reuse the implementation. |extension_id| can be
|
||||
@ -56,12 +56,11 @@ class AutomationInternalEnableTreeFunction : public ExtensionFunction {
|
||||
AUTOMATIONINTERNAL_ENABLETREE)
|
||||
|
||||
public:
|
||||
// Returns an error message or absl::nullopt on success. Exposed to allow
|
||||
// Returns an error message or std::nullopt on success. Exposed to allow
|
||||
// crosapi to reuse the implementation. |extension_id| can be the empty
|
||||
// string.
|
||||
static absl::optional<std::string> EnableTree(
|
||||
const ui::AXTreeID& ax_tree_id,
|
||||
const ExtensionId& extension_id);
|
||||
static std::optional<std::string> EnableTree(const ui::AXTreeID& ax_tree_id,
|
||||
const ExtensionId& extension_id);
|
||||
|
||||
protected:
|
||||
~AutomationInternalEnableTreeFunction() override = default;
|
||||
|
@ -100,7 +100,7 @@ class BluetoothGetDevicesFunction : public BluetoothExtensionFunction {
|
||||
void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
|
||||
|
||||
private:
|
||||
absl::optional<bluetooth::GetDevices::Params> params_;
|
||||
std::optional<bluetooth::GetDevices::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothGetDeviceFunction : public BluetoothExtensionFunction {
|
||||
@ -121,7 +121,7 @@ class BluetoothGetDeviceFunction : public BluetoothExtensionFunction {
|
||||
~BluetoothGetDeviceFunction() override;
|
||||
|
||||
private:
|
||||
absl::optional<extensions::api::bluetooth::GetDevice::Params> params_;
|
||||
std::optional<extensions::api::bluetooth::GetDevice::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothStartDiscoveryFunction : public BluetoothExtensionFunction {
|
||||
|
@ -163,7 +163,7 @@ void BluetoothDeviceToApiDevice(const device::BluetoothDevice& device,
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
absl::optional<device::BluetoothDevice::BatteryInfo> battery_info =
|
||||
std::optional<device::BluetoothDevice::BatteryInfo> battery_info =
|
||||
device.GetBatteryInfo(device::BluetoothDevice::BatteryType::kDefault);
|
||||
|
||||
if (battery_info && battery_info->percentage.has_value())
|
||||
|
@ -151,7 +151,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetAdapterState) {
|
||||
scoped_refptr<api::BluetoothGetAdapterStateFunction> get_adapter_state;
|
||||
get_adapter_state = setupFunction(new api::BluetoothGetAdapterStateFunction);
|
||||
|
||||
absl::optional<base::Value> result = utils::RunFunctionAndReturnSingleResult(
|
||||
std::optional<base::Value> result = utils::RunFunctionAndReturnSingleResult(
|
||||
get_adapter_state.get(), "[]", browser()->profile());
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_TRUE(result->is_dict());
|
||||
@ -179,7 +179,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DeviceEvents) {
|
||||
|
||||
EXPECT_CALL(*device2_, GetName())
|
||||
.WillRepeatedly(
|
||||
testing::Return(absl::optional<std::string>("the real d2")));
|
||||
testing::Return(std::optional<std::string>("the real d2")));
|
||||
EXPECT_CALL(*device2_, GetNameForDisplay())
|
||||
.WillRepeatedly(testing::Return(u"the real d2"));
|
||||
event_router()->DeviceChanged(mock_adapter_, device2_.get());
|
||||
@ -408,7 +408,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DeviceInfo) {
|
||||
.WillRepeatedly(testing::Return("A4:17:31:00:00:00"));
|
||||
EXPECT_CALL(*device1_, GetName())
|
||||
.WillRepeatedly(
|
||||
testing::Return(absl::optional<std::string>("Chromebook Pixel")));
|
||||
testing::Return(std::optional<std::string>("Chromebook Pixel")));
|
||||
EXPECT_CALL(*device1_, GetNameForDisplay())
|
||||
.WillRepeatedly(testing::Return(u"Chromebook Pixel"));
|
||||
EXPECT_CALL(*device1_, GetBluetoothClass())
|
||||
|
@ -70,7 +70,7 @@ bool IsActualConnectionFailure(bt_private::ConnectResultType result) {
|
||||
}
|
||||
}
|
||||
|
||||
absl::optional<device::ConnectionFailureReason> GetConnectionFailureReason(
|
||||
std::optional<device::ConnectionFailureReason> GetConnectionFailureReason(
|
||||
bt_private::ConnectResultType result) {
|
||||
DCHECK(IsActualConnectionFailure(result));
|
||||
|
||||
@ -612,7 +612,7 @@ void BluetoothPrivateConnectFunction::DoWork(
|
||||
}
|
||||
|
||||
void BluetoothPrivateConnectFunction::OnConnect(
|
||||
absl::optional<device::BluetoothDevice::ConnectErrorCode> error_code) {
|
||||
std::optional<device::BluetoothDevice::ConnectErrorCode> error_code) {
|
||||
if (error_code.has_value()) {
|
||||
// Set the result type and respond with true (success).
|
||||
Respond(ArgumentList(bt_private::Connect::Results::Create(
|
||||
@ -658,7 +658,7 @@ void BluetoothPrivatePairFunction::DoWork(
|
||||
}
|
||||
|
||||
void BluetoothPrivatePairFunction::OnPair(
|
||||
absl::optional<device::BluetoothDevice::ConnectErrorCode> error_code) {
|
||||
std::optional<device::BluetoothDevice::ConnectErrorCode> error_code) {
|
||||
if (error_code.has_value()) {
|
||||
Respond(Error(kPairingFailed));
|
||||
return;
|
||||
@ -688,7 +688,7 @@ void BluetoothPrivateRecordPairingFunction::DoWork(
|
||||
// Only emit metrics if this is a success or a true connection failure.
|
||||
if (success || IsActualConnectionFailure(result)) {
|
||||
device::RecordPairingResult(
|
||||
success ? absl::nullopt : GetConnectionFailureReason(result),
|
||||
success ? std::nullopt : GetConnectionFailureReason(result),
|
||||
GetBluetoothTransport(params_->transport),
|
||||
base::Milliseconds(params_->pairing_duration_ms));
|
||||
}
|
||||
@ -719,7 +719,7 @@ void BluetoothPrivateRecordReconnectionFunction::DoWork(
|
||||
// Only emit metrics if this is a success or a true connection failure.
|
||||
if (success || IsActualConnectionFailure(result)) {
|
||||
device::RecordUserInitiatedReconnectionAttemptResult(
|
||||
success ? absl::nullopt : GetConnectionFailureReason(result),
|
||||
success ? std::nullopt : GetConnectionFailureReason(result),
|
||||
device::UserInitiatedReconnectionUISurfaces::kSettings);
|
||||
}
|
||||
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef EXTENSIONS_BROWSER_API_BLUETOOTH_BLUETOOTH_PRIVATE_API_H_
|
||||
#define EXTENSIONS_BROWSER_API_BLUETOOTH_BLUETOOTH_PRIVATE_API_H_
|
||||
|
||||
#include <optional>
|
||||
#include "base/functional/callback_forward.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "device/bluetooth/bluetooth_device.h"
|
||||
@ -12,7 +13,6 @@
|
||||
#include "extensions/browser/browser_context_keyed_api_factory.h"
|
||||
#include "extensions/browser/event_router.h"
|
||||
#include "extensions/common/api/bluetooth_private.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace device {
|
||||
class BluetoothAdapter;
|
||||
@ -119,7 +119,7 @@ class BluetoothPrivateSetAdapterStateFunction
|
||||
// up state requests.
|
||||
bool parsed_ = false;
|
||||
|
||||
absl::optional<bluetooth_private::SetAdapterState::Params> params_;
|
||||
std::optional<bluetooth_private::SetAdapterState::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothPrivateSetPairingResponseFunction
|
||||
@ -141,7 +141,7 @@ class BluetoothPrivateSetPairingResponseFunction
|
||||
private:
|
||||
~BluetoothPrivateSetPairingResponseFunction() override;
|
||||
|
||||
absl::optional<bluetooth_private::SetPairingResponse::Params> params_;
|
||||
std::optional<bluetooth_private::SetPairingResponse::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothPrivateDisconnectAllFunction
|
||||
@ -167,7 +167,7 @@ class BluetoothPrivateDisconnectAllFunction
|
||||
void OnErrorCallback(scoped_refptr<device::BluetoothAdapter> adapter,
|
||||
const std::string& device_address);
|
||||
|
||||
absl::optional<bluetooth_private::DisconnectAll::Params> params_;
|
||||
std::optional<bluetooth_private::DisconnectAll::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothPrivateForgetDeviceFunction : public BluetoothExtensionFunction {
|
||||
@ -192,7 +192,7 @@ class BluetoothPrivateForgetDeviceFunction : public BluetoothExtensionFunction {
|
||||
void OnErrorCallback(scoped_refptr<device::BluetoothAdapter> adapter,
|
||||
const std::string& device_address);
|
||||
|
||||
absl::optional<bluetooth_private::ForgetDevice::Params> params_;
|
||||
std::optional<bluetooth_private::ForgetDevice::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothPrivateSetDiscoveryFilterFunction
|
||||
@ -218,7 +218,7 @@ class BluetoothPrivateSetDiscoveryFilterFunction
|
||||
void OnSuccessCallback();
|
||||
void OnErrorCallback();
|
||||
|
||||
absl::optional<bluetooth_private::SetDiscoveryFilter::Params> params_;
|
||||
std::optional<bluetooth_private::SetDiscoveryFilter::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothPrivateConnectFunction : public BluetoothExtensionFunction {
|
||||
@ -240,9 +240,9 @@ class BluetoothPrivateConnectFunction : public BluetoothExtensionFunction {
|
||||
~BluetoothPrivateConnectFunction() override;
|
||||
|
||||
void OnConnect(
|
||||
absl::optional<device::BluetoothDevice::ConnectErrorCode> error);
|
||||
std::optional<device::BluetoothDevice::ConnectErrorCode> error);
|
||||
|
||||
absl::optional<bluetooth_private::Connect::Params> params_;
|
||||
std::optional<bluetooth_private::Connect::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothPrivatePairFunction : public BluetoothExtensionFunction {
|
||||
@ -262,9 +262,9 @@ class BluetoothPrivatePairFunction : public BluetoothExtensionFunction {
|
||||
~BluetoothPrivatePairFunction() override;
|
||||
|
||||
void OnPair(
|
||||
absl::optional<device::BluetoothDevice::ConnectErrorCode> error_code);
|
||||
std::optional<device::BluetoothDevice::ConnectErrorCode> error_code);
|
||||
|
||||
absl::optional<bluetooth_private::Pair::Params> params_;
|
||||
std::optional<bluetooth_private::Pair::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothPrivateRecordPairingFunction
|
||||
@ -288,7 +288,7 @@ class BluetoothPrivateRecordPairingFunction
|
||||
void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
|
||||
|
||||
private:
|
||||
absl::optional<bluetooth_private::RecordPairing::Params> params_;
|
||||
std::optional<bluetooth_private::RecordPairing::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothPrivateRecordReconnectionFunction
|
||||
@ -312,7 +312,7 @@ class BluetoothPrivateRecordReconnectionFunction
|
||||
void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
|
||||
|
||||
private:
|
||||
absl::optional<bluetooth_private::RecordReconnection::Params> params_;
|
||||
std::optional<bluetooth_private::RecordReconnection::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothPrivateRecordDeviceSelectionFunction
|
||||
@ -336,7 +336,7 @@ class BluetoothPrivateRecordDeviceSelectionFunction
|
||||
void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
|
||||
|
||||
private:
|
||||
absl::optional<bluetooth_private::RecordDeviceSelection::Params> params_;
|
||||
std::optional<bluetooth_private::RecordDeviceSelection::Params> params_;
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
|
@ -292,7 +292,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, Connect) {
|
||||
.WillOnce(Return(false))
|
||||
.WillOnce(Return(true));
|
||||
EXPECT_CALL(*mock_device_, Connect(_, _))
|
||||
.WillOnce(RunOnceCallback<1>(/*error_code=*/absl::nullopt));
|
||||
.WillOnce(RunOnceCallback<1>(/*error_code=*/std::nullopt));
|
||||
ASSERT_TRUE(RunExtensionTest("bluetooth_private/connect", {},
|
||||
{.load_as_component = true}))
|
||||
<< message_;
|
||||
@ -309,7 +309,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, Pair) {
|
||||
WithoutArgs(Invoke(
|
||||
this,
|
||||
&BluetoothPrivateApiTest::DispatchConfirmPasskeyPairingEvent)),
|
||||
RunOnceCallback<1>(/*error_code=*/absl::nullopt)));
|
||||
RunOnceCallback<1>(/*error_code=*/std::nullopt)));
|
||||
ASSERT_TRUE(RunExtensionTest("bluetooth_private/pair", {},
|
||||
{.load_as_component = true}))
|
||||
<< message_;
|
||||
|
@ -6,9 +6,9 @@
|
||||
#define EXTENSIONS_BROWSER_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_API_H_
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "build/build_config.h"
|
||||
@ -21,7 +21,6 @@
|
||||
#include "extensions/browser/extension_function.h"
|
||||
#include "extensions/browser/extension_function_histogram_value.h"
|
||||
#include "extensions/common/api/bluetooth_low_energy.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace extensions {
|
||||
class BluetoothApiAdvertisement;
|
||||
@ -142,7 +141,7 @@ class BluetoothLowEnergyConnectFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::Connect::Params> params_;
|
||||
std::optional<bluetooth_low_energy::Connect::Params> params_;
|
||||
|
||||
private:
|
||||
void ConnectCallback(BluetoothLowEnergyEventRouter::Status status);
|
||||
@ -163,7 +162,7 @@ class BluetoothLowEnergyDisconnectFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::Disconnect::Params> params_;
|
||||
std::optional<bluetooth_low_energy::Disconnect::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothLowEnergyGetServiceFunction
|
||||
@ -181,7 +180,7 @@ class BluetoothLowEnergyGetServiceFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::GetService::Params> params_;
|
||||
std::optional<bluetooth_low_energy::GetService::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothLowEnergyGetServicesFunction
|
||||
@ -199,7 +198,7 @@ class BluetoothLowEnergyGetServicesFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::GetServices::Params> params_;
|
||||
std::optional<bluetooth_low_energy::GetServices::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothLowEnergyGetCharacteristicFunction
|
||||
@ -217,7 +216,7 @@ class BluetoothLowEnergyGetCharacteristicFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::GetCharacteristic::Params> params_;
|
||||
std::optional<bluetooth_low_energy::GetCharacteristic::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothLowEnergyGetCharacteristicsFunction
|
||||
@ -235,7 +234,7 @@ class BluetoothLowEnergyGetCharacteristicsFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::GetCharacteristics::Params> params_;
|
||||
std::optional<bluetooth_low_energy::GetCharacteristics::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothLowEnergyGetIncludedServicesFunction
|
||||
@ -253,7 +252,7 @@ class BluetoothLowEnergyGetIncludedServicesFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::GetIncludedServices::Params> params_;
|
||||
std::optional<bluetooth_low_energy::GetIncludedServices::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothLowEnergyGetDescriptorFunction
|
||||
@ -271,7 +270,7 @@ class BluetoothLowEnergyGetDescriptorFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::GetDescriptor::Params> params_;
|
||||
std::optional<bluetooth_low_energy::GetDescriptor::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothLowEnergyGetDescriptorsFunction
|
||||
@ -289,7 +288,7 @@ class BluetoothLowEnergyGetDescriptorsFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::GetDescriptors::Params> params_;
|
||||
std::optional<bluetooth_low_energy::GetDescriptors::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothLowEnergyReadCharacteristicValueFunction
|
||||
@ -307,7 +306,7 @@ class BluetoothLowEnergyReadCharacteristicValueFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::ReadCharacteristicValue::Params> params_;
|
||||
std::optional<bluetooth_low_energy::ReadCharacteristicValue::Params> params_;
|
||||
|
||||
private:
|
||||
// Success callback, called by
|
||||
@ -333,8 +332,7 @@ class BluetoothLowEnergyWriteCharacteristicValueFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::WriteCharacteristicValue::Params>
|
||||
params_;
|
||||
std::optional<bluetooth_low_energy::WriteCharacteristicValue::Params> params_;
|
||||
|
||||
private:
|
||||
// Success callback, called by
|
||||
@ -361,7 +359,7 @@ class BluetoothLowEnergyStartCharacteristicNotificationsFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::StartCharacteristicNotifications::Params>
|
||||
std::optional<bluetooth_low_energy::StartCharacteristicNotifications::Params>
|
||||
params_;
|
||||
};
|
||||
|
||||
@ -381,7 +379,7 @@ class BluetoothLowEnergyStopCharacteristicNotificationsFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::StopCharacteristicNotifications::Params>
|
||||
std::optional<bluetooth_low_energy::StopCharacteristicNotifications::Params>
|
||||
params_;
|
||||
};
|
||||
|
||||
@ -400,7 +398,7 @@ class BluetoothLowEnergyReadDescriptorValueFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::ReadDescriptorValue::Params> params_;
|
||||
std::optional<bluetooth_low_energy::ReadDescriptorValue::Params> params_;
|
||||
|
||||
private:
|
||||
// Success callback, called by
|
||||
@ -426,7 +424,7 @@ class BluetoothLowEnergyWriteDescriptorValueFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::WriteDescriptorValue::Params> params_;
|
||||
std::optional<bluetooth_low_energy::WriteDescriptorValue::Params> params_;
|
||||
|
||||
private:
|
||||
// Success callback, called by
|
||||
@ -481,7 +479,7 @@ class BluetoothLowEnergyRegisterAdvertisementFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::RegisterAdvertisement::Params> params_;
|
||||
std::optional<bluetooth_low_energy::RegisterAdvertisement::Params> params_;
|
||||
|
||||
private:
|
||||
void SuccessCallback(scoped_refptr<device::BluetoothAdvertisement>);
|
||||
@ -503,7 +501,7 @@ class BluetoothLowEnergyUnregisterAdvertisementFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::UnregisterAdvertisement::Params> params_;
|
||||
std::optional<bluetooth_low_energy::UnregisterAdvertisement::Params> params_;
|
||||
|
||||
private:
|
||||
void SuccessCallback(int advertisement_id);
|
||||
@ -545,7 +543,7 @@ class BluetoothLowEnergySetAdvertisingIntervalFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::SetAdvertisingInterval::Params> params_;
|
||||
std::optional<bluetooth_low_energy::SetAdvertisingInterval::Params> params_;
|
||||
|
||||
private:
|
||||
void ErrorCallback(device::BluetoothAdvertisement::ErrorCode status);
|
||||
@ -568,7 +566,7 @@ class BluetoothLowEnergyCreateServiceFunction
|
||||
|
||||
// Causes link error on Windows. API will never be on Windows, so #ifdefing.
|
||||
#if !BUILDFLAG(IS_WIN)
|
||||
absl::optional<bluetooth_low_energy::CreateService::Params> params_;
|
||||
std::optional<bluetooth_low_energy::CreateService::Params> params_;
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -587,7 +585,7 @@ class BluetoothLowEnergyCreateCharacteristicFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::CreateCharacteristic::Params> params_;
|
||||
std::optional<bluetooth_low_energy::CreateCharacteristic::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothLowEnergyNotifyCharacteristicValueChangedFunction
|
||||
@ -606,7 +604,7 @@ class BluetoothLowEnergyNotifyCharacteristicValueChangedFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::NotifyCharacteristicValueChanged::Params>
|
||||
std::optional<bluetooth_low_energy::NotifyCharacteristicValueChanged::Params>
|
||||
params_;
|
||||
};
|
||||
|
||||
@ -625,7 +623,7 @@ class BluetoothLowEnergyCreateDescriptorFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::CreateDescriptor::Params> params_;
|
||||
std::optional<bluetooth_low_energy::CreateDescriptor::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothLowEnergyRegisterServiceFunction
|
||||
@ -643,7 +641,7 @@ class BluetoothLowEnergyRegisterServiceFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::RegisterService::Params> params_;
|
||||
std::optional<bluetooth_low_energy::RegisterService::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothLowEnergyUnregisterServiceFunction
|
||||
@ -661,7 +659,7 @@ class BluetoothLowEnergyUnregisterServiceFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::UnregisterService::Params> params_;
|
||||
std::optional<bluetooth_low_energy::UnregisterService::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothLowEnergyRemoveServiceFunction
|
||||
@ -679,7 +677,7 @@ class BluetoothLowEnergyRemoveServiceFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::RemoveService::Params> params_;
|
||||
std::optional<bluetooth_low_energy::RemoveService::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothLowEnergySendRequestResponseFunction
|
||||
@ -697,7 +695,7 @@ class BluetoothLowEnergySendRequestResponseFunction
|
||||
void DoWork() override;
|
||||
bool ParseParams() override;
|
||||
|
||||
absl::optional<bluetooth_low_energy::SendRequestResponse::Params> params_;
|
||||
std::optional<bluetooth_low_energy::SendRequestResponse::Params> params_;
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
|
@ -408,19 +408,19 @@ void BluetoothLowEnergyEventRouter::Disconnect(
|
||||
std::move(callback).Run();
|
||||
}
|
||||
|
||||
absl::optional<BluetoothLowEnergyEventRouter::ServiceList>
|
||||
std::optional<BluetoothLowEnergyEventRouter::ServiceList>
|
||||
BluetoothLowEnergyEventRouter::GetServices(
|
||||
const std::string& device_address) const {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
if (!adapter_.get()) {
|
||||
VLOG(1) << "BluetoothAdapter not ready.";
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
BluetoothDevice* device = adapter_->GetDevice(device_address);
|
||||
if (!device) {
|
||||
VLOG(1) << "Bluetooth device not found: " << device_address;
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
ServiceList list;
|
||||
@ -1384,7 +1384,7 @@ void BluetoothLowEnergyEventRouter::HandleRequestResponse(
|
||||
}
|
||||
|
||||
if (request->type == AttributeValueRequest::ATTRIBUTE_READ_REQUEST) {
|
||||
std::move(request->value_callback).Run(/*error_code=*/absl::nullopt, value);
|
||||
std::move(request->value_callback).Run(/*error_code=*/std::nullopt, value);
|
||||
} else {
|
||||
std::move(request->success_callback).Run();
|
||||
}
|
||||
@ -1604,7 +1604,7 @@ void BluetoothLowEnergyEventRouter::OnReadRemoteCharacteristic(
|
||||
const std::string& characteristic_instance_id,
|
||||
base::OnceClosure callback,
|
||||
ErrorCallback error_callback,
|
||||
absl::optional<BluetoothGattService::GattErrorCode> error_code,
|
||||
std::optional<BluetoothGattService::GattErrorCode> error_code,
|
||||
const std::vector<uint8_t>& value) {
|
||||
if (error_code.has_value()) {
|
||||
VLOG(2) << "Remote characteristic value read failed.";
|
||||
@ -1623,7 +1623,7 @@ void BluetoothLowEnergyEventRouter::OnReadRemoteCharacteristic(
|
||||
void BluetoothLowEnergyEventRouter::OnReadRemoteDescriptor(
|
||||
base::OnceClosure callback,
|
||||
ErrorCallback error_callback,
|
||||
absl::optional<device::BluetoothGattService::GattErrorCode> error_code,
|
||||
std::optional<device::BluetoothGattService::GattErrorCode> error_code,
|
||||
const std::vector<uint8_t>& value) {
|
||||
if (error_code.has_value()) {
|
||||
VLOG(2) << "Remote characteristic/descriptor value read failed.";
|
||||
@ -1660,7 +1660,7 @@ void BluetoothLowEnergyEventRouter::OnCreateGattConnection(
|
||||
const std::string& device_address,
|
||||
ErrorCallback callback,
|
||||
std::unique_ptr<BluetoothGattConnection> connection,
|
||||
absl::optional<BluetoothDevice::ConnectErrorCode> error_code) {
|
||||
std::optional<BluetoothDevice::ConnectErrorCode> error_code) {
|
||||
if (error_code.has_value()) {
|
||||
VLOG(2) << "Failed to create GATT connection: " << error_code.value();
|
||||
|
||||
|
@ -8,10 +8,10 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/functional/callback_forward.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
@ -31,7 +31,6 @@
|
||||
#include "extensions/browser/extension_registry.h"
|
||||
#include "extensions/browser/extension_registry_observer.h"
|
||||
#include "extensions/common/api/bluetooth_low_energy.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
@ -155,11 +154,11 @@ class BluetoothLowEnergyEventRouter
|
||||
|
||||
// Returns the list of api::bluetooth_low_energy::Service objects
|
||||
// associated with the Bluetooth device with address |device_address| if
|
||||
// successful. Otherwise returns absl::nullopt, if no device with the given
|
||||
// successful. Otherwise returns std::nullopt, if no device with the given
|
||||
// address is known. If the device is found but it has no GATT services, then
|
||||
// returns an empty list.
|
||||
typedef std::vector<api::bluetooth_low_energy::Service> ServiceList;
|
||||
absl::optional<ServiceList> GetServices(
|
||||
std::optional<ServiceList> GetServices(
|
||||
const std::string& device_address) const;
|
||||
|
||||
// Returns a service based on GATT service with instance ID |instance_id| if
|
||||
@ -431,14 +430,14 @@ class BluetoothLowEnergyEventRouter
|
||||
const std::string& characteristic_instance_id,
|
||||
base::OnceClosure callback,
|
||||
ErrorCallback error_callback,
|
||||
absl::optional<device::BluetoothGattService::GattErrorCode> error_code,
|
||||
std::optional<device::BluetoothGattService::GattErrorCode> error_code,
|
||||
const std::vector<uint8_t>& value);
|
||||
|
||||
// Runs |callback|.
|
||||
void OnReadRemoteDescriptor(
|
||||
base::OnceClosure callback,
|
||||
ErrorCallback error_callback,
|
||||
absl::optional<device::BluetoothGattService::GattErrorCode> error_code,
|
||||
std::optional<device::BluetoothGattService::GattErrorCode> error_code,
|
||||
const std::vector<uint8_t>& value);
|
||||
|
||||
// Called by BluetoothDevice in response to a call to CreateGattConnection.
|
||||
@ -448,7 +447,7 @@ class BluetoothLowEnergyEventRouter
|
||||
const std::string& device_address,
|
||||
ErrorCallback callback,
|
||||
std::unique_ptr<device::BluetoothGattConnection> connection,
|
||||
absl::optional<device::BluetoothDevice::ConnectErrorCode> error_code);
|
||||
std::optional<device::BluetoothDevice::ConnectErrorCode> error_code);
|
||||
|
||||
// Called by BluetoothGattService in response to Register().
|
||||
void OnRegisterGattServiceSuccess(const std::string& service_id,
|
||||
|
@ -280,7 +280,7 @@ void BluetoothSocketListenFunction::OnGetAdapter(
|
||||
return;
|
||||
}
|
||||
|
||||
absl::optional<std::string> name;
|
||||
std::optional<std::string> name;
|
||||
if (socket->name())
|
||||
name = *socket->name();
|
||||
|
||||
@ -338,13 +338,13 @@ bool BluetoothSocketListenUsingRfcommFunction::CreateParams() {
|
||||
void BluetoothSocketListenUsingRfcommFunction::CreateService(
|
||||
scoped_refptr<device::BluetoothAdapter> adapter,
|
||||
const device::BluetoothUUID& uuid,
|
||||
const absl::optional<std::string>& name,
|
||||
const std::optional<std::string>& name,
|
||||
device::BluetoothAdapter::CreateServiceCallback callback,
|
||||
device::BluetoothAdapter::CreateServiceErrorCallback error_callback) {
|
||||
device::BluetoothAdapter::ServiceOptions service_options;
|
||||
service_options.name = std::move(name);
|
||||
|
||||
const absl::optional<ListenOptions>& options = params_->options;
|
||||
const std::optional<ListenOptions>& options = params_->options;
|
||||
if (options && options->channel)
|
||||
service_options.channel = *options->channel;
|
||||
|
||||
@ -378,13 +378,13 @@ bool BluetoothSocketListenUsingL2capFunction::CreateParams() {
|
||||
void BluetoothSocketListenUsingL2capFunction::CreateService(
|
||||
scoped_refptr<device::BluetoothAdapter> adapter,
|
||||
const device::BluetoothUUID& uuid,
|
||||
const absl::optional<std::string>& name,
|
||||
const std::optional<std::string>& name,
|
||||
device::BluetoothAdapter::CreateServiceCallback callback,
|
||||
device::BluetoothAdapter::CreateServiceErrorCallback error_callback) {
|
||||
device::BluetoothAdapter::ServiceOptions service_options;
|
||||
service_options.name = std::move(name);
|
||||
|
||||
const absl::optional<ListenOptions>& options = params_->options;
|
||||
const std::optional<ListenOptions>& options = params_->options;
|
||||
if (options && options->psm) {
|
||||
int psm = *options->psm;
|
||||
if (!IsValidPsm(psm)) {
|
||||
|
@ -7,10 +7,10 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "base/values.h"
|
||||
@ -21,7 +21,6 @@
|
||||
#include "extensions/browser/extension_function.h"
|
||||
#include "extensions/browser/extension_function_histogram_value.h"
|
||||
#include "extensions/common/api/bluetooth_socket.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace device {
|
||||
class BluetoothSocket;
|
||||
@ -123,7 +122,7 @@ class BluetoothSocketListenFunction : public BluetoothSocketAsyncApiFunction {
|
||||
virtual void CreateService(
|
||||
scoped_refptr<device::BluetoothAdapter> adapter,
|
||||
const device::BluetoothUUID& uuid,
|
||||
const absl::optional<std::string>& name,
|
||||
const std::optional<std::string>& name,
|
||||
device::BluetoothAdapter::CreateServiceCallback callback,
|
||||
device::BluetoothAdapter::CreateServiceErrorCallback error_callback) = 0;
|
||||
virtual base::Value::List CreateResults() = 0;
|
||||
@ -160,7 +159,7 @@ class BluetoothSocketListenUsingRfcommFunction
|
||||
bool CreateParams() override;
|
||||
void CreateService(scoped_refptr<device::BluetoothAdapter> adapter,
|
||||
const device::BluetoothUUID& uuid,
|
||||
const absl::optional<std::string>& name,
|
||||
const std::optional<std::string>& name,
|
||||
device::BluetoothAdapter::CreateServiceCallback callback,
|
||||
device::BluetoothAdapter::CreateServiceErrorCallback
|
||||
error_callback) override;
|
||||
@ -170,7 +169,7 @@ class BluetoothSocketListenUsingRfcommFunction
|
||||
~BluetoothSocketListenUsingRfcommFunction() override;
|
||||
|
||||
private:
|
||||
absl::optional<bluetooth_socket::ListenUsingRfcomm::Params> params_;
|
||||
std::optional<bluetooth_socket::ListenUsingRfcomm::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothSocketListenUsingL2capFunction
|
||||
@ -188,7 +187,7 @@ class BluetoothSocketListenUsingL2capFunction
|
||||
bool CreateParams() override;
|
||||
void CreateService(scoped_refptr<device::BluetoothAdapter> adapter,
|
||||
const device::BluetoothUUID& uuid,
|
||||
const absl::optional<std::string>& name,
|
||||
const std::optional<std::string>& name,
|
||||
device::BluetoothAdapter::CreateServiceCallback callback,
|
||||
device::BluetoothAdapter::CreateServiceErrorCallback
|
||||
error_callback) override;
|
||||
@ -198,7 +197,7 @@ class BluetoothSocketListenUsingL2capFunction
|
||||
~BluetoothSocketListenUsingL2capFunction() override;
|
||||
|
||||
private:
|
||||
absl::optional<bluetooth_socket::ListenUsingL2cap::Params> params_;
|
||||
std::optional<bluetooth_socket::ListenUsingL2cap::Params> params_;
|
||||
};
|
||||
|
||||
class BluetoothSocketAbstractConnectFunction :
|
||||
@ -224,7 +223,7 @@ class BluetoothSocketAbstractConnectFunction :
|
||||
private:
|
||||
virtual void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter);
|
||||
|
||||
absl::optional<bluetooth_socket::Connect::Params> params_;
|
||||
std::optional<bluetooth_socket::Connect::Params> params_;
|
||||
raw_ptr<BluetoothSocketEventDispatcher> socket_event_dispatcher_ = nullptr;
|
||||
};
|
||||
|
||||
@ -304,7 +303,7 @@ class BluetoothSocketSendFunction : public BluetoothSocketAsyncApiFunction {
|
||||
void OnError(BluetoothApiSocket::ErrorReason reason,
|
||||
const std::string& message);
|
||||
|
||||
absl::optional<bluetooth_socket::Send::Params> params_;
|
||||
std::optional<bluetooth_socket::Send::Params> params_;
|
||||
scoped_refptr<net::IOBuffer> io_buffer_;
|
||||
size_t io_buffer_size_;
|
||||
};
|
||||
|
@ -63,7 +63,7 @@ TEST_F(BluetoothSocketApiUnittest, MAYBE_CreateThenClose) {
|
||||
|
||||
auto create_function =
|
||||
base::MakeRefCounted<api::BluetoothSocketCreateFunction>();
|
||||
absl::optional<base::Value> result =
|
||||
std::optional<base::Value> result =
|
||||
RunFunctionAndReturnValue(create_function.get(), "[]");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_TRUE(result->is_dict());
|
||||
|
@ -51,7 +51,7 @@ void ClipboardAPI::OnClipboardDataChanged() {
|
||||
ClipboardSetImageDataFunction::~ClipboardSetImageDataFunction() = default;
|
||||
|
||||
ExtensionFunction::ResponseAction ClipboardSetImageDataFunction::Run() {
|
||||
absl::optional<clipboard::SetImageData::Params> params =
|
||||
std::optional<clipboard::SetImageData::Params> params =
|
||||
clipboard::SetImageData::Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
|
@ -5,13 +5,12 @@
|
||||
#ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_DECLARATIVE_API_H_
|
||||
#define EXTENSIONS_BROWSER_API_DECLARATIVE_DECLARATIVE_API_H_
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "extensions/browser/api/declarative/rules_registry.h"
|
||||
#include "extensions/browser/extension_function.h"
|
||||
#include "extensions/common/api/events.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace extensions {
|
||||
|
||||
@ -61,7 +60,7 @@ class EventsEventAddRulesFunction : public RulesFunction {
|
||||
void RecordUMA(const std::string& event_name) const override;
|
||||
|
||||
private:
|
||||
absl::optional<api::events::Event::AddRules::Params> params_;
|
||||
std::optional<api::events::Event::AddRules::Params> params_;
|
||||
};
|
||||
|
||||
class EventsEventRemoveRulesFunction : public RulesFunction {
|
||||
@ -79,7 +78,7 @@ class EventsEventRemoveRulesFunction : public RulesFunction {
|
||||
void RecordUMA(const std::string& event_name) const override;
|
||||
|
||||
private:
|
||||
absl::optional<api::events::Event::RemoveRules::Params> params_;
|
||||
std::optional<api::events::Event::RemoveRules::Params> params_;
|
||||
};
|
||||
|
||||
class EventsEventGetRulesFunction : public RulesFunction {
|
||||
@ -97,7 +96,7 @@ class EventsEventGetRulesFunction : public RulesFunction {
|
||||
void RecordUMA(const std::string& event_name) const override;
|
||||
|
||||
private:
|
||||
absl::optional<api::events::Event::GetRules::Params> params_;
|
||||
std::optional<api::events::Event::GetRules::Params> params_;
|
||||
};
|
||||
|
||||
} // namespace extensions
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "extensions/browser/api/declarative/declarative_rule.h"
|
||||
|
||||
#include <optional>
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
@ -14,7 +15,6 @@
|
||||
#include "extensions/common/extension_builder.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
using base::test::ParseJson;
|
||||
using base::test::ParseJsonDict;
|
||||
@ -141,7 +141,7 @@ struct FulfillableCondition {
|
||||
result->condition_set_id =
|
||||
id.has_value() ? static_cast<base::MatcherStringPattern::ID>(id.value())
|
||||
: base::MatcherStringPattern::kInvalidId;
|
||||
if (absl::optional<int> max_value_int = dict.FindInt("max")) {
|
||||
if (std::optional<int> max_value_int = dict.FindInt("max")) {
|
||||
result->max_value = *max_value_int;
|
||||
} else {
|
||||
*error = "Expected integer at ['max']";
|
||||
@ -230,7 +230,7 @@ class SummingAction : public base::RefCounted<SummingAction> {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
absl::optional<int> increment = dict.FindInt("value");
|
||||
std::optional<int> increment = dict.FindInt("value");
|
||||
EXPECT_TRUE(increment);
|
||||
int min_priority = dict.FindInt("priority").value_or(0);
|
||||
return scoped_refptr<const SummingAction>(
|
||||
|
@ -62,7 +62,7 @@ scoped_refptr<const BaseClass> CreateFoo(const std::string& /*instance_type*/,
|
||||
const base::Value::Dict& value,
|
||||
std::string* error,
|
||||
bool* bad_message) {
|
||||
absl::optional<int> parameter = value.FindInt("parameter");
|
||||
std::optional<int> parameter = value.FindInt("parameter");
|
||||
if (!parameter) {
|
||||
*error = "No parameter";
|
||||
*bad_message = true;
|
||||
|
@ -210,7 +210,7 @@ void RulesCacheDelegate::ReadFromStorage(const std::string& extension_id) {
|
||||
|
||||
void RulesCacheDelegate::ReadFromStorageCallback(
|
||||
const std::string& extension_id,
|
||||
absl::optional<base::Value> value) {
|
||||
std::optional<base::Value> value) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
DCHECK_EQ(Type::kPersistent, type_);
|
||||
content::BrowserThread::GetTaskRunnerForThread(rules_registry_thread_)
|
||||
|
@ -104,7 +104,7 @@ class RulesCacheDelegate {
|
||||
// Read/write a list of rules serialized to Values.
|
||||
void ReadFromStorage(const std::string& extension_id);
|
||||
void ReadFromStorageCallback(const std::string& extension_id,
|
||||
absl::optional<base::Value> value);
|
||||
std::optional<base::Value> value);
|
||||
|
||||
// Check the preferences whether the extension with |extension_id| has some
|
||||
// rules stored on disk. If this information is not in the preferences, true
|
||||
|
@ -47,7 +47,7 @@ base::Value::List RulesToValue(
|
||||
}
|
||||
|
||||
std::vector<api::events::Rule> RulesFromValue(
|
||||
const absl::optional<base::Value>& value) {
|
||||
const std::optional<base::Value>& value) {
|
||||
std::vector<api::events::Rule> rules;
|
||||
|
||||
if (!value || !value->is_list())
|
||||
@ -309,7 +309,7 @@ size_t RulesRegistry::GetNumberOfUsedRuleIdentifiersForTesting() const {
|
||||
}
|
||||
|
||||
void RulesRegistry::DeserializeAndAddRules(const std::string& extension_id,
|
||||
absl::optional<base::Value> rules) {
|
||||
std::optional<base::Value> rules) {
|
||||
DCHECK_CURRENTLY_ON(owner_thread());
|
||||
|
||||
// Since this is called in response to asynchronously loading rules from
|
||||
|
@ -232,7 +232,7 @@ class RulesRegistry : public base::RefCountedThreadSafe<RulesRegistry> {
|
||||
// Deserialize the rules from the given Value object and add them to the
|
||||
// RulesRegistry.
|
||||
void DeserializeAndAddRules(const std::string& extension_id,
|
||||
absl::optional<base::Value> rules);
|
||||
std::optional<base::Value> rules);
|
||||
|
||||
// Reports an internal error with the specified params to the extensions
|
||||
// client.
|
||||
|
@ -288,7 +288,7 @@ void ActionTracker::ResetTrackedInfoForTab(int tab_id, int64_t navigation_id) {
|
||||
|
||||
std::vector<dnr_api::MatchedRuleInfo> ActionTracker::GetMatchedRules(
|
||||
const Extension& extension,
|
||||
const absl::optional<int>& tab_id,
|
||||
const std::optional<int>& tab_id,
|
||||
const base::Time& min_time_stamp) {
|
||||
TrimRulesFromNonActiveTabs();
|
||||
|
||||
|
@ -7,15 +7,14 @@
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/time/time.h"
|
||||
#include "base/timer/timer.h"
|
||||
#include "extensions/common/api/declarative_net_request.h"
|
||||
#include "extensions/common/api/declarative_net_request/constants.h"
|
||||
#include "extensions/common/extension_id.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace base {
|
||||
class Clock;
|
||||
@ -93,7 +92,7 @@ class ActionTracker {
|
||||
// rules matched for |tab_id| will be returned.
|
||||
std::vector<api::declarative_net_request::MatchedRuleInfo> GetMatchedRules(
|
||||
const Extension& extension,
|
||||
const absl::optional<int>& tab_id,
|
||||
const std::optional<int>& tab_id,
|
||||
const base::Time& min_time_stamp);
|
||||
|
||||
// Returns the number of matched rules in |rules_tracked_| for the given
|
||||
|
@ -58,7 +58,7 @@ class ScopedGetBeforeRequestActionTimer {
|
||||
} // namespace
|
||||
|
||||
ActionInfo::ActionInfo() = default;
|
||||
ActionInfo::ActionInfo(absl::optional<RequestAction> action,
|
||||
ActionInfo::ActionInfo(std::optional<RequestAction> action,
|
||||
bool notify_request_withheld)
|
||||
: action(std::move(action)),
|
||||
notify_request_withheld(notify_request_withheld) {}
|
||||
@ -135,14 +135,14 @@ ActionInfo CompositeMatcher::GetBeforeRequestAction(
|
||||
page_access == PermissionsData::PageAccess::kWithheld);
|
||||
}
|
||||
|
||||
absl::optional<RequestAction> final_action;
|
||||
std::optional<RequestAction> final_action;
|
||||
|
||||
// The priority of the highest priority matching allow or allowAllRequests
|
||||
// rule within this matcher, or absl::nullopt otherwise.
|
||||
absl::optional<uint64_t> max_allow_rule_priority;
|
||||
// rule within this matcher, or std::nullopt otherwise.
|
||||
std::optional<uint64_t> max_allow_rule_priority;
|
||||
|
||||
for (const auto& matcher : matchers_) {
|
||||
absl::optional<RequestAction> action =
|
||||
std::optional<RequestAction> action =
|
||||
matcher->GetBeforeRequestAction(params);
|
||||
if (!action)
|
||||
continue;
|
||||
@ -172,7 +172,7 @@ ActionInfo CompositeMatcher::GetBeforeRequestAction(
|
||||
// `requires_host_permission` is true and `page_access` is withheld or denied.
|
||||
bool notify_request_withheld = page_access == PageAccess::kWithheld &&
|
||||
!final_action->IsAllowOrAllowAllRequests();
|
||||
return ActionInfo(absl::nullopt, notify_request_withheld);
|
||||
return ActionInfo(std::nullopt, notify_request_withheld);
|
||||
}
|
||||
|
||||
std::vector<RequestAction> CompositeMatcher::GetModifyHeadersActions(
|
||||
@ -181,8 +181,8 @@ std::vector<RequestAction> CompositeMatcher::GetModifyHeadersActions(
|
||||
DCHECK(params.allow_rule_max_priority.contains(this));
|
||||
|
||||
// The priority of the highest priority matching allow or allowAllRequests
|
||||
// rule within this matcher, or absl::nullopt if no such rule exists.
|
||||
absl::optional<uint64_t> max_allow_rule_priority =
|
||||
// rule within this matcher, or std::nullopt if no such rule exists.
|
||||
std::optional<uint64_t> max_allow_rule_priority =
|
||||
params.allow_rule_max_priority[this];
|
||||
|
||||
for (const auto& matcher : matchers_) {
|
||||
|
@ -7,14 +7,13 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include "extensions/browser/api/declarative_net_request/constants.h"
|
||||
#include "extensions/browser/api/declarative_net_request/request_action.h"
|
||||
#include "extensions/browser/api/declarative_net_request/ruleset_matcher.h"
|
||||
#include "extensions/common/permissions/permissions_data.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace content {
|
||||
class NavigationHandle;
|
||||
@ -33,7 +32,7 @@ class CompositeMatcher {
|
||||
// Constructs a no-op ActionInfo object.
|
||||
ActionInfo();
|
||||
|
||||
ActionInfo(absl::optional<RequestAction> action,
|
||||
ActionInfo(std::optional<RequestAction> action,
|
||||
bool notify_request_withheld);
|
||||
|
||||
ActionInfo(const ActionInfo&) = delete;
|
||||
@ -44,7 +43,7 @@ class CompositeMatcher {
|
||||
ActionInfo& operator=(ActionInfo&& other);
|
||||
|
||||
// The action to be taken for this request.
|
||||
absl::optional<RequestAction> action;
|
||||
std::optional<RequestAction> action;
|
||||
|
||||
// Whether the extension should be notified that the request was unable to
|
||||
// be redirected as the extension lacks the appropriate host permission for
|
||||
@ -86,7 +85,7 @@ class CompositeMatcher {
|
||||
std::set<RulesetID> ComputeStaticRulesetIDs() const;
|
||||
|
||||
// Returns a RequestAction for the network request specified by |params|, or
|
||||
// absl::nullopt if there is no matching rule.
|
||||
// std::nullopt if there is no matching rule.
|
||||
ActionInfo GetBeforeRequestAction(
|
||||
const RequestParams& params,
|
||||
PermissionsData::PageAccess page_access) const;
|
||||
@ -115,7 +114,7 @@ class CompositeMatcher {
|
||||
|
||||
// Denotes the cached return value for |HasAnyExtraHeadersMatcher|. Care must
|
||||
// be taken to reset this as this object is modified.
|
||||
mutable absl::optional<bool> has_any_extra_headers_matcher_;
|
||||
mutable std::optional<bool> has_any_extra_headers_matcher_;
|
||||
|
||||
const HostPermissionsAlwaysRequired host_permissions_always_required_;
|
||||
};
|
||||
|
@ -39,10 +39,10 @@ using CompositeMatcherTest = ::testing::Test;
|
||||
TestRule CreateModifyHeadersRule(
|
||||
int id,
|
||||
int priority,
|
||||
absl::optional<std::string> url_filter,
|
||||
absl::optional<std::string> regex_filter,
|
||||
absl::optional<std::vector<TestHeaderInfo>> request_headers_list,
|
||||
absl::optional<std::vector<TestHeaderInfo>> response_headers_list) {
|
||||
std::optional<std::string> url_filter,
|
||||
std::optional<std::string> regex_filter,
|
||||
std::optional<std::vector<TestHeaderInfo>> request_headers_list,
|
||||
std::optional<std::vector<TestHeaderInfo>> response_headers_list) {
|
||||
TestRule rule = CreateGenericRule();
|
||||
rule.id = id;
|
||||
rule.priority = priority;
|
||||
@ -126,16 +126,16 @@ TEST_F(CompositeMatcherTest, SamePrioritySpace) {
|
||||
// Tests the GetModifyHeadersActions method.
|
||||
TEST_F(CompositeMatcherTest, GetModifyHeadersActions) {
|
||||
TestRule rule_1 = CreateModifyHeadersRule(
|
||||
kMinValidID, kMinValidPriority, "google.com", absl::nullopt,
|
||||
kMinValidID, kMinValidPriority, "google.com", std::nullopt,
|
||||
std::vector<TestHeaderInfo>(
|
||||
{TestHeaderInfo("header1", "remove", absl::nullopt),
|
||||
{TestHeaderInfo("header1", "remove", std::nullopt),
|
||||
TestHeaderInfo("header2", "set", "value2")}),
|
||||
absl::nullopt);
|
||||
std::nullopt);
|
||||
|
||||
TestRule rule_2 = CreateModifyHeadersRule(
|
||||
kMinValidID, kMinValidPriority + 1, "/path", absl::nullopt, absl::nullopt,
|
||||
kMinValidID, kMinValidPriority + 1, "/path", std::nullopt, std::nullopt,
|
||||
std::vector<TestHeaderInfo>(
|
||||
{TestHeaderInfo("header1", "remove", absl::nullopt),
|
||||
{TestHeaderInfo("header1", "remove", std::nullopt),
|
||||
TestHeaderInfo("header2", "append", "VALUE2"),
|
||||
TestHeaderInfo("header3", "set", "VALUE3")}));
|
||||
|
||||
@ -180,7 +180,7 @@ TEST_F(CompositeMatcherTest, GetModifyHeadersActions) {
|
||||
*rule_1.id, *rule_1.priority, kSource1ID);
|
||||
action_1.request_headers_to_modify = {
|
||||
RequestAction::HeaderInfo("header1", dnr_api::HeaderOperation::kRemove,
|
||||
absl::nullopt),
|
||||
std::nullopt),
|
||||
RequestAction::HeaderInfo("header2", dnr_api::HeaderOperation::kSet,
|
||||
"value2")};
|
||||
|
||||
@ -189,7 +189,7 @@ TEST_F(CompositeMatcherTest, GetModifyHeadersActions) {
|
||||
*rule_2.id, *rule_2.priority, kSource2ID);
|
||||
action_2.response_headers_to_modify = {
|
||||
RequestAction::HeaderInfo("header1", dnr_api::HeaderOperation::kRemove,
|
||||
absl::nullopt),
|
||||
std::nullopt),
|
||||
RequestAction::HeaderInfo("header2", dnr_api::HeaderOperation::kAppend,
|
||||
"VALUE2"),
|
||||
RequestAction::HeaderInfo("header3", dnr_api::HeaderOperation::kSet,
|
||||
@ -229,7 +229,7 @@ TEST_F(CompositeMatcherTest, GetModifyHeadersActions) {
|
||||
*rule_1.id, *rule_1.priority, kSource1ID);
|
||||
action_1.request_headers_to_modify = {
|
||||
RequestAction::HeaderInfo("header1", dnr_api::HeaderOperation::kRemove,
|
||||
absl::nullopt),
|
||||
std::nullopt),
|
||||
RequestAction::HeaderInfo("header2", dnr_api::HeaderOperation::kSet,
|
||||
"value2")};
|
||||
|
||||
@ -238,7 +238,7 @@ TEST_F(CompositeMatcherTest, GetModifyHeadersActions) {
|
||||
*rule_2.id, *rule_2.priority, kSource2ID);
|
||||
action_2.response_headers_to_modify = {
|
||||
RequestAction::HeaderInfo("header1", dnr_api::HeaderOperation::kRemove,
|
||||
absl::nullopt),
|
||||
std::nullopt),
|
||||
RequestAction::HeaderInfo("header2", dnr_api::HeaderOperation::kAppend,
|
||||
"VALUE2"),
|
||||
RequestAction::HeaderInfo("header3", dnr_api::HeaderOperation::kSet,
|
||||
@ -264,40 +264,40 @@ TEST_F(CompositeMatcherTest, GetModifyHeadersActions_Priority) {
|
||||
allow_rule.priority = allow_rule_priority;
|
||||
|
||||
TestRule url_rule_1 = CreateModifyHeadersRule(
|
||||
kMinValidID + 1, allow_rule_priority - 1, "google.com", absl::nullopt,
|
||||
kMinValidID + 1, allow_rule_priority - 1, "google.com", std::nullopt,
|
||||
std::vector<TestHeaderInfo>(
|
||||
{TestHeaderInfo("header1", "remove", absl::nullopt)}),
|
||||
absl::nullopt);
|
||||
{TestHeaderInfo("header1", "remove", std::nullopt)}),
|
||||
std::nullopt);
|
||||
|
||||
TestRule url_rule_2 = CreateModifyHeadersRule(
|
||||
kMinValidID + 2, allow_rule_priority, "google.com", absl::nullopt,
|
||||
kMinValidID + 2, allow_rule_priority, "google.com", std::nullopt,
|
||||
std::vector<TestHeaderInfo>(
|
||||
{TestHeaderInfo("header2", "remove", absl::nullopt)}),
|
||||
absl::nullopt);
|
||||
{TestHeaderInfo("header2", "remove", std::nullopt)}),
|
||||
std::nullopt);
|
||||
|
||||
TestRule url_rule_3 = CreateModifyHeadersRule(
|
||||
kMinValidID + 3, allow_rule_priority + 1, "google.com", absl::nullopt,
|
||||
kMinValidID + 3, allow_rule_priority + 1, "google.com", std::nullopt,
|
||||
std::vector<TestHeaderInfo>(
|
||||
{TestHeaderInfo("header3", "remove", absl::nullopt)}),
|
||||
absl::nullopt);
|
||||
{TestHeaderInfo("header3", "remove", std::nullopt)}),
|
||||
std::nullopt);
|
||||
|
||||
TestRule regex_rule_1 = CreateModifyHeadersRule(
|
||||
kMinValidID + 4, allow_rule_priority - 1, absl::nullopt, R"(google\.com)",
|
||||
kMinValidID + 4, allow_rule_priority - 1, std::nullopt, R"(google\.com)",
|
||||
std::vector<TestHeaderInfo>(
|
||||
{TestHeaderInfo("header4", "remove", absl::nullopt)}),
|
||||
absl::nullopt);
|
||||
{TestHeaderInfo("header4", "remove", std::nullopt)}),
|
||||
std::nullopt);
|
||||
|
||||
TestRule regex_rule_2 = CreateModifyHeadersRule(
|
||||
kMinValidID + 5, allow_rule_priority, absl::nullopt, R"(google\.com)",
|
||||
kMinValidID + 5, allow_rule_priority, std::nullopt, R"(google\.com)",
|
||||
std::vector<TestHeaderInfo>(
|
||||
{TestHeaderInfo("header5", "remove", absl::nullopt)}),
|
||||
absl::nullopt);
|
||||
{TestHeaderInfo("header5", "remove", std::nullopt)}),
|
||||
std::nullopt);
|
||||
|
||||
TestRule regex_rule_3 = CreateModifyHeadersRule(
|
||||
kMinValidID + 6, allow_rule_priority + 1, absl::nullopt, R"(google\.com)",
|
||||
kMinValidID + 6, allow_rule_priority + 1, std::nullopt, R"(google\.com)",
|
||||
std::vector<TestHeaderInfo>(
|
||||
{TestHeaderInfo("header6", "remove", absl::nullopt)}),
|
||||
absl::nullopt);
|
||||
{TestHeaderInfo("header6", "remove", std::nullopt)}),
|
||||
std::nullopt);
|
||||
|
||||
const RulesetID kSource1ID(1);
|
||||
std::unique_ptr<RulesetMatcher> matcher_1;
|
||||
@ -347,12 +347,10 @@ TEST_F(CompositeMatcherTest, GetModifyHeadersActions_Priority) {
|
||||
|
||||
RequestAction header_3_action = create_action_for_rule(
|
||||
url_rule_3, kSource1ID,
|
||||
{HeaderInfo("header3", dnr_api::HeaderOperation::kRemove,
|
||||
absl::nullopt)});
|
||||
{HeaderInfo("header3", dnr_api::HeaderOperation::kRemove, std::nullopt)});
|
||||
RequestAction header_6_action = create_action_for_rule(
|
||||
regex_rule_3, kSource2ID,
|
||||
{HeaderInfo("header6", dnr_api::HeaderOperation::kRemove,
|
||||
absl::nullopt)});
|
||||
{HeaderInfo("header6", dnr_api::HeaderOperation::kRemove, std::nullopt)});
|
||||
|
||||
// For the request to "http://google.com/1", since |url_rule_3| and
|
||||
// |regex_rule_3| are the only rules with a greater priority than
|
||||
@ -374,20 +372,16 @@ TEST_F(CompositeMatcherTest, GetModifyHeadersActions_Priority) {
|
||||
|
||||
RequestAction header_1_action = create_action_for_rule(
|
||||
url_rule_1, kSource1ID,
|
||||
{HeaderInfo("header1", dnr_api::HeaderOperation::kRemove,
|
||||
absl::nullopt)});
|
||||
{HeaderInfo("header1", dnr_api::HeaderOperation::kRemove, std::nullopt)});
|
||||
RequestAction header_2_action = create_action_for_rule(
|
||||
url_rule_2, kSource1ID,
|
||||
{HeaderInfo("header2", dnr_api::HeaderOperation::kRemove,
|
||||
absl::nullopt)});
|
||||
{HeaderInfo("header2", dnr_api::HeaderOperation::kRemove, std::nullopt)});
|
||||
RequestAction header_4_action = create_action_for_rule(
|
||||
regex_rule_1, kSource2ID,
|
||||
{HeaderInfo("header4", dnr_api::HeaderOperation::kRemove,
|
||||
absl::nullopt)});
|
||||
{HeaderInfo("header4", dnr_api::HeaderOperation::kRemove, std::nullopt)});
|
||||
RequestAction header_5_action = create_action_for_rule(
|
||||
regex_rule_2, kSource2ID,
|
||||
{HeaderInfo("header5", dnr_api::HeaderOperation::kRemove,
|
||||
absl::nullopt)});
|
||||
{HeaderInfo("header5", dnr_api::HeaderOperation::kRemove, std::nullopt)});
|
||||
|
||||
// For the request to "http://google.com/2", "header1" to "header6" should be
|
||||
// removed since all modifyHeaders rules are matched and there is no matching
|
||||
@ -438,7 +432,7 @@ TEST_F(CompositeMatcherTest, NotifyWithholdFromPageAccess) {
|
||||
struct {
|
||||
const raw_ref<GURL, ExperimentalAsh> request_url;
|
||||
PageAccess access;
|
||||
absl::optional<GURL> expected_final_url;
|
||||
std::optional<GURL> expected_final_url;
|
||||
bool should_notify_withheld;
|
||||
} test_cases[] = {
|
||||
// If access to the request is allowed, we should not notify that
|
||||
@ -447,28 +441,28 @@ TEST_F(CompositeMatcherTest, NotifyWithholdFromPageAccess) {
|
||||
ruleset1_url, false},
|
||||
{ToRawRef<ExperimentalAsh>(example_url), PageAccess::kAllowed,
|
||||
https_example_url, false},
|
||||
{ToRawRef<ExperimentalAsh>(yahoo_url), PageAccess::kAllowed,
|
||||
absl::nullopt, false},
|
||||
{ToRawRef<ExperimentalAsh>(yahoo_url), PageAccess::kAllowed, std::nullopt,
|
||||
false},
|
||||
|
||||
// Notify the request is withheld if it matches with a redirect rule.
|
||||
{ToRawRef<ExperimentalAsh>(google_url), PageAccess::kWithheld,
|
||||
absl::nullopt, true},
|
||||
std::nullopt, true},
|
||||
// If the page access to the request is withheld but it matches with
|
||||
// an upgrade rule, or no rule, then we should not notify.
|
||||
{ToRawRef<ExperimentalAsh>(example_url), PageAccess::kWithheld,
|
||||
https_example_url, false},
|
||||
{ToRawRef<ExperimentalAsh>(yahoo_url), PageAccess::kWithheld,
|
||||
absl::nullopt, false},
|
||||
std::nullopt, false},
|
||||
|
||||
// If access to the request is denied instead of withheld, the extension
|
||||
// should not be notified.
|
||||
{ToRawRef<ExperimentalAsh>(google_url), PageAccess::kDenied,
|
||||
absl::nullopt, false},
|
||||
{ToRawRef<ExperimentalAsh>(google_url), PageAccess::kDenied, std::nullopt,
|
||||
false},
|
||||
// If the page access to the request is denied but it matches with
|
||||
// an upgrade rule, or no rule, then we should not notify.
|
||||
{ToRawRef<ExperimentalAsh>(example_url), PageAccess::kDenied,
|
||||
https_example_url, false},
|
||||
{ToRawRef<ExperimentalAsh>(yahoo_url), PageAccess::kDenied, absl::nullopt,
|
||||
{ToRawRef<ExperimentalAsh>(yahoo_url), PageAccess::kDenied, std::nullopt,
|
||||
false},
|
||||
};
|
||||
|
||||
@ -527,18 +521,18 @@ TEST_F(CompositeMatcherTest, HostPermissionsAlwaysRequired) {
|
||||
const char* url;
|
||||
const PageAccess access;
|
||||
const bool expected_notify_withheld;
|
||||
absl::optional<int> expected_matched_rule_id;
|
||||
std::optional<int> expected_matched_rule_id;
|
||||
} cases[] = {
|
||||
{"https://example.com", PageAccess::kAllowed, false, block_rule.id},
|
||||
{"https://example.com", PageAccess::kWithheld, true, absl::nullopt},
|
||||
{"https://example.com", PageAccess::kWithheld, true, std::nullopt},
|
||||
{"https://foo.com", PageAccess::kAllowed, false, allow_rule.id},
|
||||
// We don't expect to be notified about this (even though there's a rule
|
||||
// that would have matched) because the rule would just allow the request.
|
||||
{"https://foo.com", PageAccess::kWithheld, false, absl::nullopt},
|
||||
{"https://foo.com", PageAccess::kWithheld, false, std::nullopt},
|
||||
{"http://upgrade.com", PageAccess::kAllowed, false, upgrade_rule.id},
|
||||
{"http://upgrade.com", PageAccess::kWithheld, true, absl::nullopt},
|
||||
{"http://nomatch.com", PageAccess::kAllowed, false, absl::nullopt},
|
||||
{"http://nomatch.com", PageAccess::kWithheld, false, absl::nullopt},
|
||||
{"http://upgrade.com", PageAccess::kWithheld, true, std::nullopt},
|
||||
{"http://nomatch.com", PageAccess::kAllowed, false, std::nullopt},
|
||||
{"http://nomatch.com", PageAccess::kWithheld, false, std::nullopt},
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < std::size(cases); i++) {
|
||||
@ -552,7 +546,7 @@ TEST_F(CompositeMatcherTest, HostPermissionsAlwaysRequired) {
|
||||
composite_matcher->GetBeforeRequestAction(params, cases[i].access);
|
||||
EXPECT_EQ(cases[i].expected_notify_withheld, info.notify_request_withheld);
|
||||
|
||||
absl::optional<int> rule_matched_id;
|
||||
std::optional<int> rule_matched_id;
|
||||
if (info.action)
|
||||
rule_matched_id = info.action->rule_id;
|
||||
|
||||
@ -599,7 +593,7 @@ TEST_F(CompositeMatcherTest, GetRedirectUrlFromPriority) {
|
||||
|
||||
struct {
|
||||
GURL request_url;
|
||||
absl::optional<GURL> expected_final_url;
|
||||
std::optional<GURL> expected_final_url;
|
||||
} test_cases[] = {
|
||||
// Test requests which match exactly one rule.
|
||||
{GURL("http://abc.com"), GURL("http://google.com")},
|
||||
@ -616,9 +610,9 @@ TEST_F(CompositeMatcherTest, GetRedirectUrlFromPriority) {
|
||||
|
||||
// The request will not be redirected as it matches the upgrade rule but
|
||||
// is already https.
|
||||
{GURL("https://abcdef.com"), absl::nullopt},
|
||||
{GURL("https://abcdef.com"), std::nullopt},
|
||||
|
||||
{GURL("http://xyz.com"), absl::nullopt},
|
||||
{GURL("http://xyz.com"), std::nullopt},
|
||||
};
|
||||
|
||||
for (const auto& test_case : test_cases) {
|
||||
|
@ -5,10 +5,10 @@
|
||||
#include "extensions/browser/api/declarative_net_request/declarative_net_request_api.h"
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/containers/cxx20_erase.h"
|
||||
#include "base/functional/bind.h"
|
||||
@ -37,7 +37,6 @@
|
||||
#include "extensions/common/api/declarative_net_request/dnr_manifest_data.h"
|
||||
#include "extensions/common/error_utils.h"
|
||||
#include "extensions/common/extension_id.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace extensions {
|
||||
|
||||
@ -50,7 +49,7 @@ namespace dnr_api = api::declarative_net_request;
|
||||
// the API call is for all tabs.
|
||||
bool CanCallGetMatchedRules(content::BrowserContext* browser_context,
|
||||
const Extension* extension,
|
||||
absl::optional<int> tab_id,
|
||||
std::optional<int> tab_id,
|
||||
std::string* error) {
|
||||
bool can_call =
|
||||
declarative_net_request::HasDNRFeedbackPermission(extension, tab_id);
|
||||
@ -119,7 +118,7 @@ DeclarativeNetRequestUpdateDynamicRulesFunction::Run() {
|
||||
}
|
||||
|
||||
void DeclarativeNetRequestUpdateDynamicRulesFunction::OnDynamicRulesUpdated(
|
||||
absl::optional<std::string> error) {
|
||||
std::optional<std::string> error) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
|
||||
if (error)
|
||||
@ -224,7 +223,7 @@ DeclarativeNetRequestUpdateSessionRulesFunction::Run() {
|
||||
}
|
||||
|
||||
void DeclarativeNetRequestUpdateSessionRulesFunction::OnSessionRulesUpdated(
|
||||
absl::optional<std::string> error) {
|
||||
std::optional<std::string> error) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
|
||||
if (error)
|
||||
@ -329,7 +328,7 @@ DeclarativeNetRequestUpdateEnabledRulesetsFunction::Run() {
|
||||
}
|
||||
|
||||
void DeclarativeNetRequestUpdateEnabledRulesetsFunction::
|
||||
OnEnabledStaticRulesetsUpdated(absl::optional<std::string> error) {
|
||||
OnEnabledStaticRulesetsUpdated(std::optional<std::string> error) {
|
||||
if (error)
|
||||
Respond(Error(std::move(*error)));
|
||||
else
|
||||
@ -413,7 +412,7 @@ DeclarativeNetRequestUpdateStaticRulesFunction::Run() {
|
||||
}
|
||||
|
||||
void DeclarativeNetRequestUpdateStaticRulesFunction::OnStaticRulesUpdated(
|
||||
absl::optional<std::string> error) {
|
||||
std::optional<std::string> error) {
|
||||
if (error) {
|
||||
Respond(Error(std::move(*error)));
|
||||
} else {
|
||||
@ -482,7 +481,7 @@ DeclarativeNetRequestGetMatchedRulesFunction::Run() {
|
||||
auto params = Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params.has_value());
|
||||
|
||||
absl::optional<int> tab_id;
|
||||
std::optional<int> tab_id;
|
||||
base::Time min_time_stamp = base::Time::Min();
|
||||
|
||||
if (params->filter) {
|
||||
|
@ -33,7 +33,7 @@ class DeclarativeNetRequestUpdateDynamicRulesFunction
|
||||
ExtensionFunction::ResponseAction Run() override;
|
||||
|
||||
private:
|
||||
void OnDynamicRulesUpdated(absl::optional<std::string> error);
|
||||
void OnDynamicRulesUpdated(std::optional<std::string> error);
|
||||
};
|
||||
|
||||
class DeclarativeNetRequestGetDynamicRulesFunction : public ExtensionFunction {
|
||||
@ -68,7 +68,7 @@ class DeclarativeNetRequestUpdateSessionRulesFunction
|
||||
ExtensionFunction::ResponseAction Run() override;
|
||||
|
||||
private:
|
||||
void OnSessionRulesUpdated(absl::optional<std::string> error);
|
||||
void OnSessionRulesUpdated(std::optional<std::string> error);
|
||||
};
|
||||
|
||||
class DeclarativeNetRequestGetSessionRulesFunction : public ExtensionFunction {
|
||||
@ -95,7 +95,7 @@ class DeclarativeNetRequestUpdateEnabledRulesetsFunction
|
||||
~DeclarativeNetRequestUpdateEnabledRulesetsFunction() override;
|
||||
|
||||
private:
|
||||
void OnEnabledStaticRulesetsUpdated(absl::optional<std::string> error);
|
||||
void OnEnabledStaticRulesetsUpdated(std::optional<std::string> error);
|
||||
|
||||
// ExtensionFunction override:
|
||||
ExtensionFunction::ResponseAction Run() override;
|
||||
@ -127,7 +127,7 @@ class DeclarativeNetRequestUpdateStaticRulesFunction
|
||||
~DeclarativeNetRequestUpdateStaticRulesFunction() override;
|
||||
|
||||
private:
|
||||
void OnStaticRulesUpdated(absl::optional<std::string> error);
|
||||
void OnStaticRulesUpdated(std::optional<std::string> error);
|
||||
|
||||
// ExtensionFunction override:
|
||||
ExtensionFunction::ResponseAction Run() override;
|
||||
|
@ -77,8 +77,8 @@ DeclarativeNetRequestPrefsHelper::DeclarativeNetRequestPrefsHelper(
|
||||
DeclarativeNetRequestPrefsHelper::~DeclarativeNetRequestPrefsHelper() = default;
|
||||
|
||||
DeclarativeNetRequestPrefsHelper::RuleIdsToUpdate::RuleIdsToUpdate(
|
||||
const absl::optional<std::vector<int>>& ids_to_disable,
|
||||
const absl::optional<std::vector<int>>& ids_to_enable) {
|
||||
const std::optional<std::vector<int>>& ids_to_disable,
|
||||
const std::optional<std::vector<int>>& ids_to_enable) {
|
||||
if (ids_to_disable)
|
||||
this->ids_to_disable.insert(ids_to_disable->begin(), ids_to_disable->end());
|
||||
|
||||
|
@ -5,14 +5,13 @@
|
||||
#ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_DECLARATIVE_NET_REQUEST_PREFS_HELPER_H_
|
||||
#define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_DECLARATIVE_NET_REQUEST_PREFS_HELPER_H_
|
||||
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/flat_set.h"
|
||||
#include "base/memory/raw_ref.h"
|
||||
#include "base/values.h"
|
||||
#include "extensions/common/api/declarative_net_request/constants.h"
|
||||
#include "extensions/common/extension_id.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace extensions {
|
||||
class ExtensionPrefs;
|
||||
@ -41,8 +40,8 @@ class DeclarativeNetRequestPrefsHelper {
|
||||
|
||||
// Struct that contains the rule ids to disable or enable.
|
||||
struct RuleIdsToUpdate {
|
||||
RuleIdsToUpdate(const absl::optional<std::vector<int>>& ids_to_disable,
|
||||
const absl::optional<std::vector<int>>& ids_to_enable);
|
||||
RuleIdsToUpdate(const std::optional<std::vector<int>>& ids_to_disable,
|
||||
const std::optional<std::vector<int>>& ids_to_enable);
|
||||
RuleIdsToUpdate(RuleIdsToUpdate&&);
|
||||
~RuleIdsToUpdate();
|
||||
|
||||
@ -66,7 +65,7 @@ class DeclarativeNetRequestPrefsHelper {
|
||||
base::flat_set<int> disabled_rule_ids_after_update;
|
||||
|
||||
// Error while updating the disabled rule ids.
|
||||
absl::optional<std::string> error;
|
||||
std::optional<std::string> error;
|
||||
};
|
||||
|
||||
// Returns the set of disabled rule ids of a static ruleset.
|
||||
|
@ -80,13 +80,13 @@ TEST_F(DeclarativeNetRequestPrefsHelperTest, UpdateStaticRulesTest) {
|
||||
// Updating disabled rule ids with empty set doesn't make any change.
|
||||
{
|
||||
RuleIdsToUpdate ids_to_update(std::vector<int>() /* ids_to_disable */,
|
||||
absl::nullopt /* ids_to_enable */);
|
||||
std::nullopt /* ids_to_enable */);
|
||||
EXPECT_TRUE(ids_to_update.Empty());
|
||||
|
||||
auto result = UpdateDisabledStaticRules(ruleset1, ids_to_update);
|
||||
EXPECT_FALSE(result.changed);
|
||||
EXPECT_THAT(result.disabled_rule_ids_after_update, testing::IsEmpty());
|
||||
EXPECT_EQ(absl::nullopt, result.error);
|
||||
EXPECT_EQ(std::nullopt, result.error);
|
||||
}
|
||||
EXPECT_THAT(GetDisabledRuleIds(ruleset1), testing::IsEmpty());
|
||||
EXPECT_THAT(GetDisabledRuleIds(ruleset2), testing::IsEmpty());
|
||||
@ -96,14 +96,14 @@ TEST_F(DeclarativeNetRequestPrefsHelperTest, UpdateStaticRulesTest) {
|
||||
{
|
||||
RuleIdsToUpdate ids_to_update(
|
||||
std::vector<int>({1, 2, 3}) /* ids_to_disable */,
|
||||
absl::nullopt /* ids_to_enable */);
|
||||
std::nullopt /* ids_to_enable */);
|
||||
EXPECT_FALSE(ids_to_update.Empty());
|
||||
|
||||
auto result = UpdateDisabledStaticRules(ruleset1, ids_to_update);
|
||||
EXPECT_TRUE(result.changed);
|
||||
EXPECT_THAT(result.disabled_rule_ids_after_update,
|
||||
UnorderedElementsAre(1, 2, 3));
|
||||
EXPECT_EQ(absl::nullopt, result.error);
|
||||
EXPECT_EQ(std::nullopt, result.error);
|
||||
}
|
||||
EXPECT_THAT(GetDisabledRuleIds(ruleset1), UnorderedElementsAre(1, 2, 3));
|
||||
EXPECT_THAT(GetDisabledRuleIds(ruleset2), testing::IsEmpty());
|
||||
@ -113,14 +113,14 @@ TEST_F(DeclarativeNetRequestPrefsHelperTest, UpdateStaticRulesTest) {
|
||||
{
|
||||
RuleIdsToUpdate ids_to_update(
|
||||
std::vector<int>({3, 4, 5}) /* ids_to_disable */,
|
||||
absl::nullopt /* ids_to_enable */);
|
||||
std::nullopt /* ids_to_enable */);
|
||||
EXPECT_FALSE(ids_to_update.Empty());
|
||||
|
||||
auto result = UpdateDisabledStaticRules(ruleset2, ids_to_update);
|
||||
EXPECT_TRUE(result.changed);
|
||||
EXPECT_THAT(result.disabled_rule_ids_after_update,
|
||||
UnorderedElementsAre(3, 4, 5));
|
||||
EXPECT_EQ(absl::nullopt, result.error);
|
||||
EXPECT_EQ(std::nullopt, result.error);
|
||||
}
|
||||
|
||||
EXPECT_THAT(GetDisabledRuleIds(ruleset1), UnorderedElementsAre(1, 2, 3));
|
||||
@ -129,14 +129,14 @@ TEST_F(DeclarativeNetRequestPrefsHelperTest, UpdateStaticRulesTest) {
|
||||
|
||||
// Updating disabled rule ids with null set doesn't make any change.
|
||||
{
|
||||
RuleIdsToUpdate ids_to_update(absl::nullopt /* ids_to_disable */,
|
||||
absl::nullopt /* ids_to_enable */);
|
||||
RuleIdsToUpdate ids_to_update(std::nullopt /* ids_to_disable */,
|
||||
std::nullopt /* ids_to_enable */);
|
||||
EXPECT_TRUE(ids_to_update.Empty());
|
||||
|
||||
auto result = UpdateDisabledStaticRules(ruleset2, ids_to_update);
|
||||
EXPECT_FALSE(result.changed);
|
||||
EXPECT_THAT(result.disabled_rule_ids_after_update, testing::IsEmpty());
|
||||
EXPECT_EQ(absl::nullopt, result.error);
|
||||
EXPECT_EQ(std::nullopt, result.error);
|
||||
}
|
||||
EXPECT_THAT(GetDisabledRuleIds(ruleset1), UnorderedElementsAre(1, 2, 3));
|
||||
EXPECT_THAT(GetDisabledRuleIds(ruleset2), UnorderedElementsAre(3, 4, 5));
|
||||
@ -153,7 +153,7 @@ TEST_F(DeclarativeNetRequestPrefsHelperTest, UpdateStaticRulesTest) {
|
||||
auto result = UpdateDisabledStaticRules(ruleset2, ids_to_update);
|
||||
EXPECT_FALSE(result.changed);
|
||||
EXPECT_THAT(result.disabled_rule_ids_after_update, testing::IsEmpty());
|
||||
EXPECT_EQ(absl::nullopt, result.error);
|
||||
EXPECT_EQ(std::nullopt, result.error);
|
||||
}
|
||||
EXPECT_THAT(GetDisabledRuleIds(ruleset1), UnorderedElementsAre(1, 2, 3));
|
||||
EXPECT_THAT(GetDisabledRuleIds(ruleset2), UnorderedElementsAre(3, 4, 5));
|
||||
@ -172,7 +172,7 @@ TEST_F(DeclarativeNetRequestPrefsHelperTest, UpdateStaticRulesTest) {
|
||||
EXPECT_TRUE(result.changed);
|
||||
EXPECT_THAT(result.disabled_rule_ids_after_update,
|
||||
UnorderedElementsAre(3, 5, 6, 7));
|
||||
EXPECT_EQ(absl::nullopt, result.error);
|
||||
EXPECT_EQ(std::nullopt, result.error);
|
||||
}
|
||||
EXPECT_THAT(GetDisabledRuleIds(ruleset1), UnorderedElementsAre(1, 2, 3));
|
||||
EXPECT_THAT(GetDisabledRuleIds(ruleset2), UnorderedElementsAre(3, 5, 6, 7));
|
||||
@ -200,14 +200,14 @@ TEST_F(DeclarativeNetRequestPrefsHelperTest, UpdateStaticRulesTest) {
|
||||
// doesn't make any change since rule 4 is not disabled.
|
||||
{
|
||||
RuleIdsToUpdate ids_to_update(
|
||||
absl::nullopt /* ids_to_disable */,
|
||||
std::nullopt /* ids_to_disable */,
|
||||
std::vector<int>({1, 2, 3, 4}) /* ids_to_enable */);
|
||||
EXPECT_FALSE(ids_to_update.Empty());
|
||||
|
||||
auto result = UpdateDisabledStaticRules(ruleset1, ids_to_update);
|
||||
EXPECT_TRUE(result.changed);
|
||||
EXPECT_THAT(result.disabled_rule_ids_after_update, testing::IsEmpty());
|
||||
EXPECT_EQ(absl::nullopt, result.error);
|
||||
EXPECT_EQ(std::nullopt, result.error);
|
||||
}
|
||||
EXPECT_THAT(GetDisabledRuleIds(ruleset1), testing::IsEmpty());
|
||||
EXPECT_THAT(GetDisabledRuleIds(ruleset2), UnorderedElementsAre(3, 5, 6, 7));
|
||||
@ -217,14 +217,14 @@ TEST_F(DeclarativeNetRequestPrefsHelperTest, UpdateStaticRulesTest) {
|
||||
// rule 4 doesn't make any change since rule 4 is not disabled.
|
||||
{
|
||||
RuleIdsToUpdate ids_to_update(
|
||||
absl::nullopt /* ids_to_disable */,
|
||||
std::nullopt /* ids_to_disable */,
|
||||
std::vector<int>({3, 4, 5, 6, 7}) /* ids_to_enable */);
|
||||
EXPECT_FALSE(ids_to_update.Empty());
|
||||
|
||||
auto result = UpdateDisabledStaticRules(ruleset2, ids_to_update);
|
||||
EXPECT_TRUE(result.changed);
|
||||
EXPECT_THAT(result.disabled_rule_ids_after_update, testing::IsEmpty());
|
||||
EXPECT_EQ(absl::nullopt, result.error);
|
||||
EXPECT_EQ(std::nullopt, result.error);
|
||||
}
|
||||
EXPECT_THAT(GetDisabledRuleIds(ruleset1), testing::IsEmpty());
|
||||
EXPECT_THAT(GetDisabledRuleIds(ruleset2), testing::IsEmpty());
|
||||
@ -234,14 +234,14 @@ TEST_F(DeclarativeNetRequestPrefsHelperTest, UpdateStaticRulesTest) {
|
||||
// since there is no disabled rules.
|
||||
{
|
||||
RuleIdsToUpdate ids_to_update(
|
||||
absl::nullopt /* ids_to_disable */,
|
||||
std::nullopt /* ids_to_disable */,
|
||||
std::vector<int>({3, 4, 5}) /* ids_to_enable */);
|
||||
EXPECT_FALSE(ids_to_update.Empty());
|
||||
|
||||
auto result = UpdateDisabledStaticRules(ruleset2, ids_to_update);
|
||||
EXPECT_FALSE(result.changed);
|
||||
EXPECT_THAT(result.disabled_rule_ids_after_update, testing::IsEmpty());
|
||||
EXPECT_EQ(absl::nullopt, result.error);
|
||||
EXPECT_EQ(std::nullopt, result.error);
|
||||
}
|
||||
EXPECT_THAT(GetDisabledRuleIds(ruleset1), testing::IsEmpty());
|
||||
EXPECT_THAT(GetDisabledRuleIds(ruleset2), testing::IsEmpty());
|
||||
|
@ -79,14 +79,14 @@ size_t ExtensionUrlPatternIndexMatcher::GetRulesCount() const {
|
||||
return rules_count_;
|
||||
}
|
||||
|
||||
absl::optional<RequestAction>
|
||||
std::optional<RequestAction>
|
||||
ExtensionUrlPatternIndexMatcher::GetAllowAllRequestsAction(
|
||||
const RequestParams& params) const {
|
||||
const flat_rule::UrlRule* rule =
|
||||
GetMatchingRule(params, flat::IndexType_allow_all_requests,
|
||||
FindRuleStrategy::kHighestPriority);
|
||||
if (!rule)
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
return CreateAllowAllRequestsAction(params, *rule);
|
||||
}
|
||||
@ -94,7 +94,7 @@ ExtensionUrlPatternIndexMatcher::GetAllowAllRequestsAction(
|
||||
std::vector<RequestAction>
|
||||
ExtensionUrlPatternIndexMatcher::GetModifyHeadersActions(
|
||||
const RequestParams& params,
|
||||
absl::optional<uint64_t> min_priority) const {
|
||||
std::optional<uint64_t> min_priority) const {
|
||||
// TODO(crbug.com/1083178): Plumb |min_priority| into UrlPatternIndexMatcher
|
||||
// to prune more rules before matching on url filters.
|
||||
std::vector<const flat_rule::UrlRule*> rules =
|
||||
@ -109,21 +109,21 @@ ExtensionUrlPatternIndexMatcher::GetModifyHeadersActions(
|
||||
return GetModifyHeadersActionsFromMetadata(params, rules, *metadata_list_);
|
||||
}
|
||||
|
||||
absl::optional<RequestAction>
|
||||
std::optional<RequestAction>
|
||||
ExtensionUrlPatternIndexMatcher::GetBeforeRequestActionIgnoringAncestors(
|
||||
const RequestParams& params) const {
|
||||
return GetMaxPriorityAction(GetBeforeRequestActionHelper(params),
|
||||
GetAllowAllRequestsAction(params));
|
||||
}
|
||||
|
||||
absl::optional<RequestAction>
|
||||
std::optional<RequestAction>
|
||||
ExtensionUrlPatternIndexMatcher::GetBeforeRequestActionHelper(
|
||||
const RequestParams& params) const {
|
||||
const flat_rule::UrlRule* rule = GetMatchingRule(
|
||||
params, flat::IndexType_before_request_except_allow_all_requests,
|
||||
FindRuleStrategy::kHighestPriority);
|
||||
if (!rule)
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
const flat::UrlRuleMetadata* metadata =
|
||||
metadata_list_->LookupByKey(rule->id());
|
||||
@ -144,7 +144,7 @@ ExtensionUrlPatternIndexMatcher::GetBeforeRequestActionHelper(
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const flat_rule::UrlRule* ExtensionUrlPatternIndexMatcher::GetMatchingRule(
|
||||
|
@ -37,7 +37,7 @@ class ExtensionUrlPatternIndexMatcher final : public RulesetMatcherBase {
|
||||
~ExtensionUrlPatternIndexMatcher() override;
|
||||
std::vector<RequestAction> GetModifyHeadersActions(
|
||||
const RequestParams& params,
|
||||
absl::optional<uint64_t> min_priority) const override;
|
||||
std::optional<uint64_t> min_priority) const override;
|
||||
bool IsExtraHeadersMatcher() const override;
|
||||
size_t GetRulesCount() const override;
|
||||
|
||||
@ -50,14 +50,14 @@ class ExtensionUrlPatternIndexMatcher final : public RulesetMatcherBase {
|
||||
using UrlPatternIndexMatcher = url_pattern_index::UrlPatternIndexMatcher;
|
||||
|
||||
// RulesetMatcherBase override:
|
||||
absl::optional<RequestAction> GetAllowAllRequestsAction(
|
||||
std::optional<RequestAction> GetAllowAllRequestsAction(
|
||||
const RequestParams& params) const override;
|
||||
absl::optional<RequestAction> GetBeforeRequestActionIgnoringAncestors(
|
||||
std::optional<RequestAction> GetBeforeRequestActionIgnoringAncestors(
|
||||
const RequestParams& params) const override;
|
||||
|
||||
// Returns the highest priority action from
|
||||
// |flat::IndexType_before_request_except_allow_all_requests| index.
|
||||
absl::optional<RequestAction> GetBeforeRequestActionHelper(
|
||||
std::optional<RequestAction> GetBeforeRequestActionHelper(
|
||||
const RequestParams& params) const;
|
||||
|
||||
const url_pattern_index::flat::UrlRule* GetMatchingRule(
|
||||
|
@ -360,7 +360,7 @@ std::unique_ptr<RulesetMatcher> RulesetInfo::TakeMatcher() {
|
||||
return std::move(matcher_);
|
||||
}
|
||||
|
||||
const absl::optional<LoadRulesetResult>& RulesetInfo::load_ruleset_result()
|
||||
const std::optional<LoadRulesetResult>& RulesetInfo::load_ruleset_result()
|
||||
const {
|
||||
// |matcher_| is valid only on success.
|
||||
DCHECK_EQ(load_ruleset_result_ == LoadRulesetResult::kSuccess, !!matcher_);
|
||||
@ -449,7 +449,7 @@ void FileSequenceHelper::UpdateDynamicRules(
|
||||
DCHECK(!dynamic_ruleset.expected_checksum());
|
||||
|
||||
auto log_status_and_dispatch_callback = [&ui_callback, &load_data](
|
||||
absl::optional<std::string> error,
|
||||
std::optional<std::string> error,
|
||||
UpdateDynamicRulesStatus status) {
|
||||
base::UmaHistogramEnumeration(kUpdateDynamicRulesStatusHistogram, status);
|
||||
|
||||
@ -486,7 +486,7 @@ void FileSequenceHelper::UpdateDynamicRules(
|
||||
}
|
||||
|
||||
// Success.
|
||||
log_status_and_dispatch_callback(absl::nullopt, status);
|
||||
log_status_and_dispatch_callback(std::nullopt, status);
|
||||
}
|
||||
|
||||
void FileSequenceHelper::OnRulesetsIndexed(LoadRulesetsUICallback ui_callback,
|
||||
|
@ -6,9 +6,9 @@
|
||||
#define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_FILE_SEQUENCE_HELPER_H_
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/functional/callback_forward.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/version.h"
|
||||
@ -16,7 +16,6 @@
|
||||
#include "extensions/browser/api/declarative_net_request/file_backed_ruleset_source.h"
|
||||
#include "extensions/browser/api/declarative_net_request/ruleset_matcher.h"
|
||||
#include "extensions/common/extension_id.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace extensions {
|
||||
|
||||
@ -51,21 +50,21 @@ class RulesetInfo {
|
||||
// Clients should set a new checksum if the checksum stored in prefs should
|
||||
// be updated.
|
||||
void set_new_checksum(int new_checksum) { new_checksum_ = new_checksum; }
|
||||
absl::optional<int> new_checksum() const { return new_checksum_; }
|
||||
std::optional<int> new_checksum() const { return new_checksum_; }
|
||||
|
||||
// The expected checksum for the indexed ruleset.
|
||||
void set_expected_checksum(int checksum) { expected_checksum_ = checksum; }
|
||||
absl::optional<int> expected_checksum() const { return expected_checksum_; }
|
||||
std::optional<int> expected_checksum() const { return expected_checksum_; }
|
||||
|
||||
// Whether indexing of the ruleset was successful.
|
||||
void set_indexing_successful(bool val) { indexing_successful_ = val; }
|
||||
absl::optional<bool> indexing_successful() const {
|
||||
std::optional<bool> indexing_successful() const {
|
||||
return indexing_successful_;
|
||||
}
|
||||
|
||||
// Returns the result of loading the ruleset. The return value is valid (not
|
||||
// equal to absl::nullopt) iff CreateVerifiedMatcher() has been called.
|
||||
const absl::optional<LoadRulesetResult>& load_ruleset_result() const;
|
||||
// equal to std::nullopt) iff CreateVerifiedMatcher() has been called.
|
||||
const std::optional<LoadRulesetResult>& load_ruleset_result() const;
|
||||
|
||||
// Whether the ruleset loaded successfully.
|
||||
bool did_load_successfully() const {
|
||||
@ -80,18 +79,18 @@ class RulesetInfo {
|
||||
FileBackedRulesetSource source_;
|
||||
|
||||
// The expected checksum of the indexed ruleset.
|
||||
absl::optional<int> expected_checksum_;
|
||||
std::optional<int> expected_checksum_;
|
||||
|
||||
// Stores the result of creating a verified matcher from the |source_|.
|
||||
std::unique_ptr<RulesetMatcher> matcher_;
|
||||
absl::optional<LoadRulesetResult> load_ruleset_result_;
|
||||
std::optional<LoadRulesetResult> load_ruleset_result_;
|
||||
|
||||
// The new checksum to be persisted to prefs. A new checksum should only be
|
||||
// set in case of flatbuffer version mismatch.
|
||||
absl::optional<int> new_checksum_;
|
||||
std::optional<int> new_checksum_;
|
||||
|
||||
// Whether the indexing of this ruleset was successful.
|
||||
absl::optional<bool> indexing_successful_;
|
||||
std::optional<bool> indexing_successful_;
|
||||
};
|
||||
|
||||
// Helper to pass information related to the ruleset being loaded.
|
||||
@ -139,7 +138,7 @@ class FileSequenceHelper {
|
||||
// thread once loading is done with the LoadRequestData and an optional error
|
||||
// string.
|
||||
using UpdateDynamicRulesUICallback =
|
||||
base::OnceCallback<void(LoadRequestData, absl::optional<std::string>)>;
|
||||
base::OnceCallback<void(LoadRequestData, std::optional<std::string>)>;
|
||||
void UpdateDynamicRules(
|
||||
LoadRequestData load_data,
|
||||
std::vector<int> rule_ids_to_remove,
|
||||
|
@ -44,8 +44,8 @@ api::declarative_net_request::Rule GetAPIRule(const TestRule& rule) {
|
||||
|
||||
struct TestLoadRulesetInfo {
|
||||
bool has_new_checksum = false;
|
||||
absl::optional<bool> indexing_successful;
|
||||
absl::optional<LoadRulesetResult> load_result;
|
||||
std::optional<bool> indexing_successful;
|
||||
std::optional<LoadRulesetResult> load_result;
|
||||
};
|
||||
|
||||
struct TestCase {
|
||||
@ -83,13 +83,13 @@ class FileSequenceHelperTest : public ExtensionsTest {
|
||||
std::vector<api::declarative_net_request::Rule> rules_to_add,
|
||||
ReadJSONRulesResult::Status expected_read_status,
|
||||
UpdateDynamicRulesStatus expected_update_status,
|
||||
absl::optional<std::string> expected_error,
|
||||
std::optional<std::string> expected_error,
|
||||
bool expected_did_load_successfully) {
|
||||
base::RunLoop run_loop;
|
||||
auto add_rules_callback = base::BindOnce(
|
||||
[](base::RunLoop* run_loop, bool expected_did_load_successfully,
|
||||
absl::optional<std::string> expected_error, LoadRequestData data,
|
||||
absl::optional<std::string> error) {
|
||||
std::optional<std::string> expected_error, LoadRequestData data,
|
||||
std::optional<std::string> error) {
|
||||
EXPECT_EQ(1u, data.rulesets.size());
|
||||
EXPECT_EQ(expected_error, error) << error.value_or("no actual error");
|
||||
EXPECT_EQ(expected_did_load_successfully,
|
||||
@ -312,7 +312,7 @@ TEST_F(FileSequenceHelperTest, UpdateDynamicRules) {
|
||||
TestAddDynamicRules(source.Clone(), std::move(api_rules),
|
||||
ReadJSONRulesResult::Status::kFileDoesNotExist,
|
||||
UpdateDynamicRulesStatus::kSuccess,
|
||||
absl::nullopt /* expected_error */,
|
||||
std::nullopt /* expected_error */,
|
||||
true /* expected_did_load_successfully*/);
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ TEST_F(FileSequenceHelperTest, UpdateDynamicRules) {
|
||||
TestAddDynamicRules(source.Clone(), std::move(api_rules),
|
||||
ReadJSONRulesResult::Status::kJSONParseError,
|
||||
UpdateDynamicRulesStatus::kSuccess,
|
||||
absl::nullopt /* expected_error */,
|
||||
std::nullopt /* expected_error */,
|
||||
true /* expected_did_load_successfully*/);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "extensions/browser/api/declarative_net_request/filter_list_converter/converter.h"
|
||||
|
||||
#include <optional>
|
||||
#include "base/check_op.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/file_util.h"
|
||||
@ -12,7 +13,6 @@
|
||||
#include "base/json/json_reader.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace extensions {
|
||||
namespace declarative_net_request {
|
||||
@ -29,7 +29,7 @@ void TestConversion(std::vector<std::string> filter_list_rules,
|
||||
std::string filterlist = base::JoinString(filter_list_rules, "\n");
|
||||
CHECK(base::WriteFile(input_path, filterlist));
|
||||
|
||||
absl::optional<base::Value> expected_json =
|
||||
std::optional<base::Value> expected_json =
|
||||
base::JSONReader::Read(json_result);
|
||||
CHECK(expected_json.has_value());
|
||||
|
||||
|
@ -74,16 +74,16 @@ CreateIndexBuilders(flatbuffers::FlatBufferBuilder* builder) {
|
||||
FlatOffset<flat::UrlTransform> BuildTransformOffset(
|
||||
flatbuffers::FlatBufferBuilder* builder,
|
||||
const dnr_api::URLTransform& transform) {
|
||||
auto create_string_offset =
|
||||
[builder](const absl::optional<std::string>& str) {
|
||||
if (!str)
|
||||
return FlatStringOffset();
|
||||
auto create_string_offset = [builder](const std::optional<std::string>& str) {
|
||||
if (!str) {
|
||||
return FlatStringOffset();
|
||||
}
|
||||
|
||||
return builder->CreateSharedString(*str);
|
||||
};
|
||||
return builder->CreateSharedString(*str);
|
||||
};
|
||||
|
||||
auto skip_separator_and_create_string_offset =
|
||||
[builder](const absl::optional<std::string>& str, char separator) {
|
||||
[builder](const std::optional<std::string>& str, char separator) {
|
||||
if (!str)
|
||||
return FlatStringOffset();
|
||||
|
||||
@ -93,7 +93,7 @@ FlatOffset<flat::UrlTransform> BuildTransformOffset(
|
||||
return builder->CreateSharedString(str->c_str() + 1, str->length() - 1);
|
||||
};
|
||||
|
||||
auto should_clear_component = [](const absl::optional<std::string>& str) {
|
||||
auto should_clear_component = [](const std::optional<std::string>& str) {
|
||||
return str && str->empty();
|
||||
};
|
||||
|
||||
|
@ -178,10 +178,10 @@ IndexedRule CreateIndexedRule(
|
||||
std::string url_pattern,
|
||||
std::vector<std::string> domains,
|
||||
std::vector<std::string> excluded_domains,
|
||||
absl::optional<std::string> redirect_url,
|
||||
std::optional<std::string> redirect_url,
|
||||
dnr_api::RuleActionType action_type,
|
||||
absl::optional<dnr_api::URLTransform> url_transform,
|
||||
absl::optional<std::string> regex_substitution,
|
||||
std::optional<dnr_api::URLTransform> url_transform,
|
||||
std::optional<std::string> regex_substitution,
|
||||
std::vector<dnr_api::ModifyHeaderInfo> request_headers,
|
||||
std::vector<dnr_api::ModifyHeaderInfo> response_headers) {
|
||||
IndexedRule rule;
|
||||
@ -431,15 +431,15 @@ TEST_F(FlatRulesetIndexerTest, MultipleRules) {
|
||||
flat_rule::ElementType_OBJECT, flat_rule::ActivationType_NONE,
|
||||
flat_rule::UrlPatternType_SUBSTRING, flat_rule::AnchorType_NONE,
|
||||
flat_rule::AnchorType_BOUNDARY, "google.com", {"a.com"}, {"x.a.com"},
|
||||
absl::nullopt, dnr_api::RuleActionType::kBlock, absl::nullopt,
|
||||
absl::nullopt, {}, {}));
|
||||
std::nullopt, dnr_api::RuleActionType::kBlock, std::nullopt, std::nullopt,
|
||||
{}, {}));
|
||||
rules_to_index.push_back(CreateIndexedRule(
|
||||
2, kMinValidPriority, flat_rule::OptionFlag_APPLIES_TO_THIRD_PARTY,
|
||||
flat_rule::ElementType_IMAGE | flat_rule::ElementType_WEBSOCKET,
|
||||
flat_rule::ActivationType_NONE, flat_rule::UrlPatternType_WILDCARDED,
|
||||
flat_rule::AnchorType_NONE, flat_rule::AnchorType_NONE, "*google*",
|
||||
{"a.com"}, {}, absl::nullopt, dnr_api::RuleActionType::kBlock,
|
||||
absl::nullopt, absl::nullopt, {}, {}));
|
||||
{"a.com"}, {}, std::nullopt, dnr_api::RuleActionType::kBlock,
|
||||
std::nullopt, std::nullopt, {}, {}));
|
||||
|
||||
// Redirect rules.
|
||||
rules_to_index.push_back(CreateIndexedRule(
|
||||
@ -447,27 +447,27 @@ TEST_F(FlatRulesetIndexerTest, MultipleRules) {
|
||||
flat_rule::ElementType_IMAGE, flat_rule::ActivationType_NONE,
|
||||
flat_rule::UrlPatternType_SUBSTRING, flat_rule::AnchorType_SUBDOMAIN,
|
||||
flat_rule::AnchorType_BOUNDARY, "google.com", {}, {},
|
||||
"http://example1.com", dnr_api::RuleActionType::kRedirect, absl::nullopt,
|
||||
absl::nullopt, {}, {}));
|
||||
"http://example1.com", dnr_api::RuleActionType::kRedirect, std::nullopt,
|
||||
std::nullopt, {}, {}));
|
||||
rules_to_index.push_back(CreateIndexedRule(
|
||||
10, 2, flat_rule::OptionFlag_NONE,
|
||||
flat_rule::ElementType_SUBDOCUMENT | flat_rule::ElementType_SCRIPT,
|
||||
flat_rule::ActivationType_NONE, flat_rule::UrlPatternType_SUBSTRING,
|
||||
flat_rule::AnchorType_NONE, flat_rule::AnchorType_NONE, "example1", {},
|
||||
{"a.com"}, "http://example2.com", dnr_api::RuleActionType::kRedirect,
|
||||
absl::nullopt, absl::nullopt, {}, {}));
|
||||
std::nullopt, std::nullopt, {}, {}));
|
||||
rules_to_index.push_back(CreateIndexedRule(
|
||||
9, 3, flat_rule::OptionFlag_NONE, flat_rule::ElementType_NONE,
|
||||
flat_rule::ActivationType_NONE, flat_rule::UrlPatternType_WILDCARDED,
|
||||
flat_rule::AnchorType_NONE, flat_rule::AnchorType_NONE, "*", {}, {},
|
||||
"http://example2.com", dnr_api::RuleActionType::kRedirect, absl::nullopt,
|
||||
absl::nullopt, {}, {}));
|
||||
"http://example2.com", dnr_api::RuleActionType::kRedirect, std::nullopt,
|
||||
std::nullopt, {}, {}));
|
||||
rules_to_index.push_back(CreateIndexedRule(
|
||||
100, 3, flat_rule::OptionFlag_NONE, flat_rule::ElementType_NONE,
|
||||
flat_rule::ActivationType_NONE, flat_rule::UrlPatternType_WILDCARDED,
|
||||
flat_rule::AnchorType_NONE, flat_rule::AnchorType_NONE, "*", {}, {},
|
||||
absl::nullopt, dnr_api::RuleActionType::kRedirect, CreateUrlTransform(),
|
||||
absl::nullopt, {}, {}));
|
||||
std::nullopt, dnr_api::RuleActionType::kRedirect, CreateUrlTransform(),
|
||||
std::nullopt, {}, {}));
|
||||
|
||||
// Allow rules.
|
||||
rules_to_index.push_back(CreateIndexedRule(
|
||||
@ -475,24 +475,24 @@ TEST_F(FlatRulesetIndexerTest, MultipleRules) {
|
||||
flat_rule::ElementType_PING | flat_rule::ElementType_SCRIPT,
|
||||
flat_rule::ActivationType_NONE, flat_rule::UrlPatternType_SUBSTRING,
|
||||
flat_rule::AnchorType_SUBDOMAIN, flat_rule::AnchorType_NONE,
|
||||
"example1.com", {"xyz.com"}, {}, absl::nullopt,
|
||||
dnr_api::RuleActionType::kAllow, absl::nullopt, absl::nullopt, {}, {}));
|
||||
"example1.com", {"xyz.com"}, {}, std::nullopt,
|
||||
dnr_api::RuleActionType::kAllow, std::nullopt, std::nullopt, {}, {}));
|
||||
rules_to_index.push_back(CreateIndexedRule(
|
||||
16, kMinValidPriority,
|
||||
flat_rule::OptionFlag_IS_ALLOWLIST |
|
||||
flat_rule::OptionFlag_IS_CASE_INSENSITIVE,
|
||||
flat_rule::ElementType_IMAGE, flat_rule::ActivationType_NONE,
|
||||
flat_rule::UrlPatternType_SUBSTRING, flat_rule::AnchorType_NONE,
|
||||
flat_rule::AnchorType_NONE, "example3", {}, {}, absl::nullopt,
|
||||
dnr_api::RuleActionType::kAllow, absl::nullopt, absl::nullopt, {}, {}));
|
||||
flat_rule::AnchorType_NONE, "example3", {}, {}, std::nullopt,
|
||||
dnr_api::RuleActionType::kAllow, std::nullopt, std::nullopt, {}, {}));
|
||||
|
||||
// Allow all requests rule.
|
||||
rules_to_index.push_back(CreateIndexedRule(
|
||||
22, 3, flat_rule::OptionFlag_NONE, flat_rule::ElementType_SUBDOCUMENT,
|
||||
flat_rule::ActivationType_NONE, flat_rule::UrlPatternType_SUBSTRING,
|
||||
flat_rule::AnchorType_NONE, flat_rule::AnchorType_NONE, "example.com", {},
|
||||
{}, absl::nullopt, dnr_api::RuleActionType::kAllowAllRequests,
|
||||
absl::nullopt, absl::nullopt, {}, {}));
|
||||
{}, std::nullopt, dnr_api::RuleActionType::kAllowAllRequests,
|
||||
std::nullopt, std::nullopt, {}, {}));
|
||||
|
||||
// Modify headers rules.
|
||||
std::vector<dnr_api::ModifyHeaderInfo> request_headers_1;
|
||||
@ -501,7 +501,7 @@ TEST_F(FlatRulesetIndexerTest, MultipleRules) {
|
||||
|
||||
std::vector<dnr_api::ModifyHeaderInfo> response_headers_1;
|
||||
response_headers_1.push_back(CreateModifyHeaderInfo(
|
||||
dnr_api::HeaderOperation::kRemove, "set-cookie", absl::nullopt));
|
||||
dnr_api::HeaderOperation::kRemove, "set-cookie", std::nullopt));
|
||||
|
||||
response_headers_1.push_back(CreateModifyHeaderInfo(
|
||||
dnr_api::HeaderOperation::kAppend, "custom-1", "value-1"));
|
||||
@ -513,20 +513,20 @@ TEST_F(FlatRulesetIndexerTest, MultipleRules) {
|
||||
23, kMinValidPriority, flat_rule::OptionFlag_IS_CASE_INSENSITIVE,
|
||||
flat_rule::ElementType_SUBDOCUMENT, flat_rule::ActivationType_NONE,
|
||||
flat_rule::UrlPatternType_SUBSTRING, flat_rule::AnchorType_SUBDOMAIN,
|
||||
flat_rule::AnchorType_NONE, "example.com", {}, {}, absl::nullopt,
|
||||
dnr_api::RuleActionType::kModifyHeaders, absl::nullopt, absl::nullopt,
|
||||
flat_rule::AnchorType_NONE, "example.com", {}, {}, std::nullopt,
|
||||
dnr_api::RuleActionType::kModifyHeaders, std::nullopt, std::nullopt,
|
||||
std::move(request_headers_1), std::move(response_headers_1)));
|
||||
|
||||
std::vector<dnr_api::ModifyHeaderInfo> request_headers_2;
|
||||
request_headers_2.push_back(CreateModifyHeaderInfo(
|
||||
dnr_api::HeaderOperation::kRemove, "referer", absl::nullopt));
|
||||
dnr_api::HeaderOperation::kRemove, "referer", std::nullopt));
|
||||
|
||||
rules_to_index.push_back(CreateIndexedRule(
|
||||
24, kMinValidPriority, flat_rule::OptionFlag_IS_CASE_INSENSITIVE,
|
||||
flat_rule::ElementType_SUBDOCUMENT, flat_rule::ActivationType_NONE,
|
||||
flat_rule::UrlPatternType_SUBSTRING, flat_rule::AnchorType_SUBDOMAIN,
|
||||
flat_rule::AnchorType_NONE, "example.com", {}, {}, absl::nullopt,
|
||||
dnr_api::RuleActionType::kModifyHeaders, absl::nullopt, absl::nullopt,
|
||||
flat_rule::AnchorType_NONE, "example.com", {}, {}, std::nullopt,
|
||||
dnr_api::RuleActionType::kModifyHeaders, std::nullopt, std::nullopt,
|
||||
std::move(request_headers_2), {}));
|
||||
|
||||
// Note: It's unsafe to store/return pointers to a mutable vector since the
|
||||
@ -559,37 +559,37 @@ TEST_F(FlatRulesetIndexerTest, RegexRules) {
|
||||
flat_rule::ElementType_OBJECT, flat_rule::ActivationType_NONE,
|
||||
flat_rule::UrlPatternType_REGEXP, flat_rule::AnchorType_NONE,
|
||||
flat_rule::AnchorType_NONE, R"(^https://(abc|def))", {"a.com"},
|
||||
{"x.a.com"}, absl::nullopt, dnr_api::RuleActionType::kBlock,
|
||||
absl::nullopt, absl::nullopt, {}, {}));
|
||||
{"x.a.com"}, std::nullopt, dnr_api::RuleActionType::kBlock, std::nullopt,
|
||||
std::nullopt, {}, {}));
|
||||
// Redirect rule.
|
||||
rules_to_index.push_back(CreateIndexedRule(
|
||||
15, 2, flat_rule::OptionFlag_APPLIES_TO_FIRST_PARTY,
|
||||
flat_rule::ElementType_IMAGE, flat_rule::ActivationType_NONE,
|
||||
flat_rule::UrlPatternType_REGEXP, flat_rule::AnchorType_NONE,
|
||||
flat_rule::AnchorType_NONE, R"(^(http|https))", {}, {},
|
||||
"http://example1.com", dnr_api::RuleActionType::kRedirect, absl::nullopt,
|
||||
absl::nullopt, {}, {}));
|
||||
"http://example1.com", dnr_api::RuleActionType::kRedirect, std::nullopt,
|
||||
std::nullopt, {}, {}));
|
||||
// Regex substitution rule.
|
||||
rules_to_index.push_back(CreateIndexedRule(
|
||||
10, 29, flat_rule::OptionFlag_APPLIES_TO_FIRST_PARTY,
|
||||
flat_rule::ElementType_SCRIPT, flat_rule::ActivationType_NONE,
|
||||
flat_rule::UrlPatternType_REGEXP, flat_rule::AnchorType_NONE,
|
||||
flat_rule::AnchorType_NONE, R"((\d+\).google.com)", {}, {}, absl::nullopt,
|
||||
dnr_api::RuleActionType::kRedirect, absl::nullopt,
|
||||
flat_rule::AnchorType_NONE, R"((\d+\).google.com)", {}, {}, std::nullopt,
|
||||
dnr_api::RuleActionType::kRedirect, std::nullopt,
|
||||
R"(http://redirect.com?num=\1)", {}, {}));
|
||||
|
||||
// Modify headers rule.
|
||||
std::vector<dnr_api::ModifyHeaderInfo> request_headers;
|
||||
request_headers.push_back(CreateModifyHeaderInfo(
|
||||
dnr_api::HeaderOperation::kRemove, "referer", absl::nullopt));
|
||||
dnr_api::HeaderOperation::kRemove, "referer", std::nullopt));
|
||||
request_headers.push_back(CreateModifyHeaderInfo(
|
||||
dnr_api::HeaderOperation::kSet, "cookie", "sample-cookie"));
|
||||
rules_to_index.push_back(CreateIndexedRule(
|
||||
21, kMinValidPriority, flat_rule::OptionFlag_IS_CASE_INSENSITIVE,
|
||||
flat_rule::ElementType_SUBDOCUMENT, flat_rule::ActivationType_NONE,
|
||||
flat_rule::UrlPatternType_REGEXP, flat_rule::AnchorType_NONE,
|
||||
flat_rule::AnchorType_NONE, "*", {}, {}, absl::nullopt,
|
||||
dnr_api::RuleActionType::kModifyHeaders, absl::nullopt, absl::nullopt,
|
||||
flat_rule::AnchorType_NONE, "*", {}, {}, std::nullopt,
|
||||
dnr_api::RuleActionType::kModifyHeaders, std::nullopt, std::nullopt,
|
||||
std::move(request_headers), {}));
|
||||
|
||||
flatbuffers::DetachedBuffer buffer;
|
||||
|
@ -52,7 +52,7 @@ class UrlFilterParser {
|
||||
|
||||
// This sets the |url_pattern_type|, |anchor_left|, |anchor_right| and
|
||||
// |url_pattern| fields on the |indexed_rule_|.
|
||||
static void Parse(absl::optional<std::string> url_filter,
|
||||
static void Parse(std::optional<std::string> url_filter,
|
||||
IndexedRule* indexed_rule) {
|
||||
DCHECK(indexed_rule);
|
||||
UrlFilterParser(url_filter ? std::move(*url_filter) : std::string(),
|
||||
@ -176,8 +176,7 @@ uint8_t GetActivationTypes(const dnr_api::Rule& parsed_rule) {
|
||||
// Returns a bitmask of flat_rule::RequestMethod corresponding to passed
|
||||
// `request_methods`.
|
||||
uint16_t GetRequestMethodsMask(
|
||||
const absl::optional<std::vector<dnr_api::RequestMethod>>&
|
||||
request_methods) {
|
||||
const std::optional<std::vector<dnr_api::RequestMethod>>& request_methods) {
|
||||
uint16_t mask = flat_rule::RequestMethod_NONE;
|
||||
if (!request_methods)
|
||||
return mask;
|
||||
@ -214,7 +213,7 @@ ParseResult ComputeRequestMethods(const dnr_api::Rule& rule,
|
||||
// Returns a bitmask of flat_rule::ElementType corresponding to passed
|
||||
// |resource_types|.
|
||||
uint16_t GetResourceTypesMask(
|
||||
const absl::optional<std::vector<dnr_api::ResourceType>>& resource_types) {
|
||||
const std::optional<std::vector<dnr_api::ResourceType>>& resource_types) {
|
||||
uint16_t mask = flat_rule::ElementType_NONE;
|
||||
if (!resource_types)
|
||||
return mask;
|
||||
@ -268,7 +267,7 @@ ParseResult ComputeElementTypes(const dnr_api::Rule& rule,
|
||||
// Lower-cases and sorts |domains|, as required by the url_pattern_index
|
||||
// component and stores the result in |output|. Returns false in case of
|
||||
// failure, when one of the input strings contains non-ascii characters.
|
||||
bool CanonicalizeDomains(absl::optional<std::vector<std::string>> domains,
|
||||
bool CanonicalizeDomains(std::optional<std::vector<std::string>> domains,
|
||||
std::vector<std::string>* output) {
|
||||
DCHECK(output);
|
||||
DCHECK(output->empty());
|
||||
@ -297,7 +296,7 @@ bool IsRedirectUrlRelative(const std::string& redirect_url) {
|
||||
return !redirect_url.empty() && redirect_url[0] == '/';
|
||||
}
|
||||
|
||||
bool IsValidTransformScheme(const absl::optional<std::string>& scheme) {
|
||||
bool IsValidTransformScheme(const std::optional<std::string>& scheme) {
|
||||
if (!scheme)
|
||||
return true;
|
||||
|
||||
@ -308,7 +307,7 @@ bool IsValidTransformScheme(const absl::optional<std::string>& scheme) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsValidPort(const absl::optional<std::string>& port) {
|
||||
bool IsValidPort(const std::optional<std::string>& port) {
|
||||
if (!port || port->empty())
|
||||
return true;
|
||||
|
||||
@ -316,7 +315,7 @@ bool IsValidPort(const absl::optional<std::string>& port) {
|
||||
return base::StringToUint(*port, &port_num) && port_num <= 65535;
|
||||
}
|
||||
|
||||
bool IsEmptyOrStartsWith(const absl::optional<std::string>& str,
|
||||
bool IsEmptyOrStartsWith(const std::optional<std::string>& str,
|
||||
char starts_with) {
|
||||
return !str || str->empty() || str->at(0) == starts_with;
|
||||
}
|
||||
|
@ -6,13 +6,12 @@
|
||||
#define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_INDEXED_RULE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "base/containers/flat_set.h"
|
||||
#include "components/url_pattern_index/flat/url_pattern_index_generated.h"
|
||||
#include "extensions/common/api/declarative_net_request.h"
|
||||
#include "extensions/common/api/declarative_net_request/constants.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
class GURL;
|
||||
|
||||
@ -68,11 +67,11 @@ struct IndexedRule {
|
||||
// Note: For redirect rules, exactly one of |redirect_url|,
|
||||
// |regex_substitution| or |url_transform| will be set.
|
||||
// The redirect url for the rule.
|
||||
absl::optional<std::string> redirect_url;
|
||||
std::optional<std::string> redirect_url;
|
||||
// The regex substitution for this rule.
|
||||
absl::optional<std::string> regex_substitution;
|
||||
std::optional<std::string> regex_substitution;
|
||||
// UrlTransform for this rule.
|
||||
absl::optional<api::declarative_net_request::URLTransform> url_transform;
|
||||
std::optional<api::declarative_net_request::URLTransform> url_transform;
|
||||
|
||||
// List of request headers to modify. Valid iff this is a modify headers rule.
|
||||
std::vector<api::declarative_net_request::ModifyHeaderInfo>
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
@ -17,7 +18,6 @@
|
||||
#include "extensions/browser/api/declarative_net_request/indexed_rule.h"
|
||||
#include "extensions/common/api/declarative_net_request.h"
|
||||
#include "extensions/common/api/declarative_net_request/constants.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
using extensions::api::declarative_net_request::Rule;
|
||||
@ -28,7 +28,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
FuzzedDataProvider provider(data, size);
|
||||
|
||||
// Make a random `Rule`.
|
||||
absl::optional<base::Value> value =
|
||||
std::optional<base::Value> value =
|
||||
base::JSONReader::Read(provider.ConsumeRandomLengthString());
|
||||
if (!value || !value->is_dict())
|
||||
return 0;
|
||||
|
@ -54,8 +54,8 @@ dnr_api::Rule CreateGenericParsedRule() {
|
||||
|
||||
dnr_api::HeaderInfo CreateHeaderInfo(
|
||||
std::string header,
|
||||
absl::optional<std::vector<std::string>> values,
|
||||
absl::optional<std::vector<std::string>> excluded_values) {
|
||||
std::optional<std::vector<std::string>> values,
|
||||
std::optional<std::vector<std::string>> excluded_values) {
|
||||
dnr_api::HeaderInfo info;
|
||||
|
||||
info.header = std::move(header);
|
||||
@ -93,7 +93,7 @@ TEST_F(IndexedRuleTest, IDParsing) {
|
||||
TEST_F(IndexedRuleTest, PriorityParsing) {
|
||||
struct {
|
||||
dnr_api::RuleActionType action_type;
|
||||
absl::optional<int> priority;
|
||||
std::optional<int> priority;
|
||||
const ParseResult expected_result;
|
||||
// Only valid if |expected_result| is SUCCESS.
|
||||
const uint32_t expected_priority;
|
||||
@ -102,7 +102,7 @@ TEST_F(IndexedRuleTest, PriorityParsing) {
|
||||
ParseResult::ERROR_INVALID_RULE_PRIORITY, kDefaultPriority},
|
||||
{dnr_api::RuleActionType::kRedirect, kMinValidPriority,
|
||||
ParseResult::SUCCESS, kMinValidPriority},
|
||||
{dnr_api::RuleActionType::kRedirect, absl::nullopt, ParseResult::SUCCESS,
|
||||
{dnr_api::RuleActionType::kRedirect, std::nullopt, ParseResult::SUCCESS,
|
||||
kDefaultPriority},
|
||||
{dnr_api::RuleActionType::kRedirect, kMinValidPriority + 1,
|
||||
ParseResult::SUCCESS, kMinValidPriority + 1},
|
||||
@ -142,11 +142,11 @@ TEST_F(IndexedRuleTest, OptionsParsing) {
|
||||
struct {
|
||||
const dnr_api::DomainType domain_type;
|
||||
const dnr_api::RuleActionType action_type;
|
||||
absl::optional<bool> is_url_filter_case_sensitive;
|
||||
std::optional<bool> is_url_filter_case_sensitive;
|
||||
const uint8_t expected_options;
|
||||
} cases[] = {
|
||||
{dnr_api::DomainType::kNone, dnr_api::RuleActionType::kBlock,
|
||||
absl::nullopt,
|
||||
std::nullopt,
|
||||
flat_rule::OptionFlag_APPLIES_TO_THIRD_PARTY |
|
||||
flat_rule::OptionFlag_APPLIES_TO_FIRST_PARTY |
|
||||
flat_rule::OptionFlag_IS_CASE_INSENSITIVE},
|
||||
@ -180,27 +180,27 @@ TEST_F(IndexedRuleTest, ResourceTypesParsing) {
|
||||
using ResourceTypeVec = std::vector<dnr_api::ResourceType>;
|
||||
|
||||
struct {
|
||||
absl::optional<ResourceTypeVec> resource_types;
|
||||
absl::optional<ResourceTypeVec> excluded_resource_types;
|
||||
std::optional<ResourceTypeVec> resource_types;
|
||||
std::optional<ResourceTypeVec> excluded_resource_types;
|
||||
const ParseResult expected_result;
|
||||
// Only valid if |expected_result| is SUCCESS.
|
||||
const uint16_t expected_element_types;
|
||||
} cases[] = {
|
||||
{absl::nullopt, absl::nullopt, ParseResult::SUCCESS,
|
||||
{std::nullopt, std::nullopt, ParseResult::SUCCESS,
|
||||
flat_rule::ElementType_ANY & ~flat_rule::ElementType_MAIN_FRAME},
|
||||
{absl::nullopt, ResourceTypeVec({dnr_api::ResourceType::kScript}),
|
||||
{std::nullopt, ResourceTypeVec({dnr_api::ResourceType::kScript}),
|
||||
ParseResult::SUCCESS,
|
||||
flat_rule::ElementType_ANY & ~flat_rule::ElementType_SCRIPT},
|
||||
{ResourceTypeVec(
|
||||
{dnr_api::ResourceType::kScript, dnr_api::ResourceType::kImage}),
|
||||
absl::nullopt, ParseResult::SUCCESS,
|
||||
std::nullopt, ParseResult::SUCCESS,
|
||||
flat_rule::ElementType_SCRIPT | flat_rule::ElementType_IMAGE},
|
||||
{ResourceTypeVec(
|
||||
{dnr_api::ResourceType::kScript, dnr_api::ResourceType::kImage}),
|
||||
ResourceTypeVec({dnr_api::ResourceType::kScript}),
|
||||
ParseResult::ERROR_RESOURCE_TYPE_DUPLICATED,
|
||||
flat_rule::ElementType_NONE},
|
||||
{absl::nullopt,
|
||||
{std::nullopt,
|
||||
ResourceTypeVec(
|
||||
{dnr_api::ResourceType::kMainFrame, dnr_api::ResourceType::kSubFrame,
|
||||
dnr_api::ResourceType::kStylesheet, dnr_api::ResourceType::kScript,
|
||||
@ -240,7 +240,7 @@ TEST_F(IndexedRuleTest, ResourceTypesParsing) {
|
||||
|
||||
TEST_F(IndexedRuleTest, UrlFilterParsing) {
|
||||
struct {
|
||||
absl::optional<std::string> input_url_filter;
|
||||
std::optional<std::string> input_url_filter;
|
||||
|
||||
// Only valid if |expected_result| is SUCCESS.
|
||||
const flat_rule::UrlPatternType expected_url_pattern_type;
|
||||
@ -250,7 +250,7 @@ TEST_F(IndexedRuleTest, UrlFilterParsing) {
|
||||
|
||||
const ParseResult expected_result;
|
||||
} cases[] = {
|
||||
{absl::nullopt, flat_rule::UrlPatternType_SUBSTRING,
|
||||
{std::nullopt, flat_rule::UrlPatternType_SUBSTRING,
|
||||
flat_rule::AnchorType_NONE, flat_rule::AnchorType_NONE, "",
|
||||
ParseResult::SUCCESS},
|
||||
{"", flat_rule::UrlPatternType_SUBSTRING, flat_rule::AnchorType_NONE,
|
||||
@ -318,12 +318,12 @@ TEST_F(IndexedRuleTest, UrlFilterParsing) {
|
||||
TEST_F(IndexedRuleTest, CaseInsensitiveLowerCased) {
|
||||
const std::string kPattern = "/QUERY";
|
||||
struct {
|
||||
absl::optional<bool> is_url_filter_case_sensitive;
|
||||
std::optional<bool> is_url_filter_case_sensitive;
|
||||
std::string expected_pattern;
|
||||
} test_cases[] = {
|
||||
{false, "/query"},
|
||||
{true, "/QUERY"},
|
||||
{absl::nullopt, "/query"} // By default patterns are case insensitive.
|
||||
{std::nullopt, "/query"} // By default patterns are case insensitive.
|
||||
};
|
||||
|
||||
for (auto& test_case : test_cases) {
|
||||
@ -343,16 +343,16 @@ TEST_F(IndexedRuleTest, CaseInsensitiveLowerCased) {
|
||||
TEST_F(IndexedRuleTest, DomainsParsing) {
|
||||
using DomainVec = std::vector<std::string>;
|
||||
struct {
|
||||
absl::optional<DomainVec> domains;
|
||||
absl::optional<DomainVec> excluded_domains;
|
||||
std::optional<DomainVec> domains;
|
||||
std::optional<DomainVec> excluded_domains;
|
||||
const ParseResult expected_result;
|
||||
// Only valid if |expected_result| is SUCCESS.
|
||||
const DomainVec expected_domains;
|
||||
const DomainVec expected_excluded_domains;
|
||||
} cases[] = {
|
||||
{absl::nullopt, absl::nullopt, ParseResult::SUCCESS, {}, {}},
|
||||
{{{}}, absl::nullopt, ParseResult::ERROR_EMPTY_DOMAINS_LIST, {}, {}},
|
||||
{absl::nullopt, {{}}, ParseResult::SUCCESS, {}, {}},
|
||||
{std::nullopt, std::nullopt, ParseResult::SUCCESS, {}, {}},
|
||||
{{{}}, std::nullopt, ParseResult::ERROR_EMPTY_DOMAINS_LIST, {}, {}},
|
||||
{std::nullopt, {{}}, ParseResult::SUCCESS, {}, {}},
|
||||
{DomainVec({"a.com", "b.com", "a.com"}),
|
||||
DomainVec({"g.com", "XY.COM", "zzz.com", "a.com", "google.com"}),
|
||||
ParseResult::SUCCESS,
|
||||
@ -360,19 +360,19 @@ TEST_F(IndexedRuleTest, DomainsParsing) {
|
||||
{"google.com", "zzz.com", "xy.com", "a.com", "g.com"}},
|
||||
// Domain with non-ascii characters.
|
||||
{DomainVec({base::WideToUTF8(L"abc\x2010" /*hyphen*/ L"def.com")}),
|
||||
absl::nullopt,
|
||||
std::nullopt,
|
||||
ParseResult::ERROR_NON_ASCII_DOMAIN,
|
||||
{},
|
||||
{}},
|
||||
// Excluded domain with non-ascii characters.
|
||||
{absl::nullopt,
|
||||
{std::nullopt,
|
||||
DomainVec({base::WideToUTF8(L"36\x00b0c.com" /*36°c.com*/)}),
|
||||
ParseResult::ERROR_NON_ASCII_EXCLUDED_DOMAIN,
|
||||
{},
|
||||
{}},
|
||||
// Internationalized domain in punycode.
|
||||
{DomainVec({"xn--36c-tfa.com" /* punycode for 36°c.com*/}),
|
||||
absl::nullopt,
|
||||
std::nullopt,
|
||||
ParseResult::SUCCESS,
|
||||
{"xn--36c-tfa.com"},
|
||||
{}},
|
||||
@ -515,23 +515,23 @@ TEST_F(IndexedRuleTest, RedirectParsing) {
|
||||
struct {
|
||||
std::string redirect_dictionary_json;
|
||||
ParseResult expected_result;
|
||||
absl::optional<std::string> expected_redirect_url;
|
||||
std::optional<std::string> expected_redirect_url;
|
||||
} cases[] = {
|
||||
// clang-format off
|
||||
{
|
||||
"{}",
|
||||
ParseResult::ERROR_INVALID_REDIRECT,
|
||||
absl::nullopt
|
||||
std::nullopt
|
||||
},
|
||||
{
|
||||
R"({"url": "xyz"})",
|
||||
ParseResult::ERROR_INVALID_REDIRECT_URL,
|
||||
absl::nullopt
|
||||
std::nullopt
|
||||
},
|
||||
{
|
||||
R"({"url": "javascript:window.alert(\"hello,world\");"})",
|
||||
ParseResult::ERROR_JAVASCRIPT_REDIRECT,
|
||||
absl::nullopt
|
||||
std::nullopt
|
||||
},
|
||||
{
|
||||
R"({"url": "http://google.com"})",
|
||||
@ -541,7 +541,7 @@ TEST_F(IndexedRuleTest, RedirectParsing) {
|
||||
{
|
||||
R"({"extensionPath": "foo/xyz/"})",
|
||||
ParseResult::ERROR_INVALID_EXTENSION_PATH,
|
||||
absl::nullopt
|
||||
std::nullopt
|
||||
},
|
||||
{
|
||||
R"({"extensionPath": "/foo/xyz?q=1"})",
|
||||
@ -555,7 +555,7 @@ TEST_F(IndexedRuleTest, RedirectParsing) {
|
||||
"scheme": "",
|
||||
"host": "foo.com"
|
||||
}
|
||||
})", ParseResult::ERROR_INVALID_TRANSFORM_SCHEME, absl::nullopt
|
||||
})", ParseResult::ERROR_INVALID_TRANSFORM_SCHEME, std::nullopt
|
||||
},
|
||||
{
|
||||
R"(
|
||||
@ -564,7 +564,7 @@ TEST_F(IndexedRuleTest, RedirectParsing) {
|
||||
"scheme": "javascript",
|
||||
"host": "foo.com"
|
||||
}
|
||||
})", ParseResult::ERROR_INVALID_TRANSFORM_SCHEME, absl::nullopt
|
||||
})", ParseResult::ERROR_INVALID_TRANSFORM_SCHEME, std::nullopt
|
||||
},
|
||||
{
|
||||
R"(
|
||||
@ -573,7 +573,7 @@ TEST_F(IndexedRuleTest, RedirectParsing) {
|
||||
"scheme": "http",
|
||||
"port": "-1"
|
||||
}
|
||||
})", ParseResult::ERROR_INVALID_TRANSFORM_PORT, absl::nullopt
|
||||
})", ParseResult::ERROR_INVALID_TRANSFORM_PORT, std::nullopt
|
||||
},
|
||||
{
|
||||
R"(
|
||||
@ -582,22 +582,22 @@ TEST_F(IndexedRuleTest, RedirectParsing) {
|
||||
"scheme": "http",
|
||||
"query": "abc"
|
||||
}
|
||||
})", ParseResult::ERROR_INVALID_TRANSFORM_QUERY, absl::nullopt
|
||||
})", ParseResult::ERROR_INVALID_TRANSFORM_QUERY, std::nullopt
|
||||
},
|
||||
{
|
||||
R"({"transform": {"path": "abc"}})",
|
||||
ParseResult::SUCCESS,
|
||||
absl::nullopt
|
||||
std::nullopt
|
||||
},
|
||||
{
|
||||
R"({"transform": {"fragment": "abc"}})",
|
||||
ParseResult::ERROR_INVALID_TRANSFORM_FRAGMENT,
|
||||
absl::nullopt
|
||||
std::nullopt
|
||||
},
|
||||
{
|
||||
R"({"transform": {"path": ""}})",
|
||||
ParseResult::SUCCESS,
|
||||
absl::nullopt
|
||||
std::nullopt
|
||||
},
|
||||
{
|
||||
R"(
|
||||
@ -609,7 +609,7 @@ TEST_F(IndexedRuleTest, RedirectParsing) {
|
||||
"removeParams": ["abc"]
|
||||
}
|
||||
}
|
||||
})", ParseResult::ERROR_QUERY_AND_TRANSFORM_BOTH_SPECIFIED, absl::nullopt
|
||||
})", ParseResult::ERROR_QUERY_AND_TRANSFORM_BOTH_SPECIFIED, std::nullopt
|
||||
},
|
||||
{
|
||||
R"(
|
||||
@ -628,7 +628,7 @@ TEST_F(IndexedRuleTest, RedirectParsing) {
|
||||
"fragment": "",
|
||||
"username": "user"
|
||||
}
|
||||
})", ParseResult::SUCCESS, absl::nullopt
|
||||
})", ParseResult::SUCCESS, std::nullopt
|
||||
}
|
||||
};
|
||||
// clang-format on
|
||||
@ -817,7 +817,7 @@ TEST_F(IndexedRuleTest, InvalidAllowAllRequestsResourceType) {
|
||||
dnr_api::Rule rule = CreateGenericParsedRule();
|
||||
|
||||
if (cases[i].resource_types.empty()) {
|
||||
rule.condition.resource_types = absl::nullopt;
|
||||
rule.condition.resource_types = std::nullopt;
|
||||
} else {
|
||||
rule.condition.resource_types = cases[i].resource_types;
|
||||
}
|
||||
@ -839,7 +839,7 @@ TEST_F(IndexedRuleTest, ModifyHeadersParsing) {
|
||||
struct RawHeaderInfo {
|
||||
dnr_api::HeaderOperation operation;
|
||||
std::string header;
|
||||
absl::optional<std::string> value;
|
||||
std::optional<std::string> value;
|
||||
};
|
||||
|
||||
using RawHeaderInfoList = std::vector<RawHeaderInfo>;
|
||||
@ -849,38 +849,38 @@ TEST_F(IndexedRuleTest, ModifyHeadersParsing) {
|
||||
// specifying test cases because elements are copied when initializing a
|
||||
// vector from an array.
|
||||
struct {
|
||||
absl::optional<RawHeaderInfoList> request_headers;
|
||||
absl::optional<RawHeaderInfoList> response_headers;
|
||||
std::optional<RawHeaderInfoList> request_headers;
|
||||
std::optional<RawHeaderInfoList> response_headers;
|
||||
ParseResult expected_result;
|
||||
} cases[] = {
|
||||
// Raise an error if no headers are specified.
|
||||
{absl::nullopt, absl::nullopt,
|
||||
{std::nullopt, std::nullopt,
|
||||
ParseResult::ERROR_NO_HEADERS_TO_MODIFY_SPECIFIED},
|
||||
|
||||
// Raise an error if the request or response headers list is specified,
|
||||
// but empty.
|
||||
{RawHeaderInfoList(),
|
||||
RawHeaderInfoList(
|
||||
{{dnr_api::HeaderOperation::kRemove, "set-cookie", absl::nullopt}}),
|
||||
{{dnr_api::HeaderOperation::kRemove, "set-cookie", std::nullopt}}),
|
||||
ParseResult::ERROR_EMPTY_MODIFY_REQUEST_HEADERS_LIST},
|
||||
|
||||
{absl::nullopt, RawHeaderInfoList(),
|
||||
{std::nullopt, RawHeaderInfoList(),
|
||||
ParseResult::ERROR_EMPTY_MODIFY_RESPONSE_HEADERS_LIST},
|
||||
|
||||
// Raise an error if a header list contains an empty or invalid header
|
||||
// name.
|
||||
{absl::nullopt,
|
||||
{std::nullopt,
|
||||
RawHeaderInfoList(
|
||||
{{dnr_api::HeaderOperation::kRemove, "", absl::nullopt}}),
|
||||
{{dnr_api::HeaderOperation::kRemove, "", std::nullopt}}),
|
||||
ParseResult::ERROR_INVALID_HEADER_TO_MODIFY_NAME},
|
||||
|
||||
{absl::nullopt,
|
||||
{std::nullopt,
|
||||
RawHeaderInfoList(
|
||||
{{dnr_api::HeaderOperation::kRemove, "<<invalid>>", absl::nullopt}}),
|
||||
{{dnr_api::HeaderOperation::kRemove, "<<invalid>>", std::nullopt}}),
|
||||
ParseResult::ERROR_INVALID_HEADER_TO_MODIFY_NAME},
|
||||
|
||||
// Raise an error if a header list contains an invalid header value.
|
||||
{absl::nullopt,
|
||||
{std::nullopt,
|
||||
RawHeaderInfoList({{dnr_api::HeaderOperation::kAppend, "set-cookie",
|
||||
"invalid\nvalue"}}),
|
||||
ParseResult::ERROR_INVALID_HEADER_TO_MODIFY_VALUE},
|
||||
@ -888,33 +888,33 @@ TEST_F(IndexedRuleTest, ModifyHeadersParsing) {
|
||||
// Raise an error if a header value is specified for a remove rule.
|
||||
{RawHeaderInfoList(
|
||||
{{dnr_api::HeaderOperation::kRemove, "cookie", "remove"}}),
|
||||
absl::nullopt, ParseResult::ERROR_HEADER_VALUE_PRESENT},
|
||||
std::nullopt, ParseResult::ERROR_HEADER_VALUE_PRESENT},
|
||||
|
||||
// Raise an error if no header value is specified for an append or set
|
||||
// rule.
|
||||
{RawHeaderInfoList(
|
||||
{{dnr_api::HeaderOperation::kSet, "cookie", absl::nullopt}}),
|
||||
absl::nullopt, ParseResult::ERROR_HEADER_VALUE_NOT_SPECIFIED},
|
||||
{{dnr_api::HeaderOperation::kSet, "cookie", std::nullopt}}),
|
||||
std::nullopt, ParseResult::ERROR_HEADER_VALUE_NOT_SPECIFIED},
|
||||
|
||||
{absl::nullopt,
|
||||
{std::nullopt,
|
||||
RawHeaderInfoList(
|
||||
{{dnr_api::HeaderOperation::kAppend, "set-cookie", absl::nullopt}}),
|
||||
{{dnr_api::HeaderOperation::kAppend, "set-cookie", std::nullopt}}),
|
||||
ParseResult::ERROR_HEADER_VALUE_NOT_SPECIFIED},
|
||||
|
||||
// Raise an error if a rule specifies an invalid request header to be
|
||||
// appended.
|
||||
{RawHeaderInfoList(
|
||||
{{dnr_api::HeaderOperation::kAppend, "invalid-header", "value"}}),
|
||||
absl::nullopt, ParseResult::ERROR_APPEND_INVALID_REQUEST_HEADER},
|
||||
std::nullopt, ParseResult::ERROR_APPEND_INVALID_REQUEST_HEADER},
|
||||
|
||||
{RawHeaderInfoList(
|
||||
{{dnr_api::HeaderOperation::kRemove, "cookie", absl::nullopt},
|
||||
{{dnr_api::HeaderOperation::kRemove, "cookie", std::nullopt},
|
||||
{dnr_api::HeaderOperation::kSet, "referer", ""},
|
||||
{dnr_api::HeaderOperation::kAppend, "accept-language", "en-US"}}),
|
||||
absl::nullopt, ParseResult::SUCCESS},
|
||||
std::nullopt, ParseResult::SUCCESS},
|
||||
|
||||
{RawHeaderInfoList(
|
||||
{{dnr_api::HeaderOperation::kRemove, "referer", absl::nullopt}}),
|
||||
{{dnr_api::HeaderOperation::kRemove, "referer", std::nullopt}}),
|
||||
RawHeaderInfoList(
|
||||
{{dnr_api::HeaderOperation::kAppend, "set-cookie", "abcd"}}),
|
||||
ParseResult::SUCCESS},
|
||||
@ -972,25 +972,25 @@ TEST_F(IndexedRuleTest, RequestMethodsParsing) {
|
||||
using RequestMethodVec = std::vector<dnr_api::RequestMethod>;
|
||||
|
||||
struct {
|
||||
absl::optional<RequestMethodVec> request_methods;
|
||||
absl::optional<RequestMethodVec> excluded_request_methods;
|
||||
std::optional<RequestMethodVec> request_methods;
|
||||
std::optional<RequestMethodVec> excluded_request_methods;
|
||||
const ParseResult expected_result;
|
||||
// Only valid if `expected_result` is SUCCESS.
|
||||
const uint16_t expected_request_methods_mask;
|
||||
} cases[] = {
|
||||
{absl::nullopt, absl::nullopt, ParseResult::SUCCESS,
|
||||
{std::nullopt, std::nullopt, ParseResult::SUCCESS,
|
||||
flat_rule::RequestMethod_ANY},
|
||||
{absl::nullopt, RequestMethodVec({dnr_api::RequestMethod::kPut}),
|
||||
{std::nullopt, RequestMethodVec({dnr_api::RequestMethod::kPut}),
|
||||
ParseResult::SUCCESS,
|
||||
flat_rule::RequestMethod_ANY & ~flat_rule::RequestMethod_PUT},
|
||||
{RequestMethodVec(
|
||||
{dnr_api::RequestMethod::kDelete, dnr_api::RequestMethod::kGet}),
|
||||
absl::nullopt, ParseResult::SUCCESS,
|
||||
std::nullopt, ParseResult::SUCCESS,
|
||||
flat_rule::RequestMethod_DELETE | flat_rule::RequestMethod_GET},
|
||||
{RequestMethodVec({dnr_api::RequestMethod::kHead,
|
||||
dnr_api::RequestMethod::kOptions,
|
||||
dnr_api::RequestMethod::kPatch}),
|
||||
absl::nullopt, ParseResult::SUCCESS,
|
||||
std::nullopt, ParseResult::SUCCESS,
|
||||
flat_rule::RequestMethod_HEAD | flat_rule::RequestMethod_OPTIONS |
|
||||
flat_rule::RequestMethod_PATCH},
|
||||
{RequestMethodVec({dnr_api::RequestMethod::kPost}),
|
||||
@ -998,7 +998,7 @@ TEST_F(IndexedRuleTest, RequestMethodsParsing) {
|
||||
ParseResult::ERROR_REQUEST_METHOD_DUPLICATED,
|
||||
flat_rule::RequestMethod_NONE},
|
||||
{{{}},
|
||||
absl::nullopt,
|
||||
std::nullopt,
|
||||
ParseResult::ERROR_EMPTY_REQUEST_METHODS_LIST,
|
||||
flat_rule::RequestMethod_NONE}};
|
||||
|
||||
@ -1023,8 +1023,8 @@ TEST_F(IndexedRuleTest, RequestMethodsParsing) {
|
||||
TEST_F(IndexedRuleTest, TabID) {
|
||||
using IntVec = std::vector<int>;
|
||||
struct {
|
||||
absl::optional<IntVec> tab_ids;
|
||||
absl::optional<IntVec> excluded_tab_ids;
|
||||
std::optional<IntVec> tab_ids;
|
||||
std::optional<IntVec> excluded_tab_ids;
|
||||
RulesetID ruleset_id;
|
||||
ParseResult expected_result;
|
||||
|
||||
@ -1032,7 +1032,7 @@ TEST_F(IndexedRuleTest, TabID) {
|
||||
base::flat_set<int> expected_tab_ids;
|
||||
base::flat_set<int> expected_excluded_tab_ids;
|
||||
} cases[] = {
|
||||
{absl::nullopt, absl::nullopt, kSessionRulesetID, ParseResult::SUCCESS},
|
||||
{std::nullopt, std::nullopt, kSessionRulesetID, ParseResult::SUCCESS},
|
||||
{IntVec(), IntVec({3, 4, 4}), kSessionRulesetID,
|
||||
ParseResult::ERROR_EMPTY_TAB_IDS_LIST},
|
||||
{IntVec({1, 2}),
|
||||
@ -1041,7 +1041,7 @@ TEST_F(IndexedRuleTest, TabID) {
|
||||
ParseResult::SUCCESS,
|
||||
{1, 2},
|
||||
{}},
|
||||
{absl::nullopt,
|
||||
{std::nullopt,
|
||||
IntVec({3, 4, 3}),
|
||||
kSessionRulesetID,
|
||||
ParseResult::SUCCESS,
|
||||
@ -1049,7 +1049,7 @@ TEST_F(IndexedRuleTest, TabID) {
|
||||
{3, 4}},
|
||||
{IntVec({1, 2, 3}), IntVec({5, 2}), kSessionRulesetID,
|
||||
ParseResult::ERROR_TAB_ID_DUPLICATED},
|
||||
{IntVec({1, 2}), absl::nullopt, kDynamicRulesetID,
|
||||
{IntVec({1, 2}), std::nullopt, kDynamicRulesetID,
|
||||
ParseResult::ERROR_TAB_IDS_ON_NON_SESSION_RULE},
|
||||
{IntVec({1, 2}), IntVec({3}), kMinValidStaticRulesetID,
|
||||
ParseResult::ERROR_TAB_IDS_ON_NON_SESSION_RULE},
|
||||
@ -1094,62 +1094,61 @@ class IndexedResponseHeaderRuleTest : public IndexedRuleTest {
|
||||
TEST_F(IndexedResponseHeaderRuleTest, MatchingResponseHeaders) {
|
||||
struct RawHeaderInfo {
|
||||
std::string header;
|
||||
absl::optional<std::vector<std::string>> values;
|
||||
absl::optional<std::vector<std::string>> excluded_values;
|
||||
std::optional<std::vector<std::string>> values;
|
||||
std::optional<std::vector<std::string>> excluded_values;
|
||||
};
|
||||
|
||||
using HeaderInfoList = std::vector<RawHeaderInfo>;
|
||||
using ExcludedHeaderList = std::vector<std::string>;
|
||||
struct {
|
||||
absl::optional<HeaderInfoList> response_headers;
|
||||
absl::optional<ExcludedHeaderList> excluded_response_headers;
|
||||
std::optional<HeaderInfoList> response_headers;
|
||||
std::optional<ExcludedHeaderList> excluded_response_headers;
|
||||
ParseResult expected_result;
|
||||
} cases[] = {
|
||||
// No response headers included or excluded; should parse successfully.
|
||||
{absl::nullopt, absl::nullopt, ParseResult::SUCCESS},
|
||||
{std::nullopt, std::nullopt, ParseResult::SUCCESS},
|
||||
|
||||
// only header1 specified, matching on name only should parse
|
||||
// successfully.
|
||||
{HeaderInfoList({{"header1", absl::nullopt, absl::nullopt}}),
|
||||
absl::nullopt, ParseResult::SUCCESS},
|
||||
{HeaderInfoList({{"header1", std::nullopt, std::nullopt}}), std::nullopt,
|
||||
ParseResult::SUCCESS},
|
||||
|
||||
// Valid included and excluded response headers with values and excluded
|
||||
// values should parse successfully.
|
||||
{HeaderInfoList(
|
||||
{{"header1", std::vector<std::string>({"value-1", "value-2"}),
|
||||
absl::nullopt},
|
||||
{"header1", absl::nullopt,
|
||||
std::nullopt},
|
||||
{"header1", std::nullopt,
|
||||
std::vector<std::string>({"excluded-value"})}}),
|
||||
ExcludedHeaderList({"excluded-header"}), ParseResult::SUCCESS},
|
||||
|
||||
// An empty matching response header list should trigger an error.
|
||||
{HeaderInfoList(), absl::nullopt,
|
||||
{HeaderInfoList(), std::nullopt,
|
||||
ParseResult::ERROR_EMPTY_RESPONSE_HEADER_MATCHING_LIST},
|
||||
|
||||
// An empty matching excluded response header list should trigger an
|
||||
// error.
|
||||
{absl::nullopt, ExcludedHeaderList(),
|
||||
{std::nullopt, ExcludedHeaderList(),
|
||||
ParseResult::ERROR_EMPTY_EXCLUDED_RESPONSE_HEADER_MATCHING_LIST},
|
||||
|
||||
// Test that a rule with an empty or invalid response header name will
|
||||
// return an error.
|
||||
{HeaderInfoList({{"", absl::nullopt, absl::nullopt}}), absl::nullopt,
|
||||
{HeaderInfoList({{"", std::nullopt, std::nullopt}}), std::nullopt,
|
||||
ParseResult::ERROR_INVALID_MATCHING_RESPONSE_HEADER_NAME},
|
||||
|
||||
{absl::nullopt, ExcludedHeaderList({"<<invalid_header>>"}),
|
||||
{std::nullopt, ExcludedHeaderList({"<<invalid_header>>"}),
|
||||
ParseResult::ERROR_INVALID_MATCHING_EXCLUDED_RESPONSE_HEADER_NAME},
|
||||
|
||||
// Test that a rule with an empty response header value will return an
|
||||
// error.
|
||||
{HeaderInfoList(
|
||||
{{"header", std::vector<std::string>({""}), absl::nullopt}}),
|
||||
absl::nullopt,
|
||||
ParseResult::ERROR_INVALID_MATCHING_RESPONSE_HEADER_VALUE},
|
||||
{{"header", std::vector<std::string>({""}), std::nullopt}}),
|
||||
std::nullopt, ParseResult::ERROR_INVALID_MATCHING_RESPONSE_HEADER_VALUE},
|
||||
|
||||
// Test that a rule cannot specify the same header in `response_headers`
|
||||
// and `excluded_response_headers` if that header is to be matched based
|
||||
// on name only.
|
||||
{HeaderInfoList({{"repeated-header", absl::nullopt, absl::nullopt}}),
|
||||
{HeaderInfoList({{"repeated-header", std::nullopt, std::nullopt}}),
|
||||
ExcludedHeaderList({"repeated-header"}),
|
||||
ParseResult::ERROR_MATCHING_RESPONSE_HEADER_DUPLICATED},
|
||||
|
||||
@ -1160,7 +1159,7 @@ TEST_F(IndexedResponseHeaderRuleTest, MatchingResponseHeaders) {
|
||||
// `specific-value`.
|
||||
{HeaderInfoList(
|
||||
{{"repeated-header", std::vector<std::string>({"specific-value"}),
|
||||
absl::nullopt}}),
|
||||
std::nullopt}}),
|
||||
ExcludedHeaderList({"repeated-header"}), ParseResult::SUCCESS},
|
||||
};
|
||||
|
||||
@ -1219,13 +1218,13 @@ TEST_F(IndexedResponseHeaderRuleTest, MatchingResponseHeaders_ModifyHeaders) {
|
||||
struct RawModifyHeaderInfo {
|
||||
dnr_api::HeaderOperation operation;
|
||||
std::string header;
|
||||
absl::optional<std::string> value;
|
||||
std::optional<std::string> value;
|
||||
};
|
||||
|
||||
using ModifyHeaderInfoList = std::vector<RawModifyHeaderInfo>;
|
||||
struct {
|
||||
absl::optional<ModifyHeaderInfoList> request_headers_to_modify;
|
||||
absl::optional<ModifyHeaderInfoList> response_headers_to_modify;
|
||||
std::optional<ModifyHeaderInfoList> request_headers_to_modify;
|
||||
std::optional<ModifyHeaderInfoList> response_headers_to_modify;
|
||||
ParseResult expected_result;
|
||||
} cases[] = {
|
||||
// Two test cases here: one for a rule that tries to modify request
|
||||
@ -1233,11 +1232,11 @@ TEST_F(IndexedResponseHeaderRuleTest, MatchingResponseHeaders_ModifyHeaders) {
|
||||
// request headers cannot be further modified when it comes time to match
|
||||
// on response headers.
|
||||
{ModifyHeaderInfoList({{dnr_api::HeaderOperation::kRemove,
|
||||
"request-header", absl::nullopt}}),
|
||||
absl::nullopt,
|
||||
"request-header", std::nullopt}}),
|
||||
std::nullopt,
|
||||
ParseResult::ERROR_RESPONSE_HEADER_RULE_CANNOT_MODIFY_REQUEST_HEADERS},
|
||||
|
||||
{absl::nullopt,
|
||||
{std::nullopt,
|
||||
ModifyHeaderInfoList(
|
||||
{{dnr_api::HeaderOperation::kSet, "response-header", "new-value"}}),
|
||||
ParseResult::SUCCESS},
|
||||
@ -1248,7 +1247,7 @@ TEST_F(IndexedResponseHeaderRuleTest, MatchingResponseHeaders_ModifyHeaders) {
|
||||
dnr_api::Rule rule = CreateGenericParsedRule();
|
||||
rule.condition.response_headers.emplace();
|
||||
rule.condition.response_headers->push_back(
|
||||
CreateHeaderInfo("header", absl::nullopt, absl::nullopt));
|
||||
CreateHeaderInfo("header", std::nullopt, std::nullopt));
|
||||
|
||||
rule.action.type = dnr_api::RuleActionType::kModifyHeaders;
|
||||
if (cases[i].request_headers_to_modify) {
|
||||
|
@ -65,7 +65,7 @@ InstallIndexHelper::Result CombineResults(
|
||||
// warnings associated.
|
||||
DCHECK(!index_result.warnings.empty());
|
||||
total_result.ruleset_install_prefs.emplace_back(
|
||||
source->id(), absl::nullopt /* ruleset_checksum */,
|
||||
source->id(), std::nullopt /* ruleset_checksum */,
|
||||
true /* ignored */);
|
||||
continue;
|
||||
}
|
||||
|
@ -6,10 +6,10 @@
|
||||
#define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_INSTALL_INDEX_HELPER_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/functional/callback_forward.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "extensions/browser/api/declarative_net_request/file_backed_ruleset_source.h"
|
||||
@ -17,7 +17,6 @@
|
||||
#include "extensions/browser/api/declarative_net_request/ruleset_source.h"
|
||||
#include "extensions/common/install_warning.h"
|
||||
#include "services/data_decoder/public/cpp/data_decoder.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace extensions {
|
||||
class Extension;
|
||||
@ -34,9 +33,9 @@ class InstallIndexHelper
|
||||
Result& operator=(Result&&);
|
||||
|
||||
// Non-empty on failure.
|
||||
absl::optional<std::string> error;
|
||||
std::optional<std::string> error;
|
||||
|
||||
// Valid if |error| is absl::nullopt. Clients should not use these fields in
|
||||
// Valid if |error| is std::nullopt. Clients should not use these fields in
|
||||
// case of a failure since these may be partially populated.
|
||||
std::vector<InstallWarning> warnings;
|
||||
std::vector<RulesetInstallPref> ruleset_install_prefs;
|
||||
|
@ -105,7 +105,7 @@ size_t RegexRulesMatcher::GetRulesCount() const {
|
||||
|
||||
std::vector<RequestAction> RegexRulesMatcher::GetModifyHeadersActions(
|
||||
const RequestParams& params,
|
||||
absl::optional<uint64_t> min_priority) const {
|
||||
std::optional<uint64_t> min_priority) const {
|
||||
const std::vector<RegexRuleInfo>& potential_matches =
|
||||
GetPotentialMatches(params);
|
||||
|
||||
@ -126,7 +126,7 @@ std::vector<RequestAction> RegexRulesMatcher::GetModifyHeadersActions(
|
||||
return GetModifyHeadersActionsFromMetadata(params, rules, *metadata_list_);
|
||||
}
|
||||
|
||||
absl::optional<RequestAction> RegexRulesMatcher::GetAllowAllRequestsAction(
|
||||
std::optional<RequestAction> RegexRulesMatcher::GetAllowAllRequestsAction(
|
||||
const RequestParams& params) const {
|
||||
const std::vector<RegexRuleInfo>& potential_matches =
|
||||
GetPotentialMatches(params);
|
||||
@ -137,12 +137,12 @@ absl::optional<RequestAction> RegexRulesMatcher::GetAllowAllRequestsAction(
|
||||
re2::RE2::PartialMatch(params.url->spec(), *info.regex);
|
||||
});
|
||||
if (info == potential_matches.end())
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
return CreateAllowAllRequestsAction(params, *info->regex_rule->url_rule());
|
||||
}
|
||||
|
||||
absl::optional<RequestAction>
|
||||
std::optional<RequestAction>
|
||||
RegexRulesMatcher::GetBeforeRequestActionIgnoringAncestors(
|
||||
const RequestParams& params) const {
|
||||
const std::vector<RegexRuleInfo>& potential_matches =
|
||||
@ -153,7 +153,7 @@ RegexRulesMatcher::GetBeforeRequestActionIgnoringAncestors(
|
||||
re2::RE2::PartialMatch(params.url->spec(), *info.regex);
|
||||
});
|
||||
if (info == potential_matches.end())
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
const flat_rule::UrlRule& rule = *info->regex_rule->url_rule();
|
||||
switch (info->regex_rule->action_type()) {
|
||||
@ -179,7 +179,7 @@ RegexRulesMatcher::GetBeforeRequestActionIgnoringAncestors(
|
||||
break;
|
||||
}
|
||||
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void RegexRulesMatcher::InitializeMatcher() {
|
||||
@ -307,7 +307,7 @@ const std::vector<RegexRuleInfo>& RegexRulesMatcher::GetPotentialMatches(
|
||||
return result.first->second;
|
||||
}
|
||||
|
||||
absl::optional<RequestAction>
|
||||
std::optional<RequestAction>
|
||||
RegexRulesMatcher::CreateRegexSubstitutionRedirectAction(
|
||||
const RequestParams& params,
|
||||
const RegexRuleInfo& info) const {
|
||||
@ -330,7 +330,7 @@ RegexRulesMatcher::CreateRegexSubstitutionRedirectAction(
|
||||
info.regex->pattern().c_str(),
|
||||
info.regex_rule->regex_substitution()->c_str(),
|
||||
params.url->spec().c_str());
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
GURL redirect_url(redirect_str);
|
||||
@ -338,7 +338,7 @@ RegexRulesMatcher::CreateRegexSubstitutionRedirectAction(
|
||||
// Redirects to JavaScript urls are not allowed.
|
||||
// TODO(crbug.com/1033780): this results in counterintuitive behavior.
|
||||
if (redirect_url.SchemeIs(url::kJavaScriptScheme))
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
return CreateRedirectAction(params, *info.regex_rule->url_rule(),
|
||||
std::move(redirect_url));
|
||||
|
@ -62,15 +62,15 @@ class RegexRulesMatcher final : public RulesetMatcherBase {
|
||||
~RegexRulesMatcher() override;
|
||||
std::vector<RequestAction> GetModifyHeadersActions(
|
||||
const RequestParams& params,
|
||||
absl::optional<uint64_t> min_priority) const override;
|
||||
std::optional<uint64_t> min_priority) const override;
|
||||
bool IsExtraHeadersMatcher() const override;
|
||||
size_t GetRulesCount() const override;
|
||||
|
||||
private:
|
||||
// RulesetMatcherBase override:
|
||||
absl::optional<RequestAction> GetAllowAllRequestsAction(
|
||||
std::optional<RequestAction> GetAllowAllRequestsAction(
|
||||
const RequestParams& params) const override;
|
||||
absl::optional<RequestAction> GetBeforeRequestActionIgnoringAncestors(
|
||||
std::optional<RequestAction> GetBeforeRequestActionIgnoringAncestors(
|
||||
const RequestParams& params) const override;
|
||||
|
||||
// Helper to build the necessary data structures for matching.
|
||||
@ -87,7 +87,7 @@ class RegexRulesMatcher final : public RulesetMatcherBase {
|
||||
const RequestParams& params) const;
|
||||
|
||||
// Returns a RequestAction for the the given regex substitution rule.
|
||||
absl::optional<RequestAction> CreateRegexSubstitutionRedirectAction(
|
||||
std::optional<RequestAction> CreateRegexSubstitutionRedirectAction(
|
||||
const RequestParams& params,
|
||||
const RegexRuleInfo& info) const;
|
||||
|
||||
|
@ -34,7 +34,7 @@ dnr_api::HeaderOperation ConvertFlatHeaderOperation(
|
||||
|
||||
RequestAction::HeaderInfo::HeaderInfo(std::string header,
|
||||
dnr_api::HeaderOperation operation,
|
||||
absl::optional<std::string> value)
|
||||
std::optional<std::string> value)
|
||||
: header(std::move(header)),
|
||||
operation(operation),
|
||||
value(std::move(value)) {}
|
||||
@ -86,9 +86,9 @@ bool operator>(const RequestAction& lhs, const RequestAction& rhs) {
|
||||
std::tie(rhs.index_priority, rhs.ruleset_id, rhs.rule_id);
|
||||
}
|
||||
|
||||
absl::optional<RequestAction> GetMaxPriorityAction(
|
||||
absl::optional<RequestAction> lhs,
|
||||
absl::optional<RequestAction> rhs) {
|
||||
std::optional<RequestAction> GetMaxPriorityAction(
|
||||
std::optional<RequestAction> lhs,
|
||||
std::optional<RequestAction> rhs) {
|
||||
if (!lhs)
|
||||
return rhs;
|
||||
if (!rhs)
|
||||
|
@ -6,12 +6,11 @@
|
||||
#define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_REQUEST_ACTION_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "extensions/common/api/declarative_net_request.h"
|
||||
#include "extensions/common/api/declarative_net_request/constants.h"
|
||||
#include "extensions/common/extension_id.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
namespace extensions {
|
||||
@ -29,7 +28,7 @@ struct RequestAction {
|
||||
struct HeaderInfo {
|
||||
HeaderInfo(std::string header,
|
||||
api::declarative_net_request::HeaderOperation operation,
|
||||
absl::optional<std::string> value);
|
||||
std::optional<std::string> value);
|
||||
explicit HeaderInfo(const flat::ModifyHeaderInfo& info);
|
||||
~HeaderInfo();
|
||||
HeaderInfo(const HeaderInfo& other);
|
||||
@ -41,7 +40,7 @@ struct RequestAction {
|
||||
std::string header;
|
||||
api::declarative_net_request::HeaderOperation operation;
|
||||
// The value for |header| to be appended or set.
|
||||
absl::optional<std::string> value;
|
||||
std::optional<std::string> value;
|
||||
};
|
||||
|
||||
enum class Type {
|
||||
@ -78,7 +77,7 @@ struct RequestAction {
|
||||
Type type = Type::BLOCK;
|
||||
|
||||
// Valid iff |IsRedirectOrUpgrade()| is true.
|
||||
absl::optional<GURL> redirect_url;
|
||||
std::optional<GURL> redirect_url;
|
||||
|
||||
// The ID of the matching rule for this action.
|
||||
uint32_t rule_id;
|
||||
@ -124,9 +123,9 @@ struct RequestAction {
|
||||
bool operator<(const RequestAction& lhs, const RequestAction& rhs);
|
||||
bool operator>(const RequestAction& lhs, const RequestAction& rhs);
|
||||
|
||||
absl::optional<RequestAction> GetMaxPriorityAction(
|
||||
absl::optional<RequestAction> lhs,
|
||||
absl::optional<RequestAction> rhs);
|
||||
std::optional<RequestAction> GetMaxPriorityAction(
|
||||
std::optional<RequestAction> lhs,
|
||||
std::optional<RequestAction> rhs);
|
||||
|
||||
} // namespace declarative_net_request
|
||||
} // namespace extensions
|
||||
|
@ -5,13 +5,13 @@
|
||||
#ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_REQUEST_PARAMS_H_
|
||||
#define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_REQUEST_PARAMS_H_
|
||||
|
||||
#include <optional>
|
||||
#include "base/containers/flat_map.h"
|
||||
#include "base/functional/callback.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "components/url_pattern_index/url_pattern_index.h"
|
||||
#include "content/public/browser/global_routing_id.h"
|
||||
#include "extensions/browser/api/declarative_net_request/regex_rules_matcher.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "url/gurl.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
@ -63,14 +63,14 @@ struct RequestParams {
|
||||
embedder_conditions_matcher;
|
||||
|
||||
// A map from CompositeMatcher to the priority of its highest priority
|
||||
// matching allow or allowAllRequests rule if there is one, or absl::nullopt
|
||||
// matching allow or allowAllRequests rule if there is one, or std::nullopt
|
||||
// otherwise. Used as a cache to prevent additional calls to
|
||||
// GetBeforeRequestAction.
|
||||
mutable base::flat_map<const CompositeMatcher*, absl::optional<uint64_t>>
|
||||
mutable base::flat_map<const CompositeMatcher*, std::optional<uint64_t>>
|
||||
allow_rule_max_priority;
|
||||
|
||||
// Lower cased url, used for regex matching. Cached for performance.
|
||||
mutable absl::optional<std::string> lower_cased_url_spec;
|
||||
mutable std::optional<std::string> lower_cased_url_spec;
|
||||
|
||||
// Map from RegexRulesMatcher to a vector of potential matches for this
|
||||
// request. Cached for performance.
|
||||
|
@ -10,7 +10,7 @@ namespace extensions::declarative_net_request {
|
||||
|
||||
RuleCounts::RuleCounts() = default;
|
||||
RuleCounts::RuleCounts(size_t rule_count,
|
||||
absl::optional<size_t> unsafe_rule_count,
|
||||
std::optional<size_t> unsafe_rule_count,
|
||||
size_t regex_rule_count)
|
||||
: rule_count(rule_count),
|
||||
unsafe_rule_count(unsafe_rule_count),
|
||||
|
@ -6,8 +6,7 @@
|
||||
#define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_RULE_COUNTS_H_
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include <optional>
|
||||
|
||||
namespace extensions::declarative_net_request {
|
||||
|
||||
@ -15,7 +14,7 @@ namespace extensions::declarative_net_request {
|
||||
struct RuleCounts {
|
||||
RuleCounts();
|
||||
RuleCounts(size_t rule_count,
|
||||
absl::optional<size_t> unsafe_rule_count,
|
||||
std::optional<size_t> unsafe_rule_count,
|
||||
size_t regex_rule_count);
|
||||
|
||||
RuleCounts& operator+=(const RuleCounts& that);
|
||||
@ -26,7 +25,7 @@ struct RuleCounts {
|
||||
// utils.cc in the same directory for what constitutes an "unsafe" rule). This
|
||||
// is only counted for dynamic or session rulesets and is null for static
|
||||
// rulesets.
|
||||
absl::optional<size_t> unsafe_rule_count = absl::nullopt;
|
||||
std::optional<size_t> unsafe_rule_count = std::nullopt;
|
||||
// Tracks the total regex rule count of a ruleset.
|
||||
size_t regex_rule_count = 0;
|
||||
};
|
||||
|
@ -493,7 +493,7 @@ void RulesMonitorService::OnExtensionLoaded(
|
||||
FileBackedRulesetSource::CreateStatic(
|
||||
*extension, FileBackedRulesetSource::RulesetFilter::kIncludeAll);
|
||||
|
||||
absl::optional<std::set<RulesetID>> prefs_enabled_rulesets =
|
||||
std::optional<std::set<RulesetID>> prefs_enabled_rulesets =
|
||||
prefs_->GetDNREnabledStaticRulesets(extension->id());
|
||||
|
||||
bool ruleset_failed_to_load = false;
|
||||
@ -624,7 +624,7 @@ void RulesMonitorService::UpdateDynamicRulesInternal(
|
||||
// There is no enabled extension to respond to. While this is probably a
|
||||
// no-op, still dispatch the callback to ensure any related bookkeeping is
|
||||
// done.
|
||||
std::move(callback).Run(absl::nullopt /* error */);
|
||||
std::move(callback).Run(std::nullopt /* error */);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -664,7 +664,7 @@ void RulesMonitorService::UpdateSessionRulesInternal(
|
||||
// There is no enabled extension to respond to. While this is probably a
|
||||
// no-op, still dispatch the callback to ensure any related bookkeeping is
|
||||
// done.
|
||||
std::move(callback).Run(absl::nullopt /* error */);
|
||||
std::move(callback).Run(std::nullopt /* error */);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -728,7 +728,7 @@ void RulesMonitorService::UpdateSessionRulesInternal(
|
||||
|
||||
session_rules_[extension_id] = std::move(new_rules_value);
|
||||
UpdateRulesetMatcher(*extension, std::move(matcher));
|
||||
std::move(callback).Run(absl::nullopt /* error */);
|
||||
std::move(callback).Run(std::nullopt /* error */);
|
||||
}
|
||||
|
||||
void RulesMonitorService::UpdateEnabledStaticRulesetsInternal(
|
||||
@ -742,7 +742,7 @@ void RulesMonitorService::UpdateEnabledStaticRulesetsInternal(
|
||||
// There is no enabled extension to respond to. While this is probably a
|
||||
// no-op, still dispatch the callback to ensure any related bookkeeping is
|
||||
// done.
|
||||
std::move(callback).Run(absl::nullopt /* error */);
|
||||
std::move(callback).Run(std::nullopt /* error */);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -783,7 +783,7 @@ void RulesMonitorService::UpdateStaticRulesInternal(
|
||||
// There is no enabled extension to respond to. While this is probably a
|
||||
// no-op, still dispatch the callback to ensure any related bookkeeping is
|
||||
// done.
|
||||
std::move(callback).Run(absl::nullopt /* error */);
|
||||
std::move(callback).Run(std::nullopt /* error */);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -797,7 +797,7 @@ void RulesMonitorService::UpdateStaticRulesInternal(
|
||||
}
|
||||
|
||||
if (!result.changed) {
|
||||
std::move(callback).Run(absl::nullopt /* error */);
|
||||
std::move(callback).Run(std::nullopt /* error */);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -814,7 +814,7 @@ void RulesMonitorService::UpdateStaticRulesInternal(
|
||||
}
|
||||
}
|
||||
|
||||
std::move(callback).Run(absl::nullopt /* error */);
|
||||
std::move(callback).Run(std::nullopt /* error */);
|
||||
}
|
||||
|
||||
void RulesMonitorService::GetDisabledRuleIdsInternal(
|
||||
@ -893,7 +893,7 @@ void RulesMonitorService::OnInitialRulesetsLoadedFromDisk(
|
||||
RuleCounts static_rule_limit(
|
||||
global_rules_tracker_.GetAvailableAllocation(load_data.extension_id) +
|
||||
GetStaticGuaranteedMinimumRuleCount(),
|
||||
/*unsafe_rule_count=*/absl::nullopt, GetRegexRuleLimit());
|
||||
/*unsafe_rule_count=*/std::nullopt, GetRegexRuleLimit());
|
||||
|
||||
for (RulesetInfo& ruleset : load_data.rulesets) {
|
||||
if (!ruleset.did_load_successfully()) {
|
||||
@ -971,7 +971,7 @@ void RulesMonitorService::OnNewStaticRulesetsLoaded(
|
||||
load_data.extension_id, ExtensionRegistry::ENABLED);
|
||||
if (!extension) {
|
||||
// Still dispatch the |callback|, even though it's probably a no-op.
|
||||
std::move(callback).Run(absl::nullopt /* error */);
|
||||
std::move(callback).Run(std::nullopt /* error */);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1072,13 +1072,13 @@ void RulesMonitorService::OnNewStaticRulesetsLoaded(
|
||||
matcher->ComputeStaticRulesetIDs());
|
||||
}
|
||||
|
||||
std::move(callback).Run(absl::nullopt);
|
||||
std::move(callback).Run(std::nullopt);
|
||||
}
|
||||
|
||||
void RulesMonitorService::OnDynamicRulesUpdated(
|
||||
ApiCallback callback,
|
||||
LoadRequestData load_data,
|
||||
absl::optional<std::string> error) {
|
||||
std::optional<std::string> error) {
|
||||
DCHECK_EQ(1u, load_data.rulesets.size());
|
||||
|
||||
const bool has_error = error.has_value();
|
||||
|
@ -7,10 +7,10 @@
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/flat_map.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
@ -26,7 +26,6 @@
|
||||
#include "extensions/browser/extension_registry_observer.h"
|
||||
#include "extensions/common/api/declarative_net_request/constants.h"
|
||||
#include "extensions/common/extension_id.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace content {
|
||||
class BrowserContext;
|
||||
@ -56,7 +55,7 @@ class RulesMonitorService : public BrowserContextKeyedAPI,
|
||||
public ExtensionRegistryObserver {
|
||||
public:
|
||||
using ApiCallback =
|
||||
base::OnceCallback<void(absl::optional<std::string> error)>;
|
||||
base::OnceCallback<void(std::optional<std::string> error)>;
|
||||
using ApiCallbackToGetDisabledRuleIds =
|
||||
base::OnceCallback<void(std::vector<int> disabled_rule_ids)>;
|
||||
|
||||
@ -230,7 +229,7 @@ class RulesMonitorService : public BrowserContextKeyedAPI,
|
||||
// response to UpdateDynamicRules.
|
||||
void OnDynamicRulesUpdated(ApiCallback callback,
|
||||
LoadRequestData load_data,
|
||||
absl::optional<std::string> error);
|
||||
std::optional<std::string> error);
|
||||
|
||||
// Unloads all rulesets for the given |extension_id|.
|
||||
void RemoveCompositeMatcher(const ExtensionId& extension_id);
|
||||
|
@ -10,7 +10,7 @@ namespace extensions {
|
||||
namespace declarative_net_request {
|
||||
|
||||
RulesetInstallPref::RulesetInstallPref(RulesetID ruleset_id,
|
||||
absl::optional<int> checksum,
|
||||
std::optional<int> checksum,
|
||||
bool ignored)
|
||||
: ruleset_id(ruleset_id), checksum(checksum), ignored(ignored) {
|
||||
DCHECK_NE(ignored, checksum.has_value());
|
||||
|
@ -5,10 +5,9 @@
|
||||
#ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_RULESET_INSTALL_PREF_H_
|
||||
#define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_RULESET_INSTALL_PREF_H_
|
||||
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "extensions/common/api/declarative_net_request/constants.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace extensions {
|
||||
namespace declarative_net_request {
|
||||
@ -17,13 +16,13 @@ struct RulesetInstallPref {
|
||||
// ID of the ruleset.
|
||||
RulesetID ruleset_id;
|
||||
// Checksum of the indexed ruleset if specified.
|
||||
absl::optional<int> checksum;
|
||||
std::optional<int> checksum;
|
||||
|
||||
// If set to true, then the ruleset was ignored and not indexed.
|
||||
bool ignored;
|
||||
|
||||
RulesetInstallPref(RulesetID ruleset_id,
|
||||
absl::optional<int> checksum,
|
||||
std::optional<int> checksum,
|
||||
bool ignored);
|
||||
};
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
#include "extensions/browser/api/declarative_net_request/ruleset_manager.h"
|
||||
|
||||
#include <iterator>
|
||||
#include <optional>
|
||||
#include <tuple>
|
||||
|
||||
#include "base/check_op.h"
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/containers/cxx20_erase.h"
|
||||
@ -30,7 +30,6 @@
|
||||
#include "extensions/browser/extension_util.h"
|
||||
#include "extensions/common/api/declarative_net_request.h"
|
||||
#include "extensions/common/constants.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
namespace extensions {
|
||||
@ -238,7 +237,7 @@ bool RulesetManager::ExtensionRulesetData::operator<(
|
||||
std::tie(other.extension_install_time, other.extension_id);
|
||||
}
|
||||
|
||||
absl::optional<RequestAction> RulesetManager::GetBeforeRequestAction(
|
||||
std::optional<RequestAction> RulesetManager::GetBeforeRequestAction(
|
||||
const std::vector<RulesetAndPageAccess>& rulesets,
|
||||
const WebRequestInfo& request,
|
||||
const RequestParams& params) const {
|
||||
@ -249,7 +248,7 @@ absl::optional<RequestAction> RulesetManager::GetBeforeRequestAction(
|
||||
|
||||
// The priorities of actions between different extensions is different from
|
||||
// the priorities of actions within an extension.
|
||||
const auto action_priority = [](const absl::optional<RequestAction>& action) {
|
||||
const auto action_priority = [](const std::optional<RequestAction>& action) {
|
||||
if (!action.has_value())
|
||||
return 0;
|
||||
switch (action->type) {
|
||||
@ -268,7 +267,7 @@ absl::optional<RequestAction> RulesetManager::GetBeforeRequestAction(
|
||||
}
|
||||
};
|
||||
|
||||
absl::optional<RequestAction> action;
|
||||
std::optional<RequestAction> action;
|
||||
|
||||
// This iterates in decreasing order of extension installation time. Hence
|
||||
// more recently installed extensions get higher priority in choosing the
|
||||
@ -373,7 +372,7 @@ std::vector<RequestAction> RulesetManager::EvaluateRequestInternal(
|
||||
}
|
||||
|
||||
const RequestParams params(request);
|
||||
absl::optional<RequestAction> before_request_action =
|
||||
std::optional<RequestAction> before_request_action =
|
||||
GetBeforeRequestAction(rulesets_to_evaluate, request, params);
|
||||
|
||||
if (before_request_action) {
|
||||
|
@ -7,10 +7,10 @@
|
||||
|
||||
#include <stddef.h>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/flat_set.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/sequence_checker.h"
|
||||
@ -18,7 +18,6 @@
|
||||
#include "extensions/browser/api/declarative_net_request/utils.h"
|
||||
#include "extensions/common/extension_id.h"
|
||||
#include "extensions/common/permissions/permissions_data.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace content {
|
||||
class BrowserContext;
|
||||
@ -131,7 +130,7 @@ class RulesetManager {
|
||||
using RulesetAndPageAccess =
|
||||
std::pair<const ExtensionRulesetData*, PermissionsData::PageAccess>;
|
||||
|
||||
absl::optional<RequestAction> GetBeforeRequestAction(
|
||||
std::optional<RequestAction> GetBeforeRequestAction(
|
||||
const std::vector<RulesetAndPageAccess>& rulesets,
|
||||
const WebRequestInfo& request,
|
||||
const RequestParams& params) const;
|
||||
|
@ -5,8 +5,8 @@
|
||||
#include "extensions/browser/api/declarative_net_request/ruleset_matcher.h"
|
||||
|
||||
#include <iterator>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
#include "base/check.h"
|
||||
#include "base/containers/span.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
@ -18,7 +18,6 @@
|
||||
#include "extensions/browser/api/declarative_net_request/rule_counts.h"
|
||||
#include "extensions/browser/api/declarative_net_request/utils.h"
|
||||
#include "extensions/common/api/declarative_net_request/constants.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace extensions::declarative_net_request {
|
||||
|
||||
@ -64,15 +63,15 @@ RulesetMatcher::RulesetMatcher(std::string ruleset_data,
|
||||
|
||||
RulesetMatcher::~RulesetMatcher() = default;
|
||||
|
||||
absl::optional<RequestAction> RulesetMatcher::GetBeforeRequestAction(
|
||||
std::optional<RequestAction> RulesetMatcher::GetBeforeRequestAction(
|
||||
const RequestParams& params) const {
|
||||
base::TimeTicks start_time = base::TimeTicks::Now();
|
||||
absl::optional<RequestAction> regex_result =
|
||||
std::optional<RequestAction> regex_result =
|
||||
regex_matcher_.GetBeforeRequestAction(params);
|
||||
base::TimeDelta regex_time = base::TimeTicks::Now() - start_time;
|
||||
absl::optional<RequestAction> url_pattern_result =
|
||||
std::optional<RequestAction> url_pattern_result =
|
||||
url_pattern_index_matcher_.GetBeforeRequestAction(params);
|
||||
absl::optional<RequestAction> final_result = GetMaxPriorityAction(
|
||||
std::optional<RequestAction> final_result = GetMaxPriorityAction(
|
||||
std::move(url_pattern_result), std::move(regex_result));
|
||||
base::TimeDelta total_time = base::TimeTicks::Now() - start_time;
|
||||
int regex_rules_count = GetRegexRulesCount();
|
||||
@ -161,7 +160,7 @@ absl::optional<RequestAction> RulesetMatcher::GetBeforeRequestAction(
|
||||
|
||||
std::vector<RequestAction> RulesetMatcher::GetModifyHeadersActions(
|
||||
const RequestParams& params,
|
||||
absl::optional<uint64_t> min_priority) const {
|
||||
std::optional<uint64_t> min_priority) const {
|
||||
std::vector<RequestAction> modify_header_actions =
|
||||
url_pattern_index_matcher_.GetModifyHeadersActions(params, min_priority);
|
||||
|
||||
@ -186,7 +185,7 @@ size_t RulesetMatcher::GetRulesCount() const {
|
||||
regex_matcher_.GetRulesCount();
|
||||
}
|
||||
|
||||
absl::optional<size_t> RulesetMatcher::GetUnsafeRulesCount() const {
|
||||
std::optional<size_t> RulesetMatcher::GetUnsafeRulesCount() const {
|
||||
return unsafe_rule_count_;
|
||||
}
|
||||
|
||||
@ -214,7 +213,7 @@ void RulesetMatcher::OnDidFinishNavigation(
|
||||
regex_matcher_.OnDidFinishNavigation(navigation_handle);
|
||||
}
|
||||
|
||||
absl::optional<RequestAction>
|
||||
std::optional<RequestAction>
|
||||
RulesetMatcher::GetAllowlistedFrameActionForTesting(
|
||||
content::RenderFrameHost* host) const {
|
||||
return GetMaxPriorityAction(
|
||||
|
@ -7,15 +7,14 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "base/containers/flat_set.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "extensions/browser/api/declarative_net_request/extension_url_pattern_index_matcher.h"
|
||||
#include "extensions/browser/api/declarative_net_request/flat/extension_ruleset_generated.h"
|
||||
#include "extensions/browser/api/declarative_net_request/regex_rules_matcher.h"
|
||||
#include "extensions/common/api/declarative_net_request/constants.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace content {
|
||||
class NavigationHandle;
|
||||
@ -49,18 +48,18 @@ class RulesetMatcher {
|
||||
|
||||
~RulesetMatcher();
|
||||
|
||||
absl::optional<RequestAction> GetBeforeRequestAction(
|
||||
std::optional<RequestAction> GetBeforeRequestAction(
|
||||
const RequestParams& params) const;
|
||||
|
||||
// Returns a list of actions corresponding to all matched
|
||||
// modifyHeaders rules with priority greater than |min_priority| if specified.
|
||||
std::vector<RequestAction> GetModifyHeadersActions(
|
||||
const RequestParams& params,
|
||||
absl::optional<uint64_t> min_priority) const;
|
||||
std::optional<uint64_t> min_priority) const;
|
||||
|
||||
bool IsExtraHeadersMatcher() const;
|
||||
size_t GetRulesCount() const;
|
||||
absl::optional<size_t> GetUnsafeRulesCount() const;
|
||||
std::optional<size_t> GetUnsafeRulesCount() const;
|
||||
size_t GetRegexRulesCount() const;
|
||||
|
||||
// Returns a RuleCounts object for this matcher containing the total rule
|
||||
@ -77,7 +76,7 @@ class RulesetMatcher {
|
||||
|
||||
// Returns the tracked highest priority matching allowsAllRequests action, if
|
||||
// any, for |host|.
|
||||
absl::optional<RequestAction> GetAllowlistedFrameActionForTesting(
|
||||
std::optional<RequestAction> GetAllowlistedFrameActionForTesting(
|
||||
content::RenderFrameHost* host) const;
|
||||
|
||||
// Set the disabled rule ids to the ruleset matcher.
|
||||
@ -96,7 +95,7 @@ class RulesetMatcher {
|
||||
// The number of unsafe rules for this matcher. Computed only for dynamic and
|
||||
// session scoped rulesets as all rules for static rulesets are considered
|
||||
// "safe".
|
||||
absl::optional<size_t> unsafe_rule_count_ = absl::nullopt;
|
||||
std::optional<size_t> unsafe_rule_count_ = std::nullopt;
|
||||
|
||||
// Underlying matcher for filter-list style rules supported using the
|
||||
// |url_pattern_index| component.
|
||||
|
@ -209,11 +209,11 @@ RulesetMatcherBase::RulesetMatcherBase(const ExtensionId& extension_id,
|
||||
: extension_id_(extension_id), ruleset_id_(ruleset_id) {}
|
||||
RulesetMatcherBase::~RulesetMatcherBase() = default;
|
||||
|
||||
absl::optional<RequestAction> RulesetMatcherBase::GetBeforeRequestAction(
|
||||
std::optional<RequestAction> RulesetMatcherBase::GetBeforeRequestAction(
|
||||
const RequestParams& params) const {
|
||||
absl::optional<RequestAction> action =
|
||||
std::optional<RequestAction> action =
|
||||
GetBeforeRequestActionIgnoringAncestors(params);
|
||||
absl::optional<RequestAction> parent_action =
|
||||
std::optional<RequestAction> parent_action =
|
||||
GetAllowlistedFrameAction(params.parent_routing_id);
|
||||
|
||||
return GetMaxPriorityAction(std::move(action), std::move(parent_action));
|
||||
@ -230,7 +230,7 @@ void RulesetMatcherBase::OnRenderFrameCreated(content::RenderFrameHost* host) {
|
||||
// commit for the frame is received in the browser (via DidFinishNavigation).
|
||||
// Hence if the parent frame is allowlisted, we allow list the current frame
|
||||
// as well in OnRenderFrameCreated.
|
||||
absl::optional<RequestAction> parent_action =
|
||||
std::optional<RequestAction> parent_action =
|
||||
GetAllowlistedFrameAction(parent->GetGlobalId());
|
||||
if (!parent_action)
|
||||
return;
|
||||
@ -259,11 +259,10 @@ void RulesetMatcherBase::OnDidFinishNavigation(
|
||||
|
||||
// Find the highest priority allowAllRequests action corresponding to this
|
||||
// frame.
|
||||
absl::optional<RequestAction> parent_action =
|
||||
std::optional<RequestAction> parent_action =
|
||||
GetAllowlistedFrameAction(params.parent_routing_id);
|
||||
absl::optional<RequestAction> frame_action =
|
||||
GetAllowAllRequestsAction(params);
|
||||
absl::optional<RequestAction> action =
|
||||
std::optional<RequestAction> frame_action = GetAllowAllRequestsAction(params);
|
||||
std::optional<RequestAction> action =
|
||||
GetMaxPriorityAction(std::move(parent_action), std::move(frame_action));
|
||||
|
||||
content::GlobalRenderFrameHostId frame_id = host->GetGlobalId();
|
||||
@ -273,7 +272,7 @@ void RulesetMatcherBase::OnDidFinishNavigation(
|
||||
allowlisted_frames_.insert(std::make_pair(frame_id, std::move(*action)));
|
||||
}
|
||||
|
||||
absl::optional<RequestAction>
|
||||
std::optional<RequestAction>
|
||||
RulesetMatcherBase::GetAllowlistedFrameActionForTesting(
|
||||
content::RenderFrameHost* host) const {
|
||||
DCHECK(host);
|
||||
@ -301,12 +300,12 @@ RequestAction RulesetMatcherBase::CreateAllowAllRequestsAction(
|
||||
return CreateRequestAction(RequestAction::Type::ALLOW_ALL_REQUESTS, rule);
|
||||
}
|
||||
|
||||
absl::optional<RequestAction> RulesetMatcherBase::CreateUpgradeAction(
|
||||
std::optional<RequestAction> RulesetMatcherBase::CreateUpgradeAction(
|
||||
const RequestParams& params,
|
||||
const url_pattern_index::flat::UrlRule& rule) const {
|
||||
if (!IsUpgradeableUrl(*params.url)) {
|
||||
// TODO(crbug.com/1033780): this results in counterintuitive behavior.
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
RequestAction upgrade_action =
|
||||
CreateRequestAction(RequestAction::Type::UPGRADE, rule);
|
||||
@ -314,7 +313,7 @@ absl::optional<RequestAction> RulesetMatcherBase::CreateUpgradeAction(
|
||||
return upgrade_action;
|
||||
}
|
||||
|
||||
absl::optional<RequestAction>
|
||||
std::optional<RequestAction>
|
||||
RulesetMatcherBase::CreateRedirectActionFromMetadata(
|
||||
const RequestParams& params,
|
||||
const url_pattern_index::flat::UrlRule& rule,
|
||||
@ -344,18 +343,18 @@ RulesetMatcherBase::CreateRedirectActionFromMetadata(
|
||||
return CreateRedirectAction(params, rule, std::move(redirect_url));
|
||||
}
|
||||
|
||||
absl::optional<RequestAction> RulesetMatcherBase::CreateRedirectAction(
|
||||
std::optional<RequestAction> RulesetMatcherBase::CreateRedirectAction(
|
||||
const RequestParams& params,
|
||||
const url_pattern_index::flat::UrlRule& rule,
|
||||
GURL redirect_url) const {
|
||||
// Redirecting WebSocket handshake request is prohibited.
|
||||
// TODO(crbug.com/1033780): this results in counterintuitive behavior.
|
||||
if (params.element_type == flat_rule::ElementType_WEBSOCKET)
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
// Prevent a redirect loop where a URL continuously redirects to itself.
|
||||
if (!redirect_url.is_valid() || *params.url == redirect_url)
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
RequestAction redirect_action =
|
||||
CreateRequestAction(RequestAction::Type::REDIRECT, rule);
|
||||
@ -409,11 +408,11 @@ RequestAction RulesetMatcherBase::CreateRequestAction(
|
||||
extension_id());
|
||||
}
|
||||
|
||||
absl::optional<RequestAction> RulesetMatcherBase::GetAllowlistedFrameAction(
|
||||
std::optional<RequestAction> RulesetMatcherBase::GetAllowlistedFrameAction(
|
||||
content::GlobalRenderFrameHostId frame_id) const {
|
||||
auto it = allowlisted_frames_.find(frame_id);
|
||||
if (it == allowlisted_frames_.end())
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
return it->second.Clone();
|
||||
}
|
||||
|
@ -6,14 +6,13 @@
|
||||
#define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_RULESET_MATCHER_BASE_H_
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "content/public/browser/global_routing_id.h"
|
||||
#include "extensions/browser/api/declarative_net_request/flat/extension_ruleset_generated.h"
|
||||
#include "extensions/browser/api/declarative_net_request/request_action.h"
|
||||
#include "extensions/common/api/declarative_net_request/constants.h"
|
||||
#include "extensions/common/extension_id.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
class GURL;
|
||||
|
||||
@ -39,17 +38,17 @@ class RulesetMatcherBase {
|
||||
virtual ~RulesetMatcherBase();
|
||||
|
||||
// Returns the ruleset's highest priority matching RequestAction for the
|
||||
// onBeforeRequest phase, or absl::nullopt if the ruleset has no matching
|
||||
// onBeforeRequest phase, or std::nullopt if the ruleset has no matching
|
||||
// rule. Also takes into account any matching allowAllRequests rules for the
|
||||
// ancestor frames.
|
||||
absl::optional<RequestAction> GetBeforeRequestAction(
|
||||
std::optional<RequestAction> GetBeforeRequestAction(
|
||||
const RequestParams& params) const;
|
||||
|
||||
// Returns a vector of RequestAction for all matching modifyHeaders rules
|
||||
// with priority greater than |min_priority| if specified.
|
||||
virtual std::vector<RequestAction> GetModifyHeadersActions(
|
||||
const RequestParams& params,
|
||||
absl::optional<uint64_t> min_priority) const = 0;
|
||||
std::optional<uint64_t> min_priority) const = 0;
|
||||
|
||||
// Returns whether this modifies "extraHeaders".
|
||||
virtual bool IsExtraHeadersMatcher() const = 0;
|
||||
@ -69,7 +68,7 @@ class RulesetMatcherBase {
|
||||
|
||||
// Returns the tracked highest priority matching allowsAllRequests action, if
|
||||
// any, for |host|.
|
||||
absl::optional<RequestAction> GetAllowlistedFrameActionForTesting(
|
||||
std::optional<RequestAction> GetAllowlistedFrameActionForTesting(
|
||||
content::RenderFrameHost* host) const;
|
||||
|
||||
protected:
|
||||
@ -92,19 +91,19 @@ class RulesetMatcherBase {
|
||||
const url_pattern_index::flat::UrlRule& rule) const;
|
||||
|
||||
// Helper to create a RequestAction of type |REDIRECT| with the request
|
||||
// upgraded. Returns absl::nullopt if the request is not upgradeable.
|
||||
absl::optional<RequestAction> CreateUpgradeAction(
|
||||
// upgraded. Returns std::nullopt if the request is not upgradeable.
|
||||
std::optional<RequestAction> CreateUpgradeAction(
|
||||
const RequestParams& params,
|
||||
const url_pattern_index::flat::UrlRule& rule) const;
|
||||
|
||||
// Helpers to create a RequestAction of type |REDIRECT| with the appropriate
|
||||
// redirect url. Can return absl::nullopt if the redirect url is ill-formed or
|
||||
// redirect url. Can return std::nullopt if the redirect url is ill-formed or
|
||||
// same as the current request url.
|
||||
absl::optional<RequestAction> CreateRedirectActionFromMetadata(
|
||||
std::optional<RequestAction> CreateRedirectActionFromMetadata(
|
||||
const RequestParams& params,
|
||||
const url_pattern_index::flat::UrlRule& rule,
|
||||
const ExtensionMetadataList& metadata_list) const;
|
||||
absl::optional<RequestAction> CreateRedirectAction(
|
||||
std::optional<RequestAction> CreateRedirectAction(
|
||||
const RequestParams& params,
|
||||
const url_pattern_index::flat::UrlRule& rule,
|
||||
GURL redirect_url) const;
|
||||
@ -118,17 +117,17 @@ class RulesetMatcherBase {
|
||||
|
||||
private:
|
||||
// Returns the ruleset's highest priority matching allowAllRequests action or
|
||||
// absl::nullopt if there is no corresponding matching rule. Only takes into
|
||||
// std::nullopt if there is no corresponding matching rule. Only takes into
|
||||
// account the request |params| passed in. This doesn't take any account any
|
||||
// matching allowAllRequests rules for ancestor frames.
|
||||
virtual absl::optional<RequestAction> GetAllowAllRequestsAction(
|
||||
virtual std::optional<RequestAction> GetAllowAllRequestsAction(
|
||||
const RequestParams& params) const = 0;
|
||||
|
||||
// Returns the ruleset's highest priority matching RequestAction for the
|
||||
// onBeforeRequest phase, or absl::nullopt if the ruleset has no matching
|
||||
// onBeforeRequest phase, or std::nullopt if the ruleset has no matching
|
||||
// rule. This doesn't take any account any matching allowAllRequests rules for
|
||||
// ancestor frames.
|
||||
virtual absl::optional<RequestAction> GetBeforeRequestActionIgnoringAncestors(
|
||||
virtual std::optional<RequestAction> GetBeforeRequestActionIgnoringAncestors(
|
||||
const RequestParams& params) const = 0;
|
||||
|
||||
RequestAction CreateRequestAction(
|
||||
@ -136,8 +135,8 @@ class RulesetMatcherBase {
|
||||
const url_pattern_index::flat::UrlRule& rule) const;
|
||||
|
||||
// Returns the matching RequestAction from |allowlisted_frames_| or
|
||||
// absl::nullopt if none is found.
|
||||
absl::optional<RequestAction> GetAllowlistedFrameAction(
|
||||
// std::nullopt if none is found.
|
||||
std::optional<RequestAction> GetAllowlistedFrameAction(
|
||||
content::GlobalRenderFrameHostId frame_id) const;
|
||||
|
||||
const ExtensionId extension_id_;
|
||||
|
@ -90,7 +90,7 @@ TEST_F(RulesetMatcherTest, RedirectRule) {
|
||||
params.element_type = url_pattern_index::flat::ElementType_SUBDOCUMENT;
|
||||
params.is_third_party = true;
|
||||
|
||||
absl::optional<RequestAction> redirect_action =
|
||||
std::optional<RequestAction> redirect_action =
|
||||
matcher->GetBeforeRequestAction(params);
|
||||
ASSERT_TRUE(redirect_action);
|
||||
ASSERT_EQ(redirect_action->type, RequestAction::Type::REDIRECT);
|
||||
@ -198,7 +198,7 @@ TEST_F(RulesetMatcherTest, ModifyHeaders) {
|
||||
rule_1.condition->url_filter = std::string("example.com");
|
||||
rule_1.action->type = std::string("modifyHeaders");
|
||||
rule_1.action->request_headers = std::vector<TestHeaderInfo>(
|
||||
{TestHeaderInfo("header1", "remove", absl::nullopt)});
|
||||
{TestHeaderInfo("header1", "remove", std::nullopt)});
|
||||
|
||||
TestRule rule_2 = CreateGenericRule();
|
||||
rule_2.id = kMinValidID + 1;
|
||||
@ -207,7 +207,7 @@ TEST_F(RulesetMatcherTest, ModifyHeaders) {
|
||||
rule_2.action->type = std::string("modifyHeaders");
|
||||
rule_2.action->request_headers = std::vector<TestHeaderInfo>(
|
||||
{TestHeaderInfo("header1", "set", "value1"),
|
||||
TestHeaderInfo("header2", "remove", absl::nullopt)});
|
||||
TestHeaderInfo("header2", "remove", std::nullopt)});
|
||||
|
||||
std::unique_ptr<RulesetMatcher> matcher;
|
||||
ASSERT_TRUE(CreateVerifiedMatcher({rule_1, rule_2}, CreateTemporarySource(),
|
||||
@ -226,7 +226,7 @@ TEST_F(RulesetMatcherTest, ModifyHeaders) {
|
||||
RequestAction expected_rule_1_action = CreateRequestActionForTesting(
|
||||
RequestAction::Type::MODIFY_HEADERS, *rule_1.id, *rule_1.priority);
|
||||
expected_rule_1_action.request_headers_to_modify = {RequestAction::HeaderInfo(
|
||||
"header1", dnr_api::HeaderOperation::kRemove, absl::nullopt)};
|
||||
"header1", dnr_api::HeaderOperation::kRemove, std::nullopt)};
|
||||
|
||||
RequestAction expected_rule_2_action = CreateRequestActionForTesting(
|
||||
RequestAction::Type::MODIFY_HEADERS, *rule_2.id, *rule_2.priority);
|
||||
@ -234,7 +234,7 @@ TEST_F(RulesetMatcherTest, ModifyHeaders) {
|
||||
RequestAction::HeaderInfo("header1", dnr_api::HeaderOperation::kSet,
|
||||
"value1"),
|
||||
RequestAction::HeaderInfo("header2", dnr_api::HeaderOperation::kRemove,
|
||||
absl::nullopt)};
|
||||
std::nullopt)};
|
||||
|
||||
EXPECT_THAT(modify_header_actions,
|
||||
testing::UnorderedElementsAre(
|
||||
@ -261,7 +261,7 @@ TEST_F(RulesetMatcherTest, RedirectToExtensionPath) {
|
||||
RequestParams params;
|
||||
params.url = &example_url;
|
||||
|
||||
absl::optional<RequestAction> redirect_action =
|
||||
std::optional<RequestAction> redirect_action =
|
||||
matcher->GetBeforeRequestAction(params);
|
||||
|
||||
RequestAction expected_action = CreateRequestActionForTesting(
|
||||
@ -288,7 +288,7 @@ TEST_F(RulesetMatcherTest, RedirectToStaticUrl) {
|
||||
RequestParams params;
|
||||
params.url = &example_url;
|
||||
|
||||
absl::optional<RequestAction> redirect_action =
|
||||
std::optional<RequestAction> redirect_action =
|
||||
matcher->GetBeforeRequestAction(params);
|
||||
|
||||
ASSERT_TRUE(redirect_action.has_value());
|
||||
@ -302,7 +302,7 @@ TEST_F(RulesetMatcherTest, UrlTransform) {
|
||||
struct TestCase {
|
||||
std::string url;
|
||||
// Valid if a redirect is expected.
|
||||
absl::optional<std::string> expected_redirect_url;
|
||||
std::optional<std::string> expected_redirect_url;
|
||||
};
|
||||
|
||||
std::vector<TestCase> cases;
|
||||
@ -371,8 +371,7 @@ TEST_F(RulesetMatcherTest, UrlTransform) {
|
||||
{"http://user@7.com/xyz", "http://new_user:new_pass@7.com/xyz"});
|
||||
|
||||
auto make_query = [](const std::string& key, const std::string& value,
|
||||
const absl::optional<bool>& replace_only =
|
||||
absl::nullopt) {
|
||||
const std::optional<bool>& replace_only = std::nullopt) {
|
||||
TestRuleQueryKeyValue query;
|
||||
query.key = key;
|
||||
query.value = value;
|
||||
@ -403,7 +402,7 @@ TEST_F(RulesetMatcherTest, UrlTransform) {
|
||||
std::vector<std::string>({"r1", "r2"});
|
||||
rules.push_back(rule);
|
||||
// No redirect is performed since the url won't change.
|
||||
cases.push_back({"http://9.com/path?query#fragment", absl::nullopt});
|
||||
cases.push_back({"http://9.com/path?query#fragment", std::nullopt});
|
||||
|
||||
rule = create_transform_rule(10, "||10.com");
|
||||
rule.action->redirect->transform->query_transform.emplace();
|
||||
@ -445,7 +444,7 @@ TEST_F(RulesetMatcherTest, UrlTransform) {
|
||||
RequestParams params;
|
||||
params.url = &url;
|
||||
|
||||
absl::optional<RequestAction> redirect_action =
|
||||
std::optional<RequestAction> redirect_action =
|
||||
matcher->GetBeforeRequestAction(params);
|
||||
|
||||
if (!test_case.expected_redirect_url) {
|
||||
@ -513,8 +512,8 @@ TEST_F(RulesetMatcherTest, RegexRules) {
|
||||
|
||||
struct TestCase {
|
||||
const char* url = nullptr;
|
||||
absl::optional<RequestAction> expected_action;
|
||||
absl::optional<RequestAction> expected_modify_header_action;
|
||||
std::optional<RequestAction> expected_action;
|
||||
std::optional<RequestAction> expected_modify_header_action;
|
||||
};
|
||||
|
||||
std::vector<TestCase> test_cases;
|
||||
@ -673,7 +672,7 @@ TEST_F(RulesetMatcherTest, RegexRules_Metadata) {
|
||||
url_pattern_index::flat::ElementType element_type =
|
||||
url_pattern_index::flat::ElementType_OTHER;
|
||||
bool is_third_party = false;
|
||||
absl::optional<RequestAction> expected_action;
|
||||
std::optional<RequestAction> expected_action;
|
||||
};
|
||||
std::vector<TestCase> test_cases;
|
||||
|
||||
@ -819,14 +818,14 @@ TEST_F(RulesetMatcherTest, RegexAndFilterListRules_RedirectPriority) {
|
||||
const char* action_type;
|
||||
const char* filter;
|
||||
bool is_regex_rule;
|
||||
absl::optional<std::string> redirect_url;
|
||||
std::optional<std::string> redirect_url;
|
||||
} rule_info[] = {
|
||||
{1, 1, "redirect", "filter.com", false, "http://redirect_filter.com"},
|
||||
{2, 1, "upgradeScheme", "regex\\.com", true, absl::nullopt},
|
||||
{2, 1, "upgradeScheme", "regex\\.com", true, std::nullopt},
|
||||
{3, 9, "redirect", "common1.com", false, "http://common1_filter.com"},
|
||||
{4, 10, "redirect", "common1\\.com", true, "http://common1_regex.com"},
|
||||
{5, 10, "upgradeScheme", "common2.com", false, absl::nullopt},
|
||||
{6, 9, "upgradeScheme", "common2\\.com", true, absl::nullopt},
|
||||
{5, 10, "upgradeScheme", "common2.com", false, std::nullopt},
|
||||
{6, 9, "upgradeScheme", "common2\\.com", true, std::nullopt},
|
||||
{7, 10, "redirect", "abc\\.com", true, "http://example1.com"},
|
||||
{8, 9, "redirect", "abc", true, "http://example2.com"},
|
||||
};
|
||||
@ -857,7 +856,7 @@ TEST_F(RulesetMatcherTest, RegexAndFilterListRules_RedirectPriority) {
|
||||
|
||||
struct TestCase {
|
||||
const char* url = nullptr;
|
||||
absl::optional<RequestAction> expected_action;
|
||||
std::optional<RequestAction> expected_action;
|
||||
};
|
||||
std::vector<TestCase> test_cases;
|
||||
|
||||
@ -942,17 +941,17 @@ TEST_F(RulesetMatcherTest, RegexAndFilterListRules_ModifyHeaders) {
|
||||
rule.action->type = "modifyHeaders";
|
||||
rule.condition->url_filter = "abc";
|
||||
rule.action->request_headers = std::vector<TestHeaderInfo>(
|
||||
{TestHeaderInfo("header1", "remove", absl::nullopt),
|
||||
TestHeaderInfo("header2", "remove", absl::nullopt)});
|
||||
{TestHeaderInfo("header1", "remove", std::nullopt),
|
||||
TestHeaderInfo("header2", "remove", std::nullopt)});
|
||||
rules.push_back(rule);
|
||||
|
||||
RequestAction action_1 = CreateRequestActionForTesting(
|
||||
RequestAction::Type::MODIFY_HEADERS, 1, *rule.priority);
|
||||
action_1.request_headers_to_modify = {
|
||||
RequestAction::HeaderInfo("header1", dnr_api::HeaderOperation::kRemove,
|
||||
absl::nullopt),
|
||||
std::nullopt),
|
||||
RequestAction::HeaderInfo("header2", dnr_api::HeaderOperation::kRemove,
|
||||
absl::nullopt)};
|
||||
std::nullopt)};
|
||||
|
||||
rule = CreateGenericRule();
|
||||
rule.id = 2;
|
||||
@ -961,17 +960,17 @@ TEST_F(RulesetMatcherTest, RegexAndFilterListRules_ModifyHeaders) {
|
||||
rule.condition->regex_filter = "example";
|
||||
rule.action->type = "modifyHeaders";
|
||||
rule.action->request_headers = std::vector<TestHeaderInfo>(
|
||||
{TestHeaderInfo("header1", "remove", absl::nullopt),
|
||||
TestHeaderInfo("header3", "remove", absl::nullopt)});
|
||||
{TestHeaderInfo("header1", "remove", std::nullopt),
|
||||
TestHeaderInfo("header3", "remove", std::nullopt)});
|
||||
rules.push_back(rule);
|
||||
|
||||
RequestAction action_2 = CreateRequestActionForTesting(
|
||||
RequestAction::Type::MODIFY_HEADERS, 2, *rule.priority);
|
||||
action_2.request_headers_to_modify = {
|
||||
RequestAction::HeaderInfo("header1", dnr_api::HeaderOperation::kRemove,
|
||||
absl::nullopt),
|
||||
std::nullopt),
|
||||
RequestAction::HeaderInfo("header3", dnr_api::HeaderOperation::kRemove,
|
||||
absl::nullopt)};
|
||||
std::nullopt)};
|
||||
|
||||
std::unique_ptr<RulesetMatcher> matcher;
|
||||
ASSERT_TRUE(CreateVerifiedMatcher(rules, CreateTemporarySource(), &matcher));
|
||||
@ -1075,7 +1074,7 @@ TEST_F(RulesetMatcherTest, RegexSubstitution) {
|
||||
|
||||
struct {
|
||||
std::string url;
|
||||
absl::optional<RequestAction> expected_action;
|
||||
std::optional<RequestAction> expected_action;
|
||||
} test_cases[] = {
|
||||
{"http://google.com/path?query",
|
||||
create_redirect_action(
|
||||
@ -1085,14 +1084,14 @@ TEST_F(RulesetMatcherTest, RegexSubstitution) {
|
||||
{"http://example.com/path?q1=1&redirect=facebook.com&q2=2",
|
||||
create_redirect_action(3, "http://facebook.com")},
|
||||
// The redirect url here would have been "http://" which is invalid.
|
||||
{"http://example.com/path?q1=1&redirect=&q2=2", absl::nullopt},
|
||||
{"http://example.com/path?q1=1&redirect=&q2=2", std::nullopt},
|
||||
{"https://reddit.com", create_redirect_action(4, "https://abc.com")},
|
||||
{"http://www.rst.xyz.com/path",
|
||||
create_redirect_action(5, "https://rst.xyz.com/path")},
|
||||
{"http://yahoo.in/path",
|
||||
create_redirect_action(6, "http://yahoo.co.in/path")},
|
||||
// No match.
|
||||
{"http://example.com", absl::nullopt}};
|
||||
{"http://example.com", std::nullopt}};
|
||||
|
||||
for (const auto& test_case : test_cases) {
|
||||
SCOPED_TRACE(test_case.url);
|
||||
@ -1148,7 +1147,7 @@ TEST_F(RulesetMatcherTest, RulesCount) {
|
||||
ASSERT_TRUE(matcher);
|
||||
EXPECT_EQ(kNumRegexRules + kNumNonRegexRules, matcher->GetRulesCount());
|
||||
// For static rulesets, no rules are considered unsafe.
|
||||
EXPECT_EQ(absl::nullopt, matcher->GetUnsafeRulesCount());
|
||||
EXPECT_EQ(std::nullopt, matcher->GetUnsafeRulesCount());
|
||||
EXPECT_EQ(kNumRegexRules, matcher->GetRegexRulesCount());
|
||||
|
||||
// Recreate `matcher` for a dynamic ruleset to test that unsafe rule count is
|
||||
@ -1166,7 +1165,7 @@ TEST_F(RulesetMatcherTest, RulesCount) {
|
||||
CreateVerifiedMatcher({} /* rules */, CreateTemporarySource(), &matcher));
|
||||
ASSERT_TRUE(matcher);
|
||||
EXPECT_EQ(0u, matcher->GetRulesCount());
|
||||
EXPECT_EQ(absl::nullopt, matcher->GetUnsafeRulesCount());
|
||||
EXPECT_EQ(std::nullopt, matcher->GetUnsafeRulesCount());
|
||||
EXPECT_EQ(0u, matcher->GetRegexRulesCount());
|
||||
}
|
||||
|
||||
@ -1294,7 +1293,7 @@ TEST_F(AllowAllRequestsTest, AllowlistedFrameTracking) {
|
||||
|
||||
GURL example_url("http://example.com");
|
||||
simulate_navigation(web_contents->GetPrimaryMainFrame(), example_url);
|
||||
absl::optional<RequestAction> action =
|
||||
std::optional<RequestAction> action =
|
||||
matcher->GetAllowlistedFrameActionForTesting(
|
||||
web_contents->GetPrimaryMainFrame());
|
||||
EXPECT_FALSE(action);
|
||||
|
@ -155,7 +155,7 @@ std::ostream& operator<<(std::ostream& output, const RequestAction& action) {
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& output,
|
||||
const absl::optional<RequestAction>& action) {
|
||||
const std::optional<RequestAction>& action) {
|
||||
if (!action)
|
||||
return output << "empty Optional<RequestAction>";
|
||||
return output << *action;
|
||||
@ -455,7 +455,7 @@ FileBackedRulesetSource CreateTemporarySource(RulesetID id,
|
||||
dnr_api::ModifyHeaderInfo CreateModifyHeaderInfo(
|
||||
dnr_api::HeaderOperation operation,
|
||||
std::string header,
|
||||
absl::optional<std::string> value) {
|
||||
std::optional<std::string> value) {
|
||||
dnr_api::ModifyHeaderInfo header_info;
|
||||
|
||||
header_info.operation = operation;
|
||||
|
@ -6,10 +6,10 @@
|
||||
#define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_TEST_UTILS_H_
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "base/scoped_observation.h"
|
||||
@ -22,7 +22,6 @@
|
||||
#include "extensions/common/api/declarative_net_request.h"
|
||||
#include "extensions/common/api/declarative_net_request/constants.h"
|
||||
#include "extensions/common/extension_id.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace content {
|
||||
class BrowserContext;
|
||||
@ -60,7 +59,7 @@ std::ostream& operator<<(std::ostream& output, RequestAction::Type type);
|
||||
std::ostream& operator<<(std::ostream& output, const RequestAction& action);
|
||||
std::ostream& operator<<(std::ostream& output, const ParseResult& result);
|
||||
std::ostream& operator<<(std::ostream& output,
|
||||
const absl::optional<RequestAction>& action);
|
||||
const std::optional<RequestAction>& action);
|
||||
std::ostream& operator<<(std::ostream& output, LoadRulesetResult result);
|
||||
std::ostream& operator<<(std::ostream& output, const RuleCounts& count);
|
||||
|
||||
@ -87,7 +86,7 @@ FileBackedRulesetSource CreateTemporarySource(
|
||||
api::declarative_net_request::ModifyHeaderInfo CreateModifyHeaderInfo(
|
||||
api::declarative_net_request::HeaderOperation operation,
|
||||
std::string header,
|
||||
absl::optional<std::string> value);
|
||||
std::optional<std::string> value);
|
||||
|
||||
bool EqualsForTesting(
|
||||
const api::declarative_net_request::ModifyHeaderInfo& lhs,
|
||||
@ -120,7 +119,7 @@ class RulesetManagerObserver : public RulesetManager::TestObserver {
|
||||
|
||||
const raw_ptr<RulesetManager> manager_;
|
||||
size_t current_count_ = 0;
|
||||
absl::optional<size_t> expected_count_;
|
||||
std::optional<size_t> expected_count_;
|
||||
std::unique_ptr<base::RunLoop> run_loop_;
|
||||
std::vector<GURL> observed_requests_;
|
||||
SEQUENCE_CHECKER(sequence_checker_);
|
||||
|
@ -490,7 +490,7 @@ size_t GetEnabledStaticRuleCount(const CompositeMatcher* composite_matcher) {
|
||||
}
|
||||
|
||||
bool HasDNRFeedbackPermission(const Extension* extension,
|
||||
const absl::optional<int>& tab_id) {
|
||||
const std::optional<int>& tab_id) {
|
||||
const PermissionsData* permissions_data = extension->permissions_data();
|
||||
return tab_id.has_value()
|
||||
? permissions_data->HasAPIPermissionForTab(
|
||||
|
@ -7,9 +7,9 @@
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/auto_reset.h"
|
||||
#include "base/containers/span.h"
|
||||
#include "extensions/browser/api/declarative_net_request/file_backed_ruleset_source.h"
|
||||
@ -17,7 +17,6 @@
|
||||
#include "extensions/browser/api/web_request/web_request_resource_type.h"
|
||||
#include "extensions/common/api/declarative_net_request.h"
|
||||
#include "extensions/common/api/declarative_net_request/constants.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "third_party/re2/src/re2/re2.h"
|
||||
|
||||
namespace base {
|
||||
@ -172,7 +171,7 @@ size_t GetEnabledStaticRuleCount(const CompositeMatcher* composite_matcher);
|
||||
// for the specified |tab_id|. If |tab_is| is omitted, then non-tab specific
|
||||
// permissions are checked.
|
||||
bool HasDNRFeedbackPermission(const Extension* extension,
|
||||
const absl::optional<int>& tab_id);
|
||||
const std::optional<int>& tab_id);
|
||||
|
||||
// Returns the appropriate error string for an unsuccessful rule parsing result.
|
||||
std::string GetParseError(ParseResult error_reason, int rule_id);
|
||||
|
@ -71,16 +71,19 @@ void ParseResponseCookieImpl(const base::Value::Dict& dict,
|
||||
cookie->value = *v;
|
||||
if (const std::string* v = dict.FindString(keys::kExpiresKey))
|
||||
cookie->expires = *v;
|
||||
if (absl::optional<int> v = dict.FindInt(keys::kMaxAgeKey))
|
||||
if (std::optional<int> v = dict.FindInt(keys::kMaxAgeKey)) {
|
||||
cookie->max_age = *v;
|
||||
}
|
||||
if (const std::string* v = dict.FindString(keys::kDomainKey))
|
||||
cookie->domain = *v;
|
||||
if (const std::string* v = dict.FindString(keys::kPathKey))
|
||||
cookie->path = *v;
|
||||
if (absl::optional<bool> v = dict.FindBool(keys::kSecureKey))
|
||||
if (std::optional<bool> v = dict.FindBool(keys::kSecureKey)) {
|
||||
cookie->secure = *v;
|
||||
if (absl::optional<bool> v = dict.FindBool(keys::kHttpOnlyKey))
|
||||
}
|
||||
if (std::optional<bool> v = dict.FindBool(keys::kHttpOnlyKey)) {
|
||||
cookie->http_only = *v;
|
||||
}
|
||||
}
|
||||
|
||||
helpers::ResponseCookie ParseResponseCookie(const base::Value::Dict& dict) {
|
||||
@ -94,12 +97,15 @@ helpers::FilterResponseCookie ParseFilterResponseCookie(
|
||||
helpers::FilterResponseCookie result;
|
||||
ParseResponseCookieImpl(dict, &result);
|
||||
|
||||
if (absl::optional<int> v = dict.FindInt(keys::kAgeUpperBoundKey))
|
||||
if (std::optional<int> v = dict.FindInt(keys::kAgeUpperBoundKey)) {
|
||||
result.age_upper_bound = *v;
|
||||
if (absl::optional<int> v = dict.FindInt(keys::kAgeLowerBoundKey))
|
||||
}
|
||||
if (std::optional<int> v = dict.FindInt(keys::kAgeLowerBoundKey)) {
|
||||
result.age_lower_bound = *v;
|
||||
if (absl::optional<bool> v = dict.FindBool(keys::kSessionCookieKey))
|
||||
}
|
||||
if (std::optional<bool> v = dict.FindBool(keys::kSessionCookieKey)) {
|
||||
result.session_cookie = *v;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -239,7 +245,7 @@ scoped_refptr<const WebRequestAction> CreateIgnoreRulesAction(
|
||||
int minimum_priority = std::numeric_limits<int>::min();
|
||||
std::string ignore_tag;
|
||||
if (value.Find(keys::kLowerPriorityThanKey)) {
|
||||
absl::optional<int> minimum_priority_value =
|
||||
std::optional<int> minimum_priority_value =
|
||||
value.FindInt(keys::kLowerPriorityThanKey);
|
||||
INPUT_FORMAT_VALIDATE(minimum_priority_value);
|
||||
minimum_priority = *minimum_priority_value;
|
||||
@ -492,7 +498,7 @@ void WebRequestAction::Apply(const std::string& extension_id,
|
||||
if (!HasPermission(apply_info, extension_id))
|
||||
return;
|
||||
if (stages() & apply_info->request_data->stage) {
|
||||
absl::optional<EventResponseDelta> delta = CreateDelta(
|
||||
std::optional<EventResponseDelta> delta = CreateDelta(
|
||||
*apply_info->request_data, extension_id, extension_install_time);
|
||||
if (delta.has_value())
|
||||
apply_info->deltas->push_back(std::move(delta.value()));
|
||||
@ -531,7 +537,7 @@ std::string WebRequestCancelAction::GetName() const {
|
||||
return keys::kCancelRequestType;
|
||||
}
|
||||
|
||||
absl::optional<EventResponseDelta> WebRequestCancelAction::CreateDelta(
|
||||
std::optional<EventResponseDelta> WebRequestCancelAction::CreateDelta(
|
||||
const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const {
|
||||
@ -564,13 +570,13 @@ std::string WebRequestRedirectAction::GetName() const {
|
||||
return keys::kRedirectRequestType;
|
||||
}
|
||||
|
||||
absl::optional<EventResponseDelta> WebRequestRedirectAction::CreateDelta(
|
||||
std::optional<EventResponseDelta> WebRequestRedirectAction::CreateDelta(
|
||||
const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const {
|
||||
CHECK(request_data.stage & stages());
|
||||
if (request_data.request->url == redirect_url_)
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
EventResponseDelta result(extension_id, extension_install_time);
|
||||
result.new_url = redirect_url_;
|
||||
return result;
|
||||
@ -594,7 +600,7 @@ std::string WebRequestRedirectToTransparentImageAction::GetName() const {
|
||||
return keys::kRedirectToTransparentImageType;
|
||||
}
|
||||
|
||||
absl::optional<EventResponseDelta>
|
||||
std::optional<EventResponseDelta>
|
||||
WebRequestRedirectToTransparentImageAction::CreateDelta(
|
||||
const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
@ -623,7 +629,7 @@ std::string WebRequestRedirectToEmptyDocumentAction::GetName() const {
|
||||
return keys::kRedirectToEmptyDocumentType;
|
||||
}
|
||||
|
||||
absl::optional<EventResponseDelta>
|
||||
std::optional<EventResponseDelta>
|
||||
WebRequestRedirectToEmptyDocumentAction::CreateDelta(
|
||||
const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
@ -717,7 +723,7 @@ std::string WebRequestRedirectByRegExAction::GetName() const {
|
||||
return keys::kRedirectByRegExType;
|
||||
}
|
||||
|
||||
absl::optional<EventResponseDelta> WebRequestRedirectByRegExAction::CreateDelta(
|
||||
std::optional<EventResponseDelta> WebRequestRedirectByRegExAction::CreateDelta(
|
||||
const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const {
|
||||
@ -728,7 +734,7 @@ absl::optional<EventResponseDelta> WebRequestRedirectByRegExAction::CreateDelta(
|
||||
std::string new_url = old_url;
|
||||
if (!RE2::Replace(&new_url, *from_pattern_, to_pattern_) ||
|
||||
new_url == old_url) {
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
EventResponseDelta result(extension_id, extension_install_time);
|
||||
@ -765,8 +771,7 @@ std::string WebRequestSetRequestHeaderAction::GetName() const {
|
||||
return keys::kSetRequestHeaderType;
|
||||
}
|
||||
|
||||
absl::optional<EventResponseDelta>
|
||||
WebRequestSetRequestHeaderAction::CreateDelta(
|
||||
std::optional<EventResponseDelta> WebRequestSetRequestHeaderAction::CreateDelta(
|
||||
const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const {
|
||||
@ -804,7 +809,7 @@ std::string WebRequestRemoveRequestHeaderAction::GetName() const {
|
||||
return keys::kRemoveRequestHeaderType;
|
||||
}
|
||||
|
||||
absl::optional<EventResponseDelta>
|
||||
std::optional<EventResponseDelta>
|
||||
WebRequestRemoveRequestHeaderAction::CreateDelta(
|
||||
const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
@ -845,7 +850,7 @@ std::string WebRequestAddResponseHeaderAction::GetName() const {
|
||||
return keys::kAddResponseHeaderType;
|
||||
}
|
||||
|
||||
absl::optional<EventResponseDelta>
|
||||
std::optional<EventResponseDelta>
|
||||
WebRequestAddResponseHeaderAction::CreateDelta(
|
||||
const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
@ -854,11 +859,11 @@ WebRequestAddResponseHeaderAction::CreateDelta(
|
||||
const net::HttpResponseHeaders* headers =
|
||||
request_data.original_response_headers;
|
||||
if (!headers)
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
// Don't generate the header if it exists already.
|
||||
if (headers->HasHeaderValue(name_, value_))
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
EventResponseDelta result(extension_id, extension_install_time);
|
||||
result.added_response_headers.push_back(make_pair(name_, value_));
|
||||
@ -898,7 +903,7 @@ std::string WebRequestRemoveResponseHeaderAction::GetName() const {
|
||||
return keys::kRemoveResponseHeaderType;
|
||||
}
|
||||
|
||||
absl::optional<EventResponseDelta>
|
||||
std::optional<EventResponseDelta>
|
||||
WebRequestRemoveResponseHeaderAction::CreateDelta(
|
||||
const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
@ -907,7 +912,7 @@ WebRequestRemoveResponseHeaderAction::CreateDelta(
|
||||
const net::HttpResponseHeaders* headers =
|
||||
request_data.original_response_headers;
|
||||
if (!headers)
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
EventResponseDelta result(extension_id, extension_install_time);
|
||||
size_t iter = 0;
|
||||
@ -949,12 +954,12 @@ std::string WebRequestIgnoreRulesAction::GetName() const {
|
||||
return keys::kIgnoreRulesType;
|
||||
}
|
||||
|
||||
absl::optional<EventResponseDelta> WebRequestIgnoreRulesAction::CreateDelta(
|
||||
std::optional<EventResponseDelta> WebRequestIgnoreRulesAction::CreateDelta(
|
||||
const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const {
|
||||
CHECK(request_data.stage & stages());
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
//
|
||||
@ -994,7 +999,7 @@ std::string WebRequestRequestCookieAction::GetName() const {
|
||||
return "";
|
||||
}
|
||||
|
||||
absl::optional<EventResponseDelta> WebRequestRequestCookieAction::CreateDelta(
|
||||
std::optional<EventResponseDelta> WebRequestRequestCookieAction::CreateDelta(
|
||||
const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const {
|
||||
@ -1042,7 +1047,7 @@ std::string WebRequestResponseCookieAction::GetName() const {
|
||||
return "";
|
||||
}
|
||||
|
||||
absl::optional<EventResponseDelta> WebRequestResponseCookieAction::CreateDelta(
|
||||
std::optional<EventResponseDelta> WebRequestResponseCookieAction::CreateDelta(
|
||||
const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const {
|
||||
@ -1082,7 +1087,7 @@ std::string WebRequestSendMessageToExtensionAction::GetName() const {
|
||||
return keys::kSendMessageToExtensionType;
|
||||
}
|
||||
|
||||
absl::optional<EventResponseDelta>
|
||||
std::optional<EventResponseDelta>
|
||||
WebRequestSendMessageToExtensionAction::CreateDelta(
|
||||
const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
|
@ -7,9 +7,9 @@
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/raw_ref.h"
|
||||
@ -18,7 +18,6 @@
|
||||
#include "extensions/browser/api/declarative_webrequest/request_stage.h"
|
||||
#include "extensions/browser/api/web_request/web_request_api_helpers.h"
|
||||
#include "extensions/common/api/events.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
namespace base {
|
||||
@ -136,7 +135,7 @@ class WebRequestAction : public base::RefCounted<WebRequestAction> {
|
||||
|
||||
// Returns a description of the modification to the request caused by
|
||||
// this action.
|
||||
virtual absl::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
virtual std::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
CreateDelta(const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const = 0;
|
||||
@ -186,7 +185,7 @@ class WebRequestCancelAction : public WebRequestAction {
|
||||
|
||||
// Implementation of WebRequestAction:
|
||||
std::string GetName() const override;
|
||||
absl::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
std::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
CreateDelta(const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const override;
|
||||
@ -206,7 +205,7 @@ class WebRequestRedirectAction : public WebRequestAction {
|
||||
// Implementation of WebRequestAction:
|
||||
bool Equals(const WebRequestAction* other) const override;
|
||||
std::string GetName() const override;
|
||||
absl::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
std::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
CreateDelta(const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const override;
|
||||
@ -229,7 +228,7 @@ class WebRequestRedirectToTransparentImageAction : public WebRequestAction {
|
||||
|
||||
// Implementation of WebRequestAction:
|
||||
std::string GetName() const override;
|
||||
absl::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
std::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
CreateDelta(const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const override;
|
||||
@ -251,7 +250,7 @@ class WebRequestRedirectToEmptyDocumentAction : public WebRequestAction {
|
||||
|
||||
// Implementation of WebRequestAction:
|
||||
std::string GetName() const override;
|
||||
absl::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
std::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
CreateDelta(const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const override;
|
||||
@ -281,7 +280,7 @@ class WebRequestRedirectByRegExAction : public WebRequestAction {
|
||||
// Implementation of WebRequestAction:
|
||||
bool Equals(const WebRequestAction* other) const override;
|
||||
std::string GetName() const override;
|
||||
absl::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
std::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
CreateDelta(const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const override;
|
||||
@ -307,7 +306,7 @@ class WebRequestSetRequestHeaderAction : public WebRequestAction {
|
||||
// Implementation of WebRequestAction:
|
||||
bool Equals(const WebRequestAction* other) const override;
|
||||
std::string GetName() const override;
|
||||
absl::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
std::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
CreateDelta(const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const override;
|
||||
@ -332,7 +331,7 @@ class WebRequestRemoveRequestHeaderAction : public WebRequestAction {
|
||||
// Implementation of WebRequestAction:
|
||||
bool Equals(const WebRequestAction* other) const override;
|
||||
std::string GetName() const override;
|
||||
absl::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
std::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
CreateDelta(const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const override;
|
||||
@ -357,7 +356,7 @@ class WebRequestAddResponseHeaderAction : public WebRequestAction {
|
||||
// Implementation of WebRequestAction:
|
||||
bool Equals(const WebRequestAction* other) const override;
|
||||
std::string GetName() const override;
|
||||
absl::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
std::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
CreateDelta(const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const override;
|
||||
@ -384,7 +383,7 @@ class WebRequestRemoveResponseHeaderAction : public WebRequestAction {
|
||||
// Implementation of WebRequestAction:
|
||||
bool Equals(const WebRequestAction* other) const override;
|
||||
std::string GetName() const override;
|
||||
absl::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
std::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
CreateDelta(const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const override;
|
||||
@ -410,7 +409,7 @@ class WebRequestIgnoreRulesAction : public WebRequestAction {
|
||||
// Implementation of WebRequestAction:
|
||||
bool Equals(const WebRequestAction* other) const override;
|
||||
std::string GetName() const override;
|
||||
absl::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
std::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
CreateDelta(const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const override;
|
||||
@ -440,7 +439,7 @@ class WebRequestRequestCookieAction : public WebRequestAction {
|
||||
// Implementation of WebRequestAction:
|
||||
bool Equals(const WebRequestAction* other) const override;
|
||||
std::string GetName() const override;
|
||||
absl::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
std::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
CreateDelta(const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const override;
|
||||
@ -468,7 +467,7 @@ class WebRequestResponseCookieAction : public WebRequestAction {
|
||||
// Implementation of WebRequestAction:
|
||||
bool Equals(const WebRequestAction* other) const override;
|
||||
std::string GetName() const override;
|
||||
absl::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
std::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
CreateDelta(const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const override;
|
||||
@ -493,7 +492,7 @@ class WebRequestSendMessageToExtensionAction : public WebRequestAction {
|
||||
// Implementation of WebRequestAction:
|
||||
bool Equals(const WebRequestAction* other) const override;
|
||||
std::string GetName() const override;
|
||||
absl::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
std::optional<extension_web_request_api_helpers::EventResponseDelta>
|
||||
CreateDelta(const WebRequestData& request_data,
|
||||
const std::string& extension_id,
|
||||
const base::Time& extension_install_time) const override;
|
||||
|
@ -252,7 +252,7 @@ base::Value::Dict GetDictFromArray(
|
||||
const std::string* name = array[i];
|
||||
const std::string* value = array[i+1];
|
||||
if (base::Value* entry = dict.Find(*name)) {
|
||||
absl::optional<base::Value> entry_owned;
|
||||
std::optional<base::Value> entry_owned;
|
||||
switch (entry->type()) {
|
||||
case base::Value::Type::STRING: {
|
||||
// Replace the present string with a list.
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
@ -26,7 +26,6 @@
|
||||
#include "extensions/common/permissions/api_permission.h"
|
||||
#include "extensions/strings/grit/extensions_strings.h"
|
||||
#include "services/device/public/cpp/usb/usb_ids.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
|
||||
namespace extensions {
|
||||
@ -105,11 +104,11 @@ bool MatchesDevicePermissionEntry(const base::Value::Dict& value,
|
||||
if (!type || *type != TypeToString(entry->type())) {
|
||||
return false;
|
||||
}
|
||||
absl::optional<int> vendor_id = value.FindInt(kDeviceVendorId);
|
||||
std::optional<int> vendor_id = value.FindInt(kDeviceVendorId);
|
||||
if (!vendor_id || vendor_id.value() != entry->vendor_id()) {
|
||||
return false;
|
||||
}
|
||||
absl::optional<int> product_id = value.FindInt(kDeviceProductId);
|
||||
std::optional<int> product_id = value.FindInt(kDeviceProductId);
|
||||
if (!product_id || product_id.value() != entry->product_id()) {
|
||||
return false;
|
||||
}
|
||||
@ -167,18 +166,18 @@ void RemoveDevicePermissionEntry(BrowserContext* context,
|
||||
// Clears all DevicePermissionEntries for the app from ExtensionPrefs.
|
||||
void ClearDevicePermissionEntries(ExtensionPrefs* prefs,
|
||||
const std::string& extension_id) {
|
||||
prefs->UpdateExtensionPref(extension_id, kDevices, absl::nullopt);
|
||||
prefs->UpdateExtensionPref(extension_id, kDevices, std::nullopt);
|
||||
}
|
||||
|
||||
scoped_refptr<DevicePermissionEntry> ReadDevicePermissionEntry(
|
||||
const base::Value::Dict& entry) {
|
||||
absl::optional<int> vendor_id = entry.FindInt(kDeviceVendorId);
|
||||
std::optional<int> vendor_id = entry.FindInt(kDeviceVendorId);
|
||||
if (!vendor_id || vendor_id.value() < 0 ||
|
||||
vendor_id.value() > static_cast<int>(UINT16_MAX)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
absl::optional<int> product_id = entry.FindInt(kDeviceProductId);
|
||||
std::optional<int> product_id = entry.FindInt(kDeviceProductId);
|
||||
if (!product_id || product_id.value() < 0 ||
|
||||
product_id.value() > static_cast<int>(UINT16_MAX)) {
|
||||
return nullptr;
|
||||
|
@ -25,7 +25,7 @@ const char kSize[] = "size";
|
||||
|
||||
bool ParseResult(const std::string& status, std::string* ip, double* latency) {
|
||||
// Parses the result and returns IP and latency.
|
||||
absl::optional<base::Value> parsed_value(base::JSONReader::Read(status));
|
||||
std::optional<base::Value> parsed_value(base::JSONReader::Read(status));
|
||||
if (!parsed_value || !parsed_value->is_dict())
|
||||
return false;
|
||||
|
||||
@ -38,7 +38,7 @@ bool ParseResult(const std::string& status, std::string* ip, double* latency) {
|
||||
if (!iterator->second.is_dict())
|
||||
return false;
|
||||
|
||||
absl::optional<double> avg = iterator->second.GetDict().FindDouble("avg");
|
||||
std::optional<double> avg = iterator->second.GetDict().FindDouble("avg");
|
||||
if (!avg)
|
||||
return false;
|
||||
*latency = *avg;
|
||||
@ -75,7 +75,7 @@ ExtensionFunction::ResponseAction DiagnosticsSendPacketFunction::Run() {
|
||||
}
|
||||
|
||||
void DiagnosticsSendPacketFunction::OnTestICMPCompleted(
|
||||
absl::optional<std::string> status) {
|
||||
std::optional<std::string> status) {
|
||||
std::string ip;
|
||||
double latency;
|
||||
if (!status.has_value() || !ParseResult(status.value(), &ip, &latency)) {
|
||||
|
@ -6,11 +6,10 @@
|
||||
#define EXTENSIONS_BROWSER_API_DIAGNOSTICS_DIAGNOSTICS_API_H_
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "extensions/browser/extension_function.h"
|
||||
#include "extensions/common/api/diagnostics.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace extensions {
|
||||
|
||||
@ -27,7 +26,7 @@ class DiagnosticsSendPacketFunction : public ExtensionFunction {
|
||||
ResponseAction Run() override;
|
||||
|
||||
private:
|
||||
void OnTestICMPCompleted(absl::optional<std::string> status);
|
||||
void OnTestICMPCompleted(std::optional<std::string> status);
|
||||
};
|
||||
|
||||
} // namespace extensions
|
||||
|
@ -29,7 +29,7 @@ DnsResolveFunction::~DnsResolveFunction() = default;
|
||||
|
||||
ExtensionFunction::ResponseAction DnsResolveFunction::Run() {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
absl::optional<Resolve::Params> params = Resolve::Params::Create(args());
|
||||
std::optional<Resolve::Params> params = Resolve::Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
// Intentionally pass host only (no scheme or non-zero port) to only get a
|
||||
@ -46,8 +46,8 @@ ExtensionFunction::ResponseAction DnsResolveFunction::Run() {
|
||||
receiver_.set_disconnect_handler(base::BindOnce(
|
||||
&DnsResolveFunction::OnComplete, base::Unretained(this),
|
||||
net::ERR_NAME_NOT_RESOLVED, net::ResolveErrorInfo(net::ERR_FAILED),
|
||||
/*resolved_addresses=*/absl::nullopt,
|
||||
/*endpoint_results_with_metadata=*/absl::nullopt));
|
||||
/*resolved_addresses=*/std::nullopt,
|
||||
/*endpoint_results_with_metadata=*/std::nullopt));
|
||||
|
||||
// Balanced in OnComplete().
|
||||
AddRef();
|
||||
@ -57,8 +57,8 @@ ExtensionFunction::ResponseAction DnsResolveFunction::Run() {
|
||||
void DnsResolveFunction::OnComplete(
|
||||
int result,
|
||||
const net::ResolveErrorInfo& resolve_error_info,
|
||||
const absl::optional<net::AddressList>& resolved_addresses,
|
||||
const absl::optional<net::HostResolverEndpointResults>&
|
||||
const std::optional<net::AddressList>& resolved_addresses,
|
||||
const std::optional<net::HostResolverEndpointResults>&
|
||||
endpoint_results_with_metadata) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
receiver_.reset();
|
||||
|
@ -31,8 +31,8 @@ class DnsResolveFunction : public ExtensionFunction,
|
||||
// network::mojom::ResolveHostClient implementation:
|
||||
void OnComplete(int result,
|
||||
const net::ResolveErrorInfo& resolve_error_info,
|
||||
const absl::optional<net::AddressList>& resolved_addresses,
|
||||
const absl::optional<net::HostResolverEndpointResults>&
|
||||
const std::optional<net::AddressList>& resolved_addresses,
|
||||
const std::optional<net::HostResolverEndpointResults>&
|
||||
endpoint_results_with_metadata) override;
|
||||
|
||||
// A reference to |this| must be taken while the request is being made on this
|
||||
|
@ -61,7 +61,7 @@ IN_PROC_BROWSER_TEST_F(DnsApiTest, DnsResolveIPLiteral) {
|
||||
resolve_function->set_extension(empty_extension.get());
|
||||
resolve_function->set_has_callback(true);
|
||||
|
||||
absl::optional<base::Value> result(RunFunctionAndReturnSingleResult(
|
||||
std::optional<base::Value> result(RunFunctionAndReturnSingleResult(
|
||||
resolve_function.get(), "[\"127.0.0.1\"]", browser_context()));
|
||||
const base::Value::Dict& dict = result->GetDict();
|
||||
|
||||
@ -83,7 +83,7 @@ IN_PROC_BROWSER_TEST_F(DnsApiTest, DnsResolveHostname) {
|
||||
resolve_function->set_has_callback(true);
|
||||
|
||||
std::string function_arguments = base::StringPrintf(R"(["%s"])", kHostname);
|
||||
absl::optional<base::Value> result(RunFunctionAndReturnSingleResult(
|
||||
std::optional<base::Value> result(RunFunctionAndReturnSingleResult(
|
||||
resolve_function.get(), function_arguments, browser_context()));
|
||||
const base::Value::Dict& dict = result->GetDict();
|
||||
|
||||
|
@ -7,8 +7,8 @@
|
||||
|
||||
#include "extensions/browser/api/execute_code_function.h"
|
||||
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/ranges/algorithm.h"
|
||||
#include "extensions/browser/extension_api_frame_id_map.h"
|
||||
@ -21,7 +21,6 @@
|
||||
#include "extensions/common/mojom/run_location.mojom-shared.h"
|
||||
#include "extensions/common/utils/content_script_utils.h"
|
||||
#include "extensions/common/utils/extension_types_utils.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@ -50,7 +49,7 @@ ExecuteCodeFunction::~ExecuteCodeFunction() {
|
||||
void ExecuteCodeFunction::DidLoadAndLocalizeFile(
|
||||
const std::string& file,
|
||||
std::vector<std::unique_ptr<std::string>> data,
|
||||
absl::optional<std::string> load_error) {
|
||||
std::optional<std::string> load_error) {
|
||||
if (load_error) {
|
||||
// TODO(viettrungluu): bug: there's no particular reason the path should be
|
||||
// UTF-8, in which case this may fail.
|
||||
@ -113,7 +112,7 @@ bool ExecuteCodeFunction::Execute(const std::string& code_string,
|
||||
mojom::CodeInjectionPtr injection;
|
||||
bool is_css_injection = ShouldInsertCSS() || ShouldRemoveCSS();
|
||||
if (is_css_injection) {
|
||||
absl::optional<std::string> injection_key;
|
||||
std::optional<std::string> injection_key;
|
||||
if (host_id_.type == mojom::HostID::HostType::kExtensions) {
|
||||
injection_key = ScriptExecutor::GenerateInjectionKey(
|
||||
host_id_, script_url_, code_string);
|
||||
|
@ -6,14 +6,13 @@
|
||||
#define EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_H_
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "extensions/browser/extension_function.h"
|
||||
#include "extensions/browser/script_executor.h"
|
||||
#include "extensions/common/api/extension_types.h"
|
||||
#include "extensions/common/mojom/host_id.mojom.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace extensions {
|
||||
|
||||
@ -61,7 +60,7 @@ class ExecuteCodeFunction : public ExtensionFunction {
|
||||
// Called when contents from the loaded file have been localized.
|
||||
void DidLoadAndLocalizeFile(const std::string& file,
|
||||
std::vector<std::unique_ptr<std::string>> data,
|
||||
absl::optional<std::string> load_error);
|
||||
std::optional<std::string> load_error);
|
||||
|
||||
const mojom::HostID& host_id() const { return host_id_; }
|
||||
void set_host_id(const mojom::HostID& host_id) { host_id_ = host_id; }
|
||||
@ -80,9 +79,9 @@ class ExecuteCodeFunction : public ExtensionFunction {
|
||||
// |DeleteInjectionDetails|, since the two types are compatible; the value
|
||||
// of |run_at| defaults to |RUN_AT_NONE|.
|
||||
std::optional<api::extension_types::InjectDetails> details_;
|
||||
absl::optional<InitResult> init_result_;
|
||||
std::optional<InitResult> init_result_;
|
||||
// Set iff |init_result_| == FAILURE, holds the error string.
|
||||
absl::optional<std::string> init_error_;
|
||||
std::optional<std::string> init_error_;
|
||||
|
||||
private:
|
||||
void OnExecuteCodeFinished(std::vector<ScriptExecutor::FrameResult> results);
|
||||
|
@ -324,7 +324,7 @@ void FeedbackPrivateGetSystemInformationFunction::OnCompleted(
|
||||
ExtensionFunction::ResponseAction FeedbackPrivateReadLogSourceFunction::Run() {
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
using Params = feedback_private::ReadLogSource::Params;
|
||||
absl::optional<Params> api_params = Params::Create(args());
|
||||
std::optional<Params> api_params = Params::Create(args());
|
||||
|
||||
LogSourceAccessManager* log_source_manager =
|
||||
FeedbackPrivateAPI::GetFactoryInstance()
|
||||
@ -356,7 +356,7 @@ void FeedbackPrivateReadLogSourceFunction::OnCompleted(
|
||||
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
|
||||
ExtensionFunction::ResponseAction FeedbackPrivateSendFeedbackFunction::Run() {
|
||||
absl::optional<feedback_private::SendFeedback::Params> params =
|
||||
std::optional<feedback_private::SendFeedback::Params> params =
|
||||
feedback_private::SendFeedback::Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
@ -391,7 +391,7 @@ void FeedbackPrivateSendFeedbackFunction::OnCompleted(
|
||||
}
|
||||
|
||||
ExtensionFunction::ResponseAction FeedbackPrivateOpenFeedbackFunction::Run() {
|
||||
absl::optional<feedback_private::OpenFeedback::Params> params =
|
||||
std::optional<feedback_private::OpenFeedback::Params> params =
|
||||
feedback_private::OpenFeedback::Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
|
@ -85,7 +85,7 @@ class FeedbackPrivateApiUnittest : public FeedbackPrivateApiUnittestBase {
|
||||
scoped_refptr<FeedbackPrivateReadLogSourceFunction> function =
|
||||
base::MakeRefCounted<FeedbackPrivateReadLogSourceFunction>();
|
||||
|
||||
absl::optional<base::Value> result_value =
|
||||
std::optional<base::Value> result_value =
|
||||
RunFunctionAndReturnValue(function.get(), ParamsToJSON(params));
|
||||
if (!result_value)
|
||||
return testing::AssertionFailure() << "No result";
|
||||
@ -127,7 +127,7 @@ class FeedbackPrivateApiUnittest : public FeedbackPrivateApiUnittestBase {
|
||||
base::Value values = base::test::ParseJson(args);
|
||||
EXPECT_TRUE(values.is_list());
|
||||
|
||||
absl::optional<api::feedback_private::SendFeedback::Params> params =
|
||||
std::optional<api::feedback_private::SendFeedback::Params> params =
|
||||
api::feedback_private::SendFeedback::Params::Create(values.GetList());
|
||||
EXPECT_TRUE(params);
|
||||
|
||||
@ -136,7 +136,7 @@ class FeedbackPrivateApiUnittest : public FeedbackPrivateApiUnittestBase {
|
||||
|
||||
auto function = base::MakeRefCounted<FeedbackPrivateSendFeedbackFunction>();
|
||||
|
||||
absl::optional<base::Value> result_value =
|
||||
std::optional<base::Value> result_value =
|
||||
RunFunctionAndReturnValue(function.get(), args);
|
||||
EXPECT_TRUE(result_value);
|
||||
|
||||
|
@ -78,7 +78,7 @@ void OnGetMimeTypeFromFileForNonNativeLocalPathCompleted(
|
||||
void OnGetMimeTypeFromMetadataForNonNativeLocalPathCompleted(
|
||||
const base::FilePath& local_path,
|
||||
base::OnceCallback<void(const std::string&)> callback,
|
||||
const absl::optional<std::string>& mime_type) {
|
||||
const std::optional<std::string>& mime_type) {
|
||||
if (mime_type) {
|
||||
std::move(callback).Run(mime_type.value());
|
||||
return;
|
||||
|
@ -5,11 +5,10 @@
|
||||
#ifndef EXTENSIONS_BROWSER_API_FILE_HANDLERS_NON_NATIVE_FILE_SYSTEM_DELEGATE_H_
|
||||
#define EXTENSIONS_BROWSER_API_FILE_HANDLERS_NON_NATIVE_FILE_SYSTEM_DELEGATE_H_
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/functional/callback.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace content {
|
||||
class BrowserContext;
|
||||
@ -38,8 +37,7 @@ class NonNativeFileSystemDelegate {
|
||||
virtual void GetNonNativeLocalPathMimeType(
|
||||
content::BrowserContext* context,
|
||||
const base::FilePath& path,
|
||||
base::OnceCallback<void(const absl::optional<std::string>&)>
|
||||
callback) = 0;
|
||||
base::OnceCallback<void(const std::optional<std::string>&)> callback) = 0;
|
||||
|
||||
// Checks whether |path| points to a non-local filesystem directory and calls
|
||||
// |callback| with the result asynchronously.
|
||||
|
@ -621,8 +621,8 @@ void FileSystemChooseEntryFunction::OnDirectoryAccessConfirmed(
|
||||
void FileSystemChooseEntryFunction::BuildFileTypeInfo(
|
||||
ui::SelectFileDialog::FileTypeInfo* file_type_info,
|
||||
const base::FilePath::StringType& suggested_extension,
|
||||
const absl::optional<AcceptOptions>& accepts,
|
||||
const absl::optional<bool>& accepts_all_types) {
|
||||
const std::optional<AcceptOptions>& accepts,
|
||||
const std::optional<bool>& accepts_all_types) {
|
||||
file_type_info->include_all_files = accepts_all_types.value_or(true);
|
||||
|
||||
bool need_suggestion =
|
||||
@ -654,7 +654,7 @@ void FileSystemChooseEntryFunction::BuildFileTypeInfo(
|
||||
}
|
||||
|
||||
void FileSystemChooseEntryFunction::BuildSuggestion(
|
||||
const absl::optional<std::string>& opt_name,
|
||||
const std::optional<std::string>& opt_name,
|
||||
base::FilePath* suggested_name,
|
||||
base::FilePath::StringType* suggested_extension) {
|
||||
if (opt_name) {
|
||||
@ -711,7 +711,7 @@ void FileSystemChooseEntryFunction::MaybeUseManagedSavePath(
|
||||
FileSystemChooseEntryFunction::~FileSystemChooseEntryFunction() = default;
|
||||
|
||||
ExtensionFunction::ResponseAction FileSystemChooseEntryFunction::Run() {
|
||||
absl::optional<ChooseEntry::Params> params =
|
||||
std::optional<ChooseEntry::Params> params =
|
||||
ChooseEntry::Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
@ -985,7 +985,7 @@ FileSystemRequestFileSystemFunction::~FileSystemRequestFileSystemFunction() =
|
||||
|
||||
ExtensionFunction::ResponseAction FileSystemRequestFileSystemFunction::Run() {
|
||||
using file_system::RequestFileSystem::Params;
|
||||
const absl::optional<Params> params = Params::Create(args());
|
||||
const std::optional<Params> params = Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
consent_provider_ =
|
||||
@ -1066,7 +1066,7 @@ FileSystemRequestFileSystemFunction::~FileSystemRequestFileSystemFunction() =
|
||||
|
||||
ExtensionFunction::ResponseAction FileSystemRequestFileSystemFunction::Run() {
|
||||
using file_system::RequestFileSystem::Params;
|
||||
const absl::optional<Params> params = Params::Create(args());
|
||||
const std::optional<Params> params = Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
NOTIMPLEMENTED();
|
||||
|
@ -146,9 +146,9 @@ class FileSystemChooseEntryFunction : public FileSystemEntryFunction {
|
||||
static void BuildFileTypeInfo(
|
||||
ui::SelectFileDialog::FileTypeInfo* file_type_info,
|
||||
const base::FilePath::StringType& suggested_extension,
|
||||
const absl::optional<AcceptOptions>& accepts,
|
||||
const absl::optional<bool>& accepts_all_types);
|
||||
static void BuildSuggestion(const absl::optional<std::string>& opt_name,
|
||||
const std::optional<AcceptOptions>& accepts,
|
||||
const std::optional<bool>& accepts_all_types);
|
||||
static void BuildSuggestion(const std::optional<std::string>& opt_name,
|
||||
base::FilePath* suggested_name,
|
||||
base::FilePath::StringType* suggested_extension);
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user