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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
13 #include "base/metrics/user_metrics_action.h" | 13 #include "base/metrics/user_metrics_action.h" |
14 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 #include "content/grit/content_resources.h" | 20 #include "content/grit/content_resources.h" |
20 #include "content/public/child/v8_value_converter.h" | 21 #include "content/public/child/v8_value_converter.h" |
21 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
22 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
23 #include "content/public/renderer/render_frame.h" | 24 #include "content/public/renderer/render_frame.h" |
24 #include "content/public/renderer/render_thread.h" | 25 #include "content/public/renderer/render_thread.h" |
25 #include "extensions/common/api/messaging/message.h" | 26 #include "extensions/common/api/messaging/message.h" |
26 #include "extensions/common/constants.h" | 27 #include "extensions/common/constants.h" |
27 #include "extensions/common/extension_api.h" | 28 #include "extensions/common/extension_api.h" |
28 #include "extensions/common/extension_messages.h" | 29 #include "extensions/common/extension_messages.h" |
29 #include "extensions/common/extension_urls.h" | 30 #include "extensions/common/extension_urls.h" |
30 #include "extensions/common/feature_switch.h" | 31 #include "extensions/common/feature_switch.h" |
32 #include "extensions/common/features/behavior_feature.h" | |
31 #include "extensions/common/features/feature.h" | 33 #include "extensions/common/features/feature.h" |
32 #include "extensions/common/features/feature_provider.h" | 34 #include "extensions/common/features/feature_provider.h" |
33 #include "extensions/common/manifest.h" | 35 #include "extensions/common/manifest.h" |
34 #include "extensions/common/manifest_constants.h" | 36 #include "extensions/common/manifest_constants.h" |
35 #include "extensions/common/manifest_handlers/background_info.h" | 37 #include "extensions/common/manifest_handlers/background_info.h" |
36 #include "extensions/common/manifest_handlers/content_capabilities_handler.h" | 38 #include "extensions/common/manifest_handlers/content_capabilities_handler.h" |
37 #include "extensions/common/manifest_handlers/externally_connectable.h" | 39 #include "extensions/common/manifest_handlers/externally_connectable.h" |
38 #include "extensions/common/manifest_handlers/options_page_info.h" | 40 #include "extensions/common/manifest_handlers/options_page_info.h" |
39 #include "extensions/common/message_bundle.h" | 41 #include "extensions/common/message_bundle.h" |
40 #include "extensions/common/permissions/permission_set.h" | 42 #include "extensions/common/permissions/permission_set.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 93 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
92 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 94 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
93 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 95 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
94 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 96 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
95 #include "third_party/WebKit/public/web/WebView.h" | 97 #include "third_party/WebKit/public/web/WebView.h" |
96 #include "third_party/mojo/src/mojo/public/js/constants.h" | 98 #include "third_party/mojo/src/mojo/public/js/constants.h" |
97 #include "ui/base/layout.h" | 99 #include "ui/base/layout.h" |
98 #include "ui/base/resource/resource_bundle.h" | 100 #include "ui/base/resource/resource_bundle.h" |
99 #include "v8/include/v8.h" | 101 #include "v8/include/v8.h" |
100 | 102 |
103 using base::ASCIIToUTF16; | |
Devlin
2015/07/10 21:51:23
avoid using "usings" when it's less than about 5 -
| |
101 using base::UserMetricsAction; | 104 using base::UserMetricsAction; |
102 using blink::WebDataSource; | 105 using blink::WebDataSource; |
103 using blink::WebDocument; | 106 using blink::WebDocument; |
104 using blink::WebScopedUserGesture; | 107 using blink::WebScopedUserGesture; |
105 using blink::WebSecurityPolicy; | 108 using blink::WebSecurityPolicy; |
106 using blink::WebString; | 109 using blink::WebString; |
107 using blink::WebVector; | 110 using blink::WebVector; |
108 using blink::WebView; | 111 using blink::WebView; |
109 using content::RenderThread; | 112 using content::RenderThread; |
110 | 113 |
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
905 const std::string& module_name, | 908 const std::string& module_name, |
906 const std::string& function_name, | 909 const std::string& function_name, |
907 const base::ListValue& args, | 910 const base::ListValue& args, |
908 bool user_gesture) { | 911 bool user_gesture) { |
909 InvokeModuleSystemMethod( | 912 InvokeModuleSystemMethod( |
910 NULL, extension_id, module_name, function_name, args, user_gesture); | 913 NULL, extension_id, module_name, function_name, args, user_gesture); |
911 } | 914 } |
912 | 915 |
913 void Dispatcher::OnSetChannel(int channel) { | 916 void Dispatcher::OnSetChannel(int channel) { |
914 delegate_->SetChannel(channel); | 917 delegate_->SetChannel(channel); |
918 AddChannelSpecificFeatures(); | |
915 } | 919 } |
916 | 920 |
917 void Dispatcher::OnSetFunctionNames(const std::vector<std::string>& names) { | 921 void Dispatcher::OnSetFunctionNames(const std::vector<std::string>& names) { |
918 function_names_.clear(); | 922 function_names_.clear(); |
919 for (size_t i = 0; i < names.size(); ++i) | 923 for (size_t i = 0; i < names.size(); ++i) |
920 function_names_.insert(names[i]); | 924 function_names_.insert(names[i]); |
921 } | 925 } |
922 | 926 |
923 void Dispatcher::OnSetScriptingWhitelist( | 927 void Dispatcher::OnSetScriptingWhitelist( |
924 const ExtensionsClient::ScriptingWhitelist& extension_ids) { | 928 const ExtensionsClient::ScriptingWhitelist& extension_ids) { |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1441 | 1445 |
1442 // The "guestViewDeny" module must always be loaded last. It registers | 1446 // The "guestViewDeny" module must always be loaded last. It registers |
1443 // error-providing custom elements for the GuestView types that are not | 1447 // error-providing custom elements for the GuestView types that are not |
1444 // available, and thus all of those types must have been checked and loaded | 1448 // available, and thus all of those types must have been checked and loaded |
1445 // (or not loaded) beforehand. | 1449 // (or not loaded) beforehand. |
1446 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 1450 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
1447 module_system->Require("guestViewDeny"); | 1451 module_system->Require("guestViewDeny"); |
1448 } | 1452 } |
1449 } | 1453 } |
1450 | 1454 |
1455 void Dispatcher::AddChannelSpecificFeatures() { | |
1456 WebString extension_scheme(ASCIIToUTF16(extensions::kExtensionScheme)); | |
Devlin
2015/07/10 21:51:23
This would be simpler using WebString::fromUtf8(kE
| |
1457 | |
1458 // chrome-extension: resources should be allowed to register a Service Worker. | |
1459 if (IsExtensionAllowedToUseServiceWorker()) | |
1460 WebSecurityPolicy::registerURLSchemeAsAllowingServiceWorkers( | |
1461 extension_scheme); | |
1462 } | |
1463 | |
1464 bool Dispatcher::IsExtensionAllowedToUseServiceWorker() { | |
Devlin
2015/07/10 21:51:23
It's fine to inline this function in AddChannelSpe
| |
1465 return FeatureProvider::GetBehaviorFeature( | |
1466 BehaviorFeature::kServiceWorker) | |
1467 ->IsAvailableToEnvironment() | |
1468 .is_available(); | |
1469 } | |
1470 | |
1451 } // namespace extensions | 1471 } // namespace extensions |
OLD | NEW |