OLD | NEW |
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_error_utils.h" | 10 #include "chrome/browser/extensions/extension_error_utils.h" |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 new_window->window()->SetBounds(bounds); | 246 new_window->window()->SetBounds(bounds); |
247 new_window->window()->Show(); | 247 new_window->window()->Show(); |
248 | 248 |
249 // TODO(rafaelw): support |focused|, |zIndex| | 249 // TODO(rafaelw): support |focused|, |zIndex| |
250 | 250 |
251 result_.reset(CreateWindowValue(new_window, false)); | 251 result_.reset(CreateWindowValue(new_window, false)); |
252 | 252 |
253 return true; | 253 return true; |
254 } | 254 } |
255 | 255 |
| 256 bool UpdateWindowFunction::RunImpl() { |
| 257 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); |
| 258 const ListValue* args = static_cast<const ListValue*>(args_); |
| 259 int window_id; |
| 260 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &window_id)); |
| 261 DictionaryValue* update_props; |
| 262 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &update_props)); |
| 263 |
| 264 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, &error_); |
| 265 if (!browser) |
| 266 return false; |
| 267 |
| 268 gfx::Rect bounds = browser->window()->GetNormalBounds(); |
| 269 // Any part of the bounds can optionally be set by the caller. |
| 270 int bounds_val; |
| 271 if (update_props->HasKey(kLeftKey)) { |
| 272 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(kLeftKey, |
| 273 &bounds_val)); |
| 274 bounds.set_x(bounds_val); |
| 275 } |
| 276 |
| 277 if (update_props->HasKey(kTopKey)) { |
| 278 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(kTopKey, |
| 279 &bounds_val)); |
| 280 bounds.set_y(bounds_val); |
| 281 } |
| 282 |
| 283 if (update_props->HasKey(kWidthKey)) { |
| 284 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(kWidthKey, |
| 285 &bounds_val)); |
| 286 bounds.set_width(bounds_val); |
| 287 } |
| 288 |
| 289 if (update_props->HasKey(kHeightKey)) { |
| 290 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(kHeightKey, |
| 291 &bounds_val)); |
| 292 bounds.set_height(bounds_val); |
| 293 } |
| 294 |
| 295 // TODO(rafaelw): This call to SetBounds() ends up resulting in the target |
| 296 // window being activated (pushed to the front). On win32, this appears to be |
| 297 // the result of HWND event handling. |
| 298 browser->window()->SetBounds(bounds); |
| 299 // TODO(rafaelw): Support |focused|. |
| 300 result_.reset(CreateWindowValue(browser, false)); |
| 301 |
| 302 return true; |
| 303 } |
| 304 |
256 bool RemoveWindowFunction::RunImpl() { | 305 bool RemoveWindowFunction::RunImpl() { |
257 int window_id; | 306 int window_id; |
258 EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&window_id)); | 307 EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&window_id)); |
259 | 308 |
260 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, &error_); | 309 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, &error_); |
261 if (!browser) | 310 if (!browser) |
262 return false; | 311 return false; |
263 | 312 |
264 browser->CloseWindow(); | 313 browser->CloseWindow(); |
265 | 314 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 } | 618 } |
570 | 619 |
571 static bool GetTabById(int tab_id, Profile* profile, Browser** browser, | 620 static bool GetTabById(int tab_id, Profile* profile, Browser** browser, |
572 TabStripModel** tab_strip, | 621 TabStripModel** tab_strip, |
573 TabContents** contents, | 622 TabContents** contents, |
574 int* tab_index, | 623 int* tab_index, |
575 std::string* error_message) { | 624 std::string* error_message) { |
576 if (ExtensionTabUtil::GetTabById(tab_id, profile, browser, tab_strip, | 625 if (ExtensionTabUtil::GetTabById(tab_id, profile, browser, tab_strip, |
577 contents, tab_index)) | 626 contents, tab_index)) |
578 return true; | 627 return true; |
579 | 628 |
580 if (error_message) | 629 if (error_message) |
581 *error_message = ExtensionErrorUtils::FormatErrorMessage( | 630 *error_message = ExtensionErrorUtils::FormatErrorMessage( |
582 kTabNotFoundError, IntToString(tab_id)); | 631 kTabNotFoundError, IntToString(tab_id)); |
583 | 632 |
584 return false; | 633 return false; |
585 } | 634 } |
OLD | NEW |