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 = NULL; | |
| 1109 TabStripModel* tab_strip = NULL; | |
| 1110 TabContents* contents = NULL; | |
| 1111 int tab_index = -1; | |
| 1112 if (!GetTabById(tab_id, profile(), include_incognito(), | |
| 1113 &browser, &tab_strip, &contents, &tab_index, &error_)) | |
| 1114 return false; | |
| 1115 | |
| 1116 TabContents* new_contents = browser->DuplicateContentsAt(tab_index); | |
| 1117 int new_index = tab_strip->GetIndexOfTabContents(new_contents); | |
| 1118 | |
| 1119 // Return data about the newly created tab. | |
| 1120 if (has_callback()) { | |
| 1121 if (GetExtension()->HasAPIPermission(ExtensionAPIPermission::kTab)) { | |
| 1122 result_.reset(ExtensionTabUtil::CreateTabValue( | |
|
SanjoyPal
2012/07/06 13:46:52
shall i pass a bool parameter hasPermission to Cre
| |
| 1123 new_contents->web_contents(), | |
| 1124 tab_strip, new_index)); | |
| 1125 } else { | |
| 1126 result_.reset(Value::CreateIntegerValue( | |
| 1127 ExtensionTabUtil::GetTabId(new_contents->web_contents()))); | |
| 1128 } | |
| 1129 } | |
| 1130 | |
| 1131 return true; | |
| 1132 } | |
| 1133 | |
| 1104 bool GetTabFunction::RunImpl() { | 1134 bool GetTabFunction::RunImpl() { |
| 1105 int tab_id = -1; | 1135 int tab_id = -1; |
| 1106 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); | 1136 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); |
| 1107 | 1137 |
| 1108 TabStripModel* tab_strip = NULL; | 1138 TabStripModel* tab_strip = NULL; |
| 1109 TabContents* contents = NULL; | 1139 TabContents* contents = NULL; |
| 1110 int tab_index = -1; | 1140 int tab_index = -1; |
| 1111 if (!GetTabById(tab_id, profile(), include_incognito(), | 1141 if (!GetTabById(tab_id, profile(), include_incognito(), |
| 1112 NULL, &tab_strip, &contents, &tab_index, &error_)) | 1142 NULL, &tab_strip, &contents, &tab_index, &error_)) |
| 1113 return false; | 1143 return false; |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1824 // called for every API call the extension made. | 1854 // called for every API call the extension made. |
| 1825 GotLanguage(language); | 1855 GotLanguage(language); |
| 1826 } | 1856 } |
| 1827 | 1857 |
| 1828 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1858 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
| 1829 result_.reset(Value::CreateStringValue(language.c_str())); | 1859 result_.reset(Value::CreateStringValue(language.c_str())); |
| 1830 SendResponse(true); | 1860 SendResponse(true); |
| 1831 | 1861 |
| 1832 Release(); // Balanced in Run() | 1862 Release(); // Balanced in Run() |
| 1833 } | 1863 } |
| OLD | NEW |