Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1169)

Side by Side Diff: chrome/browser/translate/chrome_translate_client.h

Issue 2066483004: [Wait to be closed] [Translate] Migrate IPCs to Mojo interfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ensure TranslateCallback get run Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_TRANSLATE_CHROME_TRANSLATE_CLIENT_H_ 5 #ifndef CHROME_BROWSER_TRANSLATE_CHROME_TRANSLATE_CLIENT_H_
6 #define CHROME_BROWSER_TRANSLATE_CHROME_TRANSLATE_CLIENT_H_ 6 #define CHROME_BROWSER_TRANSLATE_CHROME_TRANSLATE_CLIENT_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "chrome/browser/ui/translate/translate_bubble_model.h" 12 #include "chrome/browser/ui/translate/translate_bubble_model.h"
13 #include "components/translate/content/browser/content_translate_driver.h" 13 #include "components/translate/content/browser/content_translate_driver_impl.h"
14 #include "components/translate/core/browser/translate_client.h" 14 #include "components/translate/core/browser/translate_client.h"
15 #include "components/translate/core/browser/translate_step.h" 15 #include "components/translate/core/browser/translate_step.h"
16 #include "components/translate/core/common/translate_errors.h" 16 #include "components/translate/core/common/translate_errors.h"
17 #include "content/public/browser/web_contents_observer.h" 17 #include "content/public/browser/web_contents_observer.h"
18 #include "content/public/browser/web_contents_user_data.h" 18 #include "content/public/browser/web_contents_user_data.h"
19 19
20 namespace content { 20 namespace content {
21 class BrowserContext; 21 class BrowserContext;
22 class WebContents; 22 class WebContents;
23 } // namespace content 23 } // namespace content
24 24
25 namespace test { 25 namespace test {
26 class ScopedCLDDynamicDataHarness; 26 class ScopedCLDDynamicDataHarness;
27 } // namespace test 27 } // namespace test
28 28
29 class PrefService; 29 class PrefService;
30 30
31 namespace translate { 31 namespace translate {
32 class LanguageState; 32 class LanguageState;
33 class TranslateAcceptLanguages; 33 class TranslateAcceptLanguages;
34 class TranslatePrefs; 34 class TranslatePrefs;
35 class TranslateManager; 35 class TranslateManager;
36 } // namespace translate 36 } // namespace translate
37 37
38 class ChromeTranslateClient 38 class ChromeTranslateClient
39 : public translate::TranslateClient, 39 : public translate::TranslateClient,
40 public translate::ContentTranslateDriver::Observer, 40 public translate::ContentTranslateDriverImpl::Observer,
41 public content::WebContentsObserver, 41 public content::WebContentsObserver,
42 public content::WebContentsUserData<ChromeTranslateClient> { 42 public content::WebContentsUserData<ChromeTranslateClient> {
43 public: 43 public:
44 ~ChromeTranslateClient() override; 44 ~ChromeTranslateClient() override;
45 45
46 // Gets the LanguageState associated with the page. 46 // Gets the LanguageState associated with the page.
47 translate::LanguageState& GetLanguageState(); 47 translate::LanguageState& GetLanguageState();
48 48
49 // Returns the ContentTranslateDriver instance associated with this 49 // Returns the ContentTranslateDriverImpl instance associated with this
50 // WebContents. 50 // WebContents.
51 translate::ContentTranslateDriver& translate_driver() { 51 translate::ContentTranslateDriverImpl& translate_driver() {
52 return translate_driver_; 52 return translate_driver_;
53 } 53 }
54 54
55 // Helper method to return a new TranslatePrefs instance. 55 // Helper method to return a new TranslatePrefs instance.
56 static std::unique_ptr<translate::TranslatePrefs> CreateTranslatePrefs( 56 static std::unique_ptr<translate::TranslatePrefs> CreateTranslatePrefs(
57 PrefService* prefs); 57 PrefService* prefs);
58 58
59 // Helper method to return the TranslateAcceptLanguages instance associated 59 // Helper method to return the TranslateAcceptLanguages instance associated
60 // with |browser_context|. 60 // with |browser_context|.
61 static translate::TranslateAcceptLanguages* GetTranslateAcceptLanguages( 61 static translate::TranslateAcceptLanguages* GetTranslateAcceptLanguages(
62 content::BrowserContext* browser_context); 62 content::BrowserContext* browser_context);
63 63
64 // Helper method to return the TranslateManager instance associated with 64 // Helper method to return the TranslateManager instance associated with
65 // |web_contents|, or NULL if there is no such associated instance. 65 // |web_contents|, or NULL if there is no such associated instance.
66 static translate::TranslateManager* GetManagerFromWebContents( 66 static translate::TranslateManager* GetManagerFromWebContents(
67 content::WebContents* web_contents); 67 content::WebContents* web_contents);
68 68
69 // Gets |source| and |target| language for translation. 69 // Gets |source| and |target| language for translation.
70 static void GetTranslateLanguages(content::WebContents* web_contents, 70 static void GetTranslateLanguages(content::WebContents* web_contents,
71 std::string* source, 71 std::string* source,
72 std::string* target); 72 std::string* target);
73 73
74 static void BindContentTranslateDriver(
Anand Mistry (off Chromium) 2016/07/12 07:17:09 This deserves a comment. At the very least to be c
leonhsl(Using Gerrit) 2016/07/12 10:15:09 Acknowledged.
75 content::RenderFrameHost* render_frame_host,
76 translate::mojom::ContentTranslateDriverRequest request);
77
74 // Gets the associated TranslateManager. 78 // Gets the associated TranslateManager.
75 translate::TranslateManager* GetTranslateManager(); 79 translate::TranslateManager* GetTranslateManager();
76 80
77 // Gets the associated WebContents. Returns NULL if the WebContents is being 81 // Gets the associated WebContents. Returns NULL if the WebContents is being
78 // destroyed. 82 // destroyed.
79 content::WebContents* GetWebContents(); 83 content::WebContents* GetWebContents();
80 84
81 // TranslateClient implementation. 85 // TranslateClient implementation.
82 translate::TranslateDriver* GetTranslateDriver() override; 86 translate::TranslateDriver* GetTranslateDriver() override;
83 PrefService* GetPrefs() override; 87 PrefService* GetPrefs() override;
84 std::unique_ptr<translate::TranslatePrefs> GetTranslatePrefs() override; 88 std::unique_ptr<translate::TranslatePrefs> GetTranslatePrefs() override;
85 translate::TranslateAcceptLanguages* GetTranslateAcceptLanguages() override; 89 translate::TranslateAcceptLanguages* GetTranslateAcceptLanguages() override;
86 int GetInfobarIconID() const override; 90 int GetInfobarIconID() const override;
87 #if !defined(USE_AURA) 91 #if !defined(USE_AURA)
88 std::unique_ptr<infobars::InfoBar> CreateInfoBar( 92 std::unique_ptr<infobars::InfoBar> CreateInfoBar(
89 std::unique_ptr<translate::TranslateInfoBarDelegate> delegate) 93 std::unique_ptr<translate::TranslateInfoBarDelegate> delegate)
90 const override; 94 const override;
91 #endif 95 #endif
92 void ShowTranslateUI(translate::TranslateStep step, 96 void ShowTranslateUI(translate::TranslateStep step,
93 const std::string& source_language, 97 const std::string& source_language,
94 const std::string& target_language, 98 const std::string& target_language,
95 translate::TranslateErrors::Type error_type, 99 translate::TranslateErrors::Type error_type,
96 bool triggered_from_menu) override; 100 bool triggered_from_menu) override;
97 bool IsTranslatableURL(const GURL& url) override; 101 bool IsTranslatableURL(const GURL& url) override;
98 void ShowReportLanguageDetectionErrorUI(const GURL& report_url) override; 102 void ShowReportLanguageDetectionErrorUI(const GURL& report_url) override;
99 103
100 // ContentTranslateDriver::Observer implementation. 104 // ContentTranslateDriverImpl::Observer implementation.
101 void OnLanguageDetermined( 105 void OnLanguageDetermined(
102 const translate::LanguageDetectionDetails& details) override; 106 const translate::LanguageDetectionDetails& details) override;
103 void OnPageTranslated(const std::string& original_lang, 107 void OnPageTranslated(const std::string& original_lang,
104 const std::string& translated_lang, 108 const std::string& translated_lang,
105 translate::TranslateErrors::Type error_type) override; 109 translate::TranslateErrors::Type error_type) override;
106 110
107 private: 111 private:
108 explicit ChromeTranslateClient(content::WebContents* web_contents); 112 explicit ChromeTranslateClient(content::WebContents* web_contents);
109 friend class content::WebContentsUserData<ChromeTranslateClient>; 113 friend class content::WebContentsUserData<ChromeTranslateClient>;
110 114
111 // content::WebContentsObserver implementation. 115 // content::WebContentsObserver implementation.
112 void WebContentsDestroyed() override; 116 void WebContentsDestroyed() override;
113 117
114 // Shows the translate bubble. 118 // Shows the translate bubble.
115 void ShowBubble(translate::TranslateStep step, 119 void ShowBubble(translate::TranslateStep step,
116 translate::TranslateErrors::Type error_type); 120 translate::TranslateErrors::Type error_type);
117 121
118 translate::ContentTranslateDriver translate_driver_; 122 translate::ContentTranslateDriverImpl translate_driver_;
119 std::unique_ptr<translate::TranslateManager> translate_manager_; 123 std::unique_ptr<translate::TranslateManager> translate_manager_;
120 124
121 DISALLOW_COPY_AND_ASSIGN(ChromeTranslateClient); 125 DISALLOW_COPY_AND_ASSIGN(ChromeTranslateClient);
122 }; 126 };
123 127
124 #endif // CHROME_BROWSER_TRANSLATE_CHROME_TRANSLATE_CLIENT_H_ 128 #endif // CHROME_BROWSER_TRANSLATE_CHROME_TRANSLATE_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698