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

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

Issue 2692023002: Make PaymentRequestImpl work with RenderFrameHost (Closed)
Patch Set: Address review comment Created 3 years, 9 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
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.content.Context; 8 import android.content.Context;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.graphics.Bitmap; 10 import android.graphics.Bitmap;
(...skipping 29 matching lines...) Expand all
40 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; 40 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver;
41 import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; 41 import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
42 import org.chromium.chrome.browser.tabmodel.TabModel; 42 import org.chromium.chrome.browser.tabmodel.TabModel;
43 import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; 43 import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType;
44 import org.chromium.chrome.browser.tabmodel.TabModelObserver; 44 import org.chromium.chrome.browser.tabmodel.TabModelObserver;
45 import org.chromium.chrome.browser.tabmodel.TabModelSelector; 45 import org.chromium.chrome.browser.tabmodel.TabModelSelector;
46 import org.chromium.chrome.browser.tabmodel.TabModelSelectorObserver; 46 import org.chromium.chrome.browser.tabmodel.TabModelSelectorObserver;
47 import org.chromium.components.payments.CurrencyFormatter; 47 import org.chromium.components.payments.CurrencyFormatter;
48 import org.chromium.components.payments.PaymentValidator; 48 import org.chromium.components.payments.PaymentValidator;
49 import org.chromium.components.url_formatter.UrlFormatter; 49 import org.chromium.components.url_formatter.UrlFormatter;
50 import org.chromium.content_public.browser.RenderFrameHost;
50 import org.chromium.content_public.browser.WebContents; 51 import org.chromium.content_public.browser.WebContents;
52 import org.chromium.content_public.browser.WebContentsStatics;
51 import org.chromium.mojo.system.MojoException; 53 import org.chromium.mojo.system.MojoException;
52 import org.chromium.payments.mojom.CanMakePaymentQueryResult; 54 import org.chromium.payments.mojom.CanMakePaymentQueryResult;
53 import org.chromium.payments.mojom.PaymentComplete; 55 import org.chromium.payments.mojom.PaymentComplete;
54 import org.chromium.payments.mojom.PaymentDetails; 56 import org.chromium.payments.mojom.PaymentDetails;
55 import org.chromium.payments.mojom.PaymentDetailsModifier; 57 import org.chromium.payments.mojom.PaymentDetailsModifier;
56 import org.chromium.payments.mojom.PaymentErrorReason; 58 import org.chromium.payments.mojom.PaymentErrorReason;
57 import org.chromium.payments.mojom.PaymentItem; 59 import org.chromium.payments.mojom.PaymentItem;
58 import org.chromium.payments.mojom.PaymentMethodData; 60 import org.chromium.payments.mojom.PaymentMethodData;
59 import org.chromium.payments.mojom.PaymentOptions; 61 import org.chromium.payments.mojom.PaymentOptions;
60 import org.chromium.payments.mojom.PaymentRequest; 62 import org.chromium.payments.mojom.PaymentRequest;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 241
240 /** Monitors changes in the current TabModel. */ 242 /** Monitors changes in the current TabModel. */
241 private final TabModelObserver mTabModelObserver = new EmptyTabModelObserver () { 243 private final TabModelObserver mTabModelObserver = new EmptyTabModelObserver () {
242 @Override 244 @Override
243 public void didSelectTab(Tab tab, TabSelectionType type, int lastId) { 245 public void didSelectTab(Tab tab, TabSelectionType type, int lastId) {
244 if (tab == null || tab.getId() != lastId) onDismiss(); 246 if (tab == null || tab.getId() != lastId) onDismiss();
245 } 247 }
246 }; 248 };
247 249
248 private final Handler mHandler = new Handler(); 250 private final Handler mHandler = new Handler();
251 private final RenderFrameHost mRenderFrameHost;
249 private final WebContents mWebContents; 252 private final WebContents mWebContents;
250 private final String mSchemelessOriginForPaymentApp; 253 private final String mSchemelessOriginForPaymentApp;
251 private final String mOriginForDisplay; 254 private final String mOriginForDisplay;
252 private final String mMerchantName; 255 private final String mMerchantName;
253 private final byte[][] mCertificateChain; 256 private final byte[][] mCertificateChain;
254 private final AddressEditor mAddressEditor; 257 private final AddressEditor mAddressEditor;
255 private final CardEditor mCardEditor; 258 private final CardEditor mCardEditor;
256 private final PaymentRequestJourneyLogger mJourneyLogger = new PaymentReques tJourneyLogger(); 259 private final PaymentRequestJourneyLogger mJourneyLogger = new PaymentReques tJourneyLogger();
257 260
258 private PaymentRequestClient mClient; 261 private PaymentRequestClient mClient;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 private boolean mShouldSkipShowingPaymentRequestUi; 343 private boolean mShouldSkipShowingPaymentRequestUi;
341 344
342 /** The helper to create and fill the response to send to the merchant. */ 345 /** The helper to create and fill the response to send to the merchant. */
343 private PaymentResponseHelper mPaymentResponseHelper; 346 private PaymentResponseHelper mPaymentResponseHelper;
344 347
345 /** 348 /**
346 * Builds the PaymentRequest service implementation. 349 * Builds the PaymentRequest service implementation.
347 * 350 *
348 * @param webContents The web contents that have invoked the PaymentRequest API. 351 * @param webContents The web contents that have invoked the PaymentRequest API.
349 */ 352 */
350 public PaymentRequestImpl(WebContents webContents) { 353 public PaymentRequestImpl(RenderFrameHost renderFrameHost) {
351 assert webContents != null; 354 assert renderFrameHost != null;
352 355
353 mWebContents = webContents; 356 mRenderFrameHost = renderFrameHost;
357 mWebContents = WebContentsStatics.fromRenderFrameHost(renderFrameHost);
354 358
355 mSchemelessOriginForPaymentApp = UrlFormatter.formatUrlForSecurityDispla y( 359 mSchemelessOriginForPaymentApp = UrlFormatter.formatUrlForSecurityDispla y(
356 mWebContents.getLastCommittedUrl(), false /* omit scheme for pay ment apps. */); 360 mWebContents.getLastCommittedUrl(), false /* omit scheme for pay ment apps. */);
357 361
358 mOriginForDisplay = UrlFormatter.formatUrlForSecurityDisplay( 362 mOriginForDisplay = UrlFormatter.formatUrlForSecurityDisplay(
359 mWebContents.getLastCommittedUrl(), true /* include scheme in di splay */); 363 mWebContents.getLastCommittedUrl(), true /* include scheme in di splay */);
360 364
361 mMerchantName = webContents.getTitle(); 365 mMerchantName = mWebContents.getTitle();
366
362 mCertificateChain = CertificateChainHelper.getCertificateChain(mWebConte nts); 367 mCertificateChain = CertificateChainHelper.getCertificateChain(mWebConte nts);
363 368
364 mApps = new ArrayList<>(); 369 mApps = new ArrayList<>();
365 370
366 mAddressEditor = new AddressEditor(); 371 mAddressEditor = new AddressEditor();
367 mCardEditor = new CardEditor(mWebContents, mAddressEditor, sObserverForT est); 372 mCardEditor = new CardEditor(mWebContents, mAddressEditor, sObserverForT est);
368 373
369 if (sCanMakePaymentQueries == null) sCanMakePaymentQueries = new ArrayMa p<>(); 374 if (sCanMakePaymentQueries == null) sCanMakePaymentQueries = new ArrayMa p<>();
370 375
371 recordSuccessFunnelHistograms("Initiated"); 376 recordSuccessFunnelHistograms("Initiated");
(...skipping 1285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 1662
1658 /** 1663 /**
1659 * The frecency score is calculated according to use count and last use date . The formula is 1664 * The frecency score is calculated according to use count and last use date . The formula is
1660 * the same as the one used in GetFrecencyScore in autofill_data_model.cc. 1665 * the same as the one used in GetFrecencyScore in autofill_data_model.cc.
1661 */ 1666 */
1662 private static final double getFrecencyScore(int count, long date) { 1667 private static final double getFrecencyScore(int count, long date) {
1663 long currentTime = System.currentTimeMillis(); 1668 long currentTime = System.currentTimeMillis();
1664 return -Math.log((currentTime - date) / (24 * 60 * 60 * 1000) + 2) / Mat h.log(count + 2); 1669 return -Math.log((currentTime - date) / (24 * 60 * 60 * 1000) + 2) / Mat h.log(count + 2);
1665 } 1670 }
1666 } 1671 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698