Skip to content

Commit

Permalink
new file
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouyx committed Jun 18, 2019
1 parent 6d460ce commit e8308d2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
50 changes: 50 additions & 0 deletions extensions/amp-analytics/0.1/cookie-reader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright 2019 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {getCookie} from '../../../src/cookies';
import {getMode} from '../../../src/mode';
import {isInFie} from '../../../src/friendly-iframe-embed';
import {isProxyOrigin} from '../../../src/url';

/**
* COOKIE macro resolver
* @param {!Window} win
* @param {!Element} element
* @param {string} name
* @return {?string}
*/
export function cookieReader(win, element, name) {
if (!isCookieAllowed(win, element)) {
return null;
}
return getCookie(win, name);
}

/**
* Determine if cookie writing/reading feature is supported in current
* environment.
* Disable cookie writer in friendly iframe and proxy origin and inabox.
* @param {!Window} win
* @param {!Element} element
* @return {boolean}
*/
export function isCookieAllowed(win, element) {
return (
!isInFie(element) &&
!isProxyOrigin(win.location) &&
!(getMode(win).runtime == 'inabox')
);
}
1 change: 0 additions & 1 deletion extensions/amp-analytics/0.1/cookie-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export class CookieWriter {
init_() {
// TODO: Need the consider the case for shadow doc.
if (!isCookieAllowed(this.win_, this.element_)) {
console.log("cookie not allowed");
// Note: It's important to check origin here so that setCookie doesn't
// throw error "should not attempt ot set cookie on proxy origin"
return Promise.resolve();
Expand Down

0 comments on commit e8308d2

Please sign in to comment.