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

Side by Side Diff: components/translate/content/browser/content_translate_driver.h

Issue 564743002: Move Translate browser-side IPC handling to the component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 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" 8 #include "base/basictypes.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/observer_list.h"
10 #include "components/translate/core/browser/translate_driver.h" 11 #include "components/translate/core/browser/translate_driver.h"
12 #include "components/translate/core/common/translate_errors.h"
11 #include "content/public/browser/web_contents_observer.h" 13 #include "content/public/browser/web_contents_observer.h"
12 14
13 namespace content { 15 namespace content {
14 class NavigationController; 16 class NavigationController;
15 class WebContents; 17 class WebContents;
16 } 18 }
17 19
18 namespace translate { 20 namespace translate {
19 21
22 struct LanguageDetectionDetails;
20 class TranslateManager; 23 class TranslateManager;
21 24
22 // Content implementation of TranslateDriver. 25 // Content implementation of TranslateDriver.
23 class ContentTranslateDriver : public TranslateDriver, 26 class ContentTranslateDriver : public TranslateDriver,
24 public content::WebContentsObserver { 27 public content::WebContentsObserver {
25 public: 28 public:
26 29
27 // The observer for the ContentTranslateDriver. 30 // The observer for the ContentTranslateDriver.
28 class Observer { 31 class Observer {
29 public: 32 public:
30 // Handles when the value of IsPageTranslated is changed. 33 // Handles when the value of IsPageTranslated is changed.
31 virtual void OnIsPageTranslatedChanged(content::WebContents* source) = 0; 34 virtual void OnIsPageTranslatedChanged(content::WebContents* source) {};
32 35
33 // Handles when the value of translate_enabled is changed. 36 // Handles when the value of translate_enabled is changed.
34 virtual void OnTranslateEnabledChanged(content::WebContents* source) = 0; 37 virtual void OnTranslateEnabledChanged(content::WebContents* source) {};
38
39 // Called when the page language has been determined.
40 virtual void OnLanguageDetermined(
41 const translate::LanguageDetectionDetails& details) {};
42
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) {};
35 48
36 protected: 49 protected:
37 virtual ~Observer() {} 50 virtual ~Observer() {}
38 }; 51 };
39 52
40 ContentTranslateDriver(content::NavigationController* nav_controller); 53 ContentTranslateDriver(content::NavigationController* nav_controller);
41 virtual ~ContentTranslateDriver(); 54 virtual ~ContentTranslateDriver();
42 55
43 // Sets the Observer. Calling this method is optional. 56 // Adds or Removes observers.
44 void set_observer(Observer* observer) { observer_ = observer; } 57 void AddObserver(Observer* observer);
58 void RemoveObserver(Observer* observer);
45 59
46 // Number of attempts before waiting for a page to be fully reloaded. 60 // Number of attempts before waiting for a page to be fully reloaded.
47 void set_translate_max_reload_attempts(int attempts) { 61 void set_translate_max_reload_attempts(int attempts) {
48 max_reload_check_attempts_ = attempts; 62 max_reload_check_attempts_ = attempts;
49 } 63 }
50 64
51 // Sets the TranslateManager associated with this driver. 65 // Sets the TranslateManager associated with this driver.
52 void set_translate_manager(TranslateManager* manager) { 66 void set_translate_manager(TranslateManager* manager) {
53 translate_manager_ = manager; 67 translate_manager_ = manager;
54 } 68 }
(...skipping 17 matching lines...) Expand all
72 virtual const GURL& GetVisibleURL() OVERRIDE; 86 virtual const GURL& GetVisibleURL() OVERRIDE;
73 virtual bool HasCurrentPage() OVERRIDE; 87 virtual bool HasCurrentPage() OVERRIDE;
74 virtual void OpenUrlInNewTab(const GURL& url) OVERRIDE; 88 virtual void OpenUrlInNewTab(const GURL& url) OVERRIDE;
75 89
76 // content::WebContentsObserver implementation. 90 // content::WebContentsObserver implementation.
77 virtual void NavigationEntryCommitted( 91 virtual void NavigationEntryCommitted(
78 const content::LoadCommittedDetails& load_details) OVERRIDE; 92 const content::LoadCommittedDetails& load_details) OVERRIDE;
79 virtual void DidNavigateAnyFrame( 93 virtual void DidNavigateAnyFrame(
80 const content::LoadCommittedDetails& details, 94 const content::LoadCommittedDetails& details,
81 const content::FrameNavigateParams& params) OVERRIDE; 95 const content::FrameNavigateParams& params) OVERRIDE;
96 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
97
98 // IPC handlers.
99 void OnTranslateAssignedSequenceNumber(int page_seq_no);
100 void OnLanguageDetermined(const LanguageDetectionDetails& details,
101 bool page_needs_translation);
102 void OnPageTranslated(const std::string& original_lang,
103 const std::string& translated_lang,
104 TranslateErrors::Type error_type);
82 105
83 private: 106 private:
84 // The navigation controller of the tab we are associated with. 107 // The navigation controller of the tab we are associated with.
85 content::NavigationController* navigation_controller_; 108 content::NavigationController* navigation_controller_;
86 109
87 TranslateManager* translate_manager_; 110 TranslateManager* translate_manager_;
88 111
89 Observer* observer_; 112 ObserverList<Observer, true> observer_list_;
90 113
91 // Max number of attempts before checking if a page has been reloaded. 114 // Max number of attempts before checking if a page has been reloaded.
92 int max_reload_check_attempts_; 115 int max_reload_check_attempts_;
93 116
94 base::WeakPtrFactory<ContentTranslateDriver> weak_pointer_factory_; 117 base::WeakPtrFactory<ContentTranslateDriver> weak_pointer_factory_;
95 118
96 DISALLOW_COPY_AND_ASSIGN(ContentTranslateDriver); 119 DISALLOW_COPY_AND_ASSIGN(ContentTranslateDriver);
97 }; 120 };
98 121
99 } // namespace translate 122 } // namespace translate
100 123
101 #endif // COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_H_ 124 #endif // COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698