Reland "[Payments] Enable shipping and contact info delegation [4/5]"

This is a reland of 3dd95e215bbb616913239ed37e61d15e894cf561
The payment_method_change_response is not renamed in the reland since clank
repository is using PaymentMethodChangeResponse.
The rename will be landed in a separate cl.

Original change's description:
> [Payments] Enable shipping and contact info delegation [4/5]
>
> This cl implements shipping address/option change events for PH. With
> this change payment handlers can notify the merchant when the user
> changes the selected shipping address/option, and wait for updated
> details (e.g. new shipping cost, etc) from merchant.
>
> For overall flow please check
> https://chromium-review.googlesource.com/c/chromium/src/+/1779003
>
> Bug: 984694
> Change-Id: Id881ba22bf4c846a4570801bacc49e5d4e89a72b
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1804557
> Reviewed-by: Mike West <[email protected]>
> Reviewed-by: Rouslan Solomakhin <[email protected]>
> Commit-Queue: Sahel Sharify <[email protected]>
> Cr-Commit-Position: refs/heads/master@{#700238}

Bug: 984694
Change-Id: I9a1a84e56701287eb3625b6a681a3f346c47a6e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1828101
Reviewed-by: Mike West <[email protected]>
Reviewed-by: Rouslan Solomakhin <[email protected]>
Commit-Queue: Sahel Sharify <[email protected]>
Cr-Commit-Position: refs/heads/master@{#701255}
diff --git a/components/payments/content/payment_request.cc b/components/payments/content/payment_request.cc
index d69d1ca..3d75a590 100644
--- a/components/payments/content/payment_request.cc
+++ b/components/payments/content/payment_request.cc
@@ -70,6 +70,22 @@
   return output;
 }
 
+// Redact shipping address before exposing it in ShippingAddressChangeEvent.
+// https://w3c.github.io/payment-request/#shipping-address-changed-algorithm
+mojom::PaymentAddressPtr RedactShippingAddress(
+    mojom::PaymentAddressPtr address) {
+  DCHECK(address);
+  if (!PaymentsExperimentalFeatures::IsEnabled(
+          features::kWebPaymentsRedactShippingAddress)) {
+    return address;
+  }
+  address->organization.clear();
+  address->phone.clear();
+  address->recipient.clear();
+  address->address_line.clear();
+  return address;
+}
+
 }  // namespace
 
 PaymentRequest::PaymentRequest(
@@ -326,7 +342,7 @@
   }
 
   if (state()->selected_instrument() && state()->IsPaymentAppInvoked() &&
-      payment_handler_host_.is_changing_payment_method()) {
+      payment_handler_host_.is_changing()) {
     payment_handler_host_.UpdateWith(
         PaymentDetailsConverter::ConvertToPaymentMethodChangeResponse(
             details, base::BindRepeating(
@@ -369,8 +385,7 @@
 
   spec_->RecomputeSpecForDetails();
 
-  if (state()->IsPaymentAppInvoked() &&
-      payment_handler_host_.is_changing_payment_method()) {
+  if (state()->IsPaymentAppInvoked() && payment_handler_host_.is_changing()) {
     payment_handler_host_.NoUpdatedPaymentDetails();
   }
 }
@@ -498,6 +513,45 @@
   return true;
 }
 
+bool PaymentRequest::ChangeShippingOption(
+    const std::string& shipping_option_id) {
+  DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+  DCHECK(!shipping_option_id.empty());
+
+  bool is_valid_id = false;
+  if (spec_->details().shipping_options) {
+    for (const auto& option : spec_->GetShippingOptions()) {
+      if (option->id == shipping_option_id) {
+        is_valid_id = true;
+        break;
+      }
+    }
+  }
+
+  if (!state_ || !state_->IsPaymentAppInvoked() || !client_ || !spec_ ||
+      !spec_->request_shipping() || !is_valid_id) {
+    return false;
+  }
+
+  client_->OnShippingOptionChange(shipping_option_id);
+  return true;
+}
+
+bool PaymentRequest::ChangeShippingAddress(
+    mojom::PaymentAddressPtr shipping_address) {
+  DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+  DCHECK(shipping_address);
+
+  if (!state_ || !state_->IsPaymentAppInvoked() || !client_ || !spec_ ||
+      !spec_->request_shipping()) {
+    return false;
+  }
+
+  client_->OnShippingAddressChange(
+      RedactShippingAddress(std::move(shipping_address)));
+  return true;
+}
+
 void PaymentRequest::AreRequestedMethodsSupportedCallback(
     bool methods_supported,
     const std::string& error_message) {
@@ -613,16 +667,7 @@
 
 void PaymentRequest::OnShippingAddressSelected(
     mojom::PaymentAddressPtr address) {
-  // Redact shipping address before exposing it in ShippingAddressChangeEvent.
-  // https://w3c.github.io/payment-request/#shipping-address-changed-algorithm
-  if (PaymentsExperimentalFeatures::IsEnabled(
-          features::kWebPaymentsRedactShippingAddress)) {
-    address->organization.clear();
-    address->phone.clear();
-    address->recipient.clear();
-    address->address_line.clear();
-  }
-  client_->OnShippingAddressChange(std::move(address));
+  client_->OnShippingAddressChange(RedactShippingAddress(std::move(address)));
 }
 
 void PaymentRequest::OnPayerInfoSelected(mojom::PayerDetailPtr payer_info) {