4242 * # STATUS
4343 *
4444 * Status updates are dispatched as `statusChange` jQuery events. The status
45- * is passed as the first parameter and the reason for the change as the second
46- * parameter. Currently only the "Inactive" status supports the reason parameter.
47- * The status codes are:
45+ * codes are:
4846 *
4947 * -1: Error
5048 * 0: Inactive
5149 * 1: Connecting to the remote debugger
5250 * 2: Loading agents
5351 * 3: Active
5452 * 4: Out of sync
55- *
56- * The reason codes are:
57- * - null (Unknown reason)
58- * - "explicit_close" (LiveDevelopment.close() was called)
59- * - "navigated_away" (The browser changed to a location outside of the project)
60- * - "detached_target_closed" (The tab or window was closed)
61- * - "detached_replaced_with_devtools" (The developer tools were opened in the browser)
6253 */
6354define ( function LiveDevelopment ( require , exports , module ) {
6455 "use strict" ;
@@ -78,6 +69,7 @@ define(function LiveDevelopment(require, exports, module) {
7869 DocumentManager = require ( "document/DocumentManager" ) ,
7970 EditorManager = require ( "editor/EditorManager" ) ,
8071 FileUtils = require ( "file/FileUtils" ) ,
72+ HTMLInstrumentation = require ( "language/HTMLInstrumentation" ) ,
8173 LiveDevServerManager = require ( "LiveDevelopment/LiveDevServerManager" ) ,
8274 NativeFileError = require ( "file/NativeFileError" ) ,
8375 NativeApp = require ( "utils/NativeApp" ) ,
@@ -142,8 +134,7 @@ define(function LiveDevelopment(require, exports, module) {
142134 var _liveDocument ; // the document open for live editing.
143135 var _relatedDocuments ; // CSS and JS documents that are used by the live HTML document
144136 var _serverProvider ; // current LiveDevServerProvider
145- var _closeReason ; // reason why live preview was closed
146-
137+
147138 function _isHtmlFileExt ( ext ) {
148139 return ( FileUtils . isStaticHtmlFileExt ( ext ) ||
149140 ( ProjectManager . getBaseUrl ( ) && FileUtils . isServerHtmlFileExt ( ext ) ) ) ;
@@ -461,14 +452,8 @@ define(function LiveDevelopment(require, exports, module) {
461452 * @param {integer } new status
462453 */
463454 function _setStatus ( status ) {
464- // Don't send a notification when the status didn't actually change
465- if ( status === exports . status ) {
466- return ;
467- }
468-
469455 exports . status = status ;
470- var reason = status === STATUS_INACTIVE ? _closeReason : null ;
471- $ ( exports ) . triggerHandler ( "statusChange" , [ status , reason ] ) ;
456+ $ ( exports ) . triggerHandler ( "statusChange" , status ) ;
472457 }
473458
474459 /** Triggered by Inspector.error */
@@ -520,6 +505,13 @@ define(function LiveDevelopment(require, exports, module) {
520505 } ) ;
521506 }
522507
508+ /** Triggered by Inspector.detached */
509+ function _onDetached ( event , res ) {
510+ // res.reason, e.g. "replaced_with_devtools", "target_closed", "canceled_by_user"
511+ // Sample list taken from https://chromiumcodereview.appspot.com/10947037/patch/12001/13004
512+ // However, the link refers to the Chrome Extension API, it may not apply 100% to the Inspector API
513+ }
514+
523515 // WebInspector Event: Page.frameNavigated
524516 function _onFrameNavigated ( event , res ) {
525517 // res = {frame}
@@ -548,7 +540,6 @@ define(function LiveDevelopment(require, exports, module) {
548540 if ( ! url . match ( baseUrlRegExp ) ) {
549541 // No longer in site, so terminate live dev, but don't close browser window
550542 Inspector . disconnect ( ) ;
551- _closeReason = "navigated_away" ;
552543 _setStatus ( STATUS_INACTIVE ) ;
553544 _serverProvider = null ;
554545 }
@@ -564,22 +555,10 @@ define(function LiveDevelopment(require, exports, module) {
564555 _setStatus ( STATUS_INACTIVE ) ;
565556 }
566557
567- function _onDetached ( event , res ) {
568- // If there already is a reason for closing the session, do not overwrite it
569- if ( ! _closeReason ) {
570- // Get the explanation from res.reason, e.g. "replaced_with_devtools", "target_closed", "canceled_by_user"
571- // Examples taken from https://chromiumcodereview.appspot.com/10947037/patch/12001/13004
572- // However, the link refers to the Chrome Extension API, it may not apply 100% to the Inspector API
573- // Prefix with "detached_" to create a quasi-namespace for Chrome's reasons
574- _closeReason = "detached_" + res . reason ;
575- }
576- }
577-
578558 function reconnect ( ) {
579559 unloadAgents ( ) ;
580-
581- _setStatus ( STATUS_LOADING_AGENTS ) ;
582560 var promises = loadAgents ( ) ;
561+ _setStatus ( STATUS_LOADING_AGENTS ) ;
583562 $ . when . apply ( undefined , promises ) . done ( _onLoad ) . fail ( _onError ) ;
584563 }
585564
@@ -591,8 +570,6 @@ define(function LiveDevelopment(require, exports, module) {
591570 var browserStarted = false ;
592571 var retryCount = 0 ;
593572
594- _closeReason = null ;
595-
596573 function showWrongDocError ( ) {
597574 Dialogs . showModalDialog (
598575 Dialogs . DIALOG_ID_ERROR ,
@@ -746,8 +723,6 @@ define(function LiveDevelopment(require, exports, module) {
746723 * @return {jQuery.Promise } Resolves once the connection is closed
747724 */
748725 function close ( ) {
749- _closeReason = "explicit_close" ;
750-
751726 var deferred = $ . Deferred ( ) ;
752727
753728 /*
@@ -861,6 +836,7 @@ define(function LiveDevelopment(require, exports, module) {
861836 $ . when . apply ( undefined , promises ) . done ( _onLoad ) . fail ( _onError ) ;
862837 }
863838
839+ $ ( Inspector . Inspector ) . on ( "detached.livedev" , _onDetached ) ;
864840 $ ( Inspector . Page ) . on ( "frameNavigated.livedev" , _onFrameNavigated ) ;
865841
866842 waitForInterstitialPageLoad ( )
@@ -985,7 +961,6 @@ define(function LiveDevelopment(require, exports, module) {
985961 $ ( Inspector ) . on ( "connect" , _onConnect )
986962 . on ( "disconnect" , _onDisconnect )
987963 . on ( "error" , _onError ) ;
988- $ ( Inspector . Inspector ) . on ( "detached" , _onDetached ) ;
989964 $ ( DocumentManager ) . on ( "currentDocumentChange" , _onDocumentChange )
990965 . on ( "documentSaved" , _onDocumentSaved )
991966 . on ( "dirtyFlagChange" , _onDirtyFlagChange ) ;
0 commit comments