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

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

Issue 150062: [chromium-reviews] Add getLanguage function to tabs extension (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 20334)
+++ chrome/browser/extensions/extension_tabs_module.cc (working copy)
@@ -615,6 +615,52 @@
return true;
}
+bool GetTabLanguageFunction::RunImpl() {
+ int tab_id = 0;
+ Browser* browser = NULL;
+ TabContents* contents = NULL;
+
+ // If |tab_id| is specified, look for it. Otherwise default to selected tab
+ // in the current window.
+ if (!args_->IsType(Value::TYPE_NULL)) {
+ EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&tab_id));
+ if (!GetTabById(tab_id, profile(), &browser, NULL, &contents, NULL,
+ &error_)) {
+ return false;
+ }
+ if (!browser || !contents)
+ return false;
+ } else {
+ browser = dispatcher()->GetBrowser();
+ if (!browser)
+ return false;
+ contents = browser->tabstrip_model()->GetSelectedTabContents();
+ if (!contents)
+ 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();
+ registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED,
+ NotificationService::AllSources());
+ AddRef(); // balanced in Observe()
+ return true;
+}
+
+void GetTabLanguageFunction::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ DCHECK(type == NotificationType::TAB_LANGUAGE_DETERMINED);
+ std::string language(*Details<std::string>(details).ptr());
+ result_.reset(Value::CreateStringValue(language.c_str()));
+ SendResponse(true);
+ Release(); // balanced in Run()
+}
+
// static helpers
// if |populate| is true, each window gets a list property |tabs| which contains

Powered by Google App Engine
This is Rietveld 408576698