Index: chrome/browser/resources/net_internals/dataview.js |
=================================================================== |
--- chrome/browser/resources/net_internals/dataview.js (revision 89253) |
+++ chrome/browser/resources/net_internals/dataview.js (working copy) |
@@ -13,7 +13,6 @@ |
* @constructor |
*/ |
function DataView(mainBoxId, |
- outputTextBoxId, |
exportTextButtonId, |
securityStrippingCheckboxId, |
byteLoggingCheckboxId, |
@@ -27,8 +26,6 @@ |
loggingTextSpanId) { |
DivView.call(this, mainBoxId); |
- this.textPre_ = document.getElementById(outputTextBoxId); |
- |
var securityStrippingCheckbox = |
document.getElementById(securityStrippingCheckboxId); |
securityStrippingCheckbox.onclick = |
@@ -38,8 +35,8 @@ |
byteLoggingCheckbox.onclick = |
this.onSetByteLogging_.bind(this, byteLoggingCheckbox); |
- var exportTextButton = document.getElementById(exportTextButtonId); |
- exportTextButton.onclick = this.onExportToText_.bind(this); |
+ this.exportTextButton_ = document.getElementById(exportTextButtonId); |
+ this.exportTextButton_.onclick = this.onExportToText_.bind(this); |
this.activelyCapturedCountBox_ = |
document.getElementById(activelyCapturedCountId); |
@@ -58,7 +55,6 @@ |
this.logFileChanged.bind(this, loadLogFileElement); |
this.updateEventCounts_(); |
- this.waitingForUpdate_ = false; |
g_browser.addLogObserver(this); |
} |
@@ -96,7 +92,6 @@ |
setNodeDisplay(this.dumpDataDiv_, !isViewingLogFile); |
setNodeDisplay(this.capturingTextSpan_, !isViewingLogFile); |
setNodeDisplay(this.loggingTextSpan_, isViewingLogFile); |
- this.setText_(''); |
}; |
/** |
@@ -130,11 +125,7 @@ |
g_browser.setSecurityStripping(securityStrippingCheckbox.checked); |
}; |
-/** |
- * Clears displayed text when security stripping is toggled. |
- */ |
DataView.prototype.onSecurityStrippingChanged = function() { |
- this.setText_(''); |
} |
/** |
@@ -168,15 +159,19 @@ |
g_browser.loadedLogFile(event.target.result); |
} |
+DataView.prototype.EnableExportTextButton_ = function(enabled) { |
eroman
2011/06/16 00:42:02
nit: use lowercaseCamelCase for function names in
mmenke
2011/06/16 16:16:53
Done.
|
+ this.exportTextButton_.disabled = !enabled; |
+} |
+ |
/** |
* If not already waiting for results from all updates, triggers all |
* updates and starts waiting for them to complete. |
*/ |
DataView.prototype.onExportToText_ = function() { |
- if (this.waitingForUpdate_) |
+ if (this.exportTextButton_.disabled) |
return; |
- this.waitingForUpdate = true; |
- this.setText_('Generating...'); |
+ this.EnableExportTextButton_(false); |
+ |
g_browser.updateAllInfo(this.onUpdateAllCompleted.bind(this)); |
}; |
@@ -404,12 +399,45 @@ |
} |
} |
- // Open a new window to display this text. |
- this.setText_(text.join('\n')); |
- |
- this.selectText_(); |
+ var chunkSize = 100 * 1024; |
eroman
2011/06/16 00:42:02
chunkSize is unused.
mmenke
2011/06/16 16:16:53
Removed. Accidentally left over from one of the a
|
+ var flatText = text.join('\n'); |
+ window.webkitRequestFileSystem( |
+ window.TEMPORARY, 10*1024 + flatText.length, |
eroman
2011/06/16 00:42:02
nit: the assumption here is that 1 character = 1 b
mmenke
2011/06/16 16:16:53
Fixed. Thanks for catching that. Be a pain to ru
|
+ this.OnFileSystemCreate_.bind(this, flatText), |
+ this.OnFileError_.bind(this, 'Unable to create file system.')); |
}; |
+DataView.prototype.OnFileSystemCreate_ = function(text, fileSystem) { |
eroman
2011/06/16 00:42:02
I believe javascript style stipulates lowercase fo
mmenke
2011/06/16 16:16:53
Fixed everywhere.
|
+ fileSystem.root.getFile( |
+ 'net_internals_log.txt', {create: true}, |
eroman
2011/06/16 00:42:02
I wander if we should include a unique identifier
mmenke
2011/06/16 16:16:53
I considered that, but wasn't sure it was worth th
|
+ this.OnFileCreate_.bind(this, text), |
+ this.OnFileError_.bind(this, 'Unable to create file.')); |
+} |
eroman
2011/06/16 00:42:02
nit: can you put semicolon after all of these "sta
mmenke
2011/06/16 16:16:53
Done.
|
+ |
+DataView.prototype.OnFileCreate_ = function(text, fileEntry) { |
+ fileEntry.createWriter( |
+ this.OnFileCreateWriter_.bind(this, text, fileEntry), |
+ this.OnFileError_.bind(this, 'Unable to create writer.')); |
+} |
+ |
+DataView.prototype.OnFileCreateWriter_ = function(text, fileEntry, fileWriter) { |
+ fileWriter.onerror = this.OnFileError_.bind(this, 'Write failed.') |
+ fileWriter.onwriteend = this.OnFileWriteComplete_.bind(this, fileEntry) |
+ var blobBuilder = new WebKitBlobBuilder(); |
+ blobBuilder.append(text); |
eroman
2011/06/16 00:42:02
Do you know how it serializes strings? UTF16? UTF8
mmenke
2011/06/16 16:16:53
Experimentally, just writes out UTF8.
|
+ fileWriter.write(blobBuilder.getBlob('octet/stream')); |
eroman
2011/06/16 00:42:02
One annoyance is line ending on Windows are CR LF,
mmenke
2011/06/16 16:16:53
Fixed (Use CRLF on Windows only).
|
+} |
+ |
+DataView.prototype.OnFileWriteComplete_ = function(fileEntry) { |
+ window.location = fileEntry.toURL(); |
eroman
2011/06/16 00:42:02
Not a big deal, but this might cause a flicker in
mmenke
2011/06/16 16:16:53
We don't actually update the address bar until we'
mmenke
2011/06/16 16:26:59
Well...I was wrong about this. I'll go ahead and
|
+ this.EnableExportTextButton_(true); |
+} |
+ |
+DataView.prototype.OnFileError_ = function(errorText, error) { |
+ this.EnableExportTextButton_(true); |
+ alert(errorText + ' Error: ' + error.code); |
eroman
2011/06/16 00:42:02
I suggest giving a more informative message, since
mmenke
2011/06/16 16:16:53
Done.
|
+} |
+ |
DataView.prototype.appendEventsPrintedAsText_ = function(out) { |
var allEvents = g_browser.getAllCapturedEvents(); |
@@ -480,14 +508,6 @@ |
}; |
/** |
- * Helper function to set this view's content to |text|. |
- */ |
-DataView.prototype.setText_ = function(text) { |
- this.textPre_.innerHTML = ''; |
- addTextNode(this.textPre_, text); |
-}; |
- |
-/** |
* Format a time ticks count as a timestamp. |
*/ |
DataView.prototype.formatExpirationTime_ = function(timeTicks) { |
@@ -495,15 +515,3 @@ |
var isExpired = d.getTime() < (new Date()).getTime(); |
return 't=' + d.getTime() + (isExpired ? ' [EXPIRED]' : ''); |
}; |
- |
-/** |
- * Select all text from log dump. |
- */ |
-DataView.prototype.selectText_ = function() { |
- var selection = window.getSelection(); |
- selection.removeAllRanges(); |
- |
- var range = document.createRange(); |
- range.selectNodeContents(this.textPre_); |
- selection.addRange(range); |
-}; |