| 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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 318 |
| 319 context->DispatchOnUnloadEvent(); | 319 context->DispatchOnUnloadEvent(); |
| 320 // TODO(kalman): add an invalidation observer interface to ScriptContext. | 320 // TODO(kalman): add an invalidation observer interface to ScriptContext. |
| 321 request_sender_->InvalidateSource(context); | 321 request_sender_->InvalidateSource(context); |
| 322 | 322 |
| 323 script_context_set_.Remove(context); | 323 script_context_set_.Remove(context); |
| 324 VLOG(1) << "Num tracked contexts: " << script_context_set_.size(); | 324 VLOG(1) << "Num tracked contexts: " << script_context_set_.size(); |
| 325 } | 325 } |
| 326 | 326 |
| 327 void Dispatcher::DidCreateDocumentElement(blink::WebFrame* frame) { | 327 void Dispatcher::DidCreateDocumentElement(blink::WebFrame* frame) { |
| 328 if (IsWithinPlatformApp()) { | 328 // Note: use GetEffectiveDocumentURL not just frame->document()->url() |
| 329 // WebKit doesn't let us define an additional user agent stylesheet, so we | 329 // so that this also injects the stylesheet on about:blank frames that |
| 330 // insert the default platform app stylesheet into all documents that are | 330 // are hosted in the extension process. |
| 331 // loaded in each app. | 331 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( |
| 332 frame, frame->document().url(), true /* match_about_blank */); |
| 333 const Extension* extension = |
| 334 extensions_.GetExtensionOrAppByURL(effective_document_url); |
| 335 |
| 336 if (extension && |
| 337 (extension->is_extension() || extension->is_platform_app())) { |
| 338 int resource_id = |
| 339 extension->is_platform_app() ? IDR_PLATFORM_APP_CSS : IDR_EXTENSION_CSS; |
| 332 std::string stylesheet = ResourceBundle::GetSharedInstance() | 340 std::string stylesheet = ResourceBundle::GetSharedInstance() |
| 333 .GetRawDataResource(IDR_PLATFORM_APP_CSS) | 341 .GetRawDataResource(resource_id) |
| 334 .as_string(); | 342 .as_string(); |
| 335 ReplaceFirstSubstringAfterOffset( | 343 ReplaceFirstSubstringAfterOffset( |
| 336 &stylesheet, 0, "$FONTFAMILY", system_font_family_); | 344 &stylesheet, 0, "$FONTFAMILY", system_font_family_); |
| 337 ReplaceFirstSubstringAfterOffset( | 345 ReplaceFirstSubstringAfterOffset( |
| 338 &stylesheet, 0, "$FONTSIZE", system_font_size_); | 346 &stylesheet, 0, "$FONTSIZE", system_font_size_); |
| 347 |
| 348 // Blink doesn't let us define an additional user agent stylesheet, so |
| 349 // we insert the default platform app or extension stylesheet into all |
| 350 // documents that are loaded in each app or extension. |
| 339 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet)); | 351 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet)); |
| 340 } | 352 } |
| 341 | |
| 342 content_watcher_->DidCreateDocumentElement(frame); | 353 content_watcher_->DidCreateDocumentElement(frame); |
| 343 } | 354 } |
| 344 | 355 |
| 345 void Dispatcher::DidMatchCSS( | 356 void Dispatcher::DidMatchCSS( |
| 346 blink::WebFrame* frame, | 357 blink::WebFrame* frame, |
| 347 const blink::WebVector<blink::WebString>& newly_matching_selectors, | 358 const blink::WebVector<blink::WebString>& newly_matching_selectors, |
| 348 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { | 359 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { |
| 349 content_watcher_->DidMatchCSS( | 360 content_watcher_->DidMatchCSS( |
| 350 frame, newly_matching_selectors, stopped_matching_selectors); | 361 frame, newly_matching_selectors, stopped_matching_selectors); |
| 351 } | 362 } |
| (...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1197 return v8::Handle<v8::Object>(); | 1208 return v8::Handle<v8::Object>(); |
| 1198 | 1209 |
| 1199 if (bind_name) | 1210 if (bind_name) |
| 1200 *bind_name = split.back(); | 1211 *bind_name = split.back(); |
| 1201 | 1212 |
| 1202 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) | 1213 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) |
| 1203 : bind_object; | 1214 : bind_object; |
| 1204 } | 1215 } |
| 1205 | 1216 |
| 1206 } // namespace extensions | 1217 } // namespace extensions |
| OLD | NEW |