summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorjcivelli@google.com <jcivelli@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-06 22:21:02 +0000
committerjcivelli@google.com <jcivelli@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-06 22:21:02 +0000
commit85d252e22b6bec161873a0b5656d59c8ebe04e30 (patch)
tree937f8add8eac344f93d6a8ec6604796f371c761c /chrome/common
parentd41661b5e24c8d774acea07c05ef2e5896587e56 (diff)
downloadchromium_src-85d252e22b6bec161873a0b5656d59c8ebe04e30.zip
chromium_src-85d252e22b6bec161873a0b5656d59c8ebe04e30.tar.gz
chromium_src-85d252e22b6bec161873a0b5656d59c8ebe04e30.tar.bz2
Changing the translate back-end to use the Google Translate element.
When the user indicates that a page should be translated, the browser first fetches the Google Translate Element JS code. It then sends it to the renderer, which injects the script in the page, waits for the Translate element to be initialized and then calls the translate method on it. The TranslationService class previously used to translate text chunks is now unused and has been removed. Some of its static methods that are still used have been moved to the TranslateManager class. This CL also implements the "revert" translation behavior. BUG=35474,37778,35553,39375 TEST=Test the translation feature extensively. Review URL: http://codereview.chromium.org/1599016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43768 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/render_messages.h70
-rw-r--r--chrome/common/render_messages_internal.h18
-rw-r--r--chrome/common/translate_errors.h6
3 files changed, 10 insertions, 84 deletions
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index 211297a..c76b430 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -595,34 +595,6 @@ struct ViewMsg_New_Params {
int64 session_storage_namespace_id;
};
-// Message to ask the browser to translate some text from one language to
-// another.
-struct ViewHostMsg_TranslateTextParam {
- // The routing id. Even though ViewHostMsg_TranslateText is a control message
- // (sent to the browser, not to a specific RenderViewHost), the browser needs
- // the routing id in order to send the response back to the right RenderView.
- int routing_id;
-
- // An id used to identify that specific translation.
- int work_id;
-
- // The id of the page this translation originated from.
- int page_id;
-
- // The text chunks that need to be translated.
- std::vector<string16> text_chunks;
-
- // The ISO code of the language the text to translate is in.
- std::string from_language;
-
- // The ISO code of the language the text should be translated to.
- std::string to_language;
-
- // Whether a secure connection should be used when transmitting the text for
- // translation to an external server.
- bool secure;
-};
-
struct ViewHostMsg_RunFileChooser_Params {
enum Mode {
// Requires that the file exists before allowing the user to pick it.
@@ -2569,48 +2541,6 @@ struct ParamTraits<ViewMsg_New_Params> {
}
};
-template<>
-struct ParamTraits<ViewHostMsg_TranslateTextParam> {
- typedef ViewHostMsg_TranslateTextParam param_type;
- static void Write(Message* m, const param_type& p) {
- WriteParam(m, p.routing_id);
- WriteParam(m, p.work_id);
- WriteParam(m, p.page_id);
- WriteParam(m, p.text_chunks);
- WriteParam(m, p.from_language);
- WriteParam(m, p.to_language);
- WriteParam(m, p.secure);
- }
-
- static bool Read(const Message* m, void** iter, param_type* p) {
- return
- ReadParam(m, iter, &p->routing_id) &&
- ReadParam(m, iter, &p->work_id) &&
- ReadParam(m, iter, &p->page_id) &&
- ReadParam(m, iter, &p->text_chunks) &&
- ReadParam(m, iter, &p->from_language) &&
- ReadParam(m, iter, &p->to_language) &&
- ReadParam(m, iter, &p->secure);
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(L"(");
- LogParam(p.routing_id, l);
- l->append(L", ");
- LogParam(p.work_id, l);
- l->append(L", ");
- LogParam(p.page_id, l);
- l->append(L", ");
- LogParam(p.text_chunks, l);
- l->append(L", ");
- LogParam(p.from_language, l);
- l->append(L", ");
- LogParam(p.to_language, l);
- l->append(L", ");
- LogParam(p.secure, l);
- l->append(L")");
- }
-};
-
template <>
struct SimilarTypeTraits<TranslateErrors::Type> {
typedef int Type;
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index b1222f1..68d69d0 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -896,19 +896,18 @@ IPC_BEGIN_MESSAGES(View)
// Tells the renderer to translate the page contents from one language to
// another.
- IPC_MESSAGE_ROUTED3(ViewMsg_TranslatePage,
+ IPC_MESSAGE_ROUTED4(ViewMsg_TranslatePage,
int /* page id */,
+ std::string, /* the script injected in the page */
std::string, /* BCP 47/RFC 5646 language code the page
is in */
std::string /* BCP 47/RFC 5646 language code to translate
to */)
- // Reply to the ViewHostMsg_TranslateText message with the actual translated
- // text chunks.
- IPC_MESSAGE_ROUTED3(ViewMsg_TranslateTextReponse,
- int /* id of translation work */,
- int /* error id of translation work */,
- std::vector<string16> /* the translated text chunks */)
+ // Tells the renderer to revert the text of translated page to its original
+ // contents.
+ IPC_MESSAGE_ROUTED1(ViewMsg_RevertTranslation,
+ int /* page id */)
// Reply in response to ViewHostMsg_Geolocation_RequestPermission.
IPC_MESSAGE_ROUTED2(ViewMsg_Geolocation_PermissionSet,
@@ -2227,11 +2226,6 @@ IPC_BEGIN_MESSAGES(ViewHost)
string16 /* word */,
std::vector<string16> /* suggestions */)
- // Request for text translation.
- // Used when translating a page from one language to another.
- IPC_MESSAGE_CONTROL1(ViewHostMsg_TranslateText,
- ViewHostMsg_TranslateTextParam)
-
//---------------------------------------------------------------------------
// Geolocation services messages
diff --git a/chrome/common/translate_errors.h b/chrome/common/translate_errors.h
index de2e3bd..c8f4225 100644
--- a/chrome/common/translate_errors.h
+++ b/chrome/common/translate_errors.h
@@ -11,8 +11,10 @@ class TranslateErrors {
public:
enum Type {
NONE = 0,
- NETWORK = 1,
- SERVER,
+ NETWORK, // No connectivity.
+ INITIALIZATION_ERROR, // The translation script failed to initialize.
+ TRANSLATION_ERROR, // An error was reported by the translation script
+ // during translation.
};
private: