| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/dispatcher.h" | 5 #include "extensions/renderer/dispatcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 int world_id) { | 261 int world_id) { |
| 262 #if !defined(ENABLE_EXTENSIONS) | 262 #if !defined(ENABLE_EXTENSIONS) |
| 263 return; | 263 return; |
| 264 #endif | 264 #endif |
| 265 | 265 |
| 266 const Extension* extension = | 266 const Extension* extension = |
| 267 GetExtensionFromFrameAndWorld(frame, world_id, false); | 267 GetExtensionFromFrameAndWorld(frame, world_id, false); |
| 268 const Extension* effective_extension = | 268 const Extension* effective_extension = |
| 269 GetExtensionFromFrameAndWorld(frame, world_id, true); | 269 GetExtensionFromFrameAndWorld(frame, world_id, true); |
| 270 | 270 |
| 271 bool extension_is_platform_app = extension && extension->is_platform_app(); |
| 272 |
| 273 // If we are navigating to a platform app URL, the extension must first have |
| 274 // been activated. If not, IsWithinPlatformApp will incorrectly return false, |
| 275 // and we will be missing information about what features the app has. |
| 276 // (Note: This DCHECK is invalid for non-app extensions, which do not get |
| 277 // activated in "unblessed" contexts such as content scripts and iframes.) |
| 278 if (extension_is_platform_app) |
| 279 DCHECK(IsExtensionActive(extension_id)); |
| 280 |
| 271 GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame); | 281 GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame); |
| 272 Feature::Context context_type = | 282 Feature::Context context_type = |
| 273 ClassifyJavaScriptContext(extension, | 283 ClassifyJavaScriptContext(extension, |
| 274 extension_group, | 284 extension_group, |
| 275 frame_url, | 285 frame_url, |
| 276 frame->document().securityOrigin()); | 286 frame->document().securityOrigin()); |
| 277 Feature::Context effective_context_type = ClassifyJavaScriptContext( | 287 Feature::Context effective_context_type = ClassifyJavaScriptContext( |
| 278 effective_extension, | 288 effective_extension, |
| 279 extension_group, | 289 extension_group, |
| 280 ScriptContext::GetEffectiveDocumentURL(frame, frame_url, true), | 290 ScriptContext::GetEffectiveDocumentURL(frame, frame_url, true), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 310 // lazily evalulate to Event from event_bindings.js. For extensions only | 320 // lazily evalulate to Event from event_bindings.js. For extensions only |
| 311 // though, not all webpages! | 321 // though, not all webpages! |
| 312 if (context->extension()) { | 322 if (context->extension()) { |
| 313 v8::Handle<v8::Object> chrome = AsObjectOrEmpty(GetOrCreateChrome(context)); | 323 v8::Handle<v8::Object> chrome = AsObjectOrEmpty(GetOrCreateChrome(context)); |
| 314 if (!chrome.IsEmpty()) | 324 if (!chrome.IsEmpty()) |
| 315 module_system->SetLazyField(chrome, "Event", kEventBindings, "Event"); | 325 module_system->SetLazyField(chrome, "Event", kEventBindings, "Event"); |
| 316 } | 326 } |
| 317 | 327 |
| 318 UpdateBindingsForContext(context); | 328 UpdateBindingsForContext(context); |
| 319 | 329 |
| 320 bool is_within_platform_app = IsWithinPlatformApp(); | |
| 321 // Inject custom JS into the platform app context. | 330 // Inject custom JS into the platform app context. |
| 322 if (is_within_platform_app) { | 331 if (extension_is_platform_app) { |
| 323 module_system->Require("platformApp"); | 332 module_system->Require("platformApp"); |
| 324 } | 333 } |
| 325 | 334 |
| 326 delegate_->RequireAdditionalModules(context, is_within_platform_app); | 335 delegate_->RequireAdditionalModules(context, extension_is_platform_app); |
| 327 | 336 |
| 328 VLOG(1) << "Num tracked contexts: " << script_context_set_.size(); | 337 VLOG(1) << "Num tracked contexts: " << script_context_set_.size(); |
| 329 } | 338 } |
| 330 | 339 |
| 331 void Dispatcher::WillReleaseScriptContext( | 340 void Dispatcher::WillReleaseScriptContext( |
| 332 WebFrame* frame, | 341 WebFrame* frame, |
| 333 const v8::Handle<v8::Context>& v8_context, | 342 const v8::Handle<v8::Context>& v8_context, |
| 334 int world_id) { | 343 int world_id) { |
| 335 ScriptContext* context = script_context_set_.GetByV8Context(v8_context); | 344 ScriptContext* context = script_context_set_.GetByV8Context(v8_context); |
| 336 if (!context) | 345 if (!context) |
| (...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1345 return v8::Handle<v8::Object>(); | 1354 return v8::Handle<v8::Object>(); |
| 1346 | 1355 |
| 1347 if (bind_name) | 1356 if (bind_name) |
| 1348 *bind_name = split.back(); | 1357 *bind_name = split.back(); |
| 1349 | 1358 |
| 1350 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) | 1359 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) |
| 1351 : bind_object; | 1360 : bind_object; |
| 1352 } | 1361 } |
| 1353 | 1362 |
| 1354 } // namespace extensions | 1363 } // namespace extensions |
| OLD | NEW |