Chromium Code Reviews| 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 result to be returned. We have to return a Tab object, | |
| 2193 // then a default object is created and replaced with the real | |
| 2194 // tab in case of success (contents is not null). | |
| 2195 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
| |
| 2196 if (contents) | |
| 2197 tab = ExtensionTabUtil::CreateTabObject(contents); | |
| 2198 return RespondNow(ArgumentList(tabs::Discard::Results::Create(*tab))); | |
| 2199 } | |
| 2200 | |
| 2201 TabsDiscardFunction::TabsDiscardFunction() {} | |
| 2202 TabsDiscardFunction::~TabsDiscardFunction() {} | |
| 2203 | |
| 2171 } // namespace extensions | 2204 } // namespace extensions |
| OLD | NEW |