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

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

Issue 42680: Add more of the server-side plumbing for extension APIs. Also (Closed)
Patch Set: Introduce SyncExtensionFunction Created 11 years, 9 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
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7856474aa5136a33f01d6b38b63720aafeeef641
--- /dev/null
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -0,0 +1,76 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_list.h"
+#include "chrome/browser/extensions/extension_function_dispatcher.h"
+#include "chrome/browser/extensions/extension_tabs_module.h"
+#include "chrome/browser/tab_contents/navigation_entry.h"
+
+// Forward declare static helper functions defined below
+DictionaryValue* CreateTabValue(TabStripModel* tab_strip_model, int tab_index);
+
+bool GetTabsForWindowFunction::RunImpl() {
+ if (!args_->IsType(Value::TYPE_NULL))
+ return false;
+
+ Browser* browser = BrowserList::GetLastActive();
+ if (!browser)
+ return false;
+
+ TabStripModel* tab_strip = browser->tabstrip_model();
+ result_.reset(new ListValue());
+ for (int i = 0; i < tab_strip->count(); ++i) {
+ static_cast<ListValue*>(result_.get())->Append(
+ CreateTabValue(tab_strip, i));
+ }
+
+ return true;
+}
+
+bool CreateTabFunction::RunImpl() {
+ // TODO(aa): Do data-driven validation in JS.
+ if (!args_->IsType(Value::TYPE_DICTIONARY))
+ return false;
+
+ Browser* browser = BrowserList::GetLastActive();
+ if (!browser)
+ return false;
+
+ // TODO(aa): Handle all the other properties of the new tab.
+ std::string url;
+ static_cast<const DictionaryValue*>(args_)->GetString(L"url", &url);
+ browser->AddTabWithURL(GURL(url), GURL(), PageTransition::TYPED, true, NULL);
+
+ // Return data about the newly created tab.
+ if (has_callback())
+ result_.reset(CreateTabValue(browser->tabstrip_model(),
+ browser->tabstrip_model()->count() - 1));
+
+ return true;
+}
+
+
+// static helpers
+static DictionaryValue* CreateTabValue(TabStripModel* tab_strip,
+ int tab_index) {
+ TabContents* contents = tab_strip->GetTabContentsAt(tab_index);
+ NavigationController* controller = contents->controller();
+ DCHECK(controller); // TODO(aa): Is this a valid assumption?
+
+ DictionaryValue* result = new DictionaryValue();
+ result->SetInteger(L"id", controller->session_id().id());
+ result->SetInteger(L"windowId", controller->window_id().id());
+ result->SetString(L"url", contents->GetURL().spec());
+ result->SetString(L"title", contents->GetTitle());
+ result->SetBoolean(L"selected", tab_index == tab_strip->selected_index());
+
+ NavigationEntry* entry = controller->GetActiveEntry();
+ if (entry) {
+ if (entry->favicon().is_valid())
+ result->SetString(L"favIconUrl", entry->favicon().url().spec());
+ }
+
+ return result;
+}
« 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