Skip to content

Commit

Permalink
Move isAppsV2 check to base.js
Browse files Browse the repository at this point in the history
This CL moves the isAppsV2 check from remoting.js to base.js 
so that it can be shared across the background page, confirm
dialogs and the webapp.

Review URL: https://codereview.chromium.org/484733002

Cr-Commit-Position: refs/heads/master@{#290403}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290403 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
kelvinp@chromium.org committed Aug 18, 2014
1 parent a5b441a commit 4abf225
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 36 deletions.
11 changes: 1 addition & 10 deletions remoting/webapp/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ var remoting = remoting || {};

(function(){

/** @return {boolean} */
function isAppsV2() {
var manifest = chrome.runtime.getManifest();
if (manifest && manifest.app && manifest.app.background) {
return true;
}
return false;
}

/** @param {remoting.AppLauncher} appLauncher */
function initializeAppV2(appLauncher) {
/** @type {string} */
Expand Down Expand Up @@ -69,7 +60,7 @@ function initializeBackgroundService(appLauncher) {
function main() {
/** @type {remoting.AppLauncher} */
var appLauncher = new remoting.V1AppLauncher();
if (isAppsV2()) {
if (base.isAppsV2()) {
appLauncher = new remoting.V2AppLauncher();
initializeAppV2(appLauncher);
}
Expand Down
17 changes: 17 additions & 0 deletions remoting/webapp/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ base.values = function(dict) {
});
};

/**
* @type {boolean|undefined}
* @private
*/
base.isAppsV2_ = undefined;

/**
* @return {boolean} True if this is a v2 app; false if it is a legacy app.
*/
base.isAppsV2 = function() {
if (base.isAppsV2_ === undefined) {
var manifest = chrome.runtime.getManifest();
base.isAppsV2_ =
Boolean(manifest && manifest.app && manifest.app.background);
}
return base.isAppsV2_;
};

/**
* Joins the |url| with optional query parameters defined in |opt_params|
Expand Down
2 changes: 1 addition & 1 deletion remoting/webapp/browser_test/bump_scroll_browser_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ browserTest.Bump_Scroll = function() {
browserTest.Bump_Scroll.prototype.run = function(data) {
browserTest.expect(typeof data.pin == 'string');

if (!remoting.isAppsV2) {
if (!base.isAppsV2()) {
browserTest.fail(
'Bump-scroll requires full-screen, which can only be activated ' +
'programmatically in apps v2.')
Expand Down
6 changes: 3 additions & 3 deletions remoting/webapp/event_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ function onLoad() {
remoting.connector.reconnect();
};
var doAuthRedirect = function() {
if (!remoting.isAppsV2) {
if (!base.isAppsV2()) {
remoting.oauth2.doAuthRedirect();
}
};
var fixAuthError = function() {
if (remoting.isAppsV2) {
if (base.isAppsV2()) {
var onRefresh = function() {
remoting.hostList.display();
};
Expand Down Expand Up @@ -122,7 +122,7 @@ function onLoad() {
// client area is calculated differently in full-screen mode, so register
// for both events.
remoting.fullscreen.addListener(remoting.onResize);
if (!remoting.isAppsV2) {
if (!base.isAppsV2()) {
window.addEventListener('beforeunload', remoting.promptClose, false);
window.addEventListener('unload', remoting.disconnect, false);
}
Expand Down
2 changes: 1 addition & 1 deletion remoting/webapp/hangout_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ remoting.HangoutSession.prototype.onSessionStateChanged_ = function(state) {
} finally {
if (state === State.FAILED || state === State.CLOSED) {
// close the current window
if (remoting.isAppsV2) {
if (base.isAppsV2()) {
chrome.app.window.current().close();
} else {
window.close();
Expand Down
2 changes: 1 addition & 1 deletion remoting/webapp/host_installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ remoting.HostInstaller.prototype.download_ = function() {
}

// Start downloading the package.
if (remoting.isAppsV2) {
if (base.isAppsV2()) {
// TODO(jamiewalch): Use chrome.downloads when it is available to
// apps v2 (http://crbug.com/174046)
window.open(hostPackageUrl);
Expand Down
25 changes: 6 additions & 19 deletions remoting/webapp/remoting.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ var remoting = remoting || {};

/** @type {remoting.HostSession} */ remoting.hostSession = null;

/**
* @type {boolean} True if this is a v2 app; false if it is a legacy app.
*/
remoting.isAppsV2 = false;


/**
* @type {base.EventSource} An event source object for handling global events.
* This is an interim hack. Eventually, we should move functionalities
Expand Down Expand Up @@ -47,17 +41,10 @@ function consentRequired_(authContinue) {
* Entry point for app initialization.
*/
remoting.init = function() {
// Determine whether or not this is a V2 web-app. In order to keep the apps
// v2 patch as small as possible, all JS changes needed for apps v2 are done
// at run-time. Only the manifest is patched.
var manifest = chrome.runtime.getManifest();
if (manifest && manifest.app && manifest.app.background) {
remoting.isAppsV2 = true;
if (base.isAppsV2()) {
var htmlNode = /** @type {HTMLElement} */ (document.body.parentNode);
htmlNode.classList.add('apps-v2');
}

if (!remoting.isAppsV2) {
} else {
migrateLocalToChromeStorage_();
}

Expand All @@ -66,7 +53,7 @@ remoting.init = function() {

// Create global objects.
remoting.settings = new remoting.Settings();
if (remoting.isAppsV2) {
if (base.isAppsV2()) {
remoting.identity = new remoting.Identity(consentRequired_);
remoting.fullscreen = new remoting.FullscreenAppsV2();
remoting.windowFrame = new remoting.WindowFrame(
Expand Down Expand Up @@ -138,7 +125,7 @@ remoting.init = function() {
* containing tab/window.
*/
var getCurrentId = function () {
if (remoting.isAppsV2) {
if (base.isAppsV2()) {
return Promise.resolve(chrome.app.window.current().id);
}

Expand Down Expand Up @@ -189,7 +176,7 @@ remoting.init = function() {

// For Apps v1, check the tab type to warn the user if they are not getting
// the best keyboard experience.
if (!remoting.isAppsV2 && !remoting.platformIsMac()) {
if (!base.isAppsV2() && !remoting.platformIsMac()) {
/** @param {boolean} isWindowed */
var onIsWindowed = function(isWindowed) {
if (!isWindowed) {
Expand Down Expand Up @@ -334,7 +321,7 @@ remoting.updateLocalHostState = function() {
* @return {string} Information about the current extension.
*/
remoting.getExtensionInfo = function() {
var v2OrLegacy = remoting.isAppsV2 ? " (v2)" : " (legacy)";
var v2OrLegacy = base.isAppsV2() ? " (v2)" : " (legacy)";
var manifest = chrome.runtime.getManifest();
if (manifest && manifest.version) {
var name = chrome.i18n.getMessage('PRODUCT_NAME');
Expand Down
2 changes: 1 addition & 1 deletion remoting/webapp/wcs_sandbox_container.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ remoting.WcsSandboxContainer = function(sandbox) {

window.addEventListener('message', this.onMessage_.bind(this), false);

if (remoting.isAppsV2) {
if (base.isAppsV2()) {
var message = {
'command': 'proxyXhrs'
};
Expand Down

0 comments on commit 4abf225

Please sign in to comment.