OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_dispatcher.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/common/child_process_logging.h" | 8 #include "chrome/common/child_process_logging.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
11 #include "chrome/common/extensions/extension_messages.h" | 11 #include "chrome/common/extensions/extension_messages.h" |
12 #include "chrome/common/extensions/extension_permission_set.h" | 12 #include "chrome/common/extensions/extension_permission_set.h" |
13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
14 #include "chrome/renderer/chrome_render_process_observer.h" | 14 #include "chrome/renderer/chrome_render_process_observer.h" |
15 #include "chrome/renderer/extensions/app_bindings.h" | 15 #include "chrome/renderer/extensions/app_bindings.h" |
16 #include "chrome/renderer/extensions/chrome_v8_context.h" | 16 #include "chrome/renderer/extensions/chrome_v8_context.h" |
17 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 17 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
18 #include "chrome/renderer/extensions/chrome_webstore_bindings.h" | 18 #include "chrome/renderer/extensions/chrome_webstore_bindings.h" |
19 #include "chrome/renderer/extensions/event_bindings.h" | 19 #include "chrome/renderer/extensions/event_bindings.h" |
20 #include "chrome/renderer/extensions/extension_groups.h" | 20 #include "chrome/renderer/extensions/extension_groups.h" |
21 #include "chrome/renderer/extensions/file_browser_private_bindings.h" | 21 #include "chrome/renderer/extensions/file_browser_private_bindings.h" |
22 #include "chrome/renderer/extensions/miscellaneous_bindings.h" | 22 #include "chrome/renderer/extensions/miscellaneous_bindings.h" |
23 #include "chrome/renderer/extensions/schema_generated_bindings.h" | 23 #include "chrome/renderer/extensions/schema_generated_bindings.h" |
24 #include "chrome/renderer/extensions/user_script_slave.h" | 24 #include "chrome/renderer/extensions/user_script_slave.h" |
25 #include "content/public/renderer/render_thread.h" | 25 #include "content/public/renderer/render_thread.h" |
26 #include "grit/renderer_resources.h" | 26 #include "grit/renderer_resources.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
33 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
34 #include "v8/include/v8.h" | 35 #include "v8/include/v8.h" |
35 | 36 |
36 namespace { | 37 namespace { |
37 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; | 38 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; |
38 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; | 39 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; |
39 } | 40 } |
40 | 41 |
41 using extensions::MiscellaneousBindings; | 42 using extensions::MiscellaneousBindings; |
42 using extensions::SchemaGeneratedBindings; | 43 using extensions::SchemaGeneratedBindings; |
43 using WebKit::WebDataSource; | 44 using WebKit::WebDataSource; |
| 45 using WebKit::WebDocument; |
44 using WebKit::WebFrame; | 46 using WebKit::WebFrame; |
45 using WebKit::WebSecurityPolicy; | 47 using WebKit::WebSecurityPolicy; |
46 using WebKit::WebString; | 48 using WebKit::WebString; |
47 using WebKit::WebVector; | 49 using WebKit::WebVector; |
48 using WebKit::WebView; | 50 using WebKit::WebView; |
49 using content::RenderThread; | 51 using content::RenderThread; |
50 | 52 |
51 ExtensionDispatcher::ExtensionDispatcher() | 53 ExtensionDispatcher::ExtensionDispatcher() |
52 : is_webkit_initialized_(false), | 54 : is_webkit_initialized_(false), |
53 webrequest_adblock_(false), | 55 webrequest_adblock_(false), |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 if (!RenderThread::Get()->IsRegisteredExtension(v8_extension_name)) | 268 if (!RenderThread::Get()->IsRegisteredExtension(v8_extension_name)) |
267 return true; | 269 return true; |
268 | 270 |
269 // If the V8 extension is not restricted, allow it to run anywhere. | 271 // If the V8 extension is not restricted, allow it to run anywhere. |
270 if (!restricted_v8_extensions_.count(v8_extension_name)) | 272 if (!restricted_v8_extensions_.count(v8_extension_name)) |
271 return true; | 273 return true; |
272 | 274 |
273 // Extension-only bindings should be restricted to content scripts and | 275 // Extension-only bindings should be restricted to content scripts and |
274 // extension-blessed URLs. | 276 // extension-blessed URLs. |
275 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS || | 277 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS || |
276 extensions_.ExtensionBindingsAllowed( | 278 extensions_.ExtensionBindingsAllowed(ExtensionURLInfo( |
277 UserScriptSlave::GetLatestURLForFrame(frame))) { | 279 frame->document().securityOrigin(), |
| 280 UserScriptSlave::GetDataSourceURLForFrame(frame)))) { |
278 return true; | 281 return true; |
279 } | 282 } |
280 | 283 |
281 return false; | 284 return false; |
282 } | 285 } |
283 | 286 |
284 void ExtensionDispatcher::DidCreateScriptContext( | 287 void ExtensionDispatcher::DidCreateScriptContext( |
285 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) { | 288 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) { |
286 std::string extension_id; | 289 std::string extension_id; |
287 if (!test_extension_id_.empty()) { | 290 if (!test_extension_id_.empty()) { |
288 extension_id = test_extension_id_; | 291 extension_id = test_extension_id_; |
289 } else if (world_id != 0) { | 292 } else if (world_id != 0) { |
290 extension_id = user_script_slave_->GetExtensionIdForIsolatedWorld(world_id); | 293 extension_id = user_script_slave_->GetExtensionIdForIsolatedWorld(world_id); |
291 } else { | 294 } else { |
292 GURL frame_url = UserScriptSlave::GetLatestURLForFrame(frame); | 295 GURL frame_url = UserScriptSlave::GetDataSourceURLForFrame(frame); |
293 extension_id = extensions_.GetIdByURL(frame_url); | 296 extension_id = extensions_.GetIdByURL( |
| 297 ExtensionURLInfo(frame->document().securityOrigin(), frame_url)); |
294 } | 298 } |
295 | 299 |
296 ChromeV8Context* context = | 300 ChromeV8Context* context = |
297 new ChromeV8Context(v8_context, frame, extension_id); | 301 new ChromeV8Context(v8_context, frame, extension_id); |
298 v8_context_set_.Add(context); | 302 v8_context_set_.Add(context); |
299 | 303 |
300 context->DispatchOnLoadEvent( | 304 context->DispatchOnLoadEvent( |
301 is_extension_process_, | 305 is_extension_process_, |
302 ChromeRenderProcessObserver::is_incognito_process()); | 306 ChromeRenderProcessObserver::is_incognito_process()); |
303 | 307 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 | 449 |
446 RenderThread::Get()->RegisterExtension(extension); | 450 RenderThread::Get()->RegisterExtension(extension); |
447 } | 451 } |
448 | 452 |
449 void ExtensionDispatcher::OnUsingWebRequestAPI( | 453 void ExtensionDispatcher::OnUsingWebRequestAPI( |
450 bool adblock, bool adblock_plus, bool other) { | 454 bool adblock, bool adblock_plus, bool other) { |
451 webrequest_adblock_ = adblock; | 455 webrequest_adblock_ = adblock; |
452 webrequest_adblock_plus_ = adblock_plus; | 456 webrequest_adblock_plus_ = adblock_plus; |
453 webrequest_other_ = other; | 457 webrequest_other_ = other; |
454 } | 458 } |
OLD | NEW |