| Index: chrome/browser/extensions/extension_tabs_module.cc
|
| ===================================================================
|
| --- chrome/browser/extensions/extension_tabs_module.cc (revision 35721)
|
| +++ chrome/browser/extensions/extension_tabs_module.cc (working copy)
|
| @@ -839,15 +839,24 @@
|
| return false;
|
| }
|
|
|
| - // 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();
|
| + 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.
|
| registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED,
|
| - NotificationService::AllSources());
|
| - AddRef(); // balanced in Observe()
|
| + Source<RenderViewHost>(contents->render_view_host()));
|
| +
|
| return true;
|
| }
|
|
|
| @@ -856,9 +865,16 @@
|
| 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
|
|
|