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

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

Issue 956313002: ChromeContentRendererClient should not rely on Dispatcher::is_extension_process (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: missing ifdefs Created 5 years, 9 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') | no next file » | 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 Dispatcher::Dispatcher(DispatcherDelegate* delegate) 187 Dispatcher::Dispatcher(DispatcherDelegate* delegate)
188 : delegate_(delegate), 188 : delegate_(delegate),
189 content_watcher_(new ContentWatcher()), 189 content_watcher_(new ContentWatcher()),
190 source_map_(&ResourceBundle::GetSharedInstance()), 190 source_map_(&ResourceBundle::GetSharedInstance()),
191 v8_schema_registry_(new V8SchemaRegistry), 191 v8_schema_registry_(new V8SchemaRegistry),
192 is_webkit_initialized_(false), 192 is_webkit_initialized_(false),
193 user_script_set_manager_observer_(this), 193 user_script_set_manager_observer_(this),
194 webrequest_used_(false) { 194 webrequest_used_(false) {
195 const base::CommandLine& command_line = 195 const base::CommandLine& command_line =
196 *(base::CommandLine::ForCurrentProcess()); 196 *(base::CommandLine::ForCurrentProcess());
197 is_extension_process_ = 197 set_idle_notifications_ =
198 command_line.HasSwitch(switches::kExtensionProcess) || 198 command_line.HasSwitch(switches::kExtensionProcess) ||
199 command_line.HasSwitch(::switches::kSingleProcess); 199 command_line.HasSwitch(::switches::kSingleProcess);
200 200
201 if (is_extension_process_) { 201 if (set_idle_notifications_) {
202 RenderThread::Get()->SetIdleNotificationDelayInMs( 202 RenderThread::Get()->SetIdleNotificationDelayInMs(
203 kInitialExtensionIdleHandlerDelayMs); 203 kInitialExtensionIdleHandlerDelayMs);
204 } 204 }
205 205
206 RenderThread::Get()->RegisterExtension(SafeBuiltins::CreateV8Extension()); 206 RenderThread::Get()->RegisterExtension(SafeBuiltins::CreateV8Extension());
207 207
208 user_script_set_manager_.reset(new UserScriptSetManager(&extensions_)); 208 user_script_set_manager_.reset(new UserScriptSetManager(&extensions_));
209 script_injection_manager_.reset( 209 script_injection_manager_.reset(
210 new ScriptInjectionManager(&extensions_, user_script_set_manager_.get())); 210 new ScriptInjectionManager(&extensions_, user_script_set_manager_.get()));
211 user_script_set_manager_observer_.Add(user_script_set_manager_.get()); 211 user_script_set_manager_observer_.Add(user_script_set_manager_.get());
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 if (user_gesture) 520 if (user_gesture)
521 web_user_gesture.reset(new WebScopedUserGesture); 521 web_user_gesture.reset(new WebScopedUserGesture);
522 522
523 script_context_set_.ForEach( 523 script_context_set_.ForEach(
524 extension_id, 524 extension_id,
525 render_view, 525 render_view,
526 base::Bind(&CallModuleMethod, module_name, function_name, &args)); 526 base::Bind(&CallModuleMethod, module_name, function_name, &args));
527 527
528 // Reset the idle handler each time there's any activity like event or message 528 // Reset the idle handler each time there's any activity like event or message
529 // dispatch, for which Invoke is the chokepoint. 529 // dispatch, for which Invoke is the chokepoint.
530 if (is_extension_process_) { 530 if (set_idle_notifications_) {
531 RenderThread::Get()->ScheduleIdleHandler( 531 RenderThread::Get()->ScheduleIdleHandler(
532 kInitialExtensionIdleHandlerDelayMs); 532 kInitialExtensionIdleHandlerDelayMs);
533 } 533 }
534 534
535 // Tell the browser process when an event has been dispatched with a lazy 535 // Tell the browser process when an event has been dispatched with a lazy
536 // background page active. 536 // background page active.
537 const Extension* extension = extensions_.GetByID(extension_id); 537 const Extension* extension = extensions_.GetByID(extension_id);
538 if (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && 538 if (extension && BackgroundInfo::HasLazyBackgroundPage(extension) &&
539 module_name == kEventBindings && 539 module_name == kEventBindings &&
540 function_name == kEventDispatchFunction) { 540 function_name == kEventDispatchFunction) {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 ContentWatcher::OnWatchPages) 818 ContentWatcher::OnWatchPages)
819 IPC_MESSAGE_UNHANDLED(handled = false) 819 IPC_MESSAGE_UNHANDLED(handled = false)
820 IPC_END_MESSAGE_MAP() 820 IPC_END_MESSAGE_MAP()
821 821
822 return handled; 822 return handled;
823 } 823 }
824 824
825 void Dispatcher::WebKitInitialized() { 825 void Dispatcher::WebKitInitialized() {
826 // For extensions, we want to ensure we call the IdleHandler every so often, 826 // For extensions, we want to ensure we call the IdleHandler every so often,
827 // even if the extension keeps up activity. 827 // even if the extension keeps up activity.
828 if (is_extension_process_) { 828 if (set_idle_notifications_) {
829 forced_idle_timer_.reset(new base::RepeatingTimer<content::RenderThread>); 829 forced_idle_timer_.reset(new base::RepeatingTimer<content::RenderThread>);
830 forced_idle_timer_->Start( 830 forced_idle_timer_->Start(
831 FROM_HERE, 831 FROM_HERE,
832 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), 832 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs),
833 RenderThread::Get(), 833 RenderThread::Get(),
834 &RenderThread::IdleHandler); 834 &RenderThread::IdleHandler);
835 } 835 }
836 836
837 // Initialize host permissions for any extensions that were activated before 837 // Initialize host permissions for any extensions that were activated before
838 // WebKit was initialized. 838 // WebKit was initialized.
839 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); 839 for (std::set<std::string>::iterator iter = active_extension_ids_.begin();
840 iter != active_extension_ids_.end(); 840 iter != active_extension_ids_.end();
841 ++iter) { 841 ++iter) {
842 const Extension* extension = extensions_.GetByID(*iter); 842 const Extension* extension = extensions_.GetByID(*iter);
843 CHECK(extension); 843 CHECK(extension);
844 844
845 InitOriginPermissions(extension); 845 InitOriginPermissions(extension);
846 } 846 }
847 847
848 EnableCustomElementWhiteList(); 848 EnableCustomElementWhiteList();
849 849
850 is_webkit_initialized_ = true; 850 is_webkit_initialized_ = true;
851 } 851 }
852 852
853 void Dispatcher::IdleNotification() { 853 void Dispatcher::IdleNotification() {
854 if (is_extension_process_ && forced_idle_timer_) { 854 if (set_idle_notifications_ && forced_idle_timer_) {
855 // Dampen the forced delay as well if the extension stays idle for long 855 // Dampen the forced delay as well if the extension stays idle for long
856 // periods of time. (forced_idle_timer_ can be NULL after 856 // periods of time. (forced_idle_timer_ can be NULL after
857 // OnRenderProcessShutdown has been called.) 857 // OnRenderProcessShutdown has been called.)
858 int64 forced_delay_ms = 858 int64 forced_delay_ms =
859 std::max(RenderThread::Get()->GetIdleNotificationDelayInMs(), 859 std::max(RenderThread::Get()->GetIdleNotificationDelayInMs(),
860 kMaxExtensionIdleHandlerDelayMs); 860 kMaxExtensionIdleHandlerDelayMs);
861 forced_idle_timer_->Stop(); 861 forced_idle_timer_->Stop();
862 forced_idle_timer_->Start( 862 forced_idle_timer_->Start(
863 FROM_HERE, 863 FROM_HERE,
864 base::TimeDelta::FromMilliseconds(forced_delay_ms), 864 base::TimeDelta::FromMilliseconds(forced_delay_ms),
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 return v8::Handle<v8::Object>(); 1544 return v8::Handle<v8::Object>();
1545 1545
1546 if (bind_name) 1546 if (bind_name)
1547 *bind_name = split.back(); 1547 *bind_name = split.back();
1548 1548
1549 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) 1549 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context))
1550 : bind_object; 1550 : bind_object;
1551 } 1551 }
1552 1552
1553 } // namespace extensions 1553 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698