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

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

Issue 1991083002: Remove ExtensionFunction::SetResult(T*) overload. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IWYU Created 4 years, 7 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
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_api.h" 5 #include "chrome/browser/extensions/api/tabs/tabs_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <limits> 9 #include <limits>
10 #include <memory>
10 #include <utility> 11 #include <utility>
11 #include <vector> 12 #include <vector>
12 13
13 #include "base/bind.h" 14 #include "base/bind.h"
14 #include "base/command_line.h" 15 #include "base/command_line.h"
15 #include "base/location.h" 16 #include "base/location.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/memory/ptr_util.h"
17 #include "base/memory/ref_counted_memory.h" 19 #include "base/memory/ref_counted_memory.h"
18 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
19 #include "base/stl_util.h" 21 #include "base/stl_util.h"
20 #include "base/strings/pattern.h" 22 #include "base/strings/pattern.h"
21 #include "base/strings/string16.h" 23 #include "base/strings/string16.h"
22 #include "base/strings/string_number_conversions.h" 24 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_util.h" 25 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h" 26 #include "base/strings/stringprintf.h"
25 #include "base/strings/utf_string_conversions.h" 27 #include "base/strings/utf_string_conversions.h"
26 #include "base/threading/thread_task_runner_handle.h" 28 #include "base/threading/thread_task_runner_handle.h"
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 SetResult(controller->CreateWindowValue()); 352 SetResult(controller->CreateWindowValue());
351 return true; 353 return true;
352 } 354 }
353 355
354 bool WindowsGetAllFunction::RunSync() { 356 bool WindowsGetAllFunction::RunSync() {
355 std::unique_ptr<windows::GetAll::Params> params( 357 std::unique_ptr<windows::GetAll::Params> params(
356 windows::GetAll::Params::Create(*args_)); 358 windows::GetAll::Params::Create(*args_));
357 EXTENSION_FUNCTION_VALIDATE(params.get()); 359 EXTENSION_FUNCTION_VALIDATE(params.get());
358 360
359 ApiParameterExtractor<windows::GetAll::Params> extractor(params.get()); 361 ApiParameterExtractor<windows::GetAll::Params> extractor(params.get());
360 base::ListValue* window_list = new base::ListValue(); 362 std::unique_ptr<base::ListValue> window_list(new base::ListValue());
361 const WindowControllerList::ControllerList& windows = 363 const WindowControllerList::ControllerList& windows =
362 WindowControllerList::GetInstance()->windows(); 364 WindowControllerList::GetInstance()->windows();
363 for (WindowControllerList::ControllerList::const_iterator iter = 365 for (WindowControllerList::ControllerList::const_iterator iter =
364 windows.begin(); 366 windows.begin();
365 iter != windows.end(); ++iter) { 367 iter != windows.end(); ++iter) {
366 if (!windows_util::CanOperateOnWindow(this, *iter, 368 if (!windows_util::CanOperateOnWindow(this, *iter,
367 extractor.type_filters())) 369 extractor.type_filters()))
368 continue; 370 continue;
369 if (extractor.populate_tabs()) 371 if (extractor.populate_tabs())
370 window_list->Append((*iter)->CreateWindowValueWithTabs(extension())); 372 window_list->Append((*iter)->CreateWindowValueWithTabs(extension()));
371 else 373 else
372 window_list->Append((*iter)->CreateWindowValue()); 374 window_list->Append((*iter)->CreateWindowValue());
373 } 375 }
374 SetResult(window_list); 376 SetResult(std::move(window_list));
375 return true; 377 return true;
376 } 378 }
377 379
378 bool WindowsCreateFunction::ShouldOpenIncognitoWindow( 380 bool WindowsCreateFunction::ShouldOpenIncognitoWindow(
379 const windows::Create::Params::CreateData* create_data, 381 const windows::Create::Params::CreateData* create_data,
380 std::vector<GURL>* urls, bool* is_error) { 382 std::vector<GURL>* urls, bool* is_error) {
381 *is_error = false; 383 *is_error = false;
382 const IncognitoModePrefs::Availability incognito_availability = 384 const IncognitoModePrefs::Availability incognito_availability =
383 IncognitoModePrefs::GetAvailability(GetProfile()->GetPrefs()); 385 IncognitoModePrefs::GetAvailability(GetProfile()->GetPrefs());
384 bool incognito = false; 386 bool incognito = false;
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 window_id = *params->query_info.window_id; 913 window_id = *params->query_info.window_id;
912 914
913 int index = -1; 915 int index = -1;
914 if (params->query_info.index.get()) 916 if (params->query_info.index.get())
915 index = *params->query_info.index; 917 index = *params->query_info.index;
916 918
917 std::string window_type; 919 std::string window_type;
918 if (params->query_info.window_type != tabs::WINDOW_TYPE_NONE) 920 if (params->query_info.window_type != tabs::WINDOW_TYPE_NONE)
919 window_type = tabs::ToString(params->query_info.window_type); 921 window_type = tabs::ToString(params->query_info.window_type);
920 922
921 base::ListValue* result = new base::ListValue(); 923 std::unique_ptr<base::ListValue> result(new base::ListValue());
922 Browser* last_active_browser = 924 Browser* last_active_browser =
923 chrome::FindAnyBrowser(GetProfile(), include_incognito()); 925 chrome::FindAnyBrowser(GetProfile(), include_incognito());
924 Browser* current_browser = GetCurrentBrowser(); 926 Browser* current_browser = GetCurrentBrowser();
925 for (auto* browser : *BrowserList::GetInstance()) { 927 for (auto* browser : *BrowserList::GetInstance()) {
926 if (!GetProfile()->IsSameProfile(browser->profile())) 928 if (!GetProfile()->IsSameProfile(browser->profile()))
927 continue; 929 continue;
928 930
929 if (!browser->window()) 931 if (!browser->window())
930 continue; 932 continue;
931 933
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 if (loading_status_set && loading != web_contents->IsLoading()) 1023 if (loading_status_set && loading != web_contents->IsLoading())
1022 continue; 1024 continue;
1023 1025
1024 result->Append(ExtensionTabUtil::CreateTabObject(web_contents, tab_strip, 1026 result->Append(ExtensionTabUtil::CreateTabObject(web_contents, tab_strip,
1025 i, extension()) 1027 i, extension())
1026 ->ToValue() 1028 ->ToValue()
1027 .release()); 1029 .release());
1028 } 1030 }
1029 } 1031 }
1030 1032
1031 SetResult(result); 1033 SetResult(std::move(result));
1032 return true; 1034 return true;
1033 } 1035 }
1034 1036
1035 bool TabsCreateFunction::RunSync() { 1037 bool TabsCreateFunction::RunSync() {
1036 std::unique_ptr<tabs::Create::Params> params( 1038 std::unique_ptr<tabs::Create::Params> params(
1037 tabs::Create::Params::Create(*args_)); 1039 tabs::Create::Params::Create(*args_));
1038 EXTENSION_FUNCTION_VALIDATE(params.get()); 1040 EXTENSION_FUNCTION_VALIDATE(params.get());
1039 1041
1040 ExtensionTabUtil::OpenTabParams options; 1042 ExtensionTabUtil::OpenTabParams options;
1041 AssignOptionalValue(params->create_properties.window_id, options.window_id); 1043 AssignOptionalValue(params->create_properties.window_id, options.window_id);
1042 AssignOptionalValue(params->create_properties.opener_tab_id, 1044 AssignOptionalValue(params->create_properties.opener_tab_id,
1043 options.opener_tab_id); 1045 options.opener_tab_id);
1044 AssignOptionalValue(params->create_properties.selected, options.active); 1046 AssignOptionalValue(params->create_properties.selected, options.active);
1045 // The 'active' property has replaced the 'selected' property. 1047 // The 'active' property has replaced the 'selected' property.
1046 AssignOptionalValue(params->create_properties.active, options.active); 1048 AssignOptionalValue(params->create_properties.active, options.active);
1047 AssignOptionalValue(params->create_properties.pinned, options.pinned); 1049 AssignOptionalValue(params->create_properties.pinned, options.pinned);
1048 AssignOptionalValue(params->create_properties.index, options.index); 1050 AssignOptionalValue(params->create_properties.index, options.index);
1049 AssignOptionalValue(params->create_properties.url, options.url); 1051 AssignOptionalValue(params->create_properties.url, options.url);
1050 1052
1051 std::string error; 1053 std::string error;
1052 std::unique_ptr<base::DictionaryValue> result( 1054 std::unique_ptr<base::DictionaryValue> result(
1053 ExtensionTabUtil::OpenTab(this, options, &error)); 1055 ExtensionTabUtil::OpenTab(this, options, &error));
1054 if (!result) { 1056 if (!result) {
1055 SetError(error); 1057 SetError(error);
1056 return false; 1058 return false;
1057 } 1059 }
1058 1060
1059 // Return data about the newly created tab. 1061 // Return data about the newly created tab.
1060 if (has_callback()) { 1062 if (has_callback()) {
1061 SetResult(result.release()); 1063 SetResult(std::move(result));
1062 } 1064 }
1063 return true; 1065 return true;
1064 } 1066 }
1065 1067
1066 bool TabsDuplicateFunction::RunSync() { 1068 bool TabsDuplicateFunction::RunSync() {
1067 std::unique_ptr<tabs::Duplicate::Params> params( 1069 std::unique_ptr<tabs::Duplicate::Params> params(
1068 tabs::Duplicate::Params::Create(*args_)); 1070 tabs::Duplicate::Params::Create(*args_));
1069 EXTENSION_FUNCTION_VALIDATE(params.get()); 1071 EXTENSION_FUNCTION_VALIDATE(params.get());
1070 int tab_id = params->tab_id; 1072 int tab_id = params->tab_id;
1071 1073
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 1446
1445 if (!has_callback()) 1447 if (!has_callback())
1446 return true; 1448 return true;
1447 1449
1448 if (num_tabs == 0) { 1450 if (num_tabs == 0) {
1449 error_ = "No tabs given."; 1451 error_ = "No tabs given.";
1450 return false; 1452 return false;
1451 } else if (num_tabs == 1) { 1453 } else if (num_tabs == 1) {
1452 std::unique_ptr<base::Value> value; 1454 std::unique_ptr<base::Value> value;
1453 CHECK(tab_values.get()->Remove(0, &value)); 1455 CHECK(tab_values.get()->Remove(0, &value));
1454 SetResult(value.release()); 1456 SetResult(std::move(value));
1455 } else { 1457 } else {
1456 // Only return the results as an array if there are multiple tabs. 1458 // Only return the results as an array if there are multiple tabs.
1457 SetResult(tab_values.release()); 1459 SetResult(std::move(tab_values));
1458 } 1460 }
1459 1461
1460 return true; 1462 return true;
1461 } 1463 }
1462 1464
1463 bool TabsMoveFunction::MoveTab(int tab_id, 1465 bool TabsMoveFunction::MoveTab(int tab_id,
1464 int* new_index, 1466 int* new_index,
1465 int iteration, 1467 int iteration,
1466 base::ListValue* tab_values, 1468 base::ListValue* tab_values,
1467 int* window_id) { 1469 int* window_id) {
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1727 this)); 1729 this));
1728 } 1730 }
1729 1731
1730 void TabsCaptureVisibleTabFunction::OnCaptureSuccess(const SkBitmap& bitmap) { 1732 void TabsCaptureVisibleTabFunction::OnCaptureSuccess(const SkBitmap& bitmap) {
1731 std::string base64_result; 1733 std::string base64_result;
1732 if (!EncodeBitmap(bitmap, &base64_result)) { 1734 if (!EncodeBitmap(bitmap, &base64_result)) {
1733 OnCaptureFailure(FAILURE_REASON_ENCODING_FAILED); 1735 OnCaptureFailure(FAILURE_REASON_ENCODING_FAILED);
1734 return; 1736 return;
1735 } 1737 }
1736 1738
1737 SetResult(new base::StringValue(base64_result)); 1739 SetResult(base::MakeUnique<base::StringValue>(base64_result));
1738 SendResponse(true); 1740 SendResponse(true);
1739 } 1741 }
1740 1742
1741 void TabsCaptureVisibleTabFunction::OnCaptureFailure(FailureReason reason) { 1743 void TabsCaptureVisibleTabFunction::OnCaptureFailure(FailureReason reason) {
1742 const char* reason_description = "internal error"; 1744 const char* reason_description = "internal error";
1743 switch (reason) { 1745 switch (reason) {
1744 case FAILURE_REASON_UNKNOWN: 1746 case FAILURE_REASON_UNKNOWN:
1745 reason_description = "unknown error"; 1747 reason_description = "unknown error";
1746 break; 1748 break;
1747 case FAILURE_REASON_ENCODING_FAILED: 1749 case FAILURE_REASON_ENCODING_FAILED:
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1843 } 1845 }
1844 1846
1845 registrar_.RemoveAll(); 1847 registrar_.RemoveAll();
1846 1848
1847 // Call GotLanguage in all cases as we want to guarantee the callback is 1849 // Call GotLanguage in all cases as we want to guarantee the callback is
1848 // called for every API call the extension made. 1850 // called for every API call the extension made.
1849 GotLanguage(language); 1851 GotLanguage(language);
1850 } 1852 }
1851 1853
1852 void TabsDetectLanguageFunction::GotLanguage(const std::string& language) { 1854 void TabsDetectLanguageFunction::GotLanguage(const std::string& language) {
1853 SetResult(new base::StringValue(language.c_str())); 1855 SetResult(base::MakeUnique<base::StringValue>(language.c_str()));
1854 SendResponse(true); 1856 SendResponse(true);
1855 1857
1856 Release(); // Balanced in Run() 1858 Release(); // Balanced in Run()
1857 } 1859 }
1858 1860
1859 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() 1861 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction()
1860 : chrome_details_(this), execute_tab_id_(-1) { 1862 : chrome_details_(this), execute_tab_id_(-1) {
1861 } 1863 }
1862 1864
1863 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {} 1865 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {}
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1999 2001
2000 bool TabsExecuteScriptFunction::ShouldInsertCSS() const { 2002 bool TabsExecuteScriptFunction::ShouldInsertCSS() const {
2001 return false; 2003 return false;
2002 } 2004 }
2003 2005
2004 void TabsExecuteScriptFunction::OnExecuteCodeFinished( 2006 void TabsExecuteScriptFunction::OnExecuteCodeFinished(
2005 const std::string& error, 2007 const std::string& error,
2006 const GURL& on_url, 2008 const GURL& on_url,
2007 const base::ListValue& result) { 2009 const base::ListValue& result) {
2008 if (error.empty()) 2010 if (error.empty())
2009 SetResult(result.DeepCopy()); 2011 SetResult(result.CreateDeepCopy());
2010 ExecuteCodeInTabFunction::OnExecuteCodeFinished(error, on_url, result); 2012 ExecuteCodeInTabFunction::OnExecuteCodeFinished(error, on_url, result);
2011 } 2013 }
2012 2014
2013 bool TabsInsertCSSFunction::ShouldInsertCSS() const { 2015 bool TabsInsertCSSFunction::ShouldInsertCSS() const {
2014 return true; 2016 return true;
2015 } 2017 }
2016 2018
2017 content::WebContents* ZoomAPIFunction::GetWebContents(int tab_id) { 2019 content::WebContents* ZoomAPIFunction::GetWebContents(int tab_id) {
2018 content::WebContents* web_contents = NULL; 2020 content::WebContents* web_contents = NULL;
2019 if (tab_id != -1) { 2021 if (tab_id != -1) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2155 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); 2157 ZoomModeToZoomSettings(zoom_mode, &zoom_settings);
2156 zoom_settings.default_zoom_factor.reset(new double( 2158 zoom_settings.default_zoom_factor.reset(new double(
2157 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); 2159 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel())));
2158 2160
2159 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); 2161 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings);
2160 SendResponse(true); 2162 SendResponse(true);
2161 return true; 2163 return true;
2162 } 2164 }
2163 2165
2164 } // namespace extensions 2166 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698