Chromium Code Reviews| Index: chrome/browser/extensions/api/tabs/tabs_api.cc |
| diff --git a/chrome/browser/extensions/api/tabs/tabs_api.cc b/chrome/browser/extensions/api/tabs/tabs_api.cc |
| index 082822b843de360c5af776ec9653ec3abb9dad99..f9e22ab3ae5fb07cfc7b57ece73cc4a35cae76c9 100644 |
| --- a/chrome/browser/extensions/api/tabs/tabs_api.cc |
| +++ b/chrome/browser/extensions/api/tabs/tabs_api.cc |
| @@ -74,6 +74,7 @@ |
| #include "content/public/common/url_constants.h" |
| #include "extensions/browser/app_window/app_window.h" |
| #include "extensions/browser/extension_api_frame_id_map.h" |
| +#include "extensions/browser/extension_function.h" |
|
Devlin
2016/07/21 15:39:21
no need to include this, since it's included in th
Anderson Silva
2016/07/21 20:43:04
Done.
|
| #include "extensions/browser/extension_function_dispatcher.h" |
| #include "extensions/browser/extension_host.h" |
| #include "extensions/browser/extension_zoom_request_client.h" |
| @@ -2168,4 +2169,39 @@ bool TabsGetZoomSettingsFunction::RunAsync() { |
| return true; |
| } |
| +ExtensionFunction::ResponseAction TabsDiscardFunction::Run() { |
| + std::unique_ptr<tabs::Discard::Params> params( |
| + tabs::Discard::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE(params); |
| + |
| + WebContents* contents = nullptr; |
| + Profile* profile = Profile::FromBrowserContext(browser_context()); |
| + // If |tab_id| is given, find the web_contents respective to it. |
| + // Otherwise invoke discard function in TabManager with null web_contents |
| + // that will discard the least important tab. |
| + if (params->tab_id) { |
| + int tab_id = *params->tab_id; |
| + if (!GetTabById(tab_id, profile, include_incognito(), nullptr, nullptr, |
| + &contents, nullptr, &error_)) { |
| + return RespondNow(Error(error_)); |
| + } |
| + } |
| + // Discard the tab. |
| + contents = |
| + g_browser_process->GetTabManager()->DiscardTabByExtension(contents); |
| + |
| + // Create result to be returned. We have to return a Tab object and the |
| + // success boolean, so create a default object and replace it with the |
| + // real tab in case of success (contents is not null). |
|
Devlin
2016/07/21 15:39:21
Why not return undefined in the case of no tab dis
Anderson Silva
2016/07/21 20:43:04
Done.
Removed the boolean. It was necessary before
|
| + bool success = !!contents; |
| + std::unique_ptr<tabs::Tab> tab(new tabs::Tab); |
| + if (success) |
| + tab = ExtensionTabUtil::CreateTabObject(contents); |
| + return RespondNow( |
| + ArgumentList(tabs::Discard::Results::Create(*tab, success))); |
| +} |
| + |
| +TabsDiscardFunction::TabsDiscardFunction() {} |
| +TabsDiscardFunction::~TabsDiscardFunction() {} |
| + |
| } // namespace extensions |