Chromium Code Reviews| Index: extensions/renderer/dispatcher.cc |
| diff --git a/extensions/renderer/dispatcher.cc b/extensions/renderer/dispatcher.cc |
| index c9aaec457060e951d8c0bae5a1e0731fd5505fc5..62b612382ce69a1b63789bad03c06c24c97cc8f8 100644 |
| --- a/extensions/renderer/dispatcher.cc |
| +++ b/extensions/renderer/dispatcher.cc |
| @@ -296,7 +296,7 @@ void Dispatcher::DidCreateScriptContext( |
| UpdateBindingsForContext(context); |
| - bool is_within_platform_app = IsWithinPlatformApp(); |
| + bool is_within_platform_app = IsWithinPlatformApp(frame); |
| // Inject custom JS into the platform app context. |
| if (is_within_platform_app) { |
| module_system->Require("platformApp"); |
| @@ -325,20 +325,26 @@ void Dispatcher::WillReleaseScriptContext( |
| } |
| void Dispatcher::DidCreateDocumentElement(blink::WebFrame* frame) { |
| - if (IsWithinPlatformApp()) { |
| - // WebKit doesn't let us define an additional user agent stylesheet, so we |
| - // insert the default platform app stylesheet into all documents that are |
| - // loaded in each app. |
| - std::string stylesheet = ResourceBundle::GetSharedInstance() |
| - .GetRawDataResource(IDR_PLATFORM_APP_CSS) |
| - .as_string(); |
| + if (IsWithinPlatformApp(frame) || IsWithinExtension(frame)) { |
| + std::string stylesheet; |
| + if (IsWithinPlatformApp(frame)) { |
| + // WebKit doesn't let us define an additional user agent stylesheet, so we |
| + // insert the default platform app stylesheet into all documents that are |
| + // loaded in each app. |
| + stylesheet = ResourceBundle::GetSharedInstance() |
| + .GetRawDataResource(IDR_PLATFORM_APP_CSS) |
| + .as_string(); |
| + } else if (IsWithinExtension(frame)) { |
| + stylesheet = ResourceBundle::GetSharedInstance() |
| + .GetRawDataResource(IDR_EXTENSION_CSS) |
| + .as_string(); |
| + } |
| ReplaceFirstSubstringAfterOffset( |
| &stylesheet, 0, "$FONTFAMILY", system_font_family_); |
| ReplaceFirstSubstringAfterOffset( |
| &stylesheet, 0, "$FONTSIZE", system_font_size_); |
| frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet)); |
| } |
| - |
| content_watcher_->DidCreateDocumentElement(frame); |
| } |
| @@ -1057,17 +1063,40 @@ void Dispatcher::PopulateSourceMap() { |
| delegate_->PopulateSourceMap(&source_map_); |
| } |
| -bool Dispatcher::IsWithinPlatformApp() { |
| +bool Dispatcher::IsWithinPlatformApp(blink::WebFrame* frame) { |
|
not at google - send to devlin
2014/07/19 01:54:16
sorry I didn't meant to imply that we modify IsWit
|
| for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); |
| iter != active_extension_ids_.end(); |
| ++iter) { |
| - const Extension* extension = extensions_.GetByID(*iter); |
| + // Note: use GetEffectiveDocumentURL not just frame->document()->url() |
| + // so that this also injects the stylesheet on about:blank frames that |
| + // are hosted in the extension process. |
| + GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( |
| + frame, frame->document().url(), true /* match_about_blank */); |
| + const Extension* extension = |
| + extensions_.GetExtensionOrAppByURL(effective_document_url); |
| if (extension && extension->is_platform_app()) |
| return true; |
| } |
| return false; |
| } |
| +bool Dispatcher::IsWithinExtension(blink::WebFrame* frame) { |
| + for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); |
| + iter != active_extension_ids_.end(); |
| + ++iter) { |
| + // Note: use GetEffectiveDocumentURL not just frame->document()->url() |
| + // so that this also injects the stylesheet on about:blank frames that |
| + // are hosted in the extension process. |
| + GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( |
| + frame, frame->document().url(), true /* match_about_blank */); |
| + const Extension* extension = |
| + extensions_.GetExtensionOrAppByURL(effective_document_url); |
| + if (extension && extension->is_extension()) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| // TODO(kalman): This is checking for the wrong thing, it should be checking if |
| // the frame's security origin is unique. The extension sandbox directive is |
| // checked for in extensions/common/manifest_handlers/csp_info.cc. |