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

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

Issue 400343002: Add default fonts for extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address kalman's comments Created 6 years, 5 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/dispatcher.h ('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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // lazily evalulate to Event from event_bindings.js. For extensions only 289 // lazily evalulate to Event from event_bindings.js. For extensions only
290 // though, not all webpages! 290 // though, not all webpages!
291 if (context->extension()) { 291 if (context->extension()) {
292 v8::Handle<v8::Object> chrome = AsObjectOrEmpty(GetOrCreateChrome(context)); 292 v8::Handle<v8::Object> chrome = AsObjectOrEmpty(GetOrCreateChrome(context));
293 if (!chrome.IsEmpty()) 293 if (!chrome.IsEmpty())
294 module_system->SetLazyField(chrome, "Event", kEventBindings, "Event"); 294 module_system->SetLazyField(chrome, "Event", kEventBindings, "Event");
295 } 295 }
296 296
297 UpdateBindingsForContext(context); 297 UpdateBindingsForContext(context);
298 298
299 bool is_within_platform_app = IsWithinPlatformApp(); 299 bool is_within_platform_app = IsWithinPlatformApp(frame);
300 // Inject custom JS into the platform app context. 300 // Inject custom JS into the platform app context.
301 if (is_within_platform_app) { 301 if (is_within_platform_app) {
302 module_system->Require("platformApp"); 302 module_system->Require("platformApp");
303 } 303 }
304 304
305 delegate_->RequireAdditionalModules( 305 delegate_->RequireAdditionalModules(
306 module_system, extension, context_type, is_within_platform_app); 306 module_system, extension, context_type, is_within_platform_app);
307 307
308 VLOG(1) << "Num tracked contexts: " << script_context_set_.size(); 308 VLOG(1) << "Num tracked contexts: " << script_context_set_.size();
309 } 309 }
310 310
311 void Dispatcher::WillReleaseScriptContext( 311 void Dispatcher::WillReleaseScriptContext(
312 WebFrame* frame, 312 WebFrame* frame,
313 const v8::Handle<v8::Context>& v8_context, 313 const v8::Handle<v8::Context>& v8_context,
314 int world_id) { 314 int world_id) {
315 ScriptContext* context = script_context_set_.GetByV8Context(v8_context); 315 ScriptContext* context = script_context_set_.GetByV8Context(v8_context);
316 if (!context) 316 if (!context)
317 return; 317 return;
318 318
319 context->DispatchOnUnloadEvent(); 319 context->DispatchOnUnloadEvent();
320 // TODO(kalman): add an invalidation observer interface to ScriptContext. 320 // TODO(kalman): add an invalidation observer interface to ScriptContext.
321 request_sender_->InvalidateSource(context); 321 request_sender_->InvalidateSource(context);
322 322
323 script_context_set_.Remove(context); 323 script_context_set_.Remove(context);
324 VLOG(1) << "Num tracked contexts: " << script_context_set_.size(); 324 VLOG(1) << "Num tracked contexts: " << script_context_set_.size();
325 } 325 }
326 326
327 void Dispatcher::DidCreateDocumentElement(blink::WebFrame* frame) { 327 void Dispatcher::DidCreateDocumentElement(blink::WebFrame* frame) {
328 if (IsWithinPlatformApp()) { 328 if (IsWithinPlatformApp(frame) || IsWithinExtension(frame)) {
329 // WebKit doesn't let us define an additional user agent stylesheet, so we 329 std::string stylesheet;
330 // insert the default platform app stylesheet into all documents that are 330 if (IsWithinPlatformApp(frame)) {
331 // loaded in each app. 331 // WebKit doesn't let us define an additional user agent stylesheet, so we
332 std::string stylesheet = ResourceBundle::GetSharedInstance() 332 // insert the default platform app stylesheet into all documents that are
333 .GetRawDataResource(IDR_PLATFORM_APP_CSS) 333 // loaded in each app.
334 .as_string(); 334 stylesheet = ResourceBundle::GetSharedInstance()
335 .GetRawDataResource(IDR_PLATFORM_APP_CSS)
336 .as_string();
337 } else if (IsWithinExtension(frame)) {
338 stylesheet = ResourceBundle::GetSharedInstance()
339 .GetRawDataResource(IDR_EXTENSION_CSS)
340 .as_string();
341 }
335 ReplaceFirstSubstringAfterOffset( 342 ReplaceFirstSubstringAfterOffset(
336 &stylesheet, 0, "$FONTFAMILY", system_font_family_); 343 &stylesheet, 0, "$FONTFAMILY", system_font_family_);
337 ReplaceFirstSubstringAfterOffset( 344 ReplaceFirstSubstringAfterOffset(
338 &stylesheet, 0, "$FONTSIZE", system_font_size_); 345 &stylesheet, 0, "$FONTSIZE", system_font_size_);
339 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet)); 346 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet));
340 } 347 }
341
342 content_watcher_->DidCreateDocumentElement(frame); 348 content_watcher_->DidCreateDocumentElement(frame);
343 } 349 }
344 350
345 void Dispatcher::DidMatchCSS( 351 void Dispatcher::DidMatchCSS(
346 blink::WebFrame* frame, 352 blink::WebFrame* frame,
347 const blink::WebVector<blink::WebString>& newly_matching_selectors, 353 const blink::WebVector<blink::WebString>& newly_matching_selectors,
348 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { 354 const blink::WebVector<blink::WebString>& stopped_matching_selectors) {
349 content_watcher_->DidMatchCSS( 355 content_watcher_->DidMatchCSS(
350 frame, newly_matching_selectors, stopped_matching_selectors); 356 frame, newly_matching_selectors, stopped_matching_selectors);
351 } 357 }
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 1056
1051 // Custom types sources. 1057 // Custom types sources.
1052 source_map_.RegisterSource("StorageArea", IDR_STORAGE_AREA_JS); 1058 source_map_.RegisterSource("StorageArea", IDR_STORAGE_AREA_JS);
1053 1059
1054 // Platform app sources that are not API-specific.. 1060 // Platform app sources that are not API-specific..
1055 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); 1061 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS);
1056 1062
1057 delegate_->PopulateSourceMap(&source_map_); 1063 delegate_->PopulateSourceMap(&source_map_);
1058 } 1064 }
1059 1065
1060 bool Dispatcher::IsWithinPlatformApp() { 1066 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
1061 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); 1067 for (std::set<std::string>::iterator iter = active_extension_ids_.begin();
1062 iter != active_extension_ids_.end(); 1068 iter != active_extension_ids_.end();
1063 ++iter) { 1069 ++iter) {
1064 const Extension* extension = extensions_.GetByID(*iter); 1070 // Note: use GetEffectiveDocumentURL not just frame->document()->url()
1071 // so that this also injects the stylesheet on about:blank frames that
1072 // are hosted in the extension process.
1073 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL(
1074 frame, frame->document().url(), true /* match_about_blank */);
1075 const Extension* extension =
1076 extensions_.GetExtensionOrAppByURL(effective_document_url);
1065 if (extension && extension->is_platform_app()) 1077 if (extension && extension->is_platform_app())
1066 return true; 1078 return true;
1067 } 1079 }
1068 return false; 1080 return false;
1069 } 1081 }
1070 1082
1083 bool Dispatcher::IsWithinExtension(blink::WebFrame* frame) {
1084 for (std::set<std::string>::iterator iter = active_extension_ids_.begin();
1085 iter != active_extension_ids_.end();
1086 ++iter) {
1087 // Note: use GetEffectiveDocumentURL not just frame->document()->url()
1088 // so that this also injects the stylesheet on about:blank frames that
1089 // are hosted in the extension process.
1090 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL(
1091 frame, frame->document().url(), true /* match_about_blank */);
1092 const Extension* extension =
1093 extensions_.GetExtensionOrAppByURL(effective_document_url);
1094 if (extension && extension->is_extension())
1095 return true;
1096 }
1097 return false;
1098 }
1099
1071 // TODO(kalman): This is checking for the wrong thing, it should be checking if 1100 // TODO(kalman): This is checking for the wrong thing, it should be checking if
1072 // the frame's security origin is unique. The extension sandbox directive is 1101 // the frame's security origin is unique. The extension sandbox directive is
1073 // checked for in extensions/common/manifest_handlers/csp_info.cc. 1102 // checked for in extensions/common/manifest_handlers/csp_info.cc.
1074 bool Dispatcher::IsSandboxedPage(const GURL& url) const { 1103 bool Dispatcher::IsSandboxedPage(const GURL& url) const {
1075 if (url.SchemeIs(kExtensionScheme)) { 1104 if (url.SchemeIs(kExtensionScheme)) {
1076 const Extension* extension = extensions_.GetByID(url.host()); 1105 const Extension* extension = extensions_.GetByID(url.host());
1077 if (extension) { 1106 if (extension) {
1078 return SandboxedPageInfo::IsSandboxedPage(extension, url.path()); 1107 return SandboxedPageInfo::IsSandboxedPage(extension, url.path());
1079 } 1108 }
1080 } 1109 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 return v8::Handle<v8::Object>(); 1226 return v8::Handle<v8::Object>();
1198 1227
1199 if (bind_name) 1228 if (bind_name)
1200 *bind_name = split.back(); 1229 *bind_name = split.back();
1201 1230
1202 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) 1231 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context))
1203 : bind_object; 1232 : bind_object;
1204 } 1233 }
1205 1234
1206 } // namespace extensions 1235 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/dispatcher.h ('k') | extensions/renderer/resources/extension.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698