| OLD | NEW |
| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 namespace extensions { | 113 namespace extensions { |
| 114 | 114 |
| 115 namespace { | 115 namespace { |
| 116 | 116 |
| 117 static const int64 kInitialExtensionIdleHandlerDelayMs = 5 * 1000; | 117 static const int64 kInitialExtensionIdleHandlerDelayMs = 5 * 1000; |
| 118 static const int64 kMaxExtensionIdleHandlerDelayMs = 5 * 60 * 1000; | 118 static const int64 kMaxExtensionIdleHandlerDelayMs = 5 * 60 * 1000; |
| 119 static const char kEventDispatchFunction[] = "dispatchEvent"; | 119 static const char kEventDispatchFunction[] = "dispatchEvent"; |
| 120 static const char kOnSuspendEvent[] = "runtime.onSuspend"; | 120 static const char kOnSuspendEvent[] = "runtime.onSuspend"; |
| 121 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; | 121 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; |
| 122 | 122 |
| 123 // There is only ever one instance of the Dispatcher. |
| 124 Dispatcher* g_dispatcher = nullptr; |
| 125 |
| 123 // Returns the global value for "chrome" from |context|. If one doesn't exist | 126 // Returns the global value for "chrome" from |context|. If one doesn't exist |
| 124 // creates a new object for it. | 127 // creates a new object for it. |
| 125 // | 128 // |
| 126 // Note that this isn't necessarily an object, since webpages can write, for | 129 // Note that this isn't necessarily an object, since webpages can write, for |
| 127 // example, "window.chrome = true". | 130 // example, "window.chrome = true". |
| 128 v8::Local<v8::Value> GetOrCreateChrome(ScriptContext* context) { | 131 v8::Local<v8::Value> GetOrCreateChrome(ScriptContext* context) { |
| 129 v8::Local<v8::String> chrome_string( | 132 v8::Local<v8::String> chrome_string( |
| 130 v8::String::NewFromUtf8(context->isolate(), "chrome")); | 133 v8::String::NewFromUtf8(context->isolate(), "chrome")); |
| 131 v8::Local<v8::Object> global(context->v8_context()->Global()); | 134 v8::Local<v8::Object> global(context->v8_context()->Global()); |
| 132 v8::Local<v8::Value> chrome(global->Get(chrome_string)); | 135 v8::Local<v8::Value> chrome(global->Get(chrome_string)); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 } // namespace | 186 } // namespace |
| 184 | 187 |
| 185 Dispatcher::Dispatcher(DispatcherDelegate* delegate) | 188 Dispatcher::Dispatcher(DispatcherDelegate* delegate) |
| 186 : delegate_(delegate), | 189 : delegate_(delegate), |
| 187 content_watcher_(new ContentWatcher()), | 190 content_watcher_(new ContentWatcher()), |
| 188 source_map_(&ResourceBundle::GetSharedInstance()), | 191 source_map_(&ResourceBundle::GetSharedInstance()), |
| 189 v8_schema_registry_(new V8SchemaRegistry), | 192 v8_schema_registry_(new V8SchemaRegistry), |
| 190 is_webkit_initialized_(false), | 193 is_webkit_initialized_(false), |
| 191 user_script_set_manager_observer_(this), | 194 user_script_set_manager_observer_(this), |
| 192 webrequest_used_(false) { | 195 webrequest_used_(false) { |
| 196 DCHECK(!g_dispatcher); |
| 197 g_dispatcher = this; |
| 193 const base::CommandLine& command_line = | 198 const base::CommandLine& command_line = |
| 194 *(base::CommandLine::ForCurrentProcess()); | 199 *(base::CommandLine::ForCurrentProcess()); |
| 195 set_idle_notifications_ = | 200 set_idle_notifications_ = |
| 196 command_line.HasSwitch(switches::kExtensionProcess) || | 201 command_line.HasSwitch(switches::kExtensionProcess) || |
| 197 command_line.HasSwitch(::switches::kSingleProcess); | 202 command_line.HasSwitch(::switches::kSingleProcess); |
| 198 | 203 |
| 199 if (set_idle_notifications_) { | 204 if (set_idle_notifications_) { |
| 200 RenderThread::Get()->SetIdleNotificationDelayInMs( | 205 RenderThread::Get()->SetIdleNotificationDelayInMs( |
| 201 kInitialExtensionIdleHandlerDelayMs); | 206 kInitialExtensionIdleHandlerDelayMs); |
| 202 } | 207 } |
| 203 | 208 |
| 204 RenderThread::Get()->RegisterExtension(SafeBuiltins::CreateV8Extension()); | 209 RenderThread::Get()->RegisterExtension(SafeBuiltins::CreateV8Extension()); |
| 205 | 210 |
| 206 script_context_set_.reset( | 211 script_context_set_.reset( |
| 207 new ScriptContextSet(&extensions_, &active_extension_ids_)); | 212 new ScriptContextSet(&extensions_, &active_extension_ids_)); |
| 208 user_script_set_manager_.reset(new UserScriptSetManager(&extensions_)); | 213 user_script_set_manager_.reset(new UserScriptSetManager(&extensions_)); |
| 209 script_injection_manager_.reset( | 214 script_injection_manager_.reset( |
| 210 new ScriptInjectionManager(&extensions_, user_script_set_manager_.get())); | 215 new ScriptInjectionManager(&extensions_, user_script_set_manager_.get())); |
| 211 user_script_set_manager_observer_.Add(user_script_set_manager_.get()); | 216 user_script_set_manager_observer_.Add(user_script_set_manager_.get()); |
| 212 request_sender_.reset(new RequestSender(this)); | 217 request_sender_.reset(new RequestSender(this)); |
| 213 PopulateSourceMap(); | 218 PopulateSourceMap(); |
| 214 } | 219 } |
| 215 | 220 |
| 216 Dispatcher::~Dispatcher() { | 221 Dispatcher::~Dispatcher() { |
| 222 g_dispatcher = nullptr; |
| 223 } |
| 224 |
| 225 Dispatcher* Dispatcher::Get() { |
| 226 return g_dispatcher; |
| 217 } | 227 } |
| 218 | 228 |
| 219 void Dispatcher::OnRenderFrameCreated(content::RenderFrame* render_frame) { | 229 void Dispatcher::OnRenderFrameCreated(content::RenderFrame* render_frame) { |
| 220 script_injection_manager_->OnRenderFrameCreated(render_frame); | 230 script_injection_manager_->OnRenderFrameCreated(render_frame); |
| 221 } | 231 } |
| 222 | 232 |
| 223 bool Dispatcher::IsExtensionActive(const std::string& extension_id) const { | 233 bool Dispatcher::IsExtensionActive(const std::string& extension_id) const { |
| 224 bool is_active = | 234 bool is_active = |
| 225 active_extension_ids_.find(extension_id) != active_extension_ids_.end(); | 235 active_extension_ids_.find(extension_id) != active_extension_ids_.end(); |
| 226 if (is_active) | 236 if (is_active) |
| (...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1444 // The "guestViewDeny" module must always be loaded last. It registers | 1454 // The "guestViewDeny" module must always be loaded last. It registers |
| 1445 // error-providing custom elements for the GuestView types that are not | 1455 // error-providing custom elements for the GuestView types that are not |
| 1446 // available, and thus all of those types must have been checked and loaded | 1456 // available, and thus all of those types must have been checked and loaded |
| 1447 // (or not loaded) beforehand. | 1457 // (or not loaded) beforehand. |
| 1448 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 1458 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
| 1449 module_system->Require("guestViewDeny"); | 1459 module_system->Require("guestViewDeny"); |
| 1450 } | 1460 } |
| 1451 } | 1461 } |
| 1452 | 1462 |
| 1453 } // namespace extensions | 1463 } // namespace extensions |
| OLD | NEW |