[email protected] | 3155c527 | 2014-01-21 12:38:12 | [diff] [blame] | 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 "content/public/browser/navigation_controller.h" |
| 9 | #include "content/public/browser/navigation_details.h" |
| 10 | #include "content/public/browser/navigation_entry.h" |
| 11 | |
| 12 | ContentTranslateDriver::ContentTranslateDriver( |
| 13 | content::NavigationController* nav_controller) |
| 14 | : navigation_controller_(nav_controller), |
| 15 | language_state_(this), |
| 16 | observer_(NULL) { |
| 17 | DCHECK(navigation_controller_); |
| 18 | } |
| 19 | |
| 20 | ContentTranslateDriver::~ContentTranslateDriver() {} |
| 21 | |
| 22 | void ContentTranslateDriver::DidNavigate( |
| 23 | const content::LoadCommittedDetails& details) { |
| 24 | const bool reload = |
| 25 | details.entry->GetTransitionType() == content::PAGE_TRANSITION_RELOAD || |
| 26 | details.type == content::NAVIGATION_TYPE_SAME_PAGE; |
| 27 | language_state_.DidNavigate( |
| 28 | details.is_in_page, details.is_main_frame, reload); |
| 29 | } |
| 30 | |
| 31 | // TranslateDriver methods |
| 32 | |
| 33 | bool ContentTranslateDriver::IsLinkNavigation() { |
| 34 | return navigation_controller_ && navigation_controller_->GetActiveEntry() && |
| 35 | navigation_controller_->GetActiveEntry()->GetTransitionType() == |
| 36 | content::PAGE_TRANSITION_LINK; |
| 37 | } |
| 38 | |
| 39 | void ContentTranslateDriver::OnTranslateEnabledChanged() { |
| 40 | if (observer_) { |
| 41 | content::WebContents* web_contents = |
| 42 | navigation_controller_->GetWebContents(); |
| 43 | observer_->OnTranslateEnabledChanged(web_contents); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | void ContentTranslateDriver::OnIsPageTranslatedChanged() { |
| 48 | if (observer_) { |
| 49 | content::WebContents* web_contents = |
| 50 | navigation_controller_->GetWebContents(); |
| 51 | observer_->OnIsPageTranslatedChanged(web_contents); |
| 52 | } |
| 53 | } |
[email protected] | 7aa5fe5a | 2014-03-18 15:42:57 | [diff] [blame^] | 54 | |
| 55 | LanguageState& ContentTranslateDriver::GetLanguageState() { |
| 56 | return language_state_; |
| 57 | } |