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

Turn viewer and viewport service into core services. #1236

Merged
merged 1 commit into from
Dec 23, 2015
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion build-system/tasks/presubmit-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ var forbiddenTerms = {
'test/functional/test-url-replacements.js'
],
},
'installViewerService': {
message: privateServiceFactory,
whitelist: [
'src/amp-core-service.js',
'src/service/history-impl.js',
'src/service/viewer-impl.js',
'src/service/viewport-impl.js',
'test/functional/test-cid.js',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @erwinmombay is there a way for us to declare whitelists for the whole test/ directory? I don't quite see a reason to be protective over this kind of uses in tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not currently, i didnt since i thought that people might unintentionally whitelist something they shouldnt have. but now that the list is growing, might as well.

added PR/feature here #1240

/cc @cramforce

'test/functional/test-viewport.js',
'extensions/amp-analytics/0.1/test/test-amp-analytics.js',
],
},
'installViewportService': {
message: privateServiceFactory,
whitelist: [
'src/amp-core-service.js',
'src/service/viewport-impl.js',
],
},
// Privacy sensitive
'cidFor': {
message: requiresReviewPrivacy,
Expand All @@ -73,7 +92,7 @@ var forbiddenTerms = {
message: requiresReviewPrivacy,
whitelist: [
'src/service/cid-impl.js',
'src/viewer.js',
'src/service/viewer-impl.js',
'test/functional/test-cid.js',
],
},
Expand Down
2 changes: 2 additions & 0 deletions extensions/amp-analytics/0.1/test/test-amp-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {adopt} from '../../../../src/runtime';
import {getService} from '../../../../src/service';
import {markElementScheduledForTesting} from '../../../../src/service';
import {installCidService} from '../../../../src/service/cid-impl';
import {installViewerService} from '../../../../src/service/viewer-impl';
import * as sinon from 'sinon';

adopt(window);
Expand Down Expand Up @@ -47,6 +48,7 @@ describe('amp-analytics', function() {
};
windowApi.Object = window.Object;
markElementScheduledForTesting(windowApi, 'amp-analytics');
installViewerService(windowApi);
installCidService(windowApi);
getService(windowApi, 'xhr', () => {return {
fetchJson: url => Promise.resolve(JSON.parse(jsonMockResponses[url]))
Expand Down
31 changes: 31 additions & 0 deletions src/amp-core-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright 2015 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 {installHistoryService} from './service/history-impl';
import {installViewerService} from './service/viewer-impl';
import {installViewportService} from './service/viewport-impl';


/**
* Services that can be assumed are always available in AMP.
* They are installed in amp.js very early in the application lifecyle.
* @param {!Window} window
*/
export function installCoreServices(window) {
installViewerService(window);
installViewportService(window);
installHistoryService(window);
}
8 changes: 2 additions & 6 deletions src/amp.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
*/

import './polyfills';

import {installHistoryService} from './service/history-impl';
import {installPullToRefreshBlocker} from './pull-to-refresh';
import {performanceFor} from './performance';
import {viewerFor} from './viewer';
import {vsyncFor} from './vsync';
import {templatesFor} from './template';

import {installCoreServices} from './amp-core-service';
import {installAd} from '../builtins/amp-ad';
import {installGlobalClickListener} from './document-click';
import {installImg} from '../builtins/amp-img';
Expand All @@ -47,8 +44,7 @@ try {
perf.tick('is');
installStyles(document, cssText, () => {
try {
installHistoryService(window);
viewerFor(window);
installCoreServices(window);
vsyncFor(window);
templatesFor(window);

Expand Down
2 changes: 2 additions & 0 deletions src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {BaseTemplate, registerExtendedTemplate} from './template';
import {assert} from './asserts';
import {getMode} from './mode';
import {installStyles} from './styles';
import {installCoreServices} from './amp-core-service';
import {isExperimentOn, toggleExperiment} from './experiments';
import {performanceFor} from './performance';
import {registerElement} from './custom-element';
Expand Down Expand Up @@ -93,6 +94,7 @@ export function adopt(global) {
/** @const */
global.AMP.assert = assert;

installCoreServices(global);
const viewer = viewerFor(global);

/** @const */
Expand Down
4 changes: 2 additions & 2 deletions src/service/history-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {assert} from '../asserts';
import {getService} from '../service';
import {log} from '../log';
import {timer} from '../timer';
import {viewerFor} from '../viewer';
import {installViewerService} from './viewer-impl';


/** @private @const */
Expand Down Expand Up @@ -638,7 +638,7 @@ export class HistoryBindingVirtual_ {
* @private
*/
function createHistory_(window) {
const viewer = viewerFor(window);
const viewer = installViewerService(window);
let binding;
if (viewer.isOvertakeHistory()) {
binding = new HistoryBindingVirtual_(viewer);
Expand Down
Loading