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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "apps/shell_window.h" | 11 #include "apps/shell_window.h" |
12 #include "base/base64.h" | 12 #include "base/base64.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/ref_counted_memory.h" | 16 #include "base/memory/ref_counted_memory.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
18 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
20 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
22 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
23 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
24 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
25 #include "chrome/browser/chrome_notification_types.h" | 25 #include "chrome/browser/chrome_notification_types.h" |
26 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 26 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 27 #include "chrome/browser/extensions/api/tabs/windows_helper.h" |
27 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 28 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
28 #include "chrome/browser/extensions/extension_function_util.h" | 29 #include "chrome/browser/extensions/extension_function_util.h" |
29 #include "chrome/browser/extensions/extension_host.h" | 30 #include "chrome/browser/extensions/extension_host.h" |
30 #include "chrome/browser/extensions/extension_service.h" | 31 #include "chrome/browser/extensions/extension_service.h" |
31 #include "chrome/browser/extensions/extension_tab_util.h" | 32 #include "chrome/browser/extensions/extension_tab_util.h" |
32 #include "chrome/browser/extensions/script_executor.h" | 33 #include "chrome/browser/extensions/script_executor.h" |
33 #include "chrome/browser/extensions/tab_helper.h" | 34 #include "chrome/browser/extensions/tab_helper.h" |
34 #include "chrome/browser/extensions/window_controller.h" | 35 #include "chrome/browser/extensions/window_controller.h" |
35 #include "chrome/browser/extensions/window_controller_list.h" | 36 #include "chrome/browser/extensions/window_controller_list.h" |
36 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 37 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 *browser = GetBrowserInProfileWithId( | 164 *browser = GetBrowserInProfileWithId( |
164 function->profile(), window_id, function->include_incognito(), &error); | 165 function->profile(), window_id, function->include_incognito(), &error); |
165 if (!*browser) { | 166 if (!*browser) { |
166 function->SetError(error); | 167 function->SetError(error); |
167 return false; | 168 return false; |
168 } | 169 } |
169 } | 170 } |
170 return true; | 171 return true; |
171 } | 172 } |
172 | 173 |
173 bool GetWindowFromWindowID(UIThreadExtensionFunction* function, | |
174 int window_id, | |
175 WindowController** controller) { | |
176 if (window_id == extension_misc::kCurrentWindowId) { | |
177 WindowController* extension_window_controller = | |
178 function->dispatcher()->delegate()->GetExtensionWindowController(); | |
179 // If there is a window controller associated with this extension, use that. | |
180 if (extension_window_controller) { | |
181 *controller = extension_window_controller; | |
182 } else { | |
183 // Otherwise get the focused or most recently added window. | |
184 *controller = WindowControllerList::GetInstance()-> | |
185 CurrentWindowForFunction(function); | |
186 } | |
187 if (!(*controller)) { | |
188 function->SetError(keys::kNoCurrentWindowError); | |
189 return false; | |
190 } | |
191 } else { | |
192 *controller = WindowControllerList::GetInstance()-> | |
193 FindWindowForFunctionById(function, window_id); | |
194 if (!(*controller)) { | |
195 function->SetError(ErrorUtils::FormatErrorMessage( | |
196 keys::kWindowNotFoundError, base::IntToString(window_id))); | |
197 return false; | |
198 } | |
199 } | |
200 return true; | |
201 } | |
202 | |
203 // |error_message| can optionally be passed in and will be set with an | 174 // |error_message| can optionally be passed in and will be set with an |
204 // appropriate message if the tab cannot be found by id. | 175 // appropriate message if the tab cannot be found by id. |
205 bool GetTabById(int tab_id, | 176 bool GetTabById(int tab_id, |
206 Profile* profile, | 177 Profile* profile, |
207 bool include_incognito, | 178 bool include_incognito, |
208 Browser** browser, | 179 Browser** browser, |
209 TabStripModel** tab_strip, | 180 TabStripModel** tab_strip, |
210 content::WebContents** contents, | 181 content::WebContents** contents, |
211 int* tab_index, | 182 int* tab_index, |
212 std::string* error_message) { | 183 std::string* error_message) { |
(...skipping 1852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2065 execute_tab_id_ = tab_id; | 2036 execute_tab_id_ = tab_id; |
2066 details_ = details.Pass(); | 2037 details_ = details.Pass(); |
2067 return true; | 2038 return true; |
2068 } | 2039 } |
2069 | 2040 |
2070 bool TabsInsertCSSFunction::ShouldInsertCSS() const { | 2041 bool TabsInsertCSSFunction::ShouldInsertCSS() const { |
2071 return true; | 2042 return true; |
2072 } | 2043 } |
2073 | 2044 |
2074 } // namespace extensions | 2045 } // namespace extensions |
OLD | NEW |