Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java

Issue 1942653002: Provide shipping address only to merchants that need it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@integration-tests
Patch Set: Rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.payments; 5 package org.chromium.chrome.browser.payments;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.graphics.Bitmap; 8 import android.graphics.Bitmap;
9 import android.os.Handler; 9 import android.os.Handler;
10 import android.text.TextUtils; 10 import android.text.TextUtils;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 private List<LineItem> mLineItems; 68 private List<LineItem> mLineItems;
69 private SectionInformation mShippingOptions; 69 private SectionInformation mShippingOptions;
70 private JSONObject mData; 70 private JSONObject mData;
71 private SectionInformation mShippingAddresses; 71 private SectionInformation mShippingAddresses;
72 private List<PaymentApp> mPendingApps; 72 private List<PaymentApp> mPendingApps;
73 private List<PaymentInstrument> mPendingInstruments; 73 private List<PaymentInstrument> mPendingInstruments;
74 private SectionInformation mPaymentMethods; 74 private SectionInformation mPaymentMethods;
75 private PaymentRequestUI mUI; 75 private PaymentRequestUI mUI;
76 private Callback<PaymentInformation> mPaymentInformationCallback; 76 private Callback<PaymentInformation> mPaymentInformationCallback;
77 private Pattern mRegionCodePattern; 77 private Pattern mRegionCodePattern;
78 private boolean mMerchantNeedsShippingAddress;
78 79
79 /** 80 /**
80 * Builds the dialog. 81 * Builds the dialog.
81 * 82 *
82 * @param webContents The web contents that have invoked the PaymentRequest API. 83 * @param webContents The web contents that have invoked the PaymentRequest API.
83 */ 84 */
84 public PaymentRequestImpl(WebContents webContents) { 85 public PaymentRequestImpl(WebContents webContents) {
85 if (webContents == null) return; 86 if (webContents == null) return;
86 87
87 ContentViewCore contentViewCore = ContentViewCore.fromWebContents(webCon tents); 88 ContentViewCore contentViewCore = ContentViewCore.fromWebContents(webCon tents);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } 161 }
161 mPaymentItems = Arrays.asList(details.items); 162 mPaymentItems = Arrays.asList(details.items);
162 163
163 mShippingOptions = 164 mShippingOptions =
164 getValidatedShippingOptions(details.items[0].amount.currencyCode , details); 165 getValidatedShippingOptions(details.items[0].amount.currencyCode , details);
165 if (mShippingOptions == null) { 166 if (mShippingOptions == null) {
166 disconnectFromClientWithDebugMessage("Invalid shipping options"); 167 disconnectFromClientWithDebugMessage("Invalid shipping options");
167 return; 168 return;
168 } 169 }
169 170
171 // If the merchant requests shipping and does not provide shipping optio ns here, then the
172 // merchant needs the shipping address to calculate shipping price and a vailability.
173 boolean requestShipping = options != null && options.requestShipping;
174 mMerchantNeedsShippingAddress = requestShipping && mShippingOptions.isEm pty();
175
170 mData = getValidatedData(mSupportedMethods, stringifiedData); 176 mData = getValidatedData(mSupportedMethods, stringifiedData);
171 if (mData == null) { 177 if (mData == null) {
172 disconnectFromClientWithDebugMessage("Invalid payment method specifi c data"); 178 disconnectFromClientWithDebugMessage("Invalid payment method specifi c data");
173 return; 179 return;
174 } 180 }
175 181
176 List<AutofillAddress> addresses = new ArrayList<>(); 182 List<AutofillAddress> addresses = new ArrayList<>();
177 List<AutofillProfile> profiles = PersonalDataManager.getInstance().getAd dressOnlyProfiles(); 183 List<AutofillProfile> profiles = PersonalDataManager.getInstance().getAd dressOnlyProfiles();
178 for (int i = 0; i < profiles.size(); i++) { 184 for (int i = 0; i < profiles.size(); i++) {
179 AutofillProfile profile = profiles.get(i); 185 AutofillProfile profile = profiles.get(i);
(...skipping 24 matching lines...) Expand all
204 Set<String> appMethods = app.getSupportedMethodNames(); 210 Set<String> appMethods = app.getSupportedMethodNames();
205 appMethods.retainAll(mSupportedMethods); 211 appMethods.retainAll(mSupportedMethods);
206 if (!appMethods.isEmpty()) { 212 if (!appMethods.isEmpty()) {
207 isGettingInstruments = true; 213 isGettingInstruments = true;
208 app.getInstruments(mPaymentItems, this); 214 app.getInstruments(mPaymentItems, this);
209 } 215 }
210 } 216 }
211 217
212 if (!isGettingInstruments) mPaymentMethods = new SectionInformation(); 218 if (!isGettingInstruments) mPaymentMethods = new SectionInformation();
213 219
214 boolean requestShipping = options != null && options.requestShipping;
215 mUI = new PaymentRequestUI(mContext, this, requestShipping, mMerchantNam e, mOrigin); 220 mUI = new PaymentRequestUI(mContext, this, requestShipping, mMerchantNam e, mOrigin);
216 if (mFavicon != null) mUI.setTitleBitmap(mFavicon); 221 if (mFavicon != null) mUI.setTitleBitmap(mFavicon);
217 mFavicon = null; 222 mFavicon = null;
218 } 223 }
219 224
220 private HashSet<String> getValidatedSupportedMethods(String[] methods) { 225 private HashSet<String> getValidatedSupportedMethods(String[] methods) {
221 // Payment methods are required. 226 // Payment methods are required.
222 if (methods == null || methods.length == 0) return null; 227 if (methods == null || methods.length == 0) return null;
223 228
224 HashSet<String> result = new HashSet<>(); 229 HashSet<String> result = new HashSet<>();
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 public void run() { 392 public void run() {
388 callback.onResult(mPaymentMethods); 393 callback.onResult(mPaymentMethods);
389 } 394 }
390 }); 395 });
391 } 396 }
392 397
393 @Override 398 @Override
394 public void onShippingAddressChanged(PaymentOption selectedShippingAddress) { 399 public void onShippingAddressChanged(PaymentOption selectedShippingAddress) {
395 assert selectedShippingAddress instanceof AutofillAddress; 400 assert selectedShippingAddress instanceof AutofillAddress;
396 mShippingAddresses.setSelectedItem(selectedShippingAddress); 401 mShippingAddresses.setSelectedItem(selectedShippingAddress);
397 mClient.onShippingAddressChange( 402 if (mMerchantNeedsShippingAddress) {
398 ((AutofillAddress) selectedShippingAddress).toShippingAddress()) ; 403 mClient.onShippingAddressChange(
404 ((AutofillAddress) selectedShippingAddress).toShippingAddres s());
405 }
399 } 406 }
400 407
401 @Override 408 @Override
402 public void onShippingOptionChanged(PaymentOption selectedShippingOption) { 409 public void onShippingOptionChanged(PaymentOption selectedShippingOption) {
403 mShippingOptions.setSelectedItem(selectedShippingOption); 410 mShippingOptions.setSelectedItem(selectedShippingOption);
404 mClient.onShippingOptionChange(selectedShippingOption.getIdentifier()); 411 mClient.onShippingOptionChange(selectedShippingOption.getIdentifier());
405 } 412 }
406 413
407 @Override 414 @Override
408 public void onPaymentMethodChanged(PaymentOption selectedPaymentMethod) { 415 public void onPaymentMethodChanged(PaymentOption selectedPaymentMethod) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 if (mPaymentMethods != null) { 542 if (mPaymentMethods != null) {
536 for (int i = 0; i < mPaymentMethods.getSize(); i++) { 543 for (int i = 0; i < mPaymentMethods.getSize(); i++) {
537 PaymentOption option = mPaymentMethods.getItem(i); 544 PaymentOption option = mPaymentMethods.getItem(i);
538 assert option instanceof PaymentInstrument; 545 assert option instanceof PaymentInstrument;
539 ((PaymentInstrument) option).dismiss(); 546 ((PaymentInstrument) option).dismiss();
540 } 547 }
541 mPaymentMethods = null; 548 mPaymentMethods = null;
542 } 549 }
543 } 550 }
544 } 551 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698