Commit f1da1804 authored by droger's avatar droger Committed by Commit bot

Move TranslateHelper to the translate component.

This CL moves TranslateHelper to the translate component.

A couple dependencies had to be injected, through the constructor:
- extensions (group and scheme)
- isolated world id

BUG=335087
TBR=jochen

Review URL: https://codereview.chromium.org/564793003

Cr-Commit-Position: refs/heads/master@{#295276}
parent 2a3abf4b
...@@ -83,8 +83,6 @@ ...@@ -83,8 +83,6 @@
'renderer/security_filter_peer.h', 'renderer/security_filter_peer.h',
'renderer/tts_dispatcher.cc', 'renderer/tts_dispatcher.cc',
'renderer/tts_dispatcher.h', 'renderer/tts_dispatcher.h',
'renderer/translate/translate_helper.cc',
'renderer/translate/translate_helper.h',
'renderer/web_apps.cc', 'renderer/web_apps.cc',
'renderer/web_apps.h', 'renderer/web_apps.h',
'renderer/webview_color_overlay.cc', 'renderer/webview_color_overlay.cc',
...@@ -276,8 +274,6 @@ ...@@ -276,8 +274,6 @@
'../components/components.gyp:password_manager_content_renderer', '../components/components.gyp:password_manager_content_renderer',
'../components/components.gyp:plugins_renderer', '../components/components.gyp:plugins_renderer',
'../components/components.gyp:translate_content_renderer', '../components/components.gyp:translate_content_renderer',
'../components/components.gyp:translate_core_common',
'../components/components.gyp:translate_core_language_detection',
'../components/components.gyp:visitedlink_renderer', '../components/components.gyp:visitedlink_renderer',
'../components/components.gyp:web_cache_renderer', '../components/components.gyp:web_cache_renderer',
'../content/app/resources/content_resources.gyp:content_resources', '../content/app/resources/content_resources.gyp:content_resources',
......
...@@ -17,17 +17,19 @@ ...@@ -17,17 +17,19 @@
#include "chrome/common/prerender_messages.h" #include "chrome/common/prerender_messages.h"
#include "chrome/common/render_messages.h" #include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/renderer/isolated_world_ids.h"
#include "chrome/renderer/prerender/prerender_helper.h" #include "chrome/renderer/prerender/prerender_helper.h"
#include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
#include "chrome/renderer/translate/translate_helper.h"
#include "chrome/renderer/web_apps.h" #include "chrome/renderer/web_apps.h"
#include "chrome/renderer/webview_color_overlay.h" #include "chrome/renderer/webview_color_overlay.h"
#include "components/translate/content/renderer/translate_helper.h"
#include "components/web_cache/renderer/web_cache_render_process_observer.h" #include "components/web_cache/renderer/web_cache_render_process_observer.h"
#include "content/public/common/bindings_policy.h" #include "content/public/common/bindings_policy.h"
#include "content/public/renderer/content_renderer_client.h" #include "content/public/renderer/content_renderer_client.h"
#include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_view.h" #include "content/public/renderer/render_view.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "extensions/renderer/extension_groups.h"
#include "net/base/data_url.h" #include "net/base/data_url.h"
#include "skia/ext/platform_canvas.h" #include "skia/ext/platform_canvas.h"
#include "third_party/WebKit/public/platform/WebCString.h" #include "third_party/WebKit/public/platform/WebCString.h"
...@@ -158,7 +160,11 @@ ChromeRenderViewObserver::ChromeRenderViewObserver( ...@@ -158,7 +160,11 @@ ChromeRenderViewObserver::ChromeRenderViewObserver(
web_cache::WebCacheRenderProcessObserver* web_cache_render_process_observer) web_cache::WebCacheRenderProcessObserver* web_cache_render_process_observer)
: content::RenderViewObserver(render_view), : content::RenderViewObserver(render_view),
web_cache_render_process_observer_(web_cache_render_process_observer), web_cache_render_process_observer_(web_cache_render_process_observer),
translate_helper_(new TranslateHelper(render_view)), translate_helper_(new translate::TranslateHelper(
render_view,
chrome::ISOLATED_WORLD_ID_TRANSLATE,
extensions::EXTENSION_GROUP_INTERNAL_TRANSLATE_SCRIPTS,
extensions::kExtensionScheme)),
phishing_classifier_(NULL), phishing_classifier_(NULL),
capture_timer_(false, false) { capture_timer_(false, false) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess(); const CommandLine& command_line = *CommandLine::ForCurrentProcess();
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
class ContentSettingsObserver; class ContentSettingsObserver;
class SkBitmap; class SkBitmap;
class TranslateHelper;
class WebViewColorOverlay; class WebViewColorOverlay;
class WebViewAnimatingOverlay; class WebViewAnimatingOverlay;
...@@ -33,6 +32,10 @@ namespace safe_browsing { ...@@ -33,6 +32,10 @@ namespace safe_browsing {
class PhishingClassifierDelegate; class PhishingClassifierDelegate;
} }
namespace translate {
class TranslateHelper;
}
namespace web_cache { namespace web_cache {
class WebCacheRenderProcessObserver; class WebCacheRenderProcessObserver;
} }
...@@ -98,7 +101,7 @@ class ChromeRenderViewObserver : public content::RenderViewObserver { ...@@ -98,7 +101,7 @@ class ChromeRenderViewObserver : public content::RenderViewObserver {
web_cache::WebCacheRenderProcessObserver* web_cache_render_process_observer_; web_cache::WebCacheRenderProcessObserver* web_cache_render_process_observer_;
// Have the same lifetime as us. // Have the same lifetime as us.
TranslateHelper* translate_helper_; translate::TranslateHelper* translate_helper_;
safe_browsing::PhishingClassifierDelegate* phishing_classifier_; safe_browsing::PhishingClassifierDelegate* phishing_classifier_;
// A color page overlay when visually de-emaphasized. // A color page overlay when visually de-emaphasized.
......
...@@ -3,11 +3,14 @@ ...@@ -3,11 +3,14 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/renderer/translate/translate_helper.h" #include "chrome/renderer/isolated_world_ids.h"
#include "chrome/test/base/chrome_render_view_test.h" #include "chrome/test/base/chrome_render_view_test.h"
#include "components/translate/content/common/translate_messages.h" #include "components/translate/content/common/translate_messages.h"
#include "components/translate/content/renderer/translate_helper.h"
#include "components/translate/core/common/translate_constants.h" #include "components/translate/core/common/translate_constants.h"
#include "content/public/renderer/render_view.h" #include "content/public/renderer/render_view.h"
#include "extensions/common/constants.h"
#include "extensions/renderer/extension_groups.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h" #include "third_party/WebKit/public/web/WebLocalFrame.h"
...@@ -16,11 +19,14 @@ using testing::AtLeast; ...@@ -16,11 +19,14 @@ using testing::AtLeast;
using testing::Return; using testing::Return;
using testing::_; using testing::_;
class TestTranslateHelper : public TranslateHelper { class TestTranslateHelper : public translate::TranslateHelper {
public: public:
explicit TestTranslateHelper(content::RenderView* render_view) explicit TestTranslateHelper(content::RenderView* render_view)
: TranslateHelper(render_view) { : translate::TranslateHelper(
} render_view,
chrome::ISOLATED_WORLD_ID_TRANSLATE,
extensions::EXTENSION_GROUP_INTERNAL_TRANSLATE_SCRIPTS,
extensions::kExtensionScheme) {}
virtual base::TimeDelta AdjustDelay(int delayInMs) OVERRIDE { virtual base::TimeDelta AdjustDelay(int delayInMs) OVERRIDE {
// Just returns base::TimeDelta() which has initial value 0. // Just returns base::TimeDelta() which has initial value 0.
......
...@@ -206,9 +206,16 @@ ...@@ -206,9 +206,16 @@
'target_name': 'translate_content_renderer', 'target_name': 'translate_content_renderer',
'type': 'static_library', 'type': 'static_library',
'dependencies': [ 'dependencies': [
'translate_content_common',
'translate_core_common',
'translate_core_language_detection',
'../base/base.gyp:base', '../base/base.gyp:base',
'../content/content.gyp:content_common', '../content/content.gyp:content_common',
'../content/content.gyp:content_renderer',
'../ipc/ipc.gyp:ipc', '../ipc/ipc.gyp:ipc',
'../third_party/WebKit/public/blink.gyp:blink',
'../url/url.gyp:url_lib',
'../v8/tools/gyp/v8.gyp:v8',
], ],
'include_dirs': [ 'include_dirs': [
'..', '..',
...@@ -216,6 +223,8 @@ ...@@ -216,6 +223,8 @@
'sources': [ 'sources': [
# Note: sources list duplicated in GN build. # Note: sources list duplicated in GN build.
'translate/content/renderer/renderer_cld_data_provider.h', 'translate/content/renderer/renderer_cld_data_provider.h',
'translate/content/renderer/translate_helper.cc',
'translate/content/renderer/translate_helper.h',
], ],
'conditions': [ 'conditions': [
['cld_version==0 or cld_version==2', { ['cld_version==0 or cld_version==2', {
......
...@@ -7,12 +7,21 @@ import("//build/config/features.gni") ...@@ -7,12 +7,21 @@ import("//build/config/features.gni")
static_library("renderer") { static_library("renderer") {
sources = [ sources = [
"renderer_cld_data_provider.h", "renderer_cld_data_provider.h",
"translate_helper.cc",
"translate_helper.h",
] ]
deps = [ deps = [
"//base", "//base",
"//components/translate/content/common",
"//components/translate/core/common",
"//components/translate/core/language_detection",
"//content/public/common", "//content/public/common",
"//content/public/renderer",
"//ipc", "//ipc",
"//third_party/WebKit/public:blink",
"//url",
"//v8",
] ]
if (cld_version == 0 || cld_version == 2) { if (cld_version == 0 || cld_version == 2) {
......
include_rules = [ include_rules = [
"+content/public/renderer", "+content/public/renderer",
"+third_party/cld_2", "+third_party/cld_2",
"+third_party/WebKit/public/web",
"+v8",
] ]
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_RENDERER_TRANSLATE_TRANSLATE_HELPER_H_ #ifndef COMPONENTS_TRANSLATE_CONTENT_RENDERER_TRANSLATE_HELPER_H_
#define CHROME_RENDERER_TRANSLATE_TRANSLATE_HELPER_H_ #define COMPONENTS_TRANSLATE_CONTENT_RENDERER_TRANSLATE_HELPER_H_
#include <string> #include <string>
...@@ -26,6 +26,8 @@ namespace content { ...@@ -26,6 +26,8 @@ namespace content {
class RendererCldDataProvider; class RendererCldDataProvider;
} }
namespace translate {
// This class deals with page translation. // This class deals with page translation.
// There is one TranslateHelper per RenderView. // There is one TranslateHelper per RenderView.
// //
...@@ -77,7 +79,10 @@ class RendererCldDataProvider; ...@@ -77,7 +79,10 @@ class RendererCldDataProvider;
// message to be sent to the browser process immediately. // message to be sent to the browser process immediately.
class TranslateHelper : public content::RenderViewObserver { class TranslateHelper : public content::RenderViewObserver {
public: public:
explicit TranslateHelper(content::RenderView* render_view); explicit TranslateHelper(content::RenderView* render_view,
int world_id,
int extension_group,
const std::string& extension_scheme);
virtual ~TranslateHelper(); virtual ~TranslateHelper();
// Informs us that the page's text has been extracted. // Informs us that the page's text has been extracted.
...@@ -195,7 +200,7 @@ class TranslateHelper : public content::RenderViewObserver { ...@@ -195,7 +200,7 @@ class TranslateHelper : public content::RenderViewObserver {
// Sends a message to the browser to notify it that the translation failed // Sends a message to the browser to notify it that the translation failed
// with |error|. // with |error|.
void NotifyBrowserTranslationFailed(translate::TranslateErrors::Type error); void NotifyBrowserTranslationFailed(TranslateErrors::Type error);
// Convenience method to access the main frame. Can return NULL, typically // Convenience method to access the main frame. Can return NULL, typically
// if the page is being closed. // if the page is being closed.
...@@ -239,7 +244,7 @@ class TranslateHelper : public content::RenderViewObserver { ...@@ -239,7 +244,7 @@ class TranslateHelper : public content::RenderViewObserver {
base::TimeTicks language_determined_time_; base::TimeTicks language_determined_time_;
// Provides CLD data for this process. // Provides CLD data for this process.
scoped_ptr<translate::RendererCldDataProvider> cld_data_provider_; scoped_ptr<RendererCldDataProvider> cld_data_provider_;
// Whether or not polling for CLD2 data has started. // Whether or not polling for CLD2 data has started.
bool cld_data_polling_started_; bool cld_data_polling_started_;
...@@ -255,6 +260,15 @@ class TranslateHelper : public content::RenderViewObserver { ...@@ -255,6 +260,15 @@ class TranslateHelper : public content::RenderViewObserver {
// deferred_page_capture_ is true. // deferred_page_capture_ is true.
int deferred_page_seq_no_; int deferred_page_seq_no_;
// The world ID to use for script execution.
int world_id_;
// The extension group.
int extension_group_;
// The URL scheme for translate extensions.
std::string extension_scheme_;
// The contents of the page most recently reported to PageCaptured if // The contents of the page most recently reported to PageCaptured if
// deferred_page_capture_ is true. // deferred_page_capture_ is true.
base::string16 deferred_contents_; base::string16 deferred_contents_;
...@@ -265,4 +279,6 @@ class TranslateHelper : public content::RenderViewObserver { ...@@ -265,4 +279,6 @@ class TranslateHelper : public content::RenderViewObserver {
DISALLOW_COPY_AND_ASSIGN(TranslateHelper); DISALLOW_COPY_AND_ASSIGN(TranslateHelper);
}; };
#endif // CHROME_RENDERER_TRANSLATE_TRANSLATE_HELPER_H_ } // namespace translate
#endif // COMPONENTS_TRANSLATE_CONTENT_RENDERER_TRANSLATE_HELPER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment