Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / components / translate / content / browser / content_translate_driver.h
blobd6b69adae3f2ad94f94c4a54bab3415401968a6d
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 COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_H_
6 #define COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/observer_list.h"
11 #include "components/translate/core/browser/translate_driver.h"
12 #include "components/translate/core/common/translate_errors.h"
13 #include "content/public/browser/web_contents_observer.h"
15 namespace content {
16 class NavigationController;
17 class WebContents;
20 namespace translate {
22 struct LanguageDetectionDetails;
23 class TranslateManager;
25 // Content implementation of TranslateDriver.
26 class ContentTranslateDriver : public TranslateDriver,
27 public content::WebContentsObserver {
28 public:
30 // The observer for the ContentTranslateDriver.
31 class Observer {
32 public:
33 // Handles when the value of IsPageTranslated is changed.
34 virtual void OnIsPageTranslatedChanged(content::WebContents* source) {};
36 // Handles when the value of translate_enabled is changed.
37 virtual void OnTranslateEnabledChanged(content::WebContents* source) {};
39 // Called when the page language has been determined.
40 virtual void OnLanguageDetermined(
41 const translate::LanguageDetectionDetails& details) {};
43 // Called when the page has been translated.
44 virtual void OnPageTranslated(
45 const std::string& original_lang,
46 const std::string& translated_lang,
47 translate::TranslateErrors::Type error_type) {};
49 protected:
50 virtual ~Observer() {}
53 ContentTranslateDriver(content::NavigationController* nav_controller);
54 ~ContentTranslateDriver() override;
56 // Adds or Removes observers.
57 void AddObserver(Observer* observer);
58 void RemoveObserver(Observer* observer);
60 // Number of attempts before waiting for a page to be fully reloaded.
61 void set_translate_max_reload_attempts(int attempts) {
62 max_reload_check_attempts_ = attempts;
65 // Sets the TranslateManager associated with this driver.
66 void set_translate_manager(TranslateManager* manager) {
67 translate_manager_ = manager;
70 // Initiates translation once the page is finished loading.
71 void InitiateTranslation(const std::string& page_lang, int attempt);
73 // TranslateDriver methods.
74 void OnIsPageTranslatedChanged() override;
75 void OnTranslateEnabledChanged() override;
76 bool IsLinkNavigation() override;
77 void TranslatePage(int page_seq_no,
78 const std::string& translate_script,
79 const std::string& source_lang,
80 const std::string& target_lang) override;
81 void RevertTranslation(int page_seq_no) override;
82 bool IsOffTheRecord() override;
83 const std::string& GetContentsMimeType() override;
84 const GURL& GetLastCommittedURL() override;
85 const GURL& GetVisibleURL() override;
86 bool HasCurrentPage() override;
87 void OpenUrlInNewTab(const GURL& url) override;
89 // content::WebContentsObserver implementation.
90 void NavigationEntryCommitted(
91 const content::LoadCommittedDetails& load_details) override;
92 void DidNavigateAnyFrame(content::RenderFrameHost* render_frame_host,
93 const content::LoadCommittedDetails& details,
94 const content::FrameNavigateParams& params) override;
95 bool OnMessageReceived(const IPC::Message& message) override;
97 // IPC handlers.
98 void OnTranslateAssignedSequenceNumber(int page_seq_no);
99 void OnLanguageDetermined(const LanguageDetectionDetails& details,
100 bool page_needs_translation);
101 void OnPageTranslated(const std::string& original_lang,
102 const std::string& translated_lang,
103 TranslateErrors::Type error_type);
105 private:
106 // The navigation controller of the tab we are associated with.
107 content::NavigationController* navigation_controller_;
109 TranslateManager* translate_manager_;
111 base::ObserverList<Observer, true> observer_list_;
113 // Max number of attempts before checking if a page has been reloaded.
114 int max_reload_check_attempts_;
116 base::WeakPtrFactory<ContentTranslateDriver> weak_pointer_factory_;
118 DISALLOW_COPY_AND_ASSIGN(ContentTranslateDriver);
121 } // namespace translate
123 #endif // COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_H_