Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: extensions/renderer/dispatcher.cc

Issue 537773003: Add a user agent stylesheet for extension options pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use grit to handle background-image data URIs Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 14 matching lines...) Expand all
25 #include "extensions/common/extension.h" 25 #include "extensions/common/extension.h"
26 #include "extensions/common/extension_api.h" 26 #include "extensions/common/extension_api.h"
27 #include "extensions/common/extension_messages.h" 27 #include "extensions/common/extension_messages.h"
28 #include "extensions/common/extension_urls.h" 28 #include "extensions/common/extension_urls.h"
29 #include "extensions/common/features/feature.h" 29 #include "extensions/common/features/feature.h"
30 #include "extensions/common/features/feature_provider.h" 30 #include "extensions/common/features/feature_provider.h"
31 #include "extensions/common/manifest.h" 31 #include "extensions/common/manifest.h"
32 #include "extensions/common/manifest_constants.h" 32 #include "extensions/common/manifest_constants.h"
33 #include "extensions/common/manifest_handlers/background_info.h" 33 #include "extensions/common/manifest_handlers/background_info.h"
34 #include "extensions/common/manifest_handlers/externally_connectable.h" 34 #include "extensions/common/manifest_handlers/externally_connectable.h"
35 #include "extensions/common/manifest_handlers/options_page_info.h"
35 #include "extensions/common/manifest_handlers/sandboxed_page_info.h" 36 #include "extensions/common/manifest_handlers/sandboxed_page_info.h"
36 #include "extensions/common/message_bundle.h" 37 #include "extensions/common/message_bundle.h"
37 #include "extensions/common/permissions/permission_set.h" 38 #include "extensions/common/permissions/permission_set.h"
38 #include "extensions/common/permissions/permissions_data.h" 39 #include "extensions/common/permissions/permissions_data.h"
39 #include "extensions/common/switches.h" 40 #include "extensions/common/switches.h"
40 #include "extensions/common/view_type.h" 41 #include "extensions/common/view_type.h"
41 #include "extensions/renderer/api_activity_logger.h" 42 #include "extensions/renderer/api_activity_logger.h"
42 #include "extensions/renderer/api_definitions_natives.h" 43 #include "extensions/renderer/api_definitions_natives.h"
43 #include "extensions/renderer/app_runtime_custom_bindings.h" 44 #include "extensions/renderer/app_runtime_custom_bindings.h"
44 #include "extensions/renderer/app_window_custom_bindings.h" 45 #include "extensions/renderer/app_window_custom_bindings.h"
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 script_context_set_.Remove(context); 343 script_context_set_.Remove(context);
343 VLOG(1) << "Num tracked contexts: " << script_context_set_.size(); 344 VLOG(1) << "Num tracked contexts: " << script_context_set_.size();
344 } 345 }
345 346
346 void Dispatcher::DidCreateDocumentElement(blink::WebFrame* frame) { 347 void Dispatcher::DidCreateDocumentElement(blink::WebFrame* frame) {
347 // Note: use GetEffectiveDocumentURL not just frame->document()->url() 348 // Note: use GetEffectiveDocumentURL not just frame->document()->url()
348 // so that this also injects the stylesheet on about:blank frames that 349 // so that this also injects the stylesheet on about:blank frames that
349 // are hosted in the extension process. 350 // are hosted in the extension process.
350 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( 351 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL(
351 frame, frame->document().url(), true /* match_about_blank */); 352 frame, frame->document().url(), true /* match_about_blank */);
353
352 const Extension* extension = 354 const Extension* extension =
353 extensions_.GetExtensionOrAppByURL(effective_document_url); 355 extensions_.GetExtensionOrAppByURL(effective_document_url);
354 356
355 if (extension && 357 if (extension &&
356 (extension->is_extension() || extension->is_platform_app())) { 358 (extension->is_extension() || extension->is_platform_app())) {
357 int resource_id = 359 int resource_id = extension->is_platform_app() ? IDR_PLATFORM_APP_CSS
358 extension->is_platform_app() ? IDR_PLATFORM_APP_CSS : IDR_EXTENSION_CSS; 360 : IDR_EXTENSION_FONTS_CSS;
359 std::string stylesheet = ResourceBundle::GetSharedInstance() 361 std::string stylesheet = ResourceBundle::GetSharedInstance()
360 .GetRawDataResource(resource_id) 362 .GetRawDataResource(resource_id)
361 .as_string(); 363 .as_string();
362 ReplaceFirstSubstringAfterOffset( 364 ReplaceFirstSubstringAfterOffset(
363 &stylesheet, 0, "$FONTFAMILY", system_font_family_); 365 &stylesheet, 0, "$FONTFAMILY", system_font_family_);
364 ReplaceFirstSubstringAfterOffset( 366 ReplaceFirstSubstringAfterOffset(
365 &stylesheet, 0, "$FONTSIZE", system_font_size_); 367 &stylesheet, 0, "$FONTSIZE", system_font_size_);
366 368
367 // Blink doesn't let us define an additional user agent stylesheet, so 369 // Blink doesn't let us define an additional user agent stylesheet, so
368 // we insert the default platform app or extension stylesheet into all 370 // we insert the default platform app or extension stylesheet into all
369 // documents that are loaded in each app or extension. 371 // documents that are loaded in each app or extension.
370 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet)); 372 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet));
371 } 373 }
374
375 // If this is an extension options page, and the extension has opted into
376 // using Chrome styles, then insert the Chrome extension stylesheet.
377 if (extension && extension->is_extension() &&
378 OptionsPageInfo::ShouldUseChromeStyle(extension) &&
379 effective_document_url == OptionsPageInfo::GetOptionsPage(extension)) {
380 frame->document().insertStyleSheet(
381 WebString::fromUTF8(ResourceBundle::GetSharedInstance()
382 .GetRawDataResource(IDR_EXTENSION_CSS)
383 .as_string()));
384 }
372 content_watcher_->DidCreateDocumentElement(frame); 385 content_watcher_->DidCreateDocumentElement(frame);
373 } 386 }
374 387
375 void Dispatcher::DidMatchCSS( 388 void Dispatcher::DidMatchCSS(
376 blink::WebFrame* frame, 389 blink::WebFrame* frame,
377 const blink::WebVector<blink::WebString>& newly_matching_selectors, 390 const blink::WebVector<blink::WebString>& newly_matching_selectors,
378 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { 391 const blink::WebVector<blink::WebString>& stopped_matching_selectors) {
379 content_watcher_->DidMatchCSS( 392 content_watcher_->DidMatchCSS(
380 frame, newly_matching_selectors, stopped_matching_selectors); 393 frame, newly_matching_selectors, stopped_matching_selectors);
381 } 394 }
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 return v8::Handle<v8::Object>(); 1337 return v8::Handle<v8::Object>();
1325 1338
1326 if (bind_name) 1339 if (bind_name)
1327 *bind_name = split.back(); 1340 *bind_name = split.back();
1328 1341
1329 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) 1342 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context))
1330 : bind_object; 1343 : bind_object;
1331 } 1344 }
1332 1345
1333 } // namespace extensions 1346 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698