OLD | NEW |
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 COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_H_ | 5 #ifndef COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_H_ |
6 #define COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_H_ | 6 #define COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | |
9 #include "components/translate/core/browser/translate_driver.h" | 8 #include "components/translate/core/browser/translate_driver.h" |
10 | 9 |
| 10 #include "components/translate/core/browser/language_state.h" |
| 11 |
11 namespace content { | 12 namespace content { |
| 13 struct LoadCommittedDetails; |
12 class NavigationController; | 14 class NavigationController; |
13 class WebContents; | 15 class WebContents; |
14 } | 16 } |
15 | 17 |
16 // Content implementation of TranslateDriver. | 18 // Content implementation of TranslateDriver. |
17 class ContentTranslateDriver : public TranslateDriver { | 19 class ContentTranslateDriver : public TranslateDriver { |
18 public: | 20 public: |
19 | 21 |
20 // The observer for the ContentTranslateDriver. | 22 // The observer for the ContentTranslateDriver. |
21 class Observer { | 23 class Observer { |
22 public: | 24 public: |
23 // Handles when the value of IsPageTranslated is changed. | 25 // Handles when the value of IsPageTranslated is changed. |
24 virtual void OnIsPageTranslatedChanged(content::WebContents* source) = 0; | 26 virtual void OnIsPageTranslatedChanged(content::WebContents* source) = 0; |
25 | 27 |
26 // Handles when the value of translate_enabled is changed. | 28 // Handles when the value of translate_enabled is changed. |
27 virtual void OnTranslateEnabledChanged(content::WebContents* source) = 0; | 29 virtual void OnTranslateEnabledChanged(content::WebContents* source) = 0; |
28 | 30 |
29 protected: | 31 protected: |
30 virtual ~Observer() {} | 32 virtual ~Observer() {} |
31 }; | 33 }; |
32 | 34 |
33 ContentTranslateDriver(content::NavigationController* nav_controller); | 35 ContentTranslateDriver(content::NavigationController* nav_controller); |
34 virtual ~ContentTranslateDriver(); | 36 virtual ~ContentTranslateDriver(); |
35 | 37 |
36 // Sets the Observer. Calling this method is optional. | 38 // Sets the Observer. Calling this method is optional. |
37 void set_observer(Observer* observer) { observer_ = observer; } | 39 void set_observer(Observer* observer) { observer_ = observer; } |
38 | 40 |
| 41 // Must be called on navigations. |
| 42 void DidNavigate(const content::LoadCommittedDetails& details); |
| 43 |
39 // TranslateDriver methods. | 44 // TranslateDriver methods. |
40 virtual void OnIsPageTranslatedChanged() OVERRIDE; | 45 virtual void OnIsPageTranslatedChanged() OVERRIDE; |
41 virtual void OnTranslateEnabledChanged() OVERRIDE; | 46 virtual void OnTranslateEnabledChanged() OVERRIDE; |
42 virtual bool IsLinkNavigation() OVERRIDE; | 47 virtual bool IsLinkNavigation() OVERRIDE; |
| 48 virtual LanguageState& GetLanguageState() OVERRIDE; |
43 virtual void TranslatePage(const std::string& translate_script, | 49 virtual void TranslatePage(const std::string& translate_script, |
44 const std::string& source_lang, | 50 const std::string& source_lang, |
45 const std::string& target_lang) OVERRIDE; | 51 const std::string& target_lang) OVERRIDE; |
46 virtual void RevertTranslation() OVERRIDE; | 52 virtual void RevertTranslation() OVERRIDE; |
47 virtual bool IsOffTheRecord() OVERRIDE; | 53 virtual bool IsOffTheRecord() OVERRIDE; |
48 virtual const std::string& GetContentsMimeType() OVERRIDE; | 54 virtual const std::string& GetContentsMimeType() OVERRIDE; |
49 virtual const GURL& GetLastCommittedURL() OVERRIDE; | 55 virtual const GURL& GetLastCommittedURL() OVERRIDE; |
50 virtual const GURL& GetActiveURL() OVERRIDE; | 56 virtual const GURL& GetActiveURL() OVERRIDE; |
51 virtual const GURL& GetVisibleURL() OVERRIDE; | 57 virtual const GURL& GetVisibleURL() OVERRIDE; |
52 virtual bool HasCurrentPage() OVERRIDE; | 58 virtual bool HasCurrentPage() OVERRIDE; |
53 virtual int GetCurrentPageID() OVERRIDE; | 59 virtual int GetCurrentPageID() OVERRIDE; |
54 virtual void OpenUrlInNewTab(const GURL& url) OVERRIDE; | 60 virtual void OpenUrlInNewTab(const GURL& url) OVERRIDE; |
55 | 61 |
56 private: | 62 private: |
57 // The navigation controller of the tab we are associated with. | 63 // The navigation controller of the tab we are associated with. |
58 content::NavigationController* navigation_controller_; | 64 content::NavigationController* navigation_controller_; |
59 | 65 |
| 66 LanguageState language_state_; |
60 Observer* observer_; | 67 Observer* observer_; |
61 | 68 |
62 DISALLOW_COPY_AND_ASSIGN(ContentTranslateDriver); | 69 DISALLOW_COPY_AND_ASSIGN(ContentTranslateDriver); |
63 }; | 70 }; |
64 | 71 |
65 #endif // COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_H_ | 72 #endif // COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_H_ |
OLD | NEW |