| 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 257 |
| 258 bool populate_tabs = false; | 258 bool populate_tabs = false; |
| 259 if (params->get_info.get() && params->get_info->populate.get()) | 259 if (params->get_info.get() && params->get_info->populate.get()) |
| 260 populate_tabs = *params->get_info->populate; | 260 populate_tabs = *params->get_info->populate; |
| 261 | 261 |
| 262 WindowController* controller; | 262 WindowController* controller; |
| 263 if (!GetWindowFromWindowID(this, params->window_id, &controller)) | 263 if (!GetWindowFromWindowID(this, params->window_id, &controller)) |
| 264 return false; | 264 return false; |
| 265 | 265 |
| 266 if (populate_tabs) | 266 if (populate_tabs) |
| 267 SetResult(controller->CreateWindowValueWithTabs()); | 267 SetResult(controller->CreateWindowValueWithTabs(GetExtension())); |
| 268 else | 268 else |
| 269 SetResult(controller->CreateWindowValue()); | 269 SetResult(controller->CreateWindowValue()); |
| 270 return true; | 270 return true; |
| 271 } | 271 } |
| 272 | 272 |
| 273 bool GetCurrentWindowFunction::RunImpl() { | 273 bool GetCurrentWindowFunction::RunImpl() { |
| 274 scoped_ptr<GetCurrent::Params> params(GetCurrent::Params::Create(*args_)); | 274 scoped_ptr<GetCurrent::Params> params(GetCurrent::Params::Create(*args_)); |
| 275 EXTENSION_FUNCTION_VALIDATE(params.get()); | 275 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 276 | 276 |
| 277 bool populate_tabs = false; | 277 bool populate_tabs = false; |
| 278 if (params->get_info.get() && params->get_info->populate.get()) | 278 if (params->get_info.get() && params->get_info->populate.get()) |
| 279 populate_tabs = *params->get_info->populate; | 279 populate_tabs = *params->get_info->populate; |
| 280 | 280 |
| 281 WindowController* controller; | 281 WindowController* controller; |
| 282 if (!GetWindowFromWindowID(this, | 282 if (!GetWindowFromWindowID(this, |
| 283 extension_misc::kCurrentWindowId, | 283 extension_misc::kCurrentWindowId, |
| 284 &controller)) { | 284 &controller)) { |
| 285 return false; | 285 return false; |
| 286 } | 286 } |
| 287 if (populate_tabs) | 287 if (populate_tabs) |
| 288 SetResult(controller->CreateWindowValueWithTabs()); | 288 SetResult(controller->CreateWindowValueWithTabs(GetExtension())); |
| 289 else | 289 else |
| 290 SetResult(controller->CreateWindowValue()); | 290 SetResult(controller->CreateWindowValue()); |
| 291 return true; | 291 return true; |
| 292 } | 292 } |
| 293 | 293 |
| 294 bool GetLastFocusedWindowFunction::RunImpl() { | 294 bool GetLastFocusedWindowFunction::RunImpl() { |
| 295 scoped_ptr<GetLastFocused::Params> params( | 295 scoped_ptr<GetLastFocused::Params> params( |
| 296 GetLastFocused::Params::Create(*args_)); | 296 GetLastFocused::Params::Create(*args_)); |
| 297 EXTENSION_FUNCTION_VALIDATE(params.get()); | 297 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 298 | 298 |
| 299 bool populate_tabs = false; | 299 bool populate_tabs = false; |
| 300 if (params->get_info.get() && params->get_info->populate.get()) | 300 if (params->get_info.get() && params->get_info->populate.get()) |
| 301 populate_tabs = *params->get_info->populate; | 301 populate_tabs = *params->get_info->populate; |
| 302 | 302 |
| 303 // Note: currently this returns the last active browser. If we decide to | 303 // Note: currently this returns the last active browser. If we decide to |
| 304 // include other window types (e.g. panels), we will need to add logic to | 304 // include other window types (e.g. panels), we will need to add logic to |
| 305 // WindowControllerList that mirrors the active behavior of BrowserList. | 305 // WindowControllerList that mirrors the active behavior of BrowserList. |
| 306 Browser* browser = browser::FindAnyBrowser( | 306 Browser* browser = browser::FindAnyBrowser( |
| 307 profile(), include_incognito()); | 307 profile(), include_incognito()); |
| 308 if (!browser || !browser->window()) { | 308 if (!browser || !browser->window()) { |
| 309 error_ = keys::kNoLastFocusedWindowError; | 309 error_ = keys::kNoLastFocusedWindowError; |
| 310 return false; | 310 return false; |
| 311 } | 311 } |
| 312 WindowController* controller = | 312 WindowController* controller = |
| 313 browser->extension_window_controller(); | 313 browser->extension_window_controller(); |
| 314 if (populate_tabs) | 314 if (populate_tabs) |
| 315 SetResult(controller->CreateWindowValueWithTabs()); | 315 SetResult(controller->CreateWindowValueWithTabs(GetExtension())); |
| 316 else | 316 else |
| 317 SetResult(controller->CreateWindowValue()); | 317 SetResult(controller->CreateWindowValue()); |
| 318 return true; | 318 return true; |
| 319 } | 319 } |
| 320 | 320 |
| 321 bool GetAllWindowsFunction::RunImpl() { | 321 bool GetAllWindowsFunction::RunImpl() { |
| 322 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_)); | 322 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_)); |
| 323 EXTENSION_FUNCTION_VALIDATE(params.get()); | 323 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 324 | 324 |
| 325 bool populate_tabs = false; | 325 bool populate_tabs = false; |
| 326 if (params->get_info.get() && params->get_info->populate.get()) | 326 if (params->get_info.get() && params->get_info->populate.get()) |
| 327 populate_tabs = *params->get_info->populate; | 327 populate_tabs = *params->get_info->populate; |
| 328 | 328 |
| 329 ListValue* window_list = new ListValue(); | 329 ListValue* window_list = new ListValue(); |
| 330 const WindowControllerList::ControllerList& windows = | 330 const WindowControllerList::ControllerList& windows = |
| 331 WindowControllerList::GetInstance()->windows(); | 331 WindowControllerList::GetInstance()->windows(); |
| 332 for (WindowControllerList::ControllerList::const_iterator iter = | 332 for (WindowControllerList::ControllerList::const_iterator iter = |
| 333 windows.begin(); | 333 windows.begin(); |
| 334 iter != windows.end(); ++iter) { | 334 iter != windows.end(); ++iter) { |
| 335 if (!this->CanOperateOnWindow(*iter)) | 335 if (!this->CanOperateOnWindow(*iter)) |
| 336 continue; | 336 continue; |
| 337 if (populate_tabs) | 337 if (populate_tabs) |
| 338 window_list->Append((*iter)->CreateWindowValueWithTabs()); | 338 window_list->Append((*iter)->CreateWindowValueWithTabs(GetExtension())); |
| 339 else | 339 else |
| 340 window_list->Append((*iter)->CreateWindowValue()); | 340 window_list->Append((*iter)->CreateWindowValue()); |
| 341 } | 341 } |
| 342 SetResult(window_list); | 342 SetResult(window_list); |
| 343 return true; | 343 return true; |
| 344 } | 344 } |
| 345 | 345 |
| 346 bool CreateWindowFunction::ShouldOpenIncognitoWindow( | 346 bool CreateWindowFunction::ShouldOpenIncognitoWindow( |
| 347 const base::DictionaryValue* args, | 347 const base::DictionaryValue* args, |
| 348 std::vector<GURL>* urls, | 348 std::vector<GURL>* urls, |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 Panel* panel = PanelManager::GetInstance()->CreatePanel( | 580 Panel* panel = PanelManager::GetInstance()->CreatePanel( |
| 581 title, window_profile, urls[0], panel_bounds.size()); | 581 title, window_profile, urls[0], panel_bounds.size()); |
| 582 | 582 |
| 583 // Unlike other window types, Panels do not take focus by default. | 583 // Unlike other window types, Panels do not take focus by default. |
| 584 if (!saw_focus_key || !focused) | 584 if (!saw_focus_key || !focused) |
| 585 panel->ShowInactive(); | 585 panel->ShowInactive(); |
| 586 else | 586 else |
| 587 panel->Show(); | 587 panel->Show(); |
| 588 | 588 |
| 589 SetResult( | 589 SetResult( |
| 590 panel->extension_window_controller()->CreateWindowValueWithTabs()); | 590 panel->extension_window_controller()->CreateWindowValueWithTabs( |
| 591 GetExtension())); |
| 591 return true; | 592 return true; |
| 592 } | 593 } |
| 593 #endif | 594 #endif |
| 594 // else fall through to create BrowserWindow | 595 // else fall through to create BrowserWindow |
| 595 } | 596 } |
| 596 | 597 |
| 597 // Create a new BrowserWindow. | 598 // Create a new BrowserWindow. |
| 598 Browser::CreateParams create_params(window_type, window_profile); | 599 Browser::CreateParams create_params(window_type, window_profile); |
| 599 if (extension_id.empty()) { | 600 if (extension_id.empty()) { |
| 600 create_params.initial_bounds = window_bounds; | 601 create_params.initial_bounds = window_bounds; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 if (focused) | 633 if (focused) |
| 633 new_window->window()->Show(); | 634 new_window->window()->Show(); |
| 634 else | 635 else |
| 635 new_window->window()->ShowInactive(); | 636 new_window->window()->ShowInactive(); |
| 636 | 637 |
| 637 if (new_window->profile()->IsOffTheRecord() && !include_incognito()) { | 638 if (new_window->profile()->IsOffTheRecord() && !include_incognito()) { |
| 638 // Don't expose incognito windows if the extension isn't allowed. | 639 // Don't expose incognito windows if the extension isn't allowed. |
| 639 SetResult(Value::CreateNullValue()); | 640 SetResult(Value::CreateNullValue()); |
| 640 } else { | 641 } else { |
| 641 SetResult( | 642 SetResult( |
| 642 new_window->extension_window_controller()->CreateWindowValueWithTabs()); | 643 new_window->extension_window_controller()->CreateWindowValueWithTabs( |
| 644 GetExtension())); |
| 643 } | 645 } |
| 644 | 646 |
| 645 return true; | 647 return true; |
| 646 } | 648 } |
| 647 | 649 |
| 648 bool UpdateWindowFunction::RunImpl() { | 650 bool UpdateWindowFunction::RunImpl() { |
| 649 int window_id = extension_misc::kUnknownWindowId; | 651 int window_id = extension_misc::kUnknownWindowId; |
| 650 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 652 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
| 651 DictionaryValue* update_props; | 653 DictionaryValue* update_props; |
| 652 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); | 654 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 return false; | 815 return false; |
| 814 | 816 |
| 815 TabStripModel* tab_strip = browser->tab_strip_model(); | 817 TabStripModel* tab_strip = browser->tab_strip_model(); |
| 816 TabContents* contents = tab_strip->GetActiveTabContents(); | 818 TabContents* contents = tab_strip->GetActiveTabContents(); |
| 817 if (!contents) { | 819 if (!contents) { |
| 818 error_ = keys::kNoSelectedTabError; | 820 error_ = keys::kNoSelectedTabError; |
| 819 return false; | 821 return false; |
| 820 } | 822 } |
| 821 SetResult(ExtensionTabUtil::CreateTabValue(contents->web_contents(), | 823 SetResult(ExtensionTabUtil::CreateTabValue(contents->web_contents(), |
| 822 tab_strip, | 824 tab_strip, |
| 823 tab_strip->active_index())); | 825 tab_strip->active_index(), |
| 826 GetExtension())); |
| 824 return true; | 827 return true; |
| 825 } | 828 } |
| 826 | 829 |
| 827 bool GetAllTabsInWindowFunction::RunImpl() { | 830 bool GetAllTabsInWindowFunction::RunImpl() { |
| 828 // windowId defaults to "current" window. | 831 // windowId defaults to "current" window. |
| 829 int window_id = extension_misc::kCurrentWindowId; | 832 int window_id = extension_misc::kCurrentWindowId; |
| 830 if (HasOptionalArgument(0)) | 833 if (HasOptionalArgument(0)) |
| 831 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 834 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
| 832 | 835 |
| 833 Browser* browser = NULL; | 836 Browser* browser = NULL; |
| 834 if (!GetBrowserFromWindowID(this, window_id, &browser)) | 837 if (!GetBrowserFromWindowID(this, window_id, &browser)) |
| 835 return false; | 838 return false; |
| 836 | 839 |
| 837 SetResult(ExtensionTabUtil::CreateTabList(browser)); | 840 SetResult(ExtensionTabUtil::CreateTabList(browser, GetExtension())); |
| 838 | 841 |
| 839 return true; | 842 return true; |
| 840 } | 843 } |
| 841 | 844 |
| 842 bool QueryTabsFunction::RunImpl() { | 845 bool QueryTabsFunction::RunImpl() { |
| 843 DictionaryValue* query = NULL; | 846 DictionaryValue* query = NULL; |
| 844 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &query)); | 847 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &query)); |
| 845 | 848 |
| 846 QueryArg active = ParseBoolQueryArg(query, keys::kActiveKey); | 849 QueryArg active = ParseBoolQueryArg(query, keys::kActiveKey); |
| 847 QueryArg pinned = ParseBoolQueryArg(query, keys::kPinnedKey); | 850 QueryArg pinned = ParseBoolQueryArg(query, keys::kPinnedKey); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 UTF8ToUTF16(title))) | 941 UTF8ToUTF16(title))) |
| 939 continue; | 942 continue; |
| 940 | 943 |
| 941 if (!url_pattern.MatchesURL(web_contents->GetURL())) | 944 if (!url_pattern.MatchesURL(web_contents->GetURL())) |
| 942 continue; | 945 continue; |
| 943 | 946 |
| 944 if (!MatchesQueryArg(loading, web_contents->IsLoading())) | 947 if (!MatchesQueryArg(loading, web_contents->IsLoading())) |
| 945 continue; | 948 continue; |
| 946 | 949 |
| 947 result->Append(ExtensionTabUtil::CreateTabValue( | 950 result->Append(ExtensionTabUtil::CreateTabValue( |
| 948 web_contents, tab_strip, i)); | 951 web_contents, tab_strip, i, GetExtension())); |
| 949 } | 952 } |
| 950 } | 953 } |
| 951 | 954 |
| 952 SetResult(result); | 955 SetResult(result); |
| 953 return true; | 956 return true; |
| 954 } | 957 } |
| 955 | 958 |
| 956 bool CreateTabFunction::RunImpl() { | 959 bool CreateTabFunction::RunImpl() { |
| 957 DictionaryValue* args = NULL; | 960 DictionaryValue* args = NULL; |
| 958 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 961 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 if (opener) | 1078 if (opener) |
| 1076 tab_strip->SetOpenerOfTabContentsAt(new_index, opener); | 1079 tab_strip->SetOpenerOfTabContentsAt(new_index, opener); |
| 1077 | 1080 |
| 1078 if (active) | 1081 if (active) |
| 1079 params.target_contents->web_contents()->GetView()->SetInitialFocus(); | 1082 params.target_contents->web_contents()->GetView()->SetInitialFocus(); |
| 1080 | 1083 |
| 1081 // Return data about the newly created tab. | 1084 // Return data about the newly created tab. |
| 1082 if (has_callback()) { | 1085 if (has_callback()) { |
| 1083 SetResult(ExtensionTabUtil::CreateTabValue( | 1086 SetResult(ExtensionTabUtil::CreateTabValue( |
| 1084 params.target_contents->web_contents(), | 1087 params.target_contents->web_contents(), |
| 1085 tab_strip, new_index)); | 1088 tab_strip, new_index, GetExtension())); |
| 1086 } | 1089 } |
| 1087 | 1090 |
| 1088 return true; | 1091 return true; |
| 1089 } | 1092 } |
| 1090 | 1093 |
| 1091 bool GetTabFunction::RunImpl() { | 1094 bool GetTabFunction::RunImpl() { |
| 1092 int tab_id = -1; | 1095 int tab_id = -1; |
| 1093 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); | 1096 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); |
| 1094 | 1097 |
| 1095 TabStripModel* tab_strip = NULL; | 1098 TabStripModel* tab_strip = NULL; |
| 1096 TabContents* contents = NULL; | 1099 TabContents* contents = NULL; |
| 1097 int tab_index = -1; | 1100 int tab_index = -1; |
| 1098 if (!GetTabById(tab_id, profile(), include_incognito(), | 1101 if (!GetTabById(tab_id, profile(), include_incognito(), |
| 1099 NULL, &tab_strip, &contents, &tab_index, &error_)) | 1102 NULL, &tab_strip, &contents, &tab_index, &error_)) |
| 1100 return false; | 1103 return false; |
| 1101 | 1104 |
| 1102 SetResult(ExtensionTabUtil::CreateTabValue(contents->web_contents(), | 1105 SetResult(ExtensionTabUtil::CreateTabValue(contents->web_contents(), |
| 1103 tab_strip, | 1106 tab_strip, |
| 1104 tab_index)); | 1107 tab_index, |
| 1108 GetExtension())); |
| 1105 return true; | 1109 return true; |
| 1106 } | 1110 } |
| 1107 | 1111 |
| 1108 bool GetCurrentTabFunction::RunImpl() { | 1112 bool GetCurrentTabFunction::RunImpl() { |
| 1109 DCHECK(dispatcher()); | 1113 DCHECK(dispatcher()); |
| 1110 | 1114 |
| 1111 WebContents* contents = dispatcher()->delegate()->GetAssociatedWebContents(); | 1115 WebContents* contents = dispatcher()->delegate()->GetAssociatedWebContents(); |
| 1112 if (contents) | 1116 if (contents) |
| 1113 SetResult(ExtensionTabUtil::CreateTabValue(contents)); | 1117 SetResult(ExtensionTabUtil::CreateTabValue(contents, GetExtension())); |
| 1114 | 1118 |
| 1115 return true; | 1119 return true; |
| 1116 } | 1120 } |
| 1117 | 1121 |
| 1118 bool HighlightTabsFunction::RunImpl() { | 1122 bool HighlightTabsFunction::RunImpl() { |
| 1119 DictionaryValue* info = NULL; | 1123 DictionaryValue* info = NULL; |
| 1120 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &info)); | 1124 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &info)); |
| 1121 | 1125 |
| 1122 // Get the window id from the params; default to current window if omitted. | 1126 // Get the window id from the params; default to current window if omitted. |
| 1123 int window_id = extension_misc::kCurrentWindowId; | 1127 int window_id = extension_misc::kCurrentWindowId; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 | 1164 |
| 1161 // Make sure they actually specified tabs to select. | 1165 // Make sure they actually specified tabs to select. |
| 1162 if (selection.empty()) { | 1166 if (selection.empty()) { |
| 1163 error_ = keys::kNoHighlightedTabError; | 1167 error_ = keys::kNoHighlightedTabError; |
| 1164 return false; | 1168 return false; |
| 1165 } | 1169 } |
| 1166 | 1170 |
| 1167 selection.set_active(active_index); | 1171 selection.set_active(active_index); |
| 1168 browser->tab_strip_model()->SetSelectionFromModel(selection); | 1172 browser->tab_strip_model()->SetSelectionFromModel(selection); |
| 1169 SetResult( | 1173 SetResult( |
| 1170 browser->extension_window_controller()->CreateWindowValueWithTabs()); | 1174 browser->extension_window_controller()->CreateWindowValueWithTabs( |
| 1175 GetExtension())); |
| 1171 return true; | 1176 return true; |
| 1172 } | 1177 } |
| 1173 | 1178 |
| 1174 UpdateTabFunction::UpdateTabFunction() : tab_contents_(NULL) { | 1179 UpdateTabFunction::UpdateTabFunction() : tab_contents_(NULL) { |
| 1175 } | 1180 } |
| 1176 | 1181 |
| 1177 bool UpdateTabFunction::RunImpl() { | 1182 bool UpdateTabFunction::RunImpl() { |
| 1178 DictionaryValue* update_props = NULL; | 1183 DictionaryValue* update_props = NULL; |
| 1179 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); | 1184 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); |
| 1180 | 1185 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1336 if (!url.SchemeIs(chrome::kJavaScriptScheme)) | 1341 if (!url.SchemeIs(chrome::kJavaScriptScheme)) |
| 1337 DCHECK_EQ(url.spec(), tab_contents_->web_contents()->GetURL().spec()); | 1342 DCHECK_EQ(url.spec(), tab_contents_->web_contents()->GetURL().spec()); |
| 1338 | 1343 |
| 1339 return true; | 1344 return true; |
| 1340 } | 1345 } |
| 1341 | 1346 |
| 1342 void UpdateTabFunction::PopulateResult() { | 1347 void UpdateTabFunction::PopulateResult() { |
| 1343 if (!has_callback()) | 1348 if (!has_callback()) |
| 1344 return; | 1349 return; |
| 1345 | 1350 |
| 1346 if (GetExtension()->HasAPIPermission(extensions::APIPermission::kTab)) { | 1351 SetResult(ExtensionTabUtil::CreateTabValue(tab_contents_->web_contents(), |
| 1347 SetResult(ExtensionTabUtil::CreateTabValue(tab_contents_->web_contents())); | 1352 GetExtension())); |
| 1348 } else { | |
| 1349 SetResult(Value::CreateNullValue()); | |
| 1350 } | |
| 1351 } | 1353 } |
| 1352 | 1354 |
| 1353 void UpdateTabFunction::OnExecuteCodeFinished(const std::string& error, | 1355 void UpdateTabFunction::OnExecuteCodeFinished(const std::string& error, |
| 1354 int32 on_page_id, | 1356 int32 on_page_id, |
| 1355 const GURL& url, | 1357 const GURL& url, |
| 1356 const ListValue& script_result) { | 1358 const ListValue& script_result) { |
| 1357 if (error.empty()) | 1359 if (error.empty()) |
| 1358 PopulateResult(); | 1360 PopulateResult(); |
| 1359 else | 1361 else |
| 1360 error_ = error; | 1362 error_ = error; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1432 | 1434 |
| 1433 // Clamp move location to the last position. | 1435 // Clamp move location to the last position. |
| 1434 // This is ">" because it can append to a new index position. | 1436 // This is ">" because it can append to a new index position. |
| 1435 // -1 means set the move location to the last position. | 1437 // -1 means set the move location to the last position. |
| 1436 if (new_index > target_tab_strip->count() || new_index < 0) | 1438 if (new_index > target_tab_strip->count() || new_index < 0) |
| 1437 new_index = target_tab_strip->count(); | 1439 new_index = target_tab_strip->count(); |
| 1438 | 1440 |
| 1439 target_tab_strip->InsertTabContentsAt( | 1441 target_tab_strip->InsertTabContentsAt( |
| 1440 new_index, contents, TabStripModel::ADD_NONE); | 1442 new_index, contents, TabStripModel::ADD_NONE); |
| 1441 | 1443 |
| 1442 if (has_callback()) | 1444 if (has_callback()) { |
| 1443 tab_values.Append(ExtensionTabUtil::CreateTabValue( | 1445 tab_values.Append(ExtensionTabUtil::CreateTabValue( |
| 1444 contents->web_contents(), target_tab_strip, new_index)); | 1446 contents->web_contents(), |
| 1447 target_tab_strip, |
| 1448 new_index, |
| 1449 GetExtension())); |
| 1450 } |
| 1445 | 1451 |
| 1446 continue; | 1452 continue; |
| 1447 } | 1453 } |
| 1448 } | 1454 } |
| 1449 | 1455 |
| 1450 // Perform a simple within-window move. | 1456 // Perform a simple within-window move. |
| 1451 // Clamp move location to the last position. | 1457 // Clamp move location to the last position. |
| 1452 // This is ">=" because the move must be to an existing location. | 1458 // This is ">=" because the move must be to an existing location. |
| 1453 // -1 means set the move location to the last position. | 1459 // -1 means set the move location to the last position. |
| 1454 if (new_index >= source_tab_strip->count() || new_index < 0) | 1460 if (new_index >= source_tab_strip->count() || new_index < 0) |
| 1455 new_index = source_tab_strip->count() - 1; | 1461 new_index = source_tab_strip->count() - 1; |
| 1456 | 1462 |
| 1457 if (new_index != tab_index) | 1463 if (new_index != tab_index) |
| 1458 source_tab_strip->MoveTabContentsAt(tab_index, new_index, false); | 1464 source_tab_strip->MoveTabContentsAt(tab_index, new_index, false); |
| 1459 | 1465 |
| 1460 if (has_callback()) | 1466 if (has_callback()) { |
| 1461 tab_values.Append(ExtensionTabUtil::CreateTabValue( | 1467 tab_values.Append(ExtensionTabUtil::CreateTabValue( |
| 1462 contents->web_contents(), source_tab_strip, new_index)); | 1468 contents->web_contents(), source_tab_strip, new_index, |
| 1469 GetExtension())); |
| 1470 } |
| 1463 } | 1471 } |
| 1464 | 1472 |
| 1465 if (!has_callback()) | 1473 if (!has_callback()) |
| 1466 return true; | 1474 return true; |
| 1467 | 1475 |
| 1468 // Only return the results as an array if there are multiple tabs. | 1476 // Only return the results as an array if there are multiple tabs. |
| 1469 if (tab_ids.size() > 1) { | 1477 if (tab_ids.size() > 1) { |
| 1470 SetResult(tab_values.DeepCopy()); | 1478 SetResult(tab_values.DeepCopy()); |
| 1471 } else if (tab_ids.size() == 1) { | 1479 } else if (tab_ids.size() == 1) { |
| 1472 Value* value = NULL; | 1480 Value* value = NULL; |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1823 // called for every API call the extension made. | 1831 // called for every API call the extension made. |
| 1824 GotLanguage(language); | 1832 GotLanguage(language); |
| 1825 } | 1833 } |
| 1826 | 1834 |
| 1827 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1835 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
| 1828 SetResult(Value::CreateStringValue(language.c_str())); | 1836 SetResult(Value::CreateStringValue(language.c_str())); |
| 1829 SendResponse(true); | 1837 SendResponse(true); |
| 1830 | 1838 |
| 1831 Release(); // Balanced in Run() | 1839 Release(); // Balanced in Run() |
| 1832 } | 1840 } |
| OLD | NEW |