-
Notifications
You must be signed in to change notification settings - Fork 868
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
Speedreader communicate result to tab_helper #9659
Conversation
c0c5559
to
0730123
Compare
std::string value; | ||
}; | ||
|
||
} // anonymous namespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just // namespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
||
} // anonymous namespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just // namespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
offline_pages::OfflinePageInfoHandler::Register(); | ||
#endif | ||
|
||
+ RegisterBraveExtendedInfoHandlers(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put this into BraveBrowserMainParts::PreMainMessageLoopRun
and don't introduce this patch? ChromeBrowserMainParts::PreMainMessageLoopRun
is virtual.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this first.
If I register before, then I miss the call to sessions::ContentSerializedNavigationDriver::SetInstance(..)
. Happens here.
If I register after calling ChromeBrowserMainParts::PreMainMessageLoopRun
, it introduces a very subtle bug where the tabs are restored before we register our handler. So no persisted data ever gets written to the NavigationEntry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about putting it into PreBrowserStart
? It's very close to the current position.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that worked. patch + chromium_src deleted. thanks :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good if we can DCHECK
ensuring Chromium doesn't move this logic around. If the registration happens after any serialized navigation entries are loaded, then it's a no-op. Could introduce a silent bug.
a2f4d69
to
49d5cdf
Compare
2bb9213
to
47b9a4d
Compare
void SpeedreaderExtendedInfoHandler::Register() { | ||
auto* handler = new SpeedreaderExtendedInfoHandler(); | ||
sessions::ContentSerializedNavigationDriver::GetInstance() | ||
->RegisterExtendedInfoHandler(kSpeedreaderKey, base::WrapUnique(handler)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just use make_unique to create the unique_ptr and then std::move
to pass it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
||
// This class is meant to persist data to a content::NavigationEntry so that | ||
// distilled pages will be recognized on a restored session. | ||
class SpeedreaderExtendedInfoHandler : public sessions::ExtendedInfoHandler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don't you put this class to components/speedreader
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea. moved it there, along with the speedreader::DistillState
enum. This will be helpful later when we talk to renderer
SpeedreaderExtendedInfoHandler() = default; | ||
~SpeedreaderExtendedInfoHandler() override = default; | ||
|
||
std::string GetExtendedInfo(content::NavigationEntry* entry) const override; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls add // sessions::ExtendedInfoHandler:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
SpeedreaderExtendedInfoHandler& operator=( | ||
const SpeedreaderExtendedInfoHandler&) = delete; | ||
|
||
SpeedreaderExtendedInfoHandler() = default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commonly, this constructor should be above copy/assignment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
} | ||
|
||
// static | ||
bool SpeedreaderExtendedInfoHandler::IsCachedReaderMode( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would rather return some sort of enum
instead of making identical methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed. good suggestion. this cleaned up a lot of the logic
47b9a4d
to
235a851
Compare
0f7c734
to
21724ae
Compare
// When distillation fails we return the original data. Causes this | ||
// throttle to get deleted. | ||
// | ||
// TODO(iefremov): Is it okay to rely on just this, or should the distill |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, can you please point out when it gets deleted? Probably ok, but I can't quickly find a reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i verified heuristically, which is why i was asking. if the throttle returned the original data (distill failed) that function is never reached.
#ifndef BRAVE_COMPONENTS_SPEEDREADER_SPEEDREADER_RESULT_DELEGATE_H_ | ||
#define BRAVE_COMPONENTS_SPEEDREADER_SPEEDREADER_RESULT_DELEGATE_H_ | ||
|
||
#include "content/public/browser/web_contents_user_data.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
||
#include "content/public/browser/web_contents_user_data.h" | ||
|
||
namespace content { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
std::unique_ptr<speedreader::SpeedReaderThrottle> throttle = | ||
speedreader::SpeedReaderThrottle::MaybeCreateThrottleFor( | ||
g_brave_browser_process->speedreader_rewriter_service(), | ||
HostContentSettingsMapFactory::GetForProfile( | ||
Profile::FromBrowserContext(browser_context)), | ||
request.url, state == DistillState::kSpeedreaderMode, | ||
contents, tab_helper, request.url, check_disabled_sites, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can pass wc_getter
and avoid adding the lifetime helper
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
21724ae
to
c548ea0
Compare
void SpeedreaderTabHelper::OnDistillComplete() { | ||
// Perform a state transition | ||
auto* entry = web_contents()->GetController().GetLastCommittedEntry(); | ||
DCHECK(entry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a discouraged pattern, see https://chromium.googlesource.com/chromium/src/+/HEAD/styleguide/c++/c++.md#check_dcheck_and-notreached
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotcha, fixed
#include <utility> | ||
|
||
#include "base/supports_user_data.h" | ||
#include "components/sessions/content/content_serialized_navigation_driver.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be added to DEPS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
distill_state_ = DistillState::kNone; | ||
} | ||
auto* entry = web_contents()->GetController().GetLastCommittedEntry(); | ||
DCHECK(entry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked other code and it seems we'd better have if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed and also moved to NavigationEntryCommitted
Uses the webcontents to deliver the result to the correct tab helper. We might want to follow this up by having the distiller thread return tuple: struct DistillResult { bool success; std::string buffered_body; }; If success is ever false we can abort the loader.
* Use the DistillState enum in SpeedreaderExtendedInfoHandler to de-duplicate logic. * Move DistillState to speedreader component * Move SpeedreaderExtendedInfoHandler to speedreader component * Pass wc_getter to SpeedreaderThrottle instead of creating the lifetime helper
Previously we were persisting the SpeedreaderExtendedInfoHandler data to the NavigationEntry in OnDistillComplete(). Since OnDistillComplete() is called by the throttle, the navigation entry might not be persisted yet, so the behavior is not defined. On backward navigations we would sometimes persist to the previous navigation entry, causing bugs where pages would incorrectly show up as readable. Since we wait for DidFinishNavigation, we can safely get the last committed navgiation entry.
We add two browser test cases for Speedreader. In these tests Speedreader is enabled. (1) Run a readable page through Speedreader. Close the browser and open it back up. The page should restore as readable. (2) Navigate to a non-readable page, then to a readable page, then do a back navigation. The readable state should not "stick".
7f31be1
to
b81abfe
Compare
b81abfe
to
9b618ed
Compare
CodeQL failure unrelated to the C++ code. It's an HTML blob from the guardian (for testing only) that was already vendored before these changes. I moved the directories around and CI scanned it. Safe to ignore that. |
@@ -27,6 +28,11 @@ namespace { | |||
constexpr char kTestProfileName[] = "TestProfile"; | |||
} // anonymous namespace | |||
|
|||
class TestSpeedreaderResultDelegate : public SpeedreaderResultDelegate { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also it can go the anonymous namespace above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
~SpeedreaderTabHelper() override; | ||
|
||
SpeedreaderTabHelper(const SpeedreaderTabHelper&) = delete; | ||
SpeedreaderTabHelper& operator=(SpeedreaderTabHelper&) = delete; | ||
|
||
// Helper function to return a weak pointer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the method purpose is pretty obvious, not sure if a comment like this is useful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure thing. removed it.
* Use NavigationEntryCommitted() instead of DidNavigationFinish(). We have no guarantees about the next DidNavigationStart() being called first. * Fix throttle unit test * Make several review requests to SpeedreaderBrowserTest
9b618ed
to
c5677c6
Compare
|
Resolves brave/brave-browser#17355
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
,npm run lint
,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan: