| 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 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 if (contents) | 885 if (contents) |
| 886 result_.reset(ExtensionTabUtil::CreateTabValue(contents)); | 886 result_.reset(ExtensionTabUtil::CreateTabValue(contents)); |
| 887 | 887 |
| 888 return true; | 888 return true; |
| 889 } | 889 } |
| 890 | 890 |
| 891 UpdateTabFunction::UpdateTabFunction() { | 891 UpdateTabFunction::UpdateTabFunction() { |
| 892 } | 892 } |
| 893 | 893 |
| 894 bool UpdateTabFunction::RunImpl() { | 894 bool UpdateTabFunction::RunImpl() { |
| 895 int tab_id; | |
| 896 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); | |
| 897 DictionaryValue* update_props; | 895 DictionaryValue* update_props; |
| 898 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); | 896 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); |
| 899 | 897 |
| 898 Value* tab_value = NULL; |
| 899 if (HasOptionalArgument(0)) { |
| 900 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &tab_value)); |
| 901 } |
| 902 |
| 903 int tab_id = -1; |
| 904 TabContentsWrapper* contents = NULL; |
| 905 if (tab_value == NULL || tab_value->IsType(Value::TYPE_NULL)) { |
| 906 Browser* browser = GetCurrentBrowser(); |
| 907 if (!browser) { |
| 908 error_ = keys::kNoCurrentWindowError; |
| 909 return false; |
| 910 } |
| 911 contents = browser->tabstrip_model()->GetActiveTabContents(); |
| 912 if (!contents) { |
| 913 error_ = keys::kNoSelectedTabError; |
| 914 return false; |
| 915 } |
| 916 tab_id = ExtensionTabUtil::GetTabId(contents->tab_contents()); |
| 917 } else { |
| 918 EXTENSION_FUNCTION_VALIDATE(tab_value->GetAsInteger(&tab_id)); |
| 919 } |
| 920 |
| 921 int tab_index = -1; |
| 900 TabStripModel* tab_strip = NULL; | 922 TabStripModel* tab_strip = NULL; |
| 901 TabContentsWrapper* contents = NULL; | |
| 902 int tab_index = -1; | |
| 903 if (!GetTabById(tab_id, profile(), include_incognito(), | 923 if (!GetTabById(tab_id, profile(), include_incognito(), |
| 904 NULL, &tab_strip, &contents, &tab_index, &error_)) | 924 NULL, &tab_strip, &contents, &tab_index, &error_)) { |
| 905 return false; | 925 return false; |
| 906 | 926 } |
| 907 NavigationController& controller = contents->controller(); | 927 NavigationController& controller = contents->controller(); |
| 908 | 928 |
| 909 // TODO(rafaelw): handle setting remaining tab properties: | 929 // TODO(rafaelw): handle setting remaining tab properties: |
| 910 // -title | 930 // -title |
| 911 // -favIconUrl | 931 // -favIconUrl |
| 912 | 932 |
| 913 // Navigate the tab to a new location if the url is different. | 933 // Navigate the tab to a new location if the url is different. |
| 914 std::string url_string; | 934 std::string url_string; |
| 915 if (update_props->HasKey(keys::kUrlKey)) { | 935 if (update_props->HasKey(keys::kUrlKey)) { |
| 916 EXTENSION_FUNCTION_VALIDATE(update_props->GetString( | 936 EXTENSION_FUNCTION_VALIDATE(update_props->GetString( |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1440 // called for every API call the extension made. | 1460 // called for every API call the extension made. |
| 1441 GotLanguage(language); | 1461 GotLanguage(language); |
| 1442 } | 1462 } |
| 1443 | 1463 |
| 1444 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1464 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
| 1445 result_.reset(Value::CreateStringValue(language.c_str())); | 1465 result_.reset(Value::CreateStringValue(language.c_str())); |
| 1446 SendResponse(true); | 1466 SendResponse(true); |
| 1447 | 1467 |
| 1448 Release(); // Balanced in Run() | 1468 Release(); // Balanced in Run() |
| 1449 } | 1469 } |
| OLD | NEW |