Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs.cc

Issue 10697017: Tabs Extension: Implementation of tabs.duplicate api. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 // Return data about the newly created tab. 1082 // Return data about the newly created tab.
1083 if (has_callback()) { 1083 if (has_callback()) {
1084 SetResult(ExtensionTabUtil::CreateTabValue( 1084 SetResult(ExtensionTabUtil::CreateTabValue(
1085 params.target_contents->web_contents(), 1085 params.target_contents->web_contents(),
1086 tab_strip, new_index)); 1086 tab_strip, new_index));
1087 } 1087 }
1088 1088
1089 return true; 1089 return true;
1090 } 1090 }
1091 1091
1092 bool DuplicateTabFunction::RunImpl() {
1093 int tab_id = -1;
1094 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
1095
1096 Browser* browser = NULL;
1097 TabStripModel* tab_strip = NULL;
1098 TabContents* contents = NULL;
1099 int tab_index = -1;
1100 if (!GetTabById(tab_id, profile(), include_incognito(),
1101 &browser, &tab_strip, &contents, &tab_index, &error_)) {
1102 return false;
1103 }
1104
1105 TabContents* new_contents = chrome::DuplicateTabAt(browser, tab_index);
1106 int new_index = tab_strip->GetIndexOfTabContents(new_contents);
1107
1108 // Return data about the newly created tab.
1109 if (has_callback()) {
Aaron Boodman 2012/08/15 04:14:05 You can invert this check and return early to redu
SanjoyPal 2012/09/05 08:31:15 Done.
1110 bool has_permission = GetExtension()->HasAPIPermissionForTab(tab_id,
Aaron Boodman 2012/08/15 04:14:05 Actually, I think it would be better to just pass
SanjoyPal 2012/09/05 08:31:15 Done. We need cleanup other callers of CreateTabVa
Aaron Boodman 2012/09/05 21:56:21 Since I made the original comment, we already modi
1111 extensions::APIPermission::kTab);
1112 if (has_permission)
Aaron Boodman 2012/08/15 04:14:05 Curly braces are required here...
SanjoyPal 2012/09/05 08:31:15 Done.
1113 SetResult(ExtensionTabUtil::CreateTabValue(
1114 new_contents->web_contents(),
1115 tab_strip, new_index,
1116 ExtensionTabUtil::INCLUDE_PRIVACY_SENSITIVE_FIELDS));
1117 else
Aaron Boodman 2012/08/15 04:14:05 ... and here ...
SanjoyPal 2012/09/05 08:31:15 Done.
1118 SetResult(ExtensionTabUtil::CreateTabValue(
1119 new_contents->web_contents(),
1120 tab_strip, new_index,
1121 ExtensionTabUtil::OMIT_PRIVACY_SENSITIVE_FIELDS));
1122 }
1123
1124 return true;
1125 }
1126
1092 bool GetTabFunction::RunImpl() { 1127 bool GetTabFunction::RunImpl() {
1093 int tab_id = -1; 1128 int tab_id = -1;
1094 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); 1129 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
1095 1130
1096 TabStripModel* tab_strip = NULL; 1131 TabStripModel* tab_strip = NULL;
1097 TabContents* contents = NULL; 1132 TabContents* contents = NULL;
1098 int tab_index = -1; 1133 int tab_index = -1;
1099 if (!GetTabById(tab_id, profile(), include_incognito(), 1134 if (!GetTabById(tab_id, profile(), include_incognito(),
1100 NULL, &tab_strip, &contents, &tab_index, &error_)) 1135 NULL, &tab_strip, &contents, &tab_index, &error_))
1101 return false; 1136 return false;
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
1820 // called for every API call the extension made. 1855 // called for every API call the extension made.
1821 GotLanguage(language); 1856 GotLanguage(language);
1822 } 1857 }
1823 1858
1824 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { 1859 void DetectTabLanguageFunction::GotLanguage(const std::string& language) {
1825 SetResult(Value::CreateStringValue(language.c_str())); 1860 SetResult(Value::CreateStringValue(language.c_str()));
1826 SendResponse(true); 1861 SendResponse(true);
1827 1862
1828 Release(); // Balanced in Run() 1863 Release(); // Balanced in Run()
1829 } 1864 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs.h ('k') | chrome/browser/extensions/api/tabs/tabs_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698