Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ SWG release 0.1.22.74 #24941

Merged
merged 2 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion third_party/subscriptions-project/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** Version: 0.1.22.72 */
/** Version: 0.1.22.74 */
/**
* Copyright 2018 The Subscribe with Google Authors. All Rights Reserved.
*
Expand Down
45 changes: 40 additions & 5 deletions third_party/subscriptions-project/swg.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** Version: 0.1.22.72 */
/** Version: 0.1.22.74 */
/**
* Copyright 2018 The Subscribe with Google Authors. All Rights Reserved.
*
Expand Down Expand Up @@ -4156,12 +4156,22 @@ function adsUrl(url) {
* @return {string} The complete URL.
*/
function feUrl(url, prefix = '') {
return feCached('https://news.google.com' + prefix + '/swg/_/ui/v1' + url);
// Add cache param.
url = feCached('https://news.google.com' + prefix + '/swg/_/ui/v1' + url);

// Optionally add jsmode param. This allows us to test against "aggressively" compiled Boq JS.
const query = parseQueryString$1(self.location.hash);
const boqJsMode = query['swg.boqjsmode'];
if (boqJsMode !== undefined) {
url = addQueryParam(url, 'jsmode', boqJsMode);
}

return url;
}

/**
* @param {string} url FE URL.
* @return {string} The complete URL including cache params.
* @return {string} The complete URL including cache param.
*/
function feCached(url) {
return addQueryParam(url, '_', cacheParam('hr1'));
Expand All @@ -4173,7 +4183,7 @@ function feCached(url) {
*/
function feArgs(args) {
return Object.assign(args, {
'_client': 'SwG 0.1.22.72',
'_client': 'SwG 0.1.22.74',
});
}

Expand Down Expand Up @@ -7699,7 +7709,9 @@ class Dialog {
animating = Promise.resolve();
}
return animating.then(() => {
this.doc_.getBody().removeChild(this.iframe_.getElement());
const iframeEl = this.iframe_.getElement();
iframeEl.parentNode.removeChild(iframeEl);

this.removePaddingToHtml_();
this.graypane_.destroy();
});
Expand Down Expand Up @@ -10704,6 +10716,16 @@ const PublicErrorCode = {
BUYER_CANCEL: 6,
};

/**
* The presentation mode of the buy flow
*
* @enum {number}
*/
const BuyFlowMode = {
PAY_WITH_GOOGLE: 5,
SUBSCRIBE_WITH_GOOGLE: 6,
};

/**
* Iframe used for logging and prefetching.
*
Expand Down Expand Up @@ -11085,6 +11107,10 @@ function apiV2DoesMerchantSupportSpecifiedCardType(
* message.
*/
function validateSecureContext() {
if (window.location.hostname.endsWith(Constants.TRUSTED_DOMAIN)) {
// This is for local development.
return null;
}
if (window.isSecureContext === undefined) {
// Browser not support isSecureContext, figure out a way to validate this
// for the unsupported browser.
Expand Down Expand Up @@ -12392,6 +12418,9 @@ class PaymentsAsyncClient {
opt_useIframe, opt_activities,
paymentOptions['i'] && paymentOptions['i']['redirectKey']);

/** @private {number} */
this.buyFlowMode_ = BuyFlowMode.PAY_WITH_GOOGLE;

const paymentRequestSupported = chromeSupportsPaymentRequest();
// TODO: Remove the temporary hack that disable payments
// request for inline flow.
Expand Down Expand Up @@ -12610,11 +12639,15 @@ class PaymentsAsyncClient {
});
const errorMessage = validateSecureContext() ||
validatePaymentDataRequest(paymentDataRequest);
this.buyFlowMode_ = paymentDataRequest && paymentDataRequest.swg ?
BuyFlowMode.SUBSCRIBE_WITH_GOOGLE :
BuyFlowMode.PAY_WITH_GOOGLE;
if (errorMessage) {
this.onPaymentResponse_(new Promise((resolve, reject) => {
PayFrameHelper.postMessage({
'eventType': PostMessageEventType.LOG_LOAD_PAYMENT_DATA_API,
'error': PublicErrorCode.DEVELOPER_ERROR,
'buyFlowMode': this.buyFlowMode_,
});
PaymentsAsyncClient.logDevErrorToConsole_(
'loadPaymentData', errorMessage);
Expand Down Expand Up @@ -12720,12 +12753,14 @@ class PaymentsAsyncClient {
PayFrameHelper.postMessage({
'eventType': PostMessageEventType.LOG_LOAD_PAYMENT_DATA_API,
'error': /** @type {!PublicErrorCode} */ (result['errorCode']),
'buyFlowMode': this.buyFlowMode_,
});
} else {
// If user closes window we don't get a error code
PayFrameHelper.postMessage({
'eventType': PostMessageEventType.LOG_LOAD_PAYMENT_DATA_API,
'error': PublicErrorCode.BUYER_CANCEL,
'buyFlowMode': this.buyFlowMode_,
});
}
});
Expand Down