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..067bff6104f81434fd93949c61bd2036fa2e2d54 100644 |
| --- a/chrome/browser/extensions/api/tabs/tabs_api.cc |
| +++ b/chrome/browser/extensions/api/tabs/tabs_api.cc |
| @@ -2168,4 +2168,37 @@ 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, |
| + // then a default object is created and replaced with the real |
| + // tab in case of success (contents is not null). |
| + std::unique_ptr<tabs::Tab> tab(new tabs::Tab); |
|
Devlin
2016/07/22 18:39:19
This won't be undefined, then, it'll be a tab obje
Anderson Silva
2016/07/22 20:18:25
Yes, it's a tab object. I tested in an extension a
Devlin
2016/07/22 20:20:53
^^ This. :) Marking the field as optional and the
Anderson Silva
2016/07/22 22:50:14
Done.
Empty unique_ptr crashes but no arguments wo
|
| + if (contents) |
| + tab = ExtensionTabUtil::CreateTabObject(contents); |
| + return RespondNow(ArgumentList(tabs::Discard::Results::Create(*tab))); |
| +} |
| + |
| +TabsDiscardFunction::TabsDiscardFunction() {} |
| +TabsDiscardFunction::~TabsDiscardFunction() {} |
| + |
| } // namespace extensions |