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/extension_tabs_module.h" | 5 #include "chrome/browser/extensions/extension_tabs_module.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "chrome/browser/extensions/extension_tab_util.h" | 26 #include "chrome/browser/extensions/extension_tab_util.h" |
27 #include "chrome/browser/extensions/extension_tabs_module_constants.h" | 27 #include "chrome/browser/extensions/extension_tabs_module_constants.h" |
28 #include "chrome/browser/extensions/extension_window_controller.h" | 28 #include "chrome/browser/extensions/extension_window_controller.h" |
29 #include "chrome/browser/extensions/extension_window_list.h" | 29 #include "chrome/browser/extensions/extension_window_list.h" |
30 #include "chrome/browser/extensions/script_executor.h" | 30 #include "chrome/browser/extensions/script_executor.h" |
31 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 31 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
32 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
33 #include "chrome/browser/sessions/restore_tab_helper.h" | 33 #include "chrome/browser/sessions/restore_tab_helper.h" |
34 #include "chrome/browser/translate/translate_tab_helper.h" | 34 #include "chrome/browser/translate/translate_tab_helper.h" |
35 #include "chrome/browser/ui/browser.h" | 35 #include "chrome/browser/ui/browser.h" |
| 36 #include "chrome/browser/ui/browser_finder.h" |
36 #include "chrome/browser/ui/browser_list.h" | 37 #include "chrome/browser/ui/browser_list.h" |
37 #include "chrome/browser/ui/browser_navigator.h" | 38 #include "chrome/browser/ui/browser_navigator.h" |
38 #include "chrome/browser/ui/browser_window.h" | 39 #include "chrome/browser/ui/browser_window.h" |
39 #include "chrome/browser/ui/extensions/shell_window.h" | 40 #include "chrome/browser/ui/extensions/shell_window.h" |
40 #include "chrome/browser/ui/panels/panel_manager.h" | 41 #include "chrome/browser/ui/panels/panel_manager.h" |
41 #include "chrome/browser/ui/snapshot_tab_helper.h" | 42 #include "chrome/browser/ui/snapshot_tab_helper.h" |
42 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 43 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
43 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 44 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
44 #include "chrome/browser/ui/window_sizer.h" | 45 #include "chrome/browser/ui/window_sizer.h" |
45 #include "chrome/browser/web_applications/web_app.h" | 46 #include "chrome/browser/web_applications/web_app.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 GetLastFocused::Params::Create(*args_)); | 297 GetLastFocused::Params::Create(*args_)); |
297 EXTENSION_FUNCTION_VALIDATE(params.get()); | 298 EXTENSION_FUNCTION_VALIDATE(params.get()); |
298 | 299 |
299 bool populate_tabs = false; | 300 bool populate_tabs = false; |
300 if (params->get_info.get() && params->get_info->populate.get()) | 301 if (params->get_info.get() && params->get_info->populate.get()) |
301 populate_tabs = *params->get_info->populate; | 302 populate_tabs = *params->get_info->populate; |
302 | 303 |
303 // Note: currently this returns the last active browser. If we decide to | 304 // Note: currently this returns the last active browser. If we decide to |
304 // include other window types (e.g. panels), we will need to add logic to | 305 // include other window types (e.g. panels), we will need to add logic to |
305 // ExtensionWindowList that mirrors the active behavior of BrowserList. | 306 // ExtensionWindowList that mirrors the active behavior of BrowserList. |
306 Browser* browser = BrowserList::FindAnyBrowser( | 307 Browser* browser = browser::FindAnyBrowser( |
307 profile(), include_incognito()); | 308 profile(), include_incognito()); |
308 if (!browser || !browser->window()) { | 309 if (!browser || !browser->window()) { |
309 error_ = keys::kNoLastFocusedWindowError; | 310 error_ = keys::kNoLastFocusedWindowError; |
310 return false; | 311 return false; |
311 } | 312 } |
312 ExtensionWindowController* controller = | 313 ExtensionWindowController* controller = |
313 browser->extension_window_controller(); | 314 browser->extension_window_controller(); |
314 if (populate_tabs) | 315 if (populate_tabs) |
315 result_.reset(controller->CreateWindowValueWithTabs()); | 316 result_.reset(controller->CreateWindowValueWithTabs()); |
316 else | 317 else |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 if (args->HasKey(keys::kWindowIdKey)) | 973 if (args->HasKey(keys::kWindowIdKey)) |
973 EXTENSION_FUNCTION_VALIDATE(args->GetInteger( | 974 EXTENSION_FUNCTION_VALIDATE(args->GetInteger( |
974 keys::kWindowIdKey, &window_id)); | 975 keys::kWindowIdKey, &window_id)); |
975 | 976 |
976 Browser* browser = NULL; | 977 Browser* browser = NULL; |
977 if (!GetBrowserFromWindowID(this, window_id, &browser)) | 978 if (!GetBrowserFromWindowID(this, window_id, &browser)) |
978 return false; | 979 return false; |
979 | 980 |
980 // Ensure the selected browser is tabbed. | 981 // Ensure the selected browser is tabbed. |
981 if (!browser->is_type_tabbed() && browser->IsAttemptingToCloseBrowser()) | 982 if (!browser->is_type_tabbed() && browser->IsAttemptingToCloseBrowser()) |
982 browser = Browser::GetTabbedBrowser(profile(), include_incognito()); | 983 browser = browser::FindTabbedBrowser(profile(), include_incognito()); |
983 | 984 |
984 if (!browser || !browser->window()) | 985 if (!browser || !browser->window()) |
985 return false; | 986 return false; |
986 | 987 |
987 // TODO(jstritar): Add a constant, chrome.tabs.TAB_ID_ACTIVE, that | 988 // TODO(jstritar): Add a constant, chrome.tabs.TAB_ID_ACTIVE, that |
988 // represents the active tab. | 989 // represents the active tab. |
989 content::NavigationController* opener = NULL; | 990 content::NavigationController* opener = NULL; |
990 if (args->HasKey(keys::kOpenerTabIdKey)) { | 991 if (args->HasKey(keys::kOpenerTabIdKey)) { |
991 int opener_id = -1; | 992 int opener_id = -1; |
992 EXTENSION_FUNCTION_VALIDATE(args->GetInteger( | 993 EXTENSION_FUNCTION_VALIDATE(args->GetInteger( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 bool pinned = false; | 1044 bool pinned = false; |
1044 if (args->HasKey(keys::kPinnedKey)) | 1045 if (args->HasKey(keys::kPinnedKey)) |
1045 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kPinnedKey, &pinned)); | 1046 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kPinnedKey, &pinned)); |
1046 | 1047 |
1047 // We can't load extension URLs into incognito windows unless the extension | 1048 // We can't load extension URLs into incognito windows unless the extension |
1048 // uses split mode. Special case to fall back to a tabbed window. | 1049 // uses split mode. Special case to fall back to a tabbed window. |
1049 if (url.SchemeIs(chrome::kExtensionScheme) && | 1050 if (url.SchemeIs(chrome::kExtensionScheme) && |
1050 !GetExtension()->incognito_split_mode() && | 1051 !GetExtension()->incognito_split_mode() && |
1051 browser->profile()->IsOffTheRecord()) { | 1052 browser->profile()->IsOffTheRecord()) { |
1052 Profile* profile = browser->profile()->GetOriginalProfile(); | 1053 Profile* profile = browser->profile()->GetOriginalProfile(); |
1053 browser = BrowserList::FindTabbedBrowser(profile, false); | 1054 browser = browser::FindTabbedBrowser(profile, false); |
1054 if (!browser) { | 1055 if (!browser) { |
1055 browser = Browser::Create(profile); | 1056 browser = Browser::Create(profile); |
1056 browser->window()->Show(); | 1057 browser->window()->Show(); |
1057 } | 1058 } |
1058 } | 1059 } |
1059 | 1060 |
1060 // If index is specified, honor the value, but keep it bound to | 1061 // If index is specified, honor the value, but keep it bound to |
1061 // -1 <= index <= tab_strip->count() where -1 invokes the default behavior. | 1062 // -1 <= index <= tab_strip->count() where -1 invokes the default behavior. |
1062 int index = -1; | 1063 int index = -1; |
1063 if (args->HasKey(keys::kIndexKey)) | 1064 if (args->HasKey(keys::kIndexKey)) |
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 // called for every API call the extension made. | 1816 // called for every API call the extension made. |
1816 GotLanguage(language); | 1817 GotLanguage(language); |
1817 } | 1818 } |
1818 | 1819 |
1819 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1820 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
1820 result_.reset(Value::CreateStringValue(language.c_str())); | 1821 result_.reset(Value::CreateStringValue(language.c_str())); |
1821 SendResponse(true); | 1822 SendResponse(true); |
1822 | 1823 |
1823 Release(); // Balanced in Run() | 1824 Release(); // Balanced in Run() |
1824 } | 1825 } |
OLD | NEW |