Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(800)

Unified Diff: components/translate/core/browser/language_state.cc

Issue 133273029: Move LanguageState to the translate component (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update BUILD.gn Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/translate/core/browser/language_state.cc
diff --git a/chrome/browser/tab_contents/language_state.cc b/components/translate/core/browser/language_state.cc
similarity index 65%
rename from chrome/browser/tab_contents/language_state.cc
rename to components/translate/core/browser/language_state.cc
index 90296a8506d7b45186e0b23fa41065548207668e..12ce1fdb1af77b2bc7c011085a30f1d366a1c62c 100644
--- a/chrome/browser/tab_contents/language_state.cc
+++ b/components/translate/core/browser/language_state.cc
@@ -1,40 +1,33 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/tab_contents/language_state.h"
+#include "components/translate/core/browser/language_state.h"
-#include "chrome/browser/tab_contents/language_state_observer.h"
-#include "content/public/browser/navigation_controller.h"
-#include "content/public/browser/navigation_details.h"
-#include "content/public/browser/navigation_entry.h"
-#include "content/public/browser/web_contents.h"
+#include "base/logging.h"
+#include "components/translate/core/browser/translate_driver.h"
-using content::NavigationController;
-
-LanguageState::LanguageState(NavigationController* nav_controller)
+LanguageState::LanguageState(TranslateDriver* driver)
: is_page_translated_(false),
- navigation_controller_(nav_controller),
+ translate_driver_(driver),
page_needs_translation_(false),
translation_pending_(false),
translation_declined_(false),
in_page_navigation_(false),
- translate_enabled_(false),
- observer_(NULL) {
+ translate_enabled_(false) {
+ DCHECK(translate_driver_);
}
LanguageState::~LanguageState() {
}
-void LanguageState::DidNavigate(
- const content::LoadCommittedDetails& details) {
- in_page_navigation_ = details.is_in_page;
- if (in_page_navigation_ || !details.is_main_frame)
+void LanguageState::DidNavigate(bool in_page_navigation,
+ bool is_main_frame,
+ bool reload) {
+ in_page_navigation_ = in_page_navigation;
+ if (in_page_navigation_ || !is_main_frame)
return; // Don't reset our states, the page has not changed.
- bool reload =
- details.entry->GetTransitionType() == content::PAGE_TRANSITION_RELOAD ||
- details.type == content::NAVIGATION_TYPE_SAME_PAGE;
if (reload) {
// We might not get a LanguageDetermined notifications on reloads. Make sure
// to keep the original language and to set current_lang_ so
@@ -79,10 +72,7 @@ bool LanguageState::InTranslateNavigation() const {
!translation_pending_ &&
prev_original_lang_ == original_lang_ &&
prev_original_lang_ != prev_current_lang_ &&
- navigation_controller_ &&
- navigation_controller_->GetActiveEntry() &&
- navigation_controller_->GetActiveEntry()->GetTransitionType() ==
- content::PAGE_TRANSITION_LINK;
+ translate_driver_->IsLinkNavigation();
}
void LanguageState::SetCurrentLanguage(const std::string& language) {
@@ -102,11 +92,7 @@ void LanguageState::SetTranslateEnabled(bool value) {
return;
translate_enabled_ = value;
- if (observer_) {
- content::WebContents* web_contents =
- navigation_controller_->GetWebContents();
- observer_->OnTranslateEnabledChanged(web_contents);
- }
+ translate_driver_->OnTranslateEnabledChanged();
}
bool LanguageState::HasLanguageChanged() const {
@@ -118,11 +104,7 @@ void LanguageState::SetIsPageTranslated(bool value) {
return;
is_page_translated_ = value;
- if (observer_) {
- content::WebContents* web_contents =
- navigation_controller_->GetWebContents();
- observer_->OnIsPageTranslatedChanged(web_contents);
- }
+ translate_driver_->OnIsPageTranslatedChanged();
// With the translation done, the translate feature must be enabled.
if (is_page_translated_)

Powered by Google App Engine
This is Rietveld 408576698