Commit 1e89d82e authored by ericzeng@chromium.org's avatar ericzeng@chromium.org

Add default fonts for extensions.

This CL applies the default system font style to extension pages.
Extensions that specify their own fonts will still override these styles. 

BUG=141703, 395319

Review URL: https://codereview.chromium.org/400343002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284597 0039d316-1c4b-4281-b951-d872f2087c98
parent e7349628
...@@ -325,20 +325,31 @@ void Dispatcher::WillReleaseScriptContext( ...@@ -325,20 +325,31 @@ void Dispatcher::WillReleaseScriptContext(
} }
void Dispatcher::DidCreateDocumentElement(blink::WebFrame* frame) { void Dispatcher::DidCreateDocumentElement(blink::WebFrame* frame) {
if (IsWithinPlatformApp()) { // Note: use GetEffectiveDocumentURL not just frame->document()->url()
// WebKit doesn't let us define an additional user agent stylesheet, so we // so that this also injects the stylesheet on about:blank frames that
// insert the default platform app stylesheet into all documents that are // are hosted in the extension process.
// loaded in each app. 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() || extension->is_platform_app())) {
int resource_id =
extension->is_platform_app() ? IDR_PLATFORM_APP_CSS : IDR_EXTENSION_CSS;
std::string stylesheet = ResourceBundle::GetSharedInstance() std::string stylesheet = ResourceBundle::GetSharedInstance()
.GetRawDataResource(IDR_PLATFORM_APP_CSS) .GetRawDataResource(resource_id)
.as_string(); .as_string();
ReplaceFirstSubstringAfterOffset( ReplaceFirstSubstringAfterOffset(
&stylesheet, 0, "$FONTFAMILY", system_font_family_); &stylesheet, 0, "$FONTFAMILY", system_font_family_);
ReplaceFirstSubstringAfterOffset( ReplaceFirstSubstringAfterOffset(
&stylesheet, 0, "$FONTSIZE", system_font_size_); &stylesheet, 0, "$FONTSIZE", system_font_size_);
// Blink doesn't let us define an additional user agent stylesheet, so
// we insert the default platform app or extension stylesheet into all
// documents that are loaded in each app or extension.
frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet)); frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet));
} }
content_watcher_->DidCreateDocumentElement(frame); content_watcher_->DidCreateDocumentElement(frame);
} }
......
/*
* Copyright 2014 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* A style sheet for Chrome extensions.
*/
body {
font-family: $FONTFAMILY;
font-size: $FONTSIZE;
}
...@@ -40,6 +40,9 @@ ...@@ -40,6 +40,9 @@
<!-- Platform app support. --> <!-- Platform app support. -->
<include name="IDR_PLATFORM_APP_CSS" file="platform_app.css" type="BINDATA" /> <include name="IDR_PLATFORM_APP_CSS" file="platform_app.css" type="BINDATA" />
<include name="IDR_PLATFORM_APP_JS" file="platform_app.js" type="BINDATA" /> <include name="IDR_PLATFORM_APP_JS" file="platform_app.js" type="BINDATA" />
<!-- Extension styles -->
<include name="IDR_EXTENSION_CSS" file="extension.css" type="BINDATA"/>
</includes> </includes>
</release> </release>
</grit> </grit>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment