Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Unified Diff: chrome/browser/extensions/extension_tabs_module.cc

Issue 504051: Relanding the language detection. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « chrome/browser/extensions/extension_tabs_module.h ('k') | chrome/browser/renderer_host/browser_render_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698