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 std::string stylesheet = ResourceBundle::GetSharedInstance() | 332 frame, frame->document().url(), true /* match_about_blank */); |
333 .GetRawDataResource(IDR_PLATFORM_APP_CSS) | 333 const Extension* extension = |
334 .as_string(); | 334 extensions_.GetExtensionOrAppByURL(effective_document_url); |
335 ReplaceFirstSubstringAfterOffset( | 335 if (extension) { |
not at google - send to devlin
2014/07/21 16:44:23
given the whole rest of this method is inside this
ericzeng
2014/07/21 18:12:33
Done.
| |
336 &stylesheet, 0, "$FONTFAMILY", system_font_family_); | 336 if (extension->is_extension() || extension->is_platform_app()) { |
337 ReplaceFirstSubstringAfterOffset( | 337 std::string stylesheet; |
338 &stylesheet, 0, "$FONTSIZE", system_font_size_); | 338 if (extension->is_platform_app()) |
339 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet)); | 339 // WebKit doesn't let us define an additional user agent stylesheet, so |
340 // we insert the default platform app stylesheet into all documents that | |
341 // are loaded in each app. | |
not at google - send to devlin
2014/07/21 16:44:23
this comment belongs before the "insertStyleSheet"
ericzeng
2014/07/21 18:12:33
Done.
| |
342 stylesheet = ResourceBundle::GetSharedInstance() | |
343 .GetRawDataResource(IDR_PLATFORM_APP_CSS) | |
not at google - send to devlin
2014/07/21 16:44:23
it would be simpler to switch on the resource ID r
ericzeng
2014/07/21 18:12:33
What do you mean by switching on the resource ID?
not at google - send to devlin
2014/07/21 18:31:29
Ternary operator is fine here because the block is
ericzeng
2014/07/21 18:43:11
Got it, but I'll use extension->is_platform_app()
| |
344 .as_string(); | |
345 else if (extension->is_extension()) | |
346 stylesheet = ResourceBundle::GetSharedInstance() | |
347 .GetRawDataResource(IDR_EXTENSION_CSS) | |
348 .as_string(); | |
349 ReplaceFirstSubstringAfterOffset( | |
350 &stylesheet, 0, "$FONTFAMILY", system_font_family_); | |
351 ReplaceFirstSubstringAfterOffset( | |
352 &stylesheet, 0, "$FONTSIZE", system_font_size_); | |
353 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet)); | |
354 } | |
355 content_watcher_->DidCreateDocumentElement(frame); | |
not at google - send to devlin
2014/07/21 16:44:23
(note: moving this inside the if-block is a change
| |
340 } | 356 } |
341 | |
342 content_watcher_->DidCreateDocumentElement(frame); | |
343 } | 357 } |
344 | 358 |
345 void Dispatcher::DidMatchCSS( | 359 void Dispatcher::DidMatchCSS( |
346 blink::WebFrame* frame, | 360 blink::WebFrame* frame, |
347 const blink::WebVector<blink::WebString>& newly_matching_selectors, | 361 const blink::WebVector<blink::WebString>& newly_matching_selectors, |
348 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { | 362 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { |
349 content_watcher_->DidMatchCSS( | 363 content_watcher_->DidMatchCSS( |
350 frame, newly_matching_selectors, stopped_matching_selectors); | 364 frame, newly_matching_selectors, stopped_matching_selectors); |
351 } | 365 } |
352 | 366 |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1197 return v8::Handle<v8::Object>(); | 1211 return v8::Handle<v8::Object>(); |
1198 | 1212 |
1199 if (bind_name) | 1213 if (bind_name) |
1200 *bind_name = split.back(); | 1214 *bind_name = split.back(); |
1201 | 1215 |
1202 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) | 1216 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) |
1203 : bind_object; | 1217 : bind_object; |
1204 } | 1218 } |
1205 | 1219 |
1206 } // namespace extensions | 1220 } // namespace extensions |
OLD | NEW |