Chromium Code Reviews| 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.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1094 // Return data about the newly created tab. | 1094 // Return data about the newly created tab. |
| 1095 if (has_callback()) { | 1095 if (has_callback()) { |
| 1096 result_.reset(ExtensionTabUtil::CreateTabValue( | 1096 result_.reset(ExtensionTabUtil::CreateTabValue( |
| 1097 params.target_contents->web_contents(), | 1097 params.target_contents->web_contents(), |
| 1098 tab_strip, new_index)); | 1098 tab_strip, new_index)); |
| 1099 } | 1099 } |
| 1100 | 1100 |
| 1101 return true; | 1101 return true; |
| 1102 } | 1102 } |
| 1103 | 1103 |
| 1104 bool DuplicateTabFunction::RunImpl() { | |
| 1105 int tab_id = -1; | |
| 1106 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); | |
| 1107 | |
| 1108 Browser* browser = GetCurrentBrowser(); | |
| 1109 if (!browser) { | |
| 1110 error_ = keys::kNoCurrentWindowError; | |
| 1111 return false; | |
| 1112 } | |
| 1113 | |
| 1114 TabStripModel* tab_strip = NULL; | |
| 1115 TabContents* contents = NULL; | |
| 1116 int tab_index = -1; | |
| 1117 if (!GetTabById(tab_id, profile(), include_incognito(), | |
| 1118 NULL, &tab_strip, &contents, &tab_index, &error_)) | |
|
Mihai Parparita -not on Chrome
2012/07/03 22:57:18
You need to pass in &browser instead of NULL here.
SanjoyPal
2012/07/04 06:49:46
Done. Let me know if we decide to support windowId
| |
| 1119 return false; | |
| 1120 | |
| 1121 TabContents* new_contents = browser->DuplicateContentsAt(tab_index); | |
| 1122 int new_index = tab_strip->GetIndexOfTabContents(new_contents); | |
| 1123 | |
| 1124 // Return data about the newly created tab. | |
| 1125 if (has_callback()) { | |
| 1126 if (GetExtension()->HasAPIPermission(ExtensionAPIPermission::kTab)) { | |
| 1127 result_.reset(ExtensionTabUtil::CreateTabValue( | |
| 1128 new_contents->web_contents(), | |
| 1129 tab_strip, new_index)); | |
| 1130 } else { | |
| 1131 result_.reset(Value::CreateIntegerValue( | |
| 1132 ExtensionTabUtil::GetTabId(new_contents->web_contents()))); | |
| 1133 } | |
| 1134 } | |
| 1135 | |
| 1136 return true; | |
| 1137 } | |
| 1138 | |
| 1104 bool GetTabFunction::RunImpl() { | 1139 bool GetTabFunction::RunImpl() { |
| 1105 int tab_id = -1; | 1140 int tab_id = -1; |
| 1106 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); | 1141 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); |
| 1107 | 1142 |
| 1108 TabStripModel* tab_strip = NULL; | 1143 TabStripModel* tab_strip = NULL; |
| 1109 TabContents* contents = NULL; | 1144 TabContents* contents = NULL; |
| 1110 int tab_index = -1; | 1145 int tab_index = -1; |
| 1111 if (!GetTabById(tab_id, profile(), include_incognito(), | 1146 if (!GetTabById(tab_id, profile(), include_incognito(), |
| 1112 NULL, &tab_strip, &contents, &tab_index, &error_)) | 1147 NULL, &tab_strip, &contents, &tab_index, &error_)) |
| 1113 return false; | 1148 return false; |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1824 // called for every API call the extension made. | 1859 // called for every API call the extension made. |
| 1825 GotLanguage(language); | 1860 GotLanguage(language); |
| 1826 } | 1861 } |
| 1827 | 1862 |
| 1828 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1863 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
| 1829 result_.reset(Value::CreateStringValue(language.c_str())); | 1864 result_.reset(Value::CreateStringValue(language.c_str())); |
| 1830 SendResponse(true); | 1865 SendResponse(true); |
| 1831 | 1866 |
| 1832 Release(); // Balanced in Run() | 1867 Release(); // Balanced in Run() |
| 1833 } | 1868 } |
| OLD | NEW |