Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / translate / translate_bubble_model_impl.cc
blob9d4432129157a6ed7897880fddfc1b8c349b9e0c
1 // Copyright 2013 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.
5 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h"
7 #include "chrome/browser/tab_contents/language_state.h"
8 #include "chrome/browser/translate/translate_tab_helper.h"
9 #include "chrome/browser/translate/translate_ui_delegate.h"
11 TranslateBubbleModelImpl::TranslateBubbleModelImpl(
12 TranslateBubbleModel::ViewState view_type,
13 scoped_ptr<TranslateUIDelegate> ui_delegate)
14 : ui_delegate_(ui_delegate.Pass()),
15 view_state_transition_(view_type) {
18 TranslateBubbleModelImpl::~TranslateBubbleModelImpl() {
21 TranslateBubbleModel::ViewState TranslateBubbleModelImpl::GetViewState() const {
22 return view_state_transition_.view_state();
25 void TranslateBubbleModelImpl::SetViewState(
26 TranslateBubbleModel::ViewState view_state) {
27 view_state_transition_.SetViewState(view_state);
30 void TranslateBubbleModelImpl::ShowError(TranslateErrors::Type error_type) {
31 ui_delegate_->OnErrorShown(error_type);
34 void TranslateBubbleModelImpl::GoBackFromAdvanced() {
35 view_state_transition_.GoBackFromAdvanced();
38 int TranslateBubbleModelImpl::GetNumberOfLanguages() const {
39 return ui_delegate_->GetNumberOfLanguages();
42 base::string16 TranslateBubbleModelImpl::GetLanguageNameAt(int index) const {
43 return ui_delegate_->GetLanguageNameAt(index);
46 int TranslateBubbleModelImpl::GetOriginalLanguageIndex() const {
47 return ui_delegate_->GetOriginalLanguageIndex();
50 void TranslateBubbleModelImpl::UpdateOriginalLanguageIndex(int index) {
51 ui_delegate_->UpdateOriginalLanguageIndex(index);
54 int TranslateBubbleModelImpl::GetTargetLanguageIndex() const {
55 return ui_delegate_->GetTargetLanguageIndex();
58 void TranslateBubbleModelImpl::UpdateTargetLanguageIndex(int index) {
59 ui_delegate_->UpdateTargetLanguageIndex(index);
62 void TranslateBubbleModelImpl::SetNeverTranslateLanguage(bool value) {
63 ui_delegate_->SetLanguageBlocked(value);
66 void TranslateBubbleModelImpl::SetNeverTranslateSite(bool value) {
67 ui_delegate_->SetSiteBlacklist(value);
70 bool TranslateBubbleModelImpl::ShouldAlwaysTranslate() const {
71 return ui_delegate_->ShouldAlwaysTranslate();
74 void TranslateBubbleModelImpl::SetAlwaysTranslate(bool value) {
75 ui_delegate_->SetAlwaysTranslate(value);
78 void TranslateBubbleModelImpl::Translate() {
79 ui_delegate_->Translate();
82 void TranslateBubbleModelImpl::RevertTranslation() {
83 ui_delegate_->RevertTranslation();
86 void TranslateBubbleModelImpl::TranslationDeclined(bool explicitly_closed) {
87 ui_delegate_->TranslationDeclined(explicitly_closed);
90 bool TranslateBubbleModelImpl::IsPageTranslatedInCurrentLanguages() const {
91 content::WebContents* web_contents = ui_delegate_->web_contents();
92 TranslateTabHelper* translate_tab_helper =
93 TranslateTabHelper::FromWebContents(web_contents);
94 LanguageState& language_state = translate_tab_helper->language_state();
95 return ui_delegate_->GetOriginalLanguageCode() ==
96 language_state.original_language() &&
97 ui_delegate_->GetTargetLanguageCode() ==
98 language_state.current_language();