Closed
Bug 964015
Opened 10 years ago
Closed 10 years ago
Add "Copy as data URI" for images in the Network Monitor
Categories
(DevTools :: Netmonitor, defect, P2)
DevTools
Netmonitor
Tracking
(Not tracked)
RESOLVED
FIXED
Firefox 29
People
(Reporter: vporof, Assigned: lpy)
References
Details
(Whiteboard: [good first bug][lang=js][mentor=vporof])
Attachments
(1 file, 4 obsolete files)
15.59 KB,
patch
|
lpy
:
review+
|
Details | Diff | Splinter Review |
This is useful.
Comment 1•10 years ago
|
||
Bug 964014 aims at doing the same for the markup-view. We should probably align the 2 bugs in terms of wording: "Copy Image as Data-URI" or something like this. Also, I think there's an easy way to tackle this one. Since a couple of weeks, we have the inspector actor front at toolbox level, so available from anywhere. And it turns out that, after bug 932220 lands, the inspector actor will have a new method that transforms an image URL into data-uri (it's called getDataUriFromURL or something like that). That could be an easy way to fix this.
Reporter | ||
Comment 2•10 years ago
|
||
Since we already have the image data as a string, we could convert that to a data URI directly without fiddling with the Inspector actor.
Reporter | ||
Comment 3•10 years ago
|
||
This is an easy bug to fix. If anyone's interested, feel free. This involves just adding an item in a context menu and copying to clipboard (code for this is already available).
Whiteboard: [good first bug][lang=js][mentor=vporof]
Assignee | ||
Comment 4•10 years ago
|
||
I would like to take this bug, could you please point the direction for me? Which part of code should I start to read? Thank you :)
Reporter | ||
Comment 5•10 years ago
|
||
Hi! Thanks for the interest. This should get you started with building Firefox from source, and tell you a few things about running automated tests: [0] Let me know if you need any help with that. In this bug, you'll need to add an item in the context menu here: [1] The strings there are localized, so add an entry here as well [2]. You'll have to make sure the menu item isn't shown for all requests, only for images; this should be done here [3]. Here's an example how to copy a string to clipboard: [4], and here's a place where we build a data uri for an image: [5] After implementing the new context menu item, you'll have to create an automated test to make sure this won't break in the future. Here's something you can use as inspiration: [6]. You can clone that test and modify it to suit your needs. Let me know if you need any additional help! [0] https://wiki.mozilla.org/DevTools/Hacking [1] http://dxr.mozilla.org/mozilla-central/source/browser/devtools/netmonitor/netmonitor.xul#24 [2] http://dxr.mozilla.org/mozilla-central/source/browser/locales/en-US/chrome/browser/devtools/netmonitor.dtd?from=netmonitor.dtd#178 [3] http://dxr.mozilla.org/mozilla-central/source/browser/devtools/netmonitor/netmonitor-view.js#1274 [4] http://dxr.mozilla.org/mozilla-central/source/browser/devtools/netmonitor/netmonitor-view.js#419 [5] http://dxr.mozilla.org/mozilla-central/source/browser/devtools/netmonitor/netmonitor-view.js#2051 [6] http://dxr.mozilla.org/mozilla-central/source/browser/devtools/netmonitor/test/browser_net_copy_url.js
Reporter | ||
Updated•10 years ago
|
Assignee: nobody → pylaurent1314
Status: NEW → ASSIGNED
Assignee | ||
Comment 6•10 years ago
|
||
Attach the patch. The problem is, when I tried to run the test under netmonitor, the browser just said that "XML Parsing Error: undefined entity" with <menuitem id="request-menu-context-copy-image-as-data-uri" I could not figure out what was wrong. Could you please help me? Thank you
Attachment #8367395 -
Flags: feedback?(vporof)
Assignee | ||
Updated•10 years ago
|
Attachment #8367395 -
Flags: feedback?(vporof)
Assignee | ||
Comment 7•10 years ago
|
||
I found it. Thank you
Assignee | ||
Comment 8•10 years ago
|
||
Hi. I write a test, and I set |RequestsMenu.selectedItem = requestItembut| and when I call |RequestsMenu.copyImageAsDataUri()|, I got "Full message: TypeError: this.selectedItem.attachment.responseContent is undefined". I run the test manually, and it did select the right one, which was an image. I couldn't figure it out. Please help. Thank you.
Attachment #8367395 -
Attachment is obsolete: true
Attachment #8367848 -
Flags: feedback?(vporof)
Assignee | ||
Comment 9•10 years ago
|
||
Correct: I mean |RequestsMenu.selectedItem = requestItem|
Reporter | ||
Comment 10•10 years ago
|
||
Comment on attachment 8367848 [details] [diff] [review] bug964015-V2.patch Review of attachment 8367848 [details] [diff] [review]: ----------------------------------------------------------------- ::: browser/devtools/netmonitor/netmonitor-view.js @@ +431,5 @@ > + let { mimeType, text, encoding } = this.selectedItem.attachment.responseContent.content; > + return gNetwork.getString(text).then(aString => { > + clipboardHelper.copyString("data:" + mimeType + ";" + encoding + "," + aString, > + document); > + }).then(() => window.emit(EVENTS.RESPONSE_BODY_DISPLAYED)); We don't need to emit any events here, and shouldn't return a promise. Here's how I would write this: copyImageAsDataUri: function() { let selected = this.selectedItem.attachment; let { mimeType, text, encoding } = attachment.responseContent.content; gNetwork.getString(text).then(aString => { let data = "data:" + mimeType + ";" + encoding + "," + aString; clipboardHelper.copyString(data, document); }); } @@ +1292,5 @@ > let copyUrlElement = $("#request-menu-context-copy-url"); > copyUrlElement.hidden = !this.selectedItem; > > + let copyImageAsDataUriElement = $("#request-menu-context-copy-image-as-data-uri"); > + copyImageAsDataUriElement.hidden = !this.selectedItem You should have a couple more checks here. What if the response content isn't available yet when you right click, for example? Let's cache this.selectedItem in this entire function, and write this as copyImageAsDataUriElement.hidden = !selectedItem || !selectedItem.attachment.responseContent || !selectedItem.attachment.responseContent.content.mimeType.contains("image/"); ::: browser/devtools/netmonitor/test/browser_net_copy_image_as_data_uri.js @@ +9,5 @@ > + initNetMonitor(CONTENT_TYPE_URL).then(([aTab, aDebuggee, aMonitor]) => { > + info("Starting test... "); > + > + let { NetMonitorView } = aMonitor.panelWin; > + let { RequestsMenu } = NetMonitorView; You should add a RequestsMenu.lazyUpdate = false; here to avoid responseContent being undefined below. @@ +27,5 @@ > + cleanUp(); > + }); > + }); > + > + aDebuggee.performRequests(1); No need to pass 1 here. ::: browser/locales/en-US/chrome/browser/devtools/netmonitor.dtd @@ +182,5 @@ > <!ENTITY netmonitorUI.context.copyUrl.accesskey "C"> > > +<!-- LOCALIZATION NOTE (netmonitorUI.context.copyImageAsDataUri): This is the label displayed > + - on the context menu that copies the selected image as data uri --> > +<!ENTITY netmonitorUI.context.copyImageAsDataUri "Copy Image As Data URI"> The proper capitalization is "Copy Image as Data URI". Neat tool: http://titlecapitalization.com/
Attachment #8367848 -
Flags: feedback?(vporof) → feedback+
Assignee | ||
Comment 11•10 years ago
|
||
The test can pass when run it alone, but it will timeout when run together with other tests under netmonitor/test When run together, the test couldn't fetch the image, and kept waiting, which caused timeout. Any help please? Thank you.
Attachment #8367848 -
Attachment is obsolete: true
Attachment #8368475 -
Flags: feedback?(vporof)
Reporter | ||
Comment 12•10 years ago
|
||
Comment on attachment 8368475 [details] [diff] [review] bug964015-V3.patch Review of attachment 8368475 [details] [diff] [review]: ----------------------------------------------------------------- Sometimes caching does weird things. I'll push to try, and if things are green we'll land it.
Attachment #8368475 -
Flags: feedback?(vporof) → review+
Reporter | ||
Comment 13•10 years ago
|
||
https://tbpl.mozilla.org/?tree=Try&rev=3343bd1f6a5e
Reporter | ||
Comment 14•10 years ago
|
||
Ok, this also fails on try. We should look into it.
Reporter | ||
Updated•10 years ago
|
Attachment #8368475 -
Flags: review+
Assignee | ||
Comment 15•10 years ago
|
||
Thank you for your guide.
Attachment #8368475 -
Attachment is obsolete: true
Attachment #8368571 -
Flags: review?(vporof)
Reporter | ||
Comment 16•10 years ago
|
||
Comment on attachment 8368571 [details] [diff] [review] bug964015-V4.patch Review of attachment 8368571 [details] [diff] [review]: ----------------------------------------------------------------- Do all tests pass now when run locally?
Attachment #8368571 -
Flags: review?(vporof) → review+
Reporter | ||
Comment 17•10 years ago
|
||
New try run with updated patch: https://tbpl.mozilla.org/?tree=Try&rev=67658a9c7b74
Reporter | ||
Comment 18•10 years ago
|
||
This looks like an unrelated orange. Pushing again just to be sure.
Reporter | ||
Comment 19•10 years ago
|
||
https://tbpl.mozilla.org/?tree=Try&rev=50c356cd2e6e
Assignee | ||
Comment 20•10 years ago
|
||
Yes, I am using OSX 10.9, all tests pass when run locally.
Reporter | ||
Updated•10 years ago
|
Priority: -- → P2
Comment 22•10 years ago
|
||
This has numerous conflicts with fx-team. Please rebase.
Keywords: checkin-needed
Assignee | ||
Comment 23•10 years ago
|
||
update the patch
Attachment #8368571 -
Attachment is obsolete: true
Attachment #8369161 -
Flags: review+
Assignee | ||
Updated•10 years ago
|
Keywords: checkin-needed
Reporter | ||
Comment 24•10 years ago
|
||
https://hg.mozilla.org/integration/fx-team/rev/4e95343c93e6
Keywords: checkin-needed
Whiteboard: [good first bug][lang=js][mentor=vporof] → [good first bug][lang=js][mentor=vporof][fixed-in-fx-team]
Comment 25•10 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/4e95343c93e6
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Whiteboard: [good first bug][lang=js][mentor=vporof][fixed-in-fx-team] → [good first bug][lang=js][mentor=vporof]
Target Milestone: --- → Firefox 29
Updated•6 years ago
|
Product: Firefox → DevTools
You need to log in
before you can comment on or make changes to this bug.
Description
•