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

Side by Side Diff: chrome/browser/extensions/extension_tabs_module.cc

Issue 79070: createWindow api call. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_tabs_module.h" 5 #include "chrome/browser/extensions/extension_tabs_module.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "chrome/browser/browser.h" 8 #include "chrome/browser/browser.h"
9 #include "chrome/browser/browser_list.h" 9 #include "chrome/browser/browser_list.h"
10 #include "chrome/browser/extensions/extension_function_dispatcher.h" 10 #include "chrome/browser/extensions/extension_function_dispatcher.h"
11 #include "chrome/browser/renderer_host/render_view_host_delegate.h"
11 #include "chrome/browser/tab_contents/navigation_entry.h" 12 #include "chrome/browser/tab_contents/navigation_entry.h"
12 13
14 // TODO(port): Port these files.
15 #if defined(OS_WIN)
16 #include "chrome/browser/window_sizer.h"
17 #else
18 #include "chrome/common/temp_scaffolding_stubs.h"
19 #endif
20
13 // Forward declare static helper functions defined below. 21 // Forward declare static helper functions defined below.
14 static DictionaryValue* CreateWindowValue(Browser* browser); 22 static DictionaryValue* CreateWindowValue(Browser* browser);
15 static ListValue* CreateTabList(Browser* browser); 23 static ListValue* CreateTabList(Browser* browser);
16 static DictionaryValue* CreateTabValue(TabStripModel* tab_strip_model, 24 static DictionaryValue* CreateTabValue(TabStripModel* tab_strip_model,
17 int tab_index); 25 int tab_index);
18 static bool GetIndexOfTabId(const TabStripModel* tab_strip, int tab_id, 26 static bool GetIndexOfTabId(const TabStripModel* tab_strip, int tab_id,
19 int* tab_index); 27 int* tab_index);
20 28
21 // ExtensionTabUtil 29 // ExtensionTabUtil
22 int ExtensionTabUtil::GetWindowId(const Browser* browser) { 30 int ExtensionTabUtil::GetWindowId(const Browser* browser) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 if (all_windows || (window_ids.find(ExtensionTabUtil::GetWindowId(*browser)) 73 if (all_windows || (window_ids.find(ExtensionTabUtil::GetWindowId(*browser))
66 != window_ids.end())) { 74 != window_ids.end())) {
67 static_cast<ListValue*>(result_.get())->Append( 75 static_cast<ListValue*>(result_.get())->Append(
68 CreateWindowValue(*browser)); 76 CreateWindowValue(*browser));
69 } 77 }
70 } 78 }
71 79
72 return true; 80 return true;
73 } 81 }
74 82
83 bool CreateWindowFunction::RunImpl() {
84 scoped_ptr<GURL> url(new GURL());
85
86 // Look for optional url.
87 if (args_->IsType(Value::TYPE_DICTIONARY)) {
88 const DictionaryValue *args = static_cast<const DictionaryValue*>(args_);
89 std::string url_input;
90 if (args->GetString(L"url", &url_input)) {
91 url.reset(new GURL(url_input));
92 if (!url->is_valid()) {
93 // TODO(rafaelw): need error message/callback here
94 return false;
95 }
96 }
97 }
98
99 // Try to get the browser associated with view that this call came from, so
100 // its position can be set relative to its browser window.
101 Browser* browser = dispatcher_->browser();
102 if (browser == NULL)
103 browser = BrowserList::GetLastActiveWithProfile(dispatcher_->profile());
104
105 // Try to position the new browser relative its originating browser window.
106 gfx::Rect empty_bounds;
107 gfx::Rect bounds;
108 bool maximized;
109 // The call offsets the bounds by kWindowTilePixels (defined in WindowSizer to
110 // be 10).
111 WindowSizer::GetBrowserWindowBounds(std::wstring(), empty_bounds, browser,
112 &bounds, &maximized);
113
114 // Any part of the bounds can optionally be set by the caller.
115 if (args_->IsType(Value::TYPE_DICTIONARY)) {
116 const DictionaryValue *args = static_cast<const DictionaryValue*>(args_);
117 int bounds_val;
118 if (args->GetInteger(L"left", &bounds_val))
119 bounds.set_x(bounds_val);
120
121 if (args->GetInteger(L"top", &bounds_val))
122 bounds.set_y(bounds_val);
123
124 if (args->GetInteger(L"width", &bounds_val))
125 bounds.set_width(bounds_val);
126
127 if (args->GetInteger(L"height", &bounds_val))
128 bounds.set_height(bounds_val);
129 }
130
131 Browser *new_window = Browser::Create(dispatcher_->profile());
132 if (url->is_valid()) {
133 new_window->AddTabWithURL(*(url.get()),
134 GURL(), PageTransition::LINK,
135 true, -1, NULL);
136 } else {
137 new_window->NewTab();
138 }
139 new_window->window()->SetBounds(bounds);
140 new_window->window()->Show();
141
142 // TODO(rafaelw): support |focused|, |zIndex|
143
144 result_.reset(CreateWindowValue(new_window));
145
146 return true;
147 }
148
75 bool GetTabsForWindowFunction::RunImpl() { 149 bool GetTabsForWindowFunction::RunImpl() {
76 if (!args_->IsType(Value::TYPE_NULL)) 150 if (!args_->IsType(Value::TYPE_NULL))
77 return false; 151 return false;
78 152
79 Browser* browser = BrowserList::GetLastActive(); 153 Browser* browser = BrowserList::GetLastActive();
80 if (!browser) 154 if (!browser)
81 return false; 155 return false;
82 156
83 result_.reset(CreateTabList(browser)); 157 result_.reset(CreateTabList(browser));
84 158
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 args->GetInteger(L"index", &index); 190 args->GetInteger(L"index", &index);
117 if (index < 0) { 191 if (index < 0) {
118 // Default insert behavior 192 // Default insert behavior
119 index = -1; 193 index = -1;
120 } 194 }
121 if (index > tab_strip->count()) { 195 if (index > tab_strip->count()) {
122 index = tab_strip->count(); 196 index = tab_strip->count();
123 } 197 }
124 198
125 TabContents* contents = browser->AddTabWithURL(GURL(url), GURL(), 199 TabContents* contents = browser->AddTabWithURL(GURL(url), GURL(),
126 PageTransition::TYPED, selected, index, NULL); 200 PageTransition::LINK, selected, index, NULL);
127 index = tab_strip->GetIndexOfTabContents(contents); 201 index = tab_strip->GetIndexOfTabContents(contents);
128 202
129 // Return data about the newly created tab. 203 // Return data about the newly created tab.
130 if (has_callback()) 204 if (has_callback())
131 result_.reset(CreateTabValue(tab_strip, index)); 205 result_.reset(CreateTabValue(tab_strip, index));
132 206
133 return true; 207 return true;
134 } 208 }
135 209
136 bool GetTabFunction::RunImpl() { 210 bool GetTabFunction::RunImpl() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 253
180 // TODO(rafaelw): handle setting remaining tab properties: 254 // TODO(rafaelw): handle setting remaining tab properties:
181 // -title 255 // -title
182 // -favIconUrl 256 // -favIconUrl
183 257
184 // Navigate the tab to a new location if the url different. 258 // Navigate the tab to a new location if the url different.
185 std::string url; 259 std::string url;
186 if (args->GetString(L"url", &url)) { 260 if (args->GetString(L"url", &url)) {
187 GURL new_gurl(url); 261 GURL new_gurl(url);
188 if (new_gurl.is_valid()) { 262 if (new_gurl.is_valid()) {
189 controller.LoadURL(new_gurl, GURL(), PageTransition::TYPED); 263 controller.LoadURL(new_gurl, GURL(), PageTransition::LINK);
190 } else { 264 } else {
191 // TODO(rafaelw): return some reasonable error? 265 // TODO(rafaelw): return some reasonable error?
192 } 266 }
193 } 267 }
194 268
195 bool selected; 269 bool selected;
196 // TODO(rafaelw): Setting |selected| from js doesn't make much sense. 270 // TODO(rafaelw): Setting |selected| from js doesn't make much sense.
197 // Move tab selection management up to window. 271 // Move tab selection management up to window.
198 if (args->GetBoolean(L"selected", &selected) && 272 if (args->GetBoolean(L"selected", &selected) &&
199 selected && 273 selected &&
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 int* tab_index) { 399 int* tab_index) {
326 for (int i = 0; i < tab_strip->count(); ++i) { 400 for (int i = 0; i < tab_strip->count(); ++i) {
327 TabContents* tab_contents = tab_strip->GetTabContentsAt(i); 401 TabContents* tab_contents = tab_strip->GetTabContentsAt(i);
328 if (tab_contents->controller().session_id().id() == tab_id) { 402 if (tab_contents->controller().session_id().id() == tab_id) {
329 *tab_index = i; 403 *tab_index = i;
330 return true; 404 return true;
331 } 405 }
332 } 406 }
333 return false; 407 return false;
334 } 408 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_tabs_module.h ('k') | chrome/browser/extensions/extension_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698