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_api.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1091 // If index is specified, honor the value, but keep it bound to | 1091 // If index is specified, honor the value, but keep it bound to |
1092 // -1 <= index <= tab_strip->count() where -1 invokes the default behavior. | 1092 // -1 <= index <= tab_strip->count() where -1 invokes the default behavior. |
1093 int index = -1; | 1093 int index = -1; |
1094 if (args->HasKey(keys::kIndexKey)) | 1094 if (args->HasKey(keys::kIndexKey)) |
1095 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kIndexKey, &index)); | 1095 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kIndexKey, &index)); |
1096 | 1096 |
1097 TabStripModel* tab_strip = browser->tab_strip_model(); | 1097 TabStripModel* tab_strip = browser->tab_strip_model(); |
1098 | 1098 |
1099 index = std::min(std::max(index, -1), tab_strip->count()); | 1099 index = std::min(std::max(index, -1), tab_strip->count()); |
1100 | 1100 |
1101 int add_types = active ? TabStripModel::ADD_ACTIVE : | 1101 int add_types = active ? TabStripModel::ADD_ACTIVE : TabStripModel::ADD_NONE; |
1102 TabStripModel::ADD_NONE; | |
1103 add_types |= TabStripModel::ADD_FORCE_INDEX; | 1102 add_types |= TabStripModel::ADD_FORCE_INDEX; |
1104 if (pinned) | 1103 if (pinned) |
1105 add_types |= TabStripModel::ADD_PINNED; | 1104 add_types |= TabStripModel::ADD_PINNED; |
1106 chrome::NavigateParams params(browser, url, content::PAGE_TRANSITION_LINK); | 1105 chrome::NavigateParams params(browser, url, content::PAGE_TRANSITION_LINK); |
1107 params.disposition = active ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; | 1106 params.disposition = active ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; |
1108 params.tabstrip_index = index; | 1107 params.tabstrip_index = index; |
1109 params.tabstrip_add_types = add_types; | 1108 params.tabstrip_add_types = add_types; |
1110 chrome::Navigate(¶ms); | 1109 chrome::Navigate(¶ms); |
1111 | 1110 |
1112 // The tab may have been created in a different window, so make sure we look | 1111 // The tab may have been created in a different window, so make sure we look |
1113 // at the right tab strip. | 1112 // at the right tab strip. |
1114 tab_strip = params.browser->tab_strip_model(); | 1113 tab_strip = params.browser->tab_strip_model(); |
1115 int new_index = tab_strip->GetIndexOfWebContents(params.target_contents); | 1114 int new_index = tab_strip->GetIndexOfWebContents(params.target_contents); |
1116 if (opener) | 1115 if (opener) |
1117 tab_strip->SetOpenerOfWebContentsAt(new_index, opener); | 1116 tab_strip->SetOpenerOfWebContentsAt(new_index, opener); |
1118 | 1117 |
1119 if (active) | 1118 if (active) { |
1120 params.target_contents->GetView()->SetInitialFocus(); | 1119 params.target_contents->GetView()->SetInitialFocus(); |
1120 params.target_contents->GetDelegate()->ActivateContents( | |
1121 params.target_contents); | |
not at google - send to devlin
2013/02/13 01:28:11
here and below if you activate it does it automati
Matt Perry
2013/02/13 01:38:52
Good call, it does. I've removed the extraneous ca
| |
1122 } | |
1121 | 1123 |
1122 // Return data about the newly created tab. | 1124 // Return data about the newly created tab. |
1123 if (has_callback()) { | 1125 if (has_callback()) { |
1124 SetResult(ExtensionTabUtil::CreateTabValue( | 1126 SetResult(ExtensionTabUtil::CreateTabValue( |
1125 params.target_contents, | 1127 params.target_contents, |
1126 tab_strip, new_index, GetExtension())); | 1128 tab_strip, new_index, GetExtension())); |
1127 } | 1129 } |
1128 | 1130 |
1129 return true; | 1131 return true; |
1130 } | 1132 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1299 if (update_props->HasKey(keys::kActiveKey)) | 1301 if (update_props->HasKey(keys::kActiveKey)) |
1300 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( | 1302 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( |
1301 keys::kActiveKey, &active)); | 1303 keys::kActiveKey, &active)); |
1302 | 1304 |
1303 if (active) { | 1305 if (active) { |
1304 if (tab_strip->active_index() != tab_index) { | 1306 if (tab_strip->active_index() != tab_index) { |
1305 tab_strip->ActivateTabAt(tab_index, false); | 1307 tab_strip->ActivateTabAt(tab_index, false); |
1306 DCHECK_EQ(contents, tab_strip->GetActiveWebContents()); | 1308 DCHECK_EQ(contents, tab_strip->GetActiveWebContents()); |
1307 } | 1309 } |
1308 web_contents_->Focus(); | 1310 web_contents_->Focus(); |
1311 web_contents_->GetDelegate()->ActivateContents(web_contents_); | |
1309 } | 1312 } |
1310 | 1313 |
1311 if (update_props->HasKey(keys::kHighlightedKey)) { | 1314 if (update_props->HasKey(keys::kHighlightedKey)) { |
1312 bool highlighted = false; | 1315 bool highlighted = false; |
1313 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( | 1316 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( |
1314 keys::kHighlightedKey, &highlighted)); | 1317 keys::kHighlightedKey, &highlighted)); |
1315 if (highlighted != tab_strip->IsTabSelected(tab_index)) | 1318 if (highlighted != tab_strip->IsTabSelected(tab_index)) |
1316 tab_strip->ToggleSelectionAt(tab_index); | 1319 tab_strip->ToggleSelectionAt(tab_index); |
1317 } | 1320 } |
1318 | 1321 |
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2129 extension->id(), | 2132 extension->id(), |
2130 script_type, | 2133 script_type, |
2131 code_string, | 2134 code_string, |
2132 frame_scope, | 2135 frame_scope, |
2133 run_at, | 2136 run_at, |
2134 ScriptExecutor::ISOLATED_WORLD, | 2137 ScriptExecutor::ISOLATED_WORLD, |
2135 false /* is_web_view */, | 2138 false /* is_web_view */, |
2136 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this)); | 2139 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this)); |
2137 return true; | 2140 return true; |
2138 } | 2141 } |
OLD | NEW |