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

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

Issue 672403002: Cleanup: Remove most enable_extensions logic in extensions code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix android Created 6 years, 1 month 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/dom_activity_logger.cc » ('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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 Dispatcher::Dispatcher(DispatcherDelegate* delegate) 182 Dispatcher::Dispatcher(DispatcherDelegate* delegate)
183 : delegate_(delegate), 183 : delegate_(delegate),
184 content_watcher_(new ContentWatcher()), 184 content_watcher_(new ContentWatcher()),
185 source_map_(&ResourceBundle::GetSharedInstance()), 185 source_map_(&ResourceBundle::GetSharedInstance()),
186 v8_schema_registry_(new V8SchemaRegistry), 186 v8_schema_registry_(new V8SchemaRegistry),
187 is_webkit_initialized_(false), 187 is_webkit_initialized_(false),
188 user_script_set_manager_observer_(this), 188 user_script_set_manager_observer_(this),
189 webrequest_used_(false) { 189 webrequest_used_(false) {
190 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); 190 const CommandLine& command_line = *(CommandLine::ForCurrentProcess());
191 is_extension_process_ = 191 is_extension_process_ =
192 command_line.HasSwitch(extensions::switches::kExtensionProcess) || 192 command_line.HasSwitch(switches::kExtensionProcess) ||
193 command_line.HasSwitch(::switches::kSingleProcess); 193 command_line.HasSwitch(::switches::kSingleProcess);
194 194
195 if (is_extension_process_) { 195 if (is_extension_process_) {
196 RenderThread::Get()->SetIdleNotificationDelayInMs( 196 RenderThread::Get()->SetIdleNotificationDelayInMs(
197 kInitialExtensionIdleHandlerDelayMs); 197 kInitialExtensionIdleHandlerDelayMs);
198 } 198 }
199 199
200 RenderThread::Get()->RegisterExtension(SafeBuiltins::CreateV8Extension()); 200 RenderThread::Get()->RegisterExtension(SafeBuiltins::CreateV8Extension());
201 201
202 user_script_set_manager_.reset(new UserScriptSetManager(&extensions_)); 202 user_script_set_manager_.reset(new UserScriptSetManager(&extensions_));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 253 }
254 } 254 }
255 return extension; 255 return extension;
256 } 256 }
257 257
258 void Dispatcher::DidCreateScriptContext( 258 void Dispatcher::DidCreateScriptContext(
259 WebFrame* frame, 259 WebFrame* frame,
260 const v8::Handle<v8::Context>& v8_context, 260 const v8::Handle<v8::Context>& v8_context,
261 int extension_group, 261 int extension_group,
262 int world_id) { 262 int world_id) {
263 #if !defined(ENABLE_EXTENSIONS)
264 return;
265 #endif
266
267 const Extension* extension = 263 const Extension* extension =
268 GetExtensionFromFrameAndWorld(frame, world_id, false); 264 GetExtensionFromFrameAndWorld(frame, world_id, false);
269 const Extension* effective_extension = 265 const Extension* effective_extension =
270 GetExtensionFromFrameAndWorld(frame, world_id, true); 266 GetExtensionFromFrameAndWorld(frame, world_id, true);
271 267
272 GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame); 268 GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame);
273 Feature::Context context_type = 269 Feature::Context context_type =
274 ClassifyJavaScriptContext(extension, 270 ClassifyJavaScriptContext(extension,
275 extension_group, 271 extension_group,
276 frame_url, 272 frame_url,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 UpdateBindingsForContext(context); 315 UpdateBindingsForContext(context);
320 316
321 bool is_within_platform_app = IsWithinPlatformApp(); 317 bool is_within_platform_app = IsWithinPlatformApp();
322 // Inject custom JS into the platform app context. 318 // Inject custom JS into the platform app context.
323 if (is_within_platform_app) { 319 if (is_within_platform_app) {
324 module_system->Require("platformApp"); 320 module_system->Require("platformApp");
325 } 321 }
326 322
327 if (context->GetAvailability("appViewEmbedderInternal").is_available()) { 323 if (context->GetAvailability("appViewEmbedderInternal").is_available()) {
328 module_system->Require("appView"); 324 module_system->Require("appView");
329 } else if (context_type == extensions::Feature::BLESSED_EXTENSION_CONTEXT) { 325 } else if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) {
330 module_system->Require("denyAppView"); 326 module_system->Require("denyAppView");
331 } 327 }
332 328
333 // Note: setting up the WebView class here, not the chrome.webview API. 329 // Note: setting up the WebView class here, not the chrome.webview API.
334 // The API will be automatically set up when first used. 330 // The API will be automatically set up when first used.
335 if (context->GetAvailability("webViewInternal").is_available()) { 331 if (context->GetAvailability("webViewInternal").is_available()) {
336 module_system->Require("webView"); 332 module_system->Require("webView");
337 module_system->Require("webViewConstants"); 333 module_system->Require("webViewConstants");
338 module_system->Require("webViewAttributes"); 334 module_system->Require("webViewAttributes");
339 if (context->GetAvailability("webViewExperimentalInternal") 335 if (context->GetAvailability("webViewExperimentalInternal")
340 .is_available()) { 336 .is_available()) {
341 module_system->Require("webViewExperimental"); 337 module_system->Require("webViewExperimental");
342 } 338 }
343 } else if (context_type == extensions::Feature::BLESSED_EXTENSION_CONTEXT) { 339 } else if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) {
344 module_system->Require("denyWebView"); 340 module_system->Require("denyWebView");
345 } 341 }
346 342
347 delegate_->RequireAdditionalModules(context, is_within_platform_app); 343 delegate_->RequireAdditionalModules(context, is_within_platform_app);
348 344
349 VLOG(1) << "Num tracked contexts: " << script_context_set_.size(); 345 VLOG(1) << "Num tracked contexts: " << script_context_set_.size();
350 } 346 }
351 347
352 void Dispatcher::WillReleaseScriptContext( 348 void Dispatcher::WillReleaseScriptContext(
353 WebFrame* frame, 349 WebFrame* frame,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 &stylesheet, 0, "$FONTFAMILY", system_font_family_); 382 &stylesheet, 0, "$FONTFAMILY", system_font_family_);
387 ReplaceFirstSubstringAfterOffset( 383 ReplaceFirstSubstringAfterOffset(
388 &stylesheet, 0, "$FONTSIZE", system_font_size_); 384 &stylesheet, 0, "$FONTSIZE", system_font_size_);
389 385
390 // Blink doesn't let us define an additional user agent stylesheet, so 386 // Blink doesn't let us define an additional user agent stylesheet, so
391 // we insert the default platform app or extension stylesheet into all 387 // we insert the default platform app or extension stylesheet into all
392 // documents that are loaded in each app or extension. 388 // documents that are loaded in each app or extension.
393 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet)); 389 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet));
394 } 390 }
395 391
396 // This preprocessor directive is because this file is still built in Android
397 // builds, but OptionsPageInfo is not. For Android builds, exclude this block
398 // of code to prevent link errors.
399 #if defined(ENABLE_EXTENSIONS)
400 // If this is an extension options page, and the extension has opted into 392 // If this is an extension options page, and the extension has opted into
401 // using Chrome styles, then insert the Chrome extension stylesheet. 393 // using Chrome styles, then insert the Chrome extension stylesheet.
402 if (extension && extension->is_extension() && 394 if (extension && extension->is_extension() &&
403 OptionsPageInfo::ShouldUseChromeStyle(extension) && 395 OptionsPageInfo::ShouldUseChromeStyle(extension) &&
404 effective_document_url == OptionsPageInfo::GetOptionsPage(extension)) { 396 effective_document_url == OptionsPageInfo::GetOptionsPage(extension)) {
405 frame->document().insertStyleSheet( 397 frame->document().insertStyleSheet(
406 WebString::fromUTF8(ResourceBundle::GetSharedInstance() 398 WebString::fromUTF8(ResourceBundle::GetSharedInstance()
407 .GetRawDataResource(IDR_EXTENSION_CSS) 399 .GetRawDataResource(IDR_EXTENSION_CSS)
408 .as_string())); 400 .as_string()));
409 } 401 }
410 #endif
411 402
412 content_watcher_->DidCreateDocumentElement(frame); 403 content_watcher_->DidCreateDocumentElement(frame);
413 } 404 }
414 405
415 void Dispatcher::DidMatchCSS( 406 void Dispatcher::DidMatchCSS(
416 blink::WebFrame* frame, 407 blink::WebFrame* frame,
417 const blink::WebVector<blink::WebString>& newly_matching_selectors, 408 const blink::WebVector<blink::WebString>& newly_matching_selectors,
418 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { 409 const blink::WebVector<blink::WebString>& stopped_matching_selectors) {
419 content_watcher_->DidMatchCSS( 410 content_watcher_->DidMatchCSS(
420 frame, newly_matching_selectors, stopped_matching_selectors); 411 frame, newly_matching_selectors, stopped_matching_selectors);
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 CHECK(extension) << extension_id << " was never loaded: " << error; 814 CHECK(extension) << extension_id << " was never loaded: " << error;
824 } 815 }
825 816
826 active_extension_ids_.insert(extension_id); 817 active_extension_ids_.insert(extension_id);
827 818
828 // This is called when starting a new extension page, so start the idle 819 // This is called when starting a new extension page, so start the idle
829 // handler ticking. 820 // handler ticking.
830 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); 821 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs);
831 822
832 if (is_webkit_initialized_) { 823 if (is_webkit_initialized_) {
833 extensions::DOMActivityLogger::AttachToWorld( 824 DOMActivityLogger::AttachToWorld(
834 extensions::DOMActivityLogger::kMainWorldId, extension_id); 825 DOMActivityLogger::kMainWorldId, extension_id);
835 826
836 InitOriginPermissions(extension); 827 InitOriginPermissions(extension);
837 } 828 }
838 829
839 UpdateActiveExtensions(); 830 UpdateActiveExtensions();
840 } 831 }
841 832
842 void Dispatcher::OnCancelSuspend(const std::string& extension_id) { 833 void Dispatcher::OnCancelSuspend(const std::string& extension_id) {
843 DispatchEvent(extension_id, kOnSuspendCanceledEvent); 834 DispatchEvent(extension_id, kOnSuspendCanceledEvent);
844 } 835 }
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 return v8::Handle<v8::Object>(); 1403 return v8::Handle<v8::Object>();
1413 1404
1414 if (bind_name) 1405 if (bind_name)
1415 *bind_name = split.back(); 1406 *bind_name = split.back();
1416 1407
1417 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) 1408 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context))
1418 : bind_object; 1409 : bind_object;
1419 } 1410 }
1420 1411
1421 } // namespace extensions 1412 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/BUILD.gn ('k') | extensions/renderer/dom_activity_logger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698