summaryrefslogtreecommitdiffstats
path: root/chrome/browser/renderer_host
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-07 21:41:50 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-07 21:41:50 +0000
commit807cb1036f557b8e24306c66a6bac9bfb0c804af (patch)
treeb10af2181ae1e2ce1640f868a217a868332ecc3e /chrome/browser/renderer_host
parent462474b9444dcda47b5c140f5d31b790610b6176 (diff)
downloadchromium_src-807cb1036f557b8e24306c66a6bac9bfb0c804af.zip
chromium_src-807cb1036f557b8e24306c66a6bac9bfb0c804af.tar.gz
chromium_src-807cb1036f557b8e24306c66a6bac9bfb0c804af.tar.bz2
Relanding the language detection code.
The code would crash if multiple PageContents notifications were received rapidly. The CLDHelper now notifies the TabContents directly and the TabContents ensures only one language detection can be performed at a time. Added unit-tests to validate these cases in web_contents_unittest.cc. Note that patch set 1 is the original patch, patch set 2 contains the new changes. Original review: http://codereview.chromium.org/492024/show BUG=30662 TEST=Run the unit-tests. Review URL: http://codereview.chromium.org/504051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35735 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host')
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.cc17
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.h2
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc35
-rw-r--r--chrome/browser/renderer_host/render_view_host.h20
-rw-r--r--chrome/browser/renderer_host/render_view_host_delegate.h6
5 files changed, 27 insertions, 53 deletions
diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc
index eac566b..ffa61f5 100644
--- a/chrome/browser/renderer_host/browser_render_process_host.cc
+++ b/chrome/browser/renderer_host/browser_render_process_host.cc
@@ -735,10 +735,9 @@ bool BrowserRenderProcessHost::Send(IPC::Message* msg) {
void BrowserRenderProcessHost::OnMessageReceived(const IPC::Message& msg) {
mark_child_process_activity_time();
if (msg.routing_id() == MSG_ROUTING_CONTROL) {
- // dispatch control messages
+ // Dispatch control messages.
bool msg_is_ok = true;
IPC_BEGIN_MESSAGE_MAP_EX(BrowserRenderProcessHost, msg, msg_is_ok)
- IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents)
IPC_MESSAGE_HANDLER(ViewHostMsg_UpdatedCacheStats,
OnUpdatedCacheStats)
IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged,
@@ -762,7 +761,7 @@ void BrowserRenderProcessHost::OnMessageReceived(const IPC::Message& msg) {
return;
}
- // dispatch incoming messages to the appropriate TabContents
+ // Dispatch incoming messages to the appropriate TabContents.
IPC::Channel::Listener* listener = GetListenerByID(msg.routing_id());
if (!listener) {
if (msg.is_sync()) {
@@ -836,18 +835,6 @@ void BrowserRenderProcessHost::OnChannelError() {
// TODO(darin): clean this up
}
-void BrowserRenderProcessHost::OnPageContents(const GURL& url,
- int32 page_id,
- const std::wstring& contents) {
- Profile* p = profile();
- if (!p || p->IsOffTheRecord())
- return;
-
- HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
- if (hs)
- hs->SetPageContents(url, contents);
-}
-
void BrowserRenderProcessHost::OnUpdatedCacheStats(
const WebCache::UsageStats& stats) {
WebCacheManager::GetInstance()->ObserveStats(id(), stats);
diff --git a/chrome/browser/renderer_host/browser_render_process_host.h b/chrome/browser/renderer_host/browser_render_process_host.h
index 3a6e83b..0fd51ea 100644
--- a/chrome/browser/renderer_host/browser_render_process_host.h
+++ b/chrome/browser/renderer_host/browser_render_process_host.h
@@ -104,8 +104,6 @@ class BrowserRenderProcessHost : public RenderProcessHost,
friend class VisitRelayingRenderProcessHost;
// Control message handlers.
- void OnPageContents(const GURL& url, int32 page_id,
- const std::wstring& contents);
void OnUpdatedCacheStats(const WebKit::WebCache::UsageStats& stats);
void SuddenTerminationChanged(bool enabled);
void OnExtensionAddListener(const std::string& event_name);
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index 1363afd..ad55180 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -46,8 +46,6 @@
#if defined(OS_WIN)
// TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
#include "chrome/browser/browser_accessibility_manager.h"
-// TODO(port): The compact language detection library works only for Windows.
-#include "third_party/cld/bar/toolbar/cld/i18n/encodings/compact_lang_det/win/cld_unicodetext.h"
#endif
using base::TimeDelta;
@@ -423,10 +421,6 @@ void RenderViewHost::StopFinding(bool clear_selection) {
Send(new ViewMsg_StopFinding(routing_id(), clear_selection));
}
-void RenderViewHost::GetPageLanguage() {
- Send(new ViewMsg_DeterminePageText(routing_id()));
-}
-
void RenderViewHost::Zoom(PageZoom::Function function) {
Send(new ViewMsg_Zoom(routing_id(), function));
}
@@ -759,8 +753,6 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
OnMsgDidFailProvisionalLoadWithError)
IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnMsgFindReply)
- IPC_MESSAGE_HANDLER(ViewMsg_DeterminePageText_Reply,
- OnDeterminePageTextReply)
IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCodeFinished,
OnExecuteCodeFinished)
IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFavIconURL, OnMsgUpdateFavIconURL)
@@ -844,6 +836,7 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(ViewHostMsg_AccessibilityFocusChange,
OnAccessibilityFocusChange)
IPC_MESSAGE_HANDLER(ViewHostMsg_OnCSSInserted, OnCSSInserted)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents)
// Have the super handle all other messages.
IPC_MESSAGE_UNHANDLED(RenderWidgetHost::OnMessageReceived(msg))
IPC_END_MESSAGE_MAP_EX()
@@ -1147,22 +1140,6 @@ void RenderViewHost::OnMsgFindReply(int request_id,
Send(new ViewMsg_FindReplyACK(routing_id()));
}
-void RenderViewHost::OnDeterminePageTextReply(
- const std::wstring& page_text) {
-#if defined(OS_WIN) // Only for windows.
- int num_languages = 0;
- bool is_reliable = false;
- const char* language_iso_code = LanguageCodeISO639_1(
- DetectLanguageOfUnicodeText(NULL, page_text.c_str(), true, &is_reliable,
- &num_languages, NULL));
- std::string language(language_iso_code);
- NotificationService::current()->Notify(
- NotificationType::TAB_LANGUAGE_DETERMINED,
- Source<RenderViewHost>(this),
- Details<std::string>(&language));
-#endif
-}
-
void RenderViewHost::OnExecuteCodeFinished(int request_id, bool success) {
std::pair<int, bool> result_details(request_id, success);
NotificationService::current()->Notify(
@@ -1783,3 +1760,13 @@ void RenderViewHost::OnAccessibilityFocusChange(int acc_obj_id) {
void RenderViewHost::OnCSSInserted() {
delegate_->DidInsertCSS();
}
+
+void RenderViewHost::OnPageContents(const GURL& url,
+ int32 page_id,
+ const std::wstring& contents) {
+ RenderViewHostDelegate::BrowserIntegration* integration_delegate =
+ delegate_->GetBrowserIntegrationDelegate();
+ if (!integration_delegate)
+ return;
+ integration_delegate->OnPageContents(url, process()->id(), page_id, contents);
+}
diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h
index 0d923ca..f3b1a32 100644
--- a/chrome/browser/renderer_host/render_view_host.h
+++ b/chrome/browser/renderer_host/render_view_host.h
@@ -212,12 +212,6 @@ class RenderViewHost : public RenderWidgetHost,
// clear the selection on the focused frame.
void StopFinding(bool clear_selection);
- // Get the most probable language of the text content in the tab. This sends
- // a message to the render view to get the content of the page as text. The
- // caller gets the language via the NotificationService by registering to the
- // NotificationType TAB_LANGUAGE_DETERMINED.
- void GetPageLanguage();
-
// Change the zoom level of a page.
void Zoom(PageZoom::Function function);
@@ -423,22 +417,22 @@ class RenderViewHost : public RenderWidgetHost,
// Creates a new RenderWidget with the given route id.
void CreateNewWidget(int route_id, bool activatable);
- // Send the response to an extension api call.
+ // Sends the response to an extension api call.
void SendExtensionResponse(int request_id, bool success,
const std::string& response,
const std::string& error);
- // Send a response to an extension api call that it was blocked for lack of
+ // Sends a response to an extension api call that it was blocked for lack of
// permission.
void BlockExtensionRequest(int request_id);
- // Notify the renderer that its view type has changed.
+ // Notifies the renderer that its view type has changed.
void ViewTypeChanged(ViewType::Type type);
- // Tell renderer which browser window it is being attached to.
+ // Tells the renderer which browser window it is being attached to.
void UpdateBrowserWindowId(int window_id);
- // Tell render view that custom context action has been selected.
+ // Tells the render view that a custom context action has been selected.
void PerformCustomContextMenuAction(unsigned action);
protected:
@@ -495,7 +489,6 @@ class RenderViewHost : public RenderWidgetHost,
const gfx::Rect& selection_rect,
int active_match_ordinal,
bool final_update);
- void OnDeterminePageTextReply(const std::wstring& tab_text);
void OnExecuteCodeFinished(int request_id, bool success);
void OnMsgUpdateFavIconURL(int32 page_id, const GURL& icon_url);
void OnMsgDidDownloadFavIcon(int id,
@@ -593,6 +586,9 @@ class RenderViewHost : public RenderWidgetHost,
void OnExtensionPostMessage(int port_id, const std::string& message);
void OnAccessibilityFocusChange(int acc_obj_id);
void OnCSSInserted();
+ void OnPageContents(const GURL& url,
+ int32 page_id,
+ const std::wstring& contents);
private:
friend class TestRenderViewHost;
diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h
index c3df62d..de3ef0b 100644
--- a/chrome/browser/renderer_host/render_view_host_delegate.h
+++ b/chrome/browser/renderer_host/render_view_host_delegate.h
@@ -217,6 +217,12 @@ class RenderViewHostDelegate {
virtual void OnDidGetApplicationInfo(
int32 page_id,
const webkit_glue::WebApplicationInfo& app_info) = 0;
+
+ // Notification that the contents of the page has been loaded.
+ virtual void OnPageContents(const GURL& url,
+ int renderer_process_id,
+ int32 page_id,
+ const std::wstring& contents) = 0;
};
// Resource ------------------------------------------------------------------