OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/extension_dispatcher.h" | 5 #include "chrome/renderer/extensions/dispatcher.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
11 #include "chrome/common/child_process_logging.h" | 11 #include "chrome/common/child_process_logging.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/chrome_version_info.h" | 13 #include "chrome/common/chrome_version_info.h" |
14 #include "chrome/common/extensions/api/extension_api.h" | 14 #include "chrome/common/extensions/api/extension_api.h" |
15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
16 #include "chrome/common/extensions/extension_messages.h" | 16 #include "chrome/common/extensions/extension_messages.h" |
17 #include "chrome/common/extensions/permissions/permission_set.h" | 17 #include "chrome/common/extensions/permissions/permission_set.h" |
18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
19 #include "chrome/common/view_type.h" | 19 #include "chrome/common/view_type.h" |
20 #include "chrome/renderer/chrome_render_process_observer.h" | 20 #include "chrome/renderer/chrome_render_process_observer.h" |
21 #include "chrome/renderer/extensions/api_definitions_natives.h" | 21 #include "chrome/renderer/extensions/api_definitions_natives.h" |
22 #include "chrome/renderer/extensions/app_bindings.h" | 22 #include "chrome/renderer/extensions/app_bindings.h" |
23 #include "chrome/renderer/extensions/app_window_custom_bindings.h" | 23 #include "chrome/renderer/extensions/app_window_custom_bindings.h" |
24 #include "chrome/renderer/extensions/chrome_v8_context.h" | 24 #include "chrome/renderer/extensions/chrome_v8_context.h" |
25 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 25 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
26 #include "chrome/renderer/extensions/context_menus_custom_bindings.h" | 26 #include "chrome/renderer/extensions/context_menus_custom_bindings.h" |
27 #include "chrome/renderer/extensions/event_bindings.h" | 27 #include "chrome/renderer/extensions/event_bindings.h" |
28 #include "chrome/renderer/extensions/experimental.app_custom_bindings.h" | 28 #include "chrome/renderer/extensions/experimental.app_custom_bindings.h" |
29 #include "chrome/renderer/extensions/experimental.usb_custom_bindings.h" | 29 #include "chrome/renderer/extensions/experimental.usb_custom_bindings.h" |
30 #include "chrome/renderer/extensions/extension_custom_bindings.h" | 30 #include "chrome/renderer/extensions/extension_custom_bindings.h" |
31 #include "chrome/renderer/extensions/extension_groups.h" | 31 #include "chrome/renderer/extensions/extension_groups.h" |
32 #include "chrome/renderer/extensions/extension_helper.h" | 32 #include "chrome/renderer/extensions/extension_helper.h" |
33 #include "chrome/renderer/extensions/extension_request_sender.h" | |
34 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" | 33 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" |
35 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" | 34 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" |
36 #include "chrome/renderer/extensions/file_system_natives.h" | 35 #include "chrome/renderer/extensions/file_system_natives.h" |
37 #include "chrome/renderer/extensions/i18n_custom_bindings.h" | 36 #include "chrome/renderer/extensions/i18n_custom_bindings.h" |
38 #include "chrome/renderer/extensions/media_gallery_custom_bindings.h" | 37 #include "chrome/renderer/extensions/media_gallery_custom_bindings.h" |
39 #include "chrome/renderer/extensions/miscellaneous_bindings.h" | 38 #include "chrome/renderer/extensions/miscellaneous_bindings.h" |
40 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" | 39 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" |
41 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" | 40 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" |
| 41 #include "chrome/renderer/extensions/request_sender.h" |
42 #include "chrome/renderer/extensions/runtime_custom_bindings.h" | 42 #include "chrome/renderer/extensions/runtime_custom_bindings.h" |
43 #include "chrome/renderer/extensions/send_request_natives.h" | 43 #include "chrome/renderer/extensions/send_request_natives.h" |
44 #include "chrome/renderer/extensions/set_icon_natives.h" | 44 #include "chrome/renderer/extensions/set_icon_natives.h" |
45 #include "chrome/renderer/extensions/tab_finder.h" | 45 #include "chrome/renderer/extensions/tab_finder.h" |
46 #include "chrome/renderer/extensions/tabs_custom_bindings.h" | 46 #include "chrome/renderer/extensions/tabs_custom_bindings.h" |
47 #include "chrome/renderer/extensions/tts_custom_bindings.h" | 47 #include "chrome/renderer/extensions/tts_custom_bindings.h" |
48 #include "chrome/renderer/extensions/user_script_slave.h" | 48 #include "chrome/renderer/extensions/user_script_slave.h" |
49 #include "chrome/renderer/extensions/web_request_custom_bindings.h" | 49 #include "chrome/renderer/extensions/web_request_custom_bindings.h" |
50 #include "chrome/renderer/extensions/webstore_bindings.h" | 50 #include "chrome/renderer/extensions/webstore_bindings.h" |
51 #include "chrome/renderer/module_system.h" | 51 #include "chrome/renderer/module_system.h" |
(...skipping 17 matching lines...) Expand all Loading... |
69 using WebKit::WebDataSource; | 69 using WebKit::WebDataSource; |
70 using WebKit::WebDocument; | 70 using WebKit::WebDocument; |
71 using WebKit::WebFrame; | 71 using WebKit::WebFrame; |
72 using WebKit::WebScopedUserGesture; | 72 using WebKit::WebScopedUserGesture; |
73 using WebKit::WebSecurityPolicy; | 73 using WebKit::WebSecurityPolicy; |
74 using WebKit::WebString; | 74 using WebKit::WebString; |
75 using WebKit::WebVector; | 75 using WebKit::WebVector; |
76 using WebKit::WebView; | 76 using WebKit::WebView; |
77 using content::RenderThread; | 77 using content::RenderThread; |
78 using content::RenderView; | 78 using content::RenderView; |
79 using extensions::APIPermission; | 79 |
80 using extensions::APIPermissionSet; | 80 namespace extensions { |
81 using extensions::ApiDefinitionsNatives; | |
82 using extensions::AppWindowCustomBindings; | |
83 using extensions::ContextMenusCustomBindings; | |
84 using extensions::Extension; | |
85 using extensions::ExperimentalAppCustomBindings; | |
86 using extensions::ExperimentalUsbCustomBindings; | |
87 using extensions::ExtensionAPI; | |
88 using extensions::ExtensionCustomBindings; | |
89 using extensions::Feature; | |
90 using extensions::FileBrowserHandlerCustomBindings; | |
91 using extensions::FileBrowserPrivateCustomBindings; | |
92 using extensions::FileSystemNatives; | |
93 using extensions::I18NCustomBindings; | |
94 using extensions::MiscellaneousBindings; | |
95 using extensions::MediaGalleryCustomBindings; | |
96 using extensions::PageActionsCustomBindings; | |
97 using extensions::PageCaptureCustomBindings; | |
98 using extensions::PermissionSet; | |
99 using extensions::RuntimeCustomBindings; | |
100 using extensions::SendRequestNatives; | |
101 using extensions::SetIconNatives; | |
102 using extensions::TTSCustomBindings; | |
103 using extensions::TabFinder; | |
104 using extensions::TabsCustomBindings; | |
105 using extensions::UpdatedExtensionPermissionsInfo; | |
106 using extensions::WebRequestCustomBindings; | |
107 | 81 |
108 namespace { | 82 namespace { |
109 | 83 |
110 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; | 84 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; |
111 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; | 85 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; |
112 static const char kEventDispatchFunction[] = "Event.dispatchJSON"; | 86 static const char kEventDispatchFunction[] = "Event.dispatchJSON"; |
113 static const char kOnUnloadEvent[] = "runtime.onSuspend"; | 87 static const char kOnUnloadEvent[] = "runtime.onSuspend"; |
114 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; | 88 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; |
115 | 89 |
116 class ChromeHiddenNativeHandler : public NativeHandler { | 90 class ChromeHiddenNativeHandler : public NativeHandler { |
(...skipping 25 matching lines...) Expand all Loading... |
142 for (int i = 0; i < args.Length(); ++i) | 116 for (int i = 0; i < args.Length(); ++i) |
143 components.push_back(*v8::String::Utf8Value(args[i]->ToString())); | 117 components.push_back(*v8::String::Utf8Value(args[i]->ToString())); |
144 | 118 |
145 LOG(ERROR) << JoinString(components, ','); | 119 LOG(ERROR) << JoinString(components, ','); |
146 return v8::Undefined(); | 120 return v8::Undefined(); |
147 } | 121 } |
148 }; | 122 }; |
149 | 123 |
150 class LazyBackgroundPageNativeHandler : public ChromeV8Extension { | 124 class LazyBackgroundPageNativeHandler : public ChromeV8Extension { |
151 public: | 125 public: |
152 explicit LazyBackgroundPageNativeHandler(ExtensionDispatcher* dispatcher) | 126 explicit LazyBackgroundPageNativeHandler(Dispatcher* dispatcher) |
153 : ChromeV8Extension(dispatcher) { | 127 : ChromeV8Extension(dispatcher) { |
154 RouteFunction("IncrementKeepaliveCount", | 128 RouteFunction("IncrementKeepaliveCount", |
155 base::Bind(&LazyBackgroundPageNativeHandler::IncrementKeepaliveCount, | 129 base::Bind(&LazyBackgroundPageNativeHandler::IncrementKeepaliveCount, |
156 base::Unretained(this))); | 130 base::Unretained(this))); |
157 RouteFunction("DecrementKeepaliveCount", | 131 RouteFunction("DecrementKeepaliveCount", |
158 base::Bind(&LazyBackgroundPageNativeHandler::DecrementKeepaliveCount, | 132 base::Bind(&LazyBackgroundPageNativeHandler::DecrementKeepaliveCount, |
159 base::Unretained(this))); | 133 base::Unretained(this))); |
160 } | 134 } |
161 | 135 |
162 v8::Handle<v8::Value> IncrementKeepaliveCount(const v8::Arguments& args) { | 136 v8::Handle<v8::Value> IncrementKeepaliveCount(const v8::Arguments& args) { |
163 ChromeV8Context* context = | 137 ChromeV8Context* context = dispatcher()->v8_context_set().GetCurrent(); |
164 extension_dispatcher()->v8_context_set().GetCurrent(); | |
165 if (!context) | 138 if (!context) |
166 return v8::Undefined(); | 139 return v8::Undefined(); |
167 RenderView* render_view = context->GetRenderView(); | 140 RenderView* render_view = context->GetRenderView(); |
168 if (IsContextLazyBackgroundPage(render_view, context->extension())) { | 141 if (IsContextLazyBackgroundPage(render_view, context->extension())) { |
169 render_view->Send(new ExtensionHostMsg_IncrementLazyKeepaliveCount( | 142 render_view->Send(new ExtensionHostMsg_IncrementLazyKeepaliveCount( |
170 render_view->GetRoutingID())); | 143 render_view->GetRoutingID())); |
171 } | 144 } |
172 return v8::Undefined(); | 145 return v8::Undefined(); |
173 } | 146 } |
174 | 147 |
175 v8::Handle<v8::Value> DecrementKeepaliveCount(const v8::Arguments& args) { | 148 v8::Handle<v8::Value> DecrementKeepaliveCount(const v8::Arguments& args) { |
176 ChromeV8Context* context = | 149 ChromeV8Context* context = dispatcher()->v8_context_set().GetCurrent(); |
177 extension_dispatcher()->v8_context_set().GetCurrent(); | |
178 if (!context) | 150 if (!context) |
179 return v8::Undefined(); | 151 return v8::Undefined(); |
180 RenderView* render_view = context->GetRenderView(); | 152 RenderView* render_view = context->GetRenderView(); |
181 if (IsContextLazyBackgroundPage(render_view, context->extension())) { | 153 if (IsContextLazyBackgroundPage(render_view, context->extension())) { |
182 render_view->Send(new ExtensionHostMsg_DecrementLazyKeepaliveCount( | 154 render_view->Send(new ExtensionHostMsg_DecrementLazyKeepaliveCount( |
183 render_view->GetRoutingID())); | 155 render_view->GetRoutingID())); |
184 } | 156 } |
185 return v8::Undefined(); | 157 return v8::Undefined(); |
186 } | 158 } |
187 | 159 |
188 private: | 160 private: |
189 bool IsContextLazyBackgroundPage(RenderView* render_view, | 161 bool IsContextLazyBackgroundPage(RenderView* render_view, |
190 const Extension* extension) { | 162 const Extension* extension) { |
191 if (!render_view) | 163 if (!render_view) |
192 return false; | 164 return false; |
193 | 165 |
194 ExtensionHelper* helper = ExtensionHelper::Get(render_view); | 166 ExtensionHelper* helper = ExtensionHelper::Get(render_view); |
195 return (extension && extension->has_lazy_background_page() && | 167 return (extension && extension->has_lazy_background_page() && |
196 helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); | 168 helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); |
197 } | 169 } |
198 }; | 170 }; |
199 | 171 |
200 class ProcessInfoNativeHandler : public ChromeV8Extension { | 172 class ProcessInfoNativeHandler : public ChromeV8Extension { |
201 public: | 173 public: |
202 explicit ProcessInfoNativeHandler( | 174 explicit ProcessInfoNativeHandler( |
203 ExtensionDispatcher* dispatcher, | 175 Dispatcher* dispatcher, |
204 const std::string& extension_id, | 176 const std::string& extension_id, |
205 const std::string& context_type, | 177 const std::string& context_type, |
206 bool is_incognito_context, | 178 bool is_incognito_context, |
207 int manifest_version) | 179 int manifest_version) |
208 : ChromeV8Extension(dispatcher), | 180 : ChromeV8Extension(dispatcher), |
209 extension_id_(extension_id), | 181 extension_id_(extension_id), |
210 context_type_(context_type), | 182 context_type_(context_type), |
211 is_incognito_context_(is_incognito_context), | 183 is_incognito_context_(is_incognito_context), |
212 manifest_version_(manifest_version) { | 184 manifest_version_(manifest_version) { |
213 RouteFunction("GetExtensionId", | 185 RouteFunction("GetExtensionId", |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 v8::Handle<v8::Object> chrome_object(v8::Object::New()); | 291 v8::Handle<v8::Object> chrome_object(v8::Object::New()); |
320 global->Set(chrome_string, chrome_object); | 292 global->Set(chrome_string, chrome_object); |
321 return chrome_object; | 293 return chrome_object; |
322 } | 294 } |
323 CHECK(chrome->IsObject()); | 295 CHECK(chrome->IsObject()); |
324 return chrome->ToObject(); | 296 return chrome->ToObject(); |
325 } | 297 } |
326 | 298 |
327 } // namespace | 299 } // namespace |
328 | 300 |
329 ExtensionDispatcher::ExtensionDispatcher() | 301 Dispatcher::Dispatcher() |
330 : is_webkit_initialized_(false), | 302 : is_webkit_initialized_(false), |
331 webrequest_adblock_(false), | 303 webrequest_adblock_(false), |
332 webrequest_adblock_plus_(false), | 304 webrequest_adblock_plus_(false), |
333 webrequest_other_(false), | 305 webrequest_other_(false), |
334 source_map_(&ResourceBundle::GetSharedInstance()), | 306 source_map_(&ResourceBundle::GetSharedInstance()), |
335 chrome_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) { | 307 chrome_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) { |
336 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); | 308 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); |
337 is_extension_process_ = | 309 is_extension_process_ = |
338 command_line.HasSwitch(switches::kExtensionProcess) || | 310 command_line.HasSwitch(switches::kExtensionProcess) || |
339 command_line.HasSwitch(switches::kSingleProcess); | 311 command_line.HasSwitch(switches::kSingleProcess); |
340 | 312 |
341 if (is_extension_process_) { | 313 if (is_extension_process_) { |
342 RenderThread::Get()->SetIdleNotificationDelayInMs( | 314 RenderThread::Get()->SetIdleNotificationDelayInMs( |
343 kInitialExtensionIdleHandlerDelayMs); | 315 kInitialExtensionIdleHandlerDelayMs); |
344 } | 316 } |
345 | 317 |
346 user_script_slave_.reset(new extensions::UserScriptSlave(&extensions_)); | 318 user_script_slave_.reset(new UserScriptSlave(&extensions_)); |
347 request_sender_.reset(new ExtensionRequestSender(this, &v8_context_set_)); | 319 request_sender_.reset(new RequestSender(this, &v8_context_set_)); |
348 PopulateSourceMap(); | 320 PopulateSourceMap(); |
349 PopulateLazyBindingsMap(); | 321 PopulateLazyBindingsMap(); |
350 } | 322 } |
351 | 323 |
352 ExtensionDispatcher::~ExtensionDispatcher() { | 324 Dispatcher::~Dispatcher() { |
353 } | 325 } |
354 | 326 |
355 bool ExtensionDispatcher::OnControlMessageReceived( | 327 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { |
356 const IPC::Message& message) { | |
357 bool handled = true; | 328 bool handled = true; |
358 IPC_BEGIN_MESSAGE_MAP(ExtensionDispatcher, message) | 329 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) |
359 IPC_MESSAGE_HANDLER(ExtensionMsg_SetChannel, OnSetChannel) | 330 IPC_MESSAGE_HANDLER(ExtensionMsg_SetChannel, OnSetChannel) |
360 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) | 331 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) |
361 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) | 332 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) |
362 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) | 333 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) |
363 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, | 334 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, |
364 OnDispatchOnDisconnect) | 335 OnDispatchOnDisconnect) |
365 IPC_MESSAGE_HANDLER(ExtensionMsg_SetFunctionNames, OnSetFunctionNames) | 336 IPC_MESSAGE_HANDLER(ExtensionMsg_SetFunctionNames, OnSetFunctionNames) |
366 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) | 337 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) |
367 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) | 338 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) |
368 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, | 339 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, |
369 OnSetScriptingWhitelist) | 340 OnSetScriptingWhitelist) |
370 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) | 341 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) |
371 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) | 342 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) |
372 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateTabSpecificPermissions, | 343 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateTabSpecificPermissions, |
373 OnUpdateTabSpecificPermissions) | 344 OnUpdateTabSpecificPermissions) |
374 IPC_MESSAGE_HANDLER(ExtensionMsg_ClearTabSpecificPermissions, | 345 IPC_MESSAGE_HANDLER(ExtensionMsg_ClearTabSpecificPermissions, |
375 OnClearTabSpecificPermissions) | 346 OnClearTabSpecificPermissions) |
376 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) | 347 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) |
377 IPC_MESSAGE_HANDLER(ExtensionMsg_UsingWebRequestAPI, OnUsingWebRequestAPI) | 348 IPC_MESSAGE_HANDLER(ExtensionMsg_UsingWebRequestAPI, OnUsingWebRequestAPI) |
378 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldUnload, OnShouldUnload) | 349 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldUnload, OnShouldUnload) |
379 IPC_MESSAGE_HANDLER(ExtensionMsg_Unload, OnUnload) | 350 IPC_MESSAGE_HANDLER(ExtensionMsg_Unload, OnUnload) |
380 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelUnload, OnCancelUnload) | 351 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelUnload, OnCancelUnload) |
381 IPC_MESSAGE_UNHANDLED(handled = false) | 352 IPC_MESSAGE_UNHANDLED(handled = false) |
382 IPC_END_MESSAGE_MAP() | 353 IPC_END_MESSAGE_MAP() |
383 | 354 |
384 return handled; | 355 return handled; |
385 } | 356 } |
386 | 357 |
387 void ExtensionDispatcher::WebKitInitialized() { | 358 void Dispatcher::WebKitInitialized() { |
388 // For extensions, we want to ensure we call the IdleHandler every so often, | 359 // For extensions, we want to ensure we call the IdleHandler every so often, |
389 // even if the extension keeps up activity. | 360 // even if the extension keeps up activity. |
390 if (is_extension_process_) { | 361 if (is_extension_process_) { |
391 forced_idle_timer_.Start(FROM_HERE, | 362 forced_idle_timer_.Start(FROM_HERE, |
392 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), | 363 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), |
393 RenderThread::Get(), &RenderThread::IdleHandler); | 364 RenderThread::Get(), &RenderThread::IdleHandler); |
394 } | 365 } |
395 | 366 |
396 // Initialize host permissions for any extensions that were activated before | 367 // Initialize host permissions for any extensions that were activated before |
397 // WebKit was initialized. | 368 // WebKit was initialized. |
398 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); | 369 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); |
399 iter != active_extension_ids_.end(); ++iter) { | 370 iter != active_extension_ids_.end(); ++iter) { |
400 const Extension* extension = extensions_.GetByID(*iter); | 371 const Extension* extension = extensions_.GetByID(*iter); |
401 CHECK(extension); | 372 CHECK(extension); |
402 InitOriginPermissions(extension); | 373 InitOriginPermissions(extension); |
403 } | 374 } |
404 | 375 |
405 is_webkit_initialized_ = true; | 376 is_webkit_initialized_ = true; |
406 } | 377 } |
407 | 378 |
408 void ExtensionDispatcher::IdleNotification() { | 379 void Dispatcher::IdleNotification() { |
409 if (is_extension_process_) { | 380 if (is_extension_process_) { |
410 // Dampen the forced delay as well if the extension stays idle for long | 381 // Dampen the forced delay as well if the extension stays idle for long |
411 // periods of time. | 382 // periods of time. |
412 int64 forced_delay_ms = std::max( | 383 int64 forced_delay_ms = std::max( |
413 RenderThread::Get()->GetIdleNotificationDelayInMs(), | 384 RenderThread::Get()->GetIdleNotificationDelayInMs(), |
414 kMaxExtensionIdleHandlerDelayMs); | 385 kMaxExtensionIdleHandlerDelayMs); |
415 forced_idle_timer_.Stop(); | 386 forced_idle_timer_.Stop(); |
416 forced_idle_timer_.Start(FROM_HERE, | 387 forced_idle_timer_.Start(FROM_HERE, |
417 base::TimeDelta::FromMilliseconds(forced_delay_ms), | 388 base::TimeDelta::FromMilliseconds(forced_delay_ms), |
418 RenderThread::Get(), &RenderThread::IdleHandler); | 389 RenderThread::Get(), &RenderThread::IdleHandler); |
419 } | 390 } |
420 } | 391 } |
421 | 392 |
422 void ExtensionDispatcher::OnSetFunctionNames( | 393 void Dispatcher::OnSetFunctionNames( |
423 const std::vector<std::string>& names) { | 394 const std::vector<std::string>& names) { |
424 function_names_.clear(); | 395 function_names_.clear(); |
425 for (size_t i = 0; i < names.size(); ++i) | 396 for (size_t i = 0; i < names.size(); ++i) |
426 function_names_.insert(names[i]); | 397 function_names_.insert(names[i]); |
427 } | 398 } |
428 | 399 |
429 void ExtensionDispatcher::OnSetChannel(int channel) { | 400 void Dispatcher::OnSetChannel(int channel) { |
430 chrome_channel_ = channel; | 401 chrome_channel_ = channel; |
431 } | 402 } |
432 | 403 |
433 void ExtensionDispatcher::OnMessageInvoke(const std::string& extension_id, | 404 void Dispatcher::OnMessageInvoke(const std::string& extension_id, |
434 const std::string& function_name, | 405 const std::string& function_name, |
435 const ListValue& args, | 406 const ListValue& args, |
436 const GURL& event_url, | 407 const GURL& event_url, |
437 bool user_gesture) { | 408 bool user_gesture) { |
438 scoped_ptr<WebScopedUserGesture> web_user_gesture; | 409 scoped_ptr<WebScopedUserGesture> web_user_gesture; |
439 if (user_gesture) { | 410 if (user_gesture) { |
440 web_user_gesture.reset(new WebScopedUserGesture); | 411 web_user_gesture.reset(new WebScopedUserGesture); |
441 } | 412 } |
442 | 413 |
443 v8_context_set_.DispatchChromeHiddenMethod( | 414 v8_context_set_.DispatchChromeHiddenMethod( |
444 extension_id, function_name, args, NULL, event_url); | 415 extension_id, function_name, args, NULL, event_url); |
445 | 416 |
446 // Reset the idle handler each time there's any activity like event or message | 417 // Reset the idle handler each time there's any activity like event or message |
447 // dispatch, for which Invoke is the chokepoint. | 418 // dispatch, for which Invoke is the chokepoint. |
448 if (is_extension_process_) { | 419 if (is_extension_process_) { |
449 RenderThread::Get()->ScheduleIdleHandler( | 420 RenderThread::Get()->ScheduleIdleHandler( |
450 kInitialExtensionIdleHandlerDelayMs); | 421 kInitialExtensionIdleHandlerDelayMs); |
451 } | 422 } |
452 | 423 |
453 // Tell the browser process when an event has been dispatched with a lazy | 424 // Tell the browser process when an event has been dispatched with a lazy |
454 // background page active. | 425 // background page active. |
455 const Extension* extension = extensions_.GetByID(extension_id); | 426 const Extension* extension = extensions_.GetByID(extension_id); |
456 if (extension && extension->has_lazy_background_page() && | 427 if (extension && extension->has_lazy_background_page() && |
457 function_name == kEventDispatchFunction) { | 428 function_name == kEventDispatchFunction) { |
458 RenderView* background_view = | 429 RenderView* background_view = |
459 ExtensionHelper::GetBackgroundPage(extension_id); | 430 ExtensionHelper::GetBackgroundPage(extension_id); |
460 if (background_view) { | 431 if (background_view) { |
461 background_view->Send(new ExtensionHostMsg_EventAck( | 432 background_view->Send(new ExtensionHostMsg_EventAck( |
462 background_view->GetRoutingID())); | 433 background_view->GetRoutingID())); |
463 } | 434 } |
464 } | 435 } |
465 } | 436 } |
466 | 437 |
467 void ExtensionDispatcher::OnDispatchOnConnect( | 438 void Dispatcher::OnDispatchOnConnect(int target_port_id, |
468 int target_port_id, | 439 const std::string& channel_name, |
469 const std::string& channel_name, | 440 const std::string& tab_json, |
470 const std::string& tab_json, | 441 const std::string& source_extension_id, |
471 const std::string& source_extension_id, | 442 const std::string& target_extension_id) { |
472 const std::string& target_extension_id) { | |
473 MiscellaneousBindings::DispatchOnConnect( | 443 MiscellaneousBindings::DispatchOnConnect( |
474 v8_context_set_.GetAll(), | 444 v8_context_set_.GetAll(), |
475 target_port_id, channel_name, tab_json, | 445 target_port_id, channel_name, tab_json, |
476 source_extension_id, target_extension_id, | 446 source_extension_id, target_extension_id, |
477 NULL); // All render views. | 447 NULL); // All render views. |
478 } | 448 } |
479 | 449 |
480 void ExtensionDispatcher::OnDeliverMessage(int target_port_id, | 450 void Dispatcher::OnDeliverMessage(int target_port_id, |
481 const std::string& message) { | 451 const std::string& message) { |
482 MiscellaneousBindings::DeliverMessage( | 452 MiscellaneousBindings::DeliverMessage( |
483 v8_context_set_.GetAll(), | 453 v8_context_set_.GetAll(), |
484 target_port_id, | 454 target_port_id, |
485 message, | 455 message, |
486 NULL); // All render views. | 456 NULL); // All render views. |
487 } | 457 } |
488 | 458 |
489 void ExtensionDispatcher::OnDispatchOnDisconnect(int port_id, | 459 void Dispatcher::OnDispatchOnDisconnect(int port_id, bool connection_error) { |
490 bool connection_error) { | |
491 MiscellaneousBindings::DispatchOnDisconnect( | 460 MiscellaneousBindings::DispatchOnDisconnect( |
492 v8_context_set_.GetAll(), | 461 v8_context_set_.GetAll(), |
493 port_id, connection_error, | 462 port_id, connection_error, |
494 NULL); // All render views. | 463 NULL); // All render views. |
495 } | 464 } |
496 | 465 |
497 void ExtensionDispatcher::OnLoaded( | 466 void Dispatcher::OnLoaded( |
498 const std::vector<ExtensionMsg_Loaded_Params>& loaded_extensions) { | 467 const std::vector<ExtensionMsg_Loaded_Params>& loaded_extensions) { |
499 std::vector<WebString> platform_app_patterns; | 468 std::vector<WebString> platform_app_patterns; |
500 | 469 |
501 std::vector<ExtensionMsg_Loaded_Params>::const_iterator i; | 470 std::vector<ExtensionMsg_Loaded_Params>::const_iterator i; |
502 for (i = loaded_extensions.begin(); i != loaded_extensions.end(); ++i) { | 471 for (i = loaded_extensions.begin(); i != loaded_extensions.end(); ++i) { |
503 scoped_refptr<const Extension> extension(i->ConvertToExtension()); | 472 scoped_refptr<const Extension> extension(i->ConvertToExtension()); |
504 if (!extension) { | 473 if (!extension) { |
505 // This can happen if extension parsing fails for any reason. One reason | 474 // This can happen if extension parsing fails for any reason. One reason |
506 // this can legitimately happen is if the | 475 // this can legitimately happen is if the |
507 // --enable-experimental-extension-apis changes at runtime, which happens | 476 // --enable-experimental-extension-apis changes at runtime, which happens |
(...skipping 21 matching lines...) Expand all Loading... |
529 WebView::addUserStyleSheet( | 498 WebView::addUserStyleSheet( |
530 WebString::fromUTF8(ResourceBundle::GetSharedInstance(). | 499 WebString::fromUTF8(ResourceBundle::GetSharedInstance(). |
531 GetRawDataResource(IDR_PLATFORM_APP_CSS, | 500 GetRawDataResource(IDR_PLATFORM_APP_CSS, |
532 ui::SCALE_FACTOR_NONE)), | 501 ui::SCALE_FACTOR_NONE)), |
533 patterns, | 502 patterns, |
534 WebView::UserContentInjectInAllFrames, | 503 WebView::UserContentInjectInAllFrames, |
535 WebView::UserStyleInjectInExistingDocuments); | 504 WebView::UserStyleInjectInExistingDocuments); |
536 } | 505 } |
537 } | 506 } |
538 | 507 |
539 void ExtensionDispatcher::OnUnloaded(const std::string& id) { | 508 void Dispatcher::OnUnloaded(const std::string& id) { |
540 extensions_.Remove(id); | 509 extensions_.Remove(id); |
541 active_extension_ids_.erase(id); | 510 active_extension_ids_.erase(id); |
542 | 511 |
543 // If the extension is later reloaded with a different set of permissions, | 512 // If the extension is later reloaded with a different set of permissions, |
544 // we'd like it to get a new isolated world ID, so that it can pick up the | 513 // we'd like it to get a new isolated world ID, so that it can pick up the |
545 // changed origin whitelist. | 514 // changed origin whitelist. |
546 user_script_slave_->RemoveIsolatedWorld(id); | 515 user_script_slave_->RemoveIsolatedWorld(id); |
547 | 516 |
548 // We don't do anything with existing platform-app stylesheets. They will | 517 // We don't do anything with existing platform-app stylesheets. They will |
549 // stay resident, but the URL pattern corresponding to the unloaded | 518 // stay resident, but the URL pattern corresponding to the unloaded |
550 // extension's URL just won't match anything anymore. | 519 // extension's URL just won't match anything anymore. |
551 } | 520 } |
552 | 521 |
553 void ExtensionDispatcher::OnSetScriptingWhitelist( | 522 void Dispatcher::OnSetScriptingWhitelist( |
554 const Extension::ScriptingWhitelist& extension_ids) { | 523 const Extension::ScriptingWhitelist& extension_ids) { |
555 Extension::SetScriptingWhitelist(extension_ids); | 524 Extension::SetScriptingWhitelist(extension_ids); |
556 } | 525 } |
557 | 526 |
558 bool ExtensionDispatcher::IsExtensionActive( | 527 bool Dispatcher::IsExtensionActive( |
559 const std::string& extension_id) const { | 528 const std::string& extension_id) const { |
560 bool is_active = | 529 bool is_active = |
561 active_extension_ids_.find(extension_id) != active_extension_ids_.end(); | 530 active_extension_ids_.find(extension_id) != active_extension_ids_.end(); |
562 if (is_active) | 531 if (is_active) |
563 CHECK(extensions_.Contains(extension_id)); | 532 CHECK(extensions_.Contains(extension_id)); |
564 return is_active; | 533 return is_active; |
565 } | 534 } |
566 | 535 |
567 bool ExtensionDispatcher::AllowScriptExtension( | 536 bool Dispatcher::AllowScriptExtension( |
568 WebFrame* frame, | 537 WebFrame* frame, |
569 const std::string& v8_extension_name, | 538 const std::string& v8_extension_name, |
570 int extension_group) { | 539 int extension_group) { |
571 return AllowScriptExtension(frame, v8_extension_name, extension_group, 0); | 540 return AllowScriptExtension(frame, v8_extension_name, extension_group, 0); |
572 } | 541 } |
573 | 542 |
574 namespace { | 543 namespace { |
575 | 544 |
576 // This is what the extension_group variable will be when DidCreateScriptContext | 545 // This is what the extension_group variable will be when DidCreateScriptContext |
577 // is called. We know because it's the same as what AllowScriptExtension gets | 546 // is called. We know because it's the same as what AllowScriptExtension gets |
578 // passed, and the two functions are called sequentially from WebKit. | 547 // passed, and the two functions are called sequentially from WebKit. |
579 // | 548 // |
580 // TODO(koz): Plumb extension_group through to AllowScriptExtension() from | 549 // TODO(koz): Plumb extension_group through to AllowScriptExtension() from |
581 // WebKit. | 550 // WebKit. |
582 static int g_hack_extension_group = 0; | 551 static int g_hack_extension_group = 0; |
583 | 552 |
584 } | 553 } |
585 | 554 |
586 bool ExtensionDispatcher::AllowScriptExtension( | 555 bool Dispatcher::AllowScriptExtension(WebFrame* frame, |
587 WebFrame* frame, | 556 const std::string& v8_extension_name, |
588 const std::string& v8_extension_name, | 557 int extension_group, |
589 int extension_group, | 558 int world_id) { |
590 int world_id) { | |
591 g_hack_extension_group = extension_group; | 559 g_hack_extension_group = extension_group; |
592 return true; | 560 return true; |
593 } | 561 } |
594 | 562 |
595 void ExtensionDispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 563 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
596 ChromeV8Context* context) { | 564 ChromeV8Context* context) { |
597 module_system->RegisterNativeHandler("event_bindings", | 565 module_system->RegisterNativeHandler("event_bindings", |
598 scoped_ptr<NativeHandler>(EventBindings::Get(this))); | 566 scoped_ptr<NativeHandler>(EventBindings::Get(this))); |
599 module_system->RegisterNativeHandler("miscellaneous_bindings", | 567 module_system->RegisterNativeHandler("miscellaneous_bindings", |
600 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); | 568 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); |
601 module_system->RegisterNativeHandler("apiDefinitions", | 569 module_system->RegisterNativeHandler("apiDefinitions", |
602 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this))); | 570 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this))); |
603 module_system->RegisterNativeHandler("sendRequest", | 571 module_system->RegisterNativeHandler("sendRequest", |
604 scoped_ptr<NativeHandler>( | 572 scoped_ptr<NativeHandler>( |
605 new SendRequestNatives(this, request_sender_.get()))); | 573 new SendRequestNatives(this, request_sender_.get()))); |
606 module_system->RegisterNativeHandler("setIcon", | 574 module_system->RegisterNativeHandler("setIcon", |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 module_system->RegisterNativeHandler("tabs", | 611 module_system->RegisterNativeHandler("tabs", |
644 scoped_ptr<NativeHandler>(new TabsCustomBindings())); | 612 scoped_ptr<NativeHandler>(new TabsCustomBindings())); |
645 module_system->RegisterNativeHandler("tts", | 613 module_system->RegisterNativeHandler("tts", |
646 scoped_ptr<NativeHandler>(new TTSCustomBindings())); | 614 scoped_ptr<NativeHandler>(new TTSCustomBindings())); |
647 module_system->RegisterNativeHandler("web_request", | 615 module_system->RegisterNativeHandler("web_request", |
648 scoped_ptr<NativeHandler>(new WebRequestCustomBindings())); | 616 scoped_ptr<NativeHandler>(new WebRequestCustomBindings())); |
649 module_system->RegisterNativeHandler("webstore", | 617 module_system->RegisterNativeHandler("webstore", |
650 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); | 618 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); |
651 } | 619 } |
652 | 620 |
653 void ExtensionDispatcher::PopulateSourceMap() { | 621 void Dispatcher::PopulateSourceMap() { |
654 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); | 622 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); |
655 source_map_.RegisterSource("miscellaneous_bindings", | 623 source_map_.RegisterSource("miscellaneous_bindings", |
656 IDR_MISCELLANEOUS_BINDINGS_JS); | 624 IDR_MISCELLANEOUS_BINDINGS_JS); |
657 source_map_.RegisterSource("schema_generated_bindings", | 625 source_map_.RegisterSource("schema_generated_bindings", |
658 IDR_SCHEMA_GENERATED_BINDINGS_JS); | 626 IDR_SCHEMA_GENERATED_BINDINGS_JS); |
659 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); | 627 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); |
660 source_map_.RegisterSource("apitest", IDR_EXTENSION_APITEST_JS); | 628 source_map_.RegisterSource("apitest", IDR_EXTENSION_APITEST_JS); |
661 | 629 |
662 // Libraries. | 630 // Libraries. |
663 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); | 631 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); | 680 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); |
713 source_map_.RegisterSource("webRequestInternal", | 681 source_map_.RegisterSource("webRequestInternal", |
714 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); | 682 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); |
715 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); | 683 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); |
716 | 684 |
717 // Platform app sources that are not API-specific.. | 685 // Platform app sources that are not API-specific.. |
718 source_map_.RegisterSource("browserTag", IDR_BROWSER_TAG_JS); | 686 source_map_.RegisterSource("browserTag", IDR_BROWSER_TAG_JS); |
719 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); | 687 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); |
720 } | 688 } |
721 | 689 |
722 void ExtensionDispatcher::PopulateLazyBindingsMap() { | 690 void Dispatcher::PopulateLazyBindingsMap() { |
723 lazy_bindings_map_["app"] = InstallAppBindings; | 691 lazy_bindings_map_["app"] = InstallAppBindings; |
724 lazy_bindings_map_["webstore"] = InstallWebstoreBindings; | 692 lazy_bindings_map_["webstore"] = InstallWebstoreBindings; |
725 } | 693 } |
726 | 694 |
727 void ExtensionDispatcher::InstallBindings(ModuleSystem* module_system, | 695 void Dispatcher::InstallBindings(ModuleSystem* module_system, |
728 v8::Handle<v8::Context> v8_context, | 696 v8::Handle<v8::Context> v8_context, |
729 const std::string& api) { | 697 const std::string& api) { |
730 std::map<std::string, BindingInstaller>::const_iterator lazy_binding = | 698 std::map<std::string, BindingInstaller>::const_iterator lazy_binding = |
731 lazy_bindings_map_.find(api); | 699 lazy_bindings_map_.find(api); |
732 if (lazy_binding != lazy_bindings_map_.end()) { | 700 if (lazy_binding != lazy_bindings_map_.end()) { |
733 v8::Handle<v8::Object> global(v8_context->Global()); | 701 v8::Handle<v8::Object> global(v8_context->Global()); |
734 v8::Handle<v8::Object> chrome = | 702 v8::Handle<v8::Object> chrome = |
735 global->Get(v8::String::New("chrome"))->ToObject(); | 703 global->Get(v8::String::New("chrome"))->ToObject(); |
736 v8::Handle<v8::Object> chrome_hidden = | 704 v8::Handle<v8::Object> chrome_hidden = |
737 ChromeV8Context::GetOrCreateChromeHidden(v8_context)->ToObject(); | 705 ChromeV8Context::GetOrCreateChromeHidden(v8_context)->ToObject(); |
738 (*lazy_binding->second)(module_system, chrome, chrome_hidden); | 706 (*lazy_binding->second)(module_system, chrome, chrome_hidden); |
739 } else { | 707 } else { |
740 module_system->Require(api); | 708 module_system->Require(api); |
741 } | 709 } |
742 } | 710 } |
743 | 711 |
744 void ExtensionDispatcher::DidCreateScriptContext( | 712 void Dispatcher::DidCreateScriptContext( |
745 WebFrame* frame, v8::Handle<v8::Context> v8_context, int extension_group, | 713 WebFrame* frame, v8::Handle<v8::Context> v8_context, int extension_group, |
746 int world_id) { | 714 int world_id) { |
747 // TODO(koz): If the caller didn't pass extension_group, use the last value. | 715 // TODO(koz): If the caller didn't pass extension_group, use the last value. |
748 if (extension_group == -1) | 716 if (extension_group == -1) |
749 extension_group = g_hack_extension_group; | 717 extension_group = g_hack_extension_group; |
750 | 718 |
751 std::string extension_id = GetExtensionID(frame, world_id); | 719 std::string extension_id = GetExtensionID(frame, world_id); |
752 | 720 |
753 const Extension* extension = extensions_.GetByID(extension_id); | 721 const Extension* extension = extensions_.GetByID(extension_id); |
754 if (!extension && !extension_id.empty()) { | 722 if (!extension && !extension_id.empty()) { |
755 // There are conditions where despite a context being associated with an | 723 // There are conditions where despite a context being associated with an |
756 // extension, no extension actually gets found. Ignore "invalid" because | 724 // extension, no extension actually gets found. Ignore "invalid" because |
757 // CSP blocks extension page loading by switching the extension ID to | 725 // CSP blocks extension page loading by switching the extension ID to |
758 // "invalid". This isn't interesting. | 726 // "invalid". This isn't interesting. |
759 if (extension_id != "invalid") { | 727 if (extension_id != "invalid") { |
760 LOG(ERROR) << "Extension \"" << extension_id << "\" not found"; | 728 LOG(ERROR) << "Extension \"" << extension_id << "\" not found"; |
761 RenderThread::Get()->RecordUserMetrics("ExtensionNotFound_ED"); | 729 RenderThread::Get()->RecordUserMetrics("ExtensionNotFound_ED"); |
762 } | 730 } |
763 | 731 |
764 extension_id = ""; | 732 extension_id = ""; |
765 } | 733 } |
766 | 734 |
767 ExtensionURLInfo url_info(frame->document().securityOrigin(), | 735 ExtensionURLInfo url_info(frame->document().securityOrigin(), |
768 extensions::UserScriptSlave::GetDataSourceURLForFrame(frame)); | 736 UserScriptSlave::GetDataSourceURLForFrame(frame)); |
769 | 737 |
770 Feature::Context context_type = | 738 Feature::Context context_type = |
771 ClassifyJavaScriptContext(extension_id, extension_group, url_info); | 739 ClassifyJavaScriptContext(extension_id, extension_group, url_info); |
772 | 740 |
773 ChromeV8Context* context = | 741 ChromeV8Context* context = |
774 new ChromeV8Context(v8_context, frame, extension, context_type); | 742 new ChromeV8Context(v8_context, frame, extension, context_type); |
775 v8_context_set_.Add(context); | 743 v8_context_set_.Add(context); |
776 | 744 |
777 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context, | 745 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context, |
778 &source_map_)); | 746 &source_map_)); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 | 816 |
849 context->set_module_system(module_system.Pass()); | 817 context->set_module_system(module_system.Pass()); |
850 | 818 |
851 context->DispatchOnLoadEvent( | 819 context->DispatchOnLoadEvent( |
852 ChromeRenderProcessObserver::is_incognito_process(), | 820 ChromeRenderProcessObserver::is_incognito_process(), |
853 manifest_version); | 821 manifest_version); |
854 | 822 |
855 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); | 823 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); |
856 } | 824 } |
857 | 825 |
858 std::string ExtensionDispatcher::GetExtensionID(const WebFrame* frame, | 826 std::string Dispatcher::GetExtensionID(const WebFrame* frame, |
859 int world_id) { | 827 int world_id) { |
860 if (world_id != 0) { | 828 if (world_id != 0) { |
861 // Isolated worlds (content script). | 829 // Isolated worlds (content script). |
862 return user_script_slave_->GetExtensionIdForIsolatedWorld(world_id); | 830 return user_script_slave_->GetExtensionIdForIsolatedWorld(world_id); |
863 } | 831 } |
864 | 832 |
865 // Extension pages (chrome-extension:// URLs). | 833 // Extension pages (chrome-extension:// URLs). |
866 GURL frame_url = extensions::UserScriptSlave::GetDataSourceURLForFrame(frame); | 834 GURL frame_url = UserScriptSlave::GetDataSourceURLForFrame(frame); |
867 return extensions_.GetExtensionOrAppIDByURL( | 835 return extensions_.GetExtensionOrAppIDByURL( |
868 ExtensionURLInfo(frame->document().securityOrigin(), frame_url)); | 836 ExtensionURLInfo(frame->document().securityOrigin(), frame_url)); |
869 } | 837 } |
870 | 838 |
871 bool ExtensionDispatcher::IsWithinPlatformApp(const WebFrame* frame) { | 839 bool Dispatcher::IsWithinPlatformApp(const WebFrame* frame) { |
872 const Extension* extension = | 840 const Extension* extension = |
873 extensions_.GetByID(GetExtensionID(frame->top(), 0)); | 841 extensions_.GetByID(GetExtensionID(frame->top(), 0)); |
874 return extension && extension->is_platform_app(); | 842 return extension && extension->is_platform_app(); |
875 } | 843 } |
876 | 844 |
877 void ExtensionDispatcher::WillReleaseScriptContext( | 845 void Dispatcher::WillReleaseScriptContext( |
878 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) { | 846 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) { |
879 ChromeV8Context* context = v8_context_set_.GetByV8Context(v8_context); | 847 ChromeV8Context* context = v8_context_set_.GetByV8Context(v8_context); |
880 if (!context) | 848 if (!context) |
881 return; | 849 return; |
882 | 850 |
883 context->DispatchOnUnloadEvent(); | 851 context->DispatchOnUnloadEvent(); |
884 | 852 |
885 v8_context_set_.Remove(context); | 853 v8_context_set_.Remove(context); |
886 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); | 854 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); |
887 } | 855 } |
888 | 856 |
889 void ExtensionDispatcher::OnActivateExtension( | 857 void Dispatcher::OnActivateExtension(const std::string& extension_id) { |
890 const std::string& extension_id) { | |
891 active_extension_ids_.insert(extension_id); | 858 active_extension_ids_.insert(extension_id); |
892 const Extension* extension = extensions_.GetByID(extension_id); | 859 const Extension* extension = extensions_.GetByID(extension_id); |
893 CHECK(extension); | 860 CHECK(extension); |
894 | 861 |
895 // This is called when starting a new extension page, so start the idle | 862 // This is called when starting a new extension page, so start the idle |
896 // handler ticking. | 863 // handler ticking. |
897 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); | 864 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); |
898 | 865 |
899 UpdateActiveExtensions(); | 866 UpdateActiveExtensions(); |
900 | 867 |
901 if (is_webkit_initialized_) | 868 if (is_webkit_initialized_) |
902 InitOriginPermissions(extension); | 869 InitOriginPermissions(extension); |
903 } | 870 } |
904 | 871 |
905 void ExtensionDispatcher::InitOriginPermissions(const Extension* extension) { | 872 void Dispatcher::InitOriginPermissions(const Extension* extension) { |
906 // TODO(jstritar): We should try to remove this special case. Also, these | 873 // TODO(jstritar): We should try to remove this special case. Also, these |
907 // whitelist entries need to be updated when the kManagement permission | 874 // whitelist entries need to be updated when the kManagement permission |
908 // changes. | 875 // changes. |
909 if (extension->HasAPIPermission(APIPermission::kManagement)) { | 876 if (extension->HasAPIPermission(APIPermission::kManagement)) { |
910 WebSecurityPolicy::addOriginAccessWhitelistEntry( | 877 WebSecurityPolicy::addOriginAccessWhitelistEntry( |
911 extension->url(), | 878 extension->url(), |
912 WebString::fromUTF8(chrome::kChromeUIScheme), | 879 WebString::fromUTF8(chrome::kChromeUIScheme), |
913 WebString::fromUTF8(chrome::kChromeUIExtensionIconHost), | 880 WebString::fromUTF8(chrome::kChromeUIExtensionIconHost), |
914 false); | 881 false); |
915 } | 882 } |
916 | 883 |
917 AddOrRemoveOriginPermissions( | 884 AddOrRemoveOriginPermissions( |
918 UpdatedExtensionPermissionsInfo::ADDED, | 885 UpdatedExtensionPermissionsInfo::ADDED, |
919 extension, | 886 extension, |
920 extension->GetActivePermissions()->explicit_hosts()); | 887 extension->GetActivePermissions()->explicit_hosts()); |
921 } | 888 } |
922 | 889 |
923 void ExtensionDispatcher::AddOrRemoveOriginPermissions( | 890 void Dispatcher::AddOrRemoveOriginPermissions( |
924 UpdatedExtensionPermissionsInfo::Reason reason, | 891 UpdatedExtensionPermissionsInfo::Reason reason, |
925 const Extension* extension, | 892 const Extension* extension, |
926 const URLPatternSet& origins) { | 893 const URLPatternSet& origins) { |
927 for (URLPatternSet::const_iterator i = origins.begin(); | 894 for (URLPatternSet::const_iterator i = origins.begin(); |
928 i != origins.end(); ++i) { | 895 i != origins.end(); ++i) { |
929 const char* schemes[] = { | 896 const char* schemes[] = { |
930 chrome::kHttpScheme, | 897 chrome::kHttpScheme, |
931 chrome::kHttpsScheme, | 898 chrome::kHttpsScheme, |
932 chrome::kFileScheme, | 899 chrome::kFileScheme, |
933 chrome::kChromeUIScheme, | 900 chrome::kChromeUIScheme, |
934 }; | 901 }; |
935 for (size_t j = 0; j < arraysize(schemes); ++j) { | 902 for (size_t j = 0; j < arraysize(schemes); ++j) { |
936 if (i->MatchesScheme(schemes[j])) { | 903 if (i->MatchesScheme(schemes[j])) { |
937 ((reason == UpdatedExtensionPermissionsInfo::REMOVED) ? | 904 ((reason == UpdatedExtensionPermissionsInfo::REMOVED) ? |
938 WebSecurityPolicy::removeOriginAccessWhitelistEntry : | 905 WebSecurityPolicy::removeOriginAccessWhitelistEntry : |
939 WebSecurityPolicy::addOriginAccessWhitelistEntry)( | 906 WebSecurityPolicy::addOriginAccessWhitelistEntry)( |
940 extension->url(), | 907 extension->url(), |
941 WebString::fromUTF8(schemes[j]), | 908 WebString::fromUTF8(schemes[j]), |
942 WebString::fromUTF8(i->host()), | 909 WebString::fromUTF8(i->host()), |
943 i->match_subdomains()); | 910 i->match_subdomains()); |
944 } | 911 } |
945 } | 912 } |
946 } | 913 } |
947 } | 914 } |
948 | 915 |
949 void ExtensionDispatcher::OnUpdatePermissions( | 916 void Dispatcher::OnUpdatePermissions(int reason_id, |
950 int reason_id, | 917 const std::string& extension_id, |
951 const std::string& extension_id, | 918 const APIPermissionSet& apis, |
952 const extensions::APIPermissionSet& apis, | 919 const URLPatternSet& explicit_hosts, |
953 const URLPatternSet& explicit_hosts, | 920 const URLPatternSet& scriptable_hosts) { |
954 const URLPatternSet& scriptable_hosts) { | |
955 const Extension* extension = extensions_.GetByID(extension_id); | 921 const Extension* extension = extensions_.GetByID(extension_id); |
956 if (!extension) | 922 if (!extension) |
957 return; | 923 return; |
958 | 924 |
959 scoped_refptr<const PermissionSet> delta = | 925 scoped_refptr<const PermissionSet> delta = |
960 new PermissionSet(apis, explicit_hosts, scriptable_hosts); | 926 new PermissionSet(apis, explicit_hosts, scriptable_hosts); |
961 scoped_refptr<const PermissionSet> old_active = | 927 scoped_refptr<const PermissionSet> old_active = |
962 extension->GetActivePermissions(); | 928 extension->GetActivePermissions(); |
963 UpdatedExtensionPermissionsInfo::Reason reason = | 929 UpdatedExtensionPermissionsInfo::Reason reason = |
964 static_cast<UpdatedExtensionPermissionsInfo::Reason>(reason_id); | 930 static_cast<UpdatedExtensionPermissionsInfo::Reason>(reason_id); |
965 | 931 |
966 const PermissionSet* new_active = NULL; | 932 const PermissionSet* new_active = NULL; |
967 switch (reason) { | 933 switch (reason) { |
968 case UpdatedExtensionPermissionsInfo::ADDED: | 934 case UpdatedExtensionPermissionsInfo::ADDED: |
969 new_active = PermissionSet::CreateUnion(old_active, delta); | 935 new_active = PermissionSet::CreateUnion(old_active, delta); |
970 break; | 936 break; |
971 case UpdatedExtensionPermissionsInfo::REMOVED: | 937 case UpdatedExtensionPermissionsInfo::REMOVED: |
972 new_active = PermissionSet::CreateDifference(old_active, delta); | 938 new_active = PermissionSet::CreateDifference(old_active, delta); |
973 break; | 939 break; |
974 } | 940 } |
975 | 941 |
976 extension->SetActivePermissions(new_active); | 942 extension->SetActivePermissions(new_active); |
977 AddOrRemoveOriginPermissions(reason, extension, explicit_hosts); | 943 AddOrRemoveOriginPermissions(reason, extension, explicit_hosts); |
978 } | 944 } |
979 | 945 |
980 void ExtensionDispatcher::OnUpdateTabSpecificPermissions( | 946 void Dispatcher::OnUpdateTabSpecificPermissions( |
981 int page_id, | 947 int page_id, |
982 int tab_id, | 948 int tab_id, |
983 const std::string& extension_id, | 949 const std::string& extension_id, |
984 const URLPatternSet& origin_set) { | 950 const URLPatternSet& origin_set) { |
985 RenderView* view = TabFinder::Find(tab_id); | 951 RenderView* view = TabFinder::Find(tab_id); |
986 | 952 |
987 // For now, the message should only be sent to the render view that contains | 953 // For now, the message should only be sent to the render view that contains |
988 // the target tab. This may change. Either way, if this is the target tab it | 954 // the target tab. This may change. Either way, if this is the target tab it |
989 // gives us the chance to check against the page ID to avoid races. | 955 // gives us the chance to check against the page ID to avoid races. |
990 DCHECK(view); | 956 DCHECK(view); |
991 if (view && view->GetPageId() != page_id) | 957 if (view && view->GetPageId() != page_id) |
992 return; | 958 return; |
993 | 959 |
994 const Extension* extension = extensions_.GetByID(extension_id); | 960 const Extension* extension = extensions_.GetByID(extension_id); |
995 if (!extension) | 961 if (!extension) |
996 return; | 962 return; |
997 | 963 |
998 extension->UpdateTabSpecificPermissions( | 964 extension->UpdateTabSpecificPermissions( |
999 tab_id, | 965 tab_id, |
1000 new PermissionSet(APIPermissionSet(), origin_set, URLPatternSet())); | 966 new PermissionSet(APIPermissionSet(), origin_set, URLPatternSet())); |
1001 } | 967 } |
1002 | 968 |
1003 void ExtensionDispatcher::OnClearTabSpecificPermissions( | 969 void Dispatcher::OnClearTabSpecificPermissions( |
1004 int tab_id, | 970 int tab_id, |
1005 const std::vector<std::string>& extension_ids) { | 971 const std::vector<std::string>& extension_ids) { |
1006 for (std::vector<std::string>::const_iterator it = extension_ids.begin(); | 972 for (std::vector<std::string>::const_iterator it = extension_ids.begin(); |
1007 it != extension_ids.end(); ++it) { | 973 it != extension_ids.end(); ++it) { |
1008 const Extension* extension = extensions_.GetByID(*it); | 974 const Extension* extension = extensions_.GetByID(*it); |
1009 if (extension) | 975 if (extension) |
1010 extension->ClearTabSpecificPermissions(tab_id); | 976 extension->ClearTabSpecificPermissions(tab_id); |
1011 } | 977 } |
1012 } | 978 } |
1013 | 979 |
1014 void ExtensionDispatcher::OnUpdateUserScripts( | 980 void Dispatcher::OnUpdateUserScripts( |
1015 base::SharedMemoryHandle scripts) { | 981 base::SharedMemoryHandle scripts) { |
1016 DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle"; | 982 DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle"; |
1017 user_script_slave_->UpdateScripts(scripts); | 983 user_script_slave_->UpdateScripts(scripts); |
1018 UpdateActiveExtensions(); | 984 UpdateActiveExtensions(); |
1019 } | 985 } |
1020 | 986 |
1021 void ExtensionDispatcher::UpdateActiveExtensions() { | 987 void Dispatcher::UpdateActiveExtensions() { |
1022 // In single-process mode, the browser process reports the active extensions. | 988 // In single-process mode, the browser process reports the active extensions. |
1023 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) | 989 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) |
1024 return; | 990 return; |
1025 | 991 |
1026 std::set<std::string> active_extensions = active_extension_ids_; | 992 std::set<std::string> active_extensions = active_extension_ids_; |
1027 user_script_slave_->GetActiveExtensions(&active_extensions); | 993 user_script_slave_->GetActiveExtensions(&active_extensions); |
1028 child_process_logging::SetActiveExtensions(active_extensions); | 994 child_process_logging::SetActiveExtensions(active_extensions); |
1029 } | 995 } |
1030 | 996 |
1031 void ExtensionDispatcher::RegisterExtension(v8::Extension* extension, | 997 void Dispatcher::RegisterExtension(v8::Extension* extension, |
1032 bool restrict_to_extensions) { | 998 bool restrict_to_extensions) { |
1033 if (restrict_to_extensions) | 999 if (restrict_to_extensions) |
1034 restricted_v8_extensions_.insert(extension->name()); | 1000 restricted_v8_extensions_.insert(extension->name()); |
1035 | 1001 |
1036 RenderThread::Get()->RegisterExtension(extension); | 1002 RenderThread::Get()->RegisterExtension(extension); |
1037 } | 1003 } |
1038 | 1004 |
1039 void ExtensionDispatcher::OnUsingWebRequestAPI( | 1005 void Dispatcher::OnUsingWebRequestAPI( |
1040 bool adblock, bool adblock_plus, bool other) { | 1006 bool adblock, bool adblock_plus, bool other) { |
1041 webrequest_adblock_ = adblock; | 1007 webrequest_adblock_ = adblock; |
1042 webrequest_adblock_plus_ = adblock_plus; | 1008 webrequest_adblock_plus_ = adblock_plus; |
1043 webrequest_other_ = other; | 1009 webrequest_other_ = other; |
1044 } | 1010 } |
1045 | 1011 |
1046 void ExtensionDispatcher::OnShouldUnload(const std::string& extension_id, | 1012 void Dispatcher::OnShouldUnload(const std::string& extension_id, |
1047 int sequence_id) { | 1013 int sequence_id) { |
1048 RenderThread::Get()->Send( | 1014 RenderThread::Get()->Send( |
1049 new ExtensionHostMsg_ShouldUnloadAck(extension_id, sequence_id)); | 1015 new ExtensionHostMsg_ShouldUnloadAck(extension_id, sequence_id)); |
1050 } | 1016 } |
1051 | 1017 |
1052 void ExtensionDispatcher::OnUnload(const std::string& extension_id) { | 1018 void Dispatcher::OnUnload(const std::string& extension_id) { |
1053 // Dispatch the unload event. This doesn't go through the standard event | 1019 // Dispatch the unload event. This doesn't go through the standard event |
1054 // dispatch machinery because it requires special handling. We need to let | 1020 // dispatch machinery because it requires special handling. We need to let |
1055 // the browser know when we are starting and stopping the event dispatch, so | 1021 // the browser know when we are starting and stopping the event dispatch, so |
1056 // that it still considers the extension idle despite any activity the unload | 1022 // that it still considers the extension idle despite any activity the unload |
1057 // event creates. | 1023 // event creates. |
1058 ListValue args; | 1024 ListValue args; |
1059 args.Set(0, Value::CreateStringValue(kOnUnloadEvent)); | 1025 args.Set(0, Value::CreateStringValue(kOnUnloadEvent)); |
1060 args.Set(1, Value::CreateStringValue("[]")); | 1026 args.Set(1, Value::CreateStringValue("[]")); |
1061 v8_context_set_.DispatchChromeHiddenMethod( | 1027 v8_context_set_.DispatchChromeHiddenMethod( |
1062 extension_id, kEventDispatchFunction, args, NULL, GURL()); | 1028 extension_id, kEventDispatchFunction, args, NULL, GURL()); |
1063 | 1029 |
1064 RenderThread::Get()->Send(new ExtensionHostMsg_UnloadAck(extension_id)); | 1030 RenderThread::Get()->Send(new ExtensionHostMsg_UnloadAck(extension_id)); |
1065 } | 1031 } |
1066 | 1032 |
1067 void ExtensionDispatcher::OnCancelUnload(const std::string& extension_id) { | 1033 void Dispatcher::OnCancelUnload(const std::string& extension_id) { |
1068 ListValue args; | 1034 ListValue args; |
1069 args.Set(0, Value::CreateStringValue(kOnSuspendCanceledEvent)); | 1035 args.Set(0, Value::CreateStringValue(kOnSuspendCanceledEvent)); |
1070 args.Set(1, Value::CreateStringValue("[]")); | 1036 args.Set(1, Value::CreateStringValue("[]")); |
1071 v8_context_set_.DispatchChromeHiddenMethod( | 1037 v8_context_set_.DispatchChromeHiddenMethod( |
1072 extension_id, kEventDispatchFunction, args, NULL, GURL()); | 1038 extension_id, kEventDispatchFunction, args, NULL, GURL()); |
1073 } | 1039 } |
1074 | 1040 |
1075 Feature::Context ExtensionDispatcher::ClassifyJavaScriptContext( | 1041 Feature::Context Dispatcher::ClassifyJavaScriptContext( |
1076 const std::string& extension_id, | 1042 const std::string& extension_id, |
1077 int extension_group, | 1043 int extension_group, |
1078 const ExtensionURLInfo& url_info) { | 1044 const ExtensionURLInfo& url_info) { |
1079 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) { | 1045 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) { |
1080 return extensions_.Contains(extension_id) ? | 1046 return extensions_.Contains(extension_id) ? |
1081 Feature::CONTENT_SCRIPT_CONTEXT : Feature::UNSPECIFIED_CONTEXT; | 1047 Feature::CONTENT_SCRIPT_CONTEXT : Feature::UNSPECIFIED_CONTEXT; |
1082 } | 1048 } |
1083 | 1049 |
1084 // We have an explicit check for sandboxed pages first since: | 1050 // We have an explicit check for sandboxed pages first since: |
1085 // 1. Sandboxed pages run in the same process as regular extension pages, so | 1051 // 1. Sandboxed pages run in the same process as regular extension pages, so |
(...skipping 10 matching lines...) Expand all Loading... |
1096 | 1062 |
1097 if (extensions_.ExtensionBindingsAllowed(url_info)) | 1063 if (extensions_.ExtensionBindingsAllowed(url_info)) |
1098 return Feature::UNBLESSED_EXTENSION_CONTEXT; | 1064 return Feature::UNBLESSED_EXTENSION_CONTEXT; |
1099 | 1065 |
1100 if (url_info.url().is_valid()) | 1066 if (url_info.url().is_valid()) |
1101 return Feature::WEB_PAGE_CONTEXT; | 1067 return Feature::WEB_PAGE_CONTEXT; |
1102 | 1068 |
1103 return Feature::UNSPECIFIED_CONTEXT; | 1069 return Feature::UNSPECIFIED_CONTEXT; |
1104 } | 1070 } |
1105 | 1071 |
1106 void ExtensionDispatcher::OnExtensionResponse(int request_id, | 1072 void Dispatcher::OnExtensionResponse(int request_id, |
1107 bool success, | 1073 bool success, |
1108 const base::ListValue& response, | 1074 const base::ListValue& response, |
1109 const std::string& error) { | 1075 const std::string& error) { |
1110 request_sender_->HandleResponse(request_id, success, response, error); | 1076 request_sender_->HandleResponse(request_id, success, response, error); |
1111 } | 1077 } |
1112 | 1078 |
1113 bool ExtensionDispatcher::CheckCurrentContextAccessToExtensionAPI( | 1079 bool Dispatcher::CheckCurrentContextAccessToExtensionAPI( |
1114 const std::string& function_name) const { | 1080 const std::string& function_name) const { |
1115 ChromeV8Context* context = v8_context_set().GetCurrent(); | 1081 ChromeV8Context* context = v8_context_set().GetCurrent(); |
1116 if (!context) { | 1082 if (!context) { |
1117 DLOG(ERROR) << "Not in a v8::Context"; | 1083 DLOG(ERROR) << "Not in a v8::Context"; |
1118 return false; | 1084 return false; |
1119 } | 1085 } |
1120 | 1086 |
1121 if (!context->extension()) { | 1087 if (!context->extension()) { |
1122 v8::ThrowException( | 1088 v8::ThrowException( |
1123 v8::Exception::Error(v8::String::New("Not in an extension."))); | 1089 v8::Exception::Error(v8::String::New("Not in an extension."))); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1121 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
1156 return false; | 1122 return false; |
1157 } | 1123 } |
1158 | 1124 |
1159 // We should never end up with sandboxed contexts trying to invoke extension | 1125 // We should never end up with sandboxed contexts trying to invoke extension |
1160 // APIs, they don't get extension bindings injected. If we end up here it | 1126 // APIs, they don't get extension bindings injected. If we end up here it |
1161 // means that a sandboxed page somehow managed to invoke an API anyway, so | 1127 // means that a sandboxed page somehow managed to invoke an API anyway, so |
1162 // we should abort. | 1128 // we should abort. |
1163 WebKit::WebFrame* frame = context->web_frame(); | 1129 WebKit::WebFrame* frame = context->web_frame(); |
1164 ExtensionURLInfo url_info(frame->document().securityOrigin(), | 1130 ExtensionURLInfo url_info(frame->document().securityOrigin(), |
1165 extensions::UserScriptSlave::GetDataSourceURLForFrame(frame)); | 1131 UserScriptSlave::GetDataSourceURLForFrame(frame)); |
1166 CHECK(!extensions_.IsSandboxedPage(url_info)); | 1132 CHECK(!extensions_.IsSandboxedPage(url_info)); |
1167 | 1133 |
1168 return true; | 1134 return true; |
1169 } | 1135 } |
| 1136 |
| 1137 } // namespace extensions |
OLD | NEW |