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

Side by Side 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, 8 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/browser.h"
6 #include "chrome/browser/browser_list.h"
7 #include "chrome/browser/extensions/extension_function_dispatcher.h"
8 #include "chrome/browser/extensions/extension_tabs_module.h"
9 #include "chrome/browser/tab_contents/navigation_entry.h"
10
11 // Forward declare static helper functions defined below
12 DictionaryValue* CreateTabValue(TabStripModel* tab_strip_model, int tab_index);
13
14 bool GetTabsForWindowFunction::RunImpl() {
15 if (!args_->IsType(Value::TYPE_NULL))
16 return false;
17
18 Browser* browser = BrowserList::GetLastActive();
19 if (!browser)
20 return false;
21
22 TabStripModel* tab_strip = browser->tabstrip_model();
23 result_.reset(new ListValue());
24 for (int i = 0; i < tab_strip->count(); ++i) {
25 static_cast<ListValue*>(result_.get())->Append(
26 CreateTabValue(tab_strip, i));
27 }
28
29 return true;
30 }
31
32 bool CreateTabFunction::RunImpl() {
33 // TODO(aa): Do data-driven validation in JS.
34 if (!args_->IsType(Value::TYPE_DICTIONARY))
35 return false;
36
37 Browser* browser = BrowserList::GetLastActive();
38 if (!browser)
39 return false;
40
41 // TODO(aa): Handle all the other properties of the new tab.
42 std::string url;
43 static_cast<const DictionaryValue*>(args_)->GetString(L"url", &url);
44 browser->AddTabWithURL(GURL(url), GURL(), PageTransition::TYPED, true, NULL);
45
46 // Return data about the newly created tab.
47 if (has_callback())
48 result_.reset(CreateTabValue(browser->tabstrip_model(),
49 browser->tabstrip_model()->count() - 1));
50
51 return true;
52 }
53
54
55 // static helpers
56 static DictionaryValue* CreateTabValue(TabStripModel* tab_strip,
57 int tab_index) {
58 TabContents* contents = tab_strip->GetTabContentsAt(tab_index);
59 NavigationController* controller = contents->controller();
60 DCHECK(controller); // TODO(aa): Is this a valid assumption?
61
62 DictionaryValue* result = new DictionaryValue();
63 result->SetInteger(L"id", controller->session_id().id());
64 result->SetInteger(L"windowId", controller->window_id().id());
65 result->SetString(L"url", contents->GetURL().spec());
66 result->SetString(L"title", contents->GetTitle());
67 result->SetBoolean(L"selected", tab_index == tab_strip->selected_index());
68
69 NavigationEntry* entry = controller->GetActiveEntry();
70 if (entry) {
71 if (entry->favicon().is_valid())
72 result->SetString(L"favIconUrl", entry->favicon().url().spec());
73 }
74
75 return result;
76 }
OLDNEW
« 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