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/permissions/permissions_api.h" | 5 #include "chrome/browser/extensions/api/permissions/permissions_api.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" | 8 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/permissions_updater.h" | 10 #include "chrome/browser/extensions/permissions_updater.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 enum AutoConfirmForTest { | 45 enum AutoConfirmForTest { |
46 DO_NOT_SKIP = 0, | 46 DO_NOT_SKIP = 0, |
47 PROCEED, | 47 PROCEED, |
48 ABORT | 48 ABORT |
49 }; | 49 }; |
50 AutoConfirmForTest auto_confirm_for_tests = DO_NOT_SKIP; | 50 AutoConfirmForTest auto_confirm_for_tests = DO_NOT_SKIP; |
51 bool ignore_user_gesture_for_tests = false; | 51 bool ignore_user_gesture_for_tests = false; |
52 | 52 |
53 } // namespace | 53 } // namespace |
54 | 54 |
55 bool ContainsPermissionsFunction::RunImpl() { | 55 bool PermissionsContainsFunction::RunImpl() { |
56 scoped_ptr<Contains::Params> params(Contains::Params::Create(*args_)); | 56 scoped_ptr<Contains::Params> params(Contains::Params::Create(*args_)); |
57 | 57 |
58 scoped_refptr<PermissionSet> permissions = | 58 scoped_refptr<PermissionSet> permissions = |
59 helpers::UnpackPermissionSet(params->permissions, &error_); | 59 helpers::UnpackPermissionSet(params->permissions, &error_); |
60 if (!permissions.get()) | 60 if (!permissions.get()) |
61 return false; | 61 return false; |
62 | 62 |
63 results_ = Contains::Results::Create( | 63 results_ = Contains::Results::Create( |
64 GetExtension()->GetActivePermissions()->Contains(*permissions)); | 64 GetExtension()->GetActivePermissions()->Contains(*permissions)); |
65 return true; | 65 return true; |
66 } | 66 } |
67 | 67 |
68 bool GetAllPermissionsFunction::RunImpl() { | 68 bool PermissionsGetAllFunction::RunImpl() { |
69 scoped_ptr<Permissions> permissions = | 69 scoped_ptr<Permissions> permissions = |
70 helpers::PackPermissionSet(GetExtension()->GetActivePermissions()); | 70 helpers::PackPermissionSet(GetExtension()->GetActivePermissions()); |
71 results_ = GetAll::Results::Create(*permissions); | 71 results_ = GetAll::Results::Create(*permissions); |
72 return true; | 72 return true; |
73 } | 73 } |
74 | 74 |
75 bool RemovePermissionsFunction::RunImpl() { | 75 bool PermissionsRemoveFunction::RunImpl() { |
76 scoped_ptr<Remove::Params> params(Remove::Params::Create(*args_)); | 76 scoped_ptr<Remove::Params> params(Remove::Params::Create(*args_)); |
77 EXTENSION_FUNCTION_VALIDATE(params.get()); | 77 EXTENSION_FUNCTION_VALIDATE(params.get()); |
78 | 78 |
79 scoped_refptr<PermissionSet> permissions = | 79 scoped_refptr<PermissionSet> permissions = |
80 helpers::UnpackPermissionSet(params->permissions, &error_); | 80 helpers::UnpackPermissionSet(params->permissions, &error_); |
81 if (!permissions.get()) | 81 if (!permissions.get()) |
82 return false; | 82 return false; |
83 | 83 |
84 const extensions::Extension* extension = GetExtension(); | 84 const extensions::Extension* extension = GetExtension(); |
85 | 85 |
(...skipping 17 matching lines...) Expand all Loading... |
103 results_ = Remove::Results::Create(false); | 103 results_ = Remove::Results::Create(false); |
104 return false; | 104 return false; |
105 } | 105 } |
106 | 106 |
107 PermissionsUpdater(profile()).RemovePermissions(extension, permissions.get()); | 107 PermissionsUpdater(profile()).RemovePermissions(extension, permissions.get()); |
108 results_ = Remove::Results::Create(true); | 108 results_ = Remove::Results::Create(true); |
109 return true; | 109 return true; |
110 } | 110 } |
111 | 111 |
112 // static | 112 // static |
113 void RequestPermissionsFunction::SetAutoConfirmForTests(bool should_proceed) { | 113 void PermissionsRequestFunction::SetAutoConfirmForTests(bool should_proceed) { |
114 auto_confirm_for_tests = should_proceed ? PROCEED : ABORT; | 114 auto_confirm_for_tests = should_proceed ? PROCEED : ABORT; |
115 } | 115 } |
116 | 116 |
117 // static | 117 // static |
118 void RequestPermissionsFunction::SetIgnoreUserGestureForTests( | 118 void PermissionsRequestFunction::SetIgnoreUserGestureForTests( |
119 bool ignore) { | 119 bool ignore) { |
120 ignore_user_gesture_for_tests = ignore; | 120 ignore_user_gesture_for_tests = ignore; |
121 } | 121 } |
122 | 122 |
123 RequestPermissionsFunction::RequestPermissionsFunction() {} | 123 PermissionsRequestFunction::PermissionsRequestFunction() {} |
124 | 124 |
125 void RequestPermissionsFunction::InstallUIProceed() { | 125 void PermissionsRequestFunction::InstallUIProceed() { |
126 PermissionsUpdater perms_updater(profile()); | 126 PermissionsUpdater perms_updater(profile()); |
127 perms_updater.AddPermissions(GetExtension(), requested_permissions_.get()); | 127 perms_updater.AddPermissions(GetExtension(), requested_permissions_.get()); |
128 | 128 |
129 results_ = Request::Results::Create(true); | 129 results_ = Request::Results::Create(true); |
130 SendResponse(true); | 130 SendResponse(true); |
131 | 131 |
132 Release(); // Balanced in RunImpl(). | 132 Release(); // Balanced in RunImpl(). |
133 } | 133 } |
134 | 134 |
135 void RequestPermissionsFunction::InstallUIAbort(bool user_initiated) { | 135 void PermissionsRequestFunction::InstallUIAbort(bool user_initiated) { |
136 results_ = Request::Results::Create(false); | 136 results_ = Request::Results::Create(false); |
137 SendResponse(true); | 137 SendResponse(true); |
138 | 138 |
139 Release(); // Balanced in RunImpl(). | 139 Release(); // Balanced in RunImpl(). |
140 } | 140 } |
141 | 141 |
142 RequestPermissionsFunction::~RequestPermissionsFunction() {} | 142 PermissionsRequestFunction::~PermissionsRequestFunction() {} |
143 | 143 |
144 bool RequestPermissionsFunction::RunImpl() { | 144 bool PermissionsRequestFunction::RunImpl() { |
145 if (!user_gesture() && !ignore_user_gesture_for_tests) { | 145 if (!user_gesture() && !ignore_user_gesture_for_tests) { |
146 error_ = kUserGestureRequiredError; | 146 error_ = kUserGestureRequiredError; |
147 return false; | 147 return false; |
148 } | 148 } |
149 | 149 |
150 scoped_ptr<Request::Params> params(Request::Params::Create(*args_)); | 150 scoped_ptr<Request::Params> params(Request::Params::Create(*args_)); |
151 EXTENSION_FUNCTION_VALIDATE(params.get()); | 151 EXTENSION_FUNCTION_VALIDATE(params.get()); |
152 | 152 |
153 requested_permissions_ = | 153 requested_permissions_ = |
154 helpers::UnpackPermissionSet(params->permissions, &error_); | 154 helpers::UnpackPermissionSet(params->permissions, &error_); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 InstallUIAbort(true); | 214 InstallUIAbort(true); |
215 } else { | 215 } else { |
216 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); | 216 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); |
217 install_ui_.reset(new ExtensionInstallPrompt(GetAssociatedWebContents())); | 217 install_ui_.reset(new ExtensionInstallPrompt(GetAssociatedWebContents())); |
218 install_ui_->ConfirmPermissions( | 218 install_ui_->ConfirmPermissions( |
219 this, GetExtension(), requested_permissions_.get()); | 219 this, GetExtension(), requested_permissions_.get()); |
220 } | 220 } |
221 | 221 |
222 return true; | 222 return true; |
223 } | 223 } |
OLD | NEW |