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 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 HostID(HostID::EXTENSIONS, extension_id()), | 1360 HostID(HostID::EXTENSIONS, extension_id()), |
1361 ScriptExecutor::JAVASCRIPT, | 1361 ScriptExecutor::JAVASCRIPT, |
1362 net::UnescapeURLComponent( | 1362 net::UnescapeURLComponent( |
1363 url.GetContent(), | 1363 url.GetContent(), |
1364 net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS | | 1364 net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS | |
1365 net::UnescapeRule::PATH_SEPARATORS | | 1365 net::UnescapeRule::PATH_SEPARATORS | |
1366 net::UnescapeRule::SPACES), | 1366 net::UnescapeRule::SPACES), |
1367 ScriptExecutor::SINGLE_FRAME, ExtensionApiFrameIdMap::kTopFrameId, | 1367 ScriptExecutor::SINGLE_FRAME, ExtensionApiFrameIdMap::kTopFrameId, |
1368 ScriptExecutor::DONT_MATCH_ABOUT_BLANK, UserScript::DOCUMENT_IDLE, | 1368 ScriptExecutor::DONT_MATCH_ABOUT_BLANK, UserScript::DOCUMENT_IDLE, |
1369 ScriptExecutor::MAIN_WORLD, ScriptExecutor::DEFAULT_PROCESS, GURL(), | 1369 ScriptExecutor::MAIN_WORLD, ScriptExecutor::DEFAULT_PROCESS, GURL(), |
1370 GURL(), user_gesture_, ScriptExecutor::NO_RESULT, | 1370 GURL(), user_gesture(), ScriptExecutor::NO_RESULT, |
1371 base::Bind(&TabsUpdateFunction::OnExecuteCodeFinished, this)); | 1371 base::Bind(&TabsUpdateFunction::OnExecuteCodeFinished, this)); |
1372 | 1372 |
1373 *is_async = true; | 1373 *is_async = true; |
1374 return true; | 1374 return true; |
1375 } | 1375 } |
1376 | 1376 |
1377 web_contents_->GetController().LoadURL( | 1377 web_contents_->GetController().LoadURL( |
1378 url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1378 url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1379 | 1379 |
1380 // The URL of a tab contents never actually changes to a JavaScript URL, so | 1380 // The URL of a tab contents never actually changes to a JavaScript URL, so |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2156 tabs::Discard::Params::Create(*args_)); | 2156 tabs::Discard::Params::Create(*args_)); |
2157 EXTENSION_FUNCTION_VALIDATE(params); | 2157 EXTENSION_FUNCTION_VALIDATE(params); |
2158 | 2158 |
2159 WebContents* contents = nullptr; | 2159 WebContents* contents = nullptr; |
2160 Profile* profile = Profile::FromBrowserContext(browser_context()); | 2160 Profile* profile = Profile::FromBrowserContext(browser_context()); |
2161 // If |tab_id| is given, find the web_contents respective to it. | 2161 // If |tab_id| is given, find the web_contents respective to it. |
2162 // Otherwise invoke discard function in TabManager with null web_contents | 2162 // Otherwise invoke discard function in TabManager with null web_contents |
2163 // that will discard the least important tab. | 2163 // that will discard the least important tab. |
2164 if (params->tab_id) { | 2164 if (params->tab_id) { |
2165 int tab_id = *params->tab_id; | 2165 int tab_id = *params->tab_id; |
| 2166 std::string error; |
2166 if (!GetTabById(tab_id, profile, include_incognito(), nullptr, nullptr, | 2167 if (!GetTabById(tab_id, profile, include_incognito(), nullptr, nullptr, |
2167 &contents, nullptr, &error_)) { | 2168 &contents, nullptr, &error)) { |
2168 return RespondNow(Error(error_)); | 2169 return RespondNow(Error(error)); |
2169 } | 2170 } |
2170 } | 2171 } |
2171 // Discard the tab. | 2172 // Discard the tab. |
2172 contents = | 2173 contents = |
2173 g_browser_process->GetTabManager()->DiscardTabByExtension(contents); | 2174 g_browser_process->GetTabManager()->DiscardTabByExtension(contents); |
2174 | 2175 |
2175 // Create the Tab object and return it in case of success. | 2176 // Create the Tab object and return it in case of success. |
2176 if (contents) { | 2177 if (contents) { |
2177 return RespondNow(ArgumentList(tabs::Discard::Results::Create( | 2178 return RespondNow(ArgumentList(tabs::Discard::Results::Create( |
2178 *ExtensionTabUtil::CreateTabObject(contents)))); | 2179 *ExtensionTabUtil::CreateTabObject(contents)))); |
2179 } | 2180 } |
2180 | 2181 |
2181 // Return appropriate error message otherwise. | 2182 // Return appropriate error message otherwise. |
2182 return RespondNow(Error( | 2183 return RespondNow(Error( |
2183 params->tab_id | 2184 params->tab_id |
2184 ? ErrorUtils::FormatErrorMessage(keys::kCannotDiscardTab, | 2185 ? ErrorUtils::FormatErrorMessage(keys::kCannotDiscardTab, |
2185 base::IntToString(*params->tab_id)) | 2186 base::IntToString(*params->tab_id)) |
2186 : keys::kCannotFindTabToDiscard)); | 2187 : keys::kCannotFindTabToDiscard)); |
2187 } | 2188 } |
2188 | 2189 |
2189 TabsDiscardFunction::TabsDiscardFunction() {} | 2190 TabsDiscardFunction::TabsDiscardFunction() {} |
2190 TabsDiscardFunction::~TabsDiscardFunction() {} | 2191 TabsDiscardFunction::~TabsDiscardFunction() {} |
2191 | 2192 |
2192 } // namespace extensions | 2193 } // namespace extensions |
OLD | NEW |