Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 URLFixerUpper::FixupURL(url.possibly_invalid_spec(), std::string()); | 131 URLFixerUpper::FixupURL(url.possibly_invalid_spec(), std::string()); |
| 132 return (fixed_url.SchemeIs(chrome::kChromeUIScheme) && | 132 return (fixed_url.SchemeIs(chrome::kChromeUIScheme) && |
| 133 (fixed_url.host() == chrome::kChromeUIBrowserCrashHost || | 133 (fixed_url.host() == chrome::kChromeUIBrowserCrashHost || |
| 134 fixed_url.host() == chrome::kChromeUICrashHost)); | 134 fixed_url.host() == chrome::kChromeUICrashHost)); |
| 135 } | 135 } |
| 136 | 136 |
| 137 // Reads the |value| as either a single integer value or a list of integers. | 137 // Reads the |value| as either a single integer value or a list of integers. |
| 138 bool ReadOneOrMoreIntegers( | 138 bool ReadOneOrMoreIntegers( |
| 139 Value* value, std::vector<int>* result) { | 139 Value* value, std::vector<int>* result) { |
| 140 if (value->IsType(Value::TYPE_INTEGER)) { | 140 if (value->IsType(Value::TYPE_INTEGER)) { |
| 141 int tab_id; | 141 int tab_id = -1; |
| 142 if (!value->GetAsInteger(&tab_id)) | 142 if (!value->GetAsInteger(&tab_id)) |
| 143 return false; | 143 return false; |
| 144 result->push_back(tab_id); | 144 result->push_back(tab_id); |
| 145 return true; | 145 return true; |
| 146 | 146 |
| 147 } else if (value->IsType(Value::TYPE_LIST)) { | 147 } else if (value->IsType(Value::TYPE_LIST)) { |
| 148 ListValue* tabs = static_cast<ListValue*>(value); | 148 ListValue* tabs = static_cast<ListValue*>(value); |
| 149 for (size_t i = 0; i < tabs->GetSize(); ++i) { | 149 for (size_t i = 0; i < tabs->GetSize(); ++i) { |
| 150 int tab_id; | 150 int tab_id = -1; |
| 151 if (!tabs->GetInteger(i, &tab_id)) | 151 if (!tabs->GetInteger(i, &tab_id)) |
| 152 return false; | 152 return false; |
| 153 result->push_back(tab_id); | 153 result->push_back(tab_id); |
| 154 } | 154 } |
| 155 return true; | 155 return true; |
| 156 } | 156 } |
| 157 return false; | 157 return false; |
| 158 } | 158 } |
| 159 | 159 |
| 160 // A three state enum to distinguish between when a boolean query argument is | 160 // A three state enum to distinguish between when a boolean query argument is |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 179 return value ? MATCH_TRUE : MATCH_FALSE; | 179 return value ? MATCH_TRUE : MATCH_FALSE; |
| 180 } | 180 } |
| 181 return NOT_SET; | 181 return NOT_SET; |
| 182 } | 182 } |
| 183 | 183 |
| 184 } // namespace | 184 } // namespace |
| 185 | 185 |
| 186 // Windows --------------------------------------------------------------------- | 186 // Windows --------------------------------------------------------------------- |
| 187 | 187 |
| 188 bool GetWindowFunction::RunImpl() { | 188 bool GetWindowFunction::RunImpl() { |
| 189 int window_id; | 189 int window_id = -1; |
|
Aaron Boodman
2011/12/19 02:40:00
Thanks for fixing bad older code. There was a lot
| |
| 190 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 190 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
| 191 | 191 |
| 192 bool populate_tabs = false; | |
| 193 if (HasOptionalArgument(1)) { | |
| 194 DictionaryValue* args = NULL; | |
| 195 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &args)); | |
| 196 | |
| 197 if (args->HasKey(keys::kPopulateKey)) { | |
| 198 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kPopulateKey, | |
| 199 &populate_tabs)); | |
| 200 } | |
| 201 } | |
| 202 | |
| 192 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, | 203 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, |
| 193 include_incognito(), &error_); | 204 include_incognito(), &error_); |
| 194 if (!browser || !browser->window()) { | 205 if (!browser || !browser->window()) { |
| 195 error_ = ExtensionErrorUtils::FormatErrorMessage( | 206 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 196 keys::kWindowNotFoundError, base::IntToString(window_id)); | 207 keys::kWindowNotFoundError, base::IntToString(window_id)); |
| 197 return false; | 208 return false; |
| 198 } | 209 } |
| 199 | 210 |
| 200 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); | 211 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); |
| 201 return true; | 212 return true; |
| 202 } | 213 } |
| 203 | 214 |
| 204 bool GetCurrentWindowFunction::RunImpl() { | 215 bool GetCurrentWindowFunction::RunImpl() { |
| 216 bool populate_tabs = false; | |
| 217 if (HasOptionalArgument(0)) { | |
| 218 DictionaryValue* args = NULL; | |
| 219 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | |
| 220 | |
| 221 if (args->HasKey(keys::kPopulateKey)) { | |
| 222 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kPopulateKey, | |
| 223 &populate_tabs)); | |
| 224 } | |
| 225 } | |
| 226 | |
| 205 Browser* browser = GetCurrentBrowser(); | 227 Browser* browser = GetCurrentBrowser(); |
| 206 if (!browser || !browser->window()) { | 228 if (!browser || !browser->window()) { |
| 207 error_ = keys::kNoCurrentWindowError; | 229 error_ = keys::kNoCurrentWindowError; |
| 208 return false; | 230 return false; |
| 209 } | 231 } |
| 210 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); | 232 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); |
| 211 return true; | 233 return true; |
| 212 } | 234 } |
| 213 | 235 |
| 214 bool GetLastFocusedWindowFunction::RunImpl() { | 236 bool GetLastFocusedWindowFunction::RunImpl() { |
| 237 bool populate_tabs = false; | |
| 238 if (HasOptionalArgument(0)) { | |
| 239 DictionaryValue* args = NULL; | |
| 240 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | |
| 241 | |
| 242 if (args->HasKey(keys::kPopulateKey)) { | |
| 243 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kPopulateKey, | |
| 244 &populate_tabs)); | |
| 245 } | |
| 246 } | |
| 247 | |
| 215 Browser* browser = BrowserList::FindAnyBrowser( | 248 Browser* browser = BrowserList::FindAnyBrowser( |
| 216 profile(), include_incognito()); | 249 profile(), include_incognito()); |
| 217 if (!browser || !browser->window()) { | 250 if (!browser || !browser->window()) { |
| 218 error_ = keys::kNoLastFocusedWindowError; | 251 error_ = keys::kNoLastFocusedWindowError; |
| 219 return false; | 252 return false; |
| 220 } | 253 } |
| 221 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); | 254 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); |
| 222 return true; | 255 return true; |
| 223 } | 256 } |
| 224 | 257 |
| 225 bool GetAllWindowsFunction::RunImpl() { | 258 bool GetAllWindowsFunction::RunImpl() { |
| 226 bool populate_tabs = false; | 259 bool populate_tabs = false; |
| 227 if (HasOptionalArgument(0)) { | 260 if (HasOptionalArgument(0)) { |
| 228 DictionaryValue* args; | 261 DictionaryValue* args = NULL; |
| 229 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 262 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 230 | 263 |
| 231 if (args->HasKey(keys::kPopulateKey)) { | 264 if (args->HasKey(keys::kPopulateKey)) { |
| 232 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kPopulateKey, | 265 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kPopulateKey, |
| 233 &populate_tabs)); | 266 &populate_tabs)); |
| 234 } | 267 } |
| 235 } | 268 } |
| 236 | 269 |
| 237 result_.reset(new ListValue()); | 270 result_.reset(new ListValue()); |
| 238 Profile* incognito_profile = | 271 Profile* incognito_profile = |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 error_ = keys::kNoCrashBrowserError; | 378 error_ = keys::kNoCrashBrowserError; |
| 346 return false; | 379 return false; |
| 347 } | 380 } |
| 348 urls.push_back(url); | 381 urls.push_back(url); |
| 349 } | 382 } |
| 350 } | 383 } |
| 351 } | 384 } |
| 352 | 385 |
| 353 // Look for optional tab id. | 386 // Look for optional tab id. |
| 354 if (args) { | 387 if (args) { |
| 355 int tab_id; | 388 int tab_id = -1; |
| 356 if (args->HasKey(keys::kTabIdKey)) { | 389 if (args->HasKey(keys::kTabIdKey)) { |
| 357 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTabIdKey, &tab_id)); | 390 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTabIdKey, &tab_id)); |
| 358 | 391 |
| 359 // Find the tab and detach it from the original window. | 392 // Find the tab and detach it from the original window. |
| 360 Browser* source_browser = NULL; | 393 Browser* source_browser = NULL; |
| 361 TabStripModel* source_tab_strip = NULL; | 394 TabStripModel* source_tab_strip = NULL; |
| 362 int tab_index = -1; | 395 int tab_index = -1; |
| 363 if (!GetTabById(tab_id, profile(), include_incognito(), | 396 if (!GetTabById(tab_id, profile(), include_incognito(), |
| 364 &source_browser, &source_tab_strip, &contents, | 397 &source_browser, &source_tab_strip, &contents, |
| 365 &tab_index, &error_)) | 398 &tab_index, &error_)) |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 396 popup_bounds = window_bounds; // Use window size as default for popups | 429 popup_bounds = window_bounds; // Use window size as default for popups |
| 397 #endif | 430 #endif |
| 398 | 431 |
| 399 Profile* window_profile = profile(); | 432 Profile* window_profile = profile(); |
| 400 Browser::Type window_type = Browser::TYPE_TABBED; | 433 Browser::Type window_type = Browser::TYPE_TABBED; |
| 401 bool focused = true; | 434 bool focused = true; |
| 402 bool saw_focus_key = false; | 435 bool saw_focus_key = false; |
| 403 std::string extension_id; | 436 std::string extension_id; |
| 404 | 437 |
| 405 // Decide whether we are opening a normal window or an incognito window. | 438 // Decide whether we are opening a normal window or an incognito window. |
| 406 bool is_error; | 439 bool is_error = true; |
| 407 bool open_incognito_window = ShouldOpenIncognitoWindow(args, &urls, | 440 bool open_incognito_window = ShouldOpenIncognitoWindow(args, &urls, |
| 408 &is_error); | 441 &is_error); |
| 409 if (is_error) { | 442 if (is_error) { |
| 410 // error_ member variable is set inside of ShouldOpenIncognitoWindow. | 443 // error_ member variable is set inside of ShouldOpenIncognitoWindow. |
| 411 return false; | 444 return false; |
| 412 } | 445 } |
| 413 if (open_incognito_window) { | 446 if (open_incognito_window) { |
| 414 window_profile = window_profile->GetOffTheRecordProfile(); | 447 window_profile = window_profile->GetOffTheRecordProfile(); |
| 415 } | 448 } |
| 416 | 449 |
| 417 if (args) { | 450 if (args) { |
| 418 // Any part of the bounds can optionally be set by the caller. | 451 // Any part of the bounds can optionally be set by the caller. |
| 419 int bounds_val; | 452 int bounds_val = -1; |
| 420 if (args->HasKey(keys::kLeftKey)) { | 453 if (args->HasKey(keys::kLeftKey)) { |
| 421 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kLeftKey, | 454 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kLeftKey, |
| 422 &bounds_val)); | 455 &bounds_val)); |
| 423 window_bounds.set_x(bounds_val); | 456 window_bounds.set_x(bounds_val); |
| 424 popup_bounds.set_x(bounds_val); | 457 popup_bounds.set_x(bounds_val); |
| 425 panel_bounds.set_x(bounds_val); | 458 panel_bounds.set_x(bounds_val); |
| 426 } | 459 } |
| 427 | 460 |
| 428 if (args->HasKey(keys::kTopKey)) { | 461 if (args->HasKey(keys::kTopKey)) { |
| 429 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTopKey, | 462 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTopKey, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 // Don't expose incognito windows if the extension isn't allowed. | 543 // Don't expose incognito windows if the extension isn't allowed. |
| 511 result_.reset(Value::CreateNullValue()); | 544 result_.reset(Value::CreateNullValue()); |
| 512 } else { | 545 } else { |
| 513 result_.reset(ExtensionTabUtil::CreateWindowValue(new_window, true)); | 546 result_.reset(ExtensionTabUtil::CreateWindowValue(new_window, true)); |
| 514 } | 547 } |
| 515 | 548 |
| 516 return true; | 549 return true; |
| 517 } | 550 } |
| 518 | 551 |
| 519 bool UpdateWindowFunction::RunImpl() { | 552 bool UpdateWindowFunction::RunImpl() { |
| 520 int window_id; | 553 int window_id = -1; |
| 521 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 554 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
| 522 DictionaryValue* update_props; | 555 DictionaryValue* update_props; |
| 523 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); | 556 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); |
| 524 | 557 |
| 525 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, | 558 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, |
| 526 include_incognito(), &error_); | 559 include_incognito(), &error_); |
| 527 if (!browser || !browser->window()) { | 560 if (!browser || !browser->window()) { |
| 528 error_ = ExtensionErrorUtils::FormatErrorMessage( | 561 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 529 keys::kWindowNotFoundError, base::IntToString(window_id)); | 562 keys::kWindowNotFoundError, base::IntToString(window_id)); |
| 530 return false; | 563 return false; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 if (draw_attention) | 666 if (draw_attention) |
| 634 browser->window()->FlashFrame(); | 667 browser->window()->FlashFrame(); |
| 635 } | 668 } |
| 636 | 669 |
| 637 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); | 670 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); |
| 638 | 671 |
| 639 return true; | 672 return true; |
| 640 } | 673 } |
| 641 | 674 |
| 642 bool RemoveWindowFunction::RunImpl() { | 675 bool RemoveWindowFunction::RunImpl() { |
| 643 int window_id; | 676 int window_id = -1; |
| 644 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 677 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
| 645 | 678 |
| 646 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, | 679 Browser* browser = GetBrowserInProfileWithId(profile(), window_id, |
| 647 include_incognito(), &error_); | 680 include_incognito(), &error_); |
| 648 if (!browser) | 681 if (!browser) |
| 649 return false; | 682 return false; |
| 650 | 683 |
| 651 // Don't let the extension remove the window if the user is dragging tabs | 684 // Don't let the extension remove the window if the user is dragging tabs |
| 652 // in that window. | 685 // in that window. |
| 653 if (!browser->IsTabStripEditable()) { | 686 if (!browser->IsTabStripEditable()) { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 795 result->Append(ExtensionTabUtil::CreateTabValue( | 828 result->Append(ExtensionTabUtil::CreateTabValue( |
| 796 tab_contents, tab_strip, i)); | 829 tab_contents, tab_strip, i)); |
| 797 } | 830 } |
| 798 } | 831 } |
| 799 | 832 |
| 800 result_.reset(result); | 833 result_.reset(result); |
| 801 return true; | 834 return true; |
| 802 } | 835 } |
| 803 | 836 |
| 804 bool CreateTabFunction::RunImpl() { | 837 bool CreateTabFunction::RunImpl() { |
| 805 DictionaryValue* args; | 838 DictionaryValue* args = NULL; |
| 806 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 839 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 807 | 840 |
| 808 Browser *browser; | 841 Browser *browser; |
| 809 // windowId defaults to "current" window. | 842 // windowId defaults to "current" window. |
| 810 int window_id = -1; | 843 int window_id = -1; |
| 811 if (args->HasKey(keys::kWindowIdKey)) { | 844 if (args->HasKey(keys::kWindowIdKey)) { |
| 812 EXTENSION_FUNCTION_VALIDATE(args->GetInteger( | 845 EXTENSION_FUNCTION_VALIDATE(args->GetInteger( |
| 813 keys::kWindowIdKey, &window_id)); | 846 keys::kWindowIdKey, &window_id)); |
| 814 browser = GetBrowserInProfileWithId(profile(), window_id, | 847 browser = GetBrowserInProfileWithId(profile(), window_id, |
| 815 include_incognito(), &error_); | 848 include_incognito(), &error_); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 params.target_contents->tab_contents(), | 939 params.target_contents->tab_contents(), |
| 907 params.browser->tabstrip_model(), | 940 params.browser->tabstrip_model(), |
| 908 params.browser->tabstrip_model()->GetIndexOfTabContents( | 941 params.browser->tabstrip_model()->GetIndexOfTabContents( |
| 909 params.target_contents))); | 942 params.target_contents))); |
| 910 } | 943 } |
| 911 | 944 |
| 912 return true; | 945 return true; |
| 913 } | 946 } |
| 914 | 947 |
| 915 bool GetTabFunction::RunImpl() { | 948 bool GetTabFunction::RunImpl() { |
| 916 int tab_id; | 949 int tab_id = -1; |
| 917 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); | 950 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); |
| 918 | 951 |
| 919 TabStripModel* tab_strip = NULL; | 952 TabStripModel* tab_strip = NULL; |
| 920 TabContentsWrapper* contents = NULL; | 953 TabContentsWrapper* contents = NULL; |
| 921 int tab_index = -1; | 954 int tab_index = -1; |
| 922 if (!GetTabById(tab_id, profile(), include_incognito(), | 955 if (!GetTabById(tab_id, profile(), include_incognito(), |
| 923 NULL, &tab_strip, &contents, &tab_index, &error_)) | 956 NULL, &tab_strip, &contents, &tab_index, &error_)) |
| 924 return false; | 957 return false; |
| 925 | 958 |
| 926 result_.reset(ExtensionTabUtil::CreateTabValue(contents->tab_contents(), | 959 result_.reset(ExtensionTabUtil::CreateTabValue(contents->tab_contents(), |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 994 selection.set_active(active_index); | 1027 selection.set_active(active_index); |
| 995 browser->tabstrip_model()->SetSelectionFromModel(selection); | 1028 browser->tabstrip_model()->SetSelectionFromModel(selection); |
| 996 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, true)); | 1029 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, true)); |
| 997 return true; | 1030 return true; |
| 998 } | 1031 } |
| 999 | 1032 |
| 1000 UpdateTabFunction::UpdateTabFunction() { | 1033 UpdateTabFunction::UpdateTabFunction() { |
| 1001 } | 1034 } |
| 1002 | 1035 |
| 1003 bool UpdateTabFunction::RunImpl() { | 1036 bool UpdateTabFunction::RunImpl() { |
| 1004 DictionaryValue* update_props; | 1037 DictionaryValue* update_props = NULL; |
| 1005 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); | 1038 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); |
| 1006 | 1039 |
| 1007 Value* tab_value = NULL; | 1040 Value* tab_value = NULL; |
| 1008 if (HasOptionalArgument(0)) { | 1041 if (HasOptionalArgument(0)) { |
| 1009 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &tab_value)); | 1042 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &tab_value)); |
| 1010 } | 1043 } |
| 1011 | 1044 |
| 1012 int tab_id = -1; | 1045 int tab_id = -1; |
| 1013 TabContentsWrapper* contents = NULL; | 1046 TabContentsWrapper* contents = NULL; |
| 1014 if (tab_value == NULL || tab_value->IsType(Value::TYPE_NULL)) { | 1047 if (tab_value == NULL || tab_value->IsType(Value::TYPE_NULL)) { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1144 } | 1177 } |
| 1145 | 1178 |
| 1146 SendResponse(true); | 1179 SendResponse(true); |
| 1147 return true; | 1180 return true; |
| 1148 } | 1181 } |
| 1149 | 1182 |
| 1150 bool UpdateTabFunction::OnMessageReceived(const IPC::Message& message) { | 1183 bool UpdateTabFunction::OnMessageReceived(const IPC::Message& message) { |
| 1151 if (message.type() != ExtensionHostMsg_ExecuteCodeFinished::ID) | 1184 if (message.type() != ExtensionHostMsg_ExecuteCodeFinished::ID) |
| 1152 return false; | 1185 return false; |
| 1153 | 1186 |
| 1154 int message_request_id; | 1187 int message_request_id = -1; |
| 1155 void* iter = NULL; | 1188 void* iter = NULL; |
| 1156 if (!message.ReadInt(&iter, &message_request_id)) { | 1189 if (!message.ReadInt(&iter, &message_request_id)) { |
| 1157 NOTREACHED() << "malformed extension message"; | 1190 NOTREACHED() << "malformed extension message"; |
| 1158 return true; | 1191 return true; |
| 1159 } | 1192 } |
| 1160 | 1193 |
| 1161 if (message_request_id != request_id()) | 1194 if (message_request_id != request_id()) |
| 1162 return false; | 1195 return false; |
| 1163 | 1196 |
| 1164 IPC_BEGIN_MESSAGE_MAP(UpdateTabFunction, message) | 1197 IPC_BEGIN_MESSAGE_MAP(UpdateTabFunction, message) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1182 Release(); // balanced in Execute() | 1215 Release(); // balanced in Execute() |
| 1183 } | 1216 } |
| 1184 | 1217 |
| 1185 bool MoveTabsFunction::RunImpl() { | 1218 bool MoveTabsFunction::RunImpl() { |
| 1186 Value* tab_value = NULL; | 1219 Value* tab_value = NULL; |
| 1187 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &tab_value)); | 1220 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &tab_value)); |
| 1188 | 1221 |
| 1189 std::vector<int> tab_ids; | 1222 std::vector<int> tab_ids; |
| 1190 EXTENSION_FUNCTION_VALIDATE(ReadOneOrMoreIntegers(tab_value, &tab_ids)); | 1223 EXTENSION_FUNCTION_VALIDATE(ReadOneOrMoreIntegers(tab_value, &tab_ids)); |
| 1191 | 1224 |
| 1192 DictionaryValue* update_props; | 1225 DictionaryValue* update_props = NULL; |
| 1193 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); | 1226 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); |
| 1194 | 1227 |
| 1195 int new_index; | 1228 int new_index = -1; |
| 1196 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( | 1229 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( |
| 1197 keys::kIndexKey, &new_index)); | 1230 keys::kIndexKey, &new_index)); |
| 1198 EXTENSION_FUNCTION_VALIDATE(new_index >= 0); | 1231 EXTENSION_FUNCTION_VALIDATE(new_index >= 0); |
| 1199 | 1232 |
| 1200 ListValue tab_values; | 1233 ListValue tab_values; |
| 1201 for (size_t i = 0; i < tab_ids.size(); ++i) { | 1234 for (size_t i = 0; i < tab_ids.size(); ++i) { |
| 1202 Browser* source_browser = NULL; | 1235 Browser* source_browser = NULL; |
| 1203 TabStripModel* source_tab_strip = NULL; | 1236 TabStripModel* source_tab_strip = NULL; |
| 1204 TabContentsWrapper* contents = NULL; | 1237 TabContentsWrapper* contents = NULL; |
| 1205 int tab_index = -1; | 1238 int tab_index = -1; |
| 1206 if (!GetTabById(tab_ids[i], profile(), include_incognito(), | 1239 if (!GetTabById(tab_ids[i], profile(), include_incognito(), |
| 1207 &source_browser, &source_tab_strip, &contents, | 1240 &source_browser, &source_tab_strip, &contents, |
| 1208 &tab_index, &error_)) | 1241 &tab_index, &error_)) |
| 1209 return false; | 1242 return false; |
| 1210 | 1243 |
| 1211 // Don't let the extension move the tab if the user is dragging tabs. | 1244 // Don't let the extension move the tab if the user is dragging tabs. |
| 1212 if (!source_browser->IsTabStripEditable()) { | 1245 if (!source_browser->IsTabStripEditable()) { |
| 1213 error_ = keys::kTabStripNotEditableError; | 1246 error_ = keys::kTabStripNotEditableError; |
| 1214 return false; | 1247 return false; |
| 1215 } | 1248 } |
| 1216 | 1249 |
| 1217 // Insert the tabs one after another. | 1250 // Insert the tabs one after another. |
| 1218 new_index += i; | 1251 new_index += i; |
| 1219 | 1252 |
| 1220 if (update_props->HasKey(keys::kWindowIdKey)) { | 1253 if (update_props->HasKey(keys::kWindowIdKey)) { |
| 1221 Browser* target_browser; | 1254 Browser* target_browser = NULL; |
| 1222 int window_id; | 1255 int window_id = -1; |
| 1223 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( | 1256 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( |
| 1224 keys::kWindowIdKey, &window_id)); | 1257 keys::kWindowIdKey, &window_id)); |
| 1225 target_browser = GetBrowserInProfileWithId(profile(), window_id, | 1258 target_browser = GetBrowserInProfileWithId(profile(), window_id, |
| 1226 include_incognito(), &error_); | 1259 include_incognito(), &error_); |
| 1227 if (!target_browser) | 1260 if (!target_browser) |
| 1228 return false; | 1261 return false; |
| 1229 | 1262 |
| 1230 if (!target_browser->IsTabStripEditable()) { | 1263 if (!target_browser->IsTabStripEditable()) { |
| 1231 error_ = keys::kTabStripNotEditableError; | 1264 error_ = keys::kTabStripNotEditableError; |
| 1232 return false; | 1265 return false; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1321 if (tab_value == NULL || tab_value->IsType(Value::TYPE_NULL)) { | 1354 if (tab_value == NULL || tab_value->IsType(Value::TYPE_NULL)) { |
| 1322 Browser* browser = GetCurrentBrowser(); | 1355 Browser* browser = GetCurrentBrowser(); |
| 1323 if (!browser) { | 1356 if (!browser) { |
| 1324 error_ = keys::kNoCurrentWindowError; | 1357 error_ = keys::kNoCurrentWindowError; |
| 1325 return false; | 1358 return false; |
| 1326 } | 1359 } |
| 1327 | 1360 |
| 1328 if (!ExtensionTabUtil::GetDefaultTab(browser, &contents, NULL)) | 1361 if (!ExtensionTabUtil::GetDefaultTab(browser, &contents, NULL)) |
| 1329 return false; | 1362 return false; |
| 1330 } else { | 1363 } else { |
| 1331 int tab_id; | 1364 int tab_id = -1; |
| 1332 EXTENSION_FUNCTION_VALIDATE(tab_value->GetAsInteger(&tab_id)); | 1365 EXTENSION_FUNCTION_VALIDATE(tab_value->GetAsInteger(&tab_id)); |
| 1333 | 1366 |
| 1334 Browser* browser = NULL; | 1367 Browser* browser = NULL; |
| 1335 if (!GetTabById(tab_id, profile(), include_incognito(), | 1368 if (!GetTabById(tab_id, profile(), include_incognito(), |
| 1336 &browser, NULL, &contents, NULL, &error_)) | 1369 &browser, NULL, &contents, NULL, &error_)) |
| 1337 return false; | 1370 return false; |
| 1338 } | 1371 } |
| 1339 | 1372 |
| 1340 TabContents* tab_contents = contents->tab_contents(); | 1373 TabContents* tab_contents = contents->tab_contents(); |
| 1341 if (tab_contents->showing_interstitial_page()) { | 1374 if (tab_contents->showing_interstitial_page()) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1377 // path should ensure that the tab is safely closed under such | 1410 // path should ensure that the tab is safely closed under such |
| 1378 // circumstances, whereas |Browser::CloseTabContents()| does not. | 1411 // circumstances, whereas |Browser::CloseTabContents()| does not. |
| 1379 RenderViewHost* render_view_host = | 1412 RenderViewHost* render_view_host = |
| 1380 contents->tab_contents()->render_view_host(); | 1413 contents->tab_contents()->render_view_host(); |
| 1381 render_view_host->delegate()->Close(render_view_host); | 1414 render_view_host->delegate()->Close(render_view_host); |
| 1382 } | 1415 } |
| 1383 return true; | 1416 return true; |
| 1384 } | 1417 } |
| 1385 | 1418 |
| 1386 bool CaptureVisibleTabFunction::RunImpl() { | 1419 bool CaptureVisibleTabFunction::RunImpl() { |
| 1387 Browser* browser; | 1420 Browser* browser = NULL; |
| 1388 // windowId defaults to "current" window. | 1421 // windowId defaults to "current" window. |
| 1389 int window_id = -1; | 1422 int window_id = -1; |
| 1390 | 1423 |
| 1391 if (HasOptionalArgument(0)) { | 1424 if (HasOptionalArgument(0)) { |
| 1392 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 1425 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
| 1393 browser = GetBrowserInProfileWithId(profile(), window_id, | 1426 browser = GetBrowserInProfileWithId(profile(), window_id, |
| 1394 include_incognito(), &error_); | 1427 include_incognito(), &error_); |
| 1395 } else { | 1428 } else { |
| 1396 browser = GetCurrentBrowser(); | 1429 browser = GetCurrentBrowser(); |
| 1397 } | 1430 } |
| 1398 | 1431 |
| 1399 if (!browser) { | 1432 if (!browser) { |
| 1400 error_ = keys::kNoCurrentWindowError; | 1433 error_ = keys::kNoCurrentWindowError; |
| 1401 return false; | 1434 return false; |
| 1402 } | 1435 } |
| 1403 | 1436 |
| 1404 image_format_ = FORMAT_JPEG; // Default format is JPEG. | 1437 image_format_ = FORMAT_JPEG; // Default format is JPEG. |
| 1405 image_quality_ = kDefaultQuality; // Default quality setting. | 1438 image_quality_ = kDefaultQuality; // Default quality setting. |
| 1406 | 1439 |
| 1407 if (HasOptionalArgument(1)) { | 1440 if (HasOptionalArgument(1)) { |
| 1408 DictionaryValue* options; | 1441 DictionaryValue* options = NULL; |
| 1409 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &options)); | 1442 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &options)); |
| 1410 | 1443 |
| 1411 if (options->HasKey(keys::kFormatKey)) { | 1444 if (options->HasKey(keys::kFormatKey)) { |
| 1412 std::string format; | 1445 std::string format; |
| 1413 EXTENSION_FUNCTION_VALIDATE( | 1446 EXTENSION_FUNCTION_VALIDATE( |
| 1414 options->GetString(keys::kFormatKey, &format)); | 1447 options->GetString(keys::kFormatKey, &format)); |
| 1415 | 1448 |
| 1416 if (format == keys::kFormatValueJpeg) { | 1449 if (format == keys::kFormatValueJpeg) { |
| 1417 image_format_ = FORMAT_JPEG; | 1450 image_format_ = FORMAT_JPEG; |
| 1418 } else if (format == keys::kFormatValuePng) { | 1451 } else if (format == keys::kFormatValuePng) { |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1621 // called for every API call the extension made. | 1654 // called for every API call the extension made. |
| 1622 GotLanguage(language); | 1655 GotLanguage(language); |
| 1623 } | 1656 } |
| 1624 | 1657 |
| 1625 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1658 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
| 1626 result_.reset(Value::CreateStringValue(language.c_str())); | 1659 result_.reset(Value::CreateStringValue(language.c_str())); |
| 1627 SendResponse(true); | 1660 SendResponse(true); |
| 1628 | 1661 |
| 1629 Release(); // Balanced in Run() | 1662 Release(); // Balanced in Run() |
| 1630 } | 1663 } |
| OLD | NEW |