Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Donate dialog #556

Merged
merged 11 commits into from
Oct 12, 2018
Merged

Donate dialog #556

merged 11 commits into from
Oct 12, 2018

Conversation

petemill
Copy link
Member

@petemill petemill commented Oct 3, 2018

Resolves brave/brave-browser#924

TODO

  • chrome://donate
  • Put the page in a full-width dialog, constrained to a Tab
  • Open dialog from rewards extension, passing Publisher Key and TabId
  • Height of WebUI dialog should be auto-sized to content, rest of height of content area should have semi-transparent overlay. For now I've given the dialog some x and y margin so that it doesn't appear to have replaced the tab contents.
  • y coordinate of dialog should be at content top (at the moment it's just below LocationBar)
  • Remove / Hide stub 'donate' button from this PR, or put in acceptable Donate page design in this PR
  • Close rewards extension dialog when donate dialog is opened
  • Close donate dialog when ESC is pressed
  • Remove 'Test Publisher' fallback (I couldn't get a real publisher to show in Development)
  • Bug: Dialog is opened twice resulting in dialog re-opening once when first closed will be fixed in brave-ui Button click handlers are running twice brave-ui#197

More of the features should be supported for brave/brave-browser#1221 although not all are required for this Donate dialog, which has a closer milestone than the Tipping dialog

Current state

image

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed.
  • Add appropriate QA labels (QA/Yes or QA/No) to include the closed issue in milestone

Test Plan:

  • clean profile
  • enable rewards
  • go to brave.com and click on BAT logo in the url
  • in the panel click on donate now
  • site banner should appear with default text
  • go to 3zsistemi.si and click on BAT logo in the url
  • in the panel click on donate now
  • site banner should have custom text

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

@petemill
Copy link
Member Author

petemill commented Oct 3, 2018

I suggest we work together on this branch @NejcZdovc. There's work to do on two fronts:

  1. Get more of the actual frontend and API for chrome://donate implemented, and make sure we're passing the correct data in to the dialog
  2. Improve the Dialog UX (position, size, some behavior), as well as see if it passes review.

Alternatively, we could get this PR merge-able by removing the code path to show the dialog, and then work in two subsequent PRs for the above issues.

cc @bbondy @bridiver (to review the correct BrowserContext is being used) and @bsclifton @simonhong for feedback

@NejcZdovc NejcZdovc force-pushed the donation-dialog branch 3 times, most recently from 5c19e6b to 0ef702d Compare October 4, 2018 05:55
@NejcZdovc NejcZdovc self-assigned this Oct 4, 2018
@petemill petemill force-pushed the donation-dialog branch 2 times, most recently from 6a87038 to 3c3a635 Compare October 5, 2018 21:38
@NejcZdovc NejcZdovc force-pushed the donation-dialog branch 2 times, most recently from 7608b93 to 2a62cb5 Compare October 8, 2018 18:25
@petemill
Copy link
Member Author

petemill commented Oct 10, 2018

I've had no luck with some design ambitions here:

  • Having the web view be full-width of the parent tab, but have a dynamic height. The closest I could get this is to have auto-size (like an extension popup) but min/max the width of the tab and allow the height to auto expand. Problem is the height doesn't expand high enough (even if I change the dialog to use normal document flow instead of position: fixed. Other problem is that min/max cannot be updated, so window resize does not change the size of the popup.
    Solution is for now to have a fixed size.
  • Having the popup be semi-transparent. No luck so far. Related to the first point I wanted to try setting a transparent background on the WebContents, but I didn't get far with that. A big re-architecture to get the webview inside a non-WebContent popup window with a transparent area may work, but that would take a lot of time. So it can be revisited in a separate issue.

For now I've set the popup to be a fixed [window width - 25px] x 500px, so it looks similar to other popups (Print Preview..., Cast...). Alternative would be to change to autosize and have the height manually set in the html.

@petemill
Copy link
Member Author

Scratch that last point - I've got the auto-size working with some adjustments to the html content. Still doesn't resize when the window resizes, but I'm ok with that for now.

petemill added a commit to brave/brave-ui that referenced this pull request Oct 10, 2018
NejcZdovc pushed a commit to brave/brave-ui that referenced this pull request Oct 10, 2018
}
result.SetDictionary("social", std::move(social));

web_ui()->CallJavascriptFunctionUnsafe("brave_rewards_donate.publisherBanner", result);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Use CallJavascriptFunction instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot why, but CallJavascriptFunction was not working. cc @bbondy if you can remember

we currently use CallJavascriptFunctionUnsafe across all our webui logic

publisherKey: string
title: string
description: string
background: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the publisher background and logo stored locally?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we get it from publisher API. Example of the url https://rewards-stg.bravesoftware.com/P5RxjtP44tJnVNeR9nNCLmgX. In this PR we have both of them disabled and we will fix this in the follow up, because you can't do requests outside from webui

}

void RewardsDonateDOMHandler::Init() {
Profile* profile = Profile::FromWebUI(web_ui());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as @jumde mentioned the UI should be disabled if RewardsServiceFactory::GetForProfile is null. Any menu items should similarly be disabled

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't see an obvious quick way to disable after the DomHandler::Init phase, so I disabled via the webui constructor, checking IsOffTheRecord. Shows chrome://network-error for now

const base::FilePath::StringType kPublisher_state("publisher_state");
const base::FilePath::StringType kPublisher_info_db("publisher_info_db");
const base::FilePath::StringType kPublishers_list("publishers_list");
const base::FilePath::StringType kPublisher_state("publisher_state");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these indented here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

const char kBraveNewTabJS[] = "brave_new_tab.js";
const char kBraveUIWelcomeURL[] = "chrome://welcome/";
const char kBraveUIRewardsURL[] = "chrome://rewards/";
const char kBraveUIAdblockURL[] = "chrome://adblock/";
const char kBraveUIDonateURL[] = "chrome://donate/";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is direct navigation to chrome://donate expected?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an easy way to block this? Right now it errors because it doesn't get any JSON input args, and displays fallback copy. Either way, I talked with @NejcZdovc and we'll make sure the webui doesn't display anything if navigated to in a tab.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc: @bridiver ^

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, it's only possible in non-OffTheRecord profiles and is non-functional

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e. I blocked it

Use ConstrainedWebDialogUI instead of regular WebUI in order to gain message passing for incoming arguments and dialog-closing function.
Stub content for demonstration - to be replaced with content from brave-ui.
Expose `donateToSite` to `chrome.braveRewards` which accepts tabId and publisherKey
Pass publisherKey to chrome://donate WebUI page
Read publisher key in donate JS and write to html output
@NejcZdovc NejcZdovc changed the title [WIP] Donate dialog Donate dialog Oct 11, 2018
@NejcZdovc
Copy link
Contributor

I see that security review was closed and all issues where addressed. If we missed anything @bridiver @jumde please ping me and I will create follow ups.

@NejcZdovc NejcZdovc merged commit a16f674 into master Oct 12, 2018
@NejcZdovc NejcZdovc deleted the donation-dialog branch October 12, 2018 05:51
@NejcZdovc
Copy link
Contributor

NejcZdovc commented Oct 12, 2018

master a16f674
0.56.x 8405e0b
0.55.x 7d209e9

NejcZdovc added a commit that referenced this pull request Oct 12, 2018
NejcZdovc added a commit that referenced this pull request Oct 12, 2018
@bbondy bbondy added this to the 0.55.x - Release milestone Jan 14, 2019
NejcZdovc pushed a commit that referenced this pull request Sep 19, 2019
…eight with normal DOM layout flow instead of fixed position as per #556
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Site banner
5 participants