Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / translate / chrome_translate_client.h
blob1d2a7ee166fa4372b4e2c51804ebc6fd38c86a27
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.
5 #ifndef CHROME_BROWSER_TRANSLATE_CHROME_TRANSLATE_CLIENT_H_
6 #define CHROME_BROWSER_TRANSLATE_CHROME_TRANSLATE_CLIENT_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/browser_cld_data_provider.h"
13 #include "components/translate/content/browser/content_translate_driver.h"
14 #include "components/translate/core/browser/translate_client.h"
15 #include "components/translate/core/browser/translate_step.h"
16 #include "components/translate/core/common/translate_errors.h"
17 #include "content/public/browser/web_contents_observer.h"
18 #include "content/public/browser/web_contents_user_data.h"
20 namespace content {
21 class BrowserContext;
22 class WebContents;
23 } // namespace content
25 namespace test {
26 class ScopedCLDDynamicDataHarness;
27 } // namespace test
29 class PrefService;
31 namespace translate {
32 class LanguageState;
33 class TranslateAcceptLanguages;
34 class TranslatePrefs;
35 class TranslateManager;
36 } // namespace translate
38 class ChromeTranslateClient
39 : public translate::TranslateClient,
40 public translate::ContentTranslateDriver::Observer,
41 public content::WebContentsObserver,
42 public content::WebContentsUserData<ChromeTranslateClient> {
43 public:
44 ~ChromeTranslateClient() override;
46 // Gets the LanguageState associated with the page.
47 translate::LanguageState& GetLanguageState();
49 // Returns the ContentTranslateDriver instance associated with this
50 // WebContents.
51 translate::ContentTranslateDriver& translate_driver() {
52 return translate_driver_;
55 // Helper method to return a new TranslatePrefs instance.
56 static scoped_ptr<translate::TranslatePrefs> CreateTranslatePrefs(
57 PrefService* prefs);
59 // Helper method to return the TranslateAcceptLanguages instance associated
60 // with |browser_context|.
61 static translate::TranslateAcceptLanguages* GetTranslateAcceptLanguages(
62 content::BrowserContext* browser_context);
64 // Helper method to return the TranslateManager instance associated with
65 // |web_contents|, or NULL if there is no such associated instance.
66 static translate::TranslateManager* GetManagerFromWebContents(
67 content::WebContents* web_contents);
69 // Gets |source| and |target| language for translation.
70 static void GetTranslateLanguages(content::WebContents* web_contents,
71 std::string* source,
72 std::string* target);
74 // Gets the associated TranslateManager.
75 translate::TranslateManager* GetTranslateManager();
77 // Gets the associated WebContents. Returns NULL if the WebContents is being
78 // destroyed.
79 content::WebContents* GetWebContents();
81 // TranslateClient implementation.
82 translate::TranslateDriver* GetTranslateDriver() override;
83 PrefService* GetPrefs() override;
84 scoped_ptr<translate::TranslatePrefs> GetTranslatePrefs() override;
85 translate::TranslateAcceptLanguages* GetTranslateAcceptLanguages() override;
86 int GetInfobarIconID() const override;
87 scoped_ptr<infobars::InfoBar> CreateInfoBar(
88 scoped_ptr<translate::TranslateInfoBarDelegate> delegate) const override;
89 void ShowTranslateUI(translate::TranslateStep step,
90 const std::string source_language,
91 const std::string target_language,
92 translate::TranslateErrors::Type error_type,
93 bool triggered_from_menu) override;
94 bool IsTranslatableURL(const GURL& url) override;
95 void ShowReportLanguageDetectionErrorUI(const GURL& report_url) override;
97 // ContentTranslateDriver::Observer implementation.
98 void OnLanguageDetermined(
99 const translate::LanguageDetectionDetails& details) override;
100 void OnPageTranslated(const std::string& original_lang,
101 const std::string& translated_lang,
102 translate::TranslateErrors::Type error_type) override;
104 private:
105 explicit ChromeTranslateClient(content::WebContents* web_contents);
106 friend class content::WebContentsUserData<ChromeTranslateClient>;
108 // content::WebContentsObserver implementation.
109 bool OnMessageReceived(const IPC::Message& message) override;
110 void WebContentsDestroyed() override;
112 // Shows the translate bubble.
113 void ShowBubble(translate::TranslateStep step,
114 translate::TranslateErrors::Type error_type);
116 translate::ContentTranslateDriver translate_driver_;
117 scoped_ptr<translate::TranslateManager> translate_manager_;
119 // Provides CLD data for this process.
120 scoped_ptr<translate::BrowserCldDataProvider> cld_data_provider_;
122 DISALLOW_COPY_AND_ASSIGN(ChromeTranslateClient);
125 #endif // CHROME_BROWSER_TRANSLATE_CHROME_TRANSLATE_CLIENT_H_