OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <limits> | |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/base64.h" | 11 #include "base/base64.h" |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
14 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
16 #include "base/string16.h" | 17 #include "base/string16.h" |
17 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
(...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1395 } | 1396 } |
1396 | 1397 |
1397 bool MoveTabsFunction::RunImpl() { | 1398 bool MoveTabsFunction::RunImpl() { |
1398 Value* tab_value = NULL; | 1399 Value* tab_value = NULL; |
1399 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &tab_value)); | 1400 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &tab_value)); |
1400 | 1401 |
1401 std::vector<int> tab_ids; | 1402 std::vector<int> tab_ids; |
1402 EXTENSION_FUNCTION_VALIDATE(ReadOneOrMoreIntegers(tab_value, &tab_ids)); | 1403 EXTENSION_FUNCTION_VALIDATE(ReadOneOrMoreIntegers(tab_value, &tab_ids)); |
1403 | 1404 |
1404 DictionaryValue* update_props = NULL; | 1405 DictionaryValue* update_props = NULL; |
1405 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); | 1406 if (HasOptionalArgument(1)) { |
1407 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); | |
1408 } | |
1406 | 1409 |
1407 int new_index = -1; | 1410 int new_index = -1; |
1408 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( | 1411 if (update_props && update_props->HasKey(keys::kIndexKey)) { |
1409 keys::kIndexKey, &new_index)); | 1412 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( |
1410 EXTENSION_FUNCTION_VALIDATE(new_index >= 0); | 1413 keys::kIndexKey, &new_index)); |
1414 EXTENSION_FUNCTION_VALIDATE(new_index >= 0); | |
1415 } else { | |
1416 new_index = std::numeric_limits<int>::max(); // Will get clamped | |
clintstaley
2012/03/20 17:19:29
. after all comments
mitchellwrosen
2012/03/27 01:19:49
Done.
| |
1417 } | |
1411 | 1418 |
1412 ListValue tab_values; | 1419 ListValue tab_values; |
1413 for (size_t i = 0; i < tab_ids.size(); ++i) { | 1420 for (size_t i = 0; i < tab_ids.size(); ++i) { |
1414 Browser* source_browser = NULL; | 1421 Browser* source_browser = NULL; |
1415 TabStripModel* source_tab_strip = NULL; | 1422 TabStripModel* source_tab_strip = NULL; |
1416 TabContentsWrapper* contents = NULL; | 1423 TabContentsWrapper* contents = NULL; |
1417 int tab_index = -1; | 1424 int tab_index = -1; |
1418 if (!GetTabById(tab_ids[i], profile(), include_incognito(), | 1425 if (!GetTabById(tab_ids[i], profile(), include_incognito(), |
1419 &source_browser, &source_tab_strip, &contents, | 1426 &source_browser, &source_tab_strip, &contents, |
1420 &tab_index, &error_)) | 1427 &tab_index, &error_)) |
1421 return false; | 1428 return false; |
1422 | 1429 |
1423 // Don't let the extension move the tab if the user is dragging tabs. | 1430 // Don't let the extension move the tab if the user is dragging tabs. |
1424 if (!source_browser->IsTabStripEditable()) { | 1431 if (!source_browser->IsTabStripEditable()) { |
1425 error_ = keys::kTabStripNotEditableError; | 1432 error_ = keys::kTabStripNotEditableError; |
1426 return false; | 1433 return false; |
1427 } | 1434 } |
1428 | 1435 |
1429 // Insert the tabs one after another. | 1436 // Insert the tabs one after another. |
1430 new_index += i; | 1437 new_index += i; |
1431 | 1438 |
1432 if (update_props->HasKey(keys::kWindowIdKey)) { | 1439 if (update_props && update_props->HasKey(keys::kWindowIdKey)) { |
1433 Browser* target_browser = NULL; | 1440 Browser* target_browser = NULL; |
1434 int window_id = extension_misc::kUnknownWindowId; | 1441 int window_id = extension_misc::kUnknownWindowId; |
1435 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( | 1442 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( |
1436 keys::kWindowIdKey, &window_id)); | 1443 keys::kWindowIdKey, &window_id)); |
1437 if (!GetBrowserFromWindowID(this, window_id, &target_browser)) | 1444 if (!GetBrowserFromWindowID(this, window_id, &target_browser)) |
1438 return false; | 1445 return false; |
1439 | 1446 |
1440 if (!target_browser->IsTabStripEditable()) { | 1447 if (!target_browser->IsTabStripEditable()) { |
1441 error_ = keys::kTabStripNotEditableError; | 1448 error_ = keys::kTabStripNotEditableError; |
1442 return false; | 1449 return false; |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1812 // called for every API call the extension made. | 1819 // called for every API call the extension made. |
1813 GotLanguage(language); | 1820 GotLanguage(language); |
1814 } | 1821 } |
1815 | 1822 |
1816 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1823 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
1817 result_.reset(Value::CreateStringValue(language.c_str())); | 1824 result_.reset(Value::CreateStringValue(language.c_str())); |
1818 SendResponse(true); | 1825 SendResponse(true); |
1819 | 1826 |
1820 Release(); // Balanced in Run() | 1827 Release(); // Balanced in Run() |
1821 } | 1828 } |
OLD | NEW |