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/api/tabs/tabs_api.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 } | 321 } |
322 | 322 |
323 bool WindowsGetAllFunction::RunImpl() { | 323 bool WindowsGetAllFunction::RunImpl() { |
324 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_)); | 324 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_)); |
325 EXTENSION_FUNCTION_VALIDATE(params.get()); | 325 EXTENSION_FUNCTION_VALIDATE(params.get()); |
326 | 326 |
327 bool populate_tabs = false; | 327 bool populate_tabs = false; |
328 if (params->get_info.get() && params->get_info->populate.get()) | 328 if (params->get_info.get() && params->get_info->populate.get()) |
329 populate_tabs = *params->get_info->populate; | 329 populate_tabs = *params->get_info->populate; |
330 | 330 |
331 ListValue* window_list = new ListValue(); | 331 base::ListValue* window_list = new base::ListValue(); |
332 const WindowControllerList::ControllerList& windows = | 332 const WindowControllerList::ControllerList& windows = |
333 WindowControllerList::GetInstance()->windows(); | 333 WindowControllerList::GetInstance()->windows(); |
334 for (WindowControllerList::ControllerList::const_iterator iter = | 334 for (WindowControllerList::ControllerList::const_iterator iter = |
335 windows.begin(); | 335 windows.begin(); |
336 iter != windows.end(); ++iter) { | 336 iter != windows.end(); ++iter) { |
337 if (!this->CanOperateOnWindow(*iter)) | 337 if (!this->CanOperateOnWindow(*iter)) |
338 continue; | 338 continue; |
339 if (populate_tabs) | 339 if (populate_tabs) |
340 window_list->Append((*iter)->CreateWindowValueWithTabs(GetExtension())); | 340 window_list->Append((*iter)->CreateWindowValueWithTabs(GetExtension())); |
341 else | 341 else |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 error_ = ErrorUtils::FormatErrorMessage( | 389 error_ = ErrorUtils::FormatErrorMessage( |
390 keys::kURLsNotAllowedInIncognitoError, first_url_erased); | 390 keys::kURLsNotAllowedInIncognitoError, first_url_erased); |
391 *is_error = true; | 391 *is_error = true; |
392 return false; | 392 return false; |
393 } | 393 } |
394 } | 394 } |
395 return incognito; | 395 return incognito; |
396 } | 396 } |
397 | 397 |
398 bool WindowsCreateFunction::RunImpl() { | 398 bool WindowsCreateFunction::RunImpl() { |
399 DictionaryValue* args = NULL; | 399 base::DictionaryValue* args = NULL; |
400 std::vector<GURL> urls; | 400 std::vector<GURL> urls; |
401 TabStripModel* source_tab_strip = NULL; | 401 TabStripModel* source_tab_strip = NULL; |
402 int tab_index = -1; | 402 int tab_index = -1; |
403 | 403 |
404 if (HasOptionalArgument(0)) | 404 if (HasOptionalArgument(0)) |
405 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 405 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
406 | 406 |
407 // Look for optional url. | 407 // Look for optional url. |
408 if (args) { | 408 if (args) { |
409 if (args->HasKey(keys::kUrlKey)) { | 409 if (args->HasKey(keys::kUrlKey)) { |
410 Value* url_value; | 410 Value* url_value; |
411 std::vector<std::string> url_strings; | 411 std::vector<std::string> url_strings; |
412 args->Get(keys::kUrlKey, &url_value); | 412 args->Get(keys::kUrlKey, &url_value); |
413 | 413 |
414 // First, get all the URLs the client wants to open. | 414 // First, get all the URLs the client wants to open. |
415 if (url_value->IsType(Value::TYPE_STRING)) { | 415 if (url_value->IsType(Value::TYPE_STRING)) { |
416 std::string url_string; | 416 std::string url_string; |
417 url_value->GetAsString(&url_string); | 417 url_value->GetAsString(&url_string); |
418 url_strings.push_back(url_string); | 418 url_strings.push_back(url_string); |
419 } else if (url_value->IsType(Value::TYPE_LIST)) { | 419 } else if (url_value->IsType(Value::TYPE_LIST)) { |
420 const ListValue* url_list = static_cast<const ListValue*>(url_value); | 420 const base::ListValue* url_list = |
| 421 static_cast<const base::ListValue*>(url_value); |
421 for (size_t i = 0; i < url_list->GetSize(); ++i) { | 422 for (size_t i = 0; i < url_list->GetSize(); ++i) { |
422 std::string url_string; | 423 std::string url_string; |
423 EXTENSION_FUNCTION_VALIDATE(url_list->GetString(i, &url_string)); | 424 EXTENSION_FUNCTION_VALIDATE(url_list->GetString(i, &url_string)); |
424 url_strings.push_back(url_string); | 425 url_strings.push_back(url_string); |
425 } | 426 } |
426 } | 427 } |
427 | 428 |
428 // Second, resolve, validate and convert them to GURLs. | 429 // Second, resolve, validate and convert them to GURLs. |
429 for (std::vector<std::string>::iterator i = url_strings.begin(); | 430 for (std::vector<std::string>::iterator i = url_strings.begin(); |
430 i != url_strings.end(); ++i) { | 431 i != url_strings.end(); ++i) { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 new_window->extension_window_controller()->CreateWindowValueWithTabs( | 683 new_window->extension_window_controller()->CreateWindowValueWithTabs( |
683 GetExtension())); | 684 GetExtension())); |
684 } | 685 } |
685 | 686 |
686 return true; | 687 return true; |
687 } | 688 } |
688 | 689 |
689 bool WindowsUpdateFunction::RunImpl() { | 690 bool WindowsUpdateFunction::RunImpl() { |
690 int window_id = extension_misc::kUnknownWindowId; | 691 int window_id = extension_misc::kUnknownWindowId; |
691 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 692 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
692 DictionaryValue* update_props; | 693 base::DictionaryValue* update_props; |
693 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); | 694 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); |
694 | 695 |
695 WindowController* controller; | 696 WindowController* controller; |
696 if (!GetWindowFromWindowID(this, window_id, &controller)) | 697 if (!GetWindowFromWindowID(this, window_id, &controller)) |
697 return false; | 698 return false; |
698 | 699 |
699 #if defined(OS_WIN) | 700 #if defined(OS_WIN) |
700 // Silently ignore changes on the window for metro mode. | 701 // Silently ignore changes on the window for metro mode. |
701 if (win8::IsSingleWindowMetroMode()) { | 702 if (win8::IsSingleWindowMetroMode()) { |
702 SetResult(controller->CreateWindowValue()); | 703 SetResult(controller->CreateWindowValue()); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 if (params->query_info.index.get()) | 931 if (params->query_info.index.get()) |
931 index = *params->query_info.index; | 932 index = *params->query_info.index; |
932 | 933 |
933 std::string window_type; | 934 std::string window_type; |
934 if (params->query_info.window_type != | 935 if (params->query_info.window_type != |
935 tabs::Query::Params::QueryInfo::WINDOW_TYPE_NONE) { | 936 tabs::Query::Params::QueryInfo::WINDOW_TYPE_NONE) { |
936 window_type = tabs::Query::Params::QueryInfo::ToString( | 937 window_type = tabs::Query::Params::QueryInfo::ToString( |
937 params->query_info.window_type); | 938 params->query_info.window_type); |
938 } | 939 } |
939 | 940 |
940 ListValue* result = new ListValue(); | 941 base::ListValue* result = new base::ListValue(); |
941 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 942 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
942 Browser* browser = *it; | 943 Browser* browser = *it; |
943 if (!profile()->IsSameProfile(browser->profile())) | 944 if (!profile()->IsSameProfile(browser->profile())) |
944 continue; | 945 continue; |
945 | 946 |
946 if (!browser->window()) | 947 if (!browser->window()) |
947 continue; | 948 continue; |
948 | 949 |
949 if (!include_incognito() && profile() != browser->profile()) | 950 if (!include_incognito() && profile() != browser->profile()) |
950 continue; | 951 continue; |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1438 return true; | 1439 return true; |
1439 } | 1440 } |
1440 | 1441 |
1441 void TabsUpdateFunction::PopulateResult() { | 1442 void TabsUpdateFunction::PopulateResult() { |
1442 if (!has_callback()) | 1443 if (!has_callback()) |
1443 return; | 1444 return; |
1444 | 1445 |
1445 SetResult(ExtensionTabUtil::CreateTabValue(web_contents_, GetExtension())); | 1446 SetResult(ExtensionTabUtil::CreateTabValue(web_contents_, GetExtension())); |
1446 } | 1447 } |
1447 | 1448 |
1448 void TabsUpdateFunction::OnExecuteCodeFinished(const std::string& error, | 1449 void TabsUpdateFunction::OnExecuteCodeFinished( |
1449 int32 on_page_id, | 1450 const std::string& error, |
1450 const GURL& url, | 1451 int32 on_page_id, |
1451 const ListValue& script_result) { | 1452 const GURL& url, |
| 1453 const base::ListValue& script_result) { |
1452 if (error.empty()) | 1454 if (error.empty()) |
1453 PopulateResult(); | 1455 PopulateResult(); |
1454 else | 1456 else |
1455 error_ = error; | 1457 error_ = error; |
1456 SendResponse(error.empty()); | 1458 SendResponse(error.empty()); |
1457 } | 1459 } |
1458 | 1460 |
1459 bool TabsMoveFunction::RunImpl() { | 1461 bool TabsMoveFunction::RunImpl() { |
1460 scoped_ptr<tabs::Move::Params> params(tabs::Move::Params::Create(*args_)); | 1462 scoped_ptr<tabs::Move::Params> params(tabs::Move::Params::Create(*args_)); |
1461 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1463 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1462 | 1464 |
1463 int new_index = params->move_properties.index; | 1465 int new_index = params->move_properties.index; |
1464 int* window_id = params->move_properties.window_id.get(); | 1466 int* window_id = params->move_properties.window_id.get(); |
1465 ListValue tab_values; | 1467 base::ListValue tab_values; |
1466 | 1468 |
1467 std::vector<int> tab_ids; | 1469 std::vector<int> tab_ids; |
1468 if (params->tab_ids.as_array.get()) { | 1470 if (params->tab_ids.as_array.get()) { |
1469 tab_ids = *params->tab_ids.as_array; | 1471 tab_ids = *params->tab_ids.as_array; |
1470 | 1472 |
1471 for (size_t i = 0; i < tab_ids.size(); ++i) { | 1473 for (size_t i = 0; i < tab_ids.size(); ++i) { |
1472 if (!MoveTab(tab_ids[i], &new_index, i, &tab_values, window_id)) { | 1474 if (!MoveTab(tab_ids[i], &new_index, i, &tab_values, window_id)) { |
1473 return false; | 1475 return false; |
1474 } | 1476 } |
1475 } | 1477 } |
(...skipping 18 matching lines...) Expand all Loading... |
1494 Value* value = NULL; | 1496 Value* value = NULL; |
1495 CHECK(tab_values.Get(0, &value)); | 1497 CHECK(tab_values.Get(0, &value)); |
1496 SetResult(value->DeepCopy()); | 1498 SetResult(value->DeepCopy()); |
1497 } | 1499 } |
1498 return true; | 1500 return true; |
1499 } | 1501 } |
1500 | 1502 |
1501 bool TabsMoveFunction::MoveTab(int tab_id, | 1503 bool TabsMoveFunction::MoveTab(int tab_id, |
1502 int *new_index, | 1504 int *new_index, |
1503 int iteration, | 1505 int iteration, |
1504 ListValue* tab_values, | 1506 base::ListValue* tab_values, |
1505 int* window_id) { | 1507 int* window_id) { |
1506 Browser* source_browser = NULL; | 1508 Browser* source_browser = NULL; |
1507 TabStripModel* source_tab_strip = NULL; | 1509 TabStripModel* source_tab_strip = NULL; |
1508 WebContents* contents = NULL; | 1510 WebContents* contents = NULL; |
1509 int tab_index = -1; | 1511 int tab_index = -1; |
1510 if (!GetTabById(tab_id, profile(), include_incognito(), | 1512 if (!GetTabById(tab_id, profile(), include_incognito(), |
1511 &source_browser, &source_tab_strip, &contents, | 1513 &source_browser, &source_tab_strip, &contents, |
1512 &tab_index, &error_)) { | 1514 &tab_index, &error_)) { |
1513 return false; | 1515 return false; |
1514 } | 1516 } |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2017 } | 2019 } |
2018 | 2020 |
2019 bool ExecuteCodeInTabFunction::IsWebView() const { | 2021 bool ExecuteCodeInTabFunction::IsWebView() const { |
2020 return false; | 2022 return false; |
2021 } | 2023 } |
2022 | 2024 |
2023 bool TabsExecuteScriptFunction::ShouldInsertCSS() const { | 2025 bool TabsExecuteScriptFunction::ShouldInsertCSS() const { |
2024 return false; | 2026 return false; |
2025 } | 2027 } |
2026 | 2028 |
2027 void TabsExecuteScriptFunction::OnExecuteCodeFinished(const std::string& error, | 2029 void TabsExecuteScriptFunction::OnExecuteCodeFinished( |
2028 int32 on_page_id, | 2030 const std::string& error, |
2029 const GURL& on_url, | 2031 int32 on_page_id, |
2030 const ListValue& result) { | 2032 const GURL& on_url, |
| 2033 const base::ListValue& result) { |
2031 if (error.empty()) | 2034 if (error.empty()) |
2032 SetResult(result.DeepCopy()); | 2035 SetResult(result.DeepCopy()); |
2033 ExecuteCodeInTabFunction::OnExecuteCodeFinished(error, on_page_id, on_url, | 2036 ExecuteCodeInTabFunction::OnExecuteCodeFinished(error, on_page_id, on_url, |
2034 result); | 2037 result); |
2035 } | 2038 } |
2036 | 2039 |
2037 bool ExecuteCodeInTabFunction::Init() { | 2040 bool ExecuteCodeInTabFunction::Init() { |
2038 if (details_.get()) | 2041 if (details_.get()) |
2039 return true; | 2042 return true; |
2040 | 2043 |
2041 // |tab_id| is optional so it's ok if it's not there. | 2044 // |tab_id| is optional so it's ok if it's not there. |
2042 int tab_id = -1; | 2045 int tab_id = -1; |
2043 if (args_->GetInteger(0, &tab_id)) | 2046 if (args_->GetInteger(0, &tab_id)) |
2044 EXTENSION_FUNCTION_VALIDATE(tab_id >= 0); | 2047 EXTENSION_FUNCTION_VALIDATE(tab_id >= 0); |
2045 | 2048 |
2046 // |details| are not optional. | 2049 // |details| are not optional. |
2047 DictionaryValue* details_value = NULL; | 2050 base::DictionaryValue* details_value = NULL; |
2048 if (!args_->GetDictionary(1, &details_value)) | 2051 if (!args_->GetDictionary(1, &details_value)) |
2049 return false; | 2052 return false; |
2050 scoped_ptr<InjectDetails> details(new InjectDetails()); | 2053 scoped_ptr<InjectDetails> details(new InjectDetails()); |
2051 if (!InjectDetails::Populate(*details_value, details.get())) | 2054 if (!InjectDetails::Populate(*details_value, details.get())) |
2052 return false; | 2055 return false; |
2053 | 2056 |
2054 // If the tab ID wasn't given then it needs to be converted to the | 2057 // If the tab ID wasn't given then it needs to be converted to the |
2055 // currently active tab's ID. | 2058 // currently active tab's ID. |
2056 if (tab_id == -1) { | 2059 if (tab_id == -1) { |
2057 Browser* browser = GetCurrentBrowser(); | 2060 Browser* browser = GetCurrentBrowser(); |
2058 if (!browser) | 2061 if (!browser) |
2059 return false; | 2062 return false; |
2060 content::WebContents* web_contents = NULL; | 2063 content::WebContents* web_contents = NULL; |
2061 if (!ExtensionTabUtil::GetDefaultTab(browser, &web_contents, &tab_id)) | 2064 if (!ExtensionTabUtil::GetDefaultTab(browser, &web_contents, &tab_id)) |
2062 return false; | 2065 return false; |
2063 } | 2066 } |
2064 | 2067 |
2065 execute_tab_id_ = tab_id; | 2068 execute_tab_id_ = tab_id; |
2066 details_ = details.Pass(); | 2069 details_ = details.Pass(); |
2067 return true; | 2070 return true; |
2068 } | 2071 } |
2069 | 2072 |
2070 bool TabsInsertCSSFunction::ShouldInsertCSS() const { | 2073 bool TabsInsertCSSFunction::ShouldInsertCSS() const { |
2071 return true; | 2074 return true; |
2072 } | 2075 } |
2073 | 2076 |
2074 } // namespace extensions | 2077 } // namespace extensions |
OLD | NEW |