Skip to content

Commit

Permalink
Turn viewer and viewport service into core services.
Browse files Browse the repository at this point in the history
Credit goes to @aaron on whose PR this is based. I realized, though, that viewer and viewport would be pretty hard and frustrating, so I chose to finish it myself.

Part of #1055
  • Loading branch information
cramforce committed Dec 23, 2015
1 parent 073af8d commit 845a65b
Show file tree
Hide file tree
Showing 17 changed files with 1,816 additions and 1,710 deletions.
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',
'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

0 comments on commit 845a65b

Please sign in to comment.