diff options
author | kelvinp@chromium.org <kelvinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-18 23:23:44 +0000 |
---|---|---|
committer | kelvinp@chromium.org <kelvinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-18 23:25:58 +0000 |
commit | 4abf2250f191f64cfc8b70053f313d38c79557cd (patch) | |
tree | 6fcd07a86294af76e1f1a8bc7fc449168b4cd90a | |
parent | a5b441af60f4e9b27cc5cbda8e78b5d5ab87eab3 (diff) | |
download | chromium_src-4abf2250f191f64cfc8b70053f313d38c79557cd.zip chromium_src-4abf2250f191f64cfc8b70053f313d38c79557cd.tar.gz chromium_src-4abf2250f191f64cfc8b70053f313d38c79557cd.tar.bz2 |
Move isAppsV2 check to base.js
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
-rw-r--r-- | remoting/webapp/background/background.js | 11 | ||||
-rw-r--r-- | remoting/webapp/base.js | 17 | ||||
-rw-r--r-- | remoting/webapp/browser_test/bump_scroll_browser_test.js | 2 | ||||
-rw-r--r-- | remoting/webapp/event_handlers.js | 6 | ||||
-rw-r--r-- | remoting/webapp/hangout_session.js | 2 | ||||
-rw-r--r-- | remoting/webapp/host_installer.js | 2 | ||||
-rw-r--r-- | remoting/webapp/remoting.js | 25 | ||||
-rw-r--r-- | remoting/webapp/wcs_sandbox_container.js | 2 |
8 files changed, 31 insertions, 36 deletions
diff --git a/remoting/webapp/background/background.js b/remoting/webapp/background/background.js index 28c2010..db569e0 100644 --- a/remoting/webapp/background/background.js +++ b/remoting/webapp/background/background.js @@ -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} */ @@ -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); } diff --git a/remoting/webapp/base.js b/remoting/webapp/base.js index d12db235..54f1984 100644 --- a/remoting/webapp/base.js +++ b/remoting/webapp/base.js @@ -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| diff --git a/remoting/webapp/browser_test/bump_scroll_browser_test.js b/remoting/webapp/browser_test/bump_scroll_browser_test.js index cc94734..9ddb2a1 100644 --- a/remoting/webapp/browser_test/bump_scroll_browser_test.js +++ b/remoting/webapp/browser_test/bump_scroll_browser_test.js @@ -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.') diff --git a/remoting/webapp/event_handlers.js b/remoting/webapp/event_handlers.js index 50ec1df..480dffd 100644 --- a/remoting/webapp/event_handlers.js +++ b/remoting/webapp/event_handlers.js @@ -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(); }; @@ -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); } diff --git a/remoting/webapp/hangout_session.js b/remoting/webapp/hangout_session.js index bfcda86..7776f15 100644 --- a/remoting/webapp/hangout_session.js +++ b/remoting/webapp/hangout_session.js @@ -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(); diff --git a/remoting/webapp/host_installer.js b/remoting/webapp/host_installer.js index 45dbadd..57b80396 100644 --- a/remoting/webapp/host_installer.js +++ b/remoting/webapp/host_installer.js @@ -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); diff --git a/remoting/webapp/remoting.js b/remoting/webapp/remoting.js index 6d368ef..4185eab 100644 --- a/remoting/webapp/remoting.js +++ b/remoting/webapp/remoting.js @@ -10,12 +10,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 * away from the remoting namespace and into smaller objects. @@ -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_(); } @@ -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( @@ -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); } @@ -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) { @@ -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'); diff --git a/remoting/webapp/wcs_sandbox_container.js b/remoting/webapp/wcs_sandbox_container.js index a592625..4104c36 100644 --- a/remoting/webapp/wcs_sandbox_container.js +++ b/remoting/webapp/wcs_sandbox_container.js @@ -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' }; |