diff options
-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_; |