Closed Bug 1237087 Opened 8 years ago Closed 8 years ago

Add ability for WebCompatReporter ("Report Site Issue") to send screenshots to new issue form

Categories

(Firefox for Android Graveyard :: General, defect)

defect
Not set
normal

Tracking

(firefox48 fixed)

RESOLVED FIXED
Firefox 48
Tracking Status
firefox48 --- fixed

People

(Reporter: miketaylr, Assigned: miketaylr)

Details

Attachments

(2 files, 7 obsolete files)

4.53 KB, patch
miketaylr
: review+
Details | Diff | Splinter Review
4.31 KB, patch
miketaylr
: review+
Details | Diff | Splinter Review
We've updated webcompat.com to have better image uploading capabilities and would like reports that come from the Nightly "Report Site Issue" to attach a screenshot by default  - "anonymous" reports often contain very little context. 

Users will have the opportunity to remove it before submitting.

See https://github.com/webcompat/webcompat.com/issues/879#issuecomment-169107610 for a gif of the same functionality in our Chrome add-on.
Attachment #8727465 - Attachment is obsolete: true
Attachment #8727466 - Attachment is obsolete: true
Comment on attachment 8727472 [details] [diff] [review]
Part 1 - Refactor WebCompatReport.reportIssue to take an object argument. r=?

Sebastian, would you mind reviewing?
Attachment #8727472 - Flags: review?(s.kaspari)
Attachment #8727473 - Flags: review?(s.kaspari)
In case it's helpful as context, here's where we handle incoming message events for the bug form (including making sure we only accept our own origin): https://github.com/webcompat/webcompat.com/blob/master/webcompat/static/js/lib/bugform.js#L52-L63
Comment on attachment 8727472 [details] [diff] [review]
Part 1 - Refactor WebCompatReport.reportIssue to take an object argument. r=?

Review of attachment 8727472 [details] [diff] [review]:
-----------------------------------------------------------------

::: mobile/android/chrome/content/WebcompatReporter.js
@@ +58,5 @@
>    addMenuItem: function(visible) {
>      this.menuItem = NativeWindow.menu.add({
>        name: this.strings.GetStringFromName("webcompat.menu.name"),
>        callback: () => {
> +        this.reportIssue({url: BrowserApp.selectedTab.browser.currentURI.spec;}});

This line seems to be malformed (semicolon and double closing "}"). But it looks like the next commit fixes this. Maybe collapse them?
Attachment #8727472 - Flags: review?(s.kaspari) → review+
Comment on attachment 8727473 [details] [diff] [review]
Part 2 - Send screenshot of visible window when reporting site issue. r=?

Review of attachment 8727473 [details] [diff] [review]:
-----------------------------------------------------------------

LGTM but I would like Margaret to take a quick look too.
Attachment #8727473 - Flags: review?(s.kaspari)
Attachment #8727473 - Flags: review?(margaret.leibovic)
Attachment #8727473 - Flags: review+
Thanks for review!

(In reply to Sebastian Kaspari (:sebastian) from comment #7)
> This line seems to be malformed (semicolon and double closing "}"). But it
> looks like the next commit fixes this. Maybe collapse them?

Ah, dang. I tried to fix that up in a rebase and naturally screwed it up. Will fix (and check it multiple times). I'm not sure there's a ton of value in keeping this tiny refactor in a different commit, so maybe I will just combine both patches.
Attachment #8727472 - Attachment is obsolete: true
Attachment #8727473 - Attachment is obsolete: true
Attachment #8727473 - Flags: review?(margaret.leibovic)
Comment on attachment 8727516 [details] [diff] [review]
Send screenshot of visible window when reporting site issues.

Combined commits (which fixes the semi-colon brace carnage).
Attachment #8727516 - Flags: review+ → review?(margaret.leibovic)
Comment on attachment 8727473 [details] [diff] [review]
Part 2 - Send screenshot of visible window when reporting site issue. r=?

Review of attachment 8727473 [details] [diff] [review]:
-----------------------------------------------------------------

::: mobile/android/chrome/content/WebcompatReporter.js
@@ +68,5 @@
>      });
>    },
>  
> +  getScreenshot: (tab) => {
> +    return new Promise((resolve, reject) => {

nit: reject is not used.

@@ +84,5 @@
> +        canvas.width = dpr * w;
> +        canvas.height = dpr * h;
> +        ctx.scale(dpr, dpr);
> +        ctx.drawWindow(win, x, y, w, h, '#ffffff');
> +        let screenshot = canvas.toDataURL();

nit: Do you need this `let` here, or can you just put this into resolve below?

@@ +89,5 @@
> +        resolve({url: tab.browser.currentURI.spec, data: screenshot});
> +      } catch (e) {
> +        // drawWindow can fail depending on memory or surface size. Rather than reject, we resolve
> +        // the URL so the user can continue to file an issue without a screenshot.
> +        Cu.reportError("Call to CanvasRenderingContext2d.drawWindow failed: " + e);

nit: this means something in the above `try` failed, not just `drawWindow`.

@@ +114,5 @@
>      Snackbars.show(message, Snackbars.LENGTH_LONG, options);
>    },
>  
> +  reportIssue: (tabData) => {
> +    return new Promise((resolve, reject) => {

nit: reject is not used.
Attachment #8727473 - Attachment is obsolete: false
Thanks Vlad, also just noticed the following:

> let isPrivateTab = PrivateBrowsingUtils.isBrowserPrivate(selectedTab.browser) ? true : false;

Seems like a useless ternary, isBrowserPrivate returns a boolean already.
Comment on attachment 8727516 [details] [diff] [review]
Send screenshot of visible window when reporting site issues.

Removing review request until I fix up Vlad's nits.
Attachment #8727516 - Flags: review?(margaret.leibovic)
Attachment #8727473 - Attachment is obsolete: true
Attachment #8727516 - Attachment is obsolete: true
Attachment #8727541 - Flags: review?(margaret.leibovic)
Comment on attachment 8727541 [details] [diff] [review]
Send screenshot of visible window when reporting site issues.

Review of attachment 8727541 [details] [diff] [review]:
-----------------------------------------------------------------

Cool, this is neat.

::: mobile/android/chrome/content/WebcompatReporter.js
@@ +116,5 @@
>  
> +  reportIssue: (tabData) => {
> +    return new Promise((resolve) => {
> +      const WEBCOMPAT_ORIGIN = "https://webcompat.com";
> +      let selectedTab = BrowserApp.selectedTab;

It seems a bit odd that consumers are passing the selected tab's URL directly into this method, but then it still uses the selected tab itself for other things. Could you avoid passing along the URL altogether and just get it directly here? Or pass in the tab itself?

But this is already an issue with this code, so not a big deal.

@@ +126,5 @@
> +
> +          if (event.target.defaultView.location.origin === WEBCOMPAT_ORIGIN) {
> +            // Waive Xray vision so event.origin is not chrome://browser on the other side.
> +            let win = Cu.waiveXrays(event.target.defaultView);
> +            win.postMessage(tabData.data, WEBCOMPAT_ORIGIN);

I'm not familiar with waiveXrays, but I'll trust it does what you intend it to do :)
Attachment #8727541 - Flags: review?(margaret.leibovic) → review+
Thanks for review!

(In reply to :Margaret Leibovic from comment #16)
> Comment on attachment 8727541 [details] [diff] [review]
> ::: mobile/android/chrome/content/WebcompatReporter.js
> @@ +116,5 @@
> >  
> > +  reportIssue: (tabData) => {
> > +    return new Promise((resolve) => {
> > +      const WEBCOMPAT_ORIGIN = "https://webcompat.com";
> > +      let selectedTab = BrowserApp.selectedTab;
> 
> It seems a bit odd that consumers are passing the selected tab's URL
> directly into this method, but then it still uses the selected tab itself
> for other things. Could you avoid passing along the URL altogether and just
> get it directly here? Or pass in the tab itself?
> 
> But this is already an issue with this code, so not a big deal.

Good point! We should just grab the tab once and pass it around. 

(I'll change that in a new commit since it touches the reportDesktopModePrompt code too.)

> @@ +126,5 @@
> > +
> > +          if (event.target.defaultView.location.origin === WEBCOMPAT_ORIGIN) {
> > +            // Waive Xray vision so event.origin is not chrome://browser on the other side.
> > +            let win = Cu.waiveXrays(event.target.defaultView);
> > +            win.postMessage(tabData.data, WEBCOMPAT_ORIGIN);
> 
> I'm not familiar with waiveXrays, but I'll trust it does what you intend it
> to do :)

Famous last words...
Attachment #8727541 - Attachment is obsolete: true
Comment on attachment 8727631 [details] [diff] [review]
Send screenshot of visible window when reporting site issues. r=sebastian, margaret

Updating commit message to reflect Margaret's review and carrying forward r+.
Attachment #8727631 - Flags: review+
Comment on attachment 8727633 [details] [diff] [review]
Consistently pass tab references when reporting site issues. r=?

Margaret, mind reviewing here?

Try run: https://treeherder.mozilla.org/#/jobs?repo=try&revision=9164326fdfdc
Attachment #8727633 - Flags: review?(margaret.leibovic)
Comment on attachment 8727633 [details] [diff] [review]
Consistently pass tab references when reporting site issues. r=?

Review of attachment 8727633 [details] [diff] [review]:
-----------------------------------------------------------------

Nice cleanup.
Attachment #8727633 - Flags: review?(margaret.leibovic) → review+
Attachment #8727633 - Attachment is obsolete: true
Thanks again Sebastian and Margaret for feedback and reviews.

(Updating commit msg and carrying forward r+ on the last patch)
https://hg.mozilla.org/mozilla-central/rev/e4f29173049f
https://hg.mozilla.org/mozilla-central/rev/6ac236f12205
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 48
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: