Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: chrome/browser/extensions/api/tabs/windows_util.cc

Issue 2386823002: [Extensions] Remove ExtensionFunction::SetError() (Closed)
Patch Set: lazyboy's Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "chrome/browser/extensions/api/tabs/windows_util.h" 8 #include "chrome/browser/extensions/api/tabs/windows_util.h"
9 9
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 11 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
12 #include "chrome/browser/extensions/chrome_extension_function.h" 12 #include "chrome/browser/extensions/chrome_extension_function.h"
13 #include "chrome/browser/extensions/chrome_extension_function_details.h" 13 #include "chrome/browser/extensions/chrome_extension_function_details.h"
14 #include "chrome/browser/extensions/extension_util.h" 14 #include "chrome/browser/extensions/extension_util.h"
15 #include "chrome/browser/extensions/window_controller.h" 15 #include "chrome/browser/extensions/window_controller.h"
16 #include "chrome/browser/extensions/window_controller_list.h" 16 #include "chrome/browser/extensions/window_controller_list.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "extensions/browser/extension_function.h" 18 #include "extensions/browser/extension_function.h"
19 #include "extensions/browser/extension_function_dispatcher.h" 19 #include "extensions/browser/extension_function_dispatcher.h"
20 #include "extensions/common/constants.h" 20 #include "extensions/common/constants.h"
21 #include "extensions/common/error_utils.h" 21 #include "extensions/common/error_utils.h"
22 #include "extensions/common/extension.h" 22 #include "extensions/common/extension.h"
23 23
24 namespace windows_util { 24 namespace windows_util {
25 25
26 bool GetWindowFromWindowID(UIThreadExtensionFunction* function, 26 bool GetWindowFromWindowID(UIThreadExtensionFunction* function,
27 int window_id, 27 int window_id,
28 extensions::WindowController::TypeFilter filter, 28 extensions::WindowController::TypeFilter filter,
29 extensions::WindowController** controller) { 29 extensions::WindowController** controller,
30 std::string* error) {
31 DCHECK(error);
30 if (window_id == extension_misc::kCurrentWindowId) { 32 if (window_id == extension_misc::kCurrentWindowId) {
31 extensions::WindowController* extension_window_controller = 33 extensions::WindowController* extension_window_controller =
32 function->dispatcher()->GetExtensionWindowController(); 34 function->dispatcher()->GetExtensionWindowController();
33 // If there is a window controller associated with this extension, use that. 35 // If there is a window controller associated with this extension, use that.
34 if (extension_window_controller) { 36 if (extension_window_controller) {
35 *controller = extension_window_controller; 37 *controller = extension_window_controller;
36 } else { 38 } else {
37 // Otherwise get the focused or most recently added window. 39 // Otherwise get the focused or most recently added window.
38 *controller = extensions::WindowControllerList::GetInstance() 40 *controller = extensions::WindowControllerList::GetInstance()
39 ->CurrentWindowForFunctionWithFilter(function, filter); 41 ->CurrentWindowForFunctionWithFilter(function, filter);
40 } 42 }
41 if (!(*controller)) { 43 if (!(*controller)) {
42 function->SetError(extensions::tabs_constants::kNoCurrentWindowError); 44 *error = extensions::tabs_constants::kNoCurrentWindowError;
43 return false; 45 return false;
44 } 46 }
45 } else { 47 } else {
46 *controller = 48 *controller =
47 extensions::WindowControllerList::GetInstance() 49 extensions::WindowControllerList::GetInstance()
48 ->FindWindowForFunctionByIdWithFilter(function, window_id, filter); 50 ->FindWindowForFunctionByIdWithFilter(function, window_id, filter);
49 if (!(*controller)) { 51 if (!(*controller)) {
50 function->SetError(extensions::ErrorUtils::FormatErrorMessage( 52 *error = extensions::ErrorUtils::FormatErrorMessage(
51 extensions::tabs_constants::kWindowNotFoundError, 53 extensions::tabs_constants::kWindowNotFoundError,
52 base::IntToString(window_id))); 54 base::IntToString(window_id));
53 return false; 55 return false;
54 } 56 }
55 } 57 }
56 return true; 58 return true;
57 } 59 }
58 60
59 bool CanOperateOnWindow(const UIThreadExtensionFunction* function, 61 bool CanOperateOnWindow(const UIThreadExtensionFunction* function,
60 const extensions::WindowController* controller, 62 const extensions::WindowController* controller,
61 extensions::WindowController::TypeFilter filter) { 63 extensions::WindowController::TypeFilter filter) {
62 if (filter && !controller->MatchesFilter(filter)) 64 if (filter && !controller->MatchesFilter(filter))
63 return false; 65 return false;
64 66
65 if (!filter && function->extension() && 67 if (!filter && function->extension() &&
66 !controller->IsVisibleToExtension(function->extension())) 68 !controller->IsVisibleToExtension(function->extension()))
67 return false; 69 return false;
68 70
69 if (function->browser_context() == controller->profile()) 71 if (function->browser_context() == controller->profile())
70 return true; 72 return true;
71 73
72 if (!function->include_incognito()) 74 if (!function->include_incognito())
73 return false; 75 return false;
74 76
75 Profile* profile = Profile::FromBrowserContext(function->browser_context()); 77 Profile* profile = Profile::FromBrowserContext(function->browser_context());
76 return profile->HasOffTheRecordProfile() && 78 return profile->HasOffTheRecordProfile() &&
77 profile->GetOffTheRecordProfile() == controller->profile(); 79 profile->GetOffTheRecordProfile() == controller->profile();
78 } 80 }
79 81
80 } // namespace windows_util 82 } // namespace windows_util
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tabs/windows_util.h ('k') | chrome/browser/extensions/chrome_extension_function.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698