Commit a2697205 authored by Sebastien Lalancette's avatar Sebastien Lalancette Committed by Chromium LUCI CQ

[SH-iOS] Disable LinkToText For PDF Documents

Prevent showing the Link-to-text action when the current page is not
HTML and also when, for some reason, the main frame cannot execute
JavaScript.

Bug: 1157053
Change-Id: I11702dd3d91d204b9b80f686c29ac4640c84ea88
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2585836
Commit-Queue: Sebastien Lalancette <seblalancette@chromium.org>
Commit-Queue: sebsg <sebsg@chromium.org>
Reviewed-by: default avatarsebsg <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836129}
parent 782fc921
......@@ -41,10 +41,15 @@ void LinkToTextTabHelper::CreateForWebState(web::WebState* web_state) {
bool LinkToTextTabHelper::ShouldOffer() {
// TODO(crbug.com/1134708): add more checks, like text only.
return true;
web::WebFrame* main_frame =
web_state_->GetWebFramesManager()->GetMainWebFrame();
return web_state_->ContentIsHTML() && main_frame &&
main_frame->CanCallJavaScriptFunction();
}
void LinkToTextTabHelper::GetLinkToText(LinkToTextCallback callback) {
DCHECK(ShouldOffer());
link_generation_timer_ = std::make_unique<base::ElapsedTimer>();
base::WeakPtr<LinkToTextTabHelper> weak_ptr = weak_ptr_factory_.GetWeakPtr();
......
......@@ -192,11 +192,28 @@ class LinkToTextMediatorTest : public PlatformTest {
id mocked_consumer_;
};
// Tests that the mediator should, currently, always offer link to text.
// Tests that the mediator should offer link to text to HTML pages that can
// call JavaScript functions.
TEST_F(LinkToTextMediatorTest, ShouldOfferLinkToText) {
// By default, all fake instances return the right values.
EXPECT_TRUE([mediator_ shouldOfferLinkToText]);
}
// Tests that the mediator should not offer link to text to pages that are not
// HTML.
TEST_F(LinkToTextMediatorTest, ShouldNotOfferLinkToTextNotHTML) {
web_state_->SetContentIsHTML(false);
EXPECT_FALSE([mediator_ shouldOfferLinkToText]);
}
// Tests that the mediator should not offer link to text when, for some reason,
// the main frame cannot call JavaScript functions.
TEST_F(LinkToTextMediatorTest,
ShouldNotOfferLinkToTextCannotExecuteJavaScript) {
main_frame_->set_can_call_function(false);
EXPECT_FALSE([mediator_ shouldOfferLinkToText]);
}
// Tests that the shareHighlight command is triggered with the right parameters
// when the view is not zoomed in.
TEST_F(LinkToTextMediatorTest, HandleLinkToTextSelectionTriggersCommandNoZoom) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment