Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/translate/content/browser/content_translate_driver.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "components/translate/content/browser/language_state_observer.h" | |
| 9 #include "content/public/browser/navigation_controller.h" | |
| 10 #include "content/public/browser/navigation_details.h" | |
| 11 #include "content/public/browser/navigation_entry.h" | |
| 12 | |
| 13 ContentTranslateDriver::ContentTranslateDriver( | |
| 14 content::NavigationController* nav_controller) | |
| 15 : navigation_controller_(nav_controller), | |
| 16 language_state_(this), | |
| 17 language_state_observer_(NULL) { | |
| 18 DCHECK(navigation_controller_); | |
| 19 } | |
| 20 | |
| 21 ContentTranslateDriver::~ContentTranslateDriver() {} | |
| 22 | |
| 23 LanguageState& ContentTranslateDriver::GetLanguageState() { | |
| 24 return language_state_; | |
| 25 } | |
| 26 | |
| 27 void ContentTranslateDriver::SetLanguageStateObserver( | |
| 28 LanguageStateObserver* observer) { | |
| 29 language_state_observer_ = observer; | |
|
MAD
2014/01/20 16:12:25
Since this is just a simple mutator, it could also
| |
| 30 } | |
| 31 | |
| 32 void ContentTranslateDriver::DidNavigate( | |
| 33 const content::LoadCommittedDetails& details) { | |
| 34 const bool reload = | |
| 35 details.entry->GetTransitionType() == content::PAGE_TRANSITION_RELOAD || | |
| 36 details.type == content::NAVIGATION_TYPE_SAME_PAGE; | |
| 37 language_state_.DidNavigate( | |
| 38 details.is_in_page, details.is_main_frame, reload); | |
| 39 } | |
| 40 | |
| 41 // TranslateDriver methods | |
| 42 | |
| 43 bool ContentTranslateDriver::IsLinkNavigation() { | |
| 44 return navigation_controller_ && navigation_controller_->GetActiveEntry() && | |
| 45 navigation_controller_->GetActiveEntry()->GetTransitionType() == | |
| 46 content::PAGE_TRANSITION_LINK; | |
| 47 } | |
| 48 | |
| 49 void ContentTranslateDriver::OnTranslateEnabledChanged() { | |
| 50 if (language_state_observer_) { | |
| 51 content::WebContents* web_contents = | |
| 52 navigation_controller_->GetWebContents(); | |
| 53 language_state_observer_->OnTranslateEnabledChanged(web_contents); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 void ContentTranslateDriver::OnIsPageTranslatedChanged() { | |
| 58 if (language_state_observer_) { | |
| 59 content::WebContents* web_contents = | |
| 60 navigation_controller_->GetWebContents(); | |
| 61 language_state_observer_->OnIsPageTranslatedChanged(web_contents); | |
| 62 } | |
| 63 } | |
| OLD | NEW |