Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: Source/devtools/front_end/sources/SourcesPanel.js

Issue 625843002: DevTools: Extract workspace mapping suggesting logic from sources panel. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 WebInspector.breakpointManager.addEventListener(WebInspector.BreakpointManag er.Events.BreakpointsActiveStateChanged, this._breakpointsActiveStateChanged, th is); 104 WebInspector.breakpointManager.addEventListener(WebInspector.BreakpointManag er.Events.BreakpointsActiveStateChanged, this._breakpointsActiveStateChanged, th is);
105 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._onCu rrentTargetChanged, this); 105 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._onCu rrentTargetChanged, this);
106 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerWasEnabled, this._debuggerWasEnabled, this ); 106 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerWasEnabled, this._debuggerWasEnabled, this );
107 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerWasDisabled, this._debuggerReset, this); 107 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerWasDisabled, this._debuggerReset, this);
108 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerPaused, this._debuggerPaused, this); 108 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerPaused, this._debuggerPaused, this);
109 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerResumed, this._debuggerResumed, this); 109 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerResumed, this._debuggerResumed, this);
110 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.CallFrameSelected, this._callFrameSelected, this); 110 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.CallFrameSelected, this._callFrameSelected, this);
111 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.ConsoleCommandEvaluatedInSelectedCallFrame, this._ consoleCommandEvaluatedInSelectedCallFrame, this); 111 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.ConsoleCommandEvaluatedInSelectedCallFrame, this._ consoleCommandEvaluatedInSelectedCallFrame, this);
112 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this); 112 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this);
113 WebInspector.targetManager.observeTargets(this); 113 WebInspector.targetManager.observeTargets(this);
114 new WebInspector.WorkspaceMappingSuggester(this, this._workspace);
114 } 115 }
115 116
116 WebInspector.SourcesPanel.minToolbarWidth = 215; 117 WebInspector.SourcesPanel.minToolbarWidth = 215;
117 118
118 WebInspector.SourcesPanel._infobarSymbol = Symbol("infobar");
119
120 WebInspector.SourcesPanel.prototype = { 119 WebInspector.SourcesPanel.prototype = {
121 /** 120 /**
122 * @param {?WebInspector.Target} target 121 * @param {?WebInspector.Target} target
123 */ 122 */
124 _setTarget: function(target) 123 _setTarget: function(target)
125 { 124 {
126 if (!target) 125 if (!target)
127 return; 126 return;
128 127
129 if (target.debuggerModel.isPaused()) { 128 if (target.debuggerModel.isPaused()) {
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 return true; 474 return true;
476 }, 475 },
477 476
478 /** 477 /**
479 * @param {!WebInspector.Event} event 478 * @param {!WebInspector.Event} event
480 */ 479 */
481 _editorSelected: function(event) 480 _editorSelected: function(event)
482 { 481 {
483 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data ); 482 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data );
484 this._editorChanged(uiSourceCode); 483 this._editorChanged(uiSourceCode);
485 if (Runtime.experiments.isEnabled("suggestUsingWorkspace")) {
486 if (this._editorSelectedTimer)
487 clearTimeout(this._editorSelectedTimer);
488 this._editorSelectedTimer = setTimeout(this._updateSuggestedMappingI nfobar.bind(this, uiSourceCode), 3000);
489 }
490 }, 484 },
491 485
492 /** 486 /**
493 * @param {!WebInspector.UISourceCode} uiSourceCode
494 */
495 _updateSuggestedMappingInfobar: function(uiSourceCode)
496 {
497 if (!this.isShowing())
498 return;
499 if (uiSourceCode[WebInspector.SourcesPanel._infobarSymbol])
500 return;
501
502 // First try mapping filesystem -> network.
503 var uiSourceCodeFrame = this._sourcesView.viewForFile(uiSourceCode);
504 if (uiSourceCode.project().type() === WebInspector.projectTypes.FileSyst em) {
505 var hasMappings = !!uiSourceCode.url;
506 if (hasMappings)
507 return;
508
509 var targets = WebInspector.targetManager.targets();
510 for (var i = 0; i < targets.length; ++i)
511 targets[i].resourceTreeModel.forAllResources(matchResource.bind( this));
512 }
513
514 /**
515 * @param {!WebInspector.Resource} resource
516 * @return {boolean}
517 * @this {WebInspector.SourcesPanel}
518 */
519 function matchResource(resource)
520 {
521 if (resource.contentURL().endsWith(uiSourceCode.name())) {
522 createMappingInfobar.call(this, false);
523 return true;
524 }
525 return false;
526 }
527
528 // Then map network -> filesystem.
529 if (uiSourceCode.project().type() === WebInspector.projectTypes.Network || uiSourceCode.project().type() === WebInspector.projectTypes.ContentScripts) {
530 if (this._workspace.uiSourceCodeForURL(uiSourceCode.url) !== uiSourc eCode)
531 return;
532
533 var filesystemProjects = this._workspace.projectsForType(WebInspecto r.projectTypes.FileSystem);
534 for (var i = 0; i < filesystemProjects.length; ++i) {
535 var name = uiSourceCode.name();
536 var fsUiSourceCodes = filesystemProjects[i].uiSourceCodes();
537 for (var j = 0; j < fsUiSourceCodes.length; ++j) {
538 if (fsUiSourceCodes[j].name() === name) {
539 createMappingInfobar.call(this, true);
540 return;
541 }
542 }
543 }
544
545 // There are no matching filesystems. Suggest adding a filesystem in case of localhost.
546 var originURL = uiSourceCode.originURL().asParsedURL();
547 if (originURL && originURL.host === "localhost")
548 createWorkspaceInfobar();
549 }
550
551 /**
552 * @param {boolean} isNetwork
553 * @this {WebInspector.SourcesPanel}
554 */
555 function createMappingInfobar(isNetwork)
556 {
557 var title;
558 if (isNetwork)
559 title = WebInspector.UIString("Map network resource '%s' to work space?", uiSourceCode.originURL());
560 else
561 title = WebInspector.UIString("Map workspace resource '%s' to ne twork?", uiSourceCode.path());
562
563 var infobar = new WebInspector.UISourceCodeFrame.Infobar(WebInspecto r.UISourceCodeFrame.Infobar.Level.Info, title);
564 infobar.createDetailsRowMessage(WebInspector.UIString("You can map f iles in your workspace to the ones loaded over the network. As a result, changes made in DevTools will be persisted to disk."));
565 infobar.createDetailsRowMessage(WebInspector.UIString("Use context m enu to establish the mapping at any time."));
566 var actionLink = infobar.createDetailsRowMessage("").createChild("a" );
567 actionLink.href = "";
568 actionLink.onclick = establishTheMapping.bind(this);
569 actionLink.textContent = WebInspector.UIString("Establish the mappin g now...");
570 appendInfobar(infobar);
571 }
572
573 /**
574 * @param {?Event} event
575 * @this {WebInspector.SourcesPanel}
576 */
577 function establishTheMapping(event)
578 {
579 event.consume(true);
580 if (uiSourceCode.project().type() === WebInspector.projectTypes.File System)
581 this._mapFileSystemToNetwork(uiSourceCode);
582 else
583 this._mapNetworkToFileSystem(uiSourceCode);
584 }
585
586 function createWorkspaceInfobar()
587 {
588 var infobar = new WebInspector.UISourceCodeFrame.Infobar(WebInspecto r.UISourceCodeFrame.Infobar.Level.Info, WebInspector.UIString("Serving from the file system? Add your files into the workspace."));
589 infobar.createDetailsRowMessage(WebInspector.UIString("If you add fi les into your DevTools workspace, your changes will be persisted to disk."));
590 infobar.createDetailsRowMessage(WebInspector.UIString("To add a fold er into the workspace, drag and drop it into the Sources panel."));
591 appendInfobar(infobar);
592 }
593
594 /**
595 * @param {!WebInspector.UISourceCodeFrame.Infobar} infobar
596 */
597 function appendInfobar(infobar)
598 {
599 infobar.createDetailsRowMessage("").createChild("br");
600 var rowElement = infobar.createDetailsRowMessage(WebInspector.UIStri ng("For more information on workspaces, refer to the "));
601 var a = rowElement.createChild("a");
602 a.textContent = "workspaces documentation";
603 a.href = "https://developer.chrome.com/devtools/docs/workspaces";
604 rowElement.createTextChild(".");
605 uiSourceCode[WebInspector.SourcesPanel._infobarSymbol] = infobar;
606 uiSourceCodeFrame.attachInfobars([infobar]);
607 }
608 },
609
610 /**
611 * @param {!WebInspector.Event} event 487 * @param {!WebInspector.Event} event
612 */ 488 */
613 _editorClosed: function(event) 489 _editorClosed: function(event)
614 { 490 {
615 var wasSelected = /** @type {boolean} */ (event.data.wasSelected); 491 var wasSelected = /** @type {boolean} */ (event.data.wasSelected);
616 if (wasSelected) 492 if (wasSelected)
617 this._editorChanged(null); 493 this._editorChanged(null);
618 }, 494 },
619 495
620 /** 496 /**
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 785
910 _suggestReload: function() 786 _suggestReload: function()
911 { 787 {
912 if (window.confirm(WebInspector.UIString("It is recommended to restart i nspector after making these changes. Would you like to restart it?"))) 788 if (window.confirm(WebInspector.UIString("It is recommended to restart i nspector after making these changes. Would you like to restart it?")))
913 WebInspector.reload(); 789 WebInspector.reload();
914 }, 790 },
915 791
916 /** 792 /**
917 * @param {!WebInspector.UISourceCode} uiSourceCode 793 * @param {!WebInspector.UISourceCode} uiSourceCode
918 */ 794 */
919 _mapFileSystemToNetwork: function(uiSourceCode) 795 mapFileSystemToNetwork: function(uiSourceCode)
920 { 796 {
921 WebInspector.SelectUISourceCodeForProjectTypesDialog.show(uiSourceCode.n ame(), [WebInspector.projectTypes.Network, WebInspector.projectTypes.ContentScri pts], mapFileSystemToNetwork.bind(this), this.editorView.mainElement()) 797 WebInspector.SelectUISourceCodeForProjectTypesDialog.show(uiSourceCode.n ame(), [WebInspector.projectTypes.Network, WebInspector.projectTypes.ContentScri pts], mapFileSystemToNetwork.bind(this), this.editorView.mainElement())
922 798
923 /** 799 /**
924 * @param {!WebInspector.UISourceCode} networkUISourceCode 800 * @param {!WebInspector.UISourceCode} networkUISourceCode
925 * @this {WebInspector.SourcesPanel} 801 * @this {WebInspector.SourcesPanel}
926 */ 802 */
927 function mapFileSystemToNetwork(networkUISourceCode) 803 function mapFileSystemToNetwork(networkUISourceCode)
928 { 804 {
929 this._workspace.addMapping(networkUISourceCode, uiSourceCode, WebIns pector.fileSystemWorkspaceBinding); 805 this._workspace.addMapping(networkUISourceCode, uiSourceCode, WebIns pector.fileSystemWorkspaceBinding);
930 this._suggestReload(); 806 this._suggestReload();
931 } 807 }
932 }, 808 },
933 809
934 /** 810 /**
935 * @param {!WebInspector.UISourceCode} uiSourceCode
936 */
937 _removeNetworkMapping: function(uiSourceCode)
938 {
939 if (confirm(WebInspector.UIString("Are you sure you want to remove netwo rk mapping?"))) {
940 this._workspace.removeMapping(uiSourceCode);
941 this._suggestReload();
942 }
943 },
944
945 /**
946 * @param {!WebInspector.UISourceCode} networkUISourceCode 811 * @param {!WebInspector.UISourceCode} networkUISourceCode
947 */ 812 */
948 _mapNetworkToFileSystem: function(networkUISourceCode) 813 mapNetworkToFileSystem: function(networkUISourceCode)
949 { 814 {
950 WebInspector.SelectUISourceCodeForProjectTypesDialog.show(networkUISourc eCode.name(), [WebInspector.projectTypes.FileSystem], mapNetworkToFileSystem.bin d(this), this.editorView.mainElement()) 815 WebInspector.SelectUISourceCodeForProjectTypesDialog.show(networkUISourc eCode.name(), [WebInspector.projectTypes.FileSystem], mapNetworkToFileSystem.bin d(this), this.editorView.mainElement())
951 816
952 /** 817 /**
953 * @param {!WebInspector.UISourceCode} uiSourceCode 818 * @param {!WebInspector.UISourceCode} uiSourceCode
954 * @this {WebInspector.SourcesPanel} 819 * @this {WebInspector.SourcesPanel}
955 */ 820 */
956 function mapNetworkToFileSystem(uiSourceCode) 821 function mapNetworkToFileSystem(uiSourceCode)
957 { 822 {
958 this._workspace.addMapping(networkUISourceCode, uiSourceCode, WebIns pector.fileSystemWorkspaceBinding); 823 this._workspace.addMapping(networkUISourceCode, uiSourceCode, WebIns pector.fileSystemWorkspaceBinding);
959 this._suggestReload(); 824 this._suggestReload();
960 } 825 }
961 }, 826 },
962 827
963 /** 828 /**
829 * @param {!WebInspector.UISourceCode} uiSourceCode
830 */
831 _removeNetworkMapping: function(uiSourceCode)
832 {
833 if (confirm(WebInspector.UIString("Are you sure you want to remove netwo rk mapping?"))) {
834 this._workspace.removeMapping(uiSourceCode);
835 this._suggestReload();
836 }
837 },
838
839 /**
964 * @param {!WebInspector.ContextMenu} contextMenu 840 * @param {!WebInspector.ContextMenu} contextMenu
965 * @param {!WebInspector.UISourceCode} uiSourceCode 841 * @param {!WebInspector.UISourceCode} uiSourceCode
966 */ 842 */
967 _appendUISourceCodeMappingItems: function(contextMenu, uiSourceCode) 843 _appendUISourceCodeMappingItems: function(contextMenu, uiSourceCode)
968 { 844 {
969 if (uiSourceCode.project().type() === WebInspector.projectTypes.FileSyst em) { 845 if (uiSourceCode.project().type() === WebInspector.projectTypes.FileSyst em) {
970 var hasMappings = !!uiSourceCode.url; 846 var hasMappings = !!uiSourceCode.url;
971 if (!hasMappings) 847 if (!hasMappings)
972 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLow erCaseMenuTitles() ? "Map to network resource\u2026" : "Map to Network Resource\ u2026"), this._mapFileSystemToNetwork.bind(this, uiSourceCode)); 848 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLow erCaseMenuTitles() ? "Map to network resource\u2026" : "Map to Network Resource\ u2026"), this.mapFileSystemToNetwork.bind(this, uiSourceCode));
973 else 849 else
974 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLow erCaseMenuTitles() ? "Remove network mapping" : "Remove Network Mapping"), this. _removeNetworkMapping.bind(this, uiSourceCode)); 850 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLow erCaseMenuTitles() ? "Remove network mapping" : "Remove Network Mapping"), this. _removeNetworkMapping.bind(this, uiSourceCode));
975 } 851 }
976 852
977 /** 853 /**
978 * @param {!WebInspector.Project} project 854 * @param {!WebInspector.Project} project
979 */ 855 */
980 function filterProject(project) 856 function filterProject(project)
981 { 857 {
982 return project.type() === WebInspector.projectTypes.FileSystem; 858 return project.type() === WebInspector.projectTypes.FileSystem;
983 } 859 }
984 860
985 if (uiSourceCode.project().type() === WebInspector.projectTypes.Network || uiSourceCode.project().type() === WebInspector.projectTypes.ContentScripts) { 861 if (uiSourceCode.project().type() === WebInspector.projectTypes.Network || uiSourceCode.project().type() === WebInspector.projectTypes.ContentScripts) {
986 if (!this._workspace.projects().filter(filterProject).length) 862 if (!this._workspace.projects().filter(filterProject).length)
987 return; 863 return;
988 if (this._workspace.uiSourceCodeForURL(uiSourceCode.url) === uiSourc eCode) 864 if (this._workspace.uiSourceCodeForURL(uiSourceCode.url) === uiSourc eCode)
989 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLow erCaseMenuTitles() ? "Map to file system resource\u2026" : "Map to File System R esource\u2026"), this._mapNetworkToFileSystem.bind(this, uiSourceCode)); 865 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLow erCaseMenuTitles() ? "Map to file system resource\u2026" : "Map to File System R esource\u2026"), this.mapNetworkToFileSystem.bind(this, uiSourceCode));
990 } 866 }
991 }, 867 },
992 868
993 /** 869 /**
994 * @param {!Event} event 870 * @param {!Event} event
995 * @param {!WebInspector.ContextMenu} contextMenu 871 * @param {!WebInspector.ContextMenu} contextMenu
996 * @param {!Object} target 872 * @param {!Object} target
997 */ 873 */
998 _appendUISourceCodeItems: function(event, contextMenu, target) 874 _appendUISourceCodeItems: function(event, contextMenu, target)
999 { 875 {
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 1408
1533 WebInspector.SourcesPanelFactory.prototype = { 1409 WebInspector.SourcesPanelFactory.prototype = {
1534 /** 1410 /**
1535 * @return {!WebInspector.Panel} 1411 * @return {!WebInspector.Panel}
1536 */ 1412 */
1537 createPanel: function() 1413 createPanel: function()
1538 { 1414 {
1539 return WebInspector.SourcesPanel.instance(); 1415 return WebInspector.SourcesPanel.instance();
1540 } 1416 }
1541 } 1417 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698