Index: chrome/browser/extensions/extension_tabs_module.cc |
=================================================================== |
--- chrome/browser/extensions/extension_tabs_module.cc (revision 35751) |
+++ chrome/browser/extensions/extension_tabs_module.cc (working copy) |
@@ -839,24 +839,15 @@ |
return false; |
} |
- AddRef(); // Balanced in GotLanguage() |
- |
- NavigationEntry* entry = contents->controller().GetActiveEntry(); |
- if (entry) { |
- std::string language = entry->language(); |
- if (!language.empty()) { |
- // Delay the callback invocation until after the current JS call has |
- // returned. |
- MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
- this, &DetectTabLanguageFunction::GotLanguage, language)); |
- return true; |
- } |
- } |
- // The tab contents does not know its language yet. Let's wait until it |
- // receives it. |
+ // Figure out what language |contents| contains. This sends an async call via |
+ // the browser to the renderer to determine the language of the tab the |
+ // renderer has. The renderer sends back the language of the tab after the |
+ // tab loads (it may be delayed) to the browser, which in turn notifies this |
+ // object that the language has been received. |
+ contents->GetPageLanguage(); |
registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, |
- Source<RenderViewHost>(contents->render_view_host())); |
- |
+ NotificationService::AllSources()); |
+ AddRef(); // balanced in Observe() |
return true; |
} |
@@ -865,16 +856,9 @@ |
const NotificationDetails& details) { |
DCHECK(type == NotificationType::TAB_LANGUAGE_DETERMINED); |
std::string language(*Details<std::string>(details).ptr()); |
- registrar_.Remove(this, NotificationType::TAB_LANGUAGE_DETERMINED, source); |
- |
- GotLanguage(language); |
-} |
- |
-void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
result_.reset(Value::CreateStringValue(language.c_str())); |
SendResponse(true); |
- |
- Release(); // Balanced in Run() |
+ Release(); // balanced in Run() |
} |
// static helpers |