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

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

Issue 2143383002: [Translate] Migrate IPCs to Mojo interfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix trybots Created 4 years, 4 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 <map>
9
8 #include "base/macros.h" 10 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
10 #include "base/observer_list.h" 12 #include "base/observer_list.h"
13 #include "components/translate/content/common/translate.mojom.h"
11 #include "components/translate/core/browser/translate_driver.h" 14 #include "components/translate/core/browser/translate_driver.h"
12 #include "components/translate/core/common/translate_errors.h" 15 #include "components/translate/core/common/translate_errors.h"
13 #include "content/public/browser/web_contents_observer.h" 16 #include "content/public/browser/web_contents_observer.h"
17 #include "mojo/public/cpp/bindings/binding_set.h"
14 18
15 namespace content { 19 namespace content {
16 class NavigationController; 20 class NavigationController;
17 class WebContents; 21 class WebContents;
18 } 22 }
19 23
20 namespace translate { 24 namespace translate {
21 25
22 struct LanguageDetectionDetails; 26 struct LanguageDetectionDetails;
23 class TranslateManager; 27 class TranslateManager;
24 28
25
26 // Content implementation of TranslateDriver. 29 // Content implementation of TranslateDriver.
27 class ContentTranslateDriver : public TranslateDriver, 30 class ContentTranslateDriver : public TranslateDriver,
28 public content::WebContentsObserver { 31 public content::WebContentsObserver,
32 public mojom::ContentTranslateDriver {
29 public: 33 public:
30
31 // The observer for the ContentTranslateDriver. 34 // The observer for the ContentTranslateDriver.
32 class Observer { 35 class Observer {
33 public: 36 public:
34 // Handles when the value of IsPageTranslated is changed. 37 // Handles when the value of IsPageTranslated is changed.
35 virtual void OnIsPageTranslatedChanged(content::WebContents* source) {}; 38 virtual void OnIsPageTranslatedChanged(content::WebContents* source) {};
36 39
37 // Handles when the value of translate_enabled is changed. 40 // Handles when the value of translate_enabled is changed.
38 virtual void OnTranslateEnabledChanged(content::WebContents* source) {}; 41 virtual void OnTranslateEnabledChanged(content::WebContents* source) {};
39 42
40 // Called when the page language has been determined. 43 // Called when the page language has been determined.
41 virtual void OnLanguageDetermined( 44 virtual void OnLanguageDetermined(
42 const translate::LanguageDetectionDetails& details) {}; 45 const translate::LanguageDetectionDetails& details) {};
43 46
44 // Called when the page has been translated. 47 // Called when the page has been translated.
45 virtual void OnPageTranslated( 48 virtual void OnPageTranslated(
46 const std::string& original_lang, 49 const std::string& original_lang,
47 const std::string& translated_lang, 50 const std::string& translated_lang,
48 translate::TranslateErrors::Type error_type) {}; 51 translate::TranslateErrors::Type error_type) {};
49 52
50 protected: 53 protected:
51 virtual ~Observer() {} 54 virtual ~Observer() {}
52 }; 55 };
53 56
54 ContentTranslateDriver(content::NavigationController* nav_controller); 57 explicit ContentTranslateDriver(
58 content::NavigationController* nav_controller);
55 ~ContentTranslateDriver() override; 59 ~ContentTranslateDriver() override;
56 60
61 void BindRequest(mojom::ContentTranslateDriverRequest request);
62
57 // Adds or Removes observers. 63 // Adds or Removes observers.
58 void AddObserver(Observer* observer); 64 void AddObserver(Observer* observer);
59 void RemoveObserver(Observer* observer); 65 void RemoveObserver(Observer* observer);
60 66
61 // Number of attempts before waiting for a page to be fully reloaded. 67 // Number of attempts before waiting for a page to be fully reloaded.
62 void set_translate_max_reload_attempts(int attempts) { 68 void set_translate_max_reload_attempts(int attempts) {
63 max_reload_check_attempts_ = attempts; 69 max_reload_check_attempts_ = attempts;
64 } 70 }
65 71
66 // Sets the TranslateManager associated with this driver. 72 // Sets the TranslateManager associated with this driver.
(...skipping 19 matching lines...) Expand all
86 const GURL& GetVisibleURL() override; 92 const GURL& GetVisibleURL() override;
87 bool HasCurrentPage() override; 93 bool HasCurrentPage() override;
88 void OpenUrlInNewTab(const GURL& url) override; 94 void OpenUrlInNewTab(const GURL& url) override;
89 95
90 // content::WebContentsObserver implementation. 96 // content::WebContentsObserver implementation.
91 void NavigationEntryCommitted( 97 void NavigationEntryCommitted(
92 const content::LoadCommittedDetails& load_details) override; 98 const content::LoadCommittedDetails& load_details) override;
93 void DidNavigateAnyFrame(content::RenderFrameHost* render_frame_host, 99 void DidNavigateAnyFrame(content::RenderFrameHost* render_frame_host,
94 const content::LoadCommittedDetails& details, 100 const content::LoadCommittedDetails& details,
95 const content::FrameNavigateParams& params) override; 101 const content::FrameNavigateParams& params) override;
96 bool OnMessageReceived(const IPC::Message& message,
97 content::RenderFrameHost* render_frame_host) override;
98 102
99 // IPC handlers. 103 void OnPageTranslated(bool cancelled,
100 void OnTranslateAssignedSequenceNumber(int page_seq_no); 104 const std::string& original_lang,
101 void OnLanguageDetermined(const LanguageDetectionDetails& details,
102 bool page_needs_translation);
103 void OnPageTranslated(const std::string& original_lang,
104 const std::string& translated_lang, 105 const std::string& translated_lang,
105 TranslateErrors::Type error_type); 106 TranslateErrors::Type error_type);
106 107
108 // mojom::ContentTranslateDriver implementation.
109 void RegisterPage(mojom::PagePtr page,
110 const LanguageDetectionDetails& details,
111 bool page_needs_translation) override;
112
107 private: 113 private:
114 void OnPageAway(int page_seq_no);
115
108 // The navigation controller of the tab we are associated with. 116 // The navigation controller of the tab we are associated with.
109 content::NavigationController* navigation_controller_; 117 content::NavigationController* navigation_controller_;
110 118
111 TranslateManager* translate_manager_; 119 TranslateManager* translate_manager_;
112 120
113 base::ObserverList<Observer, true> observer_list_; 121 base::ObserverList<Observer, true> observer_list_;
114 122
115 // Max number of attempts before checking if a page has been reloaded. 123 // Max number of attempts before checking if a page has been reloaded.
116 int max_reload_check_attempts_; 124 int max_reload_check_attempts_;
117 125
126 // Records mojo connections with all current alive pages.
127 int next_page_seq_no_;
128 std::map<int, mojom::PagePtr> pages_;
129
130 // ContentTranslateDriver is singleton per web contents ,
131 // serve for multiple render frames.
132 mojo::BindingSet<mojom::ContentTranslateDriver> bindings_;
133
118 base::WeakPtrFactory<ContentTranslateDriver> weak_pointer_factory_; 134 base::WeakPtrFactory<ContentTranslateDriver> weak_pointer_factory_;
119 135
120 DISALLOW_COPY_AND_ASSIGN(ContentTranslateDriver); 136 DISALLOW_COPY_AND_ASSIGN(ContentTranslateDriver);
121 }; 137 };
122 138
123 } // namespace translate 139 } // namespace translate
124 140
125 #endif // COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_H_ 141 #endif // COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_H_
OLDNEW
« no previous file with comments | « components/translate/content/browser/BUILD.gn ('k') | components/translate/content/browser/content_translate_driver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698