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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/console_model/ConsoleModel.js

Issue 2970313002: DevTools: do not clear console when preserving log (Closed)
Patch Set: Move conditions into one place Created 3 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 28 matching lines...) Expand all
39 this._messages = []; 39 this._messages = [];
40 /** @type {!Map<!SDK.RuntimeModel, !Map<number, !ConsoleModel.ConsoleMessage >>} */ 40 /** @type {!Map<!SDK.RuntimeModel, !Map<number, !ConsoleModel.ConsoleMessage >>} */
41 this._messageByExceptionId = new Map(); 41 this._messageByExceptionId = new Map();
42 this._warnings = 0; 42 this._warnings = 0;
43 this._errors = 0; 43 this._errors = 0;
44 44
45 SDK.targetManager.observeTargets(this); 45 SDK.targetManager.observeTargets(this);
46 } 46 }
47 47
48 /** 48 /**
49 * @param {!ConsoleModel.ConsoleMessage} message
50 * @return {boolean}
51 */
52 static canMessageClearConsole(message) {
53 if (Common.moduleSetting('preserveConsoleLog').get() ||
luoe 2017/07/06 22:16:00 ConsoleModel is the only place that knows that pre
pfeldman 2017/07/12 21:17:28 As you prefer.
54 message.source !== ConsoleModel.ConsoleMessage.MessageSource.ConsoleAPI ||
55 message.type !== ConsoleModel.ConsoleMessage.MessageType.Clear)
56 return false;
57 var runtimeModel = message.runtimeModel();
58 var executionContext = runtimeModel.executionContext(message.executionContex tId);
pfeldman 2017/07/12 21:17:28 when executionContext.isDefault === false, we shou
luoe 2017/07/13 00:42:03 Done.
59 var resourceTreeModel = runtimeModel.target().model(SDK.ResourceTreeModel);
60 var frame = resourceTreeModel && executionContext && executionContext.frameI d &&
pfeldman 2017/07/12 21:17:28 If there is no resourceTreeModel, we should allow
luoe 2017/07/13 00:42:03 Done.
61 resourceTreeModel.frameForId(executionContext.frameId);
62 return !!(frame && frame.isMainFrame());
63 }
64
65 /**
49 * @override 66 * @override
50 * @param {!SDK.Target} target 67 * @param {!SDK.Target} target
51 */ 68 */
52 targetAdded(target) { 69 targetAdded(target) {
53 var resourceTreeModel = target.model(SDK.ResourceTreeModel); 70 var resourceTreeModel = target.model(SDK.ResourceTreeModel);
54 if (!resourceTreeModel || resourceTreeModel.cachedResourcesLoaded()) { 71 if (!resourceTreeModel || resourceTreeModel.cachedResourcesLoaded()) {
55 this._initTarget(target); 72 this._initTarget(target);
56 return; 73 return;
57 } 74 }
58 75
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ConsoleEvaluated); 170 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ConsoleEvaluated);
154 } 171 }
155 172
156 /** 173 /**
157 * @param {!ConsoleModel.ConsoleMessage} msg 174 * @param {!ConsoleModel.ConsoleMessage} msg
158 */ 175 */
159 addMessage(msg) { 176 addMessage(msg) {
160 if (msg.source === ConsoleModel.ConsoleMessage.MessageSource.Worker && SDK.t argetManager.targetById(msg.workerId)) 177 if (msg.source === ConsoleModel.ConsoleMessage.MessageSource.Worker && SDK.t argetManager.targetById(msg.workerId))
161 return; 178 return;
162 179
163 if (msg.source === ConsoleModel.ConsoleMessage.MessageSource.ConsoleAPI && 180 if (ConsoleModel.ConsoleModel.canMessageClearConsole(msg))
164 msg.type === ConsoleModel.ConsoleMessage.MessageType.Clear)
165 this._clear(); 181 this._clear();
166 182
167 this._messages.push(msg); 183 this._messages.push(msg);
168 var runtimeModel = msg.runtimeModel(); 184 var runtimeModel = msg.runtimeModel();
169 if (msg._exceptionId && runtimeModel) { 185 if (msg._exceptionId && runtimeModel) {
170 var modelMap = this._messageByExceptionId.get(runtimeModel); 186 var modelMap = this._messageByExceptionId.get(runtimeModel);
171 if (!modelMap) { 187 if (!modelMap) {
172 modelMap = new Map(); 188 modelMap = new Map();
173 this._messageByExceptionId.set(runtimeModel, modelMap); 189 this._messageByExceptionId.set(runtimeModel, modelMap);
174 } 190 }
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 Warning: 'warning', 664 Warning: 'warning',
649 Error: 'error' 665 Error: 'error'
650 }; 666 };
651 667
652 ConsoleModel.ConsoleModel._events = Symbol('ConsoleModel.ConsoleModel.events'); 668 ConsoleModel.ConsoleModel._events = Symbol('ConsoleModel.ConsoleModel.events');
653 669
654 /** 670 /**
655 * @type {!ConsoleModel.ConsoleModel} 671 * @type {!ConsoleModel.ConsoleModel}
656 */ 672 */
657 ConsoleModel.consoleModel; 673 ConsoleModel.consoleModel;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698