| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 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_TRANSLATE_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_ |
| 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/translate/translate_manager.h" |
| 11 #include "chrome/browser/ui/translate/translate_bubble_model.h" | 12 #include "chrome/browser/ui/translate/translate_bubble_model.h" |
| 12 #include "components/translate/content/browser/content_translate_driver.h" | 13 #include "components/translate/content/browser/content_translate_driver.h" |
| 13 #include "components/translate/core/common/translate_errors.h" | 14 #include "components/translate/core/common/translate_errors.h" |
| 14 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 15 #include "content/public/browser/web_contents_user_data.h" | 16 #include "content/public/browser/web_contents_user_data.h" |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 class BrowserContext; | 19 class BrowserContext; |
| 19 class WebContents; | 20 class WebContents; |
| 20 } | 21 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 38 ContentTranslateDriver& translate_driver() { return translate_driver_; } | 39 ContentTranslateDriver& translate_driver() { return translate_driver_; } |
| 39 | 40 |
| 40 // Helper method to return a new TranslatePrefs instance. | 41 // Helper method to return a new TranslatePrefs instance. |
| 41 static scoped_ptr<TranslatePrefs> CreateTranslatePrefs(PrefService* prefs); | 42 static scoped_ptr<TranslatePrefs> CreateTranslatePrefs(PrefService* prefs); |
| 42 | 43 |
| 43 // Helper method to return the TranslateAcceptLanguages instance associated | 44 // Helper method to return the TranslateAcceptLanguages instance associated |
| 44 // with |browser_context|. | 45 // with |browser_context|. |
| 45 static TranslateAcceptLanguages* GetTranslateAcceptLanguages( | 46 static TranslateAcceptLanguages* GetTranslateAcceptLanguages( |
| 46 content::BrowserContext* browser_context); | 47 content::BrowserContext* browser_context); |
| 47 | 48 |
| 49 // Helper method to return the TranslateManager instance associated with |
| 50 // |web_contents|. |
| 51 static TranslateManager* GetManagerFromWebContents( |
| 52 content::WebContents* web_contents); |
| 53 |
| 54 // Gets the associated TranslateManager. |
| 55 TranslateManager* GetTranslateManager(); |
| 56 |
| 57 // Gets the associated WebContents. |
| 58 content::WebContents* GetWebContents(); |
| 59 |
| 48 // Denotes which state the user is in with respect to translate. | 60 // Denotes which state the user is in with respect to translate. |
| 49 enum TranslateStep { | 61 enum TranslateStep { |
| 50 BEFORE_TRANSLATE, | 62 BEFORE_TRANSLATE, |
| 51 TRANSLATING, | 63 TRANSLATING, |
| 52 AFTER_TRANSLATE, | 64 AFTER_TRANSLATE, |
| 53 TRANSLATE_ERROR | 65 TRANSLATE_ERROR |
| 54 }; | 66 }; |
| 55 | 67 |
| 56 // Called when the embedder should present UI to the user corresponding to the | 68 // Called when the embedder should present UI to the user corresponding to the |
| 57 // user's current |step|. | 69 // user's current |step|. |
| 58 void ShowTranslateUI(TranslateStep step, | 70 void ShowTranslateUI(TranslateStep step, |
| 59 content::WebContents* web_contents, | |
| 60 const std::string source_language, | 71 const std::string source_language, |
| 61 const std::string target_language, | 72 const std::string target_language, |
| 62 TranslateErrors::Type error_type); | 73 TranslateErrors::Type error_type); |
| 63 | 74 |
| 64 private: | 75 private: |
| 65 explicit TranslateTabHelper(content::WebContents* web_contents); | 76 explicit TranslateTabHelper(content::WebContents* web_contents); |
| 66 friend class content::WebContentsUserData<TranslateTabHelper>; | 77 friend class content::WebContentsUserData<TranslateTabHelper>; |
| 67 | 78 |
| 68 // content::WebContentsObserver implementation. | 79 // content::WebContentsObserver implementation. |
| 69 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 80 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 70 virtual void DidNavigateAnyFrame( | 81 virtual void DidNavigateAnyFrame( |
| 71 const content::LoadCommittedDetails& details, | 82 const content::LoadCommittedDetails& details, |
| 72 const content::FrameNavigateParams& params) OVERRIDE; | 83 const content::FrameNavigateParams& params) OVERRIDE; |
| 73 | 84 |
| 74 void OnLanguageDetermined(const LanguageDetectionDetails& details, | 85 void OnLanguageDetermined(const LanguageDetectionDetails& details, |
| 75 bool page_needs_translation); | 86 bool page_needs_translation); |
| 76 void OnPageTranslated(int32 page_id, | 87 void OnPageTranslated(int32 page_id, |
| 77 const std::string& original_lang, | 88 const std::string& original_lang, |
| 78 const std::string& translated_lang, | 89 const std::string& translated_lang, |
| 79 TranslateErrors::Type error_type); | 90 TranslateErrors::Type error_type); |
| 80 | 91 |
| 81 // Shows the translate bubble. | 92 // Shows the translate bubble. |
| 82 void ShowBubble(content::WebContents* web_contents, | 93 void ShowBubble(TranslateStep step, TranslateErrors::Type error_type); |
| 83 TranslateStep step, | |
| 84 TranslateErrors::Type error_type); | |
| 85 | 94 |
| 86 ContentTranslateDriver translate_driver_; | 95 ContentTranslateDriver translate_driver_; |
| 96 TranslateManager translate_manager_; |
| 87 | 97 |
| 88 DISALLOW_COPY_AND_ASSIGN(TranslateTabHelper); | 98 DISALLOW_COPY_AND_ASSIGN(TranslateTabHelper); |
| 89 }; | 99 }; |
| 90 | 100 |
| 91 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_ | 101 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_ |
| OLD | NEW |