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

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: 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/binding_generating_native_handler.h" 45 #include "extensions/renderer/binding_generating_native_handler.h"
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 script_context_set_.Remove(context); 326 script_context_set_.Remove(context);
326 VLOG(1) << "Num tracked contexts: " << script_context_set_.size(); 327 VLOG(1) << "Num tracked contexts: " << script_context_set_.size();
327 } 328 }
328 329
329 void Dispatcher::DidCreateDocumentElement(blink::WebFrame* frame) { 330 void Dispatcher::DidCreateDocumentElement(blink::WebFrame* frame) {
330 // Note: use GetEffectiveDocumentURL not just frame->document()->url() 331 // Note: use GetEffectiveDocumentURL not just frame->document()->url()
331 // so that this also injects the stylesheet on about:blank frames that 332 // so that this also injects the stylesheet on about:blank frames that
332 // are hosted in the extension process. 333 // are hosted in the extension process.
333 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( 334 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL(
334 frame, frame->document().url(), true /* match_about_blank */); 335 frame, frame->document().url(), true /* match_about_blank */);
336
335 const Extension* extension = 337 const Extension* extension =
336 extensions_.GetExtensionOrAppByURL(effective_document_url); 338 extensions_.GetExtensionOrAppByURL(effective_document_url);
337 339
338 if (extension && 340 if (extension &&
339 (extension->is_extension() || extension->is_platform_app())) { 341 (extension->is_extension() || extension->is_platform_app())) {
340 int resource_id = 342 int resource_id = extension->is_platform_app() ? IDR_PLATFORM_APP_CSS
341 extension->is_platform_app() ? IDR_PLATFORM_APP_CSS : IDR_EXTENSION_CSS; 343 : IDR_EXTENSION_FONTS_CSS;
342 std::string stylesheet = ResourceBundle::GetSharedInstance() 344 std::string stylesheet = ResourceBundle::GetSharedInstance()
343 .GetRawDataResource(resource_id) 345 .GetRawDataResource(resource_id)
344 .as_string(); 346 .as_string();
345 ReplaceFirstSubstringAfterOffset( 347 ReplaceFirstSubstringAfterOffset(
346 &stylesheet, 0, "$FONTFAMILY", system_font_family_); 348 &stylesheet, 0, "$FONTFAMILY", system_font_family_);
347 ReplaceFirstSubstringAfterOffset( 349 ReplaceFirstSubstringAfterOffset(
348 &stylesheet, 0, "$FONTSIZE", system_font_size_); 350 &stylesheet, 0, "$FONTSIZE", system_font_size_);
349 351
350 // Blink doesn't let us define an additional user agent stylesheet, so 352 // Blink doesn't let us define an additional user agent stylesheet, so
351 // we insert the default platform app or extension stylesheet into all 353 // we insert the default platform app or extension stylesheet into all
352 // documents that are loaded in each app or extension. 354 // documents that are loaded in each app or extension.
353 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet)); 355 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet));
354 } 356 }
357
358 if (extension && extension->is_extension() &&
359 OptionsPageInfo::ShouldUseChromeStyle(extension) &&
360 effective_document_url == OptionsPageInfo::GetOptionsPage(extension)) {
Devlin 2014/09/04 21:27:37 Is this data copied over to the renderer process?
ericzeng 2014/09/04 22:30:30 I don't know either. Which data in particular?
Devlin 2014/09/04 22:39:19 The extension's manifest data for whether or not i
ericzeng 2014/09/04 23:48:58 I'm pretty sure that it is - the IPC call when ext
Yoyo Zhou 2014/09/05 16:24:35 Yes, the renderer ought to have all the manifest d
361 frame->document().insertStyleSheet(
362 WebString::fromUTF8(ResourceBundle::GetSharedInstance()
363 .GetRawDataResource(IDR_EXTENSION_CSS)
Devlin 2014/09/04 21:27:37 Naively looking at this, it seems that you inject
ericzeng 2014/09/04 22:30:30 I think the conditional above should catch it - it
Devlin 2014/09/04 22:39:19 D'oh. Don't know why I missed that.
364 .as_string()));
365 }
355 content_watcher_->DidCreateDocumentElement(frame); 366 content_watcher_->DidCreateDocumentElement(frame);
356 } 367 }
357 368
358 void Dispatcher::DidMatchCSS( 369 void Dispatcher::DidMatchCSS(
359 blink::WebFrame* frame, 370 blink::WebFrame* frame,
360 const blink::WebVector<blink::WebString>& newly_matching_selectors, 371 const blink::WebVector<blink::WebString>& newly_matching_selectors,
361 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { 372 const blink::WebVector<blink::WebString>& stopped_matching_selectors) {
362 content_watcher_->DidMatchCSS( 373 content_watcher_->DidMatchCSS(
363 frame, newly_matching_selectors, stopped_matching_selectors); 374 frame, newly_matching_selectors, stopped_matching_selectors);
364 } 375 }
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 return v8::Handle<v8::Object>(); 1311 return v8::Handle<v8::Object>();
1301 1312
1302 if (bind_name) 1313 if (bind_name)
1303 *bind_name = split.back(); 1314 *bind_name = split.back();
1304 1315
1305 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) 1316 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context))
1306 : bind_object; 1317 : bind_object;
1307 } 1318 }
1308 1319
1309 } // namespace extensions 1320 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698