Commit 1c5a8e68 authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Call StartLanguageDetection() on init

WebStateObserver::PageLoaded triggers this call in
LanguageDetectionController, but it can be executed while a preloaded
WebState is finished in the background. Then, when that WebState
is swapped out as the active WebState, StartLanguageDetection()
will never be called in LanguageDetectionController. Thus,
the infobar never shows. Adding the call to the init method when
the WebState is swapped solves the issue.

Fixed: 947482
Change-Id: If6b6a77711039835596374bdc6121ece4642987c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095355
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avataranthonyvd <anthonyvd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751388}
parent ab0d45a4
......@@ -63,6 +63,7 @@ source_set("unit_tests") {
deps = [
":browser",
"//base",
"//base/test:test_support",
"//components/language/ios/browser",
"//components/prefs:test_support",
"//components/resources",
......
......@@ -45,6 +45,9 @@ LanguageDetectionController::LanguageDetectionController(
DCHECK(js_manager_);
translate_enabled_.Init(prefs::kOfferTranslateEnabled, prefs);
// Attempt to detect language since preloaded tabs will not execute
// WebStateObserver::PageLoaded.
StartLanguageDetection();
web_state_->AddObserver(this);
subscription_ = web_state_->AddScriptCommandCallback(
base::BindRepeating(&LanguageDetectionController::OnTextCaptured,
......
......@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/task_environment.h"
#include "components/language/ios/browser/ios_language_detection_tab_helper.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
......@@ -78,6 +79,7 @@ class LanguageDetectionControllerTest
web::TestWebState web_state_;
std::unique_ptr<LanguageDetectionController> controller_;
std::unique_ptr<LanguageDetectionDetails> details_;
base::test::TaskEnvironment environment_;
void OnLanguageDetermined(const LanguageDetectionDetails& details) override {
details_ = std::make_unique<LanguageDetectionDetails>(details);
......
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