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 if (!extension) | |
336 return; | |
337 | |
338 if (extension->is_extension() || extension->is_platform_app()) { | |
339 int resource_id = | |
340 extension->is_platform_app() ? IDR_PLATFORM_APP_CSS : IDR_EXTENSION_CSS; | |
332 std::string stylesheet = ResourceBundle::GetSharedInstance() | 341 std::string stylesheet = ResourceBundle::GetSharedInstance() |
333 .GetRawDataResource(IDR_PLATFORM_APP_CSS) | 342 .GetRawDataResource(resource_id) |
334 .as_string(); | 343 .as_string(); |
335 ReplaceFirstSubstringAfterOffset( | 344 ReplaceFirstSubstringAfterOffset( |
336 &stylesheet, 0, "$FONTFAMILY", system_font_family_); | 345 &stylesheet, 0, "$FONTFAMILY", system_font_family_); |
337 ReplaceFirstSubstringAfterOffset( | 346 ReplaceFirstSubstringAfterOffset( |
338 &stylesheet, 0, "$FONTSIZE", system_font_size_); | 347 &stylesheet, 0, "$FONTSIZE", system_font_size_); |
348 | |
349 // WebKit doesn't let us define an additional user agent stylesheet, so | |
not at google - send to devlin
2014/07/21 18:48:19
s/WebKit/Blink/
ericzeng
2014/07/21 19:29:34
Done.
| |
350 // we insert the default platform app or extension stylesheet into all | |
351 // documents that are loaded in each app or extension. | |
339 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet)); | 352 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet)); |
340 } | 353 } |
341 | |
342 content_watcher_->DidCreateDocumentElement(frame); | 354 content_watcher_->DidCreateDocumentElement(frame); |
343 } | 355 } |
344 | 356 |
345 void Dispatcher::DidMatchCSS( | 357 void Dispatcher::DidMatchCSS( |
346 blink::WebFrame* frame, | 358 blink::WebFrame* frame, |
347 const blink::WebVector<blink::WebString>& newly_matching_selectors, | 359 const blink::WebVector<blink::WebString>& newly_matching_selectors, |
348 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { | 360 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { |
349 content_watcher_->DidMatchCSS( | 361 content_watcher_->DidMatchCSS( |
350 frame, newly_matching_selectors, stopped_matching_selectors); | 362 frame, newly_matching_selectors, stopped_matching_selectors); |
351 } | 363 } |
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1197 return v8::Handle<v8::Object>(); | 1209 return v8::Handle<v8::Object>(); |
1198 | 1210 |
1199 if (bind_name) | 1211 if (bind_name) |
1200 *bind_name = split.back(); | 1212 *bind_name = split.back(); |
1201 | 1213 |
1202 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) | 1214 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) |
1203 : bind_object; | 1215 : bind_object; |
1204 } | 1216 } |
1205 | 1217 |
1206 } // namespace extensions | 1218 } // namespace extensions |
OLD | NEW |