Chromium Code Reviews| Index: components/translate/content/renderer/translate_helper.h |
| diff --git a/components/translate/content/renderer/translate_helper.h b/components/translate/content/renderer/translate_helper.h |
| index e727751013ddc8a2d32d0af10dced39b24a82030..7363939607e561327f62ade1a36bfbb35d601620 100644 |
| --- a/components/translate/content/renderer/translate_helper.h |
| +++ b/components/translate/content/renderer/translate_helper.h |
| @@ -12,8 +12,10 @@ |
| #include "base/memory/weak_ptr.h" |
| #include "base/strings/string16.h" |
| #include "base/time/time.h" |
| +#include "components/translate/content/public/interfaces/translate.mojom.h" |
| #include "components/translate/core/common/translate_errors.h" |
| #include "content/public/renderer/render_frame_observer.h" |
| +#include "mojo/public/cpp/bindings/binding.h" |
| #include "url/gurl.h" |
| namespace blink { |
| @@ -25,12 +27,13 @@ namespace translate { |
| // This class deals with page translation. |
| // There is one TranslateHelper per RenderView. |
| -class TranslateHelper : public content::RenderFrameObserver { |
| +class TranslateHelper : public content::RenderFrameObserver, |
| + public mojom::Page { |
| public: |
| - explicit TranslateHelper(content::RenderFrame* render_frame, |
| - int world_id, |
| - int extension_group, |
| - const std::string& extension_scheme); |
| + TranslateHelper(content::RenderFrame* render_frame, |
| + int world_id, |
| + int extension_group, |
| + const std::string& extension_scheme); |
| ~TranslateHelper() override; |
| // Informs us that the page's text has been extracted. |
| @@ -41,15 +44,14 @@ class TranslateHelper : public content::RenderFrameObserver { |
| // this URL loads, this is the time to prepare for it. |
| void PrepareForUrl(const GURL& url); |
| - protected: |
| - // The following methods are protected so they can be overridden in |
| - // unit-tests. |
| - void OnTranslatePage(int page_seq_no, |
| - const std::string& translate_script, |
| - const std::string& source_lang, |
| - const std::string& target_lang); |
| - void OnRevertTranslation(int page_seq_no); |
| + // mojom::Page implementation. |
| + void Translate(const std::string& translate_script, |
| + const std::string& source_lang, |
| + const std::string& target_lang, |
| + const TranslateCallback& callback) override; |
| + void RevertTranslation() override; |
| + protected: |
| // Returns true if the translate library is available, meaning the JavaScript |
| // has already been injected in that page. |
| virtual bool IsTranslateLibAvailable(); |
| @@ -102,13 +104,11 @@ class TranslateHelper : public content::RenderFrameObserver { |
| // Converts language code to the one used in server supporting list. |
| static void ConvertLanguageCodeSynonym(std::string* code); |
| + const mojom::ContentTranslateDriverPtr& GetMojoTranslateDriver(); |
|
Ken Rockot(use gerrit already)
2016/07/28 20:16:06
nit: Just GetTranslateDriver() or translate_driver
leonhsl(Using Gerrit)
2016/07/29 12:54:32
Done.
|
| + |
| // RenderFrameObserver implementation. |
| - bool OnMessageReceived(const IPC::Message& message) override; |
| void OnDestruct() override; |
| - // Informs us that the page's text has been extracted. |
| - void PageCapturedImpl(int page_seq_no, const base::string16& contents); |
| - |
| // Cancels any translation that is currently being performed. This does not |
| // revert existing translations. |
| void CancelPendingTranslation(); |
| @@ -116,11 +116,11 @@ class TranslateHelper : public content::RenderFrameObserver { |
| // Checks if the current running page translation is finished or errored and |
| // notifies the browser accordingly. If the translation has not terminated, |
| // posts a task to check again later. |
| - void CheckTranslateStatus(int page_seq_no); |
| + void CheckTranslateStatus(); |
| // Called by TranslatePage to do the actual translation. |count| is used to |
| // limit the number of retries. |
| - void TranslatePageImpl(int page_seq_no, int count); |
| + void TranslatePageImpl(int count); |
| // Sends a message to the browser to notify it that the translation failed |
| // with |error|. |
| @@ -130,12 +130,8 @@ class TranslateHelper : public content::RenderFrameObserver { |
| // if the page is being closed. |
| blink::WebLocalFrame* GetMainFrame(); |
| - // An ever-increasing sequence number of the current page, used to match up |
| - // translation requests with responses. |
| - int page_seq_no_; |
| - |
| // The states associated with the current translation. |
| - bool translation_pending_; |
| + TranslateCallback translate_callback_pending_; |
| std::string source_lang_; |
| std::string target_lang_; |
| @@ -152,6 +148,10 @@ class TranslateHelper : public content::RenderFrameObserver { |
| // The URL scheme for translate extensions. |
| std::string extension_scheme_; |
| + mojom::ContentTranslateDriverPtr mojo_translate_driver_; |
|
Ken Rockot(use gerrit already)
2016/07/28 20:16:06
nit: just translate_driver_ please.
leonhsl(Using Gerrit)
2016/07/29 12:54:32
Done.
|
| + |
| + mojo::Binding<mojom::Page> binding_; |
| + |
| // Method factory used to make calls to TranslatePageImpl. |
| base::WeakPtrFactory<TranslateHelper> weak_method_factory_; |