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

Side by Side 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 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 <memory>
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #include "content/public/browser/navigation_controller.h" 67 #include "content/public/browser/navigation_controller.h"
68 #include "content/public/browser/navigation_entry.h" 68 #include "content/public/browser/navigation_entry.h"
69 #include "content/public/browser/notification_details.h" 69 #include "content/public/browser/notification_details.h"
70 #include "content/public/browser/notification_source.h" 70 #include "content/public/browser/notification_source.h"
71 #include "content/public/browser/render_frame_host.h" 71 #include "content/public/browser/render_frame_host.h"
72 #include "content/public/browser/render_widget_host_view.h" 72 #include "content/public/browser/render_widget_host_view.h"
73 #include "content/public/browser/web_contents.h" 73 #include "content/public/browser/web_contents.h"
74 #include "content/public/common/url_constants.h" 74 #include "content/public/common/url_constants.h"
75 #include "extensions/browser/app_window/app_window.h" 75 #include "extensions/browser/app_window/app_window.h"
76 #include "extensions/browser/extension_api_frame_id_map.h" 76 #include "extensions/browser/extension_api_frame_id_map.h"
77 #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.
77 #include "extensions/browser/extension_function_dispatcher.h" 78 #include "extensions/browser/extension_function_dispatcher.h"
78 #include "extensions/browser/extension_host.h" 79 #include "extensions/browser/extension_host.h"
79 #include "extensions/browser/extension_zoom_request_client.h" 80 #include "extensions/browser/extension_zoom_request_client.h"
80 #include "extensions/browser/file_reader.h" 81 #include "extensions/browser/file_reader.h"
81 #include "extensions/browser/script_executor.h" 82 #include "extensions/browser/script_executor.h"
82 #include "extensions/common/api/extension_types.h" 83 #include "extensions/common/api/extension_types.h"
83 #include "extensions/common/constants.h" 84 #include "extensions/common/constants.h"
84 #include "extensions/common/error_utils.h" 85 #include "extensions/common/error_utils.h"
85 #include "extensions/common/extension.h" 86 #include "extensions/common/extension.h"
86 #include "extensions/common/host_id.h" 87 #include "extensions/common/host_id.h"
(...skipping 2074 matching lines...) Expand 10 before | Expand all | Expand 10 after
2161 api::tabs::ZoomSettings zoom_settings; 2162 api::tabs::ZoomSettings zoom_settings;
2162 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); 2163 ZoomModeToZoomSettings(zoom_mode, &zoom_settings);
2163 zoom_settings.default_zoom_factor.reset(new double( 2164 zoom_settings.default_zoom_factor.reset(new double(
2164 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); 2165 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel())));
2165 2166
2166 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); 2167 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings);
2167 SendResponse(true); 2168 SendResponse(true);
2168 return true; 2169 return true;
2169 } 2170 }
2170 2171
2172 ExtensionFunction::ResponseAction TabsDiscardFunction::Run() {
2173 std::unique_ptr<tabs::Discard::Params> params(
2174 tabs::Discard::Params::Create(*args_));
2175 EXTENSION_FUNCTION_VALIDATE(params);
2176
2177 WebContents* contents = nullptr;
2178 Profile* profile = Profile::FromBrowserContext(browser_context());
2179 // If |tab_id| is given, find the web_contents respective to it.
2180 // Otherwise invoke discard function in TabManager with null web_contents
2181 // that will discard the least important tab.
2182 if (params->tab_id) {
2183 int tab_id = *params->tab_id;
2184 if (!GetTabById(tab_id, profile, include_incognito(), nullptr, nullptr,
2185 &contents, nullptr, &error_)) {
2186 return RespondNow(Error(error_));
2187 }
2188 }
2189 // Discard the tab.
2190 contents =
2191 g_browser_process->GetTabManager()->DiscardTabByExtension(contents);
2192
2193 // Create result to be returned. We have to return a Tab object and the
2194 // success boolean, so create a default object and replace it with the
2195 // 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
2196 bool success = !!contents;
2197 std::unique_ptr<tabs::Tab> tab(new tabs::Tab);
2198 if (success)
2199 tab = ExtensionTabUtil::CreateTabObject(contents);
2200 return RespondNow(
2201 ArgumentList(tabs::Discard::Results::Create(*tab, success)));
2202 }
2203
2204 TabsDiscardFunction::TabsDiscardFunction() {}
2205 TabsDiscardFunction::~TabsDiscardFunction() {}
2206
2171 } // namespace extensions 2207 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698