Chromium Code Reviews| 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/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/debug/alias.h" | 9 #include "base/debug/alias.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 #include "chrome/renderer/resource_bundle_source_map.h" | 76 #include "chrome/renderer/resource_bundle_source_map.h" |
| 77 #include "content/public/renderer/render_thread.h" | 77 #include "content/public/renderer/render_thread.h" |
| 78 #include "content/public/renderer/render_view.h" | 78 #include "content/public/renderer/render_view.h" |
| 79 #include "content/public/renderer/v8_value_converter.h" | 79 #include "content/public/renderer/v8_value_converter.h" |
| 80 #include "extensions/common/constants.h" | 80 #include "extensions/common/constants.h" |
| 81 #include "extensions/common/view_type.h" | 81 #include "extensions/common/view_type.h" |
| 82 #include "grit/common_resources.h" | 82 #include "grit/common_resources.h" |
| 83 #include "grit/renderer_resources.h" | 83 #include "grit/renderer_resources.h" |
| 84 #include "third_party/WebKit/public/platform/WebString.h" | 84 #include "third_party/WebKit/public/platform/WebString.h" |
| 85 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 85 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 86 #include "third_party/WebKit/public/web/WebCustomElement.h" | |
| 86 #include "third_party/WebKit/public/web/WebDataSource.h" | 87 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 87 #include "third_party/WebKit/public/web/WebDocument.h" | 88 #include "third_party/WebKit/public/web/WebDocument.h" |
| 88 #include "third_party/WebKit/public/web/WebFrame.h" | 89 #include "third_party/WebKit/public/web/WebFrame.h" |
| 90 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | |
| 89 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 91 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
| 90 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 92 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 91 #include "third_party/WebKit/public/web/WebView.h" | 93 #include "third_party/WebKit/public/web/WebView.h" |
| 92 #include "ui/base/layout.h" | 94 #include "ui/base/layout.h" |
| 93 #include "ui/base/resource/resource_bundle.h" | 95 #include "ui/base/resource/resource_bundle.h" |
| 94 #include "v8/include/v8.h" | 96 #include "v8/include/v8.h" |
| 95 | 97 |
| 96 using WebKit::WebDataSource; | 98 using WebKit::WebDataSource; |
| 97 using WebKit::WebDocument; | 99 using WebKit::WebDocument; |
| 98 using WebKit::WebFrame; | 100 using WebKit::WebFrame; |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 | 458 |
| 457 void Dispatcher::WebKitInitialized() { | 459 void Dispatcher::WebKitInitialized() { |
| 458 // For extensions, we want to ensure we call the IdleHandler every so often, | 460 // For extensions, we want to ensure we call the IdleHandler every so often, |
| 459 // even if the extension keeps up activity. | 461 // even if the extension keeps up activity. |
| 460 if (is_extension_process_) { | 462 if (is_extension_process_) { |
| 461 forced_idle_timer_.Start(FROM_HERE, | 463 forced_idle_timer_.Start(FROM_HERE, |
| 462 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), | 464 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), |
| 463 RenderThread::Get(), &RenderThread::IdleHandler); | 465 RenderThread::Get(), &RenderThread::IdleHandler); |
| 464 } | 466 } |
| 465 | 467 |
| 468 bool is_app = false; | |
| 466 // Initialize host permissions for any extensions that were activated before | 469 // Initialize host permissions for any extensions that were activated before |
| 467 // WebKit was initialized. | 470 // WebKit was initialized. |
| 468 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); | 471 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); |
| 469 iter != active_extension_ids_.end(); ++iter) { | 472 iter != active_extension_ids_.end(); ++iter) { |
| 470 const Extension* extension = extensions_.GetByID(*iter); | 473 const Extension* extension = extensions_.GetByID(*iter); |
| 471 CHECK(extension); | 474 CHECK(extension); |
| 472 InitOriginPermissions(extension); | 475 InitOriginPermissions(extension); |
| 476 is_app |= extension->is_app(); | |
|
not at google - send to devlin
2013/08/08 21:20:25
you probably want is_platform_app()
| |
| 473 } | 477 } |
| 474 | 478 |
| 479 if (is_app) | |
| 480 EnableCustomElementWhiteList(); | |
| 481 | |
| 475 is_webkit_initialized_ = true; | 482 is_webkit_initialized_ = true; |
| 476 } | 483 } |
| 477 | 484 |
| 478 void Dispatcher::IdleNotification() { | 485 void Dispatcher::IdleNotification() { |
| 479 if (is_extension_process_) { | 486 if (is_extension_process_) { |
| 480 // Dampen the forced delay as well if the extension stays idle for long | 487 // Dampen the forced delay as well if the extension stays idle for long |
| 481 // periods of time. | 488 // periods of time. |
| 482 int64 forced_delay_ms = std::max( | 489 int64 forced_delay_ms = std::max( |
| 483 RenderThread::Get()->GetIdleNotificationDelayInMs(), | 490 RenderThread::Get()->GetIdleNotificationDelayInMs(), |
| 484 kMaxExtensionIdleHandlerDelayMs); | 491 kMaxExtensionIdleHandlerDelayMs); |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1142 | 1149 |
| 1143 // TODO(kalman): Delete this check. | 1150 // TODO(kalman): Delete this check. |
| 1144 if (frame->document().securityOrigin().isUnique()) | 1151 if (frame->document().securityOrigin().isUnique()) |
| 1145 return std::string(); | 1152 return std::string(); |
| 1146 | 1153 |
| 1147 // Extension pages (chrome-extension:// URLs). | 1154 // Extension pages (chrome-extension:// URLs). |
| 1148 GURL frame_url = UserScriptSlave::GetDataSourceURLForFrame(frame); | 1155 GURL frame_url = UserScriptSlave::GetDataSourceURLForFrame(frame); |
| 1149 return extensions_.GetExtensionOrAppIDByURL(frame_url); | 1156 return extensions_.GetExtensionOrAppIDByURL(frame_url); |
| 1150 } | 1157 } |
| 1151 | 1158 |
| 1152 bool Dispatcher::IsWithinPlatformApp(const WebFrame* frame) { | 1159 bool Dispatcher::IsWithinPlatformApp(const WebFrame* frame) { |
|
not at google - send to devlin
2013/08/08 21:20:25
I would rather we fix this method to work without
| |
| 1153 GURL url(UserScriptSlave::GetDataSourceURLForFrame(frame->top())); | 1160 GURL url(UserScriptSlave::GetDataSourceURLForFrame(frame->top())); |
| 1154 const Extension* extension = extensions_.GetExtensionOrAppByURL(url); | 1161 const Extension* extension = extensions_.GetExtensionOrAppByURL(url); |
| 1155 | 1162 |
| 1156 return extension && extension->is_platform_app(); | 1163 return extension && extension->is_platform_app(); |
| 1157 } | 1164 } |
| 1158 | 1165 |
| 1159 void Dispatcher::WillReleaseScriptContext( | 1166 void Dispatcher::WillReleaseScriptContext( |
| 1160 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) { | 1167 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) { |
| 1161 ChromeV8Context* context = v8_context_set_.GetByV8Context(v8_context); | 1168 ChromeV8Context* context = v8_context_set_.GetByV8Context(v8_context); |
| 1162 if (!context) | 1169 if (!context) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1215 | 1222 |
| 1216 if (is_webkit_initialized_) { | 1223 if (is_webkit_initialized_) { |
| 1217 InitOriginPermissions(extension); | 1224 InitOriginPermissions(extension); |
| 1218 // DOMActivity logger for a main world controlled by an extension (as in | 1225 // DOMActivity logger for a main world controlled by an extension (as in |
| 1219 // the case of an extension background page, options page, popup etc.) | 1226 // the case of an extension background page, options page, popup etc.) |
| 1220 // gets an empty title. | 1227 // gets an empty title. |
| 1221 DOMActivityLogger::AttachToWorld(DOMActivityLogger::kMainWorldId, | 1228 DOMActivityLogger::AttachToWorld(DOMActivityLogger::kMainWorldId, |
| 1222 extension_id, | 1229 extension_id, |
| 1223 extension->url(), | 1230 extension->url(), |
| 1224 string16()); | 1231 string16()); |
| 1232 | |
| 1233 const Extension* extension = extensions_.GetByID(extension_id); | |
| 1234 if (extension->is_app()) | |
| 1235 EnableCustomElementWhiteList(); | |
| 1225 } | 1236 } |
| 1226 } | 1237 } |
| 1227 | 1238 |
| 1228 void Dispatcher::InitOriginPermissions(const Extension* extension) { | 1239 void Dispatcher::InitOriginPermissions(const Extension* extension) { |
| 1229 // TODO(jstritar): We should try to remove this special case. Also, these | 1240 // TODO(jstritar): We should try to remove this special case. Also, these |
| 1230 // whitelist entries need to be updated when the kManagement permission | 1241 // whitelist entries need to be updated when the kManagement permission |
| 1231 // changes. | 1242 // changes. |
| 1232 if (extension->HasAPIPermission(APIPermission::kManagement)) { | 1243 if (extension->HasAPIPermission(APIPermission::kManagement)) { |
| 1233 WebSecurityPolicy::addOriginAccessWhitelistEntry( | 1244 WebSecurityPolicy::addOriginAccessWhitelistEntry( |
| 1234 extension->url(), | 1245 extension->url(), |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1262 WebSecurityPolicy::addOriginAccessWhitelistEntry)( | 1273 WebSecurityPolicy::addOriginAccessWhitelistEntry)( |
| 1263 extension->url(), | 1274 extension->url(), |
| 1264 WebString::fromUTF8(schemes[j]), | 1275 WebString::fromUTF8(schemes[j]), |
| 1265 WebString::fromUTF8(i->host()), | 1276 WebString::fromUTF8(i->host()), |
| 1266 i->match_subdomains()); | 1277 i->match_subdomains()); |
| 1267 } | 1278 } |
| 1268 } | 1279 } |
| 1269 } | 1280 } |
| 1270 } | 1281 } |
| 1271 | 1282 |
| 1283 void Dispatcher::EnableCustomElementWhiteList() { | |
| 1284 WebKit::WebRuntimeFeatures::enableCustomElements(true); | |
| 1285 WebKit::WebCustomElement::allowTagName("webview"); | |
| 1286 // TODO(fsamuel): Add <adview> to the whitelist once it has been converted | |
| 1287 // into a custom element. | |
| 1288 WebKit::WebCustomElement::allowTagName("browser-plugin"); | |
| 1289 } | |
| 1290 | |
| 1272 void Dispatcher::AddOrRemoveBindings(const std::string& extension_id) { | 1291 void Dispatcher::AddOrRemoveBindings(const std::string& extension_id) { |
| 1273 v8_context_set().ForEach( | 1292 v8_context_set().ForEach( |
| 1274 extension_id, | 1293 extension_id, |
| 1275 NULL, // all render views | 1294 NULL, // all render views |
| 1276 base::Bind(&Dispatcher::AddOrRemoveBindingsForContext, | 1295 base::Bind(&Dispatcher::AddOrRemoveBindingsForContext, |
| 1277 base::Unretained(this))); | 1296 base::Unretained(this))); |
| 1278 } | 1297 } |
| 1279 | 1298 |
| 1280 void Dispatcher::OnUpdatePermissions(int reason_id, | 1299 void Dispatcher::OnUpdatePermissions(int reason_id, |
| 1281 const std::string& extension_id, | 1300 const std::string& extension_id, |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1530 RenderView* background_view = | 1549 RenderView* background_view = |
| 1531 ExtensionHelper::GetBackgroundPage(extension_id); | 1550 ExtensionHelper::GetBackgroundPage(extension_id); |
| 1532 if (background_view) { | 1551 if (background_view) { |
| 1533 background_view->Send(new ExtensionHostMsg_EventAck( | 1552 background_view->Send(new ExtensionHostMsg_EventAck( |
| 1534 background_view->GetRoutingID())); | 1553 background_view->GetRoutingID())); |
| 1535 } | 1554 } |
| 1536 } | 1555 } |
| 1537 } | 1556 } |
| 1538 | 1557 |
| 1539 } // namespace extensions | 1558 } // namespace extensions |
| OLD | NEW |