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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 254 |
255 bool populate_tabs = false; | 255 bool populate_tabs = false; |
256 if (params->get_info.get() && params->get_info->populate.get()) | 256 if (params->get_info.get() && params->get_info->populate.get()) |
257 populate_tabs = *params->get_info->populate; | 257 populate_tabs = *params->get_info->populate; |
258 | 258 |
259 ExtensionWindowController* controller; | 259 ExtensionWindowController* controller; |
260 if (!GetWindowFromWindowID(this, params->window_id, &controller)) | 260 if (!GetWindowFromWindowID(this, params->window_id, &controller)) |
261 return false; | 261 return false; |
262 | 262 |
263 if (populate_tabs) | 263 if (populate_tabs) |
264 result_.reset(controller->CreateWindowValueWithTabs()); | 264 SetSingleResult(controller->CreateWindowValueWithTabs()); |
265 else | 265 else |
266 result_.reset(controller->CreateWindowValue()); | 266 SetSingleResult(controller->CreateWindowValue()); |
267 return true; | 267 return true; |
268 } | 268 } |
269 | 269 |
270 bool GetCurrentWindowFunction::RunImpl() { | 270 bool GetCurrentWindowFunction::RunImpl() { |
271 scoped_ptr<GetCurrent::Params> params(GetCurrent::Params::Create(*args_)); | 271 scoped_ptr<GetCurrent::Params> params(GetCurrent::Params::Create(*args_)); |
272 EXTENSION_FUNCTION_VALIDATE(params.get()); | 272 EXTENSION_FUNCTION_VALIDATE(params.get()); |
273 | 273 |
274 bool populate_tabs = false; | 274 bool populate_tabs = false; |
275 if (params->get_info.get() && params->get_info->populate.get()) | 275 if (params->get_info.get() && params->get_info->populate.get()) |
276 populate_tabs = *params->get_info->populate; | 276 populate_tabs = *params->get_info->populate; |
277 | 277 |
278 ExtensionWindowController* controller; | 278 ExtensionWindowController* controller; |
279 if (!GetWindowFromWindowID(this, | 279 if (!GetWindowFromWindowID(this, |
280 extension_misc::kCurrentWindowId, | 280 extension_misc::kCurrentWindowId, |
281 &controller)) { | 281 &controller)) { |
282 return false; | 282 return false; |
283 } | 283 } |
284 if (populate_tabs) | 284 if (populate_tabs) |
285 result_.reset(controller->CreateWindowValueWithTabs()); | 285 SetSingleResult(controller->CreateWindowValueWithTabs()); |
286 else | 286 else |
287 result_.reset(controller->CreateWindowValue()); | 287 SetSingleResult(controller->CreateWindowValue()); |
288 return true; | 288 return true; |
289 } | 289 } |
290 | 290 |
291 bool GetLastFocusedWindowFunction::RunImpl() { | 291 bool GetLastFocusedWindowFunction::RunImpl() { |
292 scoped_ptr<GetLastFocused::Params> params( | 292 scoped_ptr<GetLastFocused::Params> params( |
293 GetLastFocused::Params::Create(*args_)); | 293 GetLastFocused::Params::Create(*args_)); |
294 EXTENSION_FUNCTION_VALIDATE(params.get()); | 294 EXTENSION_FUNCTION_VALIDATE(params.get()); |
295 | 295 |
296 bool populate_tabs = false; | 296 bool populate_tabs = false; |
297 if (params->get_info.get() && params->get_info->populate.get()) | 297 if (params->get_info.get() && params->get_info->populate.get()) |
298 populate_tabs = *params->get_info->populate; | 298 populate_tabs = *params->get_info->populate; |
299 | 299 |
300 // Note: currently this returns the last active browser. If we decide to | 300 // Note: currently this returns the last active browser. If we decide to |
301 // include other window types (e.g. panels), we will need to add logic to | 301 // include other window types (e.g. panels), we will need to add logic to |
302 // ExtensionWindowList that mirrors the active behavior of BrowserList. | 302 // ExtensionWindowList that mirrors the active behavior of BrowserList. |
303 Browser* browser = browser::FindAnyBrowser( | 303 Browser* browser = browser::FindAnyBrowser( |
304 profile(), include_incognito()); | 304 profile(), include_incognito()); |
305 if (!browser || !browser->window()) { | 305 if (!browser || !browser->window()) { |
306 error_ = keys::kNoLastFocusedWindowError; | 306 error_ = keys::kNoLastFocusedWindowError; |
307 return false; | 307 return false; |
308 } | 308 } |
309 ExtensionWindowController* controller = | 309 ExtensionWindowController* controller = |
310 browser->extension_window_controller(); | 310 browser->extension_window_controller(); |
311 if (populate_tabs) | 311 if (populate_tabs) |
312 result_.reset(controller->CreateWindowValueWithTabs()); | 312 SetSingleResult(controller->CreateWindowValueWithTabs()); |
313 else | 313 else |
314 result_.reset(controller->CreateWindowValue()); | 314 SetSingleResult(controller->CreateWindowValue()); |
315 return true; | 315 return true; |
316 } | 316 } |
317 | 317 |
318 bool GetAllWindowsFunction::RunImpl() { | 318 bool GetAllWindowsFunction::RunImpl() { |
319 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_)); | 319 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_)); |
320 EXTENSION_FUNCTION_VALIDATE(params.get()); | 320 EXTENSION_FUNCTION_VALIDATE(params.get()); |
321 | 321 |
322 bool populate_tabs = false; | 322 bool populate_tabs = false; |
323 if (params->get_info.get() && params->get_info->populate.get()) | 323 if (params->get_info.get() && params->get_info->populate.get()) |
324 populate_tabs = *params->get_info->populate; | 324 populate_tabs = *params->get_info->populate; |
325 | 325 |
326 ListValue* window_list = new ListValue(); | 326 ListValue* window_list = new ListValue(); |
327 const ExtensionWindowList::WindowList& windows = | 327 const ExtensionWindowList::WindowList& windows = |
328 ExtensionWindowList::GetInstance()->windows(); | 328 ExtensionWindowList::GetInstance()->windows(); |
329 for (ExtensionWindowList::WindowList::const_iterator iter = | 329 for (ExtensionWindowList::WindowList::const_iterator iter = |
330 windows.begin(); | 330 windows.begin(); |
331 iter != windows.end(); ++iter) { | 331 iter != windows.end(); ++iter) { |
332 if (!this->CanOperateOnWindow(*iter)) | 332 if (!this->CanOperateOnWindow(*iter)) |
333 continue; | 333 continue; |
334 if (populate_tabs) | 334 if (populate_tabs) |
335 window_list->Append((*iter)->CreateWindowValueWithTabs()); | 335 window_list->Append((*iter)->CreateWindowValueWithTabs()); |
336 else | 336 else |
337 window_list->Append((*iter)->CreateWindowValue()); | 337 window_list->Append((*iter)->CreateWindowValue()); |
338 } | 338 } |
339 result_.reset(window_list); | 339 SetSingleResult(window_list); |
340 return true; | 340 return true; |
341 } | 341 } |
342 | 342 |
343 bool CreateWindowFunction::ShouldOpenIncognitoWindow( | 343 bool CreateWindowFunction::ShouldOpenIncognitoWindow( |
344 const base::DictionaryValue* args, | 344 const base::DictionaryValue* args, |
345 std::vector<GURL>* urls, | 345 std::vector<GURL>* urls, |
346 bool* is_error) { | 346 bool* is_error) { |
347 *is_error = false; | 347 *is_error = false; |
348 const IncognitoModePrefs::Availability incognito_availability = | 348 const IncognitoModePrefs::Availability incognito_availability = |
349 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); | 349 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 if (window_type == Browser::TYPE_PANEL) { | 576 if (window_type == Browser::TYPE_PANEL) { |
577 std::string title = | 577 std::string title = |
578 web_app::GenerateApplicationNameFromExtensionId(extension_id); | 578 web_app::GenerateApplicationNameFromExtensionId(extension_id); |
579 #if defined(USE_ASH) | 579 #if defined(USE_ASH) |
580 // Aura Panels create a new PanelViewAura. | 580 // Aura Panels create a new PanelViewAura. |
581 if (CommandLine::ForCurrentProcess()->HasSwitch( | 581 if (CommandLine::ForCurrentProcess()->HasSwitch( |
582 ash::switches::kAuraPanelManager)) { | 582 ash::switches::kAuraPanelManager)) { |
583 // Note: Panels ignore all but the first url provided. | 583 // Note: Panels ignore all but the first url provided. |
584 PanelViewAura* panel_view = new PanelViewAura(title); | 584 PanelViewAura* panel_view = new PanelViewAura(title); |
585 panel_view->Init(window_profile, urls[0], panel_bounds); | 585 panel_view->Init(window_profile, urls[0], panel_bounds); |
586 result_.reset(panel_view->extension_window_controller()-> | 586 SetSingleResult(panel_view->extension_window_controller()-> |
587 CreateWindowValueWithTabs()); | 587 CreateWindowValueWithTabs()); |
588 return true; | 588 return true; |
589 } | 589 } |
590 #else | 590 #else |
591 if (CommandLine::ForCurrentProcess()->HasSwitch( | 591 if (CommandLine::ForCurrentProcess()->HasSwitch( |
592 switches::kBrowserlessPanels)) { | 592 switches::kBrowserlessPanels)) { |
593 // Note: Panels ignore all but the first url provided. | 593 // Note: Panels ignore all but the first url provided. |
594 Panel* panel = PanelManager::GetInstance()->CreatePanel( | 594 Panel* panel = PanelManager::GetInstance()->CreatePanel( |
595 title, window_profile, urls[0], panel_bounds.size()); | 595 title, window_profile, urls[0], panel_bounds.size()); |
596 | 596 |
597 // Unlike other window types, Panels do not take focus by default. | 597 // Unlike other window types, Panels do not take focus by default. |
598 if (!saw_focus_key || !focused) | 598 if (!saw_focus_key || !focused) |
599 panel->ShowInactive(); | 599 panel->ShowInactive(); |
600 else | 600 else |
601 panel->Show(); | 601 panel->Show(); |
602 | 602 |
603 result_.reset( | 603 SetSingleResult( |
604 panel->extension_window_controller()->CreateWindowValueWithTabs()); | 604 panel->extension_window_controller()->CreateWindowValueWithTabs()); |
605 return true; | 605 return true; |
606 } | 606 } |
607 #endif | 607 #endif |
608 // else fall through to create BrowserWindow | 608 // else fall through to create BrowserWindow |
609 } | 609 } |
610 | 610 |
611 // Create a new BrowserWindow. | 611 // Create a new BrowserWindow. |
612 Browser::CreateParams create_params; | 612 Browser::CreateParams create_params; |
613 if (extension_id.empty()) { | 613 if (extension_id.empty()) { |
(...skipping 30 matching lines...) Expand all Loading... |
644 if (!saw_focus_key && window_type == Browser::TYPE_PANEL) | 644 if (!saw_focus_key && window_type == Browser::TYPE_PANEL) |
645 focused = false; | 645 focused = false; |
646 | 646 |
647 if (focused) | 647 if (focused) |
648 new_window->window()->Show(); | 648 new_window->window()->Show(); |
649 else | 649 else |
650 new_window->window()->ShowInactive(); | 650 new_window->window()->ShowInactive(); |
651 | 651 |
652 if (new_window->profile()->IsOffTheRecord() && !include_incognito()) { | 652 if (new_window->profile()->IsOffTheRecord() && !include_incognito()) { |
653 // Don't expose incognito windows if the extension isn't allowed. | 653 // Don't expose incognito windows if the extension isn't allowed. |
654 result_.reset(Value::CreateNullValue()); | 654 SetSingleResult(Value::CreateNullValue()); |
655 } else { | 655 } else { |
656 result_.reset( | 656 SetSingleResult( |
657 new_window->extension_window_controller()->CreateWindowValueWithTabs()); | 657 new_window->extension_window_controller()->CreateWindowValueWithTabs()); |
658 } | 658 } |
659 | 659 |
660 return true; | 660 return true; |
661 } | 661 } |
662 | 662 |
663 bool UpdateWindowFunction::RunImpl() { | 663 bool UpdateWindowFunction::RunImpl() { |
664 int window_id = extension_misc::kUnknownWindowId; | 664 int window_id = extension_misc::kUnknownWindowId; |
665 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 665 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
666 DictionaryValue* update_props; | 666 DictionaryValue* update_props; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 } | 784 } |
785 } | 785 } |
786 | 786 |
787 bool draw_attention = false; | 787 bool draw_attention = false; |
788 if (update_props->HasKey(keys::kDrawAttentionKey)) { | 788 if (update_props->HasKey(keys::kDrawAttentionKey)) { |
789 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( | 789 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( |
790 keys::kDrawAttentionKey, &draw_attention)); | 790 keys::kDrawAttentionKey, &draw_attention)); |
791 controller->window()->FlashFrame(draw_attention); | 791 controller->window()->FlashFrame(draw_attention); |
792 } | 792 } |
793 | 793 |
794 result_.reset(controller->CreateWindowValue()); | 794 SetSingleResult(controller->CreateWindowValue()); |
795 | 795 |
796 return true; | 796 return true; |
797 } | 797 } |
798 | 798 |
799 bool RemoveWindowFunction::RunImpl() { | 799 bool RemoveWindowFunction::RunImpl() { |
800 int window_id = -1; | 800 int window_id = -1; |
801 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 801 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
802 | 802 |
803 ExtensionWindowController* controller; | 803 ExtensionWindowController* controller; |
804 if (!GetWindowFromWindowID(this, window_id, &controller)) | 804 if (!GetWindowFromWindowID(this, window_id, &controller)) |
(...skipping 21 matching lines...) Expand all Loading... |
826 Browser* browser = NULL; | 826 Browser* browser = NULL; |
827 if (!GetBrowserFromWindowID(this, window_id, &browser)) | 827 if (!GetBrowserFromWindowID(this, window_id, &browser)) |
828 return false; | 828 return false; |
829 | 829 |
830 TabStripModel* tab_strip = browser->tab_strip_model(); | 830 TabStripModel* tab_strip = browser->tab_strip_model(); |
831 TabContents* contents = tab_strip->GetActiveTabContents(); | 831 TabContents* contents = tab_strip->GetActiveTabContents(); |
832 if (!contents) { | 832 if (!contents) { |
833 error_ = keys::kNoSelectedTabError; | 833 error_ = keys::kNoSelectedTabError; |
834 return false; | 834 return false; |
835 } | 835 } |
836 result_.reset(ExtensionTabUtil::CreateTabValue(contents->web_contents(), | 836 SetSingleResult(ExtensionTabUtil::CreateTabValue(contents->web_contents(), |
837 tab_strip, | 837 tab_strip, |
838 tab_strip->active_index())); | 838 tab_strip->active_index())); |
839 return true; | 839 return true; |
840 } | 840 } |
841 | 841 |
842 bool GetAllTabsInWindowFunction::RunImpl() { | 842 bool GetAllTabsInWindowFunction::RunImpl() { |
843 // windowId defaults to "current" window. | 843 // windowId defaults to "current" window. |
844 int window_id = extension_misc::kCurrentWindowId; | 844 int window_id = extension_misc::kCurrentWindowId; |
845 if (HasOptionalArgument(0)) | 845 if (HasOptionalArgument(0)) |
846 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 846 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
847 | 847 |
848 Browser* browser = NULL; | 848 Browser* browser = NULL; |
849 if (!GetBrowserFromWindowID(this, window_id, &browser)) | 849 if (!GetBrowserFromWindowID(this, window_id, &browser)) |
850 return false; | 850 return false; |
851 | 851 |
852 result_.reset(ExtensionTabUtil::CreateTabList(browser)); | 852 SetSingleResult(ExtensionTabUtil::CreateTabList(browser)); |
853 | 853 |
854 return true; | 854 return true; |
855 } | 855 } |
856 | 856 |
857 bool QueryTabsFunction::RunImpl() { | 857 bool QueryTabsFunction::RunImpl() { |
858 DictionaryValue* query = NULL; | 858 DictionaryValue* query = NULL; |
859 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &query)); | 859 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &query)); |
860 | 860 |
861 QueryArg active = ParseBoolQueryArg(query, keys::kActiveKey); | 861 QueryArg active = ParseBoolQueryArg(query, keys::kActiveKey); |
862 QueryArg pinned = ParseBoolQueryArg(query, keys::kPinnedKey); | 862 QueryArg pinned = ParseBoolQueryArg(query, keys::kPinnedKey); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 continue; | 957 continue; |
958 | 958 |
959 if (!MatchesQueryArg(loading, web_contents->IsLoading())) | 959 if (!MatchesQueryArg(loading, web_contents->IsLoading())) |
960 continue; | 960 continue; |
961 | 961 |
962 result->Append(ExtensionTabUtil::CreateTabValue( | 962 result->Append(ExtensionTabUtil::CreateTabValue( |
963 web_contents, tab_strip, i)); | 963 web_contents, tab_strip, i)); |
964 } | 964 } |
965 } | 965 } |
966 | 966 |
967 result_.reset(result); | 967 SetSingleResult(result); |
968 return true; | 968 return true; |
969 } | 969 } |
970 | 970 |
971 bool CreateTabFunction::RunImpl() { | 971 bool CreateTabFunction::RunImpl() { |
972 DictionaryValue* args = NULL; | 972 DictionaryValue* args = NULL; |
973 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 973 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
974 | 974 |
975 // windowId defaults to "current" window. | 975 // windowId defaults to "current" window. |
976 int window_id = extension_misc::kCurrentWindowId; | 976 int window_id = extension_misc::kCurrentWindowId; |
977 if (args->HasKey(keys::kWindowIdKey)) | 977 if (args->HasKey(keys::kWindowIdKey)) |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 tab_strip = params.browser->tab_strip_model(); | 1088 tab_strip = params.browser->tab_strip_model(); |
1089 int new_index = tab_strip->GetIndexOfTabContents(params.target_contents); | 1089 int new_index = tab_strip->GetIndexOfTabContents(params.target_contents); |
1090 if (opener) | 1090 if (opener) |
1091 tab_strip->SetOpenerOfTabContentsAt(new_index, opener); | 1091 tab_strip->SetOpenerOfTabContentsAt(new_index, opener); |
1092 | 1092 |
1093 if (active) | 1093 if (active) |
1094 params.target_contents->web_contents()->GetView()->SetInitialFocus(); | 1094 params.target_contents->web_contents()->GetView()->SetInitialFocus(); |
1095 | 1095 |
1096 // Return data about the newly created tab. | 1096 // Return data about the newly created tab. |
1097 if (has_callback()) { | 1097 if (has_callback()) { |
1098 result_.reset(ExtensionTabUtil::CreateTabValue( | 1098 SetSingleResult(ExtensionTabUtil::CreateTabValue( |
1099 params.target_contents->web_contents(), | 1099 params.target_contents->web_contents(), |
1100 tab_strip, new_index)); | 1100 tab_strip, new_index)); |
1101 } | 1101 } |
1102 | 1102 |
1103 return true; | 1103 return true; |
1104 } | 1104 } |
1105 | 1105 |
1106 bool GetTabFunction::RunImpl() { | 1106 bool GetTabFunction::RunImpl() { |
1107 int tab_id = -1; | 1107 int tab_id = -1; |
1108 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); | 1108 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); |
1109 | 1109 |
1110 TabStripModel* tab_strip = NULL; | 1110 TabStripModel* tab_strip = NULL; |
1111 TabContents* contents = NULL; | 1111 TabContents* contents = NULL; |
1112 int tab_index = -1; | 1112 int tab_index = -1; |
1113 if (!GetTabById(tab_id, profile(), include_incognito(), | 1113 if (!GetTabById(tab_id, profile(), include_incognito(), |
1114 NULL, &tab_strip, &contents, &tab_index, &error_)) | 1114 NULL, &tab_strip, &contents, &tab_index, &error_)) |
1115 return false; | 1115 return false; |
1116 | 1116 |
1117 result_.reset(ExtensionTabUtil::CreateTabValue(contents->web_contents(), | 1117 SetSingleResult(ExtensionTabUtil::CreateTabValue(contents->web_contents(), |
1118 tab_strip, | 1118 tab_strip, |
1119 tab_index)); | 1119 tab_index)); |
1120 return true; | 1120 return true; |
1121 } | 1121 } |
1122 | 1122 |
1123 bool GetCurrentTabFunction::RunImpl() { | 1123 bool GetCurrentTabFunction::RunImpl() { |
1124 DCHECK(dispatcher()); | 1124 DCHECK(dispatcher()); |
1125 | 1125 |
1126 WebContents* contents = dispatcher()->delegate()->GetAssociatedWebContents(); | 1126 WebContents* contents = dispatcher()->delegate()->GetAssociatedWebContents(); |
1127 if (contents) | 1127 if (contents) |
1128 result_.reset(ExtensionTabUtil::CreateTabValue(contents)); | 1128 SetSingleResult(ExtensionTabUtil::CreateTabValue(contents)); |
1129 | 1129 |
1130 return true; | 1130 return true; |
1131 } | 1131 } |
1132 | 1132 |
1133 bool HighlightTabsFunction::RunImpl() { | 1133 bool HighlightTabsFunction::RunImpl() { |
1134 DictionaryValue* info = NULL; | 1134 DictionaryValue* info = NULL; |
1135 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &info)); | 1135 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &info)); |
1136 | 1136 |
1137 // Get the window id from the params; default to current window if omitted. | 1137 // Get the window id from the params; default to current window if omitted. |
1138 int window_id = extension_misc::kCurrentWindowId; | 1138 int window_id = extension_misc::kCurrentWindowId; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 } | 1174 } |
1175 | 1175 |
1176 // Make sure they actually specified tabs to select. | 1176 // Make sure they actually specified tabs to select. |
1177 if (selection.empty()) { | 1177 if (selection.empty()) { |
1178 error_ = keys::kNoHighlightedTabError; | 1178 error_ = keys::kNoHighlightedTabError; |
1179 return false; | 1179 return false; |
1180 } | 1180 } |
1181 | 1181 |
1182 selection.set_active(active_index); | 1182 selection.set_active(active_index); |
1183 browser->tab_strip_model()->SetSelectionFromModel(selection); | 1183 browser->tab_strip_model()->SetSelectionFromModel(selection); |
1184 result_.reset( | 1184 SetSingleResult( |
1185 browser->extension_window_controller()->CreateWindowValueWithTabs()); | 1185 browser->extension_window_controller()->CreateWindowValueWithTabs()); |
1186 return true; | 1186 return true; |
1187 } | 1187 } |
1188 | 1188 |
1189 UpdateTabFunction::UpdateTabFunction() : tab_contents_(NULL) { | 1189 UpdateTabFunction::UpdateTabFunction() : tab_contents_(NULL) { |
1190 } | 1190 } |
1191 | 1191 |
1192 bool UpdateTabFunction::RunImpl() { | 1192 bool UpdateTabFunction::RunImpl() { |
1193 DictionaryValue* update_props = NULL; | 1193 DictionaryValue* update_props = NULL; |
1194 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); | 1194 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1348 DCHECK_EQ(url.spec(), tab_contents_->web_contents()->GetURL().spec()); | 1348 DCHECK_EQ(url.spec(), tab_contents_->web_contents()->GetURL().spec()); |
1349 | 1349 |
1350 return true; | 1350 return true; |
1351 } | 1351 } |
1352 | 1352 |
1353 void UpdateTabFunction::PopulateResult() { | 1353 void UpdateTabFunction::PopulateResult() { |
1354 if (!has_callback()) | 1354 if (!has_callback()) |
1355 return; | 1355 return; |
1356 | 1356 |
1357 if (GetExtension()->HasAPIPermission(extensions::APIPermission::kTab)) { | 1357 if (GetExtension()->HasAPIPermission(extensions::APIPermission::kTab)) { |
1358 result_.reset( | 1358 SetSingleResult( |
1359 ExtensionTabUtil::CreateTabValue(tab_contents_->web_contents())); | 1359 ExtensionTabUtil::CreateTabValue(tab_contents_->web_contents())); |
1360 } else { | 1360 } else { |
1361 result_.reset(Value::CreateNullValue()); | 1361 SetSingleResult(Value::CreateNullValue()); |
1362 } | 1362 } |
1363 } | 1363 } |
1364 | 1364 |
1365 void UpdateTabFunction::OnExecuteCodeFinished(bool success, | 1365 void UpdateTabFunction::OnExecuteCodeFinished(bool success, |
1366 int32 page_id, | 1366 int32 page_id, |
1367 const std::string& error) { | 1367 const std::string& error) { |
1368 if (!error.empty()) { | 1368 if (!error.empty()) { |
1369 CHECK(!success); | 1369 CHECK(!success); |
1370 error_ = error; | 1370 error_ = error; |
1371 } | 1371 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 if (has_callback()) | 1474 if (has_callback()) |
1475 tab_values.Append(ExtensionTabUtil::CreateTabValue( | 1475 tab_values.Append(ExtensionTabUtil::CreateTabValue( |
1476 contents->web_contents(), source_tab_strip, new_index)); | 1476 contents->web_contents(), source_tab_strip, new_index)); |
1477 } | 1477 } |
1478 | 1478 |
1479 if (!has_callback()) | 1479 if (!has_callback()) |
1480 return true; | 1480 return true; |
1481 | 1481 |
1482 // Only return the results as an array if there are multiple tabs. | 1482 // Only return the results as an array if there are multiple tabs. |
1483 if (tab_ids.size() > 1) { | 1483 if (tab_ids.size() > 1) { |
1484 result_.reset(tab_values.DeepCopy()); | 1484 SetSingleResult(tab_values.DeepCopy()); |
1485 } else if (tab_ids.size() == 1) { | 1485 } else if (tab_ids.size() == 1) { |
1486 Value* value = NULL; | 1486 Value* value = NULL; |
1487 CHECK(tab_values.Get(0, &value)); | 1487 CHECK(tab_values.Get(0, &value)); |
1488 result_.reset(value->DeepCopy()); | 1488 SetSingleResult(value->DeepCopy()); |
1489 } | 1489 } |
1490 return true; | 1490 return true; |
1491 } | 1491 } |
1492 | 1492 |
1493 bool ReloadTabFunction::RunImpl() { | 1493 bool ReloadTabFunction::RunImpl() { |
1494 bool bypass_cache = false; | 1494 bool bypass_cache = false; |
1495 if (HasOptionalArgument(1)) { | 1495 if (HasOptionalArgument(1)) { |
1496 DictionaryValue* reload_props = NULL; | 1496 DictionaryValue* reload_props = NULL; |
1497 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &reload_props)); | 1497 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &reload_props)); |
1498 | 1498 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1745 return; | 1745 return; |
1746 } | 1746 } |
1747 | 1747 |
1748 std::string base64_result; | 1748 std::string base64_result; |
1749 base::StringPiece stream_as_string( | 1749 base::StringPiece stream_as_string( |
1750 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); | 1750 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); |
1751 | 1751 |
1752 base::Base64Encode(stream_as_string, &base64_result); | 1752 base::Base64Encode(stream_as_string, &base64_result); |
1753 base64_result.insert(0, base::StringPrintf("data:%s;base64,", | 1753 base64_result.insert(0, base::StringPrintf("data:%s;base64,", |
1754 mime_type.c_str())); | 1754 mime_type.c_str())); |
1755 result_.reset(new StringValue(base64_result)); | 1755 SetSingleResult(new StringValue(base64_result)); |
1756 SendResponse(true); | 1756 SendResponse(true); |
1757 } | 1757 } |
1758 | 1758 |
1759 bool DetectTabLanguageFunction::RunImpl() { | 1759 bool DetectTabLanguageFunction::RunImpl() { |
1760 int tab_id = 0; | 1760 int tab_id = 0; |
1761 Browser* browser = NULL; | 1761 Browser* browser = NULL; |
1762 TabContents* contents = NULL; | 1762 TabContents* contents = NULL; |
1763 | 1763 |
1764 // If |tab_id| is specified, look for it. Otherwise default to selected tab | 1764 // If |tab_id| is specified, look for it. Otherwise default to selected tab |
1765 // in the current window. | 1765 // in the current window. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1821 language = *content::Details<std::string>(details).ptr(); | 1821 language = *content::Details<std::string>(details).ptr(); |
1822 | 1822 |
1823 registrar_.RemoveAll(); | 1823 registrar_.RemoveAll(); |
1824 | 1824 |
1825 // Call GotLanguage in all cases as we want to guarantee the callback is | 1825 // Call GotLanguage in all cases as we want to guarantee the callback is |
1826 // called for every API call the extension made. | 1826 // called for every API call the extension made. |
1827 GotLanguage(language); | 1827 GotLanguage(language); |
1828 } | 1828 } |
1829 | 1829 |
1830 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1830 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
1831 result_.reset(Value::CreateStringValue(language.c_str())); | 1831 SetSingleResult(Value::CreateStringValue(language.c_str())); |
1832 SendResponse(true); | 1832 SendResponse(true); |
1833 | 1833 |
1834 Release(); // Balanced in Run() | 1834 Release(); // Balanced in Run() |
1835 } | 1835 } |
OLD | NEW |