| 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 "app/gfx/codec/jpeg_codec.h" | 7 #include "app/gfx/codec/jpeg_codec.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
| 10 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 return false; | 235 return false; |
| 236 } | 236 } |
| 237 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); | 237 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); |
| 238 return true; | 238 return true; |
| 239 } | 239 } |
| 240 | 240 |
| 241 bool GetAllWindowsFunction::RunImpl() { | 241 bool GetAllWindowsFunction::RunImpl() { |
| 242 bool populate_tabs = false; | 242 bool populate_tabs = false; |
| 243 if (!args_->IsType(Value::TYPE_NULL)) { | 243 if (!args_->IsType(Value::TYPE_NULL)) { |
| 244 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); | 244 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); |
| 245 const DictionaryValue* args = static_cast<const DictionaryValue*>(args_); | 245 const DictionaryValue* args = args_as_dictionary(); |
| 246 if (args->HasKey(keys::kPopulateKey)) { | 246 if (args->HasKey(keys::kPopulateKey)) { |
| 247 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kPopulateKey, | 247 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kPopulateKey, |
| 248 &populate_tabs)); | 248 &populate_tabs)); |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 | 251 |
| 252 result_.reset(new ListValue()); | 252 result_.reset(new ListValue()); |
| 253 for (BrowserList::const_iterator browser = BrowserList::begin(); | 253 for (BrowserList::const_iterator browser = BrowserList::begin(); |
| 254 browser != BrowserList::end(); ++browser) { | 254 browser != BrowserList::end(); ++browser) { |
| 255 // Only examine browsers in the current profile. | 255 // Only examine browsers in the current profile. |
| 256 if ((*browser)->profile() == profile()) { | 256 if ((*browser)->profile() == profile()) { |
| 257 static_cast<ListValue*>(result_.get())-> | 257 static_cast<ListValue*>(result_.get())-> |
| 258 Append(ExtensionTabUtil::CreateWindowValue(*browser, populate_tabs)); | 258 Append(ExtensionTabUtil::CreateWindowValue(*browser, populate_tabs)); |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 | 261 |
| 262 return true; | 262 return true; |
| 263 } | 263 } |
| 264 | 264 |
| 265 bool CreateWindowFunction::RunImpl() { | 265 bool CreateWindowFunction::RunImpl() { |
| 266 scoped_ptr<GURL> url(new GURL()); | 266 scoped_ptr<GURL> url(new GURL()); |
| 267 | 267 |
| 268 // Look for optional url. | 268 // Look for optional url. |
| 269 if (!args_->IsType(Value::TYPE_NULL)) { | 269 if (!args_->IsType(Value::TYPE_NULL)) { |
| 270 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); | 270 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); |
| 271 const DictionaryValue *args = static_cast<const DictionaryValue*>(args_); | 271 const DictionaryValue *args = args_as_dictionary(); |
| 272 std::string url_input; | 272 std::string url_input; |
| 273 if (args->HasKey(keys::kUrlKey)) { | 273 if (args->HasKey(keys::kUrlKey)) { |
| 274 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kUrlKey, | 274 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kUrlKey, |
| 275 &url_input)); | 275 &url_input)); |
| 276 url.reset(new GURL(url_input)); | 276 url.reset(new GURL(url_input)); |
| 277 if (!url->is_valid()) { | 277 if (!url->is_valid()) { |
| 278 // The path as passed in is not valid. Try converting to absolute path. | 278 // The path as passed in is not valid. Try converting to absolute path. |
| 279 *url = GetExtension()->GetResourceURL(url_input); | 279 *url = GetExtension()->GetResourceURL(url_input); |
| 280 if (!url->is_valid()) { | 280 if (!url->is_valid()) { |
| 281 error_ = ExtensionErrorUtils::FormatErrorMessage( | 281 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 295 // be 10) | 295 // be 10) |
| 296 // | 296 // |
| 297 // NOTE(rafaelw): It's ok if dispatcher_->GetBrowser() returns NULL here. | 297 // NOTE(rafaelw): It's ok if dispatcher_->GetBrowser() returns NULL here. |
| 298 // GetBrowserWindowBounds will default to saved "default" values for the app. | 298 // GetBrowserWindowBounds will default to saved "default" values for the app. |
| 299 WindowSizer::GetBrowserWindowBounds(std::wstring(), empty_bounds, | 299 WindowSizer::GetBrowserWindowBounds(std::wstring(), empty_bounds, |
| 300 dispatcher()->GetBrowser(), &bounds, | 300 dispatcher()->GetBrowser(), &bounds, |
| 301 &maximized); | 301 &maximized); |
| 302 | 302 |
| 303 // Any part of the bounds can optionally be set by the caller. | 303 // Any part of the bounds can optionally be set by the caller. |
| 304 if (args_->IsType(Value::TYPE_DICTIONARY)) { | 304 if (args_->IsType(Value::TYPE_DICTIONARY)) { |
| 305 const DictionaryValue *args = static_cast<const DictionaryValue*>(args_); | 305 const DictionaryValue *args = args_as_dictionary(); |
| 306 int bounds_val; | 306 int bounds_val; |
| 307 if (args->HasKey(keys::kLeftKey)) { | 307 if (args->HasKey(keys::kLeftKey)) { |
| 308 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kLeftKey, | 308 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kLeftKey, |
| 309 &bounds_val)); | 309 &bounds_val)); |
| 310 bounds.set_x(bounds_val); | 310 bounds.set_x(bounds_val); |
| 311 } | 311 } |
| 312 | 312 |
| 313 if (args->HasKey(keys::kTopKey)) { | 313 if (args->HasKey(keys::kTopKey)) { |
| 314 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTopKey, | 314 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTopKey, |
| 315 &bounds_val)); | 315 &bounds_val)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 338 | 338 |
| 339 // TODO(rafaelw): support |focused|, |zIndex| | 339 // TODO(rafaelw): support |focused|, |zIndex| |
| 340 | 340 |
| 341 result_.reset(ExtensionTabUtil::CreateWindowValue(new_window, false)); | 341 result_.reset(ExtensionTabUtil::CreateWindowValue(new_window, false)); |
| 342 | 342 |
| 343 return true; | 343 return true; |
| 344 } | 344 } |
| 345 | 345 |
| 346 bool UpdateWindowFunction::RunImpl() { | 346 bool UpdateWindowFunction::RunImpl() { |
| 347 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); | 347 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); |
| 348 const ListValue* args = static_cast<const ListValue*>(args_); | 348 const ListValue* args = args_as_list(); |
| 349 int window_id; | 349 int window_id; |
| 350 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &window_id)); | 350 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &window_id)); |
| 351 DictionaryValue* update_props; | 351 DictionaryValue* update_props; |
| 352 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &update_props)); | 352 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &update_props)); |
| 353 | 353 |
| 354 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, &error_); | 354 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, &error_); |
| 355 if (!browser) | 355 if (!browser) |
| 356 return false; | 356 return false; |
| 357 | 357 |
| 358 gfx::Rect bounds = browser->window()->GetRestoredBounds(); | 358 gfx::Rect bounds = browser->window()->GetRestoredBounds(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 if (!browser) | 450 if (!browser) |
| 451 return false; | 451 return false; |
| 452 | 452 |
| 453 result_.reset(ExtensionTabUtil::CreateTabList(browser)); | 453 result_.reset(ExtensionTabUtil::CreateTabList(browser)); |
| 454 | 454 |
| 455 return true; | 455 return true; |
| 456 } | 456 } |
| 457 | 457 |
| 458 bool CreateTabFunction::RunImpl() { | 458 bool CreateTabFunction::RunImpl() { |
| 459 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); | 459 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); |
| 460 const DictionaryValue* args = static_cast<const DictionaryValue*>(args_); | 460 const DictionaryValue* args = args_as_dictionary(); |
| 461 | 461 |
| 462 Browser *browser; | 462 Browser *browser; |
| 463 // windowId defaults to "current" window. | 463 // windowId defaults to "current" window. |
| 464 int window_id = -1; | 464 int window_id = -1; |
| 465 if (args->HasKey(keys::kWindowIdKey)) { | 465 if (args->HasKey(keys::kWindowIdKey)) { |
| 466 EXTENSION_FUNCTION_VALIDATE(args->GetInteger( | 466 EXTENSION_FUNCTION_VALIDATE(args->GetInteger( |
| 467 keys::kWindowIdKey, &window_id)); | 467 keys::kWindowIdKey, &window_id)); |
| 468 browser = GetBrowserInProfileWithId(profile(), window_id, &error_); | 468 browser = GetBrowserInProfileWithId(profile(), window_id, &error_); |
| 469 } else { | 469 } else { |
| 470 browser = dispatcher()->GetBrowser(); | 470 browser = dispatcher()->GetBrowser(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 return false; | 541 return false; |
| 542 | 542 |
| 543 result_.reset(ExtensionTabUtil::CreateTabValue(contents, tab_strip, | 543 result_.reset(ExtensionTabUtil::CreateTabValue(contents, tab_strip, |
| 544 tab_index)); | 544 tab_index)); |
| 545 return true; | 545 return true; |
| 546 } | 546 } |
| 547 | 547 |
| 548 bool UpdateTabFunction::RunImpl() { | 548 bool UpdateTabFunction::RunImpl() { |
| 549 int tab_id; | 549 int tab_id; |
| 550 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); | 550 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); |
| 551 const ListValue* args = static_cast<const ListValue*>(args_); | 551 const ListValue* args = args_as_list(); |
| 552 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &tab_id)); | 552 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &tab_id)); |
| 553 DictionaryValue* update_props; | 553 DictionaryValue* update_props; |
| 554 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &update_props)); | 554 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &update_props)); |
| 555 | 555 |
| 556 TabStripModel* tab_strip = NULL; | 556 TabStripModel* tab_strip = NULL; |
| 557 TabContents* contents = NULL; | 557 TabContents* contents = NULL; |
| 558 int tab_index = -1; | 558 int tab_index = -1; |
| 559 if (!GetTabById(tab_id, profile(), NULL, &tab_strip, &contents, &tab_index, | 559 if (!GetTabById(tab_id, profile(), NULL, &tab_strip, &contents, &tab_index, |
| 560 &error_)) | 560 &error_)) |
| 561 return false; | 561 return false; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 if (has_callback()) | 621 if (has_callback()) |
| 622 result_.reset(ExtensionTabUtil::CreateTabValue(contents, tab_strip, | 622 result_.reset(ExtensionTabUtil::CreateTabValue(contents, tab_strip, |
| 623 tab_index)); | 623 tab_index)); |
| 624 | 624 |
| 625 return true; | 625 return true; |
| 626 } | 626 } |
| 627 | 627 |
| 628 bool MoveTabFunction::RunImpl() { | 628 bool MoveTabFunction::RunImpl() { |
| 629 int tab_id; | 629 int tab_id; |
| 630 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); | 630 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); |
| 631 const ListValue* args = static_cast<const ListValue*>(args_); | 631 const ListValue* args = args_as_list(); |
| 632 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &tab_id)); | 632 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &tab_id)); |
| 633 DictionaryValue* update_props; | 633 DictionaryValue* update_props; |
| 634 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &update_props)); | 634 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &update_props)); |
| 635 | 635 |
| 636 int new_index; | 636 int new_index; |
| 637 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( | 637 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( |
| 638 keys::kIndexKey, &new_index)); | 638 keys::kIndexKey, &new_index)); |
| 639 EXTENSION_FUNCTION_VALIDATE(new_index >= 0); | 639 EXTENSION_FUNCTION_VALIDATE(new_index >= 0); |
| 640 | 640 |
| 641 Browser* source_browser = NULL; | 641 Browser* source_browser = NULL; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 if (ExtensionTabUtil::GetTabById(tab_id, profile, browser, tab_strip, | 888 if (ExtensionTabUtil::GetTabById(tab_id, profile, browser, tab_strip, |
| 889 contents, tab_index)) | 889 contents, tab_index)) |
| 890 return true; | 890 return true; |
| 891 | 891 |
| 892 if (error_message) | 892 if (error_message) |
| 893 *error_message = ExtensionErrorUtils::FormatErrorMessage( | 893 *error_message = ExtensionErrorUtils::FormatErrorMessage( |
| 894 keys::kTabNotFoundError, IntToString(tab_id)); | 894 keys::kTabNotFoundError, IntToString(tab_id)); |
| 895 | 895 |
| 896 return false; | 896 return false; |
| 897 } | 897 } |
| OLD | NEW |