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_function.h" | 5 #include "chrome/browser/extensions/extension_function.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 9 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 } | 212 } |
213 | 213 |
214 ExtensionWindowController* | 214 ExtensionWindowController* |
215 UIThreadExtensionFunction::GetExtensionWindowController() { | 215 UIThreadExtensionFunction::GetExtensionWindowController() { |
216 // If the delegate has an associated window controller, return it. | 216 // If the delegate has an associated window controller, return it. |
217 ExtensionWindowController* window_controller = | 217 ExtensionWindowController* window_controller = |
218 dispatcher()->delegate()->GetExtensionWindowController(); | 218 dispatcher()->delegate()->GetExtensionWindowController(); |
219 if (window_controller) | 219 if (window_controller) |
220 return window_controller; | 220 return window_controller; |
221 | 221 |
222 Profile* profile = Profile::FromBrowserContext( | 222 return ExtensionWindowList::GetInstance()->CurrentWindowForFunction(this); |
223 render_view_host_->GetProcess()->GetBrowserContext()); | 223 } |
224 ExtensionWindowList::ProfileMatchType match_type = include_incognito_ | 224 |
225 ? ExtensionWindowController::MATCH_INCOGNITO | 225 bool UIThreadExtensionFunction::CanOperateOnWindow( |
226 : ExtensionWindowController::MATCH_NORMAL_ONLY; | 226 const ExtensionWindowController* window_controller) const { |
227 return ExtensionWindowList::GetInstance()->CurrentWindow(profile, match_type); | 227 const extensions::Extension* extension = GetExtension(); |
| 228 // |extension| is NULL for unit tests only. |
| 229 if (extension != NULL && !window_controller->IsVisibleToExtension(extension)) |
| 230 return false; |
| 231 |
| 232 if (profile() == window_controller->profile()) |
| 233 return true; |
| 234 |
| 235 if (!include_incognito()) |
| 236 return false; |
| 237 |
| 238 return profile()->HasOffTheRecordProfile() && |
| 239 profile()->GetOffTheRecordProfile() == window_controller->profile(); |
228 } | 240 } |
229 | 241 |
230 void UIThreadExtensionFunction::SendResponse(bool success) { | 242 void UIThreadExtensionFunction::SendResponse(bool success) { |
231 if (delegate_) { | 243 if (delegate_) { |
232 delegate_->OnSendResponse(this, success, bad_message_); | 244 delegate_->OnSendResponse(this, success, bad_message_); |
233 } else { | 245 } else { |
234 if (!render_view_host_ || !dispatcher()) | 246 if (!render_view_host_ || !dispatcher()) |
235 return; | 247 return; |
236 | 248 |
237 SendResponseImpl(render_view_host_->GetProcess()->GetHandle(), | 249 SendResponseImpl(render_view_host_->GetProcess()->GetHandle(), |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 295 |
284 SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() { | 296 SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() { |
285 } | 297 } |
286 | 298 |
287 SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() { | 299 SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() { |
288 } | 300 } |
289 | 301 |
290 void SyncIOThreadExtensionFunction::Run() { | 302 void SyncIOThreadExtensionFunction::Run() { |
291 SendResponse(RunImpl()); | 303 SendResponse(RunImpl()); |
292 } | 304 } |
OLD | NEW |