NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / translate / translate_tab_helper.h
blob3c35d4aacf387ab11cdacf30e5a5f6aad8b72a76
1 // Copyright 2011 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 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/ui/translate/translate_bubble_model.h"
12 #include "components/translate/content/browser/content_translate_driver.h"
13 #include "components/translate/core/common/translate_errors.h"
14 #include "content/public/browser/web_contents_observer.h"
15 #include "content/public/browser/web_contents_user_data.h"
17 namespace content {
18 class BrowserContext;
19 class WebContents;
22 struct LanguageDetectionDetails;
23 class PrefService;
24 class TranslateAcceptLanguages;
25 class TranslatePrefs;
27 class TranslateTabHelper
28 : public content::WebContentsObserver,
29 public content::WebContentsUserData<TranslateTabHelper> {
30 public:
31 virtual ~TranslateTabHelper();
33 // Gets the LanguageState associated with the page.
34 LanguageState& GetLanguageState();
36 // Returns the ContentTranslateDriver instance associated with this
37 // WebContents.
38 ContentTranslateDriver& translate_driver() { return translate_driver_; }
40 // Helper method to return a new TranslatePrefs instance.
41 static scoped_ptr<TranslatePrefs> CreateTranslatePrefs(PrefService* prefs);
43 // Helper method to return the TranslateAcceptLanguages instance associated
44 // with |browser_context|.
45 static TranslateAcceptLanguages* GetTranslateAcceptLanguages(
46 content::BrowserContext* browser_context);
48 // Denotes which state the user is in with respect to translate.
49 enum TranslateStep {
50 BEFORE_TRANSLATE,
51 TRANSLATING,
52 AFTER_TRANSLATE,
53 TRANSLATE_ERROR
56 // Called when the embedder should present UI to the user corresponding to the
57 // user's current |step|.
58 void ShowTranslateUI(TranslateStep step,
59 content::WebContents* web_contents,
60 const std::string source_language,
61 const std::string target_language,
62 TranslateErrors::Type error_type);
64 private:
65 explicit TranslateTabHelper(content::WebContents* web_contents);
66 friend class content::WebContentsUserData<TranslateTabHelper>;
68 // content::WebContentsObserver implementation.
69 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
70 virtual void DidNavigateAnyFrame(
71 const content::LoadCommittedDetails& details,
72 const content::FrameNavigateParams& params) OVERRIDE;
74 void OnLanguageDetermined(const LanguageDetectionDetails& details,
75 bool page_needs_translation);
76 void OnPageTranslated(int32 page_id,
77 const std::string& original_lang,
78 const std::string& translated_lang,
79 TranslateErrors::Type error_type);
81 // Shows the translate bubble.
82 void ShowBubble(content::WebContents* web_contents,
83 TranslateStep step,
84 TranslateErrors::Type error_type);
86 ContentTranslateDriver translate_driver_;
88 DISALLOW_COPY_AND_ASSIGN(TranslateTabHelper);
91 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_