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