diff options
author | jcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-16 00:09:13 +0000 |
---|---|---|
committer | jcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-16 00:09:13 +0000 |
commit | 7faa5386330c0de8fbd5cde8e0daea2e810ec0a6 (patch) | |
tree | 997132106b735c53f79ad225fb30b76b9e5f4c27 /chrome | |
parent | 5c1304300d3cdeecb75aa85f0c207d65e0cbf6cf (diff) | |
download | chromium_src-7faa5386330c0de8fbd5cde8e0daea2e810ec0a6.zip chromium_src-7faa5386330c0de8fbd5cde8e0daea2e810ec0a6.tar.gz chromium_src-7faa5386330c0de8fbd5cde8e0daea2e810ec0a6.tar.bz2 |
Fix for a translate related crasher.
When a page was closed, a pending task on the TranslationHelper was accessing the WebView that would be NULL.
BUG=46584
TEST=None
Review URL: http://codereview.chromium.org/2852005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49863 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rwxr-xr-x | chrome/renderer/render_view.cc | 4 | ||||
-rw-r--r-- | chrome/renderer/translate_helper.cc | 20 | ||||
-rw-r--r-- | chrome/renderer/translate_helper.h | 7 |
3 files changed, 27 insertions, 4 deletions
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 5a43efe..b99adcd 100755 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -2190,6 +2190,10 @@ void RenderView::show(WebNavigationPolicy policy) { } void RenderView::closeWidgetSoon() { + // Cancel pending translations so that the translate_helper_ does not attempt + // to access the WebView. + translate_helper_.CancelPendingTranslation(); + if (script_can_close_) RenderWidget::closeWidgetSoon(); } diff --git a/chrome/renderer/translate_helper.cc b/chrome/renderer/translate_helper.cc index 1fea5b7..7caeec4 100644 --- a/chrome/renderer/translate_helper.cc +++ b/chrome/renderer/translate_helper.cc @@ -81,7 +81,7 @@ void TranslateHelper::RevertTranslation(int page_id) { return; } - WebFrame* main_frame = render_view_->webview()->mainFrame(); + WebFrame* main_frame = GetMainFrame(); if (!main_frame) return; @@ -213,7 +213,7 @@ void TranslateHelper::CheckTranslateStatus() { } bool TranslateHelper::ExecuteScript(const std::string& script) { - WebFrame* main_frame = render_view_->webview()->mainFrame(); + WebFrame* main_frame = GetMainFrame(); if (!main_frame) return false; main_frame->executeScript(WebScriptSource(ASCIIToUTF16(script))); @@ -223,7 +223,7 @@ bool TranslateHelper::ExecuteScript(const std::string& script) { bool TranslateHelper::ExecuteScriptAndGetBoolResult(const std::string& script, bool* value) { DCHECK(value); - WebFrame* main_frame = render_view_->webview()->mainFrame(); + WebFrame* main_frame = GetMainFrame(); if (!main_frame) return false; @@ -239,7 +239,7 @@ bool TranslateHelper::ExecuteScriptAndGetBoolResult(const std::string& script, bool TranslateHelper::ExecuteScriptAndGetStringResult(const std::string& script, std::string* value) { DCHECK(value); - WebFrame* main_frame = render_view_->webview()->mainFrame(); + WebFrame* main_frame = GetMainFrame(); if (!main_frame) return false; @@ -292,3 +292,15 @@ void TranslateHelper::NotifyBrowserTranslationFailed( render_view_->Send(new ViewHostMsg_PageTranslated( render_view_->routing_id(), page_id_, source_lang_, target_lang_, error)); } + +WebFrame* TranslateHelper::GetMainFrame() { + WebKit::WebView* web_view = render_view_->webview(); + if (!web_view) { + // When the WebView is going away, the render view should have called + // CancelPendingTranslation() which should have stopped any pending work, so + // that case should not happen. + NOTREACHED(); + return NULL; + } + return web_view->mainFrame(); +} diff --git a/chrome/renderer/translate_helper.h b/chrome/renderer/translate_helper.h index 8b55e8a..979f0f1 100644 --- a/chrome/renderer/translate_helper.h +++ b/chrome/renderer/translate_helper.h @@ -11,6 +11,9 @@ #include "chrome/common/translate_errors.h" class RenderView; +namespace WebKit { +class WebFrame; +} // This class deals with page translation. // There is one TranslateHelper per RenderView. @@ -99,6 +102,10 @@ class TranslateHelper { // with |error|. void NotifyBrowserTranslationFailed(TranslateErrors::Type error); + // Convenience method to access the main frame. Can return NULL, typically + // if the page is being closed. + WebKit::WebFrame* GetMainFrame(); + // The RenderView we are performing translations for. RenderView* render_view_; |