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

Unified Diff: chrome/browser/extensions/api/tabs/tabs_api.cc

Issue 2153943002: Implementing TabManager extensions API Discard Function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixing comments Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698