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

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: Add preprocessor directive to fix Android build 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
« no previous file with comments | « extensions/renderer/BUILD.gn ('k') | extensions/renderer/resources/extension.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // This preprocessor directive is because this file is still built in Android
376 // builds, but OptionsPageInfo is not. For Android builds, exclude this block
377 // of code to prevent link errors.
378 #if defined(ENABLE_EXTENSIONS)
379 // If this is an extension options page, and the extension has opted into
380 // using Chrome styles, then insert the Chrome extension stylesheet.
381 if (extension && extension->is_extension() &&
382 OptionsPageInfo::ShouldUseChromeStyle(extension) &&
383 effective_document_url == OptionsPageInfo::GetOptionsPage(extension)) {
384 frame->document().insertStyleSheet(
385 WebString::fromUTF8(ResourceBundle::GetSharedInstance()
386 .GetRawDataResource(IDR_EXTENSION_CSS)
387 .as_string()));
388 }
389 #endif
390
372 content_watcher_->DidCreateDocumentElement(frame); 391 content_watcher_->DidCreateDocumentElement(frame);
373 } 392 }
374 393
375 void Dispatcher::DidMatchCSS( 394 void Dispatcher::DidMatchCSS(
376 blink::WebFrame* frame, 395 blink::WebFrame* frame,
377 const blink::WebVector<blink::WebString>& newly_matching_selectors, 396 const blink::WebVector<blink::WebString>& newly_matching_selectors,
378 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { 397 const blink::WebVector<blink::WebString>& stopped_matching_selectors) {
379 content_watcher_->DidMatchCSS( 398 content_watcher_->DidMatchCSS(
380 frame, newly_matching_selectors, stopped_matching_selectors); 399 frame, newly_matching_selectors, stopped_matching_selectors);
381 } 400 }
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 return v8::Handle<v8::Object>(); 1343 return v8::Handle<v8::Object>();
1325 1344
1326 if (bind_name) 1345 if (bind_name)
1327 *bind_name = split.back(); 1346 *bind_name = split.back();
1328 1347
1329 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) 1348 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context))
1330 : bind_object; 1349 : bind_object;
1331 } 1350 }
1332 1351
1333 } // namespace extensions 1352 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/BUILD.gn ('k') | extensions/renderer/resources/extension.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698