1// Copyright (c) 2012 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 "chrome/browser/tab_contents/spelling_bubble_model.h" 6 7#include "base/logging.h" 8#include "base/prefs/pref_service.h" 9#include "chrome/browser/profiles/profile.h" 10#include "chrome/common/pref_names.h" 11#include "chrome/common/url_constants.h" 12#include "content/public/browser/web_contents.h" 13#include "grit/generated_resources.h" 14#include "grit/theme_resources.h" 15#include "ui/base/l10n/l10n_util.h" 16#include "ui/base/resource/resource_bundle.h" 17#include "ui/gfx/image/image.h" 18 19using content::OpenURLParams; 20using content::Referrer; 21using content::WebContents; 22 23SpellingBubbleModel::SpellingBubbleModel(Profile* profile, 24 WebContents* web_contents, 25 bool include_autocorrect) 26 : profile_(profile), 27 web_contents_(web_contents), 28 include_autocorrect_(include_autocorrect) { 29} 30 31SpellingBubbleModel::~SpellingBubbleModel() { 32} 33 34base::string16 SpellingBubbleModel::GetTitle() const { 35 return l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE); 36} 37 38base::string16 SpellingBubbleModel::GetMessageText() const { 39 return l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_TEXT); 40} 41 42gfx::Image* SpellingBubbleModel::GetIcon() const { 43 return &ResourceBundle::GetSharedInstance().GetImageNamed( 44 IDR_PRODUCT_LOGO_16); 45} 46 47base::string16 SpellingBubbleModel::GetButtonLabel(BubbleButton button) const { 48 return l10n_util::GetStringUTF16(button == BUTTON_OK ? 49 IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_ENABLE : 50 IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_DISABLE); 51} 52 53void SpellingBubbleModel::Accept() { 54 SetPref(true); 55} 56 57void SpellingBubbleModel::Cancel() { 58 SetPref(false); 59} 60 61base::string16 SpellingBubbleModel::GetLinkText() const { 62 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); 63} 64 65void SpellingBubbleModel::LinkClicked() { 66 OpenURLParams params( 67 GURL(chrome::kPrivacyLearnMoreURL), Referrer(), NEW_FOREGROUND_TAB, 68 content::PAGE_TRANSITION_LINK, false); 69 web_contents_->OpenURL(params); 70} 71 72void SpellingBubbleModel::SetPref(bool enabled) { 73 PrefService* pref = profile_->GetPrefs(); 74 DCHECK(pref); 75 pref->SetBoolean(prefs::kSpellCheckUseSpellingService, enabled); 76 if (include_autocorrect_) 77 pref->SetBoolean(prefs::kEnableAutoSpellCorrect, enabled); 78} 79