| OLD | NEW |
| 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 2150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2161 api::tabs::ZoomSettings zoom_settings; | 2161 api::tabs::ZoomSettings zoom_settings; |
| 2162 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); | 2162 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); |
| 2163 zoom_settings.default_zoom_factor.reset(new double( | 2163 zoom_settings.default_zoom_factor.reset(new double( |
| 2164 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); | 2164 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); |
| 2165 | 2165 |
| 2166 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); | 2166 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); |
| 2167 SendResponse(true); | 2167 SendResponse(true); |
| 2168 return true; | 2168 return true; |
| 2169 } | 2169 } |
| 2170 | 2170 |
| 2171 ExtensionFunction::ResponseAction TabsDiscardFunction::Run() { |
| 2172 std::unique_ptr<tabs::Discard::Params> params( |
| 2173 tabs::Discard::Params::Create(*args_)); |
| 2174 EXTENSION_FUNCTION_VALIDATE(params); |
| 2175 |
| 2176 WebContents* contents = nullptr; |
| 2177 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 2178 // If |tab_id| is given, find the web_contents respective to it. |
| 2179 // Otherwise invoke discard function in TabManager with null web_contents |
| 2180 // that will discard the least important tab. |
| 2181 if (params->tab_id) { |
| 2182 int tab_id = *params->tab_id; |
| 2183 if (!GetTabById(tab_id, profile, include_incognito(), nullptr, nullptr, |
| 2184 &contents, nullptr, &error_)) { |
| 2185 return RespondNow(Error(error_)); |
| 2186 } |
| 2187 } |
| 2188 // Discard the tab. |
| 2189 contents = |
| 2190 g_browser_process->GetTabManager()->DiscardTabByExtension(contents); |
| 2191 |
| 2192 // Create the Tab object and return it in case of success. |
| 2193 if (contents) { |
| 2194 return RespondNow(ArgumentList(tabs::Discard::Results::Create( |
| 2195 *ExtensionTabUtil::CreateTabObject(contents)))); |
| 2196 } |
| 2197 |
| 2198 // Return appropriate error message otherwise. |
| 2199 return RespondNow(Error( |
| 2200 params->tab_id |
| 2201 ? ErrorUtils::FormatErrorMessage(keys::kCannotDiscardTab, |
| 2202 base::IntToString(*params->tab_id)) |
| 2203 : keys::kCannotFindTabToDiscard)); |
| 2204 } |
| 2205 |
| 2206 TabsDiscardFunction::TabsDiscardFunction() {} |
| 2207 TabsDiscardFunction::~TabsDiscardFunction() {} |
| 2208 |
| 2171 } // namespace extensions | 2209 } // namespace extensions |
| OLD | NEW |